Britbot
Simulator/PossibleArrivalEvent.cs
Go to the documentation of this file.
00001 using Pirates;
00002 
00003 namespace Britbot.Simulator
00004 {
00009     internal class PossibleArrivalEvent : SimulatedEvent
00010     {
00011         #region Fields & Properies
00012 
00016         private SimulatedGroup ArrivingGroup;
00017 
00021         private SimulatedIsland Island;
00022 
00023         #endregion
00024 
00025         #region Constructors & Initializers
00026 
00032         public PossibleArrivalEvent(int turn, SimulatedIsland island, SimulatedGroup group) : base(turn)
00033         {
00034             this.Island = island;
00035             this.ArrivingGroup = group;
00036         }
00037 
00038         #endregion
00039 
00044         public override bool Activate(SimulatedGame sg)
00045         {
00046             if (this.ArrivingGroup.IsBusy)
00047                 return false;
00048 
00049             this.ArrivingGroup.IsBusy = true;
00050 
00051             if (this.ArrivingGroup == null)
00052                 return false;
00053 
00054             if (!this.ArrivingGroup.IsAlive)
00055                 return false;
00056 
00057             if (this.Island.CapturingGroup != null)
00058             {
00059                 if (this.Island.CapturingGroup.Owner == this.ArrivingGroup.Owner)
00060                     return false;
00061 
00062                 //opponenets
00063                 if (this.Island.CapturingGroup.IsAlive)
00064                 {
00065                     if (this.Island.CapturingGroup.ActualFirePower() > this.ArrivingGroup.FirePower)
00066                     {
00067                         this.ArrivingGroup.Kill(sg);
00068                         return false;
00069                     }
00070                     if (this.Island.CapturingGroup.ActualFirePower() == this.ArrivingGroup.FirePower)
00071                     {
00072                         this.ArrivingGroup.Kill(sg);
00073                         this.Island.CapturingGroup.Kill(sg);
00074                         return false;
00075                     }
00076                     this.Island.CapturingGroup.Kill(sg);
00077                     this.Island.TurnsBeingCaptured = 0;
00078                 }
00079             }
00080 
00081             this.Island.CapturingGroup = this.ArrivingGroup;
00082 
00083             if (this.Island.Owner == this.ArrivingGroup.Owner)
00084                 return false;
00085             if (this.Island.Owner == Consts.NO_OWNER)
00086                 sg.AddEvent(new CaptureEvent(sg.CurrentTurn + 20 - this.Island.TurnsBeingCaptured, this.Island,
00087                     this.ArrivingGroup));
00088             else
00089                 sg.AddEvent(new DeCaptureEvent(sg.CurrentTurn + 20 - this.Island.TurnsBeingCaptured, this.Island,
00090                     this.ArrivingGroup));
00091 
00092             return false;
00093         }
00094     }
00095 }