From fdfcacff9a781d111092681e0ee44c8366c2627e Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sun, 10 May 2026 20:42:50 +0300 Subject: [PATCH] using destination pos offsets for cargo ships --- Assets/Scripts/GameObjects/FX/fxData.lua | 2 ++ Assets/Scripts/GameObjects/Units/unitData.lua | 22 +++++++-------- resourceRover.cpp | 15 +++-------- vehicle.cpp | 27 +++++++++++++------ vehicle.h | 2 ++ 5 files changed, 37 insertions(+), 31 deletions(-) create mode 100644 Assets/Scripts/GameObjects/FX/fxData.lua diff --git a/Assets/Scripts/GameObjects/FX/fxData.lua b/Assets/Scripts/GameObjects/FX/fxData.lua new file mode 100644 index 0000000..97c1dfb --- /dev/null +++ b/Assets/Scripts/GameObjects/FX/fxData.lua @@ -0,0 +1,2 @@ +fx = { +} diff --git a/Assets/Scripts/GameObjects/Units/unitData.lua b/Assets/Scripts/GameObjects/Units/unitData.lua index a39f2ca..321fabe 100644 --- a/Assets/Scripts/GameObjects/Units/unitData.lua +++ b/Assets/Scripts/GameObjects/Units/unitData.lua @@ -392,7 +392,7 @@ units = { cost = 500, size = {x = 11.505, y = 10.3979, z = 17.1902}, hitboxOffset = {x = 0, y = 5.46, z = .86}, - lineOfSight = 25, + lineOfSight = 75, name = 'Tank', basePath = PATH .. vehiclePrefix .. 'Tanks/', meshPath = 'acsTank.xml', @@ -450,7 +450,7 @@ units = { cost = 500, size = {x = 13.6, y = 6.79, z = 21.8}, hitboxOffset = {x = 0, y = 3.31, z = 0}, - lineOfSight = 25, + lineOfSight = 75, name = 'Tank', basePath = PATH .. vehiclePrefix .. 'Tanks/', meshPath = 'aincTank.xml', @@ -511,7 +511,7 @@ units = { cost = 500, size = {x = 7.2, y = 10.3, z = 15}, hitboxOffset = {x = 0, y = 5.27, z = .26}, - lineOfSight = 25, + lineOfSight = 75, name = 'Tank', basePath = PATH .. vehiclePrefix .. 'Tanks/', meshPath = 'erTank.xml', @@ -570,7 +570,7 @@ units = { cost = 500, size = {x = 9.99, y = 15.4, z = 14.}, hitboxOffset = {x = 0, y = 7.69, z = .71}, - lineOfSight = 30, + lineOfSight = 90, name = 'Artillery', basePath = PATH .. vehiclePrefix .. 'Artillery/', meshPath = 'acsArtillery.xml', @@ -628,7 +628,7 @@ units = { cost = 500, size = {x = 10.4, y = 14, z = 12.9}, hitboxOffset = {x = 0, y = 7, z = 1.3}, - lineOfSight = 30, + lineOfSight = 90, name = 'Artillery', basePath = PATH .. vehiclePrefix .. 'Artillery/', meshPath = 'aincArtillery.xml', @@ -768,7 +768,7 @@ units = { cost = 500, size = {x = 4.95, y = 6.59, z = 4.11}, hitboxOffset = {x = .178, y = 3.27, z = 0}, - lineOfSight = 150, + lineOfSight = 1500, name = 'Engineer', basePath = PATH .. vehiclePrefix .. 'Engineers/', albedoPath = 'engineer.jpg', @@ -1221,8 +1221,8 @@ units = { meshPath = 'acsCargoShip.xml', albedoPath = 'cargoship.jpg', selectionSfx = PATH .. 'Sounds/Units/Cargoships/selection.ogg', - speed = .3, - destinationOffset = .1, + speed = .45, + destinationOffset = 1.25, anglePrecision = .1, maxTurnAngle = .1, garrisonCategory = 3, @@ -1257,7 +1257,7 @@ units = { albedoPath = 'cargoship.jpg', selectionSfx = PATH .. 'Sounds/Units/Cargoships/selection.ogg', speed = .3, - destinationOffset = .1, + destinationOffset = 1.25, anglePrecision = .1, maxTurnAngle = .1, garrisonCategory = 3, @@ -1291,8 +1291,8 @@ units = { meshPath = 'erCargoShip.xml', albedoPath = 'cargoship.jpg', selectionSfx = PATH .. 'Sounds/Units/Cargoships/selection.ogg', - speed = .3, - destinationOffset = .1, + speed = .45, + destinationOffset = 1.25, anglePrecision = .1, maxTurnAngle = .1, garrisonCategory = 3, diff --git a/resourceRover.cpp b/resourceRover.cpp index c4aec9d..1057c41 100644 --- a/resourceRover.cpp +++ b/resourceRover.cpp @@ -112,16 +112,7 @@ namespace battleship{ nearestExtractor = (Extractor*)getClosestUnit(extractors); nearestRefinery = getClosestUnit(refineries); - auto closeEnough = [](GameObject *obj, Vector3 pos){ - Vector3 neVec = pos - obj->getPos(); - float angle = obj->getDirVec().getAngleBetween(neVec.norm()); - - if(angle > PI / 2) angle = PI - angle; - - return cos(angle) * neVec.getLength() < .5 * obj->getLength(); - }; - - if(nearestExtractor && closeEnough(nearestExtractor, pos)){ + if(nearestExtractor && closeEnough(nearestExtractor, pos, destinationOffset)){ ResourceDeposit *deposit = nearestExtractor->getDeposit(); if(canLoad() && deposit->getAmmount() > 0){ @@ -144,7 +135,7 @@ namespace battleship{ else removeOrder(0); } - if(nearestRefinery && closeEnough(nearestRefinery, pos)){ + if(nearestRefinery && closeEnough(nearestRefinery, pos, destinationOffset)){ if(canUnload((int)ResourceType::REFINEDS)){ cargo[(int)ResourceType::REFINEDS] -= loadSpeed; player->updateResource(ResourceType::REFINEDS, loadSpeed, true); @@ -158,7 +149,7 @@ namespace battleship{ } void ResourceRover::handleResources(Order order){ - if(!pathPoints.empty()) navigate(.01); + if(!pathPoints.empty()) navigate(destinationOffset); else if(order.type == Order::TYPE::SUPPLY) collectRefineds(order); else diff --git a/vehicle.cpp b/vehicle.cpp index 9e20649..d51aa77 100644 --- a/vehicle.cpp +++ b/vehicle.cpp @@ -57,10 +57,8 @@ namespace battleship{ removeAllPathpoints(); - if(!orders[0].targets[0].unit) - preparePathpoints(orders[0], orders[0].targets[0].pos); - else if(orders[0].type == Order::TYPE::BUILD) - preparePathpoints(orders[0], orders[0].targets[0].unit->getPos()); + Vector3 targPos = (orders[0].targets[0].unit ? orders[0].targets[0].unit->getPos() : orders[0].targets[0].pos); + preparePathpoints(orders[0], targPos); } bool Vehicle::validateGarrisonOrder(Order order){ @@ -105,6 +103,7 @@ namespace battleship{ maxTurnAngle = unitTable["maxTurnAngle"]; maxTurnAngle += game->calcAbilFromTech(Ability::Type::MAX_TURN_ANGLE, currTechs, (int)GameObject::type, id); speed = unitTable["speed"]; speed += game->calcAbilFromTech(Ability::Type::SPEED, currTechs, (int)GameObject::type, id); anglePrecision = unitTable["anglePrecision"]; + destinationOffset = unitTable["destinationOffset"]; garrisonCategory = unitTable["garrisonCategory"]; } @@ -344,8 +343,9 @@ namespace battleship{ Unit *blockingUnit = cells[dest].blockedBy; bool garrisonOrder = (order.type == Order::TYPE::GARRISON); bool buildOrder = (order.type == Order::TYPE::BUILD); + bool resourceOrder = (order.type == Order::TYPE::LOAD || order.type == Order::TYPE::UNLOAD || order.type == Order::TYPE::SUPPLY); - if(blockingUnit && blockingUnit != this && !buildOrder && (!garrisonOrder || (garrisonOrder && blockingUnit != (Unit*)targObj))){ + if(blockingUnit && blockingUnit != this && !resourceOrder && !buildOrder && (!garrisonOrder || (garrisonOrder && blockingUnit != (Unit*)targObj))){ vector surrCellIds = map->getSurroundingCells(cells[dest].pos, 1); int altDest = -1; @@ -496,8 +496,10 @@ namespace battleship{ } void Vehicle::build(Order order){ - if(pathPoints.empty()){ - Structure *structure = (Structure*)order.targets[0].unit; + Structure *structure = (Structure*)order.targets[0].unit; + float offset = .5 * Map::getSingleton()->getCellSize().x; + + if(pathPoints.empty() && closeEnough(structure, pos, offset)){ sol::table targTable = generateView()["units"][structure->getId()]; int costRate = (int)targTable["cost"] / 100, buildRate = (int)targTable["buildTime"] / 100; @@ -511,11 +513,20 @@ namespace battleship{ player->incStructuresBuilt(); } } - else navigate(0.5 * Map::getSingleton()->getCellSize().x); + else navigate(offset); } void Vehicle::select(){ if(!garrisonable) Unit::select(); } + + bool Vehicle::closeEnough(GameObject *obj, Vector3 pos, float eps){ + Vector3 neVec = pos - obj->getPos(); + float angle = obj->getDirVec().getAngleBetween(neVec.norm()); + + if(angle > PI / 2) angle = PI - angle; + + return cos(angle) * neVec.getLength() < .5 * obj->getLength() + eps; + }; } diff --git a/vehicle.h b/vehicle.h index e347588..e13c0d6 100644 --- a/vehicle.h +++ b/vehicle.h @@ -41,6 +41,7 @@ namespace battleship{ protected: std::vector pathPoints; bool pursuingTarget = false; + float destinationOffset; void arrivedAtPathpoint(bool, float = 0); void moveByTerrainQuads(vb01::Vector3, float); @@ -53,6 +54,7 @@ namespace battleship{ void garrison(Order); void patrol(Order); virtual void initProperties(); + bool closeEnough(GameObject *obj, vb01::Vector3 pos, float = 0); }; }