#include <Colony.h>
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. | |
Pheromone * | getPheromone (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. | |
Worshiper * | createWorshiper (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 |
Definition at line 40 of file Colony.h.
Colony::Colony | ( | unsigned int | food, | |
Replication * | replication | |||
) |
Empty Constructor.
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 }
void Colony::setReplication | ( | Replication * | r | ) |
Set the Replication strategy to use.
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.
i | number of the pheromone |
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 }
unsigned int Colony::getNbWorshipers | ( | ) |
Get the 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 }
void Colony::addCell | ( | ColonyCell * | cell | ) |
Add a cell.
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 }
void Colony::getCellIterators | ( | std::list< ColonyCell * >::iterator & | begin, | |
std::list< ColonyCell * >::iterator & | end | |||
) |
Get 2 iterators for iterating the ColonyCell list.
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.
Create a worshiper if possible.
size | the size of the Worshiper | |
food | the initial food amount of the Worshiper | |
b | the Behaviour of the Worshiper |
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 }
void Colony::addSurvivor | ( | Worshiper * | w | ) |
Add a survivor.
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 }
unsigned int Colony::getFood | ( | ) | const |
Get the value of m_food.
Definition at line 140 of file Colony.cpp.
References _food.
Referenced by Replication::getFood().
00140 { 00141 return _food; 00142 }
void Colony::incrementFood | ( | unsigned int | inc | ) |
Increment the food quantity.
inc | quantity to increment |
Definition at line 144 of file Colony.cpp.
References _food.
Referenced by World::fight().
00144 { 00145 _food += inc; 00146 }
bool Colony::decrementFood | ( | unsigned int | dec | ) |
Reduce the food quantity.
dec | quantity to decrement |
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.
Definition at line 80 of file Colony.cpp.
References _cells.
Referenced by Replication::getNbCells().
00080 { 00081 return _cells.size(); 00082 }
void Colony::setColor | ( | GLubyte | red, | |
GLubyte | green, | |||
GLubyte | blue | |||
) |
GLubyte * Colony::getColor | ( | ) |
Get the value of m_color.
Definition at line 165 of file Colony.cpp.
References _colors.
Referenced by ColonyCell::getColors().
00165 { 00166 return _colors; 00167 }
GLuint Colony::getTexName | ( | ) |
Get 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 }
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().