Britbot
Simulator/CaptureEvent.cs
Go to the documentation of this file.
00001 using Pirates;
00002 namespace Britbot.Simulator
00003 {
00007     internal class CaptureEvent : SimulatedEvent
00008     {
00009         #region Fields & Properies
00010 
00014         private SimulatedGroup Capturer;
00015 
00019         private SimulatedIsland Island;
00020 
00021         #endregion
00022 
00023         #region Constructors & Initializers
00024 
00030         public CaptureEvent(int turn, SimulatedIsland island, SimulatedGroup capturer) : base(turn)
00031         {
00032             this.Island = island;
00033             this.Capturer = capturer;
00034         }
00035 
00036         #endregion
00037 
00042         public override bool Activate(SimulatedGame sg)
00043         {
00044             //check if this event is still actual
00045             if (!this.Capturer.IsAlive)
00046                 return false;
00047 
00048             if (this.Island.CapturingGroup != this.Capturer)
00049                 return false;
00050 
00051             //check that the island realy of the enemy
00052             if (this.Island.Owner == this.Capturer.Owner)
00053                 return false;
00054 
00055             //if everything checks out update island
00056             if (this.Island.Owner != this.Capturer.Owner)
00057             {
00058                 if (this.Capturer.Owner == Consts.ME)
00059                     sg.MyIslandCount += this.Island.Value;
00060                 if (this.Capturer.Owner == Consts.ENEMY)
00061                     sg.EnemyIslandCount += this.Island.Value;
00062 
00063                 this.Island.Owner = this.Capturer.Owner;
00064             }
00065 
00066             return false;
00067         }
00068     }
00069 }