Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

agent.h

Go to the documentation of this file.
00001 /*
00002   svas_server -- virtual World Server of Svas
00003   Copyright (c) 2001, 2002 David Moreno Montero
00004  
00005  
00006   This program is free software; you can redistribute it and/or modify
00007   it under the terms of the GNU General Public License as published by
00008   the Free Software Foundation; either version 2 of the License, or
00009   (at your option) any later version.
00010  
00011   This program is distributed in the hope that it will be useful, but
00012   WITHOUT ANY WARRANTY; without even the implied warranty of
00013   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014   General Public License for more details.
00015  
00016   You should have received a copy of the GNU General Public License
00017   along with this program; if not, write to the Free Software
00018   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00019   02111-1307, USA.  
00020 
00021 */
00022 
00023 #ifndef __AGENT_H__
00024 #define __AGENT_H__
00025 
00026 #include <thread.h>
00027 #include "cylinder.h"
00028 #include "vector3d.h"
00029 #include <vector>
00030 #include "boundingbox.h"
00031 
00032 class Client;
00033 class World;
00034 
00035 /**
00036  * The agents are the organisms of this world. They are composed of
00037  * cylinders; It have a maximum of 256 cylinders (as array for speed).
00038  * One cylinder is created at constructor time.
00039  */
00040 class Agent{
00041  protected:
00042   /** Max id reached by agents. Each new agent need to have a brand
00043    * new id */ 
00044   static unsigned long int agentMaxId;
00045   /// The id of the actual agent 
00046   unsigned long int id;
00047 
00048   /** The parent cylinder in the agent, all the rest cylinder hangs from it */
00049   Cylinder *cylinder;
00050   /** The client to which the agent belongs */
00051   Client *client;
00052   /** 
00053    * The count of cylinders, if a new cylinder is created in this
00054    * agent this number increases, and the old number is returned.
00055    */
00056   short int cylinderCount;
00057  public:
00058   /// Creates an empty agent. The Client pointer is the agent owner
00059   Agent(Client *, const Point3d &position, const char *creationMessage, unsigned long int messageSize);
00060   /// Creates an agent based on a cylinder and it's old-agent properties
00061   Agent(Client *, Cylinder *, const char *creationMessage, unsigned long int messageSize);
00062   /// Destroy the client
00063   ~Agent();
00064 
00065   /**
00066    * @name some gets
00067    * some properties that can be consulted 
00068    * @{
00069    */
00070   unsigned long int getId(void){ return id; };
00071   Client *getClient(){ return client; };
00072   /// Returns (and maybe generate) a new cylinder id
00073   short int getCylinderCount(bool increment=false){ if (increment){ cylinderCount++;  return cylinderCount-1; } return cylinderCount; };
00074   inline short int getNumCylinders(void){ return cylinder->getNumCylinders(); }
00075   /// Get the specified cylinder. By number (see numCylinders())
00076   Cylinder *operator()(unsigned short int i){ return (*cylinder)(i); };
00077   /// Get specified cylinder by id
00078   Cylinder *operator[](unsigned short int i){ return (*cylinder)[i]; };
00079   World *getWorld();
00080   /** @}  */
00081 
00082   /// Receives a message from another agent
00083   void receiveMessage(unsigned long int _agentId, const char *message, unsigned long int size);
00084 
00085   /// Checks if the agent is in the bounding box
00086   inline bool into(BoundingBox &bbox){ return bbox.contains(cylinder->getPosition()); };
00087 
00088   /// Performs desired intentions, as each cylinder can have only one.
00089   vector<Cylinder *> performActions();
00090 };
00091 
00092 #endif

Generated on Mon Jun 17 19:53:43 2002 for Svas Server by doxygen1.2.16