mirror of
https://github.com/brmlab/brmlife.git
synced 2025-08-02 09:53:38 +02:00
agent::chenergy(): Implement
This commit is contained in:
parent
d120fcc938
commit
0398856635
3 changed files with 13 additions and 6 deletions
16
agent.cc
16
agent.cc
|
@ -22,7 +22,7 @@ agent::move_dir(int dir_x, int dir_y)
|
|||
if (dead)
|
||||
return false;
|
||||
|
||||
energy -= world::move_cost;
|
||||
chenergy(world::move_cost);
|
||||
|
||||
class tile *t2 = &tile->tile_in_dir(dir_x, dir_y);
|
||||
if (t2->agent) {
|
||||
|
@ -30,7 +30,7 @@ agent::move_dir(int dir_x, int dir_y)
|
|||
class agent *a = t2->agent;
|
||||
t2->on_agent_leave(*a);
|
||||
/* Nom. */
|
||||
energy += a->energy;
|
||||
chenergy(a->energy);
|
||||
a->energy = 0;
|
||||
} else {
|
||||
return false;
|
||||
|
@ -45,6 +45,14 @@ agent::move_dir(int dir_x, int dir_y)
|
|||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
agent::chenergy(int delta)
|
||||
{
|
||||
energy += delta;
|
||||
if (energy <= 0)
|
||||
die();
|
||||
}
|
||||
|
||||
void
|
||||
agent::die(void)
|
||||
{
|
||||
|
@ -66,9 +74,7 @@ void
|
|||
agent::on_tick(void)
|
||||
{
|
||||
if (!dead) {
|
||||
energy += world::sun_energy;
|
||||
if (energy <= 0)
|
||||
die();
|
||||
chenergy(world::sun_energy);
|
||||
|
||||
} else {
|
||||
energy += world::dead_decay;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue