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 00031 FastEcslent::Building::~Building(){ 00032 } 00033 00034 void FastEcslent::Building::init(){ 00035 // do not add any aspects 00036 weapon = new Weapon(this, WEAPON, &(WeaponTypes::Rifle)); 00037 DEBUG(std::cout << "Created weapon aspect" << std::endl;) 00038 DEBUG(std::cout << "Initialized weapon aspect" << std::endl;) 00039 this->addAspect(weapon); 00040 DEBUG(std::cout << "Added weapon aspect" << std::endl;) 00041 00042 } 00043 00044 bool FastEcslent::Building::enqueue(EntityType entType){ 00045 if(buildableEntities[entType]){ 00046 if(this->engine->gameMgr->preReqExists(entType)){ 00047 this->entityQueue.push_back(entType); 00048 if (this->entityQueue.size() == 1){// if this is first push, start entity building timer 00049 if (this->engine->gameMgr->notExceedPopCap(this->entityId)) { 00050 this->entityBeingBuilt = this->engine->entityMgr->createEntityAfterTime(entType, this->pos, this->heading); 00051 } 00052 } 00053 } 00054 return true; 00055 } else { 00056 return false; 00057 } 00058 } 00059 00060 bool FastEcslent::Building::cancelEntityBeingBuilt(){ 00061 return this->engine->entityMgr->cancelGestatingEntity(this->entityBeingBuilt); 00062 } 00063 00064 00065 bool FastEcslent::Building::removeAtIndex(unsigned int pos){ 00066 if(pos < this->entityQueue.size()) { 00067 this->entityQueue.erase(this->entityQueue.begin() + pos); 00068 return true; 00069 } else { 00070 return false; 00071 } 00072 } 00073 00074 bool FastEcslent::Building::removeTail(void){ 00075 if (this->entityQueue.empty()) { 00076 return false; 00077 } else { 00078 this->entityQueue.pop_back(); 00079 return true; 00080 } 00081 } 00082 00083 FastEcslent::Minerals* FastEcslent::MineralPatch::getNextMineral(Minerals *m){ 00084 int minMiners = m->miners; 00085 Minerals * mineral = 0; 00086 int minDist = 10000; 00087 for(std::vector<Minerals*>::iterator i= minerals.begin();i!=minerals.end();i++){ 00088 if((*i)->miners < minMiners){ //highest priority is less miners 00089 minMiners =(*i)->miners; 00090 mineral = *i; 00091 minDist = (*i)->pos.distance(m->pos); 00092 }else if((*i)->miners == minMiners && (*i)->miners < m->miners){ //second priority is shorter distance 00093 int distance = (*i)->pos.distance(m->pos); 00094 if(distance < minDist){ 00095 minDist = distance; 00096 mineral = *i; 00097 } 00098 } 00099 } 00100 return mineral; 00101 }