From 7deb1612831e0665123a16258a315cfc58cee017 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sat, 24 Feb 2024 12:51:02 +0200 Subject: [PATCH] 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