Colony Class Reference

#include <Colony.h>

Collaboration diagram for Colony:

Collaboration graph
[legend]

Public Member Functions

 Colony (unsigned int food, Replication *replication)
 Empty Constructor.
virtual ~Colony ()
 Empty Destructor.
void setReplication (Replication *r)
 Set the Replication strategy to use.
PheromonegetPheromone (unsigned int i)
 Accessor to pheromones.
unsigned int getNbWorshipers ()
 Get the number of worshipers created since the beginning.
void addCell (ColonyCell *cell)
 Add a cell.
void getCellIterators (std::list< ColonyCell * >::iterator &begin, std::list< ColonyCell * >::iterator &end)
 Get 2 iterators for iterating the ColonyCell list.
std::list< Worshiper * > * getNewWorshipers ()
 Get the list of new Worshipers to put in the World.
WorshipercreateWorshiper (unsigned int size, unsigned int food, Behaviour *b)
 Create a worshiper if possible.
void addSurvivor (Worshiper *w)
 Add a survivor.
unsigned int getFood () const
 Get the value of m_food.
void incrementFood (unsigned int inc)
 Increment the food quantity.
bool decrementFood (unsigned int dec)
 Reduce the food quantity.
unsigned int getNbCells ()
 Get the number of cells of the colony.
void setColor (GLubyte red, GLubyte green, GLubyte blue)
 Set the color.
GLubyte * getColor ()
 Get the value of m_color.
GLuint getTexName ()
 Get the value of m_tex_name.

Protected Attributes

Pheromone_pheromones
unsigned int _nb_worshipers
std::list< ColonyCell * > _cells
Replication_replicationStrategy
unsigned int _food
GLubyte * _colors
GLuint _tex_name

Detailed Description

< A colony that create Worshipers

Definition at line 40 of file Colony.h.


Constructor & Destructor Documentation

Colony::Colony ( unsigned int  food,
Replication replication 
)

Empty Constructor.

Parameters:
food initial food of the colony
replication replication strategy

Definition at line 34 of file Colony.cpp.

References _colors, _pheromones, _replicationStrategy, _tex_name, COLOR_LIMIT, COLOR_MAX, Image::genTexture1D(), GenColor::getNewColor(), Image::getPixels(), GenColor::instance(), NUMBER_PHEROMONES, Replication::setColony(), and WORSHIPER_TEXTURE_SIZE.

00034                                                            :
00035     _replicationStrategy(replication),
00036     _nb_worshipers(0),
00037     _food(food) {
00038   Image stripe(WORSHIPER_TEXTURE_SIZE, 1);
00039   GLubyte *pixels;
00040   int i;
00041 
00042   _colors = GenColor::instance()->getNewColor();
00043 
00044   // creation of the texture image for displaying worshipers
00045   pixels = stripe.getPixels();
00046   for(i = 0; i < WORSHIPER_TEXTURE_SIZE; i++) {
00047     if(i < WORSHIPER_TEXTURE_SIZE / 2) {
00048       pixels[4 * i]     = _colors[0];
00049       pixels[4 * i + 1] = _colors[1];
00050       pixels[4 * i + 2] = _colors[2];
00051       pixels[4 * i + 3] = (GLubyte) COLOR_MAX;
00052     } else {
00053       pixels[4 * i]     = _colors[0] + COLOR_LIMIT;
00054       pixels[4 * i + 1] = _colors[1] + COLOR_LIMIT;
00055       pixels[4 * i + 2] = _colors[2] + COLOR_LIMIT;
00056       pixels[4 * i + 3] = (GLubyte) COLOR_MAX;
00057     }
00058   }
00059   // generation of the texture's id
00060   _tex_name = stripe.genTexture1D();
00061 
00062   //Reciproc link with the Replication
00063   _replicationStrategy->setColony(this);
00064 
00065   //Pheromones generation
00066   _pheromones = new Pheromone[NUMBER_PHEROMONES];
00067 }

Here is the call graph for this function:


Member Function Documentation

void Colony::setReplication ( Replication r  ) 

Set the Replication strategy to use.

Parameters:
r Replication Strategy

Definition at line 84 of file Colony.cpp.

References _replicationStrategy.

00084                                            {
00085   _replicationStrategy = r;
00086 }

Pheromone * Colony::getPheromone ( unsigned int  i  ) 

Accessor to pheromones.

Parameters:
i number of the pheromone
Returns:
pointer to the pheromone, NULL if i is incorrect

Definition at line 107 of file Colony.cpp.

References _pheromones, and NUMBER_PHEROMONES.

Referenced by Behaviour::getPheromoneColony().

00107                                               {
00108   return (i < NUMBER_PHEROMONES ? &_pheromones[i] : NULL);
00109 }

Here is the caller graph for this function:

unsigned int Colony::getNbWorshipers (  ) 

Get the number of worshipers created since the beginning.

Returns:
number of worshipers created since the beginning

Definition at line 122 of file Colony.cpp.

References _nb_worshipers.

Referenced by Replication::getNbWorshipers().

00122                                      {
00123   return _nb_worshipers;
00124 }

Here is the caller graph for this function:

void Colony::addCell ( ColonyCell cell  ) 

Add a cell.

Parameters:
cell the new cell

Definition at line 126 of file Colony.cpp.

References _cells.

Referenced by ColonyCell::ColonyCell().

00126                                      {
00127   _cells.push_front(cell);
00128 }

Here is the caller graph for this function:

void Colony::getCellIterators ( std::list< ColonyCell * >::iterator &  begin,
std::list< ColonyCell * >::iterator &  end 
)

