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 using namespace FastEcslent;
00019
00020 Move *createMoveForEnt(Entity* ent, Ogre::Vector3 pos){
00021 Target* t = new Target;
00022 t->entity = 0;
00023 t->location = pos;
00024 t->offset = Ogre::Vector3(0.0f, 0.0f, 0.0f);
00025 Move* m = new Move(ent, t);
00026 m->init();
00027 return m;
00028 }
00029
00030
00031 namespace FastEcslent {
00032
00033 Gather *createGatherForEntAndMineral(SCVehicle *scv, Minerals *mineral){
00034 Target *t = new Target;
00035 t->entity = mineral;
00036 t->location = scv->pos;
00037 t->offset = Ogre::Vector3(0.0f, 0.0f, 0.0f);
00038 Gather *g = new Gather(scv, t);
00039 g->init();
00040 return g;
00041 }
00042
00043 void setMoveForEnt(Entity* ent, Ogre::Vector3 pos){
00044 Move *m = createMoveForEnt(ent, pos);
00045 UnitAI *ai = dynamic_cast<UnitAI *> (ent->getAspect(UNITAI));
00046 ai->setCommand(m);
00047 }
00048
00049 void addMoveForEnt(Entity* ent, Ogre::Vector3 pos){
00050 Move *m = createMoveForEnt(ent, pos);
00051 UnitAI *ai = dynamic_cast<UnitAI *> (ent->getAspect(UNITAI));
00052 ai->addCommand(m);
00053 }
00054
00055 PotentialMove *createPotentialMoveForEnt(Entity *ent, Ogre::Vector3 pos){
00056 Target* t = new Target;
00057 t->entity = 0;
00058 t->location = pos;
00059 t->offset = Ogre::Vector3(0.0f, 0.0f, 0.0f);
00060 PotentialMove *pm = new PotentialMove(ent, t);
00061 pm->init();
00062 return pm;
00063 }
00064
00065 void setPotentialMoveForEnt(Entity *ent, Ogre::Vector3 pos, bool append) {
00066
00067 if(ent->engine->options.side != ent->entityId.side or ent->engine->options.player != ent->entityId.player )
00068 return;
00069
00070 PotentialMove *pm = createPotentialMoveForEnt(ent, pos);
00071 UnitAI *ai = dynamic_cast<UnitAI *> (ent->getAspect(UNITAI));
00072 append?ai->addCommand(pm):ai->setCommand(pm);;
00073 }
00074
00075 void setGatherForEnt(Entity* ent, Entity* mineral, bool append){
00076 if (ent->entityType == SCV ){
00077 SCVehicle *scv = dynamic_cast<SCVehicle *>(ent);
00078 Gather *g = createGatherForEntAndMineral(scv, dynamic_cast<Minerals *>(mineral));
00079 UnitAI *ai = dynamic_cast<UnitAI *> (scv->getAspect(UNITAI));
00080 append?(ai->addCommand(g)):(ai->setCommand(g));
00081 }
00082 }
00083 }