diff --git a/agent.cc b/agent.cc index a1a401f..da51732 100644 --- a/agent.cc +++ b/agent.cc @@ -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 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(-1, 0)); spawn_herb(tile->tile_in_dir(0, -1)); - tile->on_agent_leave(*this); - tile = NULL; + die(); } else { smell_herb(tile->tile_in_dir(1, 0)); smell_herb(tile->tile_in_dir(0, 1)); diff --git a/agent.h b/agent.h index aa59e0a..f0bdfab 100644 --- a/agent.h +++ b/agent.h @@ -43,7 +43,7 @@ public: bool secrete(int id, double intensity); void chenergy(int delta); - void die(void); + virtual void die(void); void on_action_takes(void); virtual void on_tick(void); @@ -63,6 +63,7 @@ public: energy = world::herb_energy; } + void die(void); void on_tick(void); private: void smell_herb(class tile &);