mirror of
https://github.com/brmlab/brmlife.git
synced 2025-08-02 18:03:37 +02:00
Evolve herbs dynamically based on energy
This commit is contained in:
parent
4d697adc83
commit
0e1243f86f
7 changed files with 83 additions and 19 deletions
28
agent.cc
28
agent.cc
|
@ -143,4 +143,30 @@ agent::~agent()
|
|||
conn->cancel();
|
||||
conn = NULL;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
spawn_herb(class tile &t)
|
||||
{
|
||||
if (t.agent)
|
||||
return;
|
||||
class herb *h = new class herb(agent_id++, t.map);
|
||||
agents.push_back(h);
|
||||
h->spawn_at(t);
|
||||
}
|
||||
|
||||
void
|
||||
herb::on_tick(void)
|
||||
{
|
||||
agent::on_tick();
|
||||
|
||||
assert(tile);
|
||||
if (energy > 4 * world::herb_energy) {
|
||||
spawn_herb(tile->tile_in_dir(1, 0));
|
||||
spawn_herb(tile->tile_in_dir(0, 1));
|
||||
spawn_herb(tile->tile_in_dir(-1, 0));
|
||||
spawn_herb(tile->tile_in_dir(0, -1));
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue