00001
00002
00003
00004
00005
00006
00007
00008 #include <iostream>
00009 #include <assert.h>
00010
00011 #include <entityMgr.h>
00012
00013 #include <engine.h>
00014 #include <ent.h>
00015 #include <buildings.h>
00016 #include <aspect.h>
00017
00018 #include <physics.h>
00019
00020 #include <unitAI.h>
00021 #include <identity.h>
00022 #include <const.h>
00023 #include "DEBUG.h"
00024
00025
00026
00027 extern const int MaxEnts;
00028
00029
00030
00031
00032
00033
00034 FastEcslent::EntityMgr::EntityMgr(Engine* engine, Options opts): Mgr(engine) {
00035 reset();
00036 options = opts;
00037 }
00038
00039 void FastEcslent::EntityMgr::init() {
00040 DEBUG(std::cout << "EntityMgr Initialized" << std::endl;)
00041 reset();
00042 }
00043
00044 void FastEcslent::EntityMgr::tick(double dtime){
00045 DEBUG(std::cout << "Before live ent ticks" << std::endl;)
00046 for (int i = 0; i < nEnts; i++){
00047 this->ents[i]->tick(dtime);
00048 }
00049 DEBUG(std::cout << "after gestating ent ticks" << std::endl;)
00050 }
00051
00052 FastEcslent::Entity *FastEcslent::EntityMgr::createEntity(EntityType etype, Ogre::Vector3 pos, float heading){
00053 assert(nEnts < MaxEnts - 1);
00054
00055 Entity *ent;
00056 switch(etype){
00057 case SCV:
00058 ent = new SCVehicle(engine);
00059 break;
00060 case MARINE:
00061 ent = new FastEcslent::Marine(engine);
00062 break;
00063 case REAPER:
00064 ent = new Reaper(engine);
00065 break;
00066 case TANK:
00067 ent = new Tank(engine);
00068 break;
00069 case THOR:
00070 ent = new Thor(engine);
00071 break;
00072 case MARAUDER:
00073 ent = new Marauder(engine);
00074 break;
00075 case HELLION:
00076 ent = new Helion(engine);
00077 break;
00078
00079 case BARRACKS:
00080 ent = new Barracks(engine);
00081 break;
00082 case COMMANDCENTER:
00083 ent = new CommandCenter(engine);
00084 break;
00085 case FACTORY:
00086 ent = new Factory(engine);
00087 break;
00088 case ARMORY:
00089 ent = new Armory(engine);
00090 break;
00091 case ENGINEERINGBAY:
00092 ent = new EngineeringBay(engine);
00093 break;
00094 case SUPPLYDEPOT:
00095 ent = new SupplyDepot(engine);
00096 break;
00097 case REFINERY:
00098 ent = new Refinery(engine);
00099 (dynamic_cast<Refinery*>(ent))->setAssociatedOilField(pos);
00100 break;
00101
00102 case MINERALS:
00103 ent = new Minerals(engine);
00104 break;
00105
00106 case GAS:
00107 ent = new Gas(engine);
00108 break;
00109
00110
00111
00112 default:
00113 ent = new FastEcslent::Marine(engine);
00114 break;
00115 }
00116
00117 ent->pos = pos;
00118 ent->heading = heading;
00119 ent->yaw = heading;
00120
00121
00122
00123 DEBUG(std::cout << "EntityMgr: created ent: " << nEnts << std::endl;)
00124
00125
00126 return ent;
00127 }
00128
00129
00130 bool FastEcslent::EntityMgr::cancelGestatingEntity(Entity *ent){
00131 ent->switchState(DYING);
00132 return true;
00133 }
00134
00135
00136 int FastEcslent::EntityMgr::addEntityToGame(Entity *ent){
00137 ent->entityId.id = nEnts;
00138 ents[nEnts] = ent;
00139 nEnts++;
00140 return ent->entityId.id;
00141 }
00142
00143 FastEcslent::Entity *FastEcslent::EntityMgr::createEntityForPlayerAndSide(EntityType etype, Ogre::Vector3 pos, float heading,
00144 Side side, Player player){
00145
00146 FastEcslent::Entity *ent = createEntityAfterTime(etype, pos, heading);
00147
00148 ent->entityId.player = player;
00149 ent->entityId.side = side;
00150 ent->desiredSpeed = 0.0f;
00151
00152
00153 return ent;
00154 }
00155
00156
00157 FastEcslent::Entity* FastEcslent::EntityMgr::createEntityAfterTime(EntityType etype, Ogre::Vector3 pos, float heading){
00158 FastEcslent::Entity *ent = createEntity(etype, pos, heading);
00159 ent->switchState(GESTATING);
00160 int id = this->addEntityToGame(ent);
00161 DEBUG(std::cout << "Created id: " << id << std::endl;)
00162
00163 return ent;
00164 }
00165
00166 FastEcslent::Entity* FastEcslent::EntityMgr::createEntityNow(EntityType etype, Ogre::Vector3 pos, float heading){
00167 FastEcslent::Entity *ent = createEntity(etype, pos, heading);
00168 ent->switchState(ALIVE);
00169 int id = this->addEntityToGame(ent);
00170 DEBUG(std::cout << "Created id: " << id << std::endl;)
00171 return ent;
00172 }
00173
00174 FastEcslent::Entity* FastEcslent::EntityMgr::getEntityById(int id){
00175 return ents[id];
00176 }
00177
00178
00179 bool FastEcslent::EntityMgr::preReqExists(EntityType entType){
00180 return true;
00181 }
00182
00183 bool FastEcslent::EntityMgr::notExceedPopCap(Identity entId){
00184 return true;
00185 }
00186
00187 void FastEcslent::EntityMgr::dumpOne(int i){
00188 assert(i >= 0 && i < nEnts);
00189 ents[i]->print();
00190 }
00191 void FastEcslent::EntityMgr::dumpAll(){
00192 for (int i = 0; i < nEnts; i++){
00193 ents[i]->print();
00194 }
00195 }