unitAI.cpp

Go to the documentation of this file.
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 }
00045 
00046 void FastEcslent::UnitAI::setCommand(Command* command){
00047         for(std::deque<Command *>::iterator i= commands.begin();i != commands.end();i++){
00048                 (*i)->postProcess();
00049         }
00050         commands.clear();
00051         commands.push_back(command);
00052 }
00053 
00054 void FastEcslent::UnitAI::setCommandList(std::deque<Command*> cmds){
00055         commands.clear();
00056         commands = cmds;
00057 }

Generated on Fri Dec 13 14:54:18 2013 for FastECSLent by  doxygen 1.5.4