Skip to content

Commit

Permalink
Merge branch 'unit-limit' into dev
Browse files Browse the repository at this point in the history
This branch was supposed to resolve #31. See this issue why it was not possible to do so ;)
  • Loading branch information
namelessvoid committed Dec 8, 2013
2 parents 11bebda + dcdcf6e commit d85d798
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
10 changes: 9 additions & 1 deletion include/engine/army.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ namespace qrw
Army();
~Army();

void setMaxSize(int maxsize);

bool isFull();

/**
* @brief Add unit to the army.
*
Expand All @@ -43,10 +47,12 @@ namespace qrw
* @see UNITTYPES
* @see UnitsMap::getTotalUnitCount()
*/
int* getTotalUnitCount();
int* getUnitCount();

int getUnitCount(UNITTYPES unittype);

int getTotalUnitCount();

std::set<Unit*>& getUndeployedUnitsByType(UNITTYPES unittype);

/**
Expand All @@ -73,6 +79,8 @@ namespace qrw
int getDeployedUnitCount(UNITTYPES unittype);

private:
int maxsize;

/**
* @brief All units in the army.
*
Expand Down
1 change: 1 addition & 0 deletions include/engine/engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace qrw

ENGINSTATES getStatus();

int getMaxPlayerUnits();
void createPlayerUnits(int playerid, std::map<UNITTYPES, int> unitcounts);

Player& getCurrentPlayer();
Expand Down
24 changes: 23 additions & 1 deletion src/engine/army.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,29 @@
namespace qrw
{
Army::Army()
: maxsize(0)
{
}

Army::~Army()
{
}

void Army::setMaxSize(int maxsize)
{
this->maxsize = maxsize;
}

bool Army::isFull()
{
return getTotalUnitCount() >= maxsize;
}

bool Army::addUnit(Unit* unit)
{
if(isFull())
return false;

if(units.add(unit))
{
undeployedunits.add(unit);
Expand All @@ -32,7 +46,7 @@ namespace qrw
return (std::set<Unit*>&) units.getUnitsByType(unittype);
}

int* Army::getTotalUnitCount()
int* Army::getUnitCount()
{
return units.getTotalUnitCount();
}
Expand All @@ -42,6 +56,14 @@ namespace qrw
return units.getUnitCount(unittype);
}

int Army::getTotalUnitCount()
{
int* unitcount = getUnitCount();
int totalcount = 0;
for(int i = 0; i < EUT_NUMBEROFUNITTYPES; ++i)
totalcount += unitcount[i];
return totalcount;
}
std::set<Unit*>& Army::getUndeployedUnitsByType(UNITTYPES unittype)
{
return (std::set<Unit*>&) undeployedunits.getUnitsByType(unittype);
Expand Down
12 changes: 12 additions & 0 deletions src/engine/engine.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <stdio.h>
#include <climits>

#include "engine/engine.hpp"

Expand All @@ -24,8 +25,12 @@ namespace qrw
currentplayer = 0;
status = EES_PREPARE;

int maxarmysize = INT_MAX;
// int maxarmysize = getMaxPlayerUnits();
players[0].getArmy().deleteAllUnits();
players[0].getArmy().setMaxSize(maxarmysize);
players[1].getArmy().deleteAllUnits();
players[1].getArmy().setMaxSize(maxarmysize);
}

void Engine::startGame()
Expand All @@ -39,6 +44,13 @@ namespace qrw
return status;
}

int Engine::getMaxPlayerUnits()
{
if(board)
return (board->getHeight() * board->getWidth()) / 3;
return 0;
}

void Engine::createPlayerUnits(int playerid, std::map<UNITTYPES, int> unitcounts)
{
Player* player = getPlayer(playerid);
Expand Down

0 comments on commit d85d798

Please sign in to comment.