Make herbs die properly on energy depletion

This commit is contained in:
Petr Baudis 2011-12-08 00:26:20 +01:00
parent 5435014c1d
commit 343762c3bb
2 changed files with 11 additions and 3 deletions

View file

@ -181,6 +181,14 @@ agent::~agent()
} }
void
herb::die(void)
{
/* No corpse, just clean up tile. */
tile->on_agent_leave(*this);
tile = NULL;
}
static void static void
spawn_herb(class tile &t) spawn_herb(class tile &t)
{ {
@ -211,8 +219,7 @@ herb::on_tick(void)
spawn_herb(tile->tile_in_dir(0, 1)); spawn_herb(tile->tile_in_dir(0, 1));
spawn_herb(tile->tile_in_dir(-1, 0)); spawn_herb(tile->tile_in_dir(-1, 0));
spawn_herb(tile->tile_in_dir(0, -1)); spawn_herb(tile->tile_in_dir(0, -1));
tile->on_agent_leave(*this); die();
tile = NULL;
} else { } else {
smell_herb(tile->tile_in_dir(1, 0)); smell_herb(tile->tile_in_dir(1, 0));
smell_herb(tile->tile_in_dir(0, 1)); smell_herb(tile->tile_in_dir(0, 1));

View file

@ -43,7 +43,7 @@ public:
bool secrete(int id, double intensity); bool secrete(int id, double intensity);
void chenergy(int delta); void chenergy(int delta);
void die(void); virtual void die(void);
void on_action_takes(void); void on_action_takes(void);
virtual void on_tick(void); virtual void on_tick(void);
@ -63,6 +63,7 @@ public:
energy = world::herb_energy; energy = world::herb_energy;
} }
void die(void);
void on_tick(void); void on_tick(void);
private: private:
void smell_herb(class tile &); void smell_herb(class tile &);