mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
add-technology command
This commit is contained in:
@@ -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 = '',
|
||||
|
||||
+1
-1
@@ -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)
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
#include "addTechnologyCommand.h"
|
||||
#include "game.h"
|
||||
#include "player.h"
|
||||
|
||||
#include <solUtil.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user