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(); } }