From 8a5dac18a952d72bb2249e7683a1984733feb912 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sat, 26 Apr 2025 14:32:02 +0300 Subject: [PATCH] code refactoring + test map --- Assets/Models/Maps/aaa/aaa.lua | 43 +++++++++++++++++++++++----------- resourceRover.cpp | 21 ++++------------- resourceRover.h | 7 ++---- unit.cpp | 7 ++---- unit.h | 4 +--- 5 files changed, 39 insertions(+), 43 deletions(-) diff --git a/Assets/Models/Maps/aaa/aaa.lua b/Assets/Models/Maps/aaa/aaa.lua index 8c36520..6bdb5b2 100644 --- a/Assets/Models/Maps/aaa/aaa.lua +++ b/Assets/Models/Maps/aaa/aaa.lua @@ -9,23 +9,38 @@ numPlayers = 1, numSpawnPoints = 1, spawnPoints = { {x = 0.000000, y = 0.000000, z = 0.000000}, +{x = 170.000000, y = 0.000000, z = -170.000000}, {x = -170.000000, y = 0.000000, z = 170.000000}, }, players = { -{ -resourceDeposits = { - {id = 0, pos = {x = -150.000000, y = 0.000000, z = 150.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 1000}, -}, -units = { - {id = UnitId.WAR_MECH, pos = {x = 100.000000, y = 0.000000, z = 10.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, buildStatus = 100}, -} -}, -{ - resourceDeposits = {}, - units = { - {id = UnitId.ENGINEER, pos = {x = -170.000000, y = 0.000000, z = 150.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, - } -} + { + resourceDeposits = { + {id = 0, pos = {x = -150.000000, y = 0.000000, z = 150.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 1000}, + }, + units = { + {id = UnitId.WAR_MECH, pos = {x = -170.000000, y = 0.000000, z = 150.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, + {id = UnitId.RESOURCE_ROVER, pos = {x = -170.000000, y = 0.000000, z = 180.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, + {id = UnitId.TRADE_CENTER, pos = {x = -180.000000, y = 0.000000, z = 150.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, buildStatus = 100}, + {id = UnitId.LAB, pos = {x = -200.000000, y = 0.000000, z = 140.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, buildStatus = 100}, + {id = UnitId.REFINERY, pos = {x = -170.000000, y = 0.000000, z = 120.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, buildStatus = 100}, + } + }, + { + resourceDeposits = {}, + units = { + {id = UnitId.POINT_DEFENSE, pos = {x = 100.000000, y = 0.000000, z = 10.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, buildStatus = 100}, + {id = UnitId.RESOURCE_ROVER, pos = {x = 100.000000, y = 0.000000, z = -10.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, + {id = UnitId.TRADE_CENTER, pos = {x = 130.000000, y = 0.000000, z = 10.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, buildStatus = 100}, + {id = UnitId.LAB, pos = {x = 100.000000, y = 0.000000, z = 20.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, buildStatus = 100}, + {id = UnitId.REFINERY, pos = {x = 100.000000, y = 0.000000, z = 50.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, buildStatus = 100}, + } + }, + { + resourceDeposits = {}, + units = { + {id = UnitId.LAND_FACTORY, pos = {x = 170.000000, y = 0.000000, z = -170.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, buildStatus = 100}, + } + }, }, numCells = 3969, cells = { diff --git a/resourceRover.cpp b/resourceRover.cpp index 7ea60d5..7133fd4 100644 --- a/resourceRover.cpp +++ b/resourceRover.cpp @@ -37,7 +37,7 @@ namespace battleship{ loadRate = unitTable["loadRate"]; loadRate += game->calcAbilFromTech(Ability::Type::LOAD_RATE, currTechs, (int)GameObject::type, id); } - void ResourceRover::handleTransfer(Structure *targStruct, float minDist, bool loadResource){ + void ResourceRover::loadResources(Structure *targStruct, float minDist, bool loadResource){ bool closeEnough = (pos.getDistanceFrom(targStruct->getPos()) <= minDist); if(!closeEnough) return; @@ -94,19 +94,6 @@ namespace battleship{ } } - void ResourceRover::transfer(Order order, bool loadResource){ - float minDist = .5 * Map::getSingleton()->getCellSize().x; - - if(!pathPoints.empty()) - navigate(minDist); - else - handleTransfer((Structure*)order.targets[0].unit, minDist, loadResource); - } - - void ResourceRover::load(Order order){transfer(order, true);} - - void ResourceRover::unload(Order order){transfer(order, false);} - //TODO equate rover load and extractor draw rates void ResourceRover::collectRefineds(Order order, float minDist){ vector units = player->getUnits(); @@ -153,13 +140,15 @@ namespace battleship{ } } - void ResourceRover::supply(Order order){ + void ResourceRover::handleResources(Order order){ float minDist = .5 * Map::getSingleton()->getCellSize().x; if(!pathPoints.empty()) navigate(minDist); - else + else if(order.type == Order::TYPE::SUPPLY) collectRefineds(order, minDist); + else + loadResources((Structure*)order.targets[0].unit, minDist, order.type == Order::TYPE::LOAD); } void ResourceRover::update(){ diff --git a/resourceRover.h b/resourceRover.h index cfa6197..c8faf5c 100644 --- a/resourceRover.h +++ b/resourceRover.h @@ -22,11 +22,8 @@ namespace battleship{ private: void initProperties(); void collectRefineds(Order, float); - void supply(Order); - void handleTransfer(Structure*, float, bool); - void transfer(Order, bool); - void load(Order); - void unload(Order); + void loadResources(Structure*, float, bool); + void handleResources(Order); Unit* getClosestUnit(std::vector); vb01::s64 lastLoadTime = 0; diff --git a/unit.cpp b/unit.cpp index c6fdd59..587c0cd 100755 --- a/unit.cpp +++ b/unit.cpp @@ -626,14 +626,11 @@ namespace battleship{ case Order::TYPE::LAUNCH: launch(order); break; - case Order::TYPE::SUPPLY: - supply(order); break; case Order::TYPE::LOAD: - load(order); - break; + case Order::TYPE::SUPPLY: case Order::TYPE::UNLOAD: - unload(order); + handleResources(order); break; case Order::TYPE::HACK: hack(order); diff --git a/unit.h b/unit.h index 0b0ba46..118cd69 100755 --- a/unit.h +++ b/unit.h @@ -209,9 +209,7 @@ namespace battleship{ virtual void move(Order){} virtual void patrol(Order){} virtual void launch(Order); - virtual void supply(Order){} - virtual void load(Order){} - virtual void unload(Order){} + virtual void handleResources(Order){} virtual void hack(Order){} float calculateRotation(vb01::Vector3, float, float); void removeBar(vb01::Node*);