From 09fb45fdc41fa1e3b827d3c8147e516460ddb25a Mon Sep 17 00:00:00 2001 From: devZoGok Date: Tue, 24 Jun 2025 18:34:19 +0300 Subject: [PATCH] fixed destroyed unit deselection rovers have greater distance allowance to load resources from structures temporarily removed patroling --- activeGameState.cpp | 2 ++ gameObject.cpp | 1 + player.cpp | 11 +++++++++++ player.h | 1 + resourceRover.cpp | 4 +++- 5 files changed, 18 insertions(+), 1 deletion(-) diff --git a/activeGameState.cpp b/activeGameState.cpp index bfedbe8..66ac08c 100755 --- a/activeGameState.cpp +++ b/activeGameState.cpp @@ -825,10 +825,12 @@ namespace battleship{ } break; case Bind::SELECT_PATROL_POINTS: + /* if(isPressed && mainPlayer->getNumSelectedUnits() > 0){ targets.push_back(Order::Target(nullptr, mainPlayer->getSelectedUnit(0)->getPos())); selectingPatrolPoints = isPressed; } + */ break; case Bind::GROUP_0: diff --git a/gameObject.cpp b/gameObject.cpp index 3370a4e..23fb3ce 100644 --- a/gameObject.cpp +++ b/gameObject.cpp @@ -77,6 +77,7 @@ namespace battleship{ void GameObject::destroyHitbox(){ model->dettachChild(hitbox); delete hitbox; + hitbox = nullptr; } //TODO use a vector for the color nodes diff --git a/player.cpp b/player.cpp index 06d7b6a..8cbfbbd 100755 --- a/player.cpp +++ b/player.cpp @@ -142,6 +142,9 @@ namespace battleship{ } void Player::removeUnit(int id){ + if(find(selectedUnits.begin(), selectedUnits.end(), units[id]) != selectedUnits.end()) + deselectUnit(units[id]); + delete units[id]; units.erase(units.begin() + id); } @@ -244,4 +247,12 @@ namespace battleship{ return vector{}; } + + void Player::deselectUnit(Unit *unit){ + for(int i = 0; i < selectedUnits.size(); i++) + if(selectedUnits[i] == unit){ + selectedUnits.erase(selectedUnits.begin() + i); + break; + } + } } diff --git a/player.h b/player.h index 7aafdb3..8733ccf 100755 --- a/player.h +++ b/player.h @@ -36,6 +36,7 @@ namespace battleship{ void updateTradedResource(Player*, ResourceType, int, bool, bool); void addTradeOffer(Player*, TradeOffer*); std::vector getTradeOffers(Player*); + void deselectUnit(Unit*); inline int getResource(ResourceType rt){return resources[(int)rt];} inline void updateResource(ResourceType rt, int amount, bool add){resources[(int)rt] = (add ? resources[(int)rt] + amount : amount);} inline Trader* getTrader(){return trader;} diff --git a/resourceRover.cpp b/resourceRover.cpp index 7133fd4..4cbafc5 100644 --- a/resourceRover.cpp +++ b/resourceRover.cpp @@ -37,8 +37,10 @@ namespace battleship{ loadRate = unitTable["loadRate"]; loadRate += game->calcAbilFromTech(Ability::Type::LOAD_RATE, currTechs, (int)GameObject::type, id); } + //TODO implement a check of whether a vehicle is next to a building's outline void ResourceRover::loadResources(Structure *targStruct, float minDist, bool loadResource){ - bool closeEnough = (pos.getDistanceFrom(targStruct->getPos()) <= minDist); + float w = targStruct->getWidth(), l = targStruct->getLength(); + bool closeEnough = (pos.getDistanceFrom(targStruct->getPos()) <= sqrt(l * l + w * w)); if(!closeEnough) return; ResourceType resType;