entityMgr.cpp

Go to the documentation of this file.
00001 /*
00002  * entityMgr.cpp
00003  *
00004  *  Created on: Dec 18, 2011
00005  *      Author: sushil
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 //using namespace FastEcslent;
00026 
00027 extern const int MaxEnts;
00028 
00029 //FastEcslent::EntityMgr::EntityMgr() {
00030 //
00031 //      reset();
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                 break;
00100 
00101         case MINERALS:
00102                 ent = new Minerals(engine);
00103                 break;
00104 
00105         case GAS:
00106                 ent = new Gas(engine);
00107                 break;
00108 
00109 
00110 
00111         default:
00112                 ent = new FastEcslent::Marine(engine);
00113                 break;
00114         }
00115 
00116         ent->pos = pos;
00117         ent->heading = heading; // yaw is not used.
00118         ent->yaw = heading;
00119 
00120         //      ent->entityId.id = nDevelopingEnts++;
00121 
00122         DEBUG(std::cout << "EntityMgr: created ent: " << nEnts << std::endl;)
00123 //      ents[nEnts] = ent;
00124 //      nEnts++;
00125         return ent;
00126 }
00127 
00128 
00129 bool FastEcslent::EntityMgr::cancelGestatingEntity(Entity *ent){
00130         ent->switchState(DYING);
00131         return true;
00132 }
00133 
00134 
00135 int FastEcslent::EntityMgr::addEntityToGame(Entity *ent){
00136         ent->entityId.id = nEnts;
00137         ents[nEnts] = ent;
00138         nEnts++;
00139         return ent->entityId.id;
00140 }
00141 
00142 FastEcslent::Entity *FastEcslent::EntityMgr::createEntityForPlayerAndSide(EntityType etype, Ogre::Vector3 pos, float heading,
00143                 Side side, Player player){
00144 
00145         FastEcslent::Entity *ent = createEntityAfterTime(etype, pos, heading);
00146         //ent->entityId.id already set, so set rest of Id
00147         ent->entityId.player = player;
00148         ent->entityId.side = side;
00149         ent->desiredSpeed = 0.0f;
00150 
00151         //gaeSpecific Stuff
00152         return ent;
00153 }
00154 
00155 
00156 FastEcslent::Entity* FastEcslent::EntityMgr::createEntityAfterTime(EntityType etype, Ogre::Vector3 pos, float heading){
00157         FastEcslent::Entity *ent = createEntity(etype, pos, heading);
00158         ent->switchState(GESTATING);
00159         int id = this->addEntityToGame(ent);
00160         DEBUG(std::cout << "Created id: " << id << std::endl;)
00161 
00162         return ent;
00163 }
00164 
00165 FastEcslent::Entity* FastEcslent::EntityMgr::createEntityNow(EntityType etype, Ogre::Vector3 pos, float heading){
00166         FastEcslent::Entity *ent = createEntity(etype, pos, heading);
00167         ent->switchState(ALIVE);
00168         int id = this->addEntityToGame(ent);
00169         DEBUG(std::cout << "Created id: " << id << std::endl;)
00170         return ent;
00171 }
00172 
00173 FastEcslent::Entity* FastEcslent::EntityMgr::getEntityById(int id){
00174         return ents[id];
00175 }
00176 
00177 
00178 bool FastEcslent::EntityMgr::preReqExists(EntityType entType){
00179         return true;
00180 }
00181 
00182 bool FastEcslent::EntityMgr::notExceedPopCap(Identity entId){
00183         return true;
00184 }
00185 
00186 void FastEcslent::EntityMgr::dumpOne(int i){
00187         assert(i >= 0 && i < nEnts);
00188         ents[i]->print();
00189 }
00190 void FastEcslent::EntityMgr::dumpAll(){
00191         for (int i = 0; i < nEnts; i++){
00192                 ents[i]->print();
00193         }
00194 }

Generated on Fri Dec 13 14:54:17 2013 for FastECSLent by  doxygen 1.5.4