00001 /* 00002 * buildings.cpp 00003 * 00004 * Created on: Jan 9, 2013 00005 * Author: sushil 00006 */ 00007 #include <engine.h> 00008 00009 #include <buildings.h> 00010 #include <unitWeapons.h> 00011 00012 #include <const.h> 00013 #include "DEBUG.h" 00014 00015 FastEcslent::Building::Building(Engine *engine, EntityType etype) : 00016 Entity(engine, etype) { 00017 this->meshName = "Barracks.mesh"; 00018 this->uiname = "Barracks"; 00019 //this->uiname = uiname.append(boost::lexical_cast<std::string>(id)); 00020 00021 entityClass = STATIC; 00022 //entityType = etype; 00023 // for(int i = 0; i < NENTITYTYPES; i++){ 00024 // buildableEntities[i] = false; 00025 // } 00026 00027 // and so on 00028 } 00029 00030 FastEcslent::Building::~Building() { 00031 } 00032 00033 void FastEcslent::Building::init() { 00034 // do not add any aspects 00035 weapon = new Weapon(this, WEAPON, &FastEcslent::WeaponTypes::Rifle); 00036 DEBUG(std::cout << "Created weapon aspect" << std::endl;) 00037 //weapon->init(); 00038 DEBUG(std::cout << "Initialized weapon aspect" << std::endl;) 00039 this->addAspect(weapon); 00040 DEBUG(std::cout << "Added weapon aspect" << std::endl;) 00041 ai = new UnitAI(this, UNITAI); 00042 ai->init(); 00043 this->addAspect(ai); 00044 00045 } 00046 00047 //bool FastEcslent::Building::enqueue(EntityType entType){ 00048 // if(buildableEntities[entType]){ 00049 // if(this->engine->gameMgr->preReqExists(entType)){ 00050 // this->entityQueue.push_back(entType); 00051 // if (this->entityQueue.size() == 1){// if this is first push, start entity building timer 00052 // if (this->engine->gameMgr->notExceedPopCap(this->entityId)) { 00053 // this->entityBeingBuilt = this->engine->entityMgr->createEntityAfterTime(entType, this->pos, this->heading); 00054 // } 00055 // } 00056 // } 00057 // return true; 00058 // } else { 00059 // return false; 00060 // } 00061 //} 00062 // 00063 //bool FastEcslent::Building::cancelEntityBeingBuilt(){ 00064 // return this->engine->entityMgr->cancelGestatingEntity(this->entityBeingBuilt); 00065 //} 00066 // 00067 // 00068 //bool FastEcslent::Building::removeAtIndex(unsigned int pos){ 00069 // if(pos < this->entityQueue.size()) { 00070 // this->entityQueue.erase(this->entityQueue.begin() + pos); 00071 // return true; 00072 // } else { 00073 // return false; 00074 // } 00075 //} 00076 // 00077 //bool FastEcslent::Building::removeTail(void){ 00078 // if (this->entityQueue.empty()) { 00079 // return false; 00080 // } else { 00081 // this->entityQueue.pop_back(); 00082 // return true; 00083 // } 00084 //} 00085 00086 FastEcslent::Minerals* FastEcslent::MineralPatch::getNextMineral(Minerals *m){ 00087 int minMiners = m->miners; 00088 Minerals * mineral = 0; 00089 int minDist = 10000; 00090 for(std::vector<Minerals*>::iterator i= minerals.begin();i!=minerals.end();i++){ 00091 if((*i)->miners < minMiners){ //highest priority is less miners 00092 minMiners =(*i)->miners; 00093 mineral = *i; 00094 minDist = (*i)->pos.distance(m->pos); 00095 }else if((*i)->miners == minMiners && (*i)->miners < m->miners){ //second priority is shorter distance 00096 int distance = (*i)->pos.distance(m->pos); 00097 if(distance < minDist){ 00098 minDist = distance; 00099 mineral = *i; 00100 } 00101 } 00102 } 00103 return mineral; 00104 } 00105 00106 void FastEcslent::Refinery::setAssociatedOilField(Ogre::Vector3 pos){ 00107 Entity * gasEnt = 0; 00108 int minDist = 10000; 00109 for (int i = 0; i < engine->entityMgr->nEnts; i++){ 00110 Entity* ent = engine->entityMgr->ents[i]; 00111 if(ent->entityType != GAS) 00112 continue; 00113 else{ 00114 int distance = ent->pos.distance(pos); 00115 if(distance < minDist){ 00116 minDist = distance; 00117 gasEnt = ent; 00118 } 00119 } 00120 } 00121 00122 if(gasEnt){ 00123 Gas* gas = dynamic_cast<Gas*>(gasEnt); 00124 this->associatedOilField = gas; 00125 gas->refinary = this; 00126 } 00127 }