ReachableCell Class Reference

#include <ReachableCell.h>

Inheritance diagram for ReachableCell:

Inheritance graph
[legend]
Collaboration diagram for ReachableCell:

Collaboration graph
[legend]

Public Member Functions

virtual ~ReachableCell ()
 Empty Destructor.
virtual void draw ()
 Draw the cell content with OpenGL.
virtual bool reachable (Worshiper *w)
 Is the Cell reachable ?
virtual std::list< Worshiper * > * getPeople ()
 Return the list of the Worshipers currently on the Cell.
virtual std::map< Pheromone *,
unsigned int > * 
getPheromones ()
 Return the map of Pheromones currently on the Cell, associated to their life-time.
virtual bool addWorshiper (Worshiper *w)
 Add a Worshiper to the Cell.
virtual bool removeWorshiper (const Worshiper *w)
 Remove a Worshiper to the Cell.
virtual void addPheromone (Pheromone *p)
 Add a Pheromone to the Cell.
virtual void push (ReachableCell *next)
 Push that Cell upon an other.
virtual ReachableCellpop ()
 Pop that Cell and restore the previous one.
virtual CellmakeActions ()
 Make the actions needed by the Cell for one iteration.

Protected Member Functions

 ReachableCell ()
 Constructor.

Protected Attributes

std::list< Worshiper * > * _people
std::map< Pheromone *,
unsigned int > * 
_pheromones
ReachableCell_next

Detailed Description

< A Cell that can be accessed

Definition at line 39 of file ReachableCell.h.


Member Function Documentation

bool ReachableCell::reachable ( Worshiper w  )  [virtual]

Is the Cell reachable ?

Parameters:
w the Worshiper that try to access to the Cell
Returns:
true if the Worshiper can access to the Cell, false otherwise

Reimplemented from Cell.

Reimplemented in ColonyCell, and CorridorCell.

Definition at line 68 of file ReachableCell.cpp.

References _next, _people, MAX_WORSHIPER_PER_CELL, and reachable().

Referenced by addWorshiper(), reachable(), and CorridorCell::reachable().

00068                                           {
00069   return (_people->size() < MAX_WORSHIPER_PER_CELL) &&
00070     (_next != NULL ? _next->reachable(w) : true);
00071 }

Here is the call graph for this function:

Here is the caller graph for this function:

std::list< Worshiper * > * ReachableCell::getPeople (  )  [virtual]

Return the list of the Worshipers currently on the Cell.

Returns:
the list of the Worshipers

Reimplemented from Cell.

Definition at line 73 of file ReachableCell.cpp.

References _people.

Referenced by ColonyCell::makeActions().

00073                                               {
00074   return _people;
00075 }

Here is the caller graph for this function:

std::map< Pheromone *, unsigned int > * ReachableCell::getPheromones (  )  [virtual]

Return the map of Pheromones currently on the Cell, associated to their life-time.

Returns:
the map of Pheromones

Reimplemented from Cell.

Definition at line 77 of file ReachableCell.cpp.

References _pheromones.

00077                                                                {
00078   return _pheromones;
00079 }

bool ReachableCell::addWorshiper ( Worshiper w  )  [virtual]

Add a Worshiper to the Cell.

Parameters:
w the Worshiper to add
Returns:
true if the Worshiper have been correctly added, false otherwise

Reimplemented from Cell.

Definition at line 81 of file ReachableCell.cpp.

References _people, and reachable().

00081                                              {
00082   bool ok = reachable(w);
00083 
00084   if(ok) {
00085     _people->push_back(w);
00086   }
00087 
00088   return ok;
00089 }

Here is the call graph for this function:

bool ReachableCell::removeWorshiper ( const Worshiper w  )  [virtual]

Remove a Worshiper to the Cell.

Parameters:
w the Worshiper to remove
Returns:
true if the Worshiper have been correctly removed, false otherwise

Reimplemented from Cell.

Definition at line 91 of file ReachableCell.cpp.

References _people.

Referenced by ColonyCell::makeActions().

