mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
implemented add-resource command
This commit is contained in:
+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 unitFrameController.cpp cameraController.cpp)
|
||||
set(CONSOLE console.cpp abstractCommand.cpp addUnitCommand.cpp)
|
||||
set(CONSOLE console.cpp abstractCommand.cpp addUnitCommand.cpp addResourceCommand.cpp)
|
||||
set(CORE gameManager.cpp defConfigs.cpp ${CONSOLE} ${CONTROLLERS})
|
||||
set(PROJECTILES projectile.cpp)
|
||||
set(FX explosion.cpp)
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
#include "addResourceCommand.h"
|
||||
#include "map.h"
|
||||
#include "player.h"
|
||||
|
||||
namespace battleship{
|
||||
void AddResourceCommand::validate(){
|
||||
if(arguments.size() != 3)
|
||||
return;
|
||||
|
||||
playerId = atoi(arguments[0].c_str());
|
||||
|
||||
if(playerId != 0 && playerId != 1)
|
||||
return;
|
||||
|
||||
resourceId = atoi(arguments[1].c_str());
|
||||
|
||||
if(!(0 <= resourceId && resourceId <= 2))
|
||||
return;
|
||||
|
||||
resourceAmmount = atoi(arguments[2].c_str());
|
||||
}
|
||||
|
||||
void AddResourceCommand::addResource(){
|
||||
Player *player = Map::getSingleton()->getPlayer(playerId);
|
||||
|
||||
switch(resourceId){
|
||||
case 0:
|
||||
player->addRefineds(resourceAmmount);
|
||||
break;
|
||||
case 1:
|
||||
player->addWealth(resourceAmmount);
|
||||
break;
|
||||
case 2:
|
||||
player->addResearch(resourceAmmount);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void AddResourceCommand::execute(){
|
||||
AbstractCommand::handle();
|
||||
validate();
|
||||
addResource();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef ADD_RESOURCE_COMMAND_H
|
||||
#define ADD_RESOURCE_COMMAND_H
|
||||
|
||||
#include "abstractCommand.h"
|
||||
|
||||
namespace battleship{
|
||||
class AddResourceCommand : public AbstractCommand{
|
||||
public:
|
||||
AddResourceCommand(std::string argsStr) : AbstractCommand(argsStr){}
|
||||
void execute();
|
||||
private:
|
||||
void validate();
|
||||
void addResource();
|
||||
|
||||
int playerId, resourceId, resourceAmmount;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "console.h"
|
||||
#include "addUnitCommand.h"
|
||||
#include "addResourceCommand.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -15,5 +16,7 @@ namespace battleship{
|
||||
|
||||
if(cmdName == "add-unit")
|
||||
AddUnitCommand(argsStr).execute();
|
||||
else if(cmdName == "add-resource")
|
||||
AddResourceCommand(argsStr).execute();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user