From 04a475efbed5ad4b3e7cf12d3c5cda359a56de62 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Sat, 3 Dec 2011 15:47:00 +0100 Subject: [PATCH] world::max_energy: Implement upper limit for agent's energy --- agent.cc | 2 ++ world.h | 1 + 2 files changed, 3 insertions(+) diff --git a/agent.cc b/agent.cc index 054db38..0677865 100644 --- a/agent.cc +++ b/agent.cc @@ -94,6 +94,8 @@ void agent::chenergy(int delta) { energy += delta; + if (energy > world::max_energy) + energy = world::max_energy; if (energy <= 0) die(); } diff --git a/world.h b/world.h index 4381044..47a3b81 100644 --- a/world.h +++ b/world.h @@ -4,6 +4,7 @@ struct world { const static int newborn_energy = 5000; const static int herb_energy = 1000; + const static int max_energy = 20000; const static int move_cost = -50; const static int attack_cost = -400;