add-technology command

This commit is contained in:
devZoGok
2024-02-24 14:45:26 +02:00
parent 7deb161283
commit ebd42f6cab
5 changed files with 69 additions and 5 deletions
+42
View File
@@ -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();
}
}