From 59670c9310fd2758eea42de107fa525c35633666 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sat, 24 Feb 2024 12:12:48 +0200 Subject: [PATCH 01/13] labs generate research --- Assets/Scripts/GameObjects/Units/unitData.lua | 2 ++ CMakeLists.txt | 2 +- gameObjectFactory.cpp | 4 ++- player.h | 3 ++ researchStruct.cpp | 28 +++++++++++++++++++ researchStruct.h | 21 ++++++++++++++ 6 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 researchStruct.cpp create mode 100644 researchStruct.h diff --git a/Assets/Scripts/GameObjects/Units/unitData.lua b/Assets/Scripts/GameObjects/Units/unitData.lua index 35505b0..caee678 100644 --- a/Assets/Scripts/GameObjects/Units/unitData.lua +++ b/Assets/Scripts/GameObjects/Units/unitData.lua @@ -494,6 +494,8 @@ units = { size = {x = 1, y = 1.15, z = 2}, hitboxOffset = {x = 0, y = 0, z = 0}, lineOfSight = 5, + generationRate = 10000, + generationSpeed = 10, name = 'Lab', basePath = PATH .. structurePrefix .. 'Labs/', meshPath = 'lab.xml', diff --git a/CMakeLists.txt b/CMakeLists.txt index 30c1077..0434627 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ set(CORE gameManager.cpp game.cpp defConfigs.cpp ${CONSOLE} ${CONTROLLERS}) set(PROJECTILES projectile.cpp cruiseMissile.cpp) set(FX fx.cpp) set(VEHICLES vehicle.cpp engineer.cpp resourceRover.cpp) -set(STRUCTURES structure.cpp factory.cpp pointDefense.cpp extractor.cpp) +set(STRUCTURES structure.cpp factory.cpp pointDefense.cpp extractor.cpp researchStruct.cpp) set(UNITS gameObjectFactory.cpp unit.cpp ${STRUCTURES} ${VEHICLES}) set(CONTENT player.cpp pathfinder.cpp map.cpp gameObject.cpp gameObjectFrame.h resourceDeposit.cpp ${UNITS} ${PROJECTILES} ${FX}) set(GAME_SRC ${STATES} ${GUI} ${CORE} ${CONTENT} ${UTIL}) diff --git a/gameObjectFactory.cpp b/gameObjectFactory.cpp index 83fbc5f..dd39abc 100644 --- a/gameObjectFactory.cpp +++ b/gameObjectFactory.cpp @@ -8,6 +8,7 @@ #include "pointDefense.h" #include "extractor.h" #include "cruiseMissile.h" +#include "researchStruct.h" #include "defConfigs.h" #include @@ -32,8 +33,9 @@ namespace battleship{ return new PointDefense(player, id, pos, rot, buildStatus, Unit::State::STAND_GROUND); case UnitClass::EXTRACTOR: return new Extractor(player, id, pos, rot, buildStatus); - case UnitClass::MARKET: case UnitClass::LAB: + return new ResearchStruct(player, id, pos, rot, buildStatus); + case UnitClass::MARKET: case UnitClass::REFINERY: return new Structure(player, id, pos, rot, buildStatus, Unit::State::STAND_GROUND); case UnitClass::ENGINEER: diff --git a/player.h b/player.h index a5af80b..639f3e9 100755 --- a/player.h +++ b/player.h @@ -48,12 +48,15 @@ namespace battleship{ inline int getRefineds(){return refineds;} inline void setRefineds(int ref){this->refineds = ref;} inline void addRefineds(int ref){this->refineds += ref;} + inline void subtractRefineds(int ref){this->refineds -= ref;} inline int getWealth(){return wealth;} inline void setWealth(int w){this->wealth = w;} inline void addWealth(int w){this->wealth += w;} + inline void subtractWealth(int w){this->wealth -= w;} inline int getResearch(){return research;} inline void setResearch(int r){this->research = r;} inline void addResearch(int r){this->research += r;} + inline void subtractResearch(int r){this->research -= r;} inline bool isCpuPlayer(){return cpuPlayer;} inline int getNumVehiclesBuilt(){return vehiclesBuilt;} inline int getNumVehiclesDestroyed(){return vehiclesDestroyed;} diff --git a/researchStruct.cpp b/researchStruct.cpp new file mode 100644 index 0000000..9e6a241 --- /dev/null +++ b/researchStruct.cpp @@ -0,0 +1,28 @@ +#include "researchStruct.h" +#include "player.h" + +namespace battleship{ + using namespace std; + using namespace vb01; + using namespace gameBase; + + ResearchStruct::ResearchStruct(Player *player, int id, Vector3 pos, Quaternion rot, int buildStatus, Unit::State state) : Structure(player, id, pos, rot, buildStatus, state){ + sol::table unitTable = generateView()["units"][id + 1]; + generationRate = unitTable["generationRate"]; + generationSpeed = unitTable["generationSpeed"]; + } + + void ResearchStruct::update(){ + Structure::update(); + int cost = 1; + + if(player->getRefineds() >= cost && canGenerateResearch()){ + player->addResearch(generationSpeed); + player->subtractRefineds(cost); + lastGenTime = getTime(); + } + } + + void ResearchStruct::researchTechnology(int techId){ + } +} diff --git a/researchStruct.h b/researchStruct.h new file mode 100644 index 0000000..66b4444 --- /dev/null +++ b/researchStruct.h @@ -0,0 +1,21 @@ +#ifndef RESEARCH_STRUCT_H +#define RESEARCH_STRUCT_H + +#include "structure.h" + +namespace battleship{ + class ResearchStruct : public Structure{ + public: + ResearchStruct(Player*, int, vb01::Vector3, vb01::Quaternion, int = 0, Unit::State = Unit::State::STAND_GROUND); + void update(); + private: + vb01::s64 lastGenTime = 0; + int generationRate, generationSpeed; + + bool canGenerateResearch(){return vb01::getTime() - lastGenTime > generationRate;} + void generateResearch(); + void researchTechnology(int); + }; +} + +#endif From 7deb1612831e0665123a16258a315cfc58cee017 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sat, 24 Feb 2024 12:51:02 +0200 Subject: [PATCH 02/13] initting technologies --- .../Scripts/Technologies/technologyData.lua | 49 +++++++++++++++++-- defConfigs.h | 3 +- game.cpp | 39 +++++++++++++++ game.h | 4 ++ playButton.cpp | 5 +- player.h | 9 +++- technology.h | 19 +++++++ 7 files changed, 120 insertions(+), 8 deletions(-) create mode 100644 technology.h diff --git a/Assets/Scripts/Technologies/technologyData.lua b/Assets/Scripts/Technologies/technologyData.lua index 57d097e..5a0f384 100644 --- a/Assets/Scripts/Technologies/technologyData.lua +++ b/Assets/Scripts/Technologies/technologyData.lua @@ -1,10 +1,49 @@ +TechnologyId = { + APT = 0, + EFT = 1, + PCT = 2, + FPT = 3, +} + technologies = { { - name = '', - cost = 10, + id = TechnologyId.APT + name = 'Advanced power technology', + cost = 1000, icon = '', description = '', - abilities = {0}, - units = {} - } + parents = {}, + children = {}, + abilities = {}, + }, + { + id = TechnologyId.EFT + name = 'Energy field technology', + cost = 1000, + icon = '', + description = '', + parents = {}, + children = {}, + abilities = {}, + }, + { + id = TechnologyId.PCT + name = 'Plasma casting technology', + cost = 1000, + icon = '', + description = '', + parents = {}, + children = {}, + abilities = {}, + }, + { + id = TechnologyId.FPT + name = 'Fusion power technology', + cost = 1000, + icon = '', + description = '', + parents = {}, + children = {}, + abilities = {}, + }, } diff --git a/defConfigs.h b/defConfigs.h index 8a74fcd..ea9aabe 100755 --- a/defConfigs.h +++ b/defConfigs.h @@ -50,7 +50,8 @@ namespace battleship{ "Scripts/GameObjects/Projectiles/projectileData.lua", "Scripts/GameObjects/Units/unitData.lua", "Scripts/aiAgent.lua", - "Scripts/Core/player.lua" + "Scripts/Core/player.lua", + "Scripts/Technologies/technologyData.lua", }; const static Bind staticBinds[numAppStates][maxStaticBinds]{ diff --git a/game.cpp b/game.cpp index 24bfef0..57eea48 100644 --- a/game.cpp +++ b/game.cpp @@ -214,4 +214,43 @@ namespace battleship{ unit->setPlayer(newPlayer); unit->halt(); } + + vector Game::parseTechTable(int tid, string techKey, string numVarKey, string varKey){ + sol::state_view SOL_LUA_VIEW = generateView(); + SOL_LUA_VIEW.script(numVarKey + " = #" + techKey + "[" + to_string(tid + 1) + "]." + varKey); + int numVar = SOL_LUA_VIEW[numVarKey]; + sol::table techTable = SOL_LUA_VIEW[techKey][tid + 1]; + + vector varVec; + + for(int i = 0; i < numVar; i++) + varVec.push_back(techTable[varKey][i + 1]); + + return varVec; + } + + void Game::initTechnologies(){ + technologies.clear(); + + sol::state_view SOL_LUA_VIEW = generateView(); + string techKey = "technologies"; + SOL_LUA_VIEW.script("numTechs = #" + techKey); + int numTechs = SOL_LUA_VIEW["numTechs"]; + + for(int i = 0; i < numTechs; i++){ + sol::table techTable = SOL_LUA_VIEW[techKey][i + 1]; + + Technology t; + t.id = techTable["id"]; + t.cost = techTable["cost"]; + t.name = techTable["name"]; + t.icon = techTable["icon"]; + t.description = techTable["description"]; + t.parents = parseTechTable(i, techKey, "numParents", "parents"); + t.children = parseTechTable(i, techKey, "numChildren", "children"); + t.abilities = parseTechTable(i, techKey, "numAbilities", "abilities"); + + technologies.push_back(t); + } + } } diff --git a/game.h b/game.h index cb9c575..f28e77a 100644 --- a/game.h +++ b/game.h @@ -2,6 +2,7 @@ #define GAME_H #include "fx.h" +#include "technology.h" #include @@ -23,6 +24,7 @@ namespace battleship{ void removeAllElements(); void explode(vb01::Vector3, int, float, sf::Sound*); void changeUnitPlayer(Unit*, Player*); + void initTechnologies(); inline void addFx(Fx f){fx.push_back(f);} inline void addPlayer(Player *pl){players.push_back(pl);} inline std::vector& getPlayers(){return players;} @@ -32,9 +34,11 @@ namespace battleship{ Game(){} void resetLuaGameObjects(); void endGame(bool); + std::vector parseTechTable(int, std::string, std::string, std::string); bool paused = false, ended = false; std::vector fx; + std::vector technologies; std::vector players; }; } diff --git a/playButton.cpp b/playButton.cpp index 7be1f3f..1d4b369 100644 --- a/playButton.cpp +++ b/playButton.cpp @@ -28,6 +28,9 @@ namespace battleship{ for(int i = 0; i < factionsListboxes.size(); i++) factions.push_back(to_string(factionsListboxes[i]->getSelectedOption())); + + Game *game = Game::getSingleton(); + game->initTechnologies(); int selectedMap = mapListbox->getSelectedOption(); string mapName = wstringToString(mapListbox->getContents()[selectedMap]); @@ -39,7 +42,7 @@ namespace battleship{ for(int i = 0; i < numPlayers; i++){ bool cpuPlayer = (i < numPlayers - 1); string name = (cpuPlayer ? "CPU player #" + to_string(i) : "Player"); - Game::getSingleton()->addPlayer(new Player(0, 0, i, Vector3(1, 1, 1), cpuPlayer, map->getSpawnPoint(i), name)); + game->addPlayer(new Player(0, 0, i, Vector3(1, 1, 1), cpuPlayer, map->getSpawnPoint(i), name)); } map->loadPlayerGameObjects(); diff --git a/player.h b/player.h index 639f3e9..d8d5666 100755 --- a/player.h +++ b/player.h @@ -72,9 +72,16 @@ namespace battleship{ inline void incStructuresLost(){structuresLost++;} inline vb01::Vector3 getColor(){return color;} inline std::string getName(){return name;} + inline std::vector getTechnologies(){return technologies;} + inline void addTechnology(int tid){technologies.push_back(tid);} private: bool cpuPlayer = false; - int refineds = 0, wealth = 0, research = 0, faction, difficulty, team, luaPlayerId, vehiclesBuilt = 0, vehiclesDestroyed = 0, vehiclesLost = 0, structuresBuilt = 0, structuresDestroyed = 0, structuresLost = 0; + std::vector technologies; + int luaPlayerId; + int refineds = 0, wealth = 0, research = 0; + int faction, difficulty, team; + int vehiclesBuilt = 0, vehiclesDestroyed = 0, vehiclesLost = 0; + int structuresBuilt = 0, structuresDestroyed = 0, structuresLost = 0; std::string name; std::vector units, selectedUnits; std::vector projectiles; diff --git a/technology.h b/technology.h new file mode 100644 index 0000000..c93985f --- /dev/null +++ b/technology.h @@ -0,0 +1,19 @@ +#ifndef TECHNOLOGY_H +#define TECHNOLOGY_H + +#include +#include + +namespace battleship{ + struct Technology{ + int id, cost; + std::string name; + std::string icon; + std::string description; + std::vector parents; + std::vector children; + std::vector abilities; + }; +} + +#endif From ebd42f6cabe9e956e55ac37e5ae9ed9433be6736 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sat, 24 Feb 2024 14:45:26 +0200 Subject: [PATCH 03/13] add-technology command --- .../Scripts/Technologies/technologyData.lua | 8 ++-- CMakeLists.txt | 2 +- addTechnologyCommand.cpp | 42 +++++++++++++++++++ addTechnologyCommand.h | 19 +++++++++ console.cpp | 3 ++ 5 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 addTechnologyCommand.cpp create mode 100644 addTechnologyCommand.h diff --git a/Assets/Scripts/Technologies/technologyData.lua b/Assets/Scripts/Technologies/technologyData.lua index 5a0f384..9d34b9f 100644 --- a/Assets/Scripts/Technologies/technologyData.lua +++ b/Assets/Scripts/Technologies/technologyData.lua @@ -7,7 +7,7 @@ TechnologyId = { technologies = { { - id = TechnologyId.APT + id = TechnologyId.APT, name = 'Advanced power technology', cost = 1000, icon = '', @@ -17,7 +17,7 @@ technologies = { abilities = {}, }, { - id = TechnologyId.EFT + id = TechnologyId.EFT, name = 'Energy field technology', cost = 1000, icon = '', @@ -27,7 +27,7 @@ technologies = { abilities = {}, }, { - id = TechnologyId.PCT + id = TechnologyId.PCT, name = 'Plasma casting technology', cost = 1000, icon = '', @@ -37,7 +37,7 @@ technologies = { abilities = {}, }, { - id = TechnologyId.FPT + id = TechnologyId.FPT, name = 'Fusion power technology', cost = 1000, icon = '', diff --git a/CMakeLists.txt b/CMakeLists.txt index 0434627..ec20ad1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,7 @@ set(GUI tooltip.cpp concreteGuiManager.cpp ${BUTTONS} ${LISTBOXES}) set(STATES activeGameState.cpp inGameAppState.cpp guiAppState.cpp mapEditorAppState.cpp) set(UTIL util.cpp binds.h) set(CONTROLLERS gameObjectFrameController.cpp cameraController.cpp) -set(CONSOLE console.cpp abstractCommand.cpp addUnitCommand.cpp addResourceCommand.cpp) +set(CONSOLE console.cpp abstractCommand.cpp addUnitCommand.cpp addResourceCommand.cpp addTechnologyCommand.cpp) set(CORE gameManager.cpp game.cpp defConfigs.cpp ${CONSOLE} ${CONTROLLERS}) set(PROJECTILES projectile.cpp cruiseMissile.cpp) set(FX fx.cpp) diff --git a/addTechnologyCommand.cpp b/addTechnologyCommand.cpp new file mode 100644 index 0000000..7ff5025 --- /dev/null +++ b/addTechnologyCommand.cpp @@ -0,0 +1,42 @@ +#include "addTechnologyCommand.h" +#include "game.h" +#include "player.h" + +#include + +#include + +namespace battleship{ + using namespace std; + using namespace gameBase; + + void AddTechnologyCommand::validate(){ + if(arguments.size() != 2) + return; + + playerId = atoi(arguments[0].c_str()); + int numPlayers = Game::getSingleton()->getNumPlayers(); + + if(!(0 <= playerId && playerId < numPlayers)) + return; + + sol::state_view SOL_LUA_VIEW = generateView(); + SOL_LUA_VIEW.script("numTechs = #technologies"); + int numTechs = SOL_LUA_VIEW["numTechs"]; + + techId = atoi(arguments[1].c_str()); + + if(!(0 <= techId && techId < numTechs)) + return; + } + + void AddTechnologyCommand::addTechnology(){ + Game::getSingleton()->getPlayer(playerId)->addTechnology(techId); + } + + void AddTechnologyCommand::execute(){ + AbstractCommand::handle(); + validate(); + addTechnology(); + } +} diff --git a/addTechnologyCommand.h b/addTechnologyCommand.h new file mode 100644 index 0000000..d3fb32c --- /dev/null +++ b/addTechnologyCommand.h @@ -0,0 +1,19 @@ +#ifndef ADD_TECHNOLOGY_H +#define ADD_TECHNOLOGY_H + +#include "abstractCommand.h" + +namespace battleship{ + class AddTechnologyCommand : public AbstractCommand{ + public: + AddTechnologyCommand(std::string argsStr) : AbstractCommand(argsStr){} + void execute(); + private: + void validate(); + void addTechnology(); + + int playerId, techId; + }; +} + +#endif diff --git a/console.cpp b/console.cpp index 421a745..58206f7 100755 --- a/console.cpp +++ b/console.cpp @@ -1,6 +1,7 @@ #include "console.h" #include "addUnitCommand.h" #include "addResourceCommand.h" +#include "addTechnologyCommand.h" using namespace std; @@ -18,5 +19,7 @@ namespace battleship{ AddUnitCommand(argsStr).execute(); else if(cmdName == "add-resource") AddResourceCommand(argsStr).execute(); + else if(cmdName == "add-technology") + AddTechnologyCommand(argsStr).execute(); } } From 309f967b2dc86a5ae12c3a669c2e955d6fd58bdd Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sun, 25 Feb 2024 13:47:23 +0200 Subject: [PATCH 04/13] cost property factored out into configs --- Assets/Scripts/GameObjects/Units/unitData.lua | 1 + researchStruct.cpp | 6 +++--- researchStruct.h | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Assets/Scripts/GameObjects/Units/unitData.lua b/Assets/Scripts/GameObjects/Units/unitData.lua index caee678..364ee66 100644 --- a/Assets/Scripts/GameObjects/Units/unitData.lua +++ b/Assets/Scripts/GameObjects/Units/unitData.lua @@ -496,6 +496,7 @@ units = { lineOfSight = 5, generationRate = 10000, generationSpeed = 10, + researchCost = 1, name = 'Lab', basePath = PATH .. structurePrefix .. 'Labs/', meshPath = 'lab.xml', diff --git a/researchStruct.cpp b/researchStruct.cpp index 9e6a241..b229a1c 100644 --- a/researchStruct.cpp +++ b/researchStruct.cpp @@ -10,15 +10,15 @@ namespace battleship{ sol::table unitTable = generateView()["units"][id + 1]; generationRate = unitTable["generationRate"]; generationSpeed = unitTable["generationSpeed"]; + researchCost = unitTable["researchCost"]; } void ResearchStruct::update(){ Structure::update(); - int cost = 1; - if(player->getRefineds() >= cost && canGenerateResearch()){ + if(player->getRefineds() >= researchCost && canGenerateResearch()){ player->addResearch(generationSpeed); - player->subtractRefineds(cost); + player->subtractRefineds(researchCost); lastGenTime = getTime(); } } diff --git a/researchStruct.h b/researchStruct.h index 66b4444..d102e8e 100644 --- a/researchStruct.h +++ b/researchStruct.h @@ -10,7 +10,7 @@ namespace battleship{ void update(); private: vb01::s64 lastGenTime = 0; - int generationRate, generationSpeed; + int researchCost, generationRate, generationSpeed; bool canGenerateResearch(){return vb01::getTime() - lastGenTime > generationRate;} void generateResearch(); From bce93977bd5bcc6295c8178d5269e379154f8a7e Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sun, 25 Feb 2024 15:19:10 +0200 Subject: [PATCH 05/13] technologies in posession improve unit abilities --- Assets/Scripts/Abilities/abilityData.lua | 22 +++++++++-- .../Scripts/Technologies/technologyData.lua | 2 +- ability.h | 31 +++++++++++++++ defConfigs.h | 1 + engineer.cpp | 4 +- extractor.cpp | 14 +++++-- extractor.h | 2 + game.cpp | 39 +++++++++++++++++-- game.h | 3 ++ projectile.cpp | 17 ++++---- resourceRover.cpp | 17 +++++--- resourceRover.h | 1 + unit.cpp | 9 ++++- vehicle.cpp | 9 ++++- 14 files changed, 142 insertions(+), 29 deletions(-) create mode 100644 ability.h diff --git a/Assets/Scripts/Abilities/abilityData.lua b/Assets/Scripts/Abilities/abilityData.lua index 0bef041..c2dd186 100644 --- a/Assets/Scripts/Abilities/abilityData.lua +++ b/Assets/Scripts/Abilities/abilityData.lua @@ -1,5 +1,19 @@ -AbilityType = {SPEED = 0} - -ablilities = { - {type = AbilityType.SPEED, ammount = .2, units = {UnitClass.WAR_MECH}} +AbilityType = { + SPEED = 0, + HEALTH = 1, + LINE_OF_SIGHT = 1, + MAX_TURN_ANGLE = 2, + DIRECT_HIT_DAMAGE = 3, + EXPLOSION_RADIUS = 4, + EXPLOSION_DAMAGE = 5, + CAPACITY = 6, + LOAD_RATE = 7, + LOAD_SPEED = 8, + DRAW_RATE = 9, + DRAW_SPEED = 10, + HACK_RANGE = 11 +} + +abilities = { + {type = AbilityType.SPEED, gameObjType = 0, ammount = .4, gameObjIds = {UnitId.WAR_MECH}} } diff --git a/Assets/Scripts/Technologies/technologyData.lua b/Assets/Scripts/Technologies/technologyData.lua index 9d34b9f..0c7324f 100644 --- a/Assets/Scripts/Technologies/technologyData.lua +++ b/Assets/Scripts/Technologies/technologyData.lua @@ -14,7 +14,7 @@ technologies = { description = '', parents = {}, children = {}, - abilities = {}, + abilities = {0}, }, { id = TechnologyId.EFT, diff --git a/ability.h b/ability.h new file mode 100644 index 0000000..d3c92b0 --- /dev/null +++ b/ability.h @@ -0,0 +1,31 @@ +#ifndef ABILITY_H +#define ABILITY_H + +#include + +namespace battleship{ + struct Ability{ + enum class Type{ + SPEED, + HEALTH, + LINE_OF_SIGHT, + MAX_TURN_ANGLE, + DIRECT_HIT_DAMAGE, + EXPLOSION_RADIUS, + EXPLOSION_DAMAGE, + CAPACITY, + LOAD_RATE, + LOAD_SPEED, + DRAW_RATE, + DRAW_SPEED, + HACK_RANGE + }; + + Type type; + float ammount; + int gameObjType; + std::vector gameObjIds; + }; +} + +#endif diff --git a/defConfigs.h b/defConfigs.h index ea9aabe..0bcf9ff 100755 --- a/defConfigs.h +++ b/defConfigs.h @@ -52,6 +52,7 @@ namespace battleship{ "Scripts/aiAgent.lua", "Scripts/Core/player.lua", "Scripts/Technologies/technologyData.lua", + "Scripts/Abilities/abilityData.lua", }; const static Bind staticBinds[numAppStates][maxStaticBinds]{ diff --git a/engineer.cpp b/engineer.cpp index b2015d8..36a11d6 100644 --- a/engineer.cpp +++ b/engineer.cpp @@ -16,7 +16,9 @@ namespace battleship{ using namespace gameBase; Engineer::Engineer(Player *player, int id, Vector3 pos, Quaternion rot, Unit::State state) : Vehicle(player, id, pos, rot, state){ - hackRange = generateView()["units"][id + 1]["hackRange"]; + Game *game = Game::getSingleton(); + vector currTechs = player->getTechnologies(); + hackRange = generateView()["units"][id + 1]["hackRange"]; hackRange += game->calcAbilFromTech(Ability::Type::HACK_RANGE, currTechs, (int)GameObject::type, id); Vector2 size = Vector2(lenHpBar, 10); hackStatusBackground = Unit::createBar(Vector2::VEC_ZERO, size, Vector4(0, 0, 0, 1)); diff --git a/extractor.cpp b/extractor.cpp index 19c5692..23fcb6a 100644 --- a/extractor.cpp +++ b/extractor.cpp @@ -27,10 +27,6 @@ namespace battleship{ } } - sol::table unitTable = generateView()["units"][id + 1]; - drawRate = unitTable["drawRate"]; - drawSpeed = unitTable["drawSpeed"]; - Vector2 size = Vector2(lenHpBar, 10); ammountBackground = Unit::createBar(Vector2::VEC_ZERO, size, Vector4(0, 0, 0, 1)); ammountForeground = Unit::createBar(Vector2::VEC_ZERO, size, Vector4(0, 0, 1, 1)); @@ -41,6 +37,16 @@ namespace battleship{ removeBar(ammountBackground); } + void Extractor::initProperties(){ + Structure::initProperties(); + Game *game = Game::getSingleton(); + vector currTechs = player->getTechnologies(); + + sol::table unitTable = generateView()["units"][id + 1]; + drawRate = unitTable["drawRate"]; drawRate += game->calcAbilFromTech(Ability::Type::DRAW_RATE, currTechs, (int)GameObject::type, id); + drawSpeed = unitTable["drawSpeed"]; drawSpeed += game->calcAbilFromTech(Ability::Type::DRAW_SPEED, currTechs, (int)GameObject::type, id); + } + void Extractor::update(){ Structure::update(); diff --git a/extractor.h b/extractor.h index a070765..0002eb4 100644 --- a/extractor.h +++ b/extractor.h @@ -17,6 +17,8 @@ namespace battleship{ bool canDraw(){return vb01::getTime() - lastDrawTime > drawRate;} inline ResourceDeposit* getDeposit(){return deposit;} private: + void initProperties(); + int drawSpeed, drawRate; vb01::s64 lastDrawTime = 0; vb01::Node *ammountBackground = nullptr, *ammountForeground = nullptr; diff --git a/game.cpp b/game.cpp index 57eea48..9d65e11 100644 --- a/game.cpp +++ b/game.cpp @@ -7,6 +7,8 @@ #include "concreteGuiManager.h" #include "defConfigs.h" +#include + #include #include @@ -215,11 +217,11 @@ namespace battleship{ unit->halt(); } - vector Game::parseTechTable(int tid, string techKey, string numVarKey, string varKey){ + vector Game::parseTechTable(int tid, string key, string numVarKey, string varKey){ sol::state_view SOL_LUA_VIEW = generateView(); - SOL_LUA_VIEW.script(numVarKey + " = #" + techKey + "[" + to_string(tid + 1) + "]." + varKey); + SOL_LUA_VIEW.script(numVarKey + " = #" + key + "[" + to_string(tid + 1) + "]." + varKey); int numVar = SOL_LUA_VIEW[numVarKey]; - sol::table techTable = SOL_LUA_VIEW[techKey][tid + 1]; + sol::table techTable = SOL_LUA_VIEW[key][tid + 1]; vector varVec; @@ -252,5 +254,36 @@ namespace battleship{ technologies.push_back(t); } + + techKey = "abilities"; + SOL_LUA_VIEW.script("numAbilities = #" + techKey); + int numAbilities = SOL_LUA_VIEW["numAbilities"]; + + for(int i = 0; i < numAbilities; i++){ + sol::table techTable = SOL_LUA_VIEW[techKey][i + 1]; + + Ability ability; + ability.type = techTable["type"]; + ability.ammount = techTable["ammount"]; + ability.gameObjType = techTable["gameObjType"]; + ability.gameObjIds = parseTechTable(i, techKey, "numGameObjIds", "gameObjIds"); + abilities.push_back(ability); + } + } + + float Game::calcAbilFromTech(Ability::Type type, vector techResearch, int gameObjType, int unitId){ + float ammount = 0; + + for(int techId : techResearch) + for(int abilId : technologies[techId].abilities) + if( + abilities[abilId].type == type && + abilities[abilId].gameObjType == gameObjType && + find(abilities[abilId].gameObjIds.begin(), abilities[abilId].gameObjIds.end(), unitId) != abilities[abilId].gameObjIds.end() + ){ + ammount += abilities[abilId].ammount; + } + + return ammount; } } diff --git a/game.h b/game.h index f28e77a..294f3ee 100644 --- a/game.h +++ b/game.h @@ -3,6 +3,7 @@ #include "fx.h" #include "technology.h" +#include "ability.h" #include @@ -25,6 +26,7 @@ namespace battleship{ void explode(vb01::Vector3, int, float, sf::Sound*); void changeUnitPlayer(Unit*, Player*); void initTechnologies(); + float calcAbilFromTech(Ability::Type, std::vector, int, int); inline void addFx(Fx f){fx.push_back(f);} inline void addPlayer(Player *pl){players.push_back(pl);} inline std::vector& getPlayers(){return players;} @@ -39,6 +41,7 @@ namespace battleship{ bool paused = false, ended = false; std::vector fx; std::vector technologies; + std::vector abilities; std::vector players; }; } diff --git a/projectile.cpp b/projectile.cpp index b5a39a8..e362ca5 100755 --- a/projectile.cpp +++ b/projectile.cpp @@ -1,20 +1,21 @@ #include #include #include -#include -#include #include +#include +#include #include +#include "fx.h" #include "game.h" #include "unit.h" #include "util.h" +#include "player.h" #include "projectile.h" -#include "resourceDeposit.h" #include "defConfigs.h" +#include "resourceDeposit.h" #include "inGameAppState.h" -#include "fx.h" using namespace std; using namespace vb01; @@ -51,14 +52,16 @@ namespace battleship{ void Projectile::initProperties(){ GameObject::initProperties(); + Game *game = Game::getSingleton(); + vector currTechs = player->getTechnologies(); sol::table projTable = generateView()[GameObject::getGameObjTableName()][id + 1]; rayLength = projTable["rayLength"]; - directHitDamage = projTable["directHitDamage"]; + directHitDamage = projTable["directHitDamage"]; directHitDamage += game->calcAbilFromTech(Ability::Type::DIRECT_HIT_DAMAGE, currTechs, (int)GameObject::type, id); string explKey = "explosion"; - explosionDamage = projTable[explKey]["damage"]; - explosionRadius = projTable[explKey]["radius"]; + explosionDamage = projTable[explKey]["damage"]; explosionDamage += game->calcAbilFromTech(Ability::Type::EXPLOSION_DAMAGE, currTechs, (int)GameObject::type, id); + explosionRadius = projTable[explKey]["radius"]; explosionRadius += game->calcAbilFromTech(Ability::Type::EXPLOSION_RADIUS, currTechs, (int)GameObject::type, id); speed = projTable["speed"]; rotAngle = projTable["rotAngle"].get_or(0.0); } diff --git a/resourceRover.cpp b/resourceRover.cpp index d507268..1d32d55 100644 --- a/resourceRover.cpp +++ b/resourceRover.cpp @@ -1,6 +1,7 @@ #include "resourceRover.h" #include "resourceDeposit.h" #include "map.h" +#include "game.h" #include "player.h" #include "extractor.h" #include "structure.h" @@ -14,11 +15,6 @@ namespace battleship{ using namespace gameBase; ResourceRover::ResourceRover(Player *player, int id, Vector3 pos, Quaternion rot, Unit::State state) : Vehicle(player, id, pos, rot, state) { - sol::table unitTable = generateView()["units"][id + 1]; - capacity = unitTable["capacity"]; - loadSpeed = unitTable["loadSpeed"]; - loadRate = unitTable["loadRate"]; - Vector2 size = Vector2(lenHpBar, 10); loadBackground = Unit::createBar(Vector2::VEC_ZERO, size, Vector4(0, 0, 0, 1)); loadForeground = Unit::createBar(Vector2::VEC_ZERO, size, Vector4(1, 1, 0, 1)); @@ -29,6 +25,17 @@ namespace battleship{ removeBar(loadBackground); } + void ResourceRover::initProperties(){ + Vehicle::initProperties(); + Game *game = Game::getSingleton(); + vector currTechs = player->getTechnologies(); + + sol::table unitTable = generateView()["units"][id + 1]; + capacity = unitTable["capacity"]; capacity += game->calcAbilFromTech(Ability::Type::CAPACITY, currTechs, (int)GameObject::type, id); + loadSpeed = unitTable["loadSpeed"]; loadSpeed += game->calcAbilFromTech(Ability::Type::LOAD_SPEED, currTechs, (int)GameObject::type, id); + loadRate = unitTable["loadRate"]; loadRate += game->calcAbilFromTech(Ability::Type::LOAD_RATE, currTechs, (int)GameObject::type, id); + } + void ResourceRover::supply(Order order){ float minDist = .5 * Map::getSingleton()->getCellSize().x; diff --git a/resourceRover.h b/resourceRover.h index b8d4cee..bd1c637 100644 --- a/resourceRover.h +++ b/resourceRover.h @@ -15,6 +15,7 @@ namespace battleship{ ~ResourceRover(); void update(); private: + void initProperties(); void supply(Order); Unit* getClosestUnit(std::vector); inline bool canLoad(){return vb01::getTime() - lastLoadTime > loadRate && load < capacity;} diff --git a/unit.cpp b/unit.cpp index f111577..2c34719 100755 --- a/unit.cpp +++ b/unit.cpp @@ -18,6 +18,7 @@ #include "activeGameState.h" #include "defConfigs.h" #include "pathfinder.h" +#include "ability.h" using namespace glm; using namespace vb01; @@ -126,12 +127,16 @@ namespace battleship{ sol::state_view SOL_LUA_VIEW = generateView(); string objType = GameObject::getGameObjTableName(); sol::table unitTable = SOL_LUA_VIEW[objType][id + 1]; + + Game *game = Game::getSingleton(); + vector currTechs = player->getTechnologies(); + string name = unitTable["name"]; - health = unitTable["health"]; + health = unitTable["health"]; health += game->calcAbilFromTech(Ability::Type::HEALTH, currTechs, (int)GameObject::type, id); vehicle = unitTable["isVehicle"]; maxHealth = health; - lineOfSight = unitTable["lineOfSight"]; + lineOfSight = unitTable["lineOfSight"]; lineOfSight += game->calcAbilFromTech(Ability::Type::LINE_OF_SIGHT, currTechs, (int)GameObject::type, id); unitClass = (UnitClass)unitTable["unitClass"]; type = (UnitType)unitTable["unitType"]; diff --git a/vehicle.cpp b/vehicle.cpp index e95470f..45bd04a 100644 --- a/vehicle.cpp +++ b/vehicle.cpp @@ -10,6 +10,8 @@ #include "vehicle.h" #include "pathfinder.h" +#include "player.h" +#include "game.h" #include "map.h" using namespace gameBase; @@ -83,9 +85,12 @@ namespace battleship{ } void Vehicle::initProperties(){ + Game *game = Game::getSingleton(); + vector currTechs = player->getTechnologies(); + sol::table unitTable = generateView()[GameObject::getGameObjTableName()][id + 1]; - maxTurnAngle = unitTable["maxTurnAngle"]; - speed = unitTable["speed"]; + 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"]; garrisonCategory = unitTable["garrisonCategory"]; } From 43ccac92d47f6c3fae1a0fa1b11eed95c03108a6 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sun, 25 Feb 2024 16:46:52 +0200 Subject: [PATCH 06/13] structures work only once complete research structures research when they have min 30% HP --- buildableUnit.h | 13 +++++++++++++ factory.cpp | 2 ++ pointDefense.cpp | 2 ++ researchStruct.cpp | 4 +++- resourceRover.cpp | 4 ++-- structure.h | 1 + 6 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 buildableUnit.h diff --git a/buildableUnit.h b/buildableUnit.h new file mode 100644 index 0000000..772a3b6 --- /dev/null +++ b/buildableUnit.h @@ -0,0 +1,13 @@ +#ifndef BUILDABLE_UNIT_H +#define BUILDABLE_UNIT_H + +namespace battleship{ + struct BuildableUnit{ + int id; + bool buildable; + + BuildableUnit(int i, bool build) : id(i), buildable(build){} + }; +} + +#endif diff --git a/factory.cpp b/factory.cpp index dfe72c1..4554904 100644 --- a/factory.cpp +++ b/factory.cpp @@ -18,6 +18,8 @@ namespace battleship{ void Factory::update(){ Structure::update(); + if(!isComplete()) return; + if(!unitQueue.empty()) train(); } diff --git a/pointDefense.cpp b/pointDefense.cpp index 42da4ff..e21c551 100644 --- a/pointDefense.cpp +++ b/pointDefense.cpp @@ -8,6 +8,8 @@ namespace battleship{ } void PointDefense::attack(Order order){ + if(!isComplete()) return; + Unit *targUnit = order.targets[0].unit; Vector3 targDir = (targUnit ? targUnit->getPos() : order.targets[0].pos) - pos; diff --git a/researchStruct.cpp b/researchStruct.cpp index b229a1c..a7da75c 100644 --- a/researchStruct.cpp +++ b/researchStruct.cpp @@ -16,7 +16,9 @@ namespace battleship{ void ResearchStruct::update(){ Structure::update(); - if(player->getRefineds() >= researchCost && canGenerateResearch()){ + if(!isComplete()) return; + + if(health > .3 * maxHealth && player->getRefineds() >= researchCost && canGenerateResearch()){ player->addResearch(generationSpeed); player->subtractRefineds(researchCost); lastGenTime = getTime(); diff --git a/resourceRover.cpp b/resourceRover.cpp index 1d32d55..a7d51b0 100644 --- a/resourceRover.cpp +++ b/resourceRover.cpp @@ -109,7 +109,7 @@ namespace battleship{ int minDistId = -1; for(int i = 0; i < structs.size(); i++) - if(structs[i]->getBuildStatus() == 100){ + if(structs[i]->isComplete()){ minDistId = i; break; } @@ -117,7 +117,7 @@ namespace battleship{ if(minDistId == -1) return nullptr; for(int i = 0; i < structs.size(); i++) - if(structs[i]->getBuildStatus() == 100 && structs[minDistId]->getPos().getDistanceFrom(pos) > structs[i]->getPos().getDistanceFrom(pos)) + if(structs[i]->isComplete() && structs[minDistId]->getPos().getDistanceFrom(pos) > structs[i]->getPos().getDistanceFrom(pos)) minDistId = i; return structs[minDistId]; diff --git a/structure.h b/structure.h index 10bd58a..da01ffa 100644 --- a/structure.h +++ b/structure.h @@ -13,6 +13,7 @@ namespace battleship{ Structure(Player*, int, vb01::Vector3, vb01::Quaternion, int = 0, Unit::State = Unit::State::STAND_GROUND); ~Structure(); virtual void update(); + inline bool isComplete(){return buildStatus == 100;} inline int getBuildStatus(){return buildStatus;} inline void incrementBuildStatus(){buildStatus++;} private: From b9f01da8441d3750facf66d9424c2f9c51c02274 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sun, 25 Feb 2024 17:21:22 +0200 Subject: [PATCH 07/13] tech researching --- researchStruct.cpp | 21 ++++++++++++++++----- researchStruct.h | 9 +++++---- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/researchStruct.cpp b/researchStruct.cpp index a7da75c..8a725f4 100644 --- a/researchStruct.cpp +++ b/researchStruct.cpp @@ -18,13 +18,24 @@ namespace battleship{ if(!isComplete()) return; - if(health > .3 * maxHealth && player->getRefineds() >= researchCost && canGenerateResearch()){ + if(researchQueue.empty() && health > .3 * maxHealth && player->getRefineds() >= researchCost && canUpdateResearch()){ player->addResearch(generationSpeed); player->subtractRefineds(researchCost); - lastGenTime = getTime(); + lastUpdateTime = getTime(); + } + else if(!researchQueue.empty()){ + int techCost = Game::getSingleton()->getTechnology(researchQueue[0]).cost; + int playerResearch = player->getResearch(); + + if(techCost > playerResearch && canUpdateResearch()){ + researchStatus += (int)((float)playerResearch / techCost); + lastUpdateTime = getTime(); + } + else if(researchStatus >= 100 || techCost <= playerResearch){ + player->addTechnology(researchQueue[0]); + researchQueue.erase(researchQueue.begin()); + researchStatus = 0; + } } } - - void ResearchStruct::researchTechnology(int techId){ - } } diff --git a/researchStruct.h b/researchStruct.h index d102e8e..21e085f 100644 --- a/researchStruct.h +++ b/researchStruct.h @@ -8,13 +8,14 @@ namespace battleship{ public: ResearchStruct(Player*, int, vb01::Vector3, vb01::Quaternion, int = 0, Unit::State = Unit::State::STAND_GROUND); void update(); + inline void appendToQueue(int tid){researchQueue.push_back(tid);} private: - vb01::s64 lastGenTime = 0; - int researchCost, generationRate, generationSpeed; + vb01::s64 lastUpdateTime = 0; + int researchCost, generationRate, generationSpeed, researchStatus = 0; + std::vector researchQueue; - bool canGenerateResearch(){return vb01::getTime() - lastGenTime > generationRate;} + bool canUpdateResearch(){return vb01::getTime() - lastGenTime > generationRate;} void generateResearch(); - void researchTechnology(int); }; } From 7194db47ffd7199569156a068dda4973c3324f57 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sun, 3 Mar 2024 14:42:16 +0200 Subject: [PATCH 08/13] minor fixes and improvements --- Assets/Scripts/Abilities/abilityData.lua | 6 ++++-- Assets/Scripts/Technologies/technologyData.lua | 10 +++++----- game.cpp | 3 ++- game.h | 1 + player.cpp | 1 + player.h | 1 + researchStruct.cpp | 1 + researchStruct.h | 2 +- 8 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Assets/Scripts/Abilities/abilityData.lua b/Assets/Scripts/Abilities/abilityData.lua index c2dd186..d3d3ab5 100644 --- a/Assets/Scripts/Abilities/abilityData.lua +++ b/Assets/Scripts/Abilities/abilityData.lua @@ -11,9 +11,11 @@ AbilityType = { LOAD_SPEED = 8, DRAW_RATE = 9, DRAW_SPEED = 10, - HACK_RANGE = 11 + HACK_RANGE = 11, + UNIT_UNLOCK = 12 } abilities = { - {type = AbilityType.SPEED, gameObjType = 0, ammount = .4, gameObjIds = {UnitId.WAR_MECH}} + {type = AbilityType.SPEED, gameObjType = 0, ammount = .4, gameObjIds = {UnitId.WAR_MECH}}, + {type = AbilityType.UNIT_UNLOCK, gameObjType = 0, gameObjIds = {UnitId.WAR_MECH}}, } diff --git a/Assets/Scripts/Technologies/technologyData.lua b/Assets/Scripts/Technologies/technologyData.lua index 0c7324f..74b412f 100644 --- a/Assets/Scripts/Technologies/technologyData.lua +++ b/Assets/Scripts/Technologies/technologyData.lua @@ -1,4 +1,4 @@ -TechnologyId = { +TechId = { APT = 0, EFT = 1, PCT = 2, @@ -7,7 +7,7 @@ TechnologyId = { technologies = { { - id = TechnologyId.APT, + id = TechId.APT, name = 'Advanced power technology', cost = 1000, icon = '', @@ -17,7 +17,7 @@ technologies = { abilities = {0}, }, { - id = TechnologyId.EFT, + id = TechId.EFT, name = 'Energy field technology', cost = 1000, icon = '', @@ -27,7 +27,7 @@ technologies = { abilities = {}, }, { - id = TechnologyId.PCT, + id = TechId.PCT, name = 'Plasma casting technology', cost = 1000, icon = '', @@ -37,7 +37,7 @@ technologies = { abilities = {}, }, { - id = TechnologyId.FPT, + id = TechId.FPT, name = 'Fusion power technology', cost = 1000, icon = '', diff --git a/game.cpp b/game.cpp index 9d65e11..fe17b11 100644 --- a/game.cpp +++ b/game.cpp @@ -231,6 +231,7 @@ namespace battleship{ return varVec; } + //TODO clean this method up void Game::initTechnologies(){ technologies.clear(); @@ -264,7 +265,7 @@ namespace battleship{ Ability ability; ability.type = techTable["type"]; - ability.ammount = techTable["ammount"]; + ability.ammount = techTable["ammount"].get_or(0); ability.gameObjType = techTable["gameObjType"]; ability.gameObjIds = parseTechTable(i, techKey, "numGameObjIds", "gameObjIds"); abilities.push_back(ability); diff --git a/game.h b/game.h index 294f3ee..af76b46 100644 --- a/game.h +++ b/game.h @@ -32,6 +32,7 @@ namespace battleship{ inline std::vector& getPlayers(){return players;} inline Player* getPlayer(int id){return players[id];} inline int getNumPlayers(){return players.size();} + inline Technology getTechnology(int id){return technologies[id];} private: Game(){} void resetLuaGameObjects(); diff --git a/player.cpp b/player.cpp index 26faa92..2195442 100755 --- a/player.cpp +++ b/player.cpp @@ -2,6 +2,7 @@ #include "player.h" #include "structure.h" +#include "projectile.h" #include "stateManager.h" #include "activeGameState.h" #include "resourceDeposit.h" diff --git a/player.h b/player.h index d8d5666..a6a8a2e 100755 --- a/player.h +++ b/player.h @@ -9,6 +9,7 @@ namespace battleship{ class ResourceDeposit; class Projectile; + class Unit; class Player { public: diff --git a/researchStruct.cpp b/researchStruct.cpp index 8a725f4..c6848c3 100644 --- a/researchStruct.cpp +++ b/researchStruct.cpp @@ -1,5 +1,6 @@ #include "researchStruct.h" #include "player.h" +#include "game.h" namespace battleship{ using namespace std; diff --git a/researchStruct.h b/researchStruct.h index 21e085f..49ebc45 100644 --- a/researchStruct.h +++ b/researchStruct.h @@ -14,7 +14,7 @@ namespace battleship{ int researchCost, generationRate, generationSpeed, researchStatus = 0; std::vector researchQueue; - bool canUpdateResearch(){return vb01::getTime() - lastGenTime > generationRate;} + bool canUpdateResearch(){return vb01::getTime() - lastUpdateTime > generationRate;} void generateResearch(); }; } From 74515d06e1d34e5c035f59436cc02a188831f476 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sun, 3 Mar 2024 15:47:09 +0200 Subject: [PATCH 09/13] factories and engineers produce and build units by their specific buildable unit tables --- Assets/Scripts/Core/player.lua | 20 +++++----- Assets/Scripts/GameObjects/Units/unitData.lua | 38 +++++++++++++++++++ Assets/Scripts/Gui/engineerCommands.lua | 6 --- Assets/Scripts/Gui/fortCommands.lua | 3 +- Assets/Scripts/Gui/landFactoryCommands.lua | 15 +++++--- Assets/Scripts/Gui/navalFactoryCommands.lua | 4 +- activeGameState.cpp | 15 +++----- activeGameState.h | 1 + buildButton.cpp | 21 +++++++--- buildButton.h | 4 +- concreteGuiManager.cpp | 20 ++++++---- factory.cpp | 14 +++++++ factory.h | 8 ++-- trainButton.cpp | 15 ++++---- trainButton.h | 2 +- unit.cpp | 16 ++++++++ unit.h | 14 ++++--- unitButton.cpp | 2 +- unitButton.h | 3 +- 19 files changed, 150 insertions(+), 71 deletions(-) diff --git a/Assets/Scripts/Core/player.lua b/Assets/Scripts/Core/player.lua index cf4ba0f..748e28e 100644 --- a/Assets/Scripts/Core/player.lua +++ b/Assets/Scripts/Core/player.lua @@ -38,7 +38,7 @@ function Player:trainEngineers() dirToCenter = Vector3:new(0, 0, 0):subtr(fort:getPos()):norm() while #fort:getQueue() + #self:getUnitsByClass(UnitClass.ENGINEER, -1) < self.numStartEngis do - fort:appendToQueue(UnitId.ENGINEER) + fort:appendToQueue(0) end return #self:getUnitsByClass(UnitClass.ENGINEER, -1) == self.numStartEngis @@ -132,7 +132,7 @@ function Player:buildHarvester() factory = landFactories[1]:toFactory() if #factory:getQueue() == 0 then - factory:appendToQueue(UnitId.RESOURCE_ROVER) + factory:appendToQueue(3) end return false @@ -157,10 +157,10 @@ function Player:startHarvesting() return true end -function Player:buildTaskforceUnitGroup(numUnits, currNumUnits, factory, unitId) +function Player:buildTaskforceUnitGroup(numUnits, currNumUnits, factory, buId) if currNumUnits < numUnits then for i = 1, numUnits - currNumUnits do - factory:appendToQueue(unitId) + factory:appendToQueue(buId) end end end @@ -175,9 +175,9 @@ function Player:buildTaskforce() currLandFactories = self:getUnitsByClass(UnitClass.LAND_FACTORY, -1) for i = 1, #currLandFactories do - currNumWarMechs = currNumWarMechs + currLandFactories[i]:toFactory():getNumQueueUnitsById(UnitId.WAR_MECH) - currNumTanks = currNumTanks + currLandFactories[i]:toFactory():getNumQueueUnitsById(UnitId.TANK) - currNumArtillery = currNumArtillery + currLandFactories[i]:toFactory():getNumQueueUnitsById(UnitId.ARTILLERY) + currNumWarMechs = currNumWarMechs + currLandFactories[i]:toFactory():getNumQueueUnitsById(0) + currNumTanks = currNumTanks + currLandFactories[i]:toFactory():getNumQueueUnitsById(1) + currNumArtillery = currNumArtillery + currLandFactories[i]:toFactory():getNumQueueUnitsById(2) end numWarMechs = self.numDefWarMechs + self.numTaskForceWarMechs @@ -190,9 +190,9 @@ function Player:buildTaskforce() landFactory = currLandFactories[1]:toFactory() - self:buildTaskforceUnitGroup(numWarMechs, currNumWarMechs, landFactory, UnitId.WAR_MECH) - self:buildTaskforceUnitGroup(numTanks, currNumTanks, landFactory, UnitId.TANK) - self:buildTaskforceUnitGroup(numArtillery, currNumArtillery, landFactory, UnitId.ARTILLERY) + self:buildTaskforceUnitGroup(numWarMechs, currNumWarMechs, landFactory, 0) + self:buildTaskforceUnitGroup(numTanks, currNumTanks, landFactory, 1) + self:buildTaskforceUnitGroup(numArtillery, currNumArtillery, landFactory, 2) return false end diff --git a/Assets/Scripts/GameObjects/Units/unitData.lua b/Assets/Scripts/GameObjects/Units/unitData.lua index 364ee66..27d0022 100644 --- a/Assets/Scripts/GameObjects/Units/unitData.lua +++ b/Assets/Scripts/GameObjects/Units/unitData.lua @@ -73,6 +73,7 @@ units = { destinationOffset = .1, anglePrecision = .1, maxTurnAngle = .1, + guiScreen = '', garrisonCategory = 1 }, { @@ -96,6 +97,7 @@ units = { destinationOffset = .1, anglePrecision = .1, maxTurnAngle = .1, + guiScreen = '', garrisonCategory = 2 }, { @@ -119,12 +121,21 @@ units = { destinationOffset = .1, anglePrecision = .1, maxTurnAngle = .1, + guiScreen = '', garrisonCategory = 2 }, { weapons = { {type = WeaponClass.HITSCAN, rateOfFire = 2000, fireSfx = PATH .. 'Sounds/Units/WarMechs/fire.ogg', damage = 20, maxRange = 8}, }, + buildableUnits = { + {id = UnitId.LAND_FACTORY, buildable = true}, + {id = UnitId.NAVAL_FACTORY, buildable = true}, + {id = UnitId.MARKET, buildable = true}, + {id = UnitId.LAB, buildable = true}, + {id = UnitId.POINT_DEFENSE, buildable = true}, + {id = UnitId.FORT, buildable = true}, + }, unitClass = UnitClass.ENGINEER, unitType = UnitType.HOVER, armor = {ArmorType.MECHANIC}, @@ -140,6 +151,7 @@ units = { name = 'Engineer', basePath = PATH .. vehiclePrefix .. 'Engineers/', meshPath = 'engineer.xml', + guiScreen = 'engineerCommands.lua', selectionSfx = PATH .. 'Sounds/Units/Engineers/selection.ogg', deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg', speed = .1, @@ -169,6 +181,7 @@ units = { destinationOffset = .1, anglePrecision = .1, maxTurnAngle = .1, + guiScreen = '', garrisonCategory = 3 }, { @@ -193,6 +206,7 @@ units = { destinationOffset = .1, anglePrecision = .1, maxTurnAngle = .1, + guiScreen = '', garrisonCategory = 3 }, { @@ -219,6 +233,7 @@ units = { destinationOffset = .1, anglePrecision = .1, maxTurnAngle = .1, + guiScreen = '', garrisonCategory = 3 }, { @@ -242,6 +257,7 @@ units = { destinationOffset = .1, anglePrecision = .1, maxTurnAngle = .1, + guiScreen = '', garrisonCategory = 3 }, { @@ -266,6 +282,7 @@ units = { destinationOffset = .1, anglePrecision = .1, maxTurnAngle = .1, + guiScreen = '', garrisonCategory = 3 }, { @@ -289,6 +306,7 @@ units = { destinationOffset = .1, anglePrecision = .1, maxTurnAngle = .1, + guiScreen = '', garrisonCategory = 3 }, { @@ -312,6 +330,7 @@ units = { destinationOffset = .1, anglePrecision = .1, maxTurnAngle = .1, + guiScreen = '', garrisonCategory = 3 }, { @@ -334,6 +353,7 @@ units = { destinationOffset = .1, anglePrecision = .1, maxTurnAngle = .1, + guiScreen = '', garrisonCategory = 3 }, { @@ -365,6 +385,7 @@ units = { destinationOffset = .1, anglePrecision = .1, maxTurnAngle = .1, + guiScreen = '', garrisonCategory = 3 }, { @@ -403,6 +424,7 @@ units = { destinationOffset = .1, anglePrecision = .1, maxTurnAngle = .1, + guiScreen = '', garrisonCategory = 3 }, { @@ -434,9 +456,16 @@ units = { destinationOffset = .1, anglePrecision = .1, maxTurnAngle = .1, + guiScreen = '', garrisonCategory = 3 }, { + buildableUnits = { + {id = UnitId.WAR_MECH, buildable = true}, + {id = UnitId.TANK, buildable = true}, + {id = UnitId.ARTILLERY, buildable = true}, + {id = UnitId.RESOURCE_ROVER, buildable = true} + }, unitClass = UnitClass.LAND_FACTORY, unitType = UnitType.LAND, isVehicle = false, @@ -449,6 +478,7 @@ units = { name = 'Land factory', basePath = PATH .. structurePrefix .. 'LandFactories/', meshPath = 'landFactory.xml', + guiScreen = 'landFactoryCommands.lua', selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg', deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg', }, @@ -465,6 +495,7 @@ units = { name = 'Naval factory', basePath = PATH .. structurePrefix .. 'NavalFactories/', meshPath = 'navalFactory.xml', + guiScreen = 'navalFactoryCommands.lua', selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg', deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg', }, @@ -482,6 +513,7 @@ units = { basePath = PATH .. structurePrefix .. 'Markets/', meshPath = 'market.xml', selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg', + guiScreen = '', deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg', }, { @@ -500,6 +532,7 @@ units = { name = 'Lab', basePath = PATH .. structurePrefix .. 'Labs/', meshPath = 'lab.xml', + guiScreen = '', selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg', deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg', }, @@ -518,6 +551,7 @@ units = { basePath = PATH .. structurePrefix .. 'PointDefenses/', meshPath = 'pointDefense.xml', selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg', + guiScreen = '', deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg', }, { @@ -536,6 +570,7 @@ units = { basePath = PATH .. structurePrefix .. 'Extractors/', meshPath = 'extractor.xml', selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg', + guiScreen = '', deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg', }, { @@ -551,10 +586,12 @@ units = { name = 'Refinery', basePath = PATH .. structurePrefix .. 'Refineries/', meshPath = 'refinery.xml', + guiScreen = '', selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg', deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg', }, { + buildableUnits = {{id = UnitId.ENGINEER, buildable = true}}, unitClass = UnitClass.FORT, unitType = UnitType.LAND, isVehicle = false, @@ -567,6 +604,7 @@ units = { name = 'Fort', basePath = PATH .. structurePrefix .. 'Forts/', meshPath = 'fort.xml', + guiScreen = 'fortCommands.lua', selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg', deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg', }, diff --git a/Assets/Scripts/Gui/engineerCommands.lua b/Assets/Scripts/Gui/engineerCommands.lua index 8fe31c5..d9cd565 100644 --- a/Assets/Scripts/Gui/engineerCommands.lua +++ b/Assets/Scripts/Gui/engineerCommands.lua @@ -9,7 +9,6 @@ gui = { guiType = GuiType.BUTTON, buttonType = ButtonType.BUILD, trigger = 76, - structureId = UnitId.LAND_FACTORY }, { pos = {x = res.x - Size.x - 200, y = res.y - 200}, @@ -18,7 +17,6 @@ gui = { guiType = GuiType.BUTTON, buttonType = ButtonType.BUILD, trigger = 78, - structureId = UnitId.NAVAL_FACTORY }, { pos = {x = res.x - 2 * Size.x - 200, y = res.y - 200}, @@ -27,7 +25,6 @@ gui = { guiType = GuiType.BUTTON, buttonType = ButtonType.BUILD, trigger = 77, - structureId = UnitId.MARKET }, { pos = {x = res.x - 3 * Size.x - 200, y = res.y - 200}, @@ -36,7 +33,6 @@ gui = { guiType = GuiType.BUTTON, buttonType = ButtonType.BUILD, trigger = 84, - structureId = UnitId.LAB }, { pos = {x = res.x - 4 * Size.x - 200, y = res.y - 200}, @@ -45,7 +41,6 @@ gui = { guiType = GuiType.BUTTON, buttonType = ButtonType.BUILD, trigger = 68, - structureId = UnitId.POINT_DEFENSE }, { pos = {x = res.x - 5 * Size.x - 200, y = res.y - 200}, @@ -54,6 +49,5 @@ gui = { guiType = GuiType.BUTTON, buttonType = ButtonType.BUILD, trigger = 70, - structureId = UnitId.FORT }, } diff --git a/Assets/Scripts/Gui/fortCommands.lua b/Assets/Scripts/Gui/fortCommands.lua index a9f985e..2600775 100644 --- a/Assets/Scripts/Gui/fortCommands.lua +++ b/Assets/Scripts/Gui/fortCommands.lua @@ -8,7 +8,6 @@ gui = { imagePath = '', guiType = GuiType.BUTTON, buttonType = ButtonType.FORT_TRAIN, - trigger = 82, - unitId = UnitId.ENGINEER + trigger = 82 }, } diff --git a/Assets/Scripts/Gui/landFactoryCommands.lua b/Assets/Scripts/Gui/landFactoryCommands.lua index abece5c..8ad889f 100644 --- a/Assets/Scripts/Gui/landFactoryCommands.lua +++ b/Assets/Scripts/Gui/landFactoryCommands.lua @@ -1,4 +1,3 @@ -numGui = 2 res = graphics.resolution Size = {x = 100, y = 100} @@ -9,8 +8,7 @@ gui = { imagePath = '', guiType = GuiType.BUTTON, buttonType = ButtonType.LAND_FACTORY_TRAIN, - trigger = 84, - unitId = UnitId.TANK + trigger = 87 }, { pos = {x = res.x - Size.x - 200, y = res.y - 200}, @@ -18,7 +16,14 @@ gui = { imagePath = '', guiType = GuiType.BUTTON, buttonType = ButtonType.LAND_FACTORY_TRAIN, - trigger = 65, - unitId = UnitId.ARTILLERY + trigger = 84 + }, + { + pos = {x = res.x - 2 * Size.x - 200, y = res.y - 200}, + size = Size, + imagePath = '', + guiType = GuiType.BUTTON, + buttonType = ButtonType.LAND_FACTORY_TRAIN, + trigger = 65 } } diff --git a/Assets/Scripts/Gui/navalFactoryCommands.lua b/Assets/Scripts/Gui/navalFactoryCommands.lua index 2ffedbd..652031d 100644 --- a/Assets/Scripts/Gui/navalFactoryCommands.lua +++ b/Assets/Scripts/Gui/navalFactoryCommands.lua @@ -1,4 +1,3 @@ -numGui = 1 res = graphics.resolution gui = { @@ -8,7 +7,6 @@ gui = { imagePath = '', guiType = GuiType.BUTTON, buttonType = ButtonType.NAVAL_FACTORY_TRAIN, - trigger = 66, - unitId = UnitId.SCOUT_TRANSPORT + trigger = 66 } } diff --git a/activeGameState.cpp b/activeGameState.cpp index 4692a9f..8cbdb43 100755 --- a/activeGameState.cpp +++ b/activeGameState.cpp @@ -161,6 +161,7 @@ namespace battleship{ ConcreteGuiManager::getSingleton()->removeAllButtons(); buttons.clear(); + unitGuiScreen = ""; } bool ActiveGameState::selectedUnitsAmongst(vector units){ @@ -193,6 +194,7 @@ namespace battleship{ guiManager->getText("wealth"), guiManager->getText("research") }; + vector selUnits = mainPlayer->getSelectedUnits(); for (Unit *u : units) { @@ -200,16 +202,11 @@ namespace battleship{ Vector3 dragboxSize = ((Quad*)dragboxNode->getMesh(0))->getSize(); Vector3 dragboxOrigin = dragboxNode->getPosition(), dragboxEnd = dragboxOrigin + dragboxSize; Vector2 pos = u->getScreenPos(); + string guiScreen = u->getBuildableUnitGuiScreen(); - if(buttons.empty()){ - if(selectedUnitsAmongst(mainPlayer->getUnitsByClass(UnitClass::ENGINEER))) - guiManager->readLuaScreenScript("engineerCommands.lua", buttons, listboxes, checkboxes, sliders, textboxes, guiRects, texts); - else if(selectedUnitsAmongst(mainPlayer->getUnitsByClass(UnitClass::FORT))) - guiManager->readLuaScreenScript("fortCommands.lua", buttons, listboxes, checkboxes, sliders, textboxes, guiRects, texts); - else if(selectedUnitsAmongst(mainPlayer->getUnitsByClass(UnitClass::LAND_FACTORY))) - guiManager->readLuaScreenScript("landFactoryCommands.lua", buttons, listboxes, checkboxes, sliders, textboxes, guiRects, texts); - else if(selectedUnitsAmongst(mainPlayer->getUnitsByClass(UnitClass::NAVAL_FACTORY))) - guiManager->readLuaScreenScript("navalFactoryCommands.lua", buttons, listboxes, checkboxes, sliders, textboxes, guiRects, texts); + if(!selUnits.empty() && u == selUnits[0] && guiScreen != "" && guiScreen != unitGuiScreen){ + guiManager->readLuaScreenScript(u->getBuildableUnitGuiScreen(), buttons, listboxes, checkboxes, sliders, textboxes, guiRects, texts); + unitGuiScreen = guiScreen; } if(isSelectionBox && fabs(pos.x - dragboxOrigin.x) < .5 * dragboxSize.x && fabs(pos.y - dragboxOrigin.y) < .5 * dragboxSize.y){ diff --git a/activeGameState.h b/activeGameState.h index 1b01121..6de8d1b 100755 --- a/activeGameState.h +++ b/activeGameState.h @@ -47,6 +47,7 @@ namespace battleship{ GuiAppState *guiState; Player *mainPlayer; + std::string unitGuiScreen = ""; GameObject *gameObjHoveredOn = nullptr; vb01::Node *dragboxNode = nullptr; vb01::Vector2 clickPoint; diff --git a/buildButton.cpp b/buildButton.cpp index e36c9ec..29f57e0 100644 --- a/buildButton.cpp +++ b/buildButton.cpp @@ -1,8 +1,12 @@ #include "buildButton.h" #include "gameManager.h" #include "gameObject.h" +#include "unit.h" +#include "activeGameState.h" +#include "buildableUnit.h" #include "gameObjectFrameController.h" +#include #include namespace battleship{ @@ -12,13 +16,18 @@ namespace battleship{ using namespace vb01Gui; using namespace gameBase; - BuildButton::BuildButton(Vector2 pos, Vector2 size, int structureId, string name, int trigger, string imagePath) : UnitButton(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, imagePath){ - this->structureId = structureId; - } + BuildButton::BuildButton(Vector2 pos, Vector2 size, string name, int trigger, string imagePath, int uid, int slId) : + UnitButton(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, imagePath, uid), slotId(slId){} void BuildButton::onClick(){ - GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton(); - ufCtr->addGameObjectFrame(GameObjectFrame(structureId, GameObject::Type::UNIT)); - ufCtr->setPlacingFrames(true); + ActiveGameState *activeState = (ActiveGameState*)(GameManager::getSingleton()->getStateManager()->getAppStateByType((int)AppStateType::ACTIVE_STATE)); + Player *player = activeState->getPlayer(); + Unit* builder = player->getUnitsById(unitId)[0]; + + if(builder->getBuildableUnit(slotId).buildable){ + GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton(); + ufCtr->addGameObjectFrame(GameObjectFrame(builder->getBuildableUnit(slotId).id, GameObject::Type::UNIT)); + ufCtr->setPlacingFrames(true); + } } } diff --git a/buildButton.h b/buildButton.h index ae4802b..b4cd97b 100644 --- a/buildButton.h +++ b/buildButton.h @@ -6,10 +6,10 @@ namespace battleship{ class BuildButton : public UnitButton{ public: - BuildButton(vb01::Vector2, vb01::Vector2, int, std::string, int, std::string); + BuildButton(vb01::Vector2, vb01::Vector2, std::string, int, std::string, int, int); void onClick(); private: - int structureId; + int slotId; }; } diff --git a/concreteGuiManager.cpp b/concreteGuiManager.cpp index b48b393..404e6ba 100644 --- a/concreteGuiManager.cpp +++ b/concreteGuiManager.cpp @@ -163,30 +163,34 @@ namespace battleship{ } case BUILD: { - int strId = guiTable["structureId"]; + int unitId = SOL_LUA_STATE["UnitId"]["ENGINEER"]; + int strId = SOL_LUA_STATE["units"][unitId + 1]["buildableUnits"][guiId + 1]["id"]; string buttonName = SOL_LUA_STATE["units"][strId + 1]["name"]; - button = new BuildButton(pos, size, strId, buttonName, (int)guiTable["trigger"], (string)guiTable["imagePath"]); + button = new BuildButton(pos, size, buttonName, (int)guiTable["trigger"], (string)guiTable["imagePath"], unitId, guiId); break; } case LAND_FACTORY_TRAIN: { - int unitId = guiTable["unitId"]; + int facId = SOL_LUA_STATE["UnitId"]["LAND_FACTORY"]; + int unitId = SOL_LUA_STATE["units"][facId + 1]["buildableUnits"][guiId + 1]["id"]; string buttonName = SOL_LUA_STATE["units"][unitId + 1]["name"]; - button = new TrainButton(pos, size, buttonName, (int)guiTable["trigger"], (string)guiTable["imagePath"], (int)SOL_LUA_STATE["UnitId"]["LAND_FACTORY"], unitId); + button = new TrainButton(pos, size, buttonName, (int)guiTable["trigger"], (string)guiTable["imagePath"], facId, guiId); break; } case NAVAL_FACTORY_TRAIN: { - int unitId = guiTable["unitId"]; + int facId = SOL_LUA_STATE["UnitId"]["NAVAL_FACTORY"]; + int unitId = SOL_LUA_STATE["units"][facId + 1]["buildableUnits"][guiId + 1]["id"]; string buttonName = SOL_LUA_STATE["units"][unitId + 1]["name"]; - button = new TrainButton(pos, size, buttonName, (int)guiTable["trigger"], (string)guiTable["imagePath"], (int)SOL_LUA_STATE["UnitId"]["NAVAL_FACTORY"], unitId); + button = new TrainButton(pos, size, buttonName, (int)guiTable["trigger"], (string)guiTable["imagePath"], facId, guiId); break; } case FORT_TRAIN: { - int unitId = guiTable["unitId"]; + int facId = SOL_LUA_STATE["UnitId"]["FORT"]; + int unitId = SOL_LUA_STATE["units"][facId + 1]["buildableUnits"][guiId + 1]["id"]; string buttonName = SOL_LUA_STATE["units"][unitId + 1]["name"]; - button = new TrainButton(pos, size, buttonName, (int)guiTable["trigger"], (string)guiTable["imagePath"], (int)SOL_LUA_STATE["UnitId"]["FORT"], unitId); + button = new TrainButton(pos, size, buttonName, (int)guiTable["trigger"], (string)guiTable["imagePath"], facId, guiId); break; } case STATISTICS: diff --git a/factory.cpp b/factory.cpp index 4554904..0c02245 100644 --- a/factory.cpp +++ b/factory.cpp @@ -1,5 +1,6 @@ #include "factory.h" #include "player.h" +#include "game.h" #include "gameObjectFactory.h" #include "activeGameState.h" @@ -24,6 +25,14 @@ namespace battleship{ train(); } + //TODO replace repetetive string literals + void Factory::initProperties(){ + Structure::initProperties(); + Game *game = Game::getSingleton(); + vector currTechs = player->getTechnologies(); + + } + int Factory::getNumQueueUnitsById(int unitId){ int numUnits = 0; @@ -34,6 +43,11 @@ namespace battleship{ return numUnits; } + void Factory::appendToQueue(int buId){ + if(buId < buildableUnits.size() && buildableUnits[buId].buildable) + unitQueue.push_back(buildableUnits[buId].id); + } + void Factory::train(){ bool training = !unitQueue.empty(); buildStatusForeground->setVisible(training); diff --git a/factory.h b/factory.h index 851ae22..586eab8 100644 --- a/factory.h +++ b/factory.h @@ -19,14 +19,14 @@ namespace battleship{ ~Factory(){} void update(); int getNumQueueUnitsById(int); - void appendToQueue(int uid){unitQueue.push_back(uid);} + void appendToQueue(int); inline std::vector getQueue(){return unitQueue;} private: - const int MAX_LEN_QUEUE = 10; - int trainingStatus = 0; - vb01::s64 lastTrainTime = 0; std::vector unitQueue; + int maxLenQueue, trainingStatus = 0; + vb01::s64 lastTrainTime = 0; + void initProperties(); void train(); }; } diff --git a/trainButton.cpp b/trainButton.cpp index 436c84c..bab5d5e 100644 --- a/trainButton.cpp +++ b/trainButton.cpp @@ -1,5 +1,6 @@ #include "trainButton.h" #include "activeGameState.h" +#include "buildableUnit.h" #include "factory.h" #include @@ -10,19 +11,17 @@ namespace battleship{ using namespace vb01; using namespace gameBase; - TrainButton::TrainButton(Vector2 pos, Vector2 size, string name, int trigger, string imagePath, int fid, int tuid) : - factoryId(fid), - trainableUnitId(tuid), - UnitButton(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, imagePath){} + TrainButton::TrainButton(Vector2 pos, Vector2 size, string name, int trigger, string imagePath, int uid, int slId) : + UnitButton(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, imagePath, uid), + slotId(slId) {} void TrainButton::onClick(){ ActiveGameState *activeState = (ActiveGameState*)(GameManager::getSingleton()->getStateManager()->getAppStateByType((int)AppStateType::ACTIVE_STATE)); Player *player = activeState->getPlayer(); - UnitClass facClass = (UnitClass)generateView()["units"][factoryId + 1]["unitClass"]; - vector selUnits = player->getSelectedUnits(), factories = player->getUnitsByClass(facClass); + vector selUnits = player->getSelectedUnits(), factories = player->getUnitsById(unitId); for(Unit *fac : factories) - if(find(selUnits.begin(), selUnits.end(), fac) != selUnits.end()) - ((Factory*)fac)->appendToQueue(trainableUnitId); + if(fac->getBuildableUnit(slotId).buildable && find(selUnits.begin(), selUnits.end(), fac) != selUnits.end()) + ((Factory*)fac)->appendToQueue(slotId); } } diff --git a/trainButton.h b/trainButton.h index e600dd1..149c906 100644 --- a/trainButton.h +++ b/trainButton.h @@ -9,7 +9,7 @@ namespace battleship{ TrainButton(vb01::Vector2, vb01::Vector2, std::string, int, std::string, int, int); void onClick(); private: - int factoryId, trainableUnitId; + int slotId; }; } diff --git a/unit.cpp b/unit.cpp index 2c34719..27b67f0 100755 --- a/unit.cpp +++ b/unit.cpp @@ -16,6 +16,8 @@ #include "vehicle.h" #include "gameObjectFactory.h" #include "activeGameState.h" +#include "gameManager.h" +#include "projectile.h" #include "defConfigs.h" #include "pathfinder.h" #include "ability.h" @@ -171,6 +173,20 @@ namespace battleship{ armorTypes.push_back(arm); } } + + tblName = "buildableUnits"; + sol::optional bu = unitTable[tblName]; + + if(bu != sol::nullopt){ + SOL_LUA_VIEW.script("numBuildableUnits = #units[" + to_string(id + 1) + "]." + tblName); + int numBuildableUnits = SOL_LUA_VIEW["numBuildableUnits"]; + buildableUnitGuiScreen = unitTable["guiScreen"]; + + for(int i = 0; i < numBuildableUnits; i++){ + sol::table buTable = unitTable[tblName][i + 1]; + buildableUnits.push_back(BuildableUnit(buTable["id"], buTable["buildable"])); + } + } } void Unit::initWeapons(){ diff --git a/unit.h b/unit.h index 2052d9e..815c6f9 100755 --- a/unit.h +++ b/unit.h @@ -8,9 +8,8 @@ #include -#include "gameManager.h" #include "gameObject.h" -#include "projectile.h" +#include "buildableUnit.h" namespace sf{ class SoundBuffer; @@ -31,8 +30,9 @@ namespace battleship{ class Structure; class Factory; class Cruiser; - class PointDefense; class Engineer; + class PointDefense; + class Projectile; struct Order { enum class TYPE {ATTACK, BUILD, MOVE, GARRISON, EJECT, PATROL, LAUNCH, SUPPLY, HACK}; @@ -149,6 +149,8 @@ namespace battleship{ inline bool isTargetToTheRight(vb01::Vector3 dir, vb01::Vector3 lv){return lv.getAngleBetween(dir) > vb01::PI / 2;} inline Order getOrder(int i){return orders[i];} inline int getNumOrders(){return orders.size();} + inline std::string getBuildableUnitGuiScreen(){return buildableUnitGuiScreen;} + inline BuildableUnit getBuildableUnit(int i){return buildableUnits[i];} private: void renderOrderLine(bool); void updateScreenCoordinates(); @@ -165,12 +167,14 @@ namespace battleship{ UnitClass unitClass; UnitType type; std::vector orders; + std::string buildableUnitGuiScreen = ""; int health, maxHealth, playerId, lenHpBar = 200; - s64 orderLineDispTime = 0, lastFireTime = 0; + vb01::s64 orderLineDispTime = 0, lastFireTime = 0; float lineOfSight; - std::vector garrisonSlots; std::vector armorTypes; std::vector weapons; + std::vector garrisonSlots; + std::vector buildableUnits; State state = State::STAND_GROUND; std::vector getSelectingPlayers(); diff --git a/unitButton.cpp b/unitButton.cpp index 3a0d8ba..bb568a1 100644 --- a/unitButton.cpp +++ b/unitButton.cpp @@ -10,7 +10,7 @@ namespace battleship{ using namespace vb01Gui; using namespace gameBase; - UnitButton::UnitButton(Vector2 pos, Vector2 size, string name, string fontPath, int trigger, string imagePath) : Button(pos, size, name, fontPath, trigger, true, imagePath){ + UnitButton::UnitButton(Vector2 pos, Vector2 size, string name, string fontPath, int trigger, string imagePath, int uid) : Button(pos, size, name, fontPath, trigger, true, imagePath), unitId(uid){ StateManager *stateManager = GameManager::getSingleton()->getStateManager(); ActiveGameState *activeState = (ActiveGameState*)stateManager->getAppStateByType((int)AppStateType::ACTIVE_STATE); diff --git a/unitButton.h b/unitButton.h index 696ae1e..db682e5 100644 --- a/unitButton.h +++ b/unitButton.h @@ -8,8 +8,9 @@ namespace battleship{ class UnitButton : public vb01Gui::Button{ public: - UnitButton(vb01::Vector2, vb01::Vector2, std::string, std::string, int, std::string); + UnitButton(vb01::Vector2, vb01::Vector2, std::string, std::string, int, std::string, int); protected: + int unitId; std::vector units; }; } From 7d8cb8819474e0dd882f1162d5cf3d8a4c927077 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sat, 9 Mar 2024 14:05:12 +0200 Subject: [PATCH 10/13] research status bar --- Assets/Scripts/GameObjects/Units/unitData.lua | 4 +-- researchStruct.cpp | 35 ++++++++++++++++--- researchStruct.h | 6 ++++ 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/Assets/Scripts/GameObjects/Units/unitData.lua b/Assets/Scripts/GameObjects/Units/unitData.lua index 27d0022..1933a47 100644 --- a/Assets/Scripts/GameObjects/Units/unitData.lua +++ b/Assets/Scripts/GameObjects/Units/unitData.lua @@ -134,7 +134,7 @@ units = { {id = UnitId.MARKET, buildable = true}, {id = UnitId.LAB, buildable = true}, {id = UnitId.POINT_DEFENSE, buildable = true}, - {id = UnitId.FORT, buildable = true}, + {id = UnitId.FORT, buildable = false}, }, unitClass = UnitClass.ENGINEER, unitType = UnitType.HOVER, @@ -526,7 +526,7 @@ units = { size = {x = 1, y = 1.15, z = 2}, hitboxOffset = {x = 0, y = 0, z = 0}, lineOfSight = 5, - generationRate = 10000, + generationRate = 100, generationSpeed = 10, researchCost = 1, name = 'Lab', diff --git a/researchStruct.cpp b/researchStruct.cpp index c6848c3..0e498a4 100644 --- a/researchStruct.cpp +++ b/researchStruct.cpp @@ -1,7 +1,10 @@ #include "researchStruct.h" +#include "activeGameState.h" #include "player.h" #include "game.h" +#include + namespace battleship{ using namespace std; using namespace vb01; @@ -12,6 +15,15 @@ namespace battleship{ generationRate = unitTable["generationRate"]; generationSpeed = unitTable["generationSpeed"]; researchCost = unitTable["researchCost"]; + + Vector2 size = Vector2(lenHpBar, 10); + researchStatusBackground = Unit::createBar(Vector2::VEC_ZERO, size, Vector4(0, 0, 0, 1)); + researchStatusForeground = Unit::createBar(Vector2::VEC_ZERO, size, Vector4(1, 0, 1, 1)); + } + + ResearchStruct::~ResearchStruct(){ + removeBar(researchStatusBackground); + removeBar(researchStatusForeground); } void ResearchStruct::update(){ @@ -19,17 +31,30 @@ namespace battleship{ if(!isComplete()) return; - if(researchQueue.empty() && health > .3 * maxHealth && player->getRefineds() >= researchCost && canUpdateResearch()){ - player->addResearch(generationSpeed); - player->subtractRefineds(researchCost); - lastUpdateTime = getTime(); + ActiveGameState *activeState = (ActiveGameState*)GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE); + Player *mainPlayer = (activeState ? activeState->getPlayer() : nullptr); + + vector selectingPlayers = Unit::getSelectingPlayers(); + bool mainPlayerSelecting = (activeState && find(selectingPlayers.begin(), selectingPlayers.end(), mainPlayer) != selectingPlayers.end()); + + if(researchQueue.empty()){ + if(health > .3 * maxHealth && player->getRefineds() >= researchCost && canUpdateResearch()){ + player->addResearch(generationSpeed); + player->subtractRefineds(researchCost); + lastUpdateTime = getTime(); + } + + researchStatusBackground->setVisible(false); + researchStatusForeground->setVisible(false); } else if(!researchQueue.empty()){ + Unit::displayUnitStats(researchStatusForeground, researchStatusBackground, researchStatus, 100, mainPlayer == player && mainPlayerSelecting, Vector2(0, -10)); + int techCost = Game::getSingleton()->getTechnology(researchQueue[0]).cost; int playerResearch = player->getResearch(); if(techCost > playerResearch && canUpdateResearch()){ - researchStatus += (int)((float)playerResearch / techCost); + researchStatus += int(100 * ((float)playerResearch / techCost)); lastUpdateTime = getTime(); } else if(researchStatus >= 100 || techCost <= playerResearch){ diff --git a/researchStruct.h b/researchStruct.h index 49ebc45..03ef393 100644 --- a/researchStruct.h +++ b/researchStruct.h @@ -3,16 +3,22 @@ #include "structure.h" +namespace vb01{ + class Node; +} + namespace battleship{ class ResearchStruct : public Structure{ public: ResearchStruct(Player*, int, vb01::Vector3, vb01::Quaternion, int = 0, Unit::State = Unit::State::STAND_GROUND); + ~ResearchStruct(); void update(); inline void appendToQueue(int tid){researchQueue.push_back(tid);} private: vb01::s64 lastUpdateTime = 0; int researchCost, generationRate, generationSpeed, researchStatus = 0; std::vector researchQueue; + vb01::Node *researchStatusForeground = nullptr, *researchStatusBackground = nullptr; bool canUpdateResearch(){return vb01::getTime() - lastUpdateTime > generationRate;} void generateResearch(); From aaf1ee61b972b2e45d1796633cdd03a9ebb9f35e Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sat, 9 Mar 2024 14:05:45 +0200 Subject: [PATCH 11/13] unit unlock research --- ability.h | 3 ++- game.cpp | 15 ++++++++++++++- game.h | 2 ++ player.cpp | 4 ++++ player.h | 2 +- unit.cpp | 2 +- 6 files changed, 24 insertions(+), 4 deletions(-) diff --git a/ability.h b/ability.h index d3c92b0..c45f7dc 100644 --- a/ability.h +++ b/ability.h @@ -18,7 +18,8 @@ namespace battleship{ LOAD_SPEED, DRAW_RATE, DRAW_SPEED, - HACK_RANGE + HACK_RANGE, + UNIT_UNLOCK }; Type type; diff --git a/game.cpp b/game.cpp index fe17b11..5fd9e7a 100644 --- a/game.cpp +++ b/game.cpp @@ -265,7 +265,7 @@ namespace battleship{ Ability ability; ability.type = techTable["type"]; - ability.ammount = techTable["ammount"].get_or(0); + ability.ammount = techTable["ammount"].get_or(0.0); ability.gameObjType = techTable["gameObjType"]; ability.gameObjIds = parseTechTable(i, techKey, "numGameObjIds", "gameObjIds"); abilities.push_back(ability); @@ -287,4 +287,17 @@ namespace battleship{ return ammount; } + + bool Game::isUnitUnlocked(vector techResearch, int unitId){ + for(int techId : techResearch){ + for(int abilId : technologies[techId].abilities){ + vector ids = abilities[abilId].gameObjIds; + + if(find(ids.begin(), ids.end(), unitId) != ids.end()) + return true; + } + } + + return false; + } } diff --git a/game.h b/game.h index af76b46..ae42ab8 100644 --- a/game.h +++ b/game.h @@ -27,12 +27,14 @@ namespace battleship{ void changeUnitPlayer(Unit*, Player*); void initTechnologies(); float calcAbilFromTech(Ability::Type, std::vector, int, int); + bool isUnitUnlocked(std::vector, int); inline void addFx(Fx f){fx.push_back(f);} inline void addPlayer(Player *pl){players.push_back(pl);} inline std::vector& getPlayers(){return players;} inline Player* getPlayer(int id){return players[id];} inline int getNumPlayers(){return players.size();} inline Technology getTechnology(int id){return technologies[id];} + inline Ability getAbility(int id){return abilities[id];} private: Game(){} void resetLuaGameObjects(); diff --git a/player.cpp b/player.cpp index 2195442..cec2871 100755 --- a/player.cpp +++ b/player.cpp @@ -183,4 +183,8 @@ namespace battleship{ return ucUnits; } + + void Player::addTechnology(int techId){ + technologies.push_back(techId); + } } diff --git a/player.h b/player.h index a6a8a2e..e14e2c7 100755 --- a/player.h +++ b/player.h @@ -26,6 +26,7 @@ namespace battleship{ void selectUnits(std::vector); std::vector getUnitsById(int, int = -1); std::vector getUnitsByClass(UnitClass, int = -1); + void addTechnology(int); inline void deselectUnits(){selectedUnits.clear();} inline Unit* getSelectedUnit(int id){return selectedUnits[id];} inline std::vector getSelectedUnits(){return selectedUnits;} @@ -74,7 +75,6 @@ namespace battleship{ inline vb01::Vector3 getColor(){return color;} inline std::string getName(){return name;} inline std::vector getTechnologies(){return technologies;} - inline void addTechnology(int tid){technologies.push_back(tid);} private: bool cpuPlayer = false; std::vector technologies; diff --git a/unit.cpp b/unit.cpp index 27b67f0..833d6a2 100755 --- a/unit.cpp +++ b/unit.cpp @@ -184,7 +184,7 @@ namespace battleship{ for(int i = 0; i < numBuildableUnits; i++){ sol::table buTable = unitTable[tblName][i + 1]; - buildableUnits.push_back(BuildableUnit(buTable["id"], buTable["buildable"])); + buildableUnits.push_back(BuildableUnit(buTable["id"], game->isUnitUnlocked(currTechs, id) | (bool)buTable["buildable"])); } } } From feef91c9990f7fc7e1ef2d289660177bd5226639 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sat, 9 Mar 2024 14:49:04 +0200 Subject: [PATCH 12/13] technology research button --- Assets/Scripts/GameObjects/Units/unitData.lua | 2 +- Assets/Scripts/Gui/main.lua | 3 ++- Assets/Scripts/Gui/researchStructCommands.lua | 15 ++++++++++++ CMakeLists.txt | 2 +- activeGameState.cpp | 4 ++-- concreteGuiManager.cpp | 4 ++++ concreteGuiManager.h | 3 ++- researchButton.cpp | 24 +++++++++++++++++++ researchButton.h | 16 +++++++++++++ unit.cpp | 2 +- unit.h | 4 ++-- unitButton.h | 1 - 12 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 Assets/Scripts/Gui/researchStructCommands.lua create mode 100644 researchButton.cpp create mode 100644 researchButton.h diff --git a/Assets/Scripts/GameObjects/Units/unitData.lua b/Assets/Scripts/GameObjects/Units/unitData.lua index 1933a47..5e42330 100644 --- a/Assets/Scripts/GameObjects/Units/unitData.lua +++ b/Assets/Scripts/GameObjects/Units/unitData.lua @@ -532,7 +532,7 @@ units = { name = 'Lab', basePath = PATH .. structurePrefix .. 'Labs/', meshPath = 'lab.xml', - guiScreen = '', + guiScreen = 'researchStructCommands.lua', selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg', deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg', }, diff --git a/Assets/Scripts/Gui/main.lua b/Assets/Scripts/Gui/main.lua index c0dc13a..390113d 100644 --- a/Assets/Scripts/Gui/main.lua +++ b/Assets/Scripts/Gui/main.lua @@ -27,7 +27,8 @@ ButtonType = { LAND_FACTORY_TRAIN = 23, NAVAL_FACTORY_TRAIN = 24, FORT_TRAIN = 25, - STATISTICS = 26 + STATISTICS = 26, + RESEARCH = 27 } ListboxType = { diff --git a/Assets/Scripts/Gui/researchStructCommands.lua b/Assets/Scripts/Gui/researchStructCommands.lua new file mode 100644 index 0000000..166afe1 --- /dev/null +++ b/Assets/Scripts/Gui/researchStructCommands.lua @@ -0,0 +1,15 @@ +res = graphics.resolution +Size = {x = 100, y = 100} + +gui = { + { + pos = {x = res.x - 200, y = res.y - 200}, + size = Size, + name = "Research", + imagePath = '', + guiType = GuiType.BUTTON, + buttonType = ButtonType.RESEARCH, + techId = TechId.APT, + trigger = 82, + } +} diff --git a/CMakeLists.txt b/CMakeLists.txt index ec20ad1..bb506e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ set(CMAKE_BUILD_TYPE Debug) set(BUILD_TESTS ON) cmake_policy(SET CMP0015 NEW) -set(UNIT_BUTTONS unitButton.cpp buildButton.cpp trainButton.cpp) +set(UNIT_BUTTONS unitButton.cpp buildButton.cpp trainButton.cpp researchButton.cpp) set(OPTIONS_BUTTONS optionsButton.cpp tabButton.cpp okButton.cpp defaultsButton.cpp) set(IN_GAME_APP_STATE_BUTTONS mainMenuButton.cpp) set(MAP_EDITOR_BUTTONS mapEditorButton.cpp newMapButton.cpp loadMapButton.cpp exportButton.cpp) diff --git a/activeGameState.cpp b/activeGameState.cpp index 8cbdb43..3e10f66 100755 --- a/activeGameState.cpp +++ b/activeGameState.cpp @@ -202,10 +202,10 @@ namespace battleship{ Vector3 dragboxSize = ((Quad*)dragboxNode->getMesh(0))->getSize(); Vector3 dragboxOrigin = dragboxNode->getPosition(), dragboxEnd = dragboxOrigin + dragboxSize; Vector2 pos = u->getScreenPos(); - string guiScreen = u->getBuildableUnitGuiScreen(); + string guiScreen = u->getGuiScreen(); if(!selUnits.empty() && u == selUnits[0] && guiScreen != "" && guiScreen != unitGuiScreen){ - guiManager->readLuaScreenScript(u->getBuildableUnitGuiScreen(), buttons, listboxes, checkboxes, sliders, textboxes, guiRects, texts); + guiManager->readLuaScreenScript(u->getGuiScreen(), buttons, listboxes, checkboxes, sliders, textboxes, guiRects, texts); unitGuiScreen = guiScreen; } diff --git a/concreteGuiManager.cpp b/concreteGuiManager.cpp index 404e6ba..7c04e61 100644 --- a/concreteGuiManager.cpp +++ b/concreteGuiManager.cpp @@ -24,6 +24,7 @@ #include "buildButton.h" #include "trainButton.h" #include "statsButton.h" +#include "researchButton.h" namespace battleship{ using namespace std; @@ -196,6 +197,9 @@ namespace battleship{ case STATISTICS: button = new StatsButton(pos, size, name, (int)guiTable["trigger"], (string)guiTable["imagePath"]); break; + case RESEARCH: + button = new ResearchButton(pos, size, name, (int)guiTable["trigger"], (string)guiTable["imagePath"], (int)SOL_LUA_STATE["UnitId"]["LAB"], (int)guiTable["techId"]); + break; } int typeArr[2]{(int)GuiElementType::BUTTON, (int)type}; diff --git a/concreteGuiManager.h b/concreteGuiManager.h index c141da2..d9bfb29 100644 --- a/concreteGuiManager.h +++ b/concreteGuiManager.h @@ -41,7 +41,8 @@ namespace battleship{ LAND_FACTORY_TRAIN, NAVAL_FACTORY_TRAIN, FORT_TRAIN, - STATISTICS + STATISTICS, + RESEARCH }; enum ListboxType { CONTROLS, diff --git a/researchButton.cpp b/researchButton.cpp new file mode 100644 index 0000000..c950e9c --- /dev/null +++ b/researchButton.cpp @@ -0,0 +1,24 @@ +#include "researchButton.h" +#include "activeGameState.h" +#include "researchStruct.h" + +#include +#include + +namespace battleship{ + using namespace vb01; + using namespace std; + + ResearchButton::ResearchButton(Vector2 pos, Vector2 size, string name, int trigger, string imagePath, int uid, int tid) : + UnitButton(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, imagePath, uid), techId(tid){} + + void ResearchButton::onClick(){ + ActiveGameState *activeState = (ActiveGameState*)(GameManager::getSingleton()->getStateManager()->getAppStateByType((int)AppStateType::ACTIVE_STATE)); + Player *player = activeState->getPlayer(); + vector selUnits = player->getSelectedUnits(), researchStructs = player->getUnitsById(unitId); + + for(Unit *rs : researchStructs) + if(find(selUnits.begin(), selUnits.end(), rs) != selUnits.end()) + ((ResearchStruct*)rs)->appendToQueue(techId); + } +} diff --git a/researchButton.h b/researchButton.h new file mode 100644 index 0000000..337bc2f --- /dev/null +++ b/researchButton.h @@ -0,0 +1,16 @@ +#ifndef RESEARCH_BUTTON_H +#define RESEARCH_BUTTON_H + +#include "unitButton.h" + +namespace battleship{ + class ResearchButton : public UnitButton{ + public: + ResearchButton(vb01::Vector2, vb01::Vector2, std::string, int, std::string, int, int); + void onClick(); + private: + int techId; + }; +} + +#endif diff --git a/unit.cpp b/unit.cpp index 833d6a2..d800920 100755 --- a/unit.cpp +++ b/unit.cpp @@ -141,6 +141,7 @@ namespace battleship{ lineOfSight = unitTable["lineOfSight"]; lineOfSight += game->calcAbilFromTech(Ability::Type::LINE_OF_SIGHT, currTechs, (int)GameObject::type, id); unitClass = (UnitClass)unitTable["unitClass"]; type = (UnitType)unitTable["unitType"]; + guiScreen = unitTable["guiScreen"]; string tblName = "garrisonCapacity"; sol::optional gc = unitTable[tblName]; @@ -180,7 +181,6 @@ namespace battleship{ if(bu != sol::nullopt){ SOL_LUA_VIEW.script("numBuildableUnits = #units[" + to_string(id + 1) + "]." + tblName); int numBuildableUnits = SOL_LUA_VIEW["numBuildableUnits"]; - buildableUnitGuiScreen = unitTable["guiScreen"]; for(int i = 0; i < numBuildableUnits; i++){ sol::table buTable = unitTable[tblName][i + 1]; diff --git a/unit.h b/unit.h index 815c6f9..0d8d31e 100755 --- a/unit.h +++ b/unit.h @@ -149,7 +149,7 @@ namespace battleship{ inline bool isTargetToTheRight(vb01::Vector3 dir, vb01::Vector3 lv){return lv.getAngleBetween(dir) > vb01::PI / 2;} inline Order getOrder(int i){return orders[i];} inline int getNumOrders(){return orders.size();} - inline std::string getBuildableUnitGuiScreen(){return buildableUnitGuiScreen;} + inline std::string getGuiScreen(){return guiScreen;} inline BuildableUnit getBuildableUnit(int i){return buildableUnits[i];} private: void renderOrderLine(bool); @@ -167,7 +167,7 @@ namespace battleship{ UnitClass unitClass; UnitType type; std::vector orders; - std::string buildableUnitGuiScreen = ""; + std::string guiScreen = ""; int health, maxHealth, playerId, lenHpBar = 200; vb01::s64 orderLineDispTime = 0, lastFireTime = 0; float lineOfSight; diff --git a/unitButton.h b/unitButton.h index db682e5..3184544 100644 --- a/unitButton.h +++ b/unitButton.h @@ -11,7 +11,6 @@ namespace battleship{ UnitButton(vb01::Vector2, vb01::Vector2, std::string, std::string, int, std::string, int); protected: int unitId; - std::vector units; }; } From 8a885391f90aa71d7b7c653fcb92c3c5c0d09b47 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sat, 9 Mar 2024 14:54:20 +0200 Subject: [PATCH 13/13] guiScreen is now an optional property --- Assets/Scripts/GameObjects/Units/unitData.lua | 18 ------------------ unit.cpp | 5 ++++- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/Assets/Scripts/GameObjects/Units/unitData.lua b/Assets/Scripts/GameObjects/Units/unitData.lua index 5e42330..972c0e0 100644 --- a/Assets/Scripts/GameObjects/Units/unitData.lua +++ b/Assets/Scripts/GameObjects/Units/unitData.lua @@ -73,7 +73,6 @@ units = { destinationOffset = .1, anglePrecision = .1, maxTurnAngle = .1, - guiScreen = '', garrisonCategory = 1 }, { @@ -97,7 +96,6 @@ units = { destinationOffset = .1, anglePrecision = .1, maxTurnAngle = .1, - guiScreen = '', garrisonCategory = 2 }, { @@ -121,7 +119,6 @@ units = { destinationOffset = .1, anglePrecision = .1, maxTurnAngle = .1, - guiScreen = '', garrisonCategory = 2 }, { @@ -181,7 +178,6 @@ units = { destinationOffset = .1, anglePrecision = .1, maxTurnAngle = .1, - guiScreen = '', garrisonCategory = 3 }, { @@ -206,7 +202,6 @@ units = { destinationOffset = .1, anglePrecision = .1, maxTurnAngle = .1, - guiScreen = '', garrisonCategory = 3 }, { @@ -233,7 +228,6 @@ units = { destinationOffset = .1, anglePrecision = .1, maxTurnAngle = .1, - guiScreen = '', garrisonCategory = 3 }, { @@ -257,7 +251,6 @@ units = { destinationOffset = .1, anglePrecision = .1, maxTurnAngle = .1, - guiScreen = '', garrisonCategory = 3 }, { @@ -282,7 +275,6 @@ units = { destinationOffset = .1, anglePrecision = .1, maxTurnAngle = .1, - guiScreen = '', garrisonCategory = 3 }, { @@ -306,7 +298,6 @@ units = { destinationOffset = .1, anglePrecision = .1, maxTurnAngle = .1, - guiScreen = '', garrisonCategory = 3 }, { @@ -330,7 +321,6 @@ units = { destinationOffset = .1, anglePrecision = .1, maxTurnAngle = .1, - guiScreen = '', garrisonCategory = 3 }, { @@ -353,7 +343,6 @@ units = { destinationOffset = .1, anglePrecision = .1, maxTurnAngle = .1, - guiScreen = '', garrisonCategory = 3 }, { @@ -385,7 +374,6 @@ units = { destinationOffset = .1, anglePrecision = .1, maxTurnAngle = .1, - guiScreen = '', garrisonCategory = 3 }, { @@ -424,7 +412,6 @@ units = { destinationOffset = .1, anglePrecision = .1, maxTurnAngle = .1, - guiScreen = '', garrisonCategory = 3 }, { @@ -456,7 +443,6 @@ units = { destinationOffset = .1, anglePrecision = .1, maxTurnAngle = .1, - guiScreen = '', garrisonCategory = 3 }, { @@ -513,7 +499,6 @@ units = { basePath = PATH .. structurePrefix .. 'Markets/', meshPath = 'market.xml', selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg', - guiScreen = '', deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg', }, { @@ -551,7 +536,6 @@ units = { basePath = PATH .. structurePrefix .. 'PointDefenses/', meshPath = 'pointDefense.xml', selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg', - guiScreen = '', deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg', }, { @@ -570,7 +554,6 @@ units = { basePath = PATH .. structurePrefix .. 'Extractors/', meshPath = 'extractor.xml', selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg', - guiScreen = '', deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg', }, { @@ -586,7 +569,6 @@ units = { name = 'Refinery', basePath = PATH .. structurePrefix .. 'Refineries/', meshPath = 'refinery.xml', - guiScreen = '', selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg', deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg', }, diff --git a/unit.cpp b/unit.cpp index d800920..c250ef0 100755 --- a/unit.cpp +++ b/unit.cpp @@ -141,7 +141,10 @@ namespace battleship{ lineOfSight = unitTable["lineOfSight"]; lineOfSight += game->calcAbilFromTech(Ability::Type::LINE_OF_SIGHT, currTechs, (int)GameObject::type, id); unitClass = (UnitClass)unitTable["unitClass"]; type = (UnitType)unitTable["unitType"]; - guiScreen = unitTable["guiScreen"]; + + string gsk = "guiScreen"; + sol::optional nameOpt = unitTable[gsk]; + guiScreen = (nameOpt != sol::nullopt ? (string)unitTable[gsk] : ""); string tblName = "garrisonCapacity"; sol::optional gc = unitTable[tblName];