| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#ifndef _OPENCITY_AGENT_H_ |
| 23 |
#define _OPENCITY_AGENT_H_ 1 |
| 24 |
|
| 25 |
#define MAS_NDEBUG 1 // Debugging off |
| 26 |
|
| 27 |
#include "role.h" |
| 28 |
#include "main.h" |
| 29 |
|
| 30 |
#ifndef MAS_NDEBUG |
| 31 |
#define MAS_DEBUG( msg ) OPENCITY_DEBUG( msg ) |
| 32 |
#else |
| 33 |
#define MAS_DEBUG( msg ) |
| 34 |
#endif |
| 35 |
|
| 36 |
#include <ostream> |
| 37 |
#include <list> |
| 38 |
|
| 39 |
|
| 40 |
class Kernel; |
| 41 |
class Environment; |
| 42 |
class Message; |
| 43 |
|
| 44 |
typedef unsigned int AgentID_t; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
class Agent |
| 52 |
{ |
| 53 |
public: |
| 54 |
typedef enum |
| 55 |
{ |
| 56 |
AGENT_BORN, |
| 57 |
AGENT_LIVE, |
| 58 |
AGENT_DIE |
| 59 |
} agent_state_t; |
| 60 |
|
| 61 |
Agent(Kernel& kernel, Environment& env, int x, int y, MAS_ROLE role); |
| 62 |
virtual ~Agent(); |
| 63 |
|
| 64 |
void receiveMessage(const Message& msg); |
| 65 |
void sendMessage(MAS_ROLE role, const Message& msg); |
| 66 |
void sendMessageToAgent(AgentID_t agent, const Message& msg); |
| 67 |
virtual void processMessage(); |
| 68 |
|
| 69 |
virtual void born(); |
| 70 |
virtual void live(); |
| 71 |
virtual void die(); |
| 72 |
|
| 73 |
unsigned int getX() const; |
| 74 |
unsigned int getY() const; |
| 75 |
|
| 76 |
Agent* lookForAgent(MAS_DIRECTION dir, unsigned long max_distance); |
| 77 |
|
| 78 |
AgentID_t getId() const; |
| 79 |
MAS_ROLE getRole() const; |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
bool moveDirection(); |
| 86 |
bool move(int x, int y); |
| 87 |
|
| 88 |
bool canMove(int x, int y) const; |
| 89 |
bool canMove(MAS_DIRECTION dir, int &x, int &y) const; |
| 90 |
bool canMove(MAS_DIRECTION dir) const; |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
bool randomMove(int turn_percent=60); |
| 97 |
|
| 98 |
virtual void output(std::ostream& os) const; |
| 99 |
friend std::ostream& operator<<(std::ostream& os, const Agent& agent); |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
const OPENCITY_GRAPHIC_CODE |
| 109 |
GetGraphicCode() const; |
| 110 |
|
| 111 |
void |
| 112 |
SetGraphicCode( const OPENCITY_GRAPHIC_CODE gc ); |
| 113 |
|
| 114 |
|
| 115 |
protected: |
| 116 |
bool doRandomMove(int turn_percent); |
| 117 |
Kernel& m_kernel; |
| 118 |
Environment& m_environment; |
| 119 |
int m_x, m_y; |
| 120 |
MAS_DIRECTION m_direction; |
| 121 |
unsigned int m_move_speed; |
| 122 |
MAS_ROLE m_role; |
| 123 |
agent_state_t m_agent_state; |
| 124 |
std::list<Message> m_messages; |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
OPENCITY_GRAPHIC_CODE m_enumGC; |
| 130 |
|
| 131 |
private: |
| 132 |
AgentID_t m_id; |
| 133 |
}; |
| 134 |
#endif |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|