extractors can only be built on unoccupied deposits

This commit is contained in:
devZoGok
2024-05-29 20:09:35 +03:00
parent aa657e34af
commit 76bf747451
3 changed files with 10 additions and 1 deletions
+4
View File
@@ -23,6 +23,7 @@ namespace battleship{
for(ResourceDeposit *dep : deposits) for(ResourceDeposit *dep : deposits)
if(dep->getPos().getDistanceFrom(pos) < .001){ if(dep->getPos().getDistanceFrom(pos) < .001){
deposit = dep; deposit = dep;
deposit->setExtractor(this);
break; break;
} }
} }
@@ -33,6 +34,9 @@ namespace battleship{
} }
Extractor::~Extractor(){ Extractor::~Extractor(){
if(deposit)
deposit->setExtractor(nullptr);
removeBar(ammountForeground); removeBar(ammountForeground);
removeBar(ammountBackground); removeBar(ammountBackground);
} }
+1 -1
View File
@@ -68,7 +68,7 @@ namespace battleship{
for(ResourceDeposit *dep : deposits){ for(ResourceDeposit *dep : deposits){
Vector3 depPos = dep->getPos(); Vector3 depPos = dep->getPos();
if(s.getPos().getDistanceFrom(depPos) < maxDist){ if(!dep->getExtractor() && s.getPos().getDistanceFrom(depPos) < maxDist){
s.status = GameObjectFrame::PLACEABLE; s.status = GameObjectFrame::PLACEABLE;
s.placeAt(depPos); s.placeAt(depPos);
break; break;
+5
View File
@@ -4,6 +4,8 @@
#include "gameObject.h" #include "gameObject.h"
namespace battleship{ namespace battleship{
class Extractor;
class ResourceDeposit : public GameObject{ class ResourceDeposit : public GameObject{
public: public:
ResourceDeposit(Player*, int, vb01::Vector3, vb01::Quaternion, int); ResourceDeposit(Player*, int, vb01::Vector3, vb01::Quaternion, int);
@@ -11,8 +13,11 @@ namespace battleship{
inline int getAmmount(){return ammount;} inline int getAmmount(){return ammount;}
inline int getInitAmmount(){return initAmmount;} inline int getInitAmmount(){return initAmmount;}
inline void decreaseAmmount(int amnt){ammount -= amnt;} inline void decreaseAmmount(int amnt){ammount -= amnt;}
inline Extractor* getExtractor(){return extractor;}
inline void setExtractor(Extractor *e){this->extractor = e;}
private: private:
int ammount, initAmmount; int ammount, initAmmount;
Extractor *extractor = nullptr;
void reinit(); void reinit();
}; };