From 2eebc954195ef13b7b7a7c345dc769e6174cfeee Mon Sep 17 00:00:00 2001 From: devZoGok Date: Fri, 26 Jan 2024 17:12:49 +0200 Subject: [PATCH] building and vehicle construction consumes refineds --- Assets/Scripts/GameObjects/Units/unitData.lua | 23 +++++++++++++++++++ engineer.cpp | 14 +++++++---- engineer.h | 2 -- factory.cpp | 18 ++++++--------- factory.h | 6 ++--- unit.h | 2 +- 6 files changed, 42 insertions(+), 23 deletions(-) diff --git a/Assets/Scripts/GameObjects/Units/unitData.lua b/Assets/Scripts/GameObjects/Units/unitData.lua index 05191cd..68af32a 100644 --- a/Assets/Scripts/GameObjects/Units/unitData.lua +++ b/Assets/Scripts/GameObjects/Units/unitData.lua @@ -59,6 +59,7 @@ units = { armor = {ArmorType.MECHANIC}, isVehicle = true, health = 500, + buildTime = 1000, cost = 500, size = {x = 2.9, y = 8.22, z = 2.42}, hitboxOffset = {x = 0, y = 0, z = 0}, @@ -81,6 +82,7 @@ units = { armor = {ArmorType.STEEL}, isVehicle = true, health = 500, + buildTime = 1000, cost = 500, size = {x = 2.9, y = 8.22, z = 2.42}, hitboxOffset = {x = 0, y = 0, z = 0}, @@ -103,6 +105,7 @@ units = { armor = {ArmorType.MECHANIC}, isVehicle = true, health = 500, + buildTime = 1000, cost = 500, size = {x = 2.9, y = 8.22, z = 2.42}, hitboxOffset = {x = 0, y = 0, z = 0}, @@ -125,6 +128,7 @@ units = { armor = {ArmorType.MECHANIC}, isVehicle = true, health = 500, + buildTime = 1000, cost = 500, size = {x = 1, y = 8, z = 13.45}, hitboxOffset = {x = 0, y = 0, z = 0}, @@ -146,6 +150,7 @@ units = { unitType = UnitType.HOVER, isVehicle = true, health = 500, + buildTime = 1000, cost = 500, size = {x = 2, y = 8.25, z = 2}, garrisonCapacity = {2, 2, 2}, @@ -169,6 +174,7 @@ units = { armor = {ArmorType.MECHANIC}, isVehicle = true, health = 500, + buildTime = 1000, cost = 500, garrisonCapacity = {2, 2, 2}, size = {x = 2, y = 8.25, z = 2}, @@ -192,6 +198,7 @@ units = { armor = {ArmorType.CAST}, isVehicle = true, health = 500, + buildTime = 1000, cost = 500, size = {x = 2, y = 8.25, z = 2}, hitboxOffset = {x = 0, y = 0, z = 0}, @@ -214,6 +221,7 @@ units = { armor = {ArmorType.STEEL}, isVehicle = true, health = 500, + buildTime = 1000, cost = 500, size = {x = 2, y = 8.25, z = 2}, hitboxOffset = {x = 0, y = 0, z = 0}, @@ -236,6 +244,7 @@ units = { armor = {ArmorType.CAST}, isVehicle = true, health = 500, + buildTime = 1000, cost = 500, garrisonCapacity = {2, 2, 2}, size = {x = 2, y = 8.25, z = 2}, @@ -259,6 +268,7 @@ units = { armor = {ArmorType.CAST}, isVehicle = true, health = 500, + buildTime = 1000, cost = 500, size = {x = 2, y = 8.25, z = 2}, hitboxOffset = {x = 0, y = 0, z = 0}, @@ -281,6 +291,7 @@ units = { armor = {ArmorType.STEEL, ArmorType.COMBINED}, isVehicle = true, health = 500, + buildTime = 1000, cost = 500, size = {x = 2, y = 8.25, z = 2}, hitboxOffset = {x = 0, y = 0, z = 0}, @@ -302,6 +313,7 @@ units = { unitType = UnitType.SEA_LEVEL, isVehicle = true, health = 500, + buildTime = 1000, cost = 500, size = {x = 2, y = 8.25, z = 2}, hitboxOffset = {x = 0, y = 0, z = 0}, @@ -332,6 +344,7 @@ units = { unitType = UnitType.SEA_LEVEL, isVehicle = true, health = 500, + buildTime = 1000, cost = 500, size = {x = 2, y = 8.25, z = 2}, hitboxOffset = {x = 0, y = 0, z = 0}, @@ -369,6 +382,7 @@ units = { unitType = UnitType.UNDERWATER, isVehicle = true, health = 500, + buildTime = 1000, cost = 500, size = {x = 2, y = 8.25, z = 2}, hitboxOffset = {x = 0, y = 0, z = 0}, @@ -399,6 +413,7 @@ units = { unitType = UnitType.UNDERWATER, isVehicle = true, health = 500, + buildTime = 1000, cost = 500, size = {x = 1, y = 1.15, z = 2}, hitboxOffset = {x = 0, y = 0, z = 0}, @@ -419,6 +434,7 @@ units = { unitType = UnitType.LAND, isVehicle = false, health = 500, + buildTime = 1000, cost = 500, size = {x = 1, y = 1.15, z = 2}, hitboxOffset = {x = 0, y = 0, z = 0}, @@ -434,6 +450,7 @@ units = { unitType = UnitType.SEA_LEVEL, isVehicle = false, health = 500, + buildTime = 1000, cost = 500, size = {x = 1, y = 1.15, z = 2}, hitboxOffset = {x = 0, y = 0, z = 0}, @@ -449,6 +466,7 @@ units = { unitType = UnitType.LAND, isVehicle = false, health = 500, + buildTime = 1000, cost = 500, size = {x = 1, y = 1.15, z = 2}, hitboxOffset = {x = 0, y = 0, z = 0}, @@ -464,6 +482,7 @@ units = { unitType = UnitType.LAND, isVehicle = false, health = 500, + buildTime = 1000, cost = 500, size = {x = 1, y = 1.15, z = 2}, hitboxOffset = {x = 0, y = 0, z = 0}, @@ -480,6 +499,7 @@ units = { unitType = UnitType.LAND, isVehicle = false, health = 500, + buildTime = 1000, cost = 500, size = {x = 2, y = 10, z = 2}, hitboxOffset = {x = 0, y = 0, z = 0}, @@ -495,6 +515,7 @@ units = { unitType = UnitType.LAND, isVehicle = false, health = 500, + buildTime = 1000, cost = 500, size = {x = 4, y = 1.15, z = 4}, hitboxOffset = {x = 0, y = 0, z = 0}, @@ -510,6 +531,7 @@ units = { unitType = UnitType.LAND, isVehicle = false, health = 500, + buildTime = 1000, cost = 500, size = {x = 1, y = 1.15, z = 2}, hitboxOffset = {x = 0, y = 0, z = 0}, @@ -525,6 +547,7 @@ units = { unitType = UnitType.LAND, isVehicle = false, health = 1000, + buildTime = 1000, cost = 1000, size = {x = 1, y = 1.15, z = 2}, hitboxOffset = {x = 0, y = 0, z = 0}, diff --git a/engineer.cpp b/engineer.cpp index 3d7cbd2..3d1efd5 100644 --- a/engineer.cpp +++ b/engineer.cpp @@ -3,22 +3,26 @@ #include "player.h" #include "structure.h" +#include + namespace battleship{ using namespace vb01; + using namespace gameBase; - Engineer::Engineer(Player *player, int id, Vector3 pos, Quaternion rot) : Vehicle(player, id, pos, rot){ - } + Engineer::Engineer(Player *player, int id, Vector3 pos, Quaternion rot) : Vehicle(player, id, pos, rot){} void Engineer::build(Order order){ if(pathPoints.empty()){ - if(!order.targets[0].unit){ + if(!order.targets[0].unit) player->addUnit(order.targets[0].unit); - } else { Structure *structure = (Structure*)order.targets[0].unit; + sol::table targTable = generateView()["units"][order.targets[0].unit->getId()]; + int costRate = (int)targTable["cost"] / 100, buildRate = (int)targTable["buildTime"] / 100; - if(structure->getBuildStatus() < 100 && canIncrementStructureStatus()){ + if(structure->getBuildStatus() < 100 && player->getRefineds() >= costRate && getTime() - lastIncrementTime > buildRate){ structure->incrementBuildStatus(); + player->setRefineds(player->getRefineds() - costRate); lastIncrementTime = getTime(); } else if(structure->getBuildStatus() >= 100){ diff --git a/engineer.h b/engineer.h index edf3bbe..54c48ea 100644 --- a/engineer.h +++ b/engineer.h @@ -15,8 +15,6 @@ namespace battleship{ private: vb01::s64 lastIncrementTime = 0; int buildRate = 100; - - bool canIncrementStructureStatus(){return vb01::getTime() - lastIncrementTime > buildRate;} }; } diff --git a/factory.cpp b/factory.cpp index b8c9d68..4d1ff5e 100644 --- a/factory.cpp +++ b/factory.cpp @@ -4,19 +4,16 @@ #include "activeGameState.h" #include +#include #include namespace battleship{ using namespace vb01; using namespace std; + using namespace gameBase; - Factory::Factory(Player *player, int id, Vector3 pos, Quaternion rot, int buildStatus) : Structure(player, id, pos, rot, buildStatus){ - initProperties(); - } - - void Factory::initProperties(){ - } + Factory::Factory(Player *player, int id, Vector3 pos, Quaternion rot, int buildStatus) : Structure(player, id, pos, rot, buildStatus){} void Factory::update(){ Structure::update(); @@ -25,10 +22,6 @@ namespace battleship{ train(); } - void Factory::appendToQueue(int uc){ - unitQueue.push_back(uc); - } - void Factory::train(){ bool training = !unitQueue.empty(); buildStatusForeground->setVisible(training); @@ -42,9 +35,12 @@ namespace battleship{ bool mainPlayerSelecting = (activeState && find(selectingPlayers.begin(), selectingPlayers.end(), mainPlayer) != selectingPlayers.end()); Unit::displayUnitStats(buildStatusForeground, buildStatusBackground, trainingStatus, 100, mainPlayer == player && mainPlayerSelecting, Vector2(0, -10)); + sol::table targTable = generateView()["units"][unitQueue[0]]; + int costRate = (int)targTable["cost"] / 100, trainRate = (int)targTable["buildTime"] / 100; - if(canTrain()){ + if(player->getRefineds() >= costRate && getTime() - lastTrainTime > trainRate){ trainingStatus++; + player->setRefineds(player->getRefineds() - costRate); lastTrainTime = getTime(); } diff --git a/factory.h b/factory.h index 928710e..1b65322 100644 --- a/factory.h +++ b/factory.h @@ -18,17 +18,15 @@ namespace battleship{ Factory(Player*, int, vb01::Vector3, vb01::Quaternion, int = 0); ~Factory(){} void update(); - void appendToQueue(int); + void appendToQueue(int uc){unitQueue.push_back(uc);} inline std::vector getQueue(){return unitQueue;} private: const int MAX_LEN_QUEUE = 10; - int trainingStatus = 0, rateOfTraining = 50; + int trainingStatus = 0; vb01::s64 lastTrainTime = 0; std::vector unitQueue; void train(); - void initProperties(); - inline bool canTrain(){return vb01::getTime() - lastTrainTime > rateOfTraining;} }; } diff --git a/unit.h b/unit.h index e5c2b74..001eb63 100755 --- a/unit.h +++ b/unit.h @@ -160,7 +160,7 @@ namespace battleship{ UnitClass unitClass; UnitType type; std::vector orders; - int health, maxHealth, cost, id, playerId, lenHpBar = 200; + int health, maxHealth, id, playerId, lenHpBar = 200; s64 orderLineDispTime = 0, lastFireTime = 0; float lineOfSight; std::vector garrisonSlots;