45 lines
1.2 KiB
Plaintext
45 lines
1.2 KiB
Plaintext
// Behaviour scripts. Each function receives what the entity senses and
|
|
// returns the name of an action; the Rust side carries it out.
|
|
|
|
// person: sleep | go_home | eat | haul | hunt | forage | chop | mine | wander
|
|
pub fn person(c) {
|
|
if c.night {
|
|
return if c.at_home { "sleep" } else { "go_home" };
|
|
}
|
|
if c.hunger > 50.0 && c.carried_food == 0 && c.stock_food > 0 {
|
|
return "eat";
|
|
}
|
|
if c.carry >= 6 {
|
|
return "haul";
|
|
}
|
|
if c.stock_food < 12 || c.hunger > 50.0 {
|
|
if c.rabbit_near && (!c.berry_near || c.roll < 0.3) {
|
|
return "hunt";
|
|
}
|
|
if c.berry_near {
|
|
return "forage";
|
|
}
|
|
}
|
|
if c.stock_wood <= c.stock_stone * 2 + 8 {
|
|
if c.tree_near { "chop" } else if c.stone_near { "mine" } else { "wander" }
|
|
} else {
|
|
if c.stone_near { "mine" } else if c.tree_near { "chop" } else { "wander" }
|
|
}
|
|
}
|
|
|
|
// rabbit: flee | wander | stay
|
|
pub fn rabbit(c) {
|
|
if c.wolf_near {
|
|
if c.roll < 0.8 { "flee" } else { "stay" }
|
|
} else if c.roll < 0.5 {
|
|
"wander"
|
|
} else {
|
|
"stay"
|
|
}
|
|
}
|
|
|
|
// wolf: hunt | wander
|
|
pub fn wolf(c) {
|
|
if c.prey_near { "hunt" } else { "wander" }
|
|
}
|