mirror of
https://github.com/brmlab/brmlife.git
synced 2025-08-03 02:13:35 +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 "main.h"
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
|
|
||||||
|
void
|
||||||
|
agent::spawn(void)
|
||||||
|
{
|
||||||
|
spawn_at(map.agent_startpos());
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
agent::spawn_at(class tile &t)
|
agent::spawn_at(class tile &t)
|
||||||
{
|
{
|
||||||
|
|
6
agent.h
6
agent.h
|
@ -11,17 +11,19 @@ public:
|
||||||
int id;
|
int id;
|
||||||
class connection *conn;
|
class connection *conn;
|
||||||
|
|
||||||
|
class map ↦
|
||||||
class tile *tile;
|
class tile *tile;
|
||||||
|
|
||||||
int energy;
|
int energy;
|
||||||
bool dead;
|
bool dead;
|
||||||
|
|
||||||
agent(int id_, class connection *conn_)
|
agent(int id_, class connection *conn_, class map &map_)
|
||||||
: id (id_), conn (conn_)
|
: id (id_), conn (conn_), map (map_)
|
||||||
{
|
{
|
||||||
energy = world::newborn_energy;
|
energy = world::newborn_energy;
|
||||||
dead = false;
|
dead = false;
|
||||||
};
|
};
|
||||||
|
void spawn(void);
|
||||||
void spawn_at(class tile &tile);
|
void spawn_at(class tile &tile);
|
||||||
|
|
||||||
bool move_dir(int dir_x, int dir_y);
|
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);
|
int cfd = accept(lfd, NULL, NULL);
|
||||||
if (cfd >= 0) {
|
if (cfd >= 0) {
|
||||||
class connection *conn = new class connection(cfd);
|
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);
|
agents.push_back(a);
|
||||||
a->spawn_at(map.agent_startpos());
|
a->spawn();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Collect and take actions. */
|
/* Collect and take actions. */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue