public void DropBombORIG(Bomb bomb)
 {
     if (bomb.owner == this.Owner)
         return;
     if (this.Owner != null && !this.Owner.GetRelations()[bomb.owner].AtWar && (this.TurnsSinceTurnover > 10 && EmpireManager.GetEmpireByName(Planet.universeScreen.PlayerLoyalty) == bomb.owner))
         this.Owner.GetGSAI().DeclareWarOn(bomb.owner, WarType.DefensiveWar);
     if ((double)this.ShieldStrengthCurrent > 0.0)
     {
         AudioEmitter emitter = new AudioEmitter();
         emitter.Position = this.shield.Center;
         if (Planet.universeScreen.viewState <= UniverseScreen.UnivScreenState.SystemView)
         {
             Cue cue = AudioManager.GetCue("sd_impact_shield_01");
             cue.Apply3D(Planet.universeScreen.listener, emitter);
             cue.Play();
         }
         this.shield.Rotation = MathHelper.ToRadians(HelperFunctions.findAngleToTarget(this.Position, new Vector2(bomb.Position.X, bomb.Position.Y)));
         this.shield.displacement = 0.0f;
         this.shield.texscale = 2.8f;
         this.shield.Radius = this.SO.WorldBoundingSphere.Radius + 100f;
         this.shield.displacement = 0.085f * RandomMath.RandomBetween(1f, 10f);
         this.shield.texscale = 2.8f;
         this.shield.texscale = (float)(2.79999995231628 - 0.185000002384186 * (double)RandomMath.RandomBetween(1f, 10f));
         this.shield.Center = new Vector3(this.Position.X, this.Position.Y, 2500f);
         this.shield.pointLight.World = bomb.GetWorld();
         this.shield.pointLight.DiffuseColor = new Vector3(0.5f, 0.5f, 1f);
         this.shield.pointLight.Radius = 50f;
         this.shield.pointLight.Intensity = 8f;
         this.shield.pointLight.Enabled = true;
         Vector3 vector3 = Vector3.Normalize(bomb.Position - this.shield.Center);
         if (Planet.universeScreen.viewState <= UniverseScreen.UnivScreenState.SystemView)
         {
             Planet.universeScreen.flash.AddParticleThreadB(bomb.Position, Vector3.Zero);
             for (int index = 0; index < 200; ++index)
                 Planet.universeScreen.sparks.AddParticleThreadB(bomb.Position, vector3 * new Vector3(RandomMath.RandomBetween(-25f, 25f), RandomMath.RandomBetween(-25f, 25f), RandomMath.RandomBetween(-25f, 25f)));
         }
         this.ShieldStrengthCurrent -= (float)ResourceManager.WeaponsDict[bomb.WeaponName].BombTroopDamage_Max;
         if ((double)this.ShieldStrengthCurrent >= 0.0)
             return;
         this.ShieldStrengthCurrent = 0.0f;
     }
     else
     {
         float num1 = RandomMath.RandomBetween(0.0f, 100f);
         bool flag1 = true;
         if ((double)num1 < 75.0)
             flag1 = false;
         this.Population -= 1000f * ResourceManager.WeaponsDict[bomb.WeaponName].BombPopulationKillPerHit;
         AudioEmitter emitter = new AudioEmitter();
         emitter.Position = bomb.Position;
         if (Planet.universeScreen.viewState <= UniverseScreen.UnivScreenState.SystemView && this.system.isVisible)
         {
             Cue cue = AudioManager.GetCue("sd_bomb_impact_01");
             cue.Apply3D(Planet.universeScreen.listener, emitter);
             cue.Play();
             ExplosionManager.AddExplosionNoFlames(bomb.Position, 200f, 7.5f, 0.6f);
             Planet.universeScreen.flash.AddParticleThreadB(bomb.Position, Vector3.Zero);
             for (int index = 0; index < 50; ++index)
                 Planet.universeScreen.explosionParticles.AddParticleThreadB(bomb.Position, Vector3.Zero);
         }
         Planet.OrbitalDrop orbitalDrop = new Planet.OrbitalDrop();
         List<PlanetGridSquare> list = new List<PlanetGridSquare>();
         if (flag1)
         {
             foreach (PlanetGridSquare planetGridSquare in this.TilesList)
             {
                 if (planetGridSquare.building != null || planetGridSquare.TroopsHere.Count > 0)
                     list.Add(planetGridSquare);
             }
             if (list.Count > 0)
             {
                 int index = (int)RandomMath.RandomBetween(0.0f, (float)list.Count + 1f);
                 if (index > list.Count - 1)
                     index = list.Count - 1;
                 orbitalDrop.Target = list[index];
             }
             else
                 flag1 = false;
         }
         if (!flag1)
         {
             int num2 = (int)RandomMath.RandomBetween(0.0f, 5f);
             int num3 = (int)RandomMath.RandomBetween(0.0f, 7f);
             if (num2 > 4)
                 num2 = 4;
             if (num3 > 6)
                 num3 = 6;
             foreach (PlanetGridSquare planetGridSquare in this.TilesList)
             {
                 if (planetGridSquare.x == num3 && planetGridSquare.y == num2)
                 {
                     orbitalDrop.Target = planetGridSquare;
                     break;
                 }
             }
         }
         if (orbitalDrop.Target.TroopsHere.Count > 0)
         {
             orbitalDrop.Target.TroopsHere[0].Strength -= (int)RandomMath.RandomBetween((float)ResourceManager.WeaponsDict[bomb.WeaponName].BombTroopDamage_Min, (float)ResourceManager.WeaponsDict[bomb.WeaponName].BombTroopDamage_Max);
             if (orbitalDrop.Target.TroopsHere[0].Strength <= 0)
             {
                 this.TroopsHere.Remove(orbitalDrop.Target.TroopsHere[0]);
                 orbitalDrop.Target.TroopsHere.Clear();
             }
         }
         else if (orbitalDrop.Target.building != null)
         {
             orbitalDrop.Target.building.Strength -= (int)RandomMath.RandomBetween((float)ResourceManager.WeaponsDict[bomb.WeaponName].BombHardDamageMin, (float)ResourceManager.WeaponsDict[bomb.WeaponName].BombHardDamageMax);
             if (orbitalDrop.Target.building.CombatStrength > 0)
                 orbitalDrop.Target.building.CombatStrength = orbitalDrop.Target.building.Strength;
             if (orbitalDrop.Target.building.Strength <= 0)
             {
                 this.BuildingList.Remove(orbitalDrop.Target.building);
                 orbitalDrop.Target.building = (Building)null;
             }
         }
         if (Planet.universeScreen.workersPanel is CombatScreen && Planet.universeScreen.LookingAtPlanet && (Planet.universeScreen.workersPanel as CombatScreen).p == this)
         {
             AudioManager.PlayCue("Explo1");
             CombatScreen.SmallExplosion smallExplosion = new CombatScreen.SmallExplosion(4);
             smallExplosion.grid = orbitalDrop.Target.ClickRect;
             lock (GlobalStats.ExplosionLocker)
                 (Planet.universeScreen.workersPanel as CombatScreen).Explosions.Add(smallExplosion);
         }
         if ((double)this.Population <= 0.0)
         {
             this.Population = 0.0f;
             if (this.Owner != null)
             {
                 this.Owner.GetPlanets().Remove(this);
                 if (this.ExploredDict[EmpireManager.GetEmpireByName(Planet.universeScreen.PlayerLoyalty)])
                 {
                     Planet.universeScreen.NotificationManager.AddPlanetDiedNotification(this, EmpireManager.GetEmpireByName(Planet.universeScreen.PlayerLoyalty));
                     bool flag2 = true;
                     if (this.Owner != null)
                     {
                         foreach (Planet planet in this.system.PlanetList)
                         {
                             if (planet.Owner == this.Owner && planet != this)
                                 flag2 = false;
                         }
                         if (flag2)
                             this.system.OwnerList.Remove(this.Owner);
                     }
                     this.ConstructionQueue.Clear();
                     this.Owner = (Empire)null;
                     return;
                 }
             }
         }
         if (ResourceManager.WeaponsDict[bomb.WeaponName].HardCodedAction == null)
             return;
         switch (ResourceManager.WeaponsDict[bomb.WeaponName].HardCodedAction)
         {
             case "Free Owlwoks":
                 if (this.Owner == null || this.Owner != EmpireManager.GetEmpireByName("Cordrazine Collective"))
                     break;
                 for (int index = 0; index < this.TroopsHere.Count; ++index)
                 {
                     if (this.TroopsHere[index].GetOwner() == EmpireManager.GetEmpireByName("Cordrazine Collective") && this.TroopsHere[index].TargetType == "Soft")
                     {
     #if STEAM
                         if (SteamManager.SetAchievement("Owlwoks_Freed"))
                             SteamManager.SaveAllStatAndAchievementChanges();
     #endif
                         this.TroopsHere[index].SetOwner(bomb.owner);
                         this.TroopsHere[index].Name = Localizer.Token(EmpireManager.GetEmpireByName("Cordrazine Collective").data.TroopNameIndex);
                         this.TroopsHere[index].Description = Localizer.Token(EmpireManager.GetEmpireByName("Cordrazine Collective").data.TroopDescriptionIndex);
                     }
                 }
                 break;
         }
     }
 }
 private void DoViewedCombat(float elapsedTime)
 {
     this.ActiveCombats.thisLock.EnterReadLock();
     foreach (Combat combat in (List<Combat>)this.ActiveCombats)
     {
         if (combat.Attacker.TroopsHere.Count == 0 && combat.Attacker.building == null)
         {
             this.ActiveCombats.QueuePendingRemoval(combat);
             break;
         }
         else
         {
             if (combat.Attacker.TroopsHere.Count > 0)
             {
                 if (combat.Attacker.TroopsHere[0].Strength <= 0)
                 {
                     this.ActiveCombats.QueuePendingRemoval(combat);
                     break;
                 }
             }
             else if (combat.Attacker.building != null && combat.Attacker.building.Strength <= 0)
             {
                 this.ActiveCombats.QueuePendingRemoval(combat);
                 break;
             }
             if (combat.Defender.TroopsHere.Count == 0 && combat.Defender.building == null)
             {
                 this.ActiveCombats.QueuePendingRemoval(combat);
                 break;
             }
             else
             {
                 if (combat.Defender.TroopsHere.Count > 0)
                 {
                     if (combat.Defender.TroopsHere[0].Strength <= 0)
                     {
                         this.ActiveCombats.QueuePendingRemoval(combat);
                         break;
                     }
                 }
                 else if (combat.Defender.building != null && combat.Defender.building.Strength <= 0)
                 {
                     this.ActiveCombats.QueuePendingRemoval(combat);
                     break;
                 }
                 float num1;
                 int num2;
                 int num3;
                 if (combat.Attacker.TroopsHere.Count > 0)
                 {
                     num1 = combat.Attacker.TroopsHere[0].Strength;
                     num2 = combat.Attacker.TroopsHere[0].GetHardAttack();
                     num3 = combat.Attacker.TroopsHere[0].GetSoftAttack();
                 }
                 else
                 {
                     num1 = combat.Attacker.building.Strength;
                     num2 = combat.Attacker.building.HardAttack;
                     num3 = combat.Attacker.building.SoftAttack;
                 }
                 string str = combat.Defender.TroopsHere.Count <= 0 ? "Hard" : combat.Defender.TroopsHere[0].TargetType;
                 combat.Timer -= elapsedTime;
                 int num4 = 0;
                 if ((double)combat.Timer < 3.0 && combat.phase == 1)
                 {
                     for (int index = 0; index < num1; ++index)
                     {
                         if ((double)RandomMath.RandomBetween(0.0f, 100f) < (str == "Soft" ? (double)num3 : (double)num2))
                             ++num4;
                     }
                     if (num4 > 0 && (combat.Defender.TroopsHere.Count > 0 || combat.Defender.building != null && combat.Defender.building.Strength > 0))
                     {
                         AudioManager.PlayCue("sd_troop_attack_hit");
                         CombatScreen.SmallExplosion smallExplosion = new CombatScreen.SmallExplosion(1);
                         smallExplosion.grid = combat.Defender.TroopClickRect;
                         lock (GlobalStats.ExplosionLocker)
                             (Planet.universeScreen.workersPanel as CombatScreen).Explosions.Add(smallExplosion);
                         if (combat.Defender.TroopsHere.Count > 0)
                         {
                             combat.Defender.TroopsHere[0].Strength -= num4;
                             if (combat.Defender.TroopsHere[0].Strength <= 0)
                             {
                                 this.TroopsHere.Remove(combat.Defender.TroopsHere[0]);
                                 combat.Defender.TroopsHere.Clear();
                                 this.ActiveCombats.QueuePendingRemoval(combat);
                                 AudioManager.PlayCue("Explo1");
                                 lock (GlobalStats.ExplosionLocker)
                                     (Planet.universeScreen.workersPanel as CombatScreen).Explosions.Add(new CombatScreen.SmallExplosion(4)
                                     {
                                         grid = combat.Defender.TroopClickRect
                                     });
                                 if (combat.Attacker.TroopsHere.Count > 0)
                                 {
                                     combat.Attacker.TroopsHere[0].AddKill();
                                 }
                             }
                         }
                         else
                         {
                             combat.Defender.building.Strength -= num4;
                             combat.Defender.building.CombatStrength -= num4;
                             if (combat.Defender.building.Strength <= 0)
                             {
                                 this.BuildingList.Remove(combat.Defender.building);
                                 combat.Defender.building = (Building)null;
                             }
                         }
                     }
                     else if (num4 == 0)
                         AudioManager.PlayCue("sd_troop_attack_miss");
                     combat.phase = 2;
                 }
                 else if (combat.phase == 2)
                     this.ActiveCombats.QueuePendingRemoval(combat);
             }
         }
     }
     this.ActiveCombats.thisLock.ExitReadLock();
 }
        //added by gremlin deveks drop bomb
        public void DropBomb(Bomb bomb)
        {
            if (bomb.owner == this.Owner)
            {
                return;
            }
            if (this.Owner != null && !this.Owner.GetRelations()[bomb.owner].AtWar && this.TurnsSinceTurnover > 10 && EmpireManager.GetEmpireByName(Planet.universeScreen.PlayerLoyalty) == bomb.owner)
            {
                this.Owner.GetGSAI().DeclareWarOn(bomb.owner, WarType.DefensiveWar);
            }
            this.CombatTimer = 10f;
            if (this.ShieldStrengthCurrent <= 0f)
            {
                float ran = RandomMath.RandomBetween(0f, 100f);
                bool hit = true;
                if (ran < 75f)
                {
                    hit = false;
                }
                Planet population = this;
                population.Population = population.Population - 1000f * ResourceManager.WeaponsDict[bomb.WeaponName].BombPopulationKillPerHit;
                AudioEmitter e = new AudioEmitter();
                e.Position = bomb.Position;
                if (Planet.universeScreen.viewState <= UniverseScreen.UnivScreenState.SystemView && this.system.isVisible)
                {
                    Cue Explode = AudioManager.GetCue("sd_bomb_impact_01");
                    Explode.Apply3D(Planet.universeScreen.listener, e);
                    Explode.Play();
                    ExplosionManager.AddExplosionNoFlames(bomb.Position, 200f, 7.5f, 0.6f);
                    Planet.universeScreen.flash.AddParticleThreadB(bomb.Position, Vector3.Zero);
                    for (int i = 0; i < 50; i++)
                    {
                        Planet.universeScreen.explosionParticles.AddParticleThreadB(bomb.Position, Vector3.Zero);
                    }
                }
                Planet.OrbitalDrop od = new Planet.OrbitalDrop();
                List<PlanetGridSquare> PotentialHits = new List<PlanetGridSquare>();
                if (hit)
                {
                    int buildingcount = 0;
                    foreach (PlanetGridSquare pgs in this.TilesList)
                    {
                        if (pgs.building == null && pgs.TroopsHere.Count <= 0)
                        {
                            continue;
                        }
                        PotentialHits.Add(pgs);
                        if(pgs.building!=null)
                        {
                            buildingcount++;
                        }
                    }
                    if ( PotentialHits.Count <= 0)
                    {
                        hit = false;
                        if (this.BuildingList.Count > 0)
                            this.BuildingList.Clear();
                    }
                    else
                    {
                        int ranhit = (int)RandomMath.RandomBetween(0f, (float)PotentialHits.Count + 1f);
                        if (ranhit > PotentialHits.Count - 1)
                        {
                            ranhit = PotentialHits.Count - 1;
                        }
                        od.Target = PotentialHits[ranhit];
                    }
                }
                if (!hit)
                {
                    int row = (int)RandomMath.RandomBetween(0f, 5f);
                    int column = (int)RandomMath.RandomBetween(0f, 7f);
                    if (row > 4)
                    {
                        row = 4;
                    }
                    if (column > 6)
                    {
                        column = 6;
                    }
                    foreach (PlanetGridSquare pgs in this.TilesList)
                    {
                        if (pgs.x != column || pgs.y != row)
                        {
                            continue;
                        }
                        od.Target = pgs;
                        break;
                    }
                }
                if (od.Target.TroopsHere.Count > 0)
                {
                    Troop item = od.Target.TroopsHere[0];
                    item.Strength = item.Strength - (int)RandomMath.RandomBetween((float)ResourceManager.WeaponsDict[bomb.WeaponName].BombTroopDamage_Min, (float)ResourceManager.WeaponsDict[bomb.WeaponName].BombTroopDamage_Max);
                    if (od.Target.TroopsHere[0].Strength <= 0)
                    {
                        this.TroopsHere.Remove(od.Target.TroopsHere[0]);
                        od.Target.TroopsHere.Clear();
                    }
                }
                else if (od.Target.building != null)
                {
                    Building target = od.Target.building;
                    target.Strength = target.Strength - (int)RandomMath.RandomBetween((float)ResourceManager.WeaponsDict[bomb.WeaponName].BombHardDamageMin, (float)ResourceManager.WeaponsDict[bomb.WeaponName].BombHardDamageMax);
                    if (od.Target.building.CombatStrength > 0)
                    {
                        od.Target.building.CombatStrength = od.Target.building.Strength;
                    }
                    if (od.Target.building.Strength <= 0)
                    {
                        this.BuildingList.Remove(od.Target.building);
                        od.Target.building = null;

                        bool flag = od.Target.Biosphere;
                        //Added Code here
                        od.Target.Habitable = false;
                        od.Target.highlighted = false;
                        od.Target.Biosphere = false;
                        this.TerraformPoints--;
                        //Building Wasteland = new Building;
                        //Wasteland.Name="Fissionables";
                        //od.Target.building=Wasteland;
                        if (flag)
                        {
                            foreach (Building bios in this.BuildingList)
                            {
                                if (bios.Name == "Biospheres")
                                {
                                    od.Target.building = bios;
                                    break;
                                }
                            }
                            if (od.Target.building != null)
                            {
                                this.Population -= od.Target.building.MaxPopIncrease;
                                this.BuildingList.Remove(od.Target.building);
                                od.Target.building = null;
                            }
                        }

                    }
                }
                if (Planet.universeScreen.workersPanel is CombatScreen && Planet.universeScreen.LookingAtPlanet && (Planet.universeScreen.workersPanel as CombatScreen).p == this)
                {
                    AudioManager.PlayCue("Explo1");
                    CombatScreen.SmallExplosion exp1 = new CombatScreen.SmallExplosion(4);
                    exp1.grid = od.Target.ClickRect;
                    lock (GlobalStats.ExplosionLocker)
                    {
                        (Planet.universeScreen.workersPanel as CombatScreen).Explosions.Add(exp1);
                    }
                }
                if (this.Population <= 0f)
                {
                    this.Population = 0f;
                    if (this.Owner != null)
                    {
                        this.Owner.GetPlanets().Remove(this);
                        if (this.ExploredDict[EmpireManager.GetEmpireByName(Planet.universeScreen.PlayerLoyalty)])
                        {
                            Planet.universeScreen.NotificationManager.AddPlanetDiedNotification(this, EmpireManager.GetEmpireByName(Planet.universeScreen.PlayerLoyalty));
                        }
                        bool removeowner = true;
                        if (this.Owner != null)
                        {
                            foreach (Planet other in this.system.PlanetList)
                            {
                                if (other.Owner != this.Owner || other == this)
                                {
                                    continue;
                                }
                                removeowner = false;
                            }
                            if (removeowner)
                            {
                                this.system.OwnerList.Remove(this.Owner);
                            }
                        }
                        this.ConstructionQueue.Clear();
                        this.Owner = null;
                        return;
                    }
                }
                if (ResourceManager.WeaponsDict[bomb.WeaponName].HardCodedAction != null)
                {
                    string hardCodedAction = ResourceManager.WeaponsDict[bomb.WeaponName].HardCodedAction;
                    string str = hardCodedAction;
                    if (hardCodedAction != null)
                    {
                        if (str != "Free Owlwoks")
                        {
                            return;
                        }
                        if (this.Owner != null && this.Owner == EmpireManager.GetEmpireByName("Cordrazine Collective"))
                        {
                            for (int i = 0; i < this.TroopsHere.Count; i++)
                            {
                                if (this.TroopsHere[i].GetOwner() == EmpireManager.GetEmpireByName("Cordrazine Collective") && this.TroopsHere[i].TargetType == "Soft")
                                {
                                    if (SteamManager.SetAchievement("Owlwoks_Freed"))
                                    {
                                        SteamManager.SaveAllStatAndAchievementChanges();
                                    }
                                    this.TroopsHere[i].SetOwner(bomb.owner);
                                    this.TroopsHere[i].Name = Localizer.Token(EmpireManager.GetEmpireByName("Cordrazine Collective").data.TroopNameIndex);
                                    this.TroopsHere[i].Description = Localizer.Token(EmpireManager.GetEmpireByName("Cordrazine Collective").data.TroopDescriptionIndex);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                AudioEmitter emitter = new AudioEmitter();
                emitter.Position = this.shield.Center;
                if (Planet.universeScreen.viewState <= UniverseScreen.UnivScreenState.SystemView)
                {
                    Cue shieldcue = AudioManager.GetCue("sd_impact_shield_01");
                    shieldcue.Apply3D(Planet.universeScreen.listener, emitter);
                    shieldcue.Play();
                }
                this.shield.Rotation = MathHelper.ToRadians(HelperFunctions.findAngleToTarget(this.Position, new Vector2(bomb.Position.X, bomb.Position.Y)));
                this.shield.displacement = 0f;
                this.shield.texscale = 2.8f;
                this.shield.Radius = this.SO.WorldBoundingSphere.Radius + 100f;
                this.shield.displacement = 0.085f * RandomMath.RandomBetween(1f, 10f);
                this.shield.texscale = 2.8f;
                this.shield.texscale = 2.8f - 0.185f * RandomMath.RandomBetween(1f, 10f);
                this.shield.Center = new Vector3(this.Position.X, this.Position.Y, 2500f);
                this.shield.pointLight.World = bomb.GetWorld();
                this.shield.pointLight.DiffuseColor = new Vector3(0.5f, 0.5f, 1f);
                this.shield.pointLight.Radius = 50f;
                this.shield.pointLight.Intensity = 8f;
                this.shield.pointLight.Enabled = true;
                Vector3 vel = Vector3.Normalize(bomb.Position - this.shield.Center);
                if (Planet.universeScreen.viewState <= UniverseScreen.UnivScreenState.SystemView)
                {
                    Planet.universeScreen.flash.AddParticleThreadB(bomb.Position, Vector3.Zero);
                    for (int i = 0; i < 200; i++)
                    {
                        Planet.universeScreen.sparks.AddParticleThreadB(bomb.Position, vel * new Vector3(RandomMath.RandomBetween(-25f, 25f), RandomMath.RandomBetween(-25f, 25f), RandomMath.RandomBetween(-25f, 25f)));
                    }
                }
                Planet shieldStrengthCurrent = this;
                shieldStrengthCurrent.ShieldStrengthCurrent = shieldStrengthCurrent.ShieldStrengthCurrent - (float)ResourceManager.WeaponsDict[bomb.WeaponName].BombTroopDamage_Max;
                if (this.ShieldStrengthCurrent < 0f)
                {
                    this.ShieldStrengthCurrent = 0f;
                    return;
                }
            }
        }