From 0628ccf4a399ff0e4b0a3a1917e2f1045720cecd Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sun, 3 May 2026 20:57:19 +0300 Subject: [PATCH] units without horizontally rotatable weapons also consider the angle to the target only selecting cells blocked by other units bugfix for issuing orders to (in)complete buildings --- player.cpp | 2 +- vehicle.cpp | 16 +++++++++++++--- weapon.h | 2 ++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/player.cpp b/player.cpp index 16558b2..7684eb1 100755 --- a/player.cpp +++ b/player.cpp @@ -123,7 +123,7 @@ namespace battleship{ } if(!u->isVehicle() && ((Structure*)u)->isComplete()){ - structBuilt = false; + structBuilt = true; break; } } diff --git a/vehicle.cpp b/vehicle.cpp index 7996d8a..d215db7 100644 --- a/vehicle.cpp +++ b/vehicle.cpp @@ -276,7 +276,7 @@ namespace battleship{ void Vehicle::navigateToTarget(float minDist){ if(!pursuingTarget){ Vector3 targPos = (orders[0].targets[0].unit ? orders[0].targets[0].unit->getPos() : orders[0].targets[0].pos); - preparePathpoints(orders[0], targPos); + preparePathpoints(orders[0], targPos, true); pursuingTarget = true; if(orders[0].type == Order::TYPE::GARRISON) addPathpoint(targPos); @@ -340,7 +340,7 @@ namespace battleship{ if(type != UnitType::HOVER) dest = pf->clampDestToSourceRegion(source, dest); - if(cells[dest].blockedBy){ + if(cells[dest].blockedBy && cells[dest].blockedBy != this){ vector surrCellIds = map->getSurroundingCells(cells[dest].pos, 1); int altDest = -1; @@ -461,6 +461,7 @@ namespace battleship{ Order::Target target = order.targets[0]; Vector3 targVec = (target.unit ? target.unit->getPos() : target.pos) - pos; float distToTarg = targVec.getLength(); + float angleToTarg = dirVec.getAngleBetween(targVec.norm()); vector attackWeapons = getWeaponsByOrder(Order::TYPE::ATTACK); Weapon *weapon = attackWeapons[0]; @@ -470,9 +471,18 @@ namespace battleship{ weapon = w; float minDist = weapon->getMaxRange(); + float minAngle = weapon->getMaxFireAngle(); if(order.playerAssigned || (!order.playerAssigned && state == Unit::State::CHASE)){ - if(distToTarg > minDist) + bool horizontal = false; + + for(const Weapon::Component &comp : weapon->getComponents()) + if(!comp.vertical){ + horizontal = true; + break; + } + + if(distToTarg > minDist || (!horizontal && angleToTarg > minAngle)) navigateToTarget(.5 * Map::getSingleton()->getCellSize().x); else pursuingTarget = false; diff --git a/weapon.h b/weapon.h index 7db6dfd..5a543c3 100644 --- a/weapon.h +++ b/weapon.h @@ -41,11 +41,13 @@ namespace battleship{ virtual void fire(Order); void trackTarget(vb01::Vector3); bool canAttackTarget(int, int); + inline const std::vector& getComponents(){return components;} inline int getProjectileId(){return projId;} inline int getRateOfFire(){return rateOfFire;} inline int getDamage(){return damage;} inline int getMinRange(){return minRange;} inline int getMaxRange(){return maxRange;} + inline float getMaxFireAngle(){return maxFireAngle;} inline Unit* getUnit(){return unit;} inline Type getType(){return type;} inline Order::TYPE getOrderType(){return orderType;}