Britbot
Simulator/DeCaptureEvent.cs
Go to the documentation of this file.
00001 #region #Usings
00002 
00003 using Pirates;
00004 
00005 #endregion
00006 
00007 namespace Britbot.Simulator
00008 {
00012     internal class DeCaptureEvent : SimulatedEvent
00013     {
00014         #region Fields & Properies
00015 
00019         private SimulatedGroup Capturer;
00020 
00024         private SimulatedIsland Island;
00025 
00026         #endregion
00027 
00028         #region Constructors & Initializers
00029 
00035         public DeCaptureEvent(int turn, SimulatedIsland island, SimulatedGroup capturer) : base(turn)
00036         {
00037             this.Island = island;
00038             this.Capturer = capturer;
00039         }
00040 
00041         #endregion
00042 
00047         public override bool Activate(SimulatedGame sg)
00048         {
00049             //check if this event is still actuall
00050             if (!Capturer.IsAlive)
00051                 return false;
00052 
00053             if (this.Island.CapturingGroup != this.Capturer)
00054                 return false;
00055 
00056             //check that the island realy of the enemy
00057             if (this.Island.Owner == this.Capturer.Owner)
00058                 return false;
00059 
00060             //if everything checks out update island
00061             
00062             if (this.Island.Owner == Consts.ME)
00063                 sg.MyIslandCount -= this.Island.Value;
00064             if (this.Island.Owner == Consts.ENEMY)
00065                 sg.EnemyIslandCount -= this.Island.Value;
00066                         
00067             this.Island.Owner = Consts.NO_OWNER;
00068             this.Island.TurnsBeingCaptured = 0;
00069 
00070             //set out a capture event
00071             int captureTurn = sg.CurrentTurn + Bot.Game.Islands()[0].CaptureTurns;
00072             sg.AddEvent(new CaptureEvent(captureTurn, this.Island, this.Capturer));
00073 
00074             return false;
00075         }
00076     }
00077 }