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 for (int i = 0; i < nEnts;i++){
00043 ents[i]->init();
00044 }
00045
00046
00047 }
00048
00049 void FastEcslent::EntityMgr::tick(double dtime){
00050 DEBUG(std::cout << "Before live ent ticks" << std::endl;)
00051 for (int i = 0; i < nEnts; i++){
00052 this->ents[i]->tick(dtime);
00053 }
00054 DEBUG(std::cout << "after gestating ent ticks" << std::endl;)
00055 }
00056
00057 FastEcslent::Entity *FastEcslent::EntityMgr::createEntity(EntityType etype, Ogre::Vector3 pos, float heading){
00058 assert(nEnts < MaxEnts - 1);
00059
00060 Entity *ent;
00061 switch(etype){
00062 case SCV:
00063 ent = new SCVehicle(engine);
00064 break;
00065 case MARINE:
00066 ent = new FastEcslent::Marine(engine);
00067 break;
00068 case REAPER:
00069 ent = new Reaper(engine);
00070 break;
00071 case TANK:
00072 ent = new Tank(engine);
00073 break;
00074 case THOR:
00075 ent = new Thor(engine);
00076 break;
00077 case MARAUDER:
00078 ent = new Marauder(engine);
00079 break;
00080 case HELLION:
00081 ent = new Helion(engine);
00082 break;
00083
00084 case BARRACKS:
00085 ent = new Barracks(engine);
00086 break;
00087 case COMMANDCENTER:
00088 ent = new CommandCenter(engine);
00089 break;
00090 case FACTORY:
00091 ent = new Factory(engine);
00092 break;
00093 case ARMORY:
00094 ent = new Armory(engine);
00095 break;
00096 case ENGINEERINGBAY:
00097 ent = new EngineeringBay(engine);
00098 break;
00099 case SUPPLYDEPOT:
00100 ent = new SupplyDepot(engine);
00101 break;
00102 case REFINERY:
00103 ent = new Refinery(engine);
00104 break;
00105
00106 case MINERALS:
00107 ent = new Minerals(engine);
00108 break;
00109
00110 case GAS:
00111 ent = new Gas(engine);
00112 break;
00113
00114
00115
00116 default:
00117 ent = new FastEcslent::Marine(engine);
00118 break;
00119 }
00120
00121 ent->pos = pos;
00122 ent->heading = heading;
00123 ent->yaw = heading;
00124
00125
00126
00127 DEBUG(std::cout << "EntityMgr: created ent: " << nEnts << std::endl;)
00128
00129
00130 return ent;
00131 }
00132
00133
00134 bool FastEcslent::EntityMgr::cancelGestatingEntity(Entity *ent){
00135 ent->switchState(DYING);
00136 return true;
00137 }
00138
00139
00140 int FastEcslent::EntityMgr::addEntityToGame(Entity *ent){
00141 ent->entityId.id = nEnts;
00142 ents[nEnts] = ent;
00143 nEnts++;
00144 return ent->entityId.id;
00145 }
00146
00147 FastEcslent::Entity *FastEcslent::EntityMgr::createEntityForPlayerAndSide(EntityType etype, Ogre::Vector3 pos, float heading,
00148 Side side, Player player){
00149
00150 FastEcslent::Entity *ent = createEntityAfterTime(etype, pos, heading);
00151
00152 ent->entityId.player = player;
00153 ent->entityId.side = side;
00154 ent->desiredSpeed = 0.0f;
00155
00156
00157 return ent;
00158 }
00159
00160
00161 FastEcslent::Entity* FastEcslent::EntityMgr::createEntityAfterTime(EntityType etype, Ogre::Vector3 pos, float heading){
00162 FastEcslent::Entity *ent = createEntity(etype, pos, heading);
00163 ent->switchState(GESTATING);
00164 int id = this->addEntityToGame(ent);
00165 DEBUG(std::cout << "Created id: " << id << std::endl;)
00166
00167 return ent;
00168 }
00169
00170 FastEcslent::Entity* FastEcslent::EntityMgr::createEntityNow(EntityType etype, Ogre::Vector3 pos, float heading){
00171 FastEcslent::Entity *ent = createEntity(etype, pos, heading);
00172 ent->switchState(ALIVE);
00173 int id = this->addEntityToGame(ent);
00174 DEBUG(std::cout << "Created id: " << id << std::endl;)
00175 return ent;
00176 }
00177
00178 FastEcslent::Entity* FastEcslent::EntityMgr::getEntityById(int id){
00179 return ents[id];
00180 }
00181
00182
00183 bool FastEcslent::EntityMgr::preReqExists(EntityType entType){
00184 return true;
00185 }
00186
00187 bool FastEcslent::EntityMgr::notExceedPopCap(Identity entId){
00188 return true;
00189 }
00190
00191 void FastEcslent::EntityMgr::dumpOne(int i){
00192 assert(i >= 0 && i < nEnts);
00193 ents[i]->print();
00194 }
00195 void FastEcslent::EntityMgr::dumpAll(){
00196 for (int i = 0; i < nEnts; i++){
00197 ents[i]->print();
00198 }
00199 }