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
00017 namespace FastEcslent {
00018
00019 enum CommandType {
00020 MoveCommand = 0,
00021 AttackCommand = 1,
00022 RamCommand = 2,
00023 MaintainCommand = 3,
00024 GatherCommand = 4,
00025
00026 FLOCK
00027 };
00028
00029
00030 enum LeadershipType {
00031 ClosestToTarget = 0,
00032 FurthestFromTarget = 1,
00033 MostMassive = 2,
00034 LeastMassive = 3,
00035 Random = 4
00036 };
00037
00038 class Entity;
00039 class Group;
00040
00041 class Command {
00042 public:
00043 CommandType commandType;
00044 Command(CommandType ct){
00045 commandType = ct;
00046 }
00047
00048 virtual bool done() = 0;
00049 virtual void init() = 0;
00050 virtual void tick(double dt) = 0;
00051 virtual void postProcess() = 0;
00052 };
00053
00054
00055 class UnitCommand : public Command {
00056
00057 public:
00058
00059 Target *target;
00060 Entity *entity;
00061
00062 UnitCommand(Entity *ent, CommandType ct, Target* targ): Command(ct) {
00063 entity = ent;
00064 target = targ;
00065 }
00066
00067
00068 Ogre::Vector3 relativePos;
00069 Ogre::Vector3 relativeVel;
00070 Ogre::Vector3 predictedPos;
00071 Ogre::Vector3 interceptPos;
00072
00073 double predictedTimeToClose;
00074 double relativeSpeed;
00075 };
00076
00077
00078 class Tactic: public Command {
00079 public:
00080 GroupTarget* target;
00081 Group* group;
00082 Tactic(Group* grp, CommandType ct, GroupTarget* trgt): Command(ct){
00083 group = grp;
00084 target = trgt;
00085 }
00086
00087 int mostMassive(bool);
00088 int closestToTarget(bool, Ogre::Vector3 tpos);
00089 void changeLeadership(LeadershipType selector);
00090
00091 };
00092
00093
00094
00095 class Move: public UnitCommand {
00096 private:
00097 bool valid(Ogre::Vector3 pos){
00098 return true;
00099 }
00100
00101 public:
00102 Move (Entity *ent, Target *tgt): UnitCommand(ent, MoveCommand, tgt) {
00103 if(valid(tgt->location)) {
00104 DEBUG(std::cout << "Moving to: " << tgt->location << std::endl;)
00105 }
00106 }
00107 virtual bool done();
00108 virtual void init();
00109 virtual void tick(double dt);
00110 virtual void postProcess(){};
00111 };
00112
00113
00114 class Wait: public UnitCommand {
00115 private:
00116 bool valid(Ogre::Vector3 pos){
00117 return true;
00118 }
00119
00120 public:
00121 Wait (Entity *ent, Target *tgt): UnitCommand(ent, GatherCommand, tgt) {
00122 timeLeftToWait = tgt->waitTime;
00123 DEBUG(std::cout << "Waiting for: " << tgt->waitTime << std::endl;)
00124 }
00125 bool finished;
00126 double timeLeftToWait;
00127 virtual bool done();
00128 virtual void init();
00129 virtual void tick(double dt);
00130 };
00131
00132
00133
00134 class PotentialMove: public UnitCommand {
00135 private:
00136 bool valid(Ogre::Vector3 pos){
00137 return true;
00138 }
00139 double A, B, B2, m, n, RepulsionThresholdDistance;
00140
00141 public:
00142 PotentialMove (Entity *ent, Target *tgt): UnitCommand(ent, MoveCommand, tgt) {
00143 if(valid(tgt->location)) {
00144 DEBUG(std::cout << "Moving to: " << tgt->location << " using Potential Fields" << std::endl;)
00145 A = 1000.0;
00146 B = 800000.0;
00147 B2 = 3000000.0;
00148 m = 4.0;
00149 n = 1;
00150 RepulsionThresholdDistance = 10000;
00151 }
00152 }
00153 virtual bool done();
00154 virtual void init();
00155 virtual void tick(double dt);
00156 virtual void postProcess(){};
00157
00158 };
00159
00160 class Maintain: public UnitCommand {
00161 private:
00162 bool valid (Entity *ent);
00163
00164 public:
00165 Maintain (Entity *ent, Target *tgt);
00166 virtual bool done();
00167 virtual void init();
00168 virtual void tick(double dt);
00169
00170 };
00171
00172 }
00173
00174
00175
00176 #endif