#include <FoodCell.h>
Public Member Functions | |
virtual | ~FoodCell () |
Empty Destructor. | |
unsigned int | getMax () |
Get the value of _max. | |
unsigned int | getInc () |
Get the value of _inc. | |
virtual unsigned int | getFood () |
Get the amount of food the Cell contains. | |
virtual unsigned int | addFood (unsigned int inc) |
Add some food on the Cell. | |
virtual unsigned int | subFood (unsigned int inc) |
Substract some food on the Cell. | |
virtual Cell * | makeActions () |
Make the actions needed by the Cell for one iteration. | |
Protected Member Functions | |
FoodCell (unsigned int max, unsigned int inc, unsigned int value) | |
Constructor of FoodCell. | |
Protected Attributes | |
unsigned int | _max |
unsigned int | _inc |
unsigned int | _value |
Definition at line 33 of file FoodCell.h.
FoodCell::FoodCell | ( | unsigned int | max, | |
unsigned int | inc, | |||
unsigned int | value | |||
) | [protected] |
Constructor of FoodCell.
max | the max value of food the Cell can contain | |
inc | the regeneration rate of the food | |
value | the amount of the food currently on the Cell |
Definition at line 27 of file FoodCell.cpp.
00027 : 00028 ReachableCell(), _max(max), _inc(inc), _value(value) { 00029 00030 }
unsigned int FoodCell::getMax | ( | ) |
Get the value of _max.
Definition at line 36 of file FoodCell.cpp.
References _max.
00036 { 00037 return _max; 00038 }
unsigned int FoodCell::getInc | ( | ) |
Get the value of _inc.
Definition at line 40 of file FoodCell.cpp.
References _inc.
00040 { 00041 return _inc; 00042 }
unsigned int FoodCell::getFood | ( | ) | [virtual] |
Get the amount of food the Cell contains.
Reimplemented from Cell.
Definition at line 44 of file FoodCell.cpp.
References _value.
Referenced by GodsGiftFood::makeActions(), and CorpseFood::makeActions().
00044 { 00045 return _value; 00046 }
unsigned int FoodCell::addFood | ( | unsigned int | inc | ) | [virtual] |
Add some food on the Cell.
inc | the food to add on the Cell |
Reimplemented from Cell.
Definition at line 48 of file FoodCell.cpp.
00048 { 00049 unsigned int res = inc; 00050 00051 if(_value + inc > _max) { 00052 res = _max - _value; 00053 _value = _max; 00054 } else { 00055 _value = _value + inc; 00056 } 00057 00058 return res; 00059 }
unsigned int FoodCell::subFood | ( | unsigned int | inc | ) | [virtual] |
Substract some food on the Cell.
inc | the food to remove of the Cell |
Reimplemented from Cell.
Definition at line 61 of file FoodCell.cpp.
References _value.
00061 { 00062 int res = inc; 00063 00064 if((signed int) (_value - inc) < 0) { 00065 res = _value; 00066 _value = 0; 00067 } else { 00068 _value = _value - inc; 00069 } 00070 00071 return res; 00072 }
Cell * FoodCell::makeActions | ( | ) | [virtual] |
Make the actions needed by the Cell for one iteration.
Reimplemented from ReachableCell.
Reimplemented in CorpseFood, and GodsGiftFood.
Definition at line 74 of file FoodCell.cpp.
References _inc, _max, _value, and ReachableCell::makeActions().
Referenced by GodsGiftFood::makeActions(), and CorpseFood::makeActions().
00074 { 00075 ReachableCell::makeActions(); 00076 00077 _value += _inc; 00078 _value = (_value > _max ? _max : _value); 00079 00080 return this; 00081 }
unsigned int FoodCell::_max [protected] |
the max value of food the Cell can contain
Definition at line 38 of file FoodCell.h.
Referenced by addFood(), getMax(), and makeActions().
unsigned int FoodCell::_inc [protected] |
the regeneration rate of the food
Definition at line 41 of file FoodCell.h.
Referenced by getInc(), and makeActions().
unsigned int FoodCell::_value [protected] |
the amount of the food currently on the Cell
Definition at line 44 of file FoodCell.h.
Referenced by addFood(), getFood(), makeActions(), and subFood().