mirror of
https://github.com/brmlab/brmlife.git
synced 2025-08-03 02:13:35 +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)
|
if (dead)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
energy -= world::move_cost;
|
chenergy(world::move_cost);
|
||||||
|
|
||||||
class tile *t2 = &tile->tile_in_dir(dir_x, dir_y);
|
class tile *t2 = &tile->tile_in_dir(dir_x, dir_y);
|
||||||
if (t2->agent) {
|
if (t2->agent) {
|
||||||
|
@ -30,7 +30,7 @@ agent::move_dir(int dir_x, int dir_y)
|
||||||
class agent *a = t2->agent;
|
class agent *a = t2->agent;
|
||||||
t2->on_agent_leave(*a);
|
t2->on_agent_leave(*a);
|
||||||
/* Nom. */
|
/* Nom. */
|
||||||
energy += a->energy;
|
chenergy(a->energy);
|
||||||
a->energy = 0;
|
a->energy = 0;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -45,6 +45,14 @@ agent::move_dir(int dir_x, int dir_y)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
agent::chenergy(int delta)
|
||||||
|
{
|
||||||
|
energy += delta;
|
||||||
|
if (energy <= 0)
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
agent::die(void)
|
agent::die(void)
|
||||||
{
|
{
|
||||||
|
@ -66,9 +74,7 @@ void
|
||||||
agent::on_tick(void)
|
agent::on_tick(void)
|
||||||
{
|
{
|
||||||
if (!dead) {
|
if (!dead) {
|
||||||
energy += world::sun_energy;
|
chenergy(world::sun_energy);
|
||||||
if (energy <= 0)
|
|
||||||
die();
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
energy += world::dead_decay;
|
energy += world::dead_decay;
|
||||||
|
|
1
agent.h
1
agent.h
|
@ -26,6 +26,7 @@ public:
|
||||||
|
|
||||||
bool move_dir(int dir_x, int dir_y);
|
bool move_dir(int dir_x, int dir_y);
|
||||||
|
|
||||||
|
void chenergy(int delta);
|
||||||
void die(void);
|
void die(void);
|
||||||
|
|
||||||
void on_action_takes(void);
|
void on_action_takes(void);
|
||||||
|
|
2
world.h
2
world.h
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
struct world {
|
struct world {
|
||||||
const static int newborn_energy = 500;
|
const static int newborn_energy = 500;
|
||||||
const static int move_cost = 10;
|
const static int move_cost = -10;
|
||||||
const static int sun_energy = 1;
|
const static int sun_energy = 1;
|
||||||
|
|
||||||
const static int dead_body_energy = 500;
|
const static int dead_body_energy = 500;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue