From 0e56ce4748f7bbbdadb703d92c390a2f458ff37c Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sat, 30 Nov 2024 16:53:42 +0200 Subject: [PATCH] garrison order validation --- unit.cpp | 2 +- unit.h | 3 ++- vehicle.cpp | 10 ++++++++++ vehicle.h | 1 + 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/unit.cpp b/unit.cpp index 9035e93..4affd74 100755 --- a/unit.cpp +++ b/unit.cpp @@ -690,7 +690,7 @@ namespace battleship{ case Order::TYPE::MOVE: return vehicle; case Order::TYPE::GARRISON: - return true; + return validateGarrisonOrder(order); case Order::TYPE::EJECT: return !garrisonSlots.empty(); case Order::TYPE::LAUNCH: diff --git a/unit.h b/unit.h index d299ace..a02d90b 100755 --- a/unit.h +++ b/unit.h @@ -164,6 +164,7 @@ namespace battleship{ void updateScreenCoordinates(); void initWeapons(); void destroyWeapons(); + bool validateOrder(Order); inline bool canDisplayOrderLine(){return vb01::getTime() - orderLineDispTime < orderVecDispLength;} const int orderVecDispLength = 2000, DEATH_HP = 0; @@ -187,7 +188,7 @@ namespace battleship{ std::vector getSelectingPlayers(); void removeOrder(int); - bool validateOrder(Order); + virtual bool validateGarrisonOrder(Order){return false;} virtual void targetUnitsAutomatically(); virtual void reinit(); virtual void initProperties(); diff --git a/vehicle.cpp b/vehicle.cpp index b02a763..e370f60 100644 --- a/vehicle.cpp +++ b/vehicle.cpp @@ -46,6 +46,16 @@ namespace battleship{ pursuingTarget = false; } + bool Vehicle::validateGarrisonOrder(Order order){ + Unit *targUnit = order.targets[0].unit; + + for(GarrisonSlot slot : targUnit->getGarrisonSlots()) + if(!slot.vehicle && slot.category >= garrisonCategory) + return true; + + return false; + } + void Vehicle::receiveOrder(Order order, bool add){ if(!(order.type == Order::TYPE::EJECT || order.type == Order::TYPE::LAUNCH)){ Order::Target targ = order.targets[0]; diff --git a/vehicle.h b/vehicle.h index 64c4f13..40eb0fc 100644 --- a/vehicle.h +++ b/vehicle.h @@ -25,6 +25,7 @@ namespace battleship{ std::vector debugPathPoints; inline int getNextPatrolPointId(int numPoints) {return patrolPointId == numPoints - 1 ? 0 : patrolPointId + 1;} + bool validateGarrisonOrder(Order); void enterGarrisonable(); void halt(); void turn(float);