Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

agent.h

00001 /***************************************************************************
00002                         agent.h  -  description
00003                             -------------------
00004     begin                : nov 29th 2005
00005     copyright            : (C) 2005-2006 by Duong-Khang NGUYEN
00006     email                : neoneurone @ users sourceforge net
00007     author               : Victor STINNER
00008     
00009     $Id: agent.h 32 2006-08-06 18:59:25Z neoneurone $
00010  ***************************************************************************/
00011 
00012 /***************************************************************************
00013  *                                                                         *
00014  *   This program is free software; you can redistribute it and/or modify  *
00015  *   it under the terms of the GNU General Public License as published by  *
00016  *   the Free Software Foundation; either version 2 of the License, or     *
00017  *   any later version.                                                    *
00018  *                                                                         *
00019  ***************************************************************************/
00020 
00021 
00022 #ifndef _OPENCITY_AGENT_H_
00023 #define _OPENCITY_AGENT_H_ 1
00024 
00025 #define MAS_NDEBUG 1            // Debugging off
00026 
00027 #include "role.h"
00028 #include "main.h"               
00029 
00030 #ifndef MAS_NDEBUG
00031     #define MAS_DEBUG( msg ) OPENCITY_DEBUG( msg )
00032 #else
00033     #define MAS_DEBUG( msg )
00034 #endif
00035 
00036 #include <ostream>
00037 #include <list>
00038 
00039 // Forward declaration
00040 class Kernel;
00041 class Environment;
00042 class Message;
00043 
00044 typedef unsigned int AgentID_t;
00045 
00046 
00047    /*=====================================================================*/
00051 class Agent
00052 {
00053 public:
00054     typedef enum
00055     {
00056         AGENT_BORN,
00057         AGENT_LIVE,
00058         AGENT_DIE
00059     } agent_state_t;
00060 
00061     Agent(Kernel& kernel, Environment& env, int x, int y, Role_t role);
00062     virtual ~Agent();
00063 
00064     void receiveMessage(const Message& msg);
00065     void sendMessage(Role_t role, const Message& msg);
00066     void sendMessageToAgent(AgentID_t agent, const Message& msg);
00067     virtual void processMessage();
00068     
00069     virtual void born();
00070     virtual void live();
00071     virtual void die();
00072 
00073     unsigned int getX() const;
00074     unsigned int getY() const;
00075     
00076     Agent* lookForAgent(direction_t dir, unsigned long max_distance);
00077     
00078     AgentID_t getId() const;
00079     Role_t getRole() const;
00080 
00081 //========================================================================
00085     bool moveDirection();
00086     bool move(int x, int y);
00087 
00088     bool canMove(int x, int y) const;
00089     bool canMove(direction_t dir, int &x, int &y) const;
00090     bool canMove(direction_t dir) const;
00091 
00092 //========================================================================
00096     bool randomMove(int turn_percent=60);
00097 
00098     virtual void output(std::ostream& os) const;
00099     friend std::ostream& operator<<(std::ostream& os, const Agent& agent);
00100 
00101 
00102    /*=====================================================================*/
00103    /*                          OPENCITY  SPECIFIC                         */
00104    /*=====================================================================*/
00105 //========================================================================
00108     const OPENCITY_GRAPHIC_CODE
00109     GetGraphicCode() const;
00110 
00111     void
00112     SetGraphicCode( const OPENCITY_GRAPHIC_CODE gc );
00113 
00114 
00115 protected:
00116     bool doRandomMove(int turn_percent);
00117     Kernel& m_kernel;
00118     Environment& m_environment;
00119     int m_x, m_y;
00120     direction_t m_direction;
00121     unsigned int m_move_speed;
00122     Role_t m_role;
00123     agent_state_t m_agent_state;
00124     std::list<Message> m_messages;
00125 
00126    /*=====================================================================*/
00127    /*                          OPENCITY  SPECIFIC                         */
00128    /*=====================================================================*/
00129     OPENCITY_GRAPHIC_CODE m_enumGC;     
00130 
00131 private:
00132     AgentID_t m_id;
00133 };
00134 #endif
00135 
00136 
00137 
00138 
00139 
00140 
00141 
00142 
00143 
00144 
00145 
00146 
00147 
00148 
00149 
00150 
00151 
00152 
00153 
00154 
00155 
00156 
00157 
00158 
00159 
00160 
00161 
00162 
00163 
00164 
00165 
00166 
00167 

Generated on Sat Nov 11 10:21:09 2006 for OpenCity by  doxygen 1.4.2