mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
rovers can transfer different resources
This commit is contained in:
+11
-3
@@ -147,7 +147,15 @@ namespace battleship{
|
||||
|
||||
bool supply = (
|
||||
gameObjUnit &&
|
||||
((Unit*)gameObjHoveredOn)->getUnitClass() == UnitClass::EXTRACTOR &&
|
||||
(
|
||||
(
|
||||
((Unit*)gameObjHoveredOn)->getUnitClass() == UnitClass::EXTRACTOR &&
|
||||
((Extractor*)gameObjHoveredOn)->getDeposit()->getAmmount()
|
||||
) |
|
||||
((Unit*)gameObjHoveredOn)->getUnitClass() == UnitClass::TRADE_CENTER |
|
||||
((Unit*)gameObjHoveredOn)->getUnitClass() == UnitClass::REFINERY |
|
||||
((Unit*)gameObjHoveredOn)->getUnitClass() == UnitClass::LAB
|
||||
) &&
|
||||
mainPlayer->getSelectedUnit(0)->getUnitClass() == UnitClass::RESOURCE_ROVER
|
||||
);
|
||||
|
||||
@@ -157,7 +165,7 @@ namespace battleship{
|
||||
cursorState = CursorState::GARRISON;
|
||||
}
|
||||
else if(supply){
|
||||
orderPossible = (ownGameObj && ((Extractor*)gameObjHoveredOn)->getDeposit()->getAmmount());
|
||||
orderPossible = ownGameObj;
|
||||
cursorState = CursorState::SUPPLY;
|
||||
}
|
||||
else if(gameObjUnit && !ownGameObj)
|
||||
@@ -169,7 +177,7 @@ namespace battleship{
|
||||
if(cursorState == CursorState::GARRISON)
|
||||
orderPossible = (ownGameObj && gameObjTransport && canGarrison);
|
||||
else if(cursorState == CursorState::SUPPLY)
|
||||
orderPossible = (ownGameObj && supply && ((Extractor*)gameObjHoveredOn)->getDeposit()->getAmmount());
|
||||
orderPossible = (ownGameObj && supply);
|
||||
else if(cursorState == CursorState::HACK)
|
||||
orderPossible = (!ownGameObj && gameObjUnit && mainPlayer->getSelectedUnit(0)->getUnitClass() == UnitClass::ENGINEER);
|
||||
else if(gameObjUnit)
|
||||
|
||||
+84
-44
@@ -18,6 +18,8 @@ namespace battleship{
|
||||
Vector2 size = Vector2(lenHpBar, 10);
|
||||
loadBackground = Unit::createBar(Vector2::VEC_ZERO, size, Vector4(0, 0, 0, 1));
|
||||
loadForeground = Unit::createBar(Vector2::VEC_ZERO, size, Vector4(1, 1, 0, 1));
|
||||
|
||||
initProperties();
|
||||
}
|
||||
|
||||
ResourceRover::~ResourceRover(){
|
||||
@@ -26,7 +28,6 @@ namespace battleship{
|
||||
}
|
||||
|
||||
void ResourceRover::initProperties(){
|
||||
Vehicle::initProperties();
|
||||
Game *game = Game::getSingleton();
|
||||
vector<int> currTechs = player->getTechnologies();
|
||||
|
||||
@@ -36,54 +37,93 @@ namespace battleship{
|
||||
loadRate = unitTable["loadRate"]; loadRate += game->calcAbilFromTech(Ability::Type::LOAD_RATE, currTechs, (int)GameObject::type, id);
|
||||
}
|
||||
|
||||
//TODO equate rover load and extractor draw rates
|
||||
void ResourceRover::collectRefineds(Order order, float minDist){
|
||||
vector<Unit*> units = player->getUnits();
|
||||
vector<Structure*> extractors, refineries;
|
||||
|
||||
for(Unit *unit : units){
|
||||
if(unit->getUnitClass() == UnitClass::EXTRACTOR && ((Extractor*)unit)->getDeposit()->getAmmount() > 0)
|
||||
extractors.push_back((Structure*)unit);
|
||||
else if(unit->getUnitClass() == UnitClass::REFINERY)
|
||||
refineries.push_back((Structure*)unit);
|
||||
}
|
||||
|
||||
nearestExtractor = (Extractor*)getClosestUnit(extractors);
|
||||
nearestRefinery = getClosestUnit(refineries);
|
||||
|
||||
if(nearestExtractor && nearestExtractor->getPos().getDistanceFrom(pos) <= minDist){
|
||||
ResourceDeposit *deposit = nearestExtractor->getDeposit();
|
||||
|
||||
if(canLoad() && deposit->getAmmount() > 0){
|
||||
if(nearestExtractor->canDraw()){
|
||||
nearestExtractor->draw();
|
||||
load[(int)ResourceType::REFINEDS] += loadSpeed;
|
||||
lastLoadTime = getTime();
|
||||
}
|
||||
}
|
||||
else if(calcTotalLoad() == capacity && nearestRefinery)
|
||||
preparePathpoints(order, nearestRefinery->getPos(), true);
|
||||
}
|
||||
else if(!nearestExtractor){
|
||||
if(nearestRefinery && load[(int)ResourceType::REFINEDS] > 0)
|
||||
preparePathpoints(order, nearestRefinery->getPos(), true);
|
||||
else
|
||||
removeOrder(0);
|
||||
}
|
||||
|
||||
if(nearestRefinery && nearestRefinery->getPos().getDistanceFrom(pos) <= minDist){
|
||||
if(canUnload((int)ResourceType::REFINEDS)){
|
||||
load[(int)ResourceType::REFINEDS] -= loadSpeed;
|
||||
player->updateResource(ResourceType::REFINEDS, loadSpeed, true);
|
||||
lastLoadTime = getTime();
|
||||
}
|
||||
else if(load[(int)ResourceType::REFINEDS] == 0 && nearestExtractor)
|
||||
preparePathpoints(order, nearestExtractor->getPos());
|
||||
}
|
||||
}
|
||||
|
||||
void ResourceRover::transferResource(Structure *targStruct, float minDist){
|
||||
bool closeEnough = (pos.getDistanceFrom(targStruct->getPos()) <= minDist);
|
||||
ResourceType resType;
|
||||
|
||||
switch(targStruct->getUnitClass()){
|
||||
case UnitClass::TRADE_CENTER:
|
||||
resType = ResourceType::WEALTH;
|
||||
break;
|
||||
case UnitClass::REFINERY:
|
||||
resType = ResourceType::REFINEDS;
|
||||
break;
|
||||
case UnitClass::LAB:
|
||||
resType = ResourceType::RESEARCH;
|
||||
break;
|
||||
}
|
||||
|
||||
if(closeEnough){
|
||||
if(player == targStruct->getPlayer() && canLoad() && player->getResource(resType) > 0){
|
||||
player->updateResource(resType, -loadSpeed, true);
|
||||
load[(int)resType] += loadSpeed;
|
||||
lastLoadTime = getTime();
|
||||
}
|
||||
else if(player != targStruct->getPlayer() && canUnload((int)resType)){
|
||||
targStruct->getPlayer()->updateResource(resType, loadSpeed, true);
|
||||
load[(int)resType] -= loadSpeed;
|
||||
lastLoadTime = getTime();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ResourceRover::supply(Order order){
|
||||
float minDist = .5 * Map::getSingleton()->getCellSize().x;
|
||||
|
||||
|
||||
if(!pathPoints.empty())
|
||||
navigate(minDist);
|
||||
else{
|
||||
vector<Unit*> units = player->getUnits();
|
||||
vector<Structure*> extractors, refineries;
|
||||
Unit *targUnit = order.targets[0].unit;
|
||||
|
||||
for(Unit *unit : units){
|
||||
if(unit->getUnitClass() == UnitClass::EXTRACTOR && ((Extractor*)unit)->getDeposit()->getAmmount() > 0)
|
||||
extractors.push_back((Structure*)unit);
|
||||
else if(unit->getUnitClass() == UnitClass::REFINERY)
|
||||
refineries.push_back((Structure*)unit);
|
||||
}
|
||||
|
||||
nearestExtractor = (Extractor*)getClosestUnit(extractors);
|
||||
nearestRefinery = getClosestUnit(refineries);
|
||||
|
||||
if(nearestExtractor && nearestExtractor->getPos().getDistanceFrom(pos) <= minDist){
|
||||
ResourceDeposit *deposit = nearestExtractor->getDeposit();
|
||||
|
||||
if(canLoad() && deposit->getAmmount() > 0){
|
||||
if(nearestExtractor->canDraw()){
|
||||
nearestExtractor->draw();
|
||||
load += loadSpeed;
|
||||
lastLoadTime = getTime();
|
||||
}
|
||||
}
|
||||
else if(load == capacity && nearestRefinery)
|
||||
preparePathpoints(order, nearestRefinery->getPos(), true);
|
||||
}
|
||||
else if(!nearestExtractor){
|
||||
if(nearestRefinery && load > 0)
|
||||
preparePathpoints(order, nearestRefinery->getPos(), true);
|
||||
else
|
||||
removeOrder(0);
|
||||
}
|
||||
|
||||
if(nearestRefinery && nearestRefinery->getPos().getDistanceFrom(pos) <= minDist){
|
||||
if(canUnload()){
|
||||
load -= loadSpeed;
|
||||
player->updateResource(ResourceType::REFINEDS, 1, true);
|
||||
lastLoadTime = getTime();
|
||||
}
|
||||
else if(load == 0 && nearestExtractor)
|
||||
preparePathpoints(order, nearestExtractor->getPos());
|
||||
}
|
||||
if(targUnit->getUnitClass() == UnitClass::EXTRACTOR)
|
||||
collectRefineds(order, minDist);
|
||||
else transferResource((Structure*)targUnit, minDist);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +140,7 @@ namespace battleship{
|
||||
vector<Player*> selectingPlayers = getSelectingPlayers();
|
||||
bool mainPlayerSelecting = (activeState && find(selectingPlayers.begin(), selectingPlayers.end(), mainPlayer) != selectingPlayers.end());
|
||||
|
||||
Unit::displayUnitStats(loadForeground, loadBackground, load, capacity, mainPlayer == player && mainPlayerSelecting, Vector2(0, -10));
|
||||
Unit::displayUnitStats(loadForeground, loadBackground, calcTotalLoad(), capacity, mainPlayer == player && mainPlayerSelecting, Vector2(0, -10));
|
||||
}
|
||||
|
||||
Unit* ResourceRover::getClosestUnit(vector<Structure*> structs){
|
||||
|
||||
+6
-3
@@ -17,12 +17,15 @@ namespace battleship{
|
||||
private:
|
||||
void initProperties();
|
||||
void supply(Order);
|
||||
void collectRefineds(Order, float);
|
||||
void transferResource(Structure*, float);
|
||||
Unit* getClosestUnit(std::vector<Structure*>);
|
||||
inline bool canLoad(){return vb01::getTime() - lastLoadTime > loadRate && load < capacity;}
|
||||
inline bool canUnload(){return vb01::getTime() - lastLoadTime > loadRate && load > 0;}
|
||||
inline bool canLoad(){return vb01::getTime() - lastLoadTime > loadRate && calcTotalLoad() < capacity;}
|
||||
inline bool canUnload(int id){return vb01::getTime() - lastLoadTime > loadRate && load[id] > 0;}
|
||||
inline int calcTotalLoad(){return load[0] + load[1] + load[2];}
|
||||
|
||||
vb01::s64 lastLoadTime = 0;
|
||||
int load = 0, capacity, loadRate, loadSpeed;
|
||||
int load[3]{0, 0, 0}, capacity, loadRate, loadSpeed;
|
||||
Extractor *nearestExtractor = nullptr;
|
||||
Unit *nearestRefinery = nullptr;
|
||||
vb01::Node *loadBackground = nullptr, *loadForeground = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user