From 4d697adc837fd7fdc4e27d0b13a95d9c18215fde Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Sun, 27 Nov 2011 05:26:44 +0100 Subject: [PATCH] Spawn some herbs at startup --- agent.h | 12 ++++++++++++ main.cc | 9 +++++++++ map.cc | 2 ++ world.h | 4 ++++ 4 files changed, 27 insertions(+) diff --git a/agent.h b/agent.h index d974402..d080b44 100644 --- a/agent.h +++ b/agent.h @@ -48,4 +48,16 @@ public: ~agent(); }; +class herb : public agent { +public: + herb(int id_, class map &map_) + : agent(id_, NULL, map_) + { + energy = world::herb_energy; + attr.move = 0; + attr.attack = 0; + attr.defense = 0; + } +}; + #endif diff --git a/main.cc b/main.cc index 3e8594e..f157c8c 100644 --- a/main.cc +++ b/main.cc @@ -23,6 +23,7 @@ int main(int argc, char *argv[]) { class map map(argc < 2 ? 40 : atoi(argv[1]), argc < 3 ? 20 : atoi(argv[2])); + int herbs = argc < 4 ? map.w * map.h / world::herb_rate : atoi(argv[3]); srandom(time(NULL)); @@ -44,6 +45,14 @@ main(int argc, char *argv[]) std::list agents; int aid = 0; + /* Spawn herbs. */ + + for (int i = 0; i < herbs; i++) { + class agent *a = new class herb(aid++, map); + agents.push_back(a); + a->spawn(); + } + /* Main tick loop. */ while (true) { diff --git a/map.cc b/map.cc index 7985d93..0a9c392 100644 --- a/map.cc +++ b/map.cc @@ -32,6 +32,8 @@ tile::symbol(void) if (agent) { if (agent->dead) return 'a'; + if (agent->attr.move < 0.01) + return 'x'; return '0' + (agent->id % 10); } return type_symbol(); diff --git a/world.h b/world.h index dff7ccd..daf8419 100644 --- a/world.h +++ b/world.h @@ -3,6 +3,8 @@ struct world { const static int newborn_energy = 5000; + const static int herb_energy = 1500; + const static int move_cost = -50; const static int attack_cost = -400; const static int defense_cost = -200; @@ -15,6 +17,8 @@ struct world { const static int dead_body_energy = 2000; const static double dead_body_energy_carryover = 0.5; const static int dead_decay = -10; + + const static int herb_rate = 20; /* one herb per herb_rate tiles */ }; #endif