2018-07-09 22:33:29 +02:00
|
|
|
/* *******************************************************************
|
|
|
|
* Includes
|
|
|
|
* ******************************************************************/
|
2017-09-08 18:39:22 +02:00
|
|
|
|
2017-03-07 20:57:09 +01:00
|
|
|
#include "Player.h"
|
2018-07-26 21:15:59 +02:00
|
|
|
#include "Unit.h"
|
2018-07-09 19:26:13 +02:00
|
|
|
#include <string.h>
|
2017-09-08 18:39:22 +02:00
|
|
|
|
2018-07-09 22:33:29 +02:00
|
|
|
/* *******************************************************************
|
|
|
|
* Defines
|
|
|
|
* ******************************************************************/
|
2017-09-08 18:39:22 +02:00
|
|
|
|
2018-07-09 22:33:29 +02:00
|
|
|
/* *******************************************************************
|
|
|
|
* Types definition
|
|
|
|
* ******************************************************************/
|
2017-03-07 20:57:09 +01:00
|
|
|
|
2018-07-09 22:33:29 +02:00
|
|
|
/* *******************************************************************
|
|
|
|
* Global variables definition
|
|
|
|
* ******************************************************************/
|
2017-09-09 12:47:17 +02:00
|
|
|
|
2018-07-09 22:33:29 +02:00
|
|
|
/* *******************************************************************
|
|
|
|
* Local variables definition
|
|
|
|
* ******************************************************************/
|
|
|
|
|
|
|
|
/* *******************************************************************
|
|
|
|
* Local prototypes declaration
|
|
|
|
* ******************************************************************/
|
|
|
|
|
|
|
|
/* *******************************************************************
|
|
|
|
* Functions definition
|
|
|
|
* ******************************************************************/
|
2017-11-05 04:16:32 +01:00
|
|
|
|
2018-07-09 19:26:13 +02:00
|
|
|
/*****************************************************************//**
|
|
|
|
*
|
|
|
|
* \brief Constructor for Player class.
|
|
|
|
*
|
|
|
|
*********************************************************************/
|
2018-07-10 00:04:16 +02:00
|
|
|
Player::Player(const char* const strPlayerName):
|
|
|
|
_name{'\0'}
|
2017-11-05 04:16:32 +01:00
|
|
|
{
|
2018-07-10 00:04:16 +02:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
DEFAULT_RESOURCES = 300
|
|
|
|
};
|
|
|
|
|
2018-07-09 19:26:13 +02:00
|
|
|
if (strPlayerName != NULL)
|
2017-11-05 19:08:38 +01:00
|
|
|
{
|
2018-07-09 19:26:13 +02:00
|
|
|
strncpy(_name, strPlayerName, MAX_NAME_LENGTH);
|
2017-11-05 19:08:38 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-09 19:26:13 +02:00
|
|
|
/* Undefined player name. */
|
2017-09-08 18:39:22 +02:00
|
|
|
}
|
2018-07-10 00:04:16 +02:00
|
|
|
|
|
|
|
/* Set all resources to default value. */
|
|
|
|
memset(_resourcesMap, DEFAULT_RESOURCES, sizeof(uint8_t) * MAX_RESOURCE_TYPES);
|
2017-03-07 20:57:09 +01:00
|
|
|
}
|
2018-07-26 21:15:59 +02:00
|
|
|
|
|
|
|
void Player::handleUnits(void)
|
|
|
|
{
|
|
|
|
for (size_t szUnit = 0; szUnit < MAX_UNITS; szUnit++)
|
|
|
|
{
|
|
|
|
/* Select Unit object from internal table. */
|
|
|
|
Unit& unit = _unitsMap[szUnit];
|
|
|
|
|
|
|
|
/* Execute unit handler. */
|
|
|
|
unit.handler();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Player::drawUnits(void)
|
|
|
|
{
|
|
|
|
for (size_t szUnit = 0; szUnit < MAX_UNITS; szUnit++)
|
|
|
|
{
|
|
|
|
/* Select Unit object from internal table. */
|
|
|
|
Unit& u = _unitsMap[szUnit];
|
|
|
|
|
|
|
|
/* Execute drawHandler for selected Unit. */
|
|
|
|
u.drawHandler();
|
|
|
|
}
|
|
|
|
}
|