Support for breeding

One party initiates the breeding; the other party exerts most of the
energy if its breeding key matches. It is that party's responsibility to
set up the newborn agent's connection (but the father can pass it an
arbitrary message). Newborn is spawned immediately but can be
renegotiated on first connect.
This commit is contained in:
Petr Baudis 2011-12-08 03:14:57 +01:00
parent b693b5d6f4
commit 23f2fce7ff
6 changed files with 100 additions and 9 deletions

17
agent.h
View file

@ -1,6 +1,8 @@
#ifndef BRMLIFE__AGENT_H
#define BRMLIFE__AGENT_H
#include <string>
#include "map.h"
#include "pheromone.h"
#include "world.h"
@ -12,12 +14,12 @@ class connection;
*
* - tile set, connection set: active client or connected corpse
* - tile set, connection NULL: herb or disconnected corpse
* - tile NULL, connection set: negotiation or zombie connection with no corpse anymore
* - tile NULL, connection set: negotiating client or zombie connection with no corpse anymore
*
* Agents are created (we may not keep this list up to date) on incoming
* connection, by blooming herb or when converting corpse to herb. Herbs
* are immediately spawned (assigned a tile); clients are spawned only
* after negotiation.
* connection, by breeding, by blooming herb or when converting corpse
* to herb. Herbs and bred clients are immediately spawned (assigned a tile);
* connecting clients are spawned only after negotiation.
*
* Agents are destroyed in the main loop when they are completely abandoned,
* i.e. both their tile and connection become NULL. */
@ -34,19 +36,21 @@ public:
double move;
double attack;
double defense;
long breeding_key;
} attr;
int energy;
bool dead;
bool newborn, dead;
class pheromones pheromones;
agent(int id_, class connection *conn_, class map &map_)
: id (id_), conn (conn_), map (map_), tile (NULL)
: id (id_), conn (conn_), map (map_), tile (NULL), newborn (true)
{
attr.move = 1.0;
attr.attack = 0.5;
attr.defense = 0.5;
attr.breeding_key = 0;
energy = world::newborn_energy;
dead = false;
};
@ -55,6 +59,7 @@ public:
bool move_dir(int dir_x, int dir_y);
bool attack_dir(int dir_x, int dir_y);
bool breed_dir(int dir_x, int dir_y, std::string info);
bool secrete(int id, double intensity);
void chenergy(int delta);