00001 /* 00002 * unutAI.cpp 00003 * 00004 * Created on: Dec 21, 2011 00005 * Author: sushil 00006 */ 00007 00008 #include <unitAI.h> 00009 #include "DEBUG.h" 00010 00011 inline void FastEcslent::UnitAI::tick(double dt) { 00012 00013 if (!commands.empty()) { 00014 //do the command 00015 commands.front()->tick(dt); 00016 if (commands.front()->done()){ // if done 00017 commands.pop_front(); // pop top 00018 if(!commands.empty()){ // if more commands 00019 commands.front()->init(); // init next command 00020 } 00021 } 00022 00023 } 00024 00025 } 00026 00027 void FastEcslent::UnitAI::init(){ 00028 // DEBUG(std::cout << "Starting unitAi for Entity: " << entity->entityId.id << std::endl;) 00029 if(!commands.empty()){ 00030 commands.front()->init(); 00031 } 00032 } 00033 00034 void FastEcslent::UnitAI::addCommand(Command* command){ 00035 commands.push_back(command); 00036 } 00037 00038 void FastEcslent::UnitAI::setCommand(Command* command){ 00039 for(std::deque<Command *>::iterator i= commands.begin();i != commands.end();i++){ 00040 (*i)->postProcess(); 00041 } 00042 commands.clear(); 00043 commands.push_back(command); 00044 } 00045 00046 void FastEcslent::UnitAI::setCommandList(std::deque<Command*> cmds){ 00047 commands.clear(); 00048 commands = cmds; 00049 }