Get 2 iterators for iterating the ColonyCell list.

Parameters:
begin the iterator to the beginning of the list
end the iterator to the end of the list

Definition at line 130 of file Colony.cpp.

References _cells.

00131                                                                   {
00132   begin = _cells.begin();
00133   end = _cells.end();
00134 }

Worshiper * Colony::createWorshiper ( unsigned int  size,
unsigned int  food,
Behaviour b 
)

Create a worshiper if possible.

Parameters:
size the size of the Worshiper
food the initial food amount of the Worshiper
b the Behaviour of the Worshiper
Returns:
a new worshiper, NULL if there is not enough food

Definition at line 88 of file Colony.cpp.

References _food, and _nb_worshipers.

Referenced by Replication::createWorshiper().

00089                    {
00090 
00091   Worshiper * worshiper = NULL;
00092   int reste = _food - food;
00093 
00094   if(reste >= 0) { //There is enough food
00095     _food = reste;
00096     worshiper = new  Worshiper(b, this, size, food);
00097     _nb_worshipers++;
00098   } else if(_food > 0) { //There is not enough food, just a little we can spend
00099     worshiper = new  Worshiper(b, this, size, _food);
00100     _food = 0;
00101     _nb_worshipers++;
00102   } //else we have no food at all
00103 
00104   return worshiper;
00105 }

Here is the caller graph for this function:

void Colony::addSurvivor ( Worshiper w  ) 

Add a survivor.

Parameters:
w worshiper to add

Definition at line 111 of file Colony.cpp.

References _food, _replicationStrategy, Replication::addSurvivor(), Worshiper::destroyVisualContext(), and Worshiper::getFood().

Referenced by ColonyCell::makeActions().

00111                                      {
00112   //Add the food to the colony
00113   _food += w->getFood();
00114 
00115   //Destroy the worshiper's visual context
00116   w->destroyVisualContext();
00117 
00118   //The replication handles it
00119   _replicationStrategy->addSurvivor(w);
00120 }

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int Colony::getFood (  )  const

Get the value of m_food.

Returns:
the value of m_food

Definition at line 140 of file Colony.cpp.

References _food.

Referenced by Replication::getFood().

00140                                    {
00141     return _food;
00142   }

Here is the caller graph for this function:

void Colony::incrementFood ( unsigned int  inc  ) 

Increment the food quantity.

Parameters:
inc quantity to increment

Definition at line 144 of file Colony.cpp.

References _food.

Referenced by World::fight().

00144                                            {
00145   _food += inc;
00146 }

Here is the caller graph for this function:

bool Colony::decrementFood ( unsigned int  dec  ) 

Reduce the food quantity.

Parameters:
dec quantity to decrement
Returns:
true if m_food can be decremented, false else

Definition at line 148 of file Colony.cpp.

References _food.

00148                                            {
00149   bool res;
00150   if(_food >= dec) {
00151     _food -= dec;
00152     res = true;
00153   } else {
00154     res = false;
00155   }
00156   return res;
00157 }

unsigned int Colony::getNbCells (  ) 

Get the number of cells of the colony.

Returns:
number of cells of the colony

Definition at line 80 of file Colony.cpp.

References _cells.

Referenced by Replication::getNbCells().

00080                                 {
00081   return _cells.size();
00082 }

Here is the caller graph for this function:

void Colony::setColor ( GLubyte  red,
GLubyte  green,
GLubyte  blue 
)

Set the color.

Parameters:
red the amount of red
green the amount of green
blue the amount of blue

Definition at line 159 of file Colony.cpp.

References _colors.

00159                                                               {
00160   _colors[0] = red;
00161   _colors[1] = green;
00162   _colors[2] = blue;
00163 }

GLubyte * Colony::getColor (  ) 

Get the value of m_color.

Returns:
the value of m_color

Definition at line 165 of file Colony.cpp.

References _colors.

Referenced by ColonyCell::getColors().

00165                           {
00166   return _colors;
00167 }

Here is the caller graph for this function:

GLuint Colony::getTexName (  ) 

Get the value of m_tex_name.

Returns:
the value of m_tex_name

Definition at line 170 of file Colony.cpp.

References _tex_name.

Referenced by Worshiper::draw().

00170                           {
00171   return _tex_name;
00172 }

Here is the caller graph for this function:


Field Documentation

Pheromone* Colony::_pheromones [protected]

The pheromones

Definition at line 45 of file Colony.h.

Referenced by Colony(), getPheromone(), and ~Colony().

unsigned int Colony::_nb_worshipers [protected]

Number of worshipers created since the beginning

Definition at line 48 of file Colony.h.

Referenced by createWorshiper(), and getNbWorshipers().

std::list<ColonyCell*> Colony::_cells [protected]

Cells of the ColonyCell

Definition at line 51 of file Colony.h.

Referenced by addCell(), getCellIterators(), and getNbCells().

Replication* Colony::_replicationStrategy [protected]

Replication strategy

Definition at line 54 of file Colony.h.

Referenced by addSurvivor(), Colony(), getNewWorshipers(), setReplication(), and ~Colony().

unsigned int Colony::_food [protected]

Food

Definition at line 57 of file Colony.h.

Referenced by addSurvivor(), createWorshiper(), decrementFood(), getFood(), and incrementFood().

GLubyte* Colony::_colors [protected]

The color of the Colony

Definition at line 60 of file Colony.h.

Referenced by Colony(), getColor(), setColor(), and ~Colony().

GLuint Colony::_tex_name [protected]

The texture id used to display the Colony's worshipers

Definition at line 63 of file Colony.h.

Referenced by Colony(), and getTexName().


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