src/Behaviour.cpp

00001 /*
00002 This file is part of Teapot Colony Wars.
00003 
00004 Teapot Colony Wars is free software: you can redistribute it and/or modify
00005 it under the terms of the GNU General Public License as published by
00006 the Free Software Foundation, either version 2 of the License, or
00007 (at your option) any later version.
00008 
00009 Teapot Colony Wars is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with Teapot Colony Wars.  If not, see <http://www.gnu.org/licenses/>.
00016 */
00017 
00018 #include "Behaviour.h"
00019 
00020 #include <list>
00021 
00022 #include "Random.h"
00023 #include "Colony.h"
00024 #include "Worshiper.h"
00025 #include "VisualContext.h"
00026 
00027 
00028 Behaviour::Behaviour() : _worshiper(NULL), _action(MOVECMD_NOMOVE),
00029     _pheros(new std::list<Pheromone*>) {
00030 
00031 }
00032 
00033 Behaviour::~Behaviour() {
00034   delete _pheros;
00035 }
00036 
00037 void Behaviour::setWorshiper(const Worshiper* w) {
00038   _worshiper = w;
00039 }
00040 
00041 move_command Behaviour::getLastAction() const {
00042   return _worshiper->getLastAction();
00043 }
00044 
00045 Pheromone* Behaviour::getPheromoneColony(unsigned int i) {
00046   return _worshiper->getColony()->getPheromone(i);
00047 }
00048 
00049 void Behaviour::putPheromone(unsigned int n) {
00050   _pheros->push_back(getPheromoneColony(n));
00051 }
00052 
00053 VisualContext* Behaviour::getVisualContext() const {
00054   return _worshiper->getVisualContext();
00055 }
00056 
00057 unsigned int Behaviour::getSize() const {
00058   return _worshiper->getSize();
00059 }
00060 
00061 unsigned int Behaviour::getFood() const {
00062   return _worshiper->getFood();
00063 }
00064 
00065 unsigned int Behaviour::getCapacity() const {
00066   return _worshiper->getCapacity();
00067 }
00068 
00069 move_command Behaviour::randomMove() const {
00070   move_command res;
00071   do{
00072     res = (move_command) (Random::value() % getVisualContext()->nbMovements());
00073   } while(res == getLastAction());
00074   return res;
00075 }

Generated on Sat Feb 2 22:22:54 2008 for Teapot Colony Wars by  doxygen 1.5.4