00001
00002
00003
00004
00005
00006
00007
00008 #include <OgreVector3.h>
00009 #include <ai/gather.h>
00010 #include <command.h>
00011 #include <ent.h>
00012 #include <buildings.h>
00013 #include <target.h>
00014 #include <group.h>
00015 #include <unitAI.h>
00016 #include <groupAI.h>
00017
00018 #include "commandFactory.h"
00019 #include <deque>
00020 #include <string>
00021
00022 using namespace FastEcslent;
00023
00024 namespace FastEcslent {
00025
00026 Move *createMoveForEnt(Entity* ent, Ogre::Vector3 pos){
00027 Target* t = new Target;
00028 t->entity = 0;
00029 t->location = pos;
00030 t->offset = Ogre::Vector3(0.0f, 0.0f, 0.0f);
00031 Move* m = new Move(ent, t);
00032 m->init();
00033 return m;
00034 }
00035
00036 Wait *createWaitForEnt(Entity* ent, double wtime){
00037 Target* t = new Target;
00038 t->waitTime = wtime;
00039 t->entity = 0;
00040 t->location = Ogre::Vector3(0.0f, 0.0f, 0.0f);
00041 t->offset = Ogre::Vector3(0.0f, 0.0f, 0.0f);
00042 Wait* w = new Wait(ent, t);
00043 w->init();
00044 return w;
00045 }
00046
00047 Gather *createGatherForEntAndMineral(SCVehicle *scv, Entity *resource){
00048 Target *t = new Target;
00049 t->entity = resource;
00050 t->location = scv->pos;
00051 t->offset = Ogre::Vector3(0.0f, 0.0f, 0.0f);
00052 Gather *g = new Gather(scv, t);
00053 g->init();
00054 return g;
00055 }
00056
00057 void setMoveForEnt(Entity* ent, Ogre::Vector3 pos){
00058 Move *m = createMoveForEnt(ent, pos);
00059 UnitAI *ai = dynamic_cast<UnitAI *> (ent->getAspect(UNITAI));
00060 ai->setCommand(m);
00061 }
00062
00063 void addMoveForEnt(Entity* ent, Ogre::Vector3 pos){
00064 Move *m = createMoveForEnt(ent, pos);
00065 UnitAI *ai = dynamic_cast<UnitAI *> (ent->getAspect(UNITAI));
00066 ai->addCommand(m);
00067 }
00068
00069 std::deque<Command*> addCommandForEnt(Entity* ent, CommandFactory* commandFactory, std::pair<int, Ogre::Vector3 > mouseTargets){
00070
00071 if(ent != NULL and ent->getAspect(UNITAI) != NULL and commandFactory != NULL)
00072 {
00073
00074 UnitAI *ai = dynamic_cast<UnitAI *> (ent->getAspect(UNITAI));
00075
00076 ai->setCommandList(commandFactory->MakeCommand(ent,mouseTargets));
00077 return ai->commands;
00078 }
00079 return std::deque<Command*>();
00080 }
00081
00082 PotentialMove *createPotentialMoveForEnt(Entity *ent, Ogre::Vector3 pos){
00083 Target* t = new Target;
00084 t->entity = 0;
00085 t->location = pos;
00086 t->offset = Ogre::Vector3(0.0f, 0.0f, 0.0f);
00087 PotentialMove *pm = new PotentialMove(ent, t);
00088 pm->init();
00089 return pm;
00090 }
00091
00092 void setPotentialMoveForEnt(Entity *ent, Ogre::Vector3 pos, bool append) {
00093
00094 if(ent->engine->options.side != ent->entityId.side or ent->engine->options.player != ent->entityId.player )
00095 return;
00096
00097 PotentialMove *pm = createPotentialMoveForEnt(ent, pos);
00098 UnitAI *ai = dynamic_cast<UnitAI *> (ent->getAspect(UNITAI));
00099 append?ai->addCommand(pm):ai->setCommand(pm);;
00100 }
00101
00102 void setGatherForEnt(Entity* ent, Entity* resource, bool append){
00103 if (ent->entityType == SCV ){
00104 SCVehicle *scv = dynamic_cast<SCVehicle *>(ent);
00105 Gather *g = createGatherForEntAndMineral(scv, resource);
00106 UnitAI *ai = dynamic_cast<UnitAI *> (scv->getAspect(UNITAI));
00107 append?(ai->addCommand(g)):(ai->setCommand(g));
00108 }
00109 }
00110 std::string EntityTypeToIconName(EntityType entType)
00111 {
00112 std::string typeString = "";
00113 switch(entType)
00114 {
00115 case SCV:
00116 typeString = "Boats/SCV";
00117 break;
00118 case MARINE:
00119 typeString = "Boats/MARINE";
00120 break;
00121 case HELLION:
00122 typeString = "Boats/VULTURE";
00123 break;
00124 case BARRACKS:
00125 typeString = "BarracksPanel";
00126 break;
00127 case FACTORY:
00128 typeString = "FactoryPanel";
00129 break;
00130 default:
00131 typeString = "Boats/MARINE";
00132 }
00133 return typeString;
00134 }
00135 }