diff --git a/buildableUnit.h b/buildableUnit.h new file mode 100644 index 0000000..772a3b6 --- /dev/null +++ b/buildableUnit.h @@ -0,0 +1,13 @@ +#ifndef BUILDABLE_UNIT_H +#define BUILDABLE_UNIT_H + +namespace battleship{ + struct BuildableUnit{ + int id; + bool buildable; + + BuildableUnit(int i, bool build) : id(i), buildable(build){} + }; +} + +#endif diff --git a/factory.cpp b/factory.cpp index dfe72c1..4554904 100644 --- a/factory.cpp +++ b/factory.cpp @@ -18,6 +18,8 @@ namespace battleship{ void Factory::update(){ Structure::update(); + if(!isComplete()) return; + if(!unitQueue.empty()) train(); } diff --git a/pointDefense.cpp b/pointDefense.cpp index 42da4ff..e21c551 100644 --- a/pointDefense.cpp +++ b/pointDefense.cpp @@ -8,6 +8,8 @@ namespace battleship{ } void PointDefense::attack(Order order){ + if(!isComplete()) return; + Unit *targUnit = order.targets[0].unit; Vector3 targDir = (targUnit ? targUnit->getPos() : order.targets[0].pos) - pos; diff --git a/researchStruct.cpp b/researchStruct.cpp index b229a1c..a7da75c 100644 --- a/researchStruct.cpp +++ b/researchStruct.cpp @@ -16,7 +16,9 @@ namespace battleship{ void ResearchStruct::update(){ Structure::update(); - if(player->getRefineds() >= researchCost && canGenerateResearch()){ + if(!isComplete()) return; + + if(health > .3 * maxHealth && player->getRefineds() >= researchCost && canGenerateResearch()){ player->addResearch(generationSpeed); player->subtractRefineds(researchCost); lastGenTime = getTime(); diff --git a/resourceRover.cpp b/resourceRover.cpp index 1d32d55..a7d51b0 100644 --- a/resourceRover.cpp +++ b/resourceRover.cpp @@ -109,7 +109,7 @@ namespace battleship{ int minDistId = -1; for(int i = 0; i < structs.size(); i++) - if(structs[i]->getBuildStatus() == 100){ + if(structs[i]->isComplete()){ minDistId = i; break; } @@ -117,7 +117,7 @@ namespace battleship{ if(minDistId == -1) return nullptr; for(int i = 0; i < structs.size(); i++) - if(structs[i]->getBuildStatus() == 100 && structs[minDistId]->getPos().getDistanceFrom(pos) > structs[i]->getPos().getDistanceFrom(pos)) + if(structs[i]->isComplete() && structs[minDistId]->getPos().getDistanceFrom(pos) > structs[i]->getPos().getDistanceFrom(pos)) minDistId = i; return structs[minDistId]; diff --git a/structure.h b/structure.h index 10bd58a..da01ffa 100644 --- a/structure.h +++ b/structure.h @@ -13,6 +13,7 @@ namespace battleship{ Structure(Player*, int, vb01::Vector3, vb01::Quaternion, int = 0, Unit::State = Unit::State::STAND_GROUND); ~Structure(); virtual void update(); + inline bool isComplete(){return buildStatus == 100;} inline int getBuildStatus(){return buildStatus;} inline void incrementBuildStatus(){buildStatus++;} private: