buildings.cpp

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

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