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 #include <enums.h> 00011 #include <ent.h> 00012 #include <engine.h> 00013 00014 inline void FastEcslent::UnitAI::tick(double dt) { 00015 if( state == NETSLAVE && 00016 entity->entityId.side != entity->engine->options.side && 00017 entity->entityId.player != entity->engine->options.player ){ //controlled by remote 00018 return; 00019 } 00020 00021 if (!commands.empty()) { 00022 //do the command 00023 commands.front()->tick(dt); 00024 if (commands.front()->done()){ // if done 00025 commands.pop_front(); // pop top 00026 if(!commands.empty()){ // if more commands 00027 commands.front()->init(); // init next command 00028 } 00029 } 00030 state = MANUAL; 00031 } 00032 00033 } 00034 00035 void FastEcslent::UnitAI::init(){ 00036 // DEBUG(std::cout << "Starting unitAi for Entity: " << entity->entityId.id << std::endl;) 00037 if(!commands.empty()){ 00038 commands.front()->init(); 00039 } 00040 } 00041 00042 void FastEcslent::UnitAI::addCommand(Command* command){ 00043 commands.push_back(command); 00044 if(commands.size() == 1) //first command we've pushed, needs to be init 00045 { 00046 command->init(); 00047 } 00048 } 00049 00050 void FastEcslent::UnitAI::setCommand(Command* command){ 00051 for(std::deque<Command *>::iterator i= commands.begin();i != commands.end();i++){ 00052 (*i)->postProcess(); 00053 } 00054 commands.clear(); 00055 commands.push_back(command); 00056 command->init(); 00057 } 00058 00059 void FastEcslent::UnitAI::setCommandList(std::deque<Command*> cmds){ 00060 for(std::deque<Command *>::iterator i= commands.begin();i != commands.end();i++){ 00061 (*i)->postProcess(); 00062 } 00063 commands.clear(); 00064 commands = cmds; 00065 commands.front()->init(); 00066 }