function ResourceController::addResourceField(%this, %field)
{
   if(%this.resourceFields $= "")
      %this.resourceFields = %field;
   else
      %this.resourceFields = %this.resourceFields SPC %field;
}

function ResourceController::getResourceFields(%this)
{
   return %this.resourceFields;
}

function ResourceController::getResourceBonus(%this, %player)
{
   %resourceBonus = 0;
   %numberOfResourceFields = getWordCount(%this.resourceFields);
   
   for(%i = 0; %i < %numberOfResourceFields; %i++)
   {
      %resourceField = getWord(%this.resourceFields, %i);
      %fieldOwner = %resourceField.getOwner();
      if(isObject(%fieldOwner))
      {
         %fieldOwnerId = %fieldOwner.getId();
         %playerId = %player.getId();
         
         if(%fieldOwnerId == %playerId)
            switch$(%resourceField.getFieldSpecial())
            {
               case "resource1":
                  %resourceBonus += $pref::Game::Resource1FieldBonus;
               
               case "resource2":
                  %resourceBonus += $pref::Game::Resource2FieldBonus;
               
               case "resource3":
                  %resourceBonus += $pref::Game::Resource3FieldBonus;
            }
      }
   }
   
   return %resourceBonus;
}

function ResourceController::harvest(%this, %harvestingPlayer)
{
   if(%harvestingPlayer.getActions() < $pref::Game::ActionsLimit)
      %harvestingPlayer.addResource(1);
   
   %this.schedule(mMax($pref::Game::ResourceGainTick - %this.getResourceBonus(%harvestingPlayer) SPC $pref::Game::MinimumResourceGainTick), "harvest", %harvestingPlayer);
}