From 343762c3bb1c2bf526e3eec7e49d4c2808bfc604 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Thu, 8 Dec 2011 00:26:20 +0100 Subject: [PATCH] Make herbs die properly on energy depletion --- agent.cc | 11 +++++++++-- agent.h | 3 ++- 2 files changed, 11 insertions(+), 3 deletions(-) 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 &);