00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 #ifndef COMMAND_H_
00009 #define COMMAND_H_
00010 
00011 #include "DEBUG.h"
00012 #include <OgreVector3.h>
00013 
00014 #include<target.h>
00015 
00016 #include "enums.h"
00017 
00018 namespace FastEcslent {
00019 
00020         enum CommandType {
00021                 MoveCommand     = 0,
00022                 AttackCommand   = 1,
00023                 RamCommand      = 2,
00024                 MaintainCommand = 3,
00025                 GatherCommand   = 4,
00026                 ConstructCommand= 5,
00027 
00028                 FLOCK
00029         };
00030 
00031 
00032         enum LeadershipType {
00033                 ClosestToTarget     = 0,
00034                 FurthestFromTarget  = 1,
00035                 MostMassive         = 2,
00036                 LeastMassive        = 3,
00037                 Random              = 4
00038         };
00039 
00040         class Entity;
00041         class Group;
00042 
00043         class Command {
00044         public:
00045                 CommandType commandType ;
00046                 Entity *entity; 
00047                 Command(CommandType ct,Entity *entity = NULL): entity(entity),commandType(ct) {};
00048                 Command(Command& orig): entity(orig.entity), commandType(orig.commandType) {};
00049 
00050                 virtual bool done() = 0;
00051                 virtual void init() = 0;
00052                 virtual void tick(double dt) = 0;
00053                 virtual void postProcess() = 0;
00054                 virtual Command* clone() {};
00055         };
00056         
00057         class BuildCommand : public Command {
00058 
00059         public:
00060 
00061             EntityType entType; 
00062             bool isDone; 
00064                 BuildCommand(Entity* entity, EntityType entType, CommandType ct): Command(ct), entType(entType), isDone(false) {this->entity = entity;}
00065                 BuildCommand(BuildCommand& orig): Command(orig.commandType), entType(orig.entType) {}
00066                 virtual bool done();
00067                 virtual void init();
00068                 virtual void tick(double dt);
00069                 virtual Command* clone() {return new BuildCommand(*this);}
00070                 virtual void postProcess() {};
00071 
00072         };
00073         
00074         class GasFieldCommand : public Command {
00075 
00076         public:
00077 
00078                 GasFieldCommand(CommandType ct,Entity *entity): Command(ct,entity) {}
00079                 GasFieldCommand(GasFieldCommand& orig): Command(orig.commandType) {}
00080                 virtual bool done();
00081                 virtual void init();
00082                 virtual void tick(double dt);
00083                 virtual Command* clone() {return new GasFieldCommand(*this);}
00084                 virtual void postProcess() {};
00085 
00086         };
00087 
00088 
00089         class UnitCommand : public Command {
00090 
00091         public:
00092 
00093                 Target *target;
00094                 
00095 
00096                 UnitCommand(Entity *ent, CommandType ct, Target* targ): Command(ct,ent) {
00097                         
00098                         target = targ;
00099                 }
00100 
00101                 
00102                 Ogre::Vector3 relativePos;
00103                 Ogre::Vector3 relativeVel;
00104                 Ogre::Vector3 predictedPos;
00105                 Ogre::Vector3 interceptPos;
00106 
00107                 double predictedTimeToClose;
00108                 double relativeSpeed;
00109         };
00110 
00111 
00112         class Tactic: public Command {
00113         public:
00114                 GroupTarget* target;
00115                 Group* group;
00116                 Tactic(Group* grp, CommandType ct, GroupTarget* trgt): Command(ct){
00117                         group = grp;
00118                         target = trgt;
00119                 }
00120 
00121                 int mostMassive(bool);
00122                 int closestToTarget(bool, Ogre::Vector3 tpos);
00123                 void changeLeadership(LeadershipType selector);
00124 
00125         };
00126         
00127 
00128 
00129 
00130 
00131 
00132 
00133 
00134 
00135 
00136 
00137 
00138 
00139 
00140 
00141 
00142 
00143 
00144 
00145 
00146 
00147 
00148 
00149         class Move: public UnitCommand {
00150         private:
00151                 bool valid(Ogre::Vector3 pos){
00152                         return true;
00153                 }
00154 
00155         public:
00156                 Move (Entity *ent, Target *tgt): UnitCommand(ent, MoveCommand, tgt) {
00157                         if(valid(tgt->location)) {
00158                                 DEBUG(std::cout << "Moving to: " << tgt->location << std::endl;)
00159                         }
00160                 }
00161                 virtual bool done();
00162                 virtual void init();
00163                 virtual void tick(double dt);
00164                 virtual void postProcess(){}; 
00165                 virtual Command* clone() {};
00166         };
00167 
00168         
00169         class Wait: public UnitCommand { 
00170         private:
00171                 bool valid(Ogre::Vector3 pos){
00172                         return true;
00173                 }
00174 
00175         public:
00176                 Wait (Entity *ent, Target *tgt): UnitCommand(ent, GatherCommand, tgt) {
00177                         timeLeftToWait = tgt->waitTime;
00178                         DEBUG(std::cout << "Waiting for: " << tgt->waitTime << std::endl;)
00179                 }
00180                 bool finished;
00181                 double timeLeftToWait;
00182                 virtual bool done();
00183                 virtual void init();
00184                 virtual void tick(double dt);
00185                 void postProcess(){};
00186                 virtual Command* clone() {};
00187         };
00188         
00189 
00190 
00191         class PotentialMove: public UnitCommand {
00192         private:
00193                 bool valid(Ogre::Vector3 pos){
00194                         return true;
00195                 }
00196                 double A, B, B2, m, n, RepulsionThresholdDistance;
00197 
00198         public:
00199                 PotentialMove (Entity *ent, Target *tgt): UnitCommand(ent, MoveCommand, tgt) {
00200                         if(valid(tgt->location)) {
00201                                 DEBUG(std::cout << "Moving to: " << tgt->location << " using Potential Fields" << std::endl;)
00202                                 A = 1000.0;
00203                                 B = 800000.0;
00204                                 B2 = 3000000.0;
00205                                 m = 4.0;
00206                                 n = 1;
00207                                 RepulsionThresholdDistance = 10000;
00208                         }
00209                 }
00210                 virtual bool done();
00211                 virtual void init();
00212                 virtual void tick(double dt);
00213                 virtual void postProcess(){};
00214                 virtual Command* clone() {};
00215 
00216         };
00217 
00218         class Maintain: public UnitCommand {
00219         private:
00220                 bool valid (Entity *ent);
00221 
00222         public:
00223                 Maintain (Entity *ent, Target *tgt);
00224                 virtual bool done();
00225                 virtual void init();
00226                 virtual void tick(double dt);
00227                 virtual Command* clone() {};
00228 
00229         };
00230 
00231 }
00232 
00233 
00234 
00235 #endif