function Player::getFields(%this)
{
   return %this.fields;
}

function Player::addFields(%this, %fields)
{
   %this.fields += %fields;
   gameInstance.update();
}

function Player::getBases(%this)
{
   return %this.bases;
}

function Player::addBases(%this, %bases)
{
   %this.bases += %bases;
}

function Player::getOpponent(%this)
{
   if(%this.getName() $= "playerOne")
      return playerTwo;
   return playerOne;
}

function Player::getResource(%this)
{
   return %this.resource;
}

function Player::setResource(%this, %resource)
{
   %this.resource = %resource;
}

function Player::getActions(%this)
{
   return %this.actions;
}

function Player::setActions(%this, %actions)
{
   %this.actions = %actions;
   updateHud();
}

function Player::getMainBase(%this)
{
   return %this.mainBase;
}

function Player::addResource(%this, %resource)
{
   if(%this.resource + %resource < $pref::Game::ResourceLimit)
      %this.resource += %resource;
   else
   {
      %this.resource = (%this.resource + %resource) % $pref::Game::ResourceLimit;
      %this.addActions(1);
   }
   
   // play a sound for this player, if resources were collected
   if(%this.getId() == gameInstance.getHumanPlayer().getId() && %resource > 0)
      alxPlay(resourceCollectedSound);
   
   updateHud();
}

function Player::addActions(%this, %actions)
{
   if(%this.actions + %actions <= $pref::Game::ActionsLimit)
   {
      %this.actions += %actions;
      
      // play a sound for this player, if actions were collected
      if(%this.getId() == gameInstance.getHumanPlayer().getId() && %actions > 0)
         alxPlay(actionCollectedSound);
         
      updateHud();
   }
}

function Player::getResourceFields(%this)
{
   // get all owned resource fields and bases
   %allResourceFields = resControl.getResourceFields();
   %allResourceFieldsCount = getWordCount(%allResourceFields);
   %ownedResourceFields = "";
   for(%i = 0; %i < %allResourceFieldsCount; %i++)
   {
      %currentResourceField = getWord(%allResourceFields, %i);
      %currentResourceFieldOwner = %currentResourceField.getOwner();
      
      if(isObject(%currentResourceFieldOwner) && %currentResourceFieldOwner.getId() == %this.getId())
         %ownedResourceFields = setWord(%ownedResourceFields, getWordCount(%ownedResourceFields), %currentResourceField);
   }
   
   return %ownedResourceFields;
}