00091                                                       {
00092   std::list<Worshiper *>::iterator it, end = _people->end();
00093   bool find = false;
00094 
00095   for(it = _people->begin(); !find && it != end; ++it) {
00096     if(find = ((*it) == w)) {
00097       _people->erase(it);
00098     }
00099   }
00100 
00101   return find;
00102 }

Here is the caller graph for this function:

void ReachableCell::addPheromone ( Pheromone p  )  [virtual]

Add a Pheromone to the Cell.

Parameters:
p the Pheromone to add
Returns:
true if the Pheromone have been correctly added, false otherwise

Reimplemented from Cell.

Definition at line 104 of file ReachableCell.cpp.

References PHEROMONE_LIFE_TIME.

00104                                              {
00105   (*_pheromones)[p] = PHEROMONE_LIFE_TIME;
00106 }

void ReachableCell::push ( ReachableCell next  )  [virtual]

Push that Cell upon an other.

Parameters:
next the Cell we want to cover

Definition at line 108 of file ReachableCell.cpp.

References _next, _people, and _pheromones.

Referenced by World::addGodsGift(), and World::fight().

00108                                             {
00109   _next = next;
00110   _people = _next->_people;
00111   _pheromones = _next->_pheromones;
00112 }

Here is the caller graph for this function:

ReachableCell * ReachableCell::pop (  )  [virtual]

Pop that Cell and restore the previous one.

Returns:
a pointer to the old Cell which should replace this one

Definition at line 114 of file ReachableCell.cpp.

References _next, _people, and _pheromones.

Referenced by GodsGiftFood::makeActions(), and CorpseFood::makeActions().

00114                                   {
00115   ReachableCell *next = NULL;
00116 
00117   if(_next != NULL) {
00118     // petite astuce : pour éviter que le destructeur de cette Cell détruise
00119     // la Cell en dessous ainsi que les pointeurs qu'elle partage avec elle,
00120     // on les positionnent à NULL
00121     _people = NULL;
00122     _pheromones = NULL;
00123     next = _next;
00124     _next = NULL;
00125   }
00126   // puis on s'auto-détruit
00127   delete this;
00128 
00129   // et on retourne la Cell qui était précédement en dessous
00130   return next;
00131 }

Here is the caller graph for this function:

Cell * ReachableCell::makeActions (  )  [virtual]

Make the actions needed by the Cell for one iteration.

Returns:
a pointer to the new Cell which should replace this one

Reimplemented from Cell.

Reimplemented in ColonyCell, CorpseFood, FoodCell, and GodsGiftFood.

Definition at line 133 of file ReachableCell.cpp.

References _pheromones.

Referenced by FoodCell::makeActions(), and ColonyCell::makeActions().

00133                                  {
00134   std::map<Pheromone*, unsigned int>::iterator it, end;
00135 
00136   // on met à jour les phéromones en fonction de leur durée de vie
00137   end = _pheromones->end();
00138   for(it = _pheromones->begin(); it != end; ++it) {
00139     if(it->second <= 1) {
00140       // on supprime la phéromone
00141       _pheromones->erase(it);
00142     } else {
00143       // sinon on la décrémente
00144       it->second--;
00145     }
00146   }
00147 
00148   return this;
00149 }

Here is the caller graph for this function:


Field Documentation

std::list<Worshiper *>* ReachableCell::_people [protected]

The Worshipers on the Cell

Definition at line 44 of file ReachableCell.h.

Referenced by addWorshiper(), draw(), getPeople(), pop(), push(), reachable(), ReachableCell(), removeWorshiper(), and ~ReachableCell().

std::map<Pheromone*, unsigned int>* ReachableCell::_pheromones [protected]

The Pheromones on the Cell

Definition at line 47 of file ReachableCell.h.

Referenced by getPheromones(), makeActions(), pop(), push(), ReachableCell(), and ~ReachableCell().

ReachableCell* ReachableCell::_next [protected]

The Cell under the current one

Definition at line 50 of file ReachableCell.h.

Referenced by pop(), push(), and reachable().


The documentation for this class was generated from the following files:
Generated on Sat Feb 2 22:23:18 2008 for Teapot Colony Wars by  doxygen 1.5.4