cargo ships only source resources until they're full or the deposits are empty

This commit is contained in:
devZoGok
2024-01-24 14:54:34 +02:00
parent a7718cb9e1
commit f177172714
4 changed files with 19 additions and 15 deletions
+3 -7
View File
@@ -11,7 +11,7 @@ namespace battleship{
using namespace vb01;
using namespace gameBase;
Extractor::Extractor(Player *player, int id, Vector3 pos, Quaternion rot, int buildStatus, ResourceDeposit *rd) : Structure(player, id, pos, rot, buildStatus){
Extractor::Extractor(Player *player, int id, Vector3 pos, Quaternion rot, int buildStatus, ResourceDeposit *rd) : Structure(player, id, pos, rot, buildStatus), drawRate(10){
if(!rd){
vector<ResourceDeposit*> deposits;
@@ -56,11 +56,7 @@ namespace battleship{
}
void Extractor::draw(){
if(canDraw()){
deposit->decrementAmmount();
lastDrawTime = getTime();
}
deposit->decrementAmmount();
lastDrawTime = getTime();
}
bool Extractor::canDraw(){return vb01::getTime() - lastDrawTime > drawRate && deposit->getAmmount() > 0;}
}
+2 -1
View File
@@ -14,13 +14,14 @@ namespace battleship{
~Extractor();
void update();
void draw();
bool canDraw(){return vb01::getTime() - lastDrawTime > drawRate;}
inline ResourceDeposit* getDeposit(){return deposit;}
private:
int drawRate;
vb01::s64 lastDrawTime = 0;
vb01::Node *ammountBackground = nullptr, *ammountForeground = nullptr;
ResourceDeposit *deposit = nullptr;
bool canDraw();
};
}
+11 -6
View File
@@ -1,4 +1,5 @@
#include "resourceRover.h"
#include "resourceDeposit.h"
#include "map.h"
#include "player.h"
#include "extractor.h"
@@ -43,7 +44,7 @@ namespace battleship{
refineries.push_back((Structure*)unit);
}
nearestExtractor = getClosestUnit(extractors);
nearestExtractor = (Extractor*)getClosestUnit(extractors);
nearestRefinery = getClosestUnit(refineries);
if(!nearestExtractor){
@@ -52,12 +53,16 @@ namespace battleship{
}
if(nearestExtractor && nearestExtractor->getPos().getDistanceFrom(pos) <= minDist){
if(canLoad()){
((Extractor*)nearestExtractor)->draw();
load++;
lastLoadTime = getTime();
ResourceDeposit *deposit = nearestExtractor->getDeposit();
if(canLoad() && deposit->getAmmount() > 0){
if(nearestExtractor->canDraw()){
nearestExtractor->draw();
load++;
lastLoadTime = getTime();
}
}
else if(load == capacity && nearestRefinery)
else if((deposit->getAmmount() == 0 || load == capacity) && nearestRefinery)
preparePathpoints(order, nearestRefinery->getPos(), true);
}
else if(nearestRefinery && nearestRefinery->getPos().getDistanceFrom(pos) <= minDist){
+3 -1
View File
@@ -7,6 +7,7 @@
namespace battleship{
class Structure;
class Extractor;
class ResourceRover : public Vehicle{
public:
@@ -21,7 +22,8 @@ namespace battleship{
vb01::s64 lastLoadTime = 0;
int load = 0, capacity, loadRate;
Unit *nearestExtractor = nullptr, *nearestRefinery = nullptr;
Extractor *nearestExtractor = nullptr;
Unit *nearestRefinery = nullptr;
vb01::Node *loadBackground = nullptr, *loadForeground = nullptr;
};
}