mirror of
https://github.com/brmlab/brmlife.git
synced 2025-08-02 18:03:37 +02:00
agent::spawn(): Introduce
This commit is contained in:
parent
7714906baa
commit
812e0da79b
3 changed files with 12 additions and 4 deletions
6
agent.cc
6
agent.cc
|
@ -7,6 +7,12 @@
|
|||
#include "main.h"
|
||||
#include "map.h"
|
||||
|
||||
void
|
||||
agent::spawn(void)
|
||||
{
|
||||
spawn_at(map.agent_startpos());
|
||||
}
|
||||
|
||||
void
|
||||
agent::spawn_at(class tile &t)
|
||||
{
|
||||
|
|
6
agent.h
6
agent.h
|
@ -11,17 +11,19 @@ public:
|
|||
int id;
|
||||
class connection *conn;
|
||||
|
||||
class map ↦
|
||||
class tile *tile;
|
||||
|
||||
int energy;
|
||||
bool dead;
|
||||
|
||||
agent(int id_, class connection *conn_)
|
||||
: id (id_), conn (conn_)
|
||||
agent(int id_, class connection *conn_, class map &map_)
|
||||
: id (id_), conn (conn_), map (map_)
|
||||
{
|
||||
energy = world::newborn_energy;
|
||||
dead = false;
|
||||
};
|
||||
void spawn(void);
|
||||
void spawn_at(class tile &tile);
|
||||
|
||||
bool move_dir(int dir_x, int dir_y);
|
||||
|
|
4
main.cc
4
main.cc
|
@ -67,9 +67,9 @@ next_agent:
|
|||
int cfd = accept(lfd, NULL, NULL);
|
||||
if (cfd >= 0) {
|
||||
class connection *conn = new class connection(cfd);
|
||||
class agent *a = new class agent(aid++, conn);
|
||||
class agent *a = new class agent(aid++, conn, map);
|
||||
agents.push_back(a);
|
||||
a->spawn_at(map.agent_startpos());
|
||||
a->spawn();
|
||||
}
|
||||
|
||||
/* Collect and take actions. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue