|
Britbot
|
00001 using System; 00002 using System.Collections.Generic; 00003 using Pirates; 00004 00005 namespace Britbot.Simulator 00006 { 00010 internal class SimulatedGroup 00011 { 00012 #region Fields & Properies 00013 00017 public double FirePower; 00018 00022 public int Id; 00023 00027 public bool IsAlive; 00028 00032 public int Owner; 00033 00037 public int ReviveTurn; 00038 00039 public bool IsCapturing; 00040 00041 //originals 00042 public bool OriginalIsAlive; 00043 public int OriginalReviveTurn; 00044 public bool OriginalIsCapturing; 00045 #endregion 00046 00047 #region Constructors & Initializers 00048 00055 public SimulatedGroup(int id, int owner, double firePower,bool isCapturing) 00056 { 00057 //just set stuff 00058 this.Id = id; 00059 this.Owner = owner; 00060 this.FirePower = firePower; 00061 this.IsCapturing = isCapturing; 00062 00063 this.IsAlive = true; 00064 this.ReviveTurn = -1; 00065 00066 //set originals 00067 this.OriginalIsAlive = IsAlive; 00068 this.OriginalIsCapturing = isCapturing; 00069 this.OriginalReviveTurn = -1; 00070 } 00071 00076 public SimulatedGroup(SimulatedGroup sg) 00077 { 00078 this.Id = sg.Id; 00079 this.Owner = sg.Owner; 00080 this.FirePower = sg.FirePower; 00081 this.IsAlive = sg.IsAlive; 00082 this.ReviveTurn = sg.ReviveTurn; 00083 } 00084 00085 #endregion 00086 00087 public bool IsBusy = false; 00088 00089 public int ActualFirePower() 00090 { 00091 if (this.IsCapturing || this.Owner == Consts.ENEMY) 00092 return (int) this.FirePower - 1; 00093 return (int) this.FirePower; 00094 } 00095 00100 public void Kill(SimulatedGame sg) 00101 { 00102 this.IsAlive = false; 00103 this.ReviveTurn = sg.CurrentTurn + Bot.Game.GetSpawnTurns(); 00104 00105 if (this.Owner == Consts.ME) 00106 sg.MyDeadPirates += (int) this.FirePower; 00107 else 00108 sg.EnemyDeadPirates += (int) this.FirePower; 00109 00110 sg.AddEvent(new ReviveEvent(this.ReviveTurn, this)); 00111 } 00112 00119 public static bool operator ==(SimulatedGroup sg1, SimulatedGroup sg2) 00120 { 00121 if (ReferenceEquals(sg1, null) && ReferenceEquals(sg2, null)) 00122 return true; //both null 00123 00124 return !ReferenceEquals(sg1,null) && !ReferenceEquals(sg2,null) && sg1.Id == sg2.Id; 00125 } 00126 00133 public static bool operator !=(SimulatedGroup sg1, SimulatedGroup sg2) 00134 { 00135 return !(sg1 == sg2); 00136 } 00137 00138 protected bool Equals(SimulatedGroup other) 00139 { 00140 return this.Id == other.Id && this.Owner == other.Owner && this.FirePower.Equals(other.FirePower) && 00141 this.IsAlive == other.IsAlive && this.ReviveTurn == other.ReviveTurn; 00142 } 00143 00144 public override bool Equals(object obj) 00145 { 00146 if (object.ReferenceEquals(null, obj)) 00147 return false; 00148 if (object.ReferenceEquals(this, obj)) 00149 return true; 00150 if (obj.GetType() != this.GetType()) 00151 return false; 00152 return Equals((SimulatedGroup)obj); 00153 } 00154 00155 public override int GetHashCode() 00156 { 00157 unchecked 00158 { 00159 int hashCode = this.Id; 00160 hashCode = (hashCode * 397) ^ this.Owner; 00161 hashCode = (hashCode * 397) ^ this.FirePower.GetHashCode(); 00162 hashCode = (hashCode * 397) ^ this.IsAlive.GetHashCode(); 00163 hashCode = (hashCode * 397) ^ this.ReviveTurn; 00164 return hashCode; 00165 } 00166 } 00167 } 00168 }
1.7.6.1