Spawn some herbs at startup

This commit is contained in:
Petr Baudis 2011-11-27 05:26:44 +01:00
parent b80ccfdffd
commit 4d697adc83
4 changed files with 27 additions and 0 deletions

12
agent.h
View file

@ -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

View file

@ -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<class agent *> 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) {

2
map.cc
View file

@ -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();

View file

@ -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