public SaveFleetDesignScreen(Fleet f) { this.f = f; base.IsPopup = true; base.TransitionOnTime = TimeSpan.FromSeconds(0.25); base.TransitionOffTime = TimeSpan.FromSeconds(0.25); }
public RequisitionScreen(FleetDesignScreen fds) { this.fds = fds; this.f = fds.fleet; base.IsPopup = true; base.TransitionOnTime = TimeSpan.FromSeconds(0.25); base.TransitionOffTime = TimeSpan.FromSeconds(0.25); }
protected void Dispose(bool disposing) { if (!disposed) { if (disposing) { if (this.ForcePool != null) this.ForcePool.Dispose(); if (this.BorderNodes != null) this.BorderNodes.Dispose(); if (this.SensorNodes != null) this.SensorNodes.Dispose(); if (this.OwnedShips != null) this.OwnedShips.Dispose(); if (this.SensorNodeLocker != null) this.SensorNodeLocker.Dispose(); if (this.BorderNodeLocker != null) this.BorderNodeLocker.Dispose(); if (this.DefensiveFleet != null) this.DefensiveFleet.Dispose(); if (this.GSAI != null) this.GSAI.Dispose(); } this.ForcePool = null; this.BorderNodes = null; this.SensorNodes = null; this.OwnedShips = null; this.SensorNodeLocker = null; this.BorderNodeLocker = null; this.DefensiveFleet = null; this.GSAI = null; this.disposed = true; } }
public static void CreateFleetAt(string FleetUID, Empire Owner, Vector2 Position) { FileInfo theFleetFI; if (GlobalStats.ActiveMod != null && Directory.Exists(string.Concat(Ship_Game.ResourceManager.WhichModPath, "/FleetDesigns")) && File.Exists(string.Concat(Ship_Game.ResourceManager.WhichModPath, "/FleetDesigns/", FleetUID, ".xml"))) { theFleetFI = new FileInfo(string.Concat(Ship_Game.ResourceManager.WhichModPath, "/FleetDesigns/", FleetUID, ".xml")); } else if (File.Exists(string.Concat("Content/FleetDesigns/", FleetUID, ".xml"))) { theFleetFI = new FileInfo(string.Concat("Content/FleetDesigns/", FleetUID, ".xml")); } else { string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); theFleetFI = new FileInfo(string.Concat(path, "/StarDrive/Fleet Designs/", FleetUID, ".xml")); } XmlSerializer serializer1 = new XmlSerializer(typeof(FleetDesign)); FleetDesign data = (FleetDesign)serializer1.Deserialize(theFleetFI.OpenRead()); Fleet fleet = new Fleet() { Position = Position, Owner = Owner, DataNodes = new BatchRemovalCollection<FleetDataNode>() }; foreach (FleetDataNode node in data.Data) { fleet.DataNodes.Add(node); } fleet.Name = data.Name; fleet.FleetIconIndex = data.FleetIconIndex; fleet.DataNodes.thisLock.EnterWriteLock(); foreach (FleetDataNode node in fleet.DataNodes) { Ship s = ResourceManager.CreateShipAtPoint(node.ShipName, Owner, Position + node.FleetOffset); s.RelativeFleetOffset = node.FleetOffset; node.SetShip(s); fleet.AddShip(s); } fleet.DataNodes.thisLock.ExitWriteLock(); foreach (Ship s in Owner.GetFleetsDict()[1].Ships) { s.fleet = null; } Owner.GetFleetsDict()[1] = fleet; }
public void SetCombatStatusTo(Fleet.FleetCombatStatus fcs) { this.CenterCS = fcs; this.ScreenCS = fcs; this.LeftCS = fcs; this.RightCS = fcs; this.RearCS = fcs; foreach (Ship ship in (List<Ship>)this.Ships) ship.FleetCombatStatus = fcs; }
public FleetGoal(Fleet fleet, Vector2 MovePosition, float facing, Vector2 fVec, Fleet.FleetGoalType t) { this.type = t; this.fleet = fleet; this.FinalFacingVector = fVec; this.FinalFacing = facing; this.MovePosition = MovePosition; }
private void DoFleetRequisition() { switch (this.Step) { case 0: Planet planet1 = (Planet)null; List<Planet> list = new List<Planet>(); foreach (Planet planet2 in this.empire.GetPlanets()) { if (planet2.HasShipyard) list.Add(planet2); } int num1 = 9999999; foreach (Planet planet2 in list) { if (planet2.HasShipyard) { int num2 = 0; foreach (QueueItem queueItem in (List<QueueItem>)planet2.ConstructionQueue) num2 += (int)(((double)queueItem.Cost - (double)queueItem.productionTowards) / (double)planet2.NetProductionPerTurn); if (planet2.ConstructionQueue.Count == 0) num2 = (int)(((double)this.beingBuilt.GetCost(this.empire) - (double)planet2.ProductionHere) / (double)planet2.NetProductionPerTurn); if (num2 < num1) { num1 = num2; planet1 = planet2; } } } if (planet1 == null) break; this.PlanetBuildingAt = planet1; planet1.ConstructionQueue.Add(new QueueItem() { isShip = true, QueueNumber = planet1.ConstructionQueue.Count, sData = this.beingBuilt.GetShipData(), Goal = this, Cost = this.beingBuilt.GetCost(this.empire), NotifyOnEmpty=false }); ++this.Step; break; case 2: if (this.fleet != null) { using (List<FleetDataNode>.Enumerator enumerator = this.fleet.DataNodes.GetEnumerator()) { while (enumerator.MoveNext()) { FleetDataNode current = enumerator.Current; if (current.GoalGUID == this.guid) { if (this.fleet.Ships.Count == 0) this.fleet.Position = this.beingBuilt.Position + new Vector2(RandomMath.RandomBetween(-3000f, 3000f), RandomMath.RandomBetween(-3000f, 3000f)); current.SetShip(this.beingBuilt); this.beingBuilt.fleet = this.fleet; this.beingBuilt.RelativeFleetOffset = current.FleetOffset; this.fleet.AddShip(this.beingBuilt); current.GoalGUID = Guid.Empty; this.beingBuilt.GetAI().OrderMoveToFleetPosition(this.fleet.Position + this.beingBuilt.FleetOffset, this.beingBuilt.fleet.facing, new Vector2(0.0f, -1f), true, this.fleet.speed, this.fleet); } } break; } } else { this.empire.GetGSAI().Goals.QueuePendingRemoval(this); break; } } }
public void OrderMoveToFleetPosition(Vector2 position, float desiredFacing, Vector2 fVec, bool ClearOrders, float SpeedLimit, Fleet fleet) { SpeedLimit = this.Owner.speed; if (ClearOrders) { this.OrderQueue.Clear(); lock (this.wayPointLocker) { this.ActiveWayPoints.Clear(); } } this.State = AIState.MoveTo; this.MovePosition = position; this.FinalFacingVector = fVec; this.DesiredFacing = desiredFacing; bool inCombat = this.Owner.InCombat; this.OrderQueue.AddLast(new ArtificialIntelligence.ShipGoal(ArtificialIntelligence.Plan.RotateToFaceMovePosition, this.MovePosition, 0f)); ArtificialIntelligence.ShipGoal to1k = new ArtificialIntelligence.ShipGoal(ArtificialIntelligence.Plan.MoveToWithin1000Fleet, this.MovePosition, desiredFacing) { SpeedLimit = SpeedLimit, fleet = fleet }; this.OrderQueue.AddLast(to1k); ArtificialIntelligence.ShipGoal finalApproach = new ArtificialIntelligence.ShipGoal(ArtificialIntelligence.Plan.MakeFinalApproachFleet, this.MovePosition, desiredFacing) { SpeedLimit = SpeedLimit, fleet = fleet }; this.OrderQueue.AddLast(finalApproach); this.OrderQueue.AddLast(new ArtificialIntelligence.ShipGoal(ArtificialIntelligence.Plan.RotateInlineWithVelocity, Vector2.Zero, 0f)); ArtificialIntelligence.ShipGoal slow = new ArtificialIntelligence.ShipGoal(ArtificialIntelligence.Plan.StopWithBackThrust, position, 0f) { SpeedLimit = this.Owner.speed }; this.OrderQueue.AddLast(slow); this.OrderQueue.AddLast(new ArtificialIntelligence.ShipGoal(ArtificialIntelligence.Plan.RotateToDesiredFacing, this.MovePosition, desiredFacing)); }
private void HandleFleetSelections(InputState input) { bool flag = false; int index = 10; if (input.CurrentKeyboardState.IsKeyDown(Keys.LeftControl)) { if (input.CurrentKeyboardState.IsKeyDown(Keys.D1) && input.LastKeyboardState.IsKeyUp(Keys.D1)) { index = 1; flag = true; } else if (input.CurrentKeyboardState.IsKeyDown(Keys.D2) && input.LastKeyboardState.IsKeyUp(Keys.D2)) { index = 2; flag = true; } else if (input.CurrentKeyboardState.IsKeyDown(Keys.D3) && input.LastKeyboardState.IsKeyUp(Keys.D3)) { index = 3; flag = true; } else if (input.CurrentKeyboardState.IsKeyDown(Keys.D4) && input.LastKeyboardState.IsKeyUp(Keys.D4)) { index = 4; flag = true; } else if (input.CurrentKeyboardState.IsKeyDown(Keys.D5) && input.LastKeyboardState.IsKeyUp(Keys.D5)) { index = 5; flag = true; } else if (input.CurrentKeyboardState.IsKeyDown(Keys.D6) && input.LastKeyboardState.IsKeyUp(Keys.D6)) { index = 6; flag = true; } else if (input.CurrentKeyboardState.IsKeyDown(Keys.D7) && input.LastKeyboardState.IsKeyUp(Keys.D7)) { index = 7; flag = true; } else if (input.CurrentKeyboardState.IsKeyDown(Keys.D8) && input.LastKeyboardState.IsKeyUp(Keys.D8)) { index = 8; flag = true; } else if (input.CurrentKeyboardState.IsKeyDown(Keys.D9) && input.LastKeyboardState.IsKeyUp(Keys.D9)) { index = 9; flag = true; } } if (flag && !input.CurrentKeyboardState.IsKeyDown(Keys.LeftShift)) { if (this.SelectedShipList.Count > 0) { foreach (Ship ship in (List<Ship>)this.player.GetFleetsDict()[index].Ships) ship.fleet = (Fleet)null; this.player.GetFleetsDict()[index] = (Fleet)null; string str = ""; switch (index) { case 1: str = "First"; break; case 2: str = "Second"; break; case 3: str = "Third"; break; case 4: str = "Fourth"; break; case 5: str = "Fifth"; break; case 6: str = "Sixth"; break; case 7: str = "Seventh"; break; case 8: str = "Eigth"; break; case 9: str = "Ninth"; break; } foreach (Ship ship in (List<Ship>)this.SelectedShipList) { ship.RemoveFromAllFleets(); } this.player.GetFleetsDict()[index] = new Fleet(); this.player.GetFleetsDict()[index].Name = str + " Fleet"; this.player.GetFleetsDict()[index].Owner = this.player; foreach (Ship ship in (List<Ship>)this.SelectedShipList) { if (ship.loyalty == this.player && ship.Role != "construction" && ship.Mothership == null) //fbedard: cannot add ships from hangar in fleeet this.player.GetFleetsDict()[index].Ships.Add(ship); } this.player.GetFleetsDict()[index].AutoArrange(); if (this.SelectedShip != null && this.SelectedShip != this.previousSelection) this.previousSelection = this.SelectedShip; this.SelectedShip = (Ship)null; this.SelectedShipList.Clear(); this.SelectedFlank = (List<Fleet.Squad>)null; if (this.player.GetFleetsDict()[index].Ships.Count > 0) { this.SelectedFleet = this.player.GetFleetsDict()[index]; AudioManager.PlayCue("techy_affirm1"); } else this.SelectedFleet = (Fleet)null; foreach (Ship ship in (List<Ship>)this.player.GetFleetsDict()[index].Ships) { this.SelectedShipList.Add(ship); ship.fleet = this.player.GetFleetsDict()[index]; } this.RecomputeFleetButtons(true); } } //added by gremlin add ships to exiting fleet else if (flag && input.CurrentKeyboardState.IsKeyDown(Keys.LeftShift)) { if (this.SelectedShipList.Count > 0) { //foreach (Ship ship in (List<Ship>)this.player.GetFleetsDict()[index].Ships) // ship.fleet = (Fleet)null; //this.player.GetFleetsDict()[index] = (Fleet)null; string str = ""; switch (index) { case 1: str = "First"; break; case 2: str = "Second"; break; case 3: str = "Third"; break; case 4: str = "Fourth"; break; case 5: str = "Fifth"; break; case 6: str = "Sixth"; break; case 7: str = "Seventh"; break; case 8: str = "Eigth"; break; case 9: str = "Ninth"; break; } foreach (Ship ship in (List<Ship>)this.SelectedShipList) { if (ship.fleet != null && ship.fleet.Name == str + " Fleet") continue; if (ship.fleet != null && ship.fleet.Name != str + " Fleet") ship.RemoveFromAllFleets(); } if (this.player.GetFleetsDict()[index] !=null && this.player.GetFleetsDict()[index].Ships.Count == 0) { this.player.GetFleetsDict()[index] = new Fleet(); this.player.GetFleetsDict()[index].Name = str + " Fleet"; this.player.GetFleetsDict()[index].Owner = this.player; } foreach (Ship ship in (List<Ship>)this.SelectedShipList) { if (ship.loyalty == this.player && ship.Role != "construction" && (ship.fleet ==null ||ship.fleet.Name != str + " Fleet") && ship.Mothership == null) //fbedard: cannot add ships from hangar in fleeet this.player.GetFleetsDict()[index].Ships.Add(ship); } this.player.GetFleetsDict()[index].AutoArrange(); if (this.SelectedShip != null && this.SelectedShip != this.previousSelection) this.previousSelection = this.SelectedShip; this.SelectedShip = (Ship)null; this.SelectedShipList.Clear(); this.SelectedFlank = (List<Fleet.Squad>)null; if (this.player.GetFleetsDict()[index].Ships.Count > 0) { this.SelectedFleet = this.player.GetFleetsDict()[index]; AudioManager.PlayCue("techy_affirm1"); } else this.SelectedFleet = (Fleet)null; foreach (Ship ship in (List<Ship>)this.player.GetFleetsDict()[index].Ships) { this.SelectedShipList.Add(ship); ship.fleet = this.player.GetFleetsDict()[index]; } this.RecomputeFleetButtons(true); } } //end of added by else { if (input.CurrentKeyboardState.IsKeyDown(Keys.D1) && input.LastKeyboardState.IsKeyUp(Keys.D1)) index = 1; else if (input.CurrentKeyboardState.IsKeyDown(Keys.D2) && input.LastKeyboardState.IsKeyUp(Keys.D2)) index = 2; else if (input.CurrentKeyboardState.IsKeyDown(Keys.D3) && input.LastKeyboardState.IsKeyUp(Keys.D3)) index = 3; else if (input.CurrentKeyboardState.IsKeyDown(Keys.D4) && input.LastKeyboardState.IsKeyUp(Keys.D4)) index = 4; else if (input.CurrentKeyboardState.IsKeyDown(Keys.D5) && input.LastKeyboardState.IsKeyUp(Keys.D5)) index = 5; else if (input.CurrentKeyboardState.IsKeyDown(Keys.D6) && input.LastKeyboardState.IsKeyUp(Keys.D6)) index = 6; else if (input.CurrentKeyboardState.IsKeyDown(Keys.D7) && input.LastKeyboardState.IsKeyUp(Keys.D7)) index = 7; else if (input.CurrentKeyboardState.IsKeyDown(Keys.D8) && input.LastKeyboardState.IsKeyUp(Keys.D8)) index = 8; else if (input.CurrentKeyboardState.IsKeyDown(Keys.D9) && input.LastKeyboardState.IsKeyUp(Keys.D9)) index = 9; if (index != 10) { this.SelectedPlanet = (Planet)null; if (this.SelectedShip != null && this.SelectedShip != this.previousSelection) this.previousSelection = this.SelectedShip; this.SelectedShip = (Ship)null; this.SelectedFlank = (List<Fleet.Squad>)null; if (this.player.GetFleetsDict()[index].Ships.Count > 0) { this.SelectedFleet = this.player.GetFleetsDict()[index]; AudioManager.PlayCue("techy_affirm1"); } else this.SelectedFleet = (Fleet)null; this.SelectedShipList.Clear(); foreach (Ship ship in (List<Ship>)this.player.GetFleetsDict()[index].Ships) { this.SelectedShipList.Add(ship); this.SelectedSomethingTimer = 3f; } if (this.SelectedFleet != null) { List<Ship> shipList = new List<Ship>(); foreach (Ship ship in (List<Ship>)this.SelectedFleet.Ships) shipList.Add(ship); this.shipListInfoUI.SetShipList(shipList, true); } if (this.SelectedFleet != null && (double)this.ClickTimer < (double)this.TimerDelay) { this.ViewingShip = false; this.AdjustCamTimer = 0.5f; this.transitionDestination.X = this.SelectedFleet.findAveragePosition().X; this.transitionDestination.Y = this.SelectedFleet.findAveragePosition().Y; if (this.camHeight < this.GetZfromScreenState(UniverseScreen.UnivScreenState.SystemView)) this.transitionDestination.Z = this.GetZfromScreenState(UniverseScreen.UnivScreenState.SystemView); } else if (this.SelectedFleet != null) this.ClickTimer = 0.0f; } } Fleet fleet = this.SelectedFleet; }
public void ChangeFleet(int which) { this.SelectedNodeList.Clear(); if (this.FleetToEdit != -1) { foreach (KeyValuePair<int, Ship_Game.Gameplay.Fleet> Fleet in EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).GetFleetsDict()) { foreach (Ship ship in Fleet.Value.Ships) { ship.GetSO().World = Matrix.CreateTranslation(new Vector3(ship.RelativeFleetOffset, -1000000f)); } } } this.FleetToEdit = which; List<FleetDataNode> ToRemove = new List<FleetDataNode>(); foreach (FleetDataNode node in EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).GetFleetsDict()[this.FleetToEdit].DataNodes) { if ((Ship_Game.ResourceManager.ShipsDict.ContainsKey(node.ShipName) || node.GetShip() != null) && (node.GetShip() != null || EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).WeCanBuildThis(node.ShipName))) { continue; } ToRemove.Add(node); } List<Ship_Game.Gameplay.Fleet.Squad> SquadsToRemove = new List<Ship_Game.Gameplay.Fleet.Squad>(); foreach (FleetDataNode node in ToRemove) { EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).GetFleetsDict()[this.FleetToEdit].DataNodes.Remove(node); foreach (List<Ship_Game.Gameplay.Fleet.Squad> flanks in EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).GetFleetsDict()[this.FleetToEdit].AllFlanks) { foreach (Ship_Game.Gameplay.Fleet.Squad Squad in flanks) { if (Squad.DataNodes.Contains(node)) { Squad.DataNodes.Remove(node); } if (Squad.DataNodes.Count != 0) { continue; } SquadsToRemove.Add(Squad); } } } foreach (List<Ship_Game.Gameplay.Fleet.Squad> flanks in EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).GetFleetsDict()[this.FleetToEdit].AllFlanks) { foreach (Ship_Game.Gameplay.Fleet.Squad Squad in SquadsToRemove) { if (!flanks.Contains(Squad)) { continue; } flanks.Remove(Squad); } } this.fleet = EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).GetFleetsDict()[which]; foreach (Ship ship in this.fleet.Ships) { ship.GetSO().World = Matrix.CreateTranslation(new Vector3(ship.RelativeFleetOffset, 0f)); ship.GetSO().Visibility = ObjectVisibility.Rendered; } }
public FleetDesignScreen(EmpireUIOverlay EmpireUI) { this.fleet = new Fleet(); this.EmpireUI = EmpireUI; base.TransitionOnTime = TimeSpan.FromSeconds(0.75); }
private void LoadEverything(object sender, RunWorkerCompletedEventArgs ev) { bool stop; List<SolarSystem>.Enumerator enumerator; base.ScreenManager.inter.ObjectManager.Clear(); this.data = new UniverseData(); RandomEventManager.ActiveEvent = this.savedData.RandomEvent; UniverseScreen.DeepSpaceManager = new SpatialManager(); this.ThrusterEffect = base.ScreenManager.Content.Load<Effect>("Effects/Thrust"); int count = this.data.SolarSystemsList.Count; this.data.loadFogPath = this.savedData.FogMapName; this.data.difficulty = UniverseData.GameDifficulty.Normal; this.data.difficulty = this.savedData.gameDifficulty; this.data.Size = this.savedData.Size; this.data.FTLSpeedModifier = this.savedData.FTLModifier; this.data.EnemyFTLSpeedModifier = this.savedData.EnemyFTLModifier; this.data.GravityWells = this.savedData.GravityWells; //added by gremlin: adjuse projector radius to map size. but only normal or higher. //this is pretty bad as its not connected to the creating game screen code that sets the map sizes. If someone changes the map size they wont know to change this as well. if (this.data.Size.X > 7300000f) Empire.ProjectorRadius = this.data.Size.X / 70f; EmpireManager.EmpireList.Clear(); if (Empire.universeScreen!=null && Empire.universeScreen.MasterShipList != null) Empire.universeScreen.MasterShipList.Clear(); foreach (SavedGame.EmpireSaveData d in this.savedData.EmpireDataList) { Empire e =new Empire(); e.data = new EmpireData(); e= this.CreateEmpireFromEmpireSaveData(d); this.data.EmpireList.Add(e); if (e.data.Traits.Name == this.PlayerLoyalty) { e.AutoColonize = this.savedData.AutoColonize; e.AutoExplore = this.savedData.AutoExplore; e.AutoFreighters = this.savedData.AutoFreighters; e.AutoBuild = this.savedData.AutoProjectors; } EmpireManager.EmpireList.Add(e); } foreach (Empire e in this.data.EmpireList) { if (e.data.AbsorbedBy == null) { continue; } foreach (KeyValuePair<string, TechEntry> tech in EmpireManager.GetEmpireByName(e.data.AbsorbedBy).GetTDict()) { if (!tech.Value.Unlocked) { continue; } EmpireManager.GetEmpireByName(e.data.AbsorbedBy).UnlockHullsSave(tech.Key, e.data.Traits.ShipType); } } foreach (SavedGame.EmpireSaveData d in this.savedData.EmpireDataList) { Empire e = EmpireManager.GetEmpireByName(d.Name); foreach (Relationship r in d.Relations) { e.GetRelations().Add(EmpireManager.GetEmpireByName(r.Name), r); if (r.ActiveWar == null) { continue; } r.ActiveWar.SetCombatants(e, EmpireManager.GetEmpireByName(r.Name)); } } this.data.SolarSystemsList = new List<SolarSystem>(); foreach (SavedGame.SolarSystemSaveData sdata in this.savedData.SolarSystemDataList) { SolarSystem system = this.CreateSystemFromData(sdata); system.guid = sdata.guid; this.data.SolarSystemsList.Add(system); } foreach (SavedGame.EmpireSaveData d in this.savedData.EmpireDataList) { Empire e = EmpireManager.GetEmpireByName(d.empireData.Traits.Name); foreach (SavedGame.ShipSaveData shipData in d.OwnedShips) { Ship ship = Ship.LoadSavedShip(shipData.data); ship.guid = shipData.guid; ship.Name = shipData.Name; if (!string.IsNullOrEmpty(shipData.VanityName)) ship.VanityName = shipData.VanityName; else { if (ship.Role == "troop") { if (shipData.TroopList.Count > 0) { ship.VanityName = shipData.TroopList[0].Name; } else ship.VanityName = shipData.Name; } else ship.VanityName = shipData.Name; } ship.Position = shipData.Position; if (shipData.IsPlayerShip) { this.playerShip = ship; this.playerShip.PlayerShip = true; this.data.playerShip = this.playerShip; } ship.experience = shipData.experience; ship.kills = shipData.kills; if (!Ship_Game.ResourceManager.ShipsDict.ContainsKey(shipData.Name)) { shipData.data.Hull = shipData.Hull; Ship newShip = Ship.CreateShipFromShipData(shipData.data); newShip.SetShipData(shipData.data); if (!newShip.InitForLoad()) { continue; } newShip.InitializeStatus(); newShip.IsPlayerDesign = false; newShip.FromSave = true; Ship_Game.ResourceManager.ShipsDict.Add(shipData.Name, newShip); } else if (Ship_Game.ResourceManager.ShipsDict[shipData.Name].FromSave) { ship.IsPlayerDesign = false; ship.FromSave = true; } float oldbasestr = ship.BaseStrength; float newbasestr = ResourceManager.CalculateBaseStrength(ship); ship.BaseStrength = newbasestr; foreach(ModuleSlotData moduleSD in shipData.data.ModuleSlotList) { ShipModule mismatch =null; bool exists =ResourceManager.ShipModulesDict.TryGetValue(moduleSD.InstalledModuleUID,out mismatch); if (exists) continue; System.Diagnostics.Debug.WriteLine(string.Concat("mismatch =", moduleSD.InstalledModuleUID)); } ship.PowerCurrent = shipData.Power; ship.yRotation = shipData.yRotation; ship.Ordinance = shipData.Ordnance; ship.Rotation = shipData.Rotation; ship.Velocity = shipData.Velocity; ship.isSpooling = shipData.AfterBurnerOn; ship.InCombatTimer = shipData.InCombatTimer; foreach (Troop t in shipData.TroopList) { t.SetOwner(EmpireManager.GetEmpireByName(t.OwnerString)); ship.TroopList.Add(t); } foreach (Rectangle AOO in shipData.AreaOfOperation) { ship.AreaOfOperation.Add(AOO); } ship.TetherGuid = shipData.TetheredTo; ship.TetherOffset = shipData.TetherOffset; if (ship.InCombatTimer > 0f) { ship.InCombat = true; } ship.loyalty = e; ship.InitializeAI(); ship.GetAI().CombatState = shipData.data.CombatState; ship.GetAI().FoodOrProd = shipData.AISave.FoodOrProd; ship.GetAI().State = shipData.AISave.state; ship.GetAI().DefaultAIState = shipData.AISave.defaultstate; ship.GetAI().GotoStep = shipData.AISave.GoToStep; ship.GetAI().MovePosition = shipData.AISave.MovePosition; ship.GetAI().OrbitTargetGuid = shipData.AISave.OrbitTarget; ship.GetAI().ColonizeTargetGuid = shipData.AISave.ColonizeTarget; ship.GetAI().TargetGuid = shipData.AISave.AttackTarget; ship.GetAI().SystemToDefendGuid = shipData.AISave.SystemToDefend; ship.GetAI().EscortTargetGuid = shipData.AISave.EscortTarget; bool hasCargo = false; if (shipData.FoodCount > 0f) { ship.AddGood("Food", (int)shipData.FoodCount); ship.GetAI().FoodOrProd = "Food"; hasCargo = true; } if (shipData.ProdCount > 0f) { ship.AddGood("Production", (int)shipData.ProdCount); ship.GetAI().FoodOrProd = "Prod"; hasCargo = true; } if (shipData.PopCount > 0f) { ship.AddGood("Colonists_1000", (int)shipData.PopCount); } AIState state = ship.GetAI().State; if (state == AIState.SystemTrader) { ship.GetAI().OrderTradeFromSave(hasCargo, shipData.AISave.startGuid, shipData.AISave.endGuid); } else if (state == AIState.PassengerTransport) { ship.GetAI().OrderTransportPassengersFromSave(); } e.AddShip(ship); foreach (SavedGame.ProjectileSaveData pdata in shipData.Projectiles) { Weapon w = Ship_Game.ResourceManager.GetWeapon(pdata.Weapon); Projectile p = w.LoadProjectiles(pdata.Velocity, ship); p.Velocity = pdata.Velocity; p.Position = pdata.Position; p.Center = pdata.Position; p.duration = pdata.Duration; ship.Projectiles.Add(p); } this.data.MasterShipList.Add(ship); } } foreach (SavedGame.EmpireSaveData d in this.savedData.EmpireDataList) { Empire e = EmpireManager.GetEmpireByName(d.Name); foreach (SavedGame.FleetSave fleetsave in d.FleetsList) { Ship_Game.Gameplay.Fleet fleet = new Ship_Game.Gameplay.Fleet() { guid = fleetsave.FleetGuid, IsCoreFleet = fleetsave.IsCoreFleet, facing = fleetsave.facing }; foreach (SavedGame.FleetShipSave ssave in fleetsave.ShipsInFleet) { foreach (Ship ship in this.data.MasterShipList) { if (ship.guid != ssave.shipGuid) { continue; } ship.RelativeFleetOffset = ssave.fleetOffset; fleet.AddShip(ship); } } foreach (FleetDataNode node in fleetsave.DataNodes) { fleet.DataNodes.Add(node); } foreach (FleetDataNode node in fleet.DataNodes) { foreach (Ship ship in fleet.Ships) { if (!(node.ShipGuid != Guid.Empty) || !(ship.guid == node.ShipGuid)) { continue; } node.SetShip(ship); node.ShipName = ship.Name; break; } } fleet.AssignPositions(fleet.facing); fleet.Name = fleetsave.Name; fleet.TaskStep = fleetsave.TaskStep; fleet.Owner = e; fleet.Position = fleetsave.Position; if (e.GetFleetsDict().ContainsKey(fleetsave.Key)) { e.GetFleetsDict()[fleetsave.Key] = fleet; } else { e.GetFleetsDict().TryAdd(fleetsave.Key, fleet); } e.GetFleetsDict()[fleetsave.Key].SetSpeed(); fleet.findAveragePositionset(); fleet.Setavgtodestination(); } foreach (SavedGame.ShipSaveData shipData in d.OwnedShips) { foreach (Ship ship in e.GetShips()) { if (ship.Position != shipData.Position) { continue; } } } } foreach (SavedGame.EmpireSaveData d in this.savedData.EmpireDataList) { Empire e = EmpireManager.GetEmpireByName(d.Name); e.SpaceRoadsList = new List<SpaceRoad>(); foreach (SavedGame.SpaceRoadSave roadsave in d.SpaceRoadData) { SpaceRoad road = new SpaceRoad(); foreach (SolarSystem s in this.data.SolarSystemsList) { if (roadsave.OriginGUID == s.guid) { road.SetOrigin(s); } if (roadsave.DestGUID != s.guid) { continue; } road.SetDestination(s); } foreach (SavedGame.RoadNodeSave nodesave in roadsave.RoadNodes) { RoadNode node = new RoadNode(); foreach (Ship s in this.data.MasterShipList) { if (nodesave.Guid_Platform != s.guid) { continue; } node.Platform = s; } node.Position = nodesave.Position; road.RoadNodesList.Add(node); } e.SpaceRoadsList.Add(road); } foreach (SavedGame.GoalSave gsave in d.GSAIData.Goals) { Goal g = new Goal() { empire = e, type = gsave.type }; if (g.type == GoalType.BuildShips && gsave.ToBuildUID != null && !Ship_Game.ResourceManager.ShipsDict.ContainsKey(gsave.ToBuildUID)) { continue; } g.ToBuildUID = gsave.ToBuildUID; g.Step = gsave.GoalStep; g.guid = gsave.GoalGuid; g.GoalName = gsave.GoalName; g.BuildPosition = gsave.BuildPosition; if (gsave.fleetGuid != Guid.Empty) { foreach (KeyValuePair<int, Ship_Game.Gameplay.Fleet> Fleet in e.GetFleetsDict()) { if (Fleet.Value.guid != gsave.fleetGuid) { continue; } g.SetFleet(Fleet.Value); } } foreach (SolarSystem s in this.data.SolarSystemsList) { foreach (Planet p in s.PlanetList) { if (p.guid == gsave.planetWhereBuildingAtGuid) { g.SetPlanetWhereBuilding(p); } if (p.guid != gsave.markedPlanetGuid) { continue; } g.SetMarkedPlanet(p); } } foreach (Ship s in this.data.MasterShipList) { if (gsave.colonyShipGuid == s.guid) { g.SetColonyShip(s); } if (gsave.beingBuiltGUID != s.guid) { continue; } g.SetBeingBuilt(s); } e.GetGSAI().Goals.Add(g); } for (int i = 0; i < d.GSAIData.PinGuids.Count; i++) { e.GetGSAI().ThreatMatrix.Pins.TryAdd(d.GSAIData.PinGuids[i], d.GSAIData.PinList[i]); } e.GetGSAI().UsedFleets = d.GSAIData.UsedFleets; lock (GlobalStats.TaskLocker) { foreach (MilitaryTask task in d.GSAIData.MilitaryTaskList) { task.SetEmpire(e); e.GetGSAI().TaskList.Add(task); if (task.TargetPlanetGuid != Guid.Empty) { enumerator = this.data.SolarSystemsList.GetEnumerator(); try { do { if (!enumerator.MoveNext()) { break; } SolarSystem s = enumerator.Current; stop = false; foreach (Planet p in s.PlanetList) { if (p.guid != task.TargetPlanetGuid) { continue; } task.SetTargetPlanet(p); stop = true; break; } } while (!stop); } finally { ((IDisposable)enumerator).Dispose(); } } foreach (Guid guid in task.HeldGoals) { foreach (Goal g in e.GetGSAI().Goals) { if (g.guid != guid) { continue; } g.Held = true; } } try { if (task.WhichFleet != -1) { e.GetFleetsDict()[task.WhichFleet].Task = task; } } catch { task.WhichFleet = 0; } } } foreach (SavedGame.ShipSaveData shipData in d.OwnedShips) { foreach (Ship ship in this.data.MasterShipList) { if (ship.guid != shipData.guid) { continue; } foreach (Vector2 waypoint in shipData.AISave.ActiveWayPoints) { ship.GetAI().ActiveWayPoints.Enqueue(waypoint); } foreach (SavedGame.ShipGoalSave sg in shipData.AISave.ShipGoalsList) { ArtificialIntelligence.ShipGoal g = new ArtificialIntelligence.ShipGoal(sg.Plan, sg.MovePosition, sg.FacingVector); foreach (SolarSystem s in this.data.SolarSystemsList) { foreach (Planet p in s.PlanetList) { if (sg.TargetPlanetGuid == p.guid) { g.TargetPlanet = p; ship.GetAI().ColonizeTarget = p; } if (p.guid == shipData.AISave.startGuid) { ship.GetAI().start = p; } if (p.guid != shipData.AISave.endGuid) { continue; } ship.GetAI().end = p; } } if (sg.fleetGuid != Guid.Empty) { foreach (KeyValuePair<int, Ship_Game.Gameplay.Fleet> fleet in e.GetFleetsDict()) { if (fleet.Value.guid != sg.fleetGuid) { continue; } g.fleet = fleet.Value; } } g.VariableString = sg.VariableString; g.DesiredFacing = sg.DesiredFacing; g.SpeedLimit = sg.SpeedLimit; foreach (Goal goal in ship.loyalty.GetGSAI().Goals) { if (sg.goalGuid != goal.guid) { continue; } g.goal = goal; } ship.GetAI().OrderQueue.AddLast(g); } } } } foreach (SavedGame.SolarSystemSaveData sdata in this.savedData.SolarSystemDataList) { foreach (SavedGame.RingSave rsave in sdata.RingList) { Planet p = new Planet(); foreach (SolarSystem s in this.data.SolarSystemsList) { foreach (Planet p1 in s.PlanetList) { if (p1.guid != rsave.Planet.guid) { continue; } p = p1; break; } } if (p.Owner == null) { continue; } foreach (SavedGame.QueueItemSave qisave in rsave.Planet.QISaveList) { QueueItem qi = new QueueItem(); if (qisave.isBuilding) { qi.isBuilding = true; qi.Building = Ship_Game.ResourceManager.BuildingsDict[qisave.UID]; qi.Cost = qi.Building.Cost * this.savedData.GamePacing; qi.NotifyOnEmpty = false; foreach (PlanetGridSquare pgs in p.TilesList) { if ((float)pgs.x != qisave.pgsVector.X || (float)pgs.y != qisave.pgsVector.Y) { continue; } pgs.QItem = qi; qi.pgs = pgs; break; } } if (qisave.isTroop) { qi.isTroop = true; qi.troop = Ship_Game.ResourceManager.TroopsDict[qisave.UID]; qi.Cost = qi.troop.GetCost(); qi.NotifyOnEmpty = false; } if (qisave.isShip) { qi.isShip = true; if (!Ship_Game.ResourceManager.ShipsDict.ContainsKey(qisave.UID)) { continue; } qi.sData = Ship_Game.ResourceManager.GetShip(qisave.UID).GetShipData(); qi.DisplayName = qisave.DisplayName; qi.Cost = 0f; foreach (ModuleSlot slot in Ship_Game.ResourceManager.GetShip(qisave.UID).ModuleSlotList) { if (slot.InstalledModuleUID == null) { continue; } QueueItem cost = qi; cost.Cost = cost.Cost + Ship_Game.ResourceManager.GetModule(slot.InstalledModuleUID).Cost * this.savedData.GamePacing; } QueueItem queueItem = qi; queueItem.Cost += qi.Cost * p.Owner.data.Traits.ShipCostMod; queueItem.Cost *= (GlobalStats.ActiveModInfo != null && GlobalStats.ActiveModInfo.useHullBonuses && ResourceManager.HullBonuses.ContainsKey(Ship_Game.ResourceManager.GetShip(qisave.UID).GetShipData().Hull) ? 1f - ResourceManager.HullBonuses[Ship_Game.ResourceManager.GetShip(qisave.UID).GetShipData().Hull].CostBonus : 1); if (qi.sData.HasFixedCost) { qi.Cost = (float)qi.sData.FixedCost; } if (qisave.IsRefit) { qi.isRefit = true; qi.Cost = qisave.RefitCost; } } foreach (Goal g in p.Owner.GetGSAI().Goals) { if (g.guid != qisave.GoalGUID) { continue; } qi.Goal = g; qi.NotifyOnEmpty = false; } if (qisave.isShip && qi.Goal != null) { qi.Goal.beingBuilt = Ship_Game.ResourceManager.GetShip(qisave.UID); } qi.productionTowards = qisave.ProgressTowards; p.ConstructionQueue.Add(qi); } } } this.Loaded = true; }
public virtual void UpdateShipStatus(float elapsedTime) { if ((double)elapsedTime == 0.0) return; if (Ship.universeScreen.GravityWells && this.system != null && !this.inborders) { bool flag = false; foreach (Planet planet in this.system.PlanetList) { if ((double)Vector2.Distance(this.Position, planet.Position) < (double)(GlobalStats.GravityWellRange * (1 + ((Math.Log(planet.scale))/1.5) ))) { flag = true; this.InhibitedTimer = 1.5f; break; } } if (!flag) this.InhibitedTimer = 0.0f; } this.MoveModulesTimer -= elapsedTime; this.updateTimer -= elapsedTime; //Disable if enough EMP damage --this.EMPDamage; if ((double)this.EMPDamage < 0.0) this.EMPDamage = 0.0f; else if ((double)this.EMPDamage > (double)this.Size + (double)this.BonusEMP_Protection) this.disabled = true; else this.disabled = false; this.CargoMass = 0.0f; if ((double)this.rotation > 2.0 * Math.PI) { Ship ship = this; double num = (double)ship.rotation - 6.28318548202515; ship.rotation = (float)num; } if ((double)this.rotation < 0.0) { Ship ship = this; double num = (double)ship.rotation + 6.28318548202515; ship.rotation = (float)num; } if (this.InCombat && !this.disabled && this.hasCommand || this.PlayerShip) { foreach (Weapon weapon in this.Weapons) weapon.Update(elapsedTime); } this.TroopBoardingDefense = 0.0f; foreach (Troop troop in this.TroopList) { troop.SetShip(this); if (troop.GetOwner() == this.loyalty) this.TroopBoardingDefense += (float)troop.Strength; } if (this.updateTimer <= 0.0) { if ((this.InCombat && !this.disabled && this.hasCommand || this.PlayerShip) && this.Weapons.Count > 0) { IOrderedEnumerable<Weapon> orderedEnumerable = Enumerable.OrderByDescending<Weapon, float>((IEnumerable<Weapon>)this.Weapons, (Func<Weapon, float>)(weapon => weapon.GetModifiedRange())); bool flag = false; foreach (Weapon weapon in (IEnumerable<Weapon>)orderedEnumerable) { if (weapon.DamageAmount > 0.0 && !flag) { this.maxWeaponsRange = weapon.GetModifiedRange(); flag = true; } weapon.fireDelay = Ship_Game.ResourceManager.WeaponsDict[weapon.UID].fireDelay; //Added by McShooterz: weapon tag modifiers with check if mod uses them if (GlobalStats.ActiveModInfo != null && GlobalStats.ActiveModInfo.useWeaponModifiers) { if (weapon.Tag_Beam) weapon.fireDelay += - Ship_Game.ResourceManager.WeaponsDict[weapon.UID].fireDelay * this.loyalty.data.WeaponTags["Beam"].Rate; if (weapon.Tag_Energy) weapon.fireDelay += - Ship_Game.ResourceManager.WeaponsDict[weapon.UID].fireDelay * this.loyalty.data.WeaponTags["Energy"].Rate; if (weapon.Tag_Explosive) weapon.fireDelay += - Ship_Game.ResourceManager.WeaponsDict[weapon.UID].fireDelay * this.loyalty.data.WeaponTags["Explosive"].Rate; if (weapon.Tag_Guided) weapon.fireDelay += - Ship_Game.ResourceManager.WeaponsDict[weapon.UID].fireDelay * this.loyalty.data.WeaponTags["Guided"].Rate; if (weapon.Tag_Hybrid) weapon.fireDelay += - Ship_Game.ResourceManager.WeaponsDict[weapon.UID].fireDelay * this.loyalty.data.WeaponTags["Hybrid"].Rate; if (weapon.Tag_Intercept) weapon.fireDelay += - Ship_Game.ResourceManager.WeaponsDict[weapon.UID].fireDelay * this.loyalty.data.WeaponTags["Intercept"].Rate; if (weapon.Tag_Kinetic) weapon.fireDelay += - Ship_Game.ResourceManager.WeaponsDict[weapon.UID].fireDelay * this.loyalty.data.WeaponTags["Kinetic"].Rate; if (weapon.Tag_Missile) weapon.fireDelay += - Ship_Game.ResourceManager.WeaponsDict[weapon.UID].fireDelay * this.loyalty.data.WeaponTags["Missile"].Rate; if (weapon.Tag_Railgun) weapon.fireDelay += - Ship_Game.ResourceManager.WeaponsDict[weapon.UID].fireDelay * this.loyalty.data.WeaponTags["Railgun"].Rate; if (weapon.Tag_Torpedo) weapon.fireDelay += - Ship_Game.ResourceManager.WeaponsDict[weapon.UID].fireDelay * this.loyalty.data.WeaponTags["Torpedo"].Rate; if (weapon.Tag_Cannon) weapon.fireDelay += - Ship_Game.ResourceManager.WeaponsDict[weapon.UID].fireDelay * this.loyalty.data.WeaponTags["Cannon"].Rate; if (weapon.Tag_Subspace) weapon.fireDelay += - Ship_Game.ResourceManager.WeaponsDict[weapon.UID].fireDelay * this.loyalty.data.WeaponTags["Subspace"].Rate; if (weapon.Tag_PD) weapon.fireDelay += - Ship_Game.ResourceManager.WeaponsDict[weapon.UID].fireDelay * this.loyalty.data.WeaponTags["PD"].Rate; if (weapon.Tag_Bomb) weapon.fireDelay += - Ship_Game.ResourceManager.WeaponsDict[weapon.UID].fireDelay * this.loyalty.data.WeaponTags["Bomb"].Rate; if (weapon.Tag_SpaceBomb) weapon.fireDelay += - Ship_Game.ResourceManager.WeaponsDict[weapon.UID].fireDelay * this.loyalty.data.WeaponTags["Spacebomb"].Rate; if (weapon.Tag_BioWeapon) weapon.fireDelay += - Ship_Game.ResourceManager.WeaponsDict[weapon.UID].fireDelay * this.loyalty.data.WeaponTags["BioWeapon"].Rate; if (weapon.Tag_Drone) weapon.fireDelay += - Ship_Game.ResourceManager.WeaponsDict[weapon.UID].fireDelay * this.loyalty.data.WeaponTags["Drone"].Rate; if (weapon.Tag_Warp) weapon.fireDelay += - Ship_Game.ResourceManager.WeaponsDict[weapon.UID].fireDelay * this.loyalty.data.WeaponTags["Warp"].Rate; if (weapon.Tag_Array) weapon.fireDelay += - Ship_Game.ResourceManager.WeaponsDict[weapon.UID].fireDelay * this.loyalty.data.WeaponTags["Array"].Rate; if (weapon.Tag_Flak) weapon.fireDelay += - Ship_Game.ResourceManager.WeaponsDict[weapon.UID].fireDelay * this.loyalty.data.WeaponTags["Flak"].Rate; if (weapon.Tag_Tractor) weapon.fireDelay += - Ship_Game.ResourceManager.WeaponsDict[weapon.UID].fireDelay * this.loyalty.data.WeaponTags["Tractor"].Rate; } //Added by McShooterz: Hull bonus Fire Rate if (GlobalStats.ActiveModInfo != null && GlobalStats.ActiveModInfo.useHullBonuses) { HullBonus mod; if (Ship_Game.ResourceManager.HullBonuses.TryGetValue(this.shipData.Hull, out mod)) weapon.fireDelay *= 1f - mod.FireRateBonus; } } } try { foreach (Empire index1 in EmpireManager.EmpireList) { if (index1 != this.loyalty && !this.loyalty.GetRelations()[index1].Treaty_OpenBorders) { for (int index2 = 0; index2 < index1.Inhibitors.Count; ++index2) { Ship ship = index1.Inhibitors[index2]; if (ship != null && (double)Vector2.Distance(this.Center, ship.Position) <= (double)ship.InhibitionRadius) { this.Inhibited = true; this.InhibitedTimer = 5f; break; } } if (this.Inhibited) break; } } } catch { System.Diagnostics.Debug.WriteLine("Inhibitor blew up"); } this.inSensorRange = false; if (Ship.universeScreen.Debug || this.loyalty == Ship.universeScreen.player || this.loyalty != Ship.universeScreen.player && Ship.universeScreen.player.GetRelations()[this.loyalty].Treaty_Alliance) this.inSensorRange = true; else if (!this.inSensorRange) { List<GameplayObject> nearby = UniverseScreen.ShipSpatialManager.GetNearby((GameplayObject)this); for (int index = 0; index < nearby.Count; ++index) //Parallel.For(0, nearby.Count, (index,status) => { Ship ship = nearby[index] as Ship; if (ship != null && ship.loyalty == Ship.universeScreen.player && ((double)Vector2.Distance(ship.Position, this.Center) <= (double)ship.SensorRange || Ship.universeScreen.Debug)) { this.inSensorRange = true; break; //status.Stop(); //return; } }//); } if (this.shipStatusChanged || this.InCombat) { this.Health = 0f; float sensorBonus = 0f; if (this.shipStatusChanged) { this.Hangars.Clear(); this.Shields.Clear(); this.Transporters.Clear(); this.Thrust = 0f; this.Mass = this.Size / 2f; this.shield_max = 0f; this.number_Alive_Internal_slots = 0f; this.BonusEMP_Protection = 0f; this.PowerStoreMax = 0f; this.PowerFlowMax = 0f; this.OrdinanceMax = 0f; this.ModulePowerDraw = 0.0f; this.ShieldPowerDraw = 0f; this.RepairRate = 0f; this.CargoSpace_Max = 0f; this.SensorRange = 0f; this.HasTroopBay = false; this.WarpThrust = 0f; this.TurnThrust = 0f; this.InhibitionRadius = 0f; this.OrdAddedPerSecond = 0f; this.WarpDraw = 0f; this.HealPerTurn = 0; this.ECMValue = 0f; this.FTLSpoolTime = 0f; this.hasCommand = this.IsPlatform; } foreach (ModuleSlot moduleSlot in this.ModuleSlotList) { //Get total internal slots if (moduleSlot.Restrictions == Restrictions.I && moduleSlot.module.Active) ++this.number_Alive_Internal_slots; if (moduleSlot.module.ModuleType == ShipModuleType.Dummy) continue; this.Health = (float)(this.Health + moduleSlot.module.Health); if (this.shipStatusChanged) { this.RepairRate += moduleSlot.module.BonusRepairRate; if ((double)moduleSlot.module.Mass < 0.0 && moduleSlot.Powered) { Ship ship3 = this; double num3 = (double)ship3.Mass + (double)moduleSlot.module.Mass; ship3.Mass = (float)num3; } else if ((double)moduleSlot.module.Mass > 0.0) { Ship ship3 = this; double num3; if (moduleSlot.module.ModuleType == ShipModuleType.Armor && this.loyalty != null) { float ArmourMassModifier = this.loyalty.data.ArmourMassModifier; double ArmourMass = (double)moduleSlot.module.Mass * ArmourMassModifier; num3 = (double)ship3.Mass + ArmourMass; } else { num3 = (double)ship3.Mass + (double)moduleSlot.module.Mass; } ship3.Mass = (float)num3; } //Checks to see if there is an active command module if (moduleSlot.module.Active && (moduleSlot.module.Powered || moduleSlot.module.PowerDraw == 0 )) { if (!this.hasCommand && moduleSlot.module.IsCommandModule) this.hasCommand = true; this.OrdinanceMax += (float)moduleSlot.module.OrdinanceCapacity; this.CargoSpace_Max += moduleSlot.module.Cargo_Capacity; this.InhibitionRadius += moduleSlot.module.InhibitionRadius; this.BonusEMP_Protection += moduleSlot.module.EMP_Protection; if (moduleSlot.module.SensorRange > this.SensorRange) this.SensorRange = moduleSlot.module.SensorRange; if (moduleSlot.module.SensorBonus > sensorBonus) sensorBonus = moduleSlot.module.SensorBonus; if (moduleSlot.module.shield_power_max > 0f) { this.shield_max += moduleSlot.module.GetShieldsMax(); this.ShieldPowerDraw += moduleSlot.module.PowerDraw; this.Shields.Add(moduleSlot.module); } else this.ModulePowerDraw += moduleSlot.module.PowerDraw; this.Thrust += moduleSlot.module.thrust; this.WarpThrust += (float)moduleSlot.module.WarpThrust; this.TurnThrust += (float)moduleSlot.module.TurnThrust; if (moduleSlot.module.ECM > this.ECMValue) { this.ECMValue = moduleSlot.module.ECM; if (this.ECMValue > 1.0f) this.ECMValue = 1.0f; if (this.ECMValue < 0f) this.ECMValue = 0f; } this.OrdAddedPerSecond += moduleSlot.module.OrdnanceAddedPerSecond; this.HealPerTurn += moduleSlot.module.HealPerTurn; if (moduleSlot.module.ModuleType == ShipModuleType.Hangar) { this.Hangars.Add(moduleSlot.module); if (moduleSlot.module.IsTroopBay) this.HasTroopBay = true; } if (moduleSlot.module.ModuleType == ShipModuleType.Transporter) this.Transporters.Add(moduleSlot.module); if (moduleSlot.module.InstalledWeapon != null && moduleSlot.module.InstalledWeapon.isRepairBeam) this.RepairBeams.Add(moduleSlot.module); if (moduleSlot.module.PowerStoreMax != 0) this.PowerStoreMax += moduleSlot.module.PowerStoreMax; if (moduleSlot.module.PowerFlowMax != 0) this.PowerFlowMax += moduleSlot.module.PowerFlowMax; this.WarpDraw += moduleSlot.module.PowerDrawAtWarp; if (moduleSlot.module.FTLSpoolTime > this.FTLSpoolTime) this.FTLSpoolTime = moduleSlot.module.FTLSpoolTime; } } } //Update max health due to bonuses that increase module health if (this.Health > this.HealthMax) this.HealthMax = this.Health; if (this.shipStatusChanged) { this.SensorRange += sensorBonus; //Apply modifiers to stats if (this.loyalty != null) { this.Mass *= this.loyalty.data.MassModifier; this.RepairRate += (float)(this.RepairRate * this.Level * 0.05) + this.RepairRate * this.loyalty.data.Traits.RepairMod; this.PowerFlowMax += this.PowerFlowMax * this.loyalty.data.PowerFlowMod; this.PowerStoreMax += this.PowerStoreMax * this.loyalty.data.FuelCellModifier; this.SensorRange *= this.loyalty.data.SensorModifier; } if (this.FTLSpoolTime == 0) this.FTLSpoolTime = 3f; //Hull bonuses if (GlobalStats.ActiveModInfo != null && GlobalStats.ActiveModInfo.useHullBonuses) { HullBonus mod; if (ResourceManager.HullBonuses.TryGetValue(this.shipData.Hull, out mod)) { this.RepairRate += this.RepairRate * mod.RepairBonus; this.CargoSpace_Max += this.CargoSpace_Max * mod.CargoBonus; this.SensorRange += this.SensorRange * mod.SensorBonus; this.WarpThrust += this.WarpThrust * mod.SpeedBonus; this.Thrust += this.Thrust * mod.SpeedBonus; } } } } //Power draw based on warp if (!this.inborders && this.engineState == Ship.MoveState.Warp) { this.PowerDraw = (this.loyalty.data.FTLPowerDrainModifier * this.ModulePowerDraw) + (this.WarpDraw * this.loyalty.data.FTLPowerDrainModifier / 2); } else if (this.engineState != Ship.MoveState.Warp && this.ShieldsUp) this.PowerDraw = this.ModulePowerDraw + this.ShieldPowerDraw; else this.PowerDraw = this.ModulePowerDraw; //This is what updates all of the modules of a ship foreach (ModuleSlot slot in this.ModuleSlotList) slot.module.Update(1f); //Check Current Shields if (this.engineState == Ship.MoveState.Warp || !this.ShieldsUp) this.shield_power = 0f; else { if (this.InCombat || this.shield_power != this.shield_max) { this.shield_power = 0.0f; foreach (ShipModule shield in this.Shields) this.shield_power += shield.shield_power; if (this.shield_power > this.shield_max) this.shield_power = this.shield_max; } } //Add ordnance if (this.Ordinance < this.OrdinanceMax) { this.Ordinance += this.OrdAddedPerSecond; if(this.Ordinance > this.OrdinanceMax) this.Ordinance = this.OrdinanceMax; } else this.Ordinance = this.OrdinanceMax; //Repair if (this.Health < this.HealthMax) { this.shipStatusChanged = true; if (!this.InCombat || GlobalStats.ActiveModInfo != null && GlobalStats.ActiveModInfo.useCombatRepair) { //Added by McShooterz: Priority repair float repairTracker = this.InCombat ? this.RepairRate * 0.1f : this.RepairRate; IEnumerable<ModuleSlot> damagedModules = this.ModuleSlotList.Where(moduleSlot => moduleSlot.module.ModuleType != ShipModuleType.Dummy && moduleSlot.module.Health < moduleSlot.module.HealthMax).OrderBy(moduleSlot => HelperFunctions.ModulePriority(moduleSlot.module)).AsEnumerable(); foreach (ModuleSlot moduleSlot in damagedModules) { //if destroyed do not repair in combat if (this.InCombat && moduleSlot.module.Health < 1) continue; if (moduleSlot.module.HealthMax - moduleSlot.module.Health > repairTracker) { moduleSlot.module.Repair(repairTracker); break; } else { repairTracker -= moduleSlot.module.HealthMax - moduleSlot.module.Health; moduleSlot.module.Repair(moduleSlot.module.HealthMax); } } } } else { this.shipStatusChanged = false; } List<Troop> OwnTroops = new List<Troop>(); List<Troop> EnemyTroops = new List<Troop>(); foreach (Troop troop in this.TroopList) { if (troop.GetOwner() == this.loyalty) OwnTroops.Add(troop); else EnemyTroops.Add(troop); } if (this.HealPerTurn > 0) { foreach (Troop troop in OwnTroops) { if (troop.Strength < troop.GetStrengthMax()) { troop.Strength += this.HealPerTurn; } else troop.Strength = troop.GetStrengthMax(); } } if (EnemyTroops.Count > 0) { float num1 = 0; for (int index = 0; index < this.MechanicalBoardingDefense; ++index) { if ((this.system != null ? this.system.RNG.RandomBetween(0.0f, 100f) : Ship.universeScreen.DeepSpaceRNG.RandomBetween(0.0f, 100f)) <= 60.0) ++num1; } foreach (Troop troop in EnemyTroops) { float num2 = num1; if (num1 > 0) { if (num1 > troop.Strength) { float num3 = troop.Strength; troop.Strength = 0; num1 -= num3; } else { troop.Strength -= num1; num1 -= num2; } if (troop.Strength <= 0) this.TroopList.Remove(troop); } else break; } EnemyTroops.Clear(); foreach (Troop troop in this.TroopList) EnemyTroops.Add(troop); if (OwnTroops.Count > 0 && EnemyTroops.Count > 0) { foreach (Troop troop in OwnTroops) { for (int index = 0; index < troop.Strength; ++index) { if ((this.system != null ? this.system.RNG.RandomBetween(0.0f, 100f) : Ship.universeScreen.DeepSpaceRNG.RandomBetween(0.0f, 100f)) >= troop.BoardingStrength) ++num1; } } foreach (Troop troop in EnemyTroops) { float num2 = num1; if (num1 > 0) { if (num1 > troop.Strength) { float num3 = troop.Strength; troop.Strength = 0; num1 -= num3; } else { troop.Strength -= num1; num1 -= num2; } if (troop.Strength <= 0) this.TroopList.Remove(troop); if (num1 <= 0) break; } else break; } } EnemyTroops.Clear(); foreach (Troop troop in this.TroopList) EnemyTroops.Add(troop); if (EnemyTroops.Count > 0) { float num2 = 0; foreach (Troop troop in EnemyTroops) { for (int index = 0; index < troop.Strength; ++index) { if ((this.system != null ? this.system.RNG.RandomBetween(0.0f, 100f) : Ship.universeScreen.DeepSpaceRNG.RandomBetween(0.0f, 100f)) >= troop.BoardingStrength) ++num2; } } foreach (Troop troop in OwnTroops) { float num3 = num2; if (num2 > 0) { if (num2 > troop.Strength) { float num4 = troop.Strength; troop.Strength = 0; num2 -= num4; } else { troop.Strength -= num2; num2 -= num3; } if (troop.Strength <= 0) this.TroopList.Remove(troop); } else break; } if (num2 > 0) { this.MechanicalBoardingDefense -= (float)num2; if (this.MechanicalBoardingDefense < 0.0) this.MechanicalBoardingDefense = 0.0f; } } OwnTroops.Clear(); foreach (Troop troop in this.TroopList) { if (troop.GetOwner() == this.loyalty) OwnTroops.Add(troop); } if (OwnTroops.Count == 0 && this.MechanicalBoardingDefense <= 0.0) { this.loyalty.GetShips().QueuePendingRemoval(this); this.loyalty = EnemyTroops[0].GetOwner(); this.loyalty.AddShipNextFrame(this); if (this.fleet != null) { this.fleet.Ships.Remove(this); this.fleet = (Fleet)null; } this.AI.ClearOrdersNext = true; this.AI.State = AIState.AwaitingOrders; } } //this.UpdateSystem(elapsedTime); this.updateTimer = 1f; if (this.NeedRecalculate) { this.RecalculatePower(); this.NeedRecalculate = false; } //Change FTL modifier for ship based on solar system { float ftlmodtemp =1; if (this.system != null) { bool modified = false; if (Ship.universeScreen.EnemyFTLModifier <1 || Ship.universeScreen.FTLModifier < 1) { ftlmodtemp = Ship.universeScreen.FTLModifier; modified = true; } if (this.system != null) { bool friendlySystem = true; bool count = false; foreach (Empire empire in this.system.OwnerList) { count = true; friendlySystem = false; if (this.inborders ) //||( this.loyalty.GetRelations().TryGetValue(empire, out relation) && relation.Treaty_OpenBorders)) { friendlySystem = true; break; } } if (!friendlySystem || (!Ship.universeScreen.FTLInNuetralSystems && !count)) { ftlmodtemp *= Ship.universeScreen.EnemyFTLModifier; modified = true; } } if (!modified) ftlmodtemp = 1f; } else ftlmodtemp = 1f; //Apply in borders bonus through ftl modifier this.FTLmodifier = 1; if (this.inborders && this.loyalty.data.Traits.InBordersSpeedBonus > 0) this.FTLmodifier += this.loyalty.data.Traits.InBordersSpeedBonus; this.FTLmodifier *= ftlmodtemp; } } else if (this.GetAI().BadGuysNear || (this.InFrustum && Ship.universeScreen.viewState <= UniverseScreen.UnivScreenState.SystemView )|| this.MoveModulesTimer > 0.0 || GlobalStats.ForceFullSim) // || (Ship.universeScreen !=null && Ship.universeScreen.Lag <= .03f))) { if (elapsedTime > 0.0) { //if (this.Velocity != Vector2.Zero) //this.UpdatedModulesOnce = false; if (this.Velocity != Vector2.Zero || this.isTurning || this.TetheredTo != null) { this.UpdatedModulesOnce = false; float cos = (float)Math.Cos((double)this.Rotation); float sin = (float)Math.Sin((double)this.Rotation); float tan = (float)Math.Tan((double)this.yRotation); foreach (ModuleSlot moduleSlot in this.ModuleSlotList) //Parallel.ForEach(this.ModuleSlotList, moduleSlot => { ++GlobalStats.ModuleUpdates; moduleSlot.module.UpdateEveryFrame(elapsedTime, cos, sin, tan); }//); } else if( !this.UpdatedModulesOnce) { float cos = (float)Math.Cos((double)this.Rotation); float sin = (float)Math.Sin((double)this.Rotation); float tan = (float)Math.Tan((double)this.yRotation); foreach (ModuleSlot moduleSlot in this.ModuleSlotList) //Parallel.ForEach(this.ModuleSlotList, moduleSlot => { ++GlobalStats.ModuleUpdates; moduleSlot.module.UpdateEveryFrame(elapsedTime, cos, sin, tan); }//); this.UpdatedModulesOnce = true; } } else if (elapsedTime < 0.0 && !this.UpdatedModulesOnce) { float cos = (float)Math.Cos((double)this.Rotation); float sin = (float)Math.Sin((double)this.Rotation); float tan = (float)Math.Tan((double)this.yRotation); foreach (ModuleSlot moduleSlot in this.ModuleSlotList) { ++GlobalStats.ModuleUpdates; moduleSlot.module.UpdateEveryFrame(elapsedTime, cos, sin, tan); } this.UpdatedModulesOnce = true; } } if (this.Ordinance > this.OrdinanceMax) this.Ordinance = this.OrdinanceMax; this.percent = this.number_Alive_Internal_slots / this.number_Internal_slots; if (this.percent < 0.35) this.Die(this.LastDamagedBy, false); if (this.Mass < (this.Size / 2)) this.Mass = (this.Size / 2); this.PowerCurrent -= this.PowerDraw * elapsedTime; if (this.PowerCurrent < this.PowerStoreMax) this.PowerCurrent += (this.PowerFlowMax + (this.loyalty != null ? this.PowerFlowMax * this.loyalty.data.PowerFlowMod : 0)) * elapsedTime; //if (this.ResourceDrawDict.Count > 0) //{ // //foreach (KeyValuePair<string, float> draw in this.ResourceDrawDict) // //{ // // string index1 = draw.Key; // // float drawvalue = draw.Value; // // if (drawvalue <= 0 || this.CargoDict[index1] <= 0.0f) // // continue; // // float store = this.CargoDict[index1]; // // store -= drawvalue * elapsedTime; // // if (store < 0) // // store = 0; // // this.CargoDict[index1] = store; // //} // foreach (string index1 in Enumerable.ToList<string>((IEnumerable<string>)this.ResourceDrawDict.Keys)) // { // Dictionary<string, float> dictionary; // string index2; // (dictionary = this.CargoDict)[index2 = index1] = dictionary[index2] - this.ResourceDrawDict[index1] * elapsedTime; // if ((double)this.CargoDict[index1] <= 0.0) // this.CargoDict[index1] = 0.0f; // } //} if (this.PowerCurrent <= 0.0) { this.PowerCurrent = 0.0f; this.HyperspaceReturn(); } if (this.PowerCurrent > this.PowerStoreMax) this.PowerCurrent = this.PowerStoreMax; if (this.shield_percent < 0.0) this.shield_percent = 0.0; this.shield_percent = 100.0 * this.shield_power / this.shield_max; if (this.shield_percent < 0.0) this.shield_percent = 0.0; if (this.Mass <= 0.0) this.Mass = 1f; switch (this.engineState) { case Ship.MoveState.Sublight: this.velocityMaximum = this.GetSTLSpeed(); break; case Ship.MoveState.Warp: this.velocityMaximum = this.GetFTLSpeed(); break; } this.speed = this.velocityMaximum; this.rotationRadiansPerSecond = this.TurnThrust / this.Mass / 700f; this.rotationRadiansPerSecond += (float)(this.rotationRadiansPerSecond * this.Level * 0.0500000007450581); this.yBankAmount = this.rotationRadiansPerSecond * elapsedTime;// 50f; if (this.engineState == Ship.MoveState.Warp) { //if (this.FTLmodifier != 1f) //this.velocityMaximum *= this.FTLmodifier; this.Velocity = Vector2.Normalize(new Vector2((float)Math.Sin((double)this.Rotation), -(float)Math.Cos((double)this.Rotation))) * this.velocityMaximum; } if (this.Thrust == 0.0 || this.mass == 0.0) { this.EnginesKnockedOut = true; this.velocityMaximum = this.Velocity.Length(); Ship ship = this; Vector2 vector2 = ship.velocity - this.velocity * (elapsedTime * 0.1f); ship.velocity = vector2; } else this.EnginesKnockedOut = false; if (this.Velocity.Length() <= this.velocityMaximum) return; this.Velocity = Vector2.Normalize(this.Velocity) * this.velocityMaximum; }
public void Initialize() { this.GSAI = new GSAI(this); for (int key = 1; key < 100; ++key) { Fleet fleet = new Fleet(); fleet.Owner = this; string str = ""; switch (key) { case 0: str = "10th"; break; case 1: str = "1st"; break; case 2: str = "2nd"; break; case 3: str = "3rd"; break; case 4: str = "4th"; break; case 5: str = "5th"; break; case 6: str = "6th"; break; case 7: str = "7th"; break; case 8: str = "8th"; break; case 9: str = "9th"; break; } fleet.Name = str + " fleet"; this.FleetsDict.TryAdd(key, fleet); } foreach (KeyValuePair<string, Technology> keyValuePair in ResourceManager.TechTree) { TechEntry techEntry = new TechEntry(); techEntry.Progress = 0.0f; techEntry.UID = keyValuePair.Key; //added by McShooterz: Checks if tech is racial, hides it, and reveals it only to races that pass if (keyValuePair.Value.RaceRestrictions.Count != 0) { techEntry.Discovered = false; techEntry.GetTech().Secret = true; foreach (Technology.RequiredRace raceTech in keyValuePair.Value.RaceRestrictions) { if (raceTech.ShipType == this.data.Traits.ShipType) { techEntry.Discovered = true; techEntry.Unlocked = keyValuePair.Value.RootNode == 1; if (this.data.Traits.Militaristic == 1 && techEntry.GetTech().Militaristic) techEntry.Unlocked = true; break; } } } else //not racial tech { techEntry.Unlocked = keyValuePair.Value.RootNode == 1; } if (this.isFaction || this.data.Traits.Prewarp == 1) { techEntry.Unlocked = false; } if (this.data.Traits.Militaristic == 1) { //added by McShooterz: alternate way to unlock militaristic techs if (techEntry.GetTech().Militaristic && techEntry.GetTech().RaceRestrictions.Count == 0) techEntry.Unlocked = true; // If using the customMilTraitsTech option in ModInformation, default traits will NOT be automatically unlocked. Allows for totally custom militaristic traits. if (GlobalStats.ActiveModInfo == null || (GlobalStats.ActiveModInfo != null && !GlobalStats.ActiveModInfo.customMilTraitTechs)) { if (techEntry.UID == "HeavyFighterHull") { techEntry.Unlocked = true; } if (techEntry.UID == "Military") { techEntry.Unlocked = true; } if (techEntry.UID == "ArmorTheory") { techEntry.Unlocked = true; } } } if(this.data.Traits.Cybernetic >0) { if (techEntry.UID == "Biospheres") techEntry.Unlocked = true; } if (techEntry.Unlocked) techEntry.Progress = techEntry.GetTech().Cost * UniverseScreen.GamePaceStatic; this.TechnologyDict.Add(keyValuePair.Key, techEntry); } foreach (KeyValuePair<string, ShipData> keyValuePair in ResourceManager.HullsDict) this.UnlockedHullsDict.Add(keyValuePair.Value.Hull, false); foreach (KeyValuePair<string, Troop> keyValuePair in ResourceManager.TroopsDict) this.UnlockedTroopDict.Add(keyValuePair.Key, false); foreach (KeyValuePair<string, Building> keyValuePair in ResourceManager.BuildingsDict) this.UnlockedBuildingsDict.Add(keyValuePair.Key, false); foreach (KeyValuePair<string, ShipModule> keyValuePair in ResourceManager.ShipModulesDict) this.UnlockedModulesDict.Add(keyValuePair.Key, false); //unlock from empire data file foreach (string building in this.data.unlockBuilding) this.UnlockedBuildingsDict[building] = true; foreach (KeyValuePair<string, TechEntry> keyValuePair in this.TechnologyDict) { if (keyValuePair.Value.Unlocked) { keyValuePair.Value.Unlocked = false; this.UnlockTech(keyValuePair.Key); } } //unlock ships from empire data foreach (string ship in this.data.unlockShips) this.ShipsWeCanBuild.Add(ship); //clear these lists as they serve no more purpose this.data.unlockBuilding.Clear(); this.data.unlockShips.Clear(); this.UpdateShipsWeCanBuild(); if (this.data.EconomicPersonality == null) this.data.EconomicPersonality = new ETrait { Name = "Generalists" }; //Added by McShooterz: mod support for EconomicResearchStrategy folder try { if (File.Exists(string.Concat(Ship_Game.ResourceManager.WhichModPath, "/EconomicResearchStrategy/", this.data.EconomicPersonality.Name, ".xml"))) { this.economicResearchStrategy = (EconomicResearchStrategy)ResourceManager.EconSerializer.Deserialize((Stream)new FileInfo(string.Concat(Ship_Game.ResourceManager.WhichModPath, "/EconomicResearchStrategy/", this.data.EconomicPersonality.Name, ".xml")).OpenRead()); } else { this.economicResearchStrategy = (EconomicResearchStrategy)ResourceManager.EconSerializer.Deserialize((Stream)new FileInfo("Content/EconomicResearchStrategy/" + this.data.EconomicPersonality.Name + ".xml").OpenRead()); } } catch(Exception e) { e.Data.Add("Failing File: ", string.Concat(Ship_Game.ResourceManager.WhichModPath, "/EconomicResearchStrategy/", this.data.EconomicPersonality.Name, ".xml")); e.Data.Add("Fail Reaseon: ", e.InnerException); throw e; } //Added by gremlin Figure out techs with modules that we have ships for. foreach (KeyValuePair<string,TechEntry> tech in this.TechnologyDict) { if(tech.Value.GetTech().ModulesUnlocked.Count>0 && tech.Value.GetTech().HullsUnlocked.Count()==0 && !this.WeCanUseThis(tech.Value.GetTech())) { this.TechnologyDict[tech.Key].shipDesignsCanuseThis = false; } } foreach (KeyValuePair<string,TechEntry> tech in this.TechnologyDict) { if(!tech.Value.shipDesignsCanuseThis) { if(WeCanUseThisLater(tech.Value)) { tech.Value.shipDesignsCanuseThis = true; } } } this.MarkShipDesignsUnlockable(); }
protected void HandleRightMouseNew(InputState input) { if (this.SkipRightOnce) { if (input.CurrentMouseState.RightButton != ButtonState.Released || input.LastMouseState.RightButton != ButtonState.Released) return; this.SkipRightOnce = false; } else { Viewport viewport; if (input.CurrentMouseState.RightButton == ButtonState.Pressed && input.LastMouseState.RightButton == ButtonState.Released) { this.SelectedSomethingTimer = 3f; this.startDrag = new Vector2((float)input.CurrentMouseState.X, (float)input.CurrentMouseState.Y); this.startDragWorld = this.GetWorldSpaceFromScreenSpace(this.startDrag); this.ProjectedPosition = this.GetWorldSpaceFromScreenSpace(this.startDrag); Vector3 position = this.ScreenManager.GraphicsDevice.Viewport.Unproject(new Vector3((float)input.CurrentMouseState.X, (float)input.CurrentMouseState.Y, 0.0f), this.projection, this.view, Matrix.Identity); viewport = this.ScreenManager.GraphicsDevice.Viewport; Vector3 direction = viewport.Unproject(new Vector3((float)input.CurrentMouseState.X, (float)input.CurrentMouseState.Y, 1f), this.projection, this.view, Matrix.Identity) - position; direction.Normalize(); Ray ray = new Ray(position, direction); float num = -ray.Position.Z / ray.Direction.Z; Vector3 vector3 = new Vector3(ray.Position.X + num * ray.Direction.X, ray.Position.Y + num * ray.Direction.Y, 0.0f); } if (this.SelectedShip != null && this.SelectedShip.GetAI().State == AIState.ManualControl && (double)Vector2.Distance(this.startDragWorld, this.SelectedShip.Center) < 5000.0) return; if (input.CurrentMouseState.RightButton == ButtonState.Released && input.LastMouseState.RightButton == ButtonState.Pressed) { viewport = this.ScreenManager.GraphicsDevice.Viewport; Vector3 position = viewport.Unproject(new Vector3((float)input.CurrentMouseState.X, (float)input.CurrentMouseState.Y, 0.0f), this.projection, this.view, Matrix.Identity); viewport = this.ScreenManager.GraphicsDevice.Viewport; Vector3 direction = viewport.Unproject(new Vector3((float)input.CurrentMouseState.X, (float)input.CurrentMouseState.Y, 1f), this.projection, this.view, Matrix.Identity) - position; direction.Normalize(); Ray ray = new Ray(position, direction); float num1 = -ray.Position.Z / ray.Direction.Z; Vector3 vector3 = new Vector3(ray.Position.X + num1 * ray.Direction.X, ray.Position.Y + num1 * ray.Direction.Y, 0.0f); Vector2 vector2_1 = new Vector2(vector3.X, vector3.Y); Vector2 target = new Vector2((float)input.CurrentMouseState.X, (float)input.CurrentMouseState.Y); float num2 = Math.Abs(MathHelper.ToRadians(this.findAngleToTarget(this.startDrag, target))); Vector2 vector2_2 = Vector2.Normalize(target - this.startDrag); if ((double)input.RightMouseTimer > 0.0) { if (this.SelectedFleet != null && this.SelectedFleet.Owner == this.player) { AudioManager.PlayCue("echo_affirm1"); this.SelectedSomethingTimer = 3f; float num3 = Math.Abs(MathHelper.ToRadians(this.findAngleToTarget(this.SelectedFleet.Position, vector2_1))); Vector2 vectorToTarget = HelperFunctions.FindVectorToTarget(Vector2.Zero, HelperFunctions.findPointFromAngleAndDistanceUsingRadians(this.SelectedFleet.Position, num3, 1f)); foreach (Ship ship in (List<Ship>)this.SelectedFleet.Ships) this.player.GetGSAI().DefensiveCoordinator.remove(ship); Ship ship1 = this.CheckShipClick(this.startDrag); Planet planet; lock (GlobalStats.ClickableSystemsLock) planet = this.CheckPlanetClick(this.startDrag); if (ship1 != null && ship1.loyalty != this.player) { this.SelectedFleet.Position = ship1.Center; this.SelectedFleet.AssignPositions(0.0f); foreach (Ship ship2 in (List<Ship>)this.SelectedFleet.Ships) { if (ship2.Role == "troop") ship2.GetAI().OrderTroopToBoardShip(ship1); else if (input.CurrentKeyboardState.IsKeyDown(Keys.LeftShift)) ship2.GetAI().OrderQueueSpecificTarget(ship1); else ship2.GetAI().OrderAttackSpecificTarget(ship1); } } else if (planet != null) { foreach (Ship ship2 in (List<Ship>)this.SelectedFleet.Ships) { RightClickship(ship2, planet,false); } } else if (input.CurrentKeyboardState.IsKeyDown(Keys.LeftShift)) this.SelectedFleet.FormationWarpToQ(vector2_1, num3, vectorToTarget); else if (input.CurrentKeyboardState.IsKeyDown(Keys.LeftAlt)) this.SelectedFleet.MoveToDirectly(vector2_1, num3, vectorToTarget); else this.SelectedFleet.FormationWarpTo(vector2_1, num3, vectorToTarget); } else if (this.SelectedShip != null && this.SelectedShip.loyalty == this.player) { this.player.GetGSAI().DefensiveCoordinator.DefensiveForcePool.Remove(this.SelectedShip); this.SelectedSomethingTimer = 3f; Ship ship = this.CheckShipClick(this.startDrag); Planet planet; lock (GlobalStats.ClickableSystemsLock) planet = this.CheckPlanetClick(this.startDrag); if (ship != null && ship != this.SelectedShip) #region Target Ship { if (this.SelectedShip.Role == "construction") { AudioManager.PlayCue("UI_Misc20"); return; } else { AudioManager.PlayCue("echo_affirm1"); if (ship.loyalty == this.player) { if (this.SelectedShip.Role == "troop") { if (ship.TroopList.Count < ship.TroopCapacity) this.SelectedShip.GetAI().OrderTroopToShip(ship); else this.SelectedShip.DoEscort(ship); } else this.SelectedShip.DoEscort(ship); } else if (this.SelectedShip.Role == "troop") this.SelectedShip.GetAI().OrderTroopToBoardShip(ship); else if (input.CurrentKeyboardState.IsKeyDown(Keys.LeftShift)) this.SelectedShip.GetAI().OrderQueueSpecificTarget(ship); else this.SelectedShip.GetAI().OrderAttackSpecificTarget(ship); } } #endregion else if (ship != null && ship == this.SelectedShip) { if (ship.loyalty == this.player) this.LoadShipMenuNodes(1); else this.LoadShipMenuNodes(0); if (!this.pieMenu.Visible) { this.pieMenu.RootNode = this.shipMenu; this.pieMenu.Show(this.pieMenu.Position); } else this.pieMenu.ChangeTo((PieMenuNode)null); } else if (planet != null) { RightClickship(this.SelectedShip, planet,true); } else if (this.SelectedShip.Role == "construction") { AudioManager.PlayCue("UI_Misc20"); return; } else { AudioManager.PlayCue("echo_affirm1"); if (input.CurrentKeyboardState.IsKeyDown(Keys.LeftShift)) { if (input.CurrentKeyboardState.IsKeyDown(Keys.LeftAlt)) this.SelectedShip.GetAI().OrderMoveDirectlyTowardsPosition(vector2_1, num2, vector2_2, false); else this.SelectedShip.GetAI().OrderMoveTowardsPosition(vector2_1, num2, vector2_2, false,null); } else if (input.CurrentKeyboardState.IsKeyDown(Keys.LeftAlt)) this.SelectedShip.GetAI().OrderMoveDirectlyTowardsPosition(vector2_1, num2, vector2_2, true); else if (input.CurrentKeyboardState.IsKeyDown(Keys.LeftControl)) { this.SelectedShip.GetAI().OrderMoveTowardsPosition(vector2_1, num2, vector2_2, true,null); this.SelectedShip.GetAI().OrderQueue.AddLast(new ArtificialIntelligence.ShipGoal(ArtificialIntelligence.Plan.HoldPosition, vector2_1, num2)); this.SelectedShip.GetAI().HasPriorityOrder = true; this.SelectedShip.GetAI().IgnoreCombat = true; } else this.SelectedShip.GetAI().OrderMoveTowardsPosition(vector2_1, num2, vector2_2, true,null); } } else if (this.SelectedShipList.Count > 0) { this.SelectedSomethingTimer = 3f; foreach (Ship ship in (List<Ship>)this.SelectedShipList) { if (ship.loyalty != this.player || ship.Role == "construction") { AudioManager.PlayCue("UI_Misc20"); return; } } AudioManager.PlayCue("echo_affirm1"); Ship ship1 = this.CheckShipClick(this.startDrag); Planet planet; lock (GlobalStats.ClickableSystemsLock) planet = this.CheckPlanetClick(this.startDrag); if (ship1 != null || planet != null) #region Target Planet { foreach (Ship ship2 in (List<Ship>)this.SelectedShipList) { this.player.GetGSAI().DefensiveCoordinator.remove(ship2); if (ship1 != null && ship1 != ship2) { if (ship1.loyalty == this.player) { if (ship2.Role == "troop") { if (ship1.TroopList.Count < ship1.TroopCapacity) ship2.GetAI().OrderTroopToShip(ship1); else ship2.DoEscort(ship1); } else ship2.DoEscort(ship1); } else if (ship2.Role == "troop") ship2.GetAI().OrderTroopToBoardShip(ship1); else if (input.CurrentKeyboardState.IsKeyDown(Keys.LeftShift)) ship2.GetAI().OrderQueueSpecificTarget(ship1); else ship2.GetAI().OrderAttackSpecificTarget(ship1); } else if (planet != null) { RightClickship(ship2, planet, false); } } } #endregion else { this.SelectedSomethingTimer = 3f; foreach (Ship ship2 in (List<Ship>)this.SelectedShipList) { if (ship2.Role == "construction") { this.SelectedShipList.Clear(); AudioManager.PlayCue("UI_Misc20"); return; } } AudioManager.PlayCue("echo_affirm1"); this.endDragWorld = this.GetWorldSpaceFromScreenSpace(input.CursorPosition); Enumerable.OrderBy<Ship, float>((IEnumerable<Ship>)this.SelectedShipList, (Func<Ship, float>)(ship => ship.Center.X)); Vector2 fVec = new Vector2(-vector2_2.Y, vector2_2.X); float num3 = Vector2.Distance(this.endDragWorld, this.startDragWorld); int num4 = 0; int num5 = 0; float num6 = 0.0f; for (int index = 0; index < this.SelectedShipList.Count; ++index) { this.player.GetGSAI().DefensiveCoordinator.remove(this.SelectedShipList[index]); if ((double)this.SelectedShipList[index].GetSO().WorldBoundingSphere.Radius > (double)num6) num6 = this.SelectedShipList[index].GetSO().WorldBoundingSphere.Radius; } Fleet fleet = new Fleet(); if ((double)this.SelectedShipList.Count * (double)num6 > (double)num3) { for (int index = 0; index < this.SelectedShipList.Count; ++index) { fleet.AddShip(this.SelectedShipList[index].SoftCopy()); fleet.Ships[index].RelativeFleetOffset = new Vector2((num6 + 200f) * (float)num5, (float)num4 * (num6 + 200f)); ++num5; if ((double)fleet.Ships[index].RelativeFleetOffset.X + (double)num6 > (double)num3) { num5 = 0; ++num4; } } } else { float num7 = num3 / (float)this.SelectedShipList.Count; for (int index = 0; index < this.SelectedShipList.Count; ++index) { fleet.AddShip(this.SelectedShipList[index].SoftCopy()); fleet.Ships[index].RelativeFleetOffset = new Vector2(num7 * (float)index, 0.0f); } } fleet.ProjectPos(this.endDragWorld, num2 - 1.570796f, fVec); foreach (Ship ship2 in (List<Ship>)fleet.Ships) { foreach (Ship ship3 in (List<Ship>)this.SelectedShipList) { if (ship2.guid == ship3.guid) { if (input.CurrentKeyboardState.IsKeyDown(Keys.LeftShift)) { if (input.CurrentKeyboardState.IsKeyDown(Keys.LeftAlt)) ship3.GetAI().OrderMoveDirectlyTowardsPosition(ship2.projectedPosition, num2 - 1.570796f, fVec, false); else ship3.GetAI().OrderMoveTowardsPosition(ship2.projectedPosition, num2 - 1.570796f, fVec, false,null); } else if (input.CurrentKeyboardState.IsKeyDown(Keys.LeftAlt)) ship3.GetAI().OrderMoveDirectlyTowardsPosition(ship2.projectedPosition, num2 - 1.570796f, fVec, true); else ship3.GetAI().OrderMoveTowardsPosition(ship2.projectedPosition, num2 - 1.570796f, fVec, true,null); } } } this.projectedGroup = (ShipGroup)fleet; fleet.Reset(); } } if (this.SelectedFlank == null && this.SelectedFleet == null && (this.SelectedItem == null && this.SelectedShip == null) && (this.SelectedPlanet == null && this.SelectedShipList.Count == 0)) { Ship ship = this.CheckShipClick(input.CursorPosition); if (ship != null) { this.SelectedShip = ship; if (ship.loyalty == this.player) this.LoadShipMenuNodes(1); else this.LoadShipMenuNodes(0); if (!this.pieMenu.Visible) { this.pieMenu.RootNode = this.shipMenu; this.pieMenu.Show(this.pieMenu.Position); } else this.pieMenu.ChangeTo((PieMenuNode)null); } } } else { this.ProjectingPosition = true; if (this.SelectedFleet != null && this.SelectedFleet.Owner == this.player) { this.SelectedSomethingTimer = 3f; if (input.CurrentKeyboardState.IsKeyDown(Keys.LeftShift)) this.SelectedFleet.FormationWarpToQ(this.ProjectedPosition, num2, vector2_2); else this.SelectedFleet.FormationWarpTo(this.ProjectedPosition, num2, vector2_2); AudioManager.PlayCue("echo_affirm1"); foreach (Ship ship in (List<Ship>)this.SelectedFleet.Ships) this.player.GetGSAI().DefensiveCoordinator.remove(ship); } else if (this.SelectedShip != null && this.SelectedShip.loyalty == this.player) { this.player.GetGSAI().DefensiveCoordinator.remove(this.SelectedShip); this.SelectedSomethingTimer = 3f; if (this.SelectedShip.Role == "construction") { if (this.SelectedShip != null && this.SelectedShip != this.previousSelection) this.previousSelection = this.SelectedShip; this.SelectedShip = (Ship)null; AudioManager.PlayCue("UI_Misc20"); return; } else { AudioManager.PlayCue("echo_affirm1"); if (input.CurrentKeyboardState.IsKeyDown(Keys.LeftShift)) { if (input.CurrentKeyboardState.IsKeyDown(Keys.LeftAlt)) this.SelectedShip.GetAI().OrderMoveDirectlyTowardsPosition(this.ProjectedPosition, num2, vector2_2, false); else this.SelectedShip.GetAI().OrderMoveTowardsPosition(this.ProjectedPosition, num2, vector2_2, false,null); } else if (input.CurrentKeyboardState.IsKeyDown(Keys.LeftAlt)) this.SelectedShip.GetAI().OrderMoveDirectlyTowardsPosition(this.ProjectedPosition, num2, vector2_2, true); else this.SelectedShip.GetAI().OrderMoveTowardsPosition(this.ProjectedPosition, num2, vector2_2, true,null); } } else if (this.SelectedShipList.Count > 0) { this.SelectedSomethingTimer = 3f; foreach (Ship ship in (List<Ship>)this.SelectedShipList) { if (ship.loyalty != this.player) return; if (ship.Role == "construction") { this.SelectedShipList.Clear(); AudioManager.PlayCue("UI_Misc20"); return; } } AudioManager.PlayCue("echo_affirm1"); this.endDragWorld = this.GetWorldSpaceFromScreenSpace(input.CursorPosition); Enumerable.OrderBy<Ship, float>((IEnumerable<Ship>)this.SelectedShipList, (Func<Ship, float>)(ship => ship.Center.X)); Vector2 fVec = new Vector2(-vector2_2.Y, vector2_2.X); float num3 = Vector2.Distance(this.endDragWorld, this.startDragWorld); int num4 = 0; int num5 = 0; float num6 = 0.0f; for (int index = 0; index < this.SelectedShipList.Count; ++index) { this.player.GetGSAI().DefensiveCoordinator.remove(this.SelectedShipList[index]); if ((double)this.SelectedShipList[index].GetSO().WorldBoundingSphere.Radius > (double)num6) num6 = this.SelectedShipList[index].GetSO().WorldBoundingSphere.Radius; } Fleet fleet = new Fleet(); if ((double)this.SelectedShipList.Count * (double)num6 > (double)num3) { for (int index = 0; index < this.SelectedShipList.Count; ++index) { fleet.AddShip(this.SelectedShipList[index].SoftCopy()); fleet.Ships[index].RelativeFleetOffset = new Vector2((num6 + 200f) * (float)num5, (float)num4 * (num6 + 200f)); ++num5; if ((double)this.SelectedShipList[index].RelativeFleetOffset.X + (double)num6 > (double)num3) { num5 = 0; ++num4; } } } else { float num7 = num3 / (float)this.SelectedShipList.Count; for (int index = 0; index < this.SelectedShipList.Count; ++index) { fleet.AddShip(this.SelectedShipList[index].SoftCopy()); fleet.Ships[index].RelativeFleetOffset = new Vector2(num7 * (float)index, 0.0f); } } fleet.ProjectPos(this.ProjectedPosition, num2 - 1.570796f, fVec); foreach (Ship ship1 in (List<Ship>)fleet.Ships) { foreach (Ship ship2 in (List<Ship>)this.SelectedShipList) { if (ship1.guid == ship2.guid) { if (input.CurrentKeyboardState.IsKeyDown(Keys.LeftShift)) { if (input.CurrentKeyboardState.IsKeyDown(Keys.LeftAlt)) ship2.GetAI().OrderMoveDirectlyTowardsPosition(ship1.projectedPosition, num2 - 1.570796f, fVec, false); else ship2.GetAI().OrderMoveTowardsPosition(ship1.projectedPosition, num2 - 1.570796f, fVec, false,null); } else if (input.CurrentKeyboardState.IsKeyDown(Keys.LeftAlt)) ship2.GetAI().OrderMoveDirectlyTowardsPosition(ship1.projectedPosition, num2 - 1.570796f, fVec, true); else ship2.GetAI().OrderMoveTowardsPosition(ship1.projectedPosition, num2 - 1.570796f, fVec, true,null); } } } this.projectedGroup = (ShipGroup)fleet; } } } if (input.CurrentMouseState.RightButton == ButtonState.Pressed && input.LastMouseState.RightButton == ButtonState.Pressed) { Vector2 target = new Vector2((float)input.CurrentMouseState.X, (float)input.CurrentMouseState.Y); float facing = Math.Abs(MathHelper.ToRadians(this.findAngleToTarget(this.startDrag, target))); Vector2 fVec1 = Vector2.Normalize(target - this.startDrag); if ((double)input.RightMouseTimer > 0.0) return; this.ProjectingPosition = true; if (this.SelectedFlank != null) { this.SelectedFleet.ProjectPos(this.ProjectedPosition, facing, this.SelectedFlank); ShipGroup shipGroup = new ShipGroup(); foreach (Fleet.Squad squad in this.SelectedFlank) { foreach (Ship ship in (List<Ship>)squad.Ships) shipGroup.Ships.Add(ship); } shipGroup.ProjectedFacing = facing; this.projectedGroup = shipGroup; } else if (this.SelectedFleet != null && this.SelectedFleet.Owner == this.player) { this.ProjectingPosition = true; this.SelectedFleet.ProjectPos(this.ProjectedPosition, facing, fVec1); this.projectedGroup = (ShipGroup)this.SelectedFleet; } else if (this.SelectedShip != null && this.SelectedShip.loyalty == this.player) { if (this.SelectedShip.Role == "construction") { this.SelectedShip = (Ship)null; AudioManager.PlayCue("UI_Misc20"); } else { ShipGroup shipGroup = new ShipGroup(); shipGroup.Ships.Add(this.SelectedShip); shipGroup.ProjectPos(this.ProjectedPosition, facing, fVec1); this.projectedGroup = shipGroup; } } else { if (this.SelectedShipList.Count <= 0) return; foreach (Ship ship in (List<Ship>)this.SelectedShipList) { if (ship.loyalty != this.player) return; } this.endDragWorld = this.GetWorldSpaceFromScreenSpace(input.CursorPosition); Enumerable.OrderBy<Ship, float>((IEnumerable<Ship>)this.SelectedShipList, (Func<Ship, float>)(ship => ship.Center.X)); Vector2 fVec2 = new Vector2(-fVec1.Y, fVec1.X); float num1 = Vector2.Distance(this.endDragWorld, this.startDragWorld); int num2 = 0; int num3 = 0; float num4 = 0.0f; for (int index = 0; index < this.SelectedShipList.Count; ++index) { if ((double)this.SelectedShipList[index].GetSO().WorldBoundingSphere.Radius > (double)num4) num4 = this.SelectedShipList[index].GetSO().WorldBoundingSphere.Radius; } Fleet fleet = new Fleet(); if ((double)this.SelectedShipList.Count * (double)num4 > (double)num1) { for (int index = 0; index < this.SelectedShipList.Count; ++index) { fleet.AddShip(this.SelectedShipList[index].SoftCopy()); fleet.Ships[index].RelativeFleetOffset = new Vector2((num4 + 200f) * (float)num3, (float)num2 * (num4 + 200f)); ++num3; if ((double)this.SelectedShipList[index].RelativeFleetOffset.X + (double)num4 > (double)num1) { num3 = 0; ++num2; } } } else { float num5 = num1 / (float)this.SelectedShipList.Count; for (int index = 0; index < this.SelectedShipList.Count; ++index) { fleet.AddShip(this.SelectedShipList[index].SoftCopy()); fleet.Ships[index].RelativeFleetOffset = new Vector2(num5 * (float)index, 0.0f); } } fleet.ProjectPos(this.ProjectedPosition, facing - 1.570796f, fVec2); this.projectedGroup = (ShipGroup)fleet; } } else this.ProjectingPosition = false; } }
protected void Dispose(bool disposing) { if (disposing) { lock (this) { if (this.starfield != null) this.starfield.Dispose(); if (this.fleet != null) this.fleet.Dispose(); if (this.AvailableShips != null) this.AvailableShips.Dispose(); if (this.ShipSL != null) this.ShipSL.Dispose(); if (this.FleetSL != null) this.FleetSL.Dispose(); } this.starfield = null; this.fleet = null; this.ShipSL = null; this.FleetSL = null; this.AvailableShips = null; } }
protected void HandleSelectionBox(InputState input) { if (this.LookingAtPlanet) return; if (this.SelectedShip != null) { //if (input.CurrentKeyboardState.IsKeyDown(Keys.R) && !input.LastKeyboardState.IsKeyDown(Keys.R)) //fbedard: what is that !!!! // this.SelectedShip.FightersOut = !this.SelectedShip.FightersOut; if (input.CurrentKeyboardState.IsKeyDown(Keys.Q) && !input.LastKeyboardState.IsKeyDown(Keys.Q)) { if (!this.pieMenu.Visible) { if (this.SelectedShip != null) this.LoadShipMenuNodes(this.SelectedShip.loyalty == this.player ? 1 : 0); this.pieMenu.RootNode = this.shipMenu; this.pieMenu.Show(this.pieMenu.Position); } else this.pieMenu.ChangeTo((PieMenuNode)null); } } Vector2 vector2 = input.CursorPosition - this.pieMenu.Position; vector2.Y *= -1f; Vector2 selectionVector = vector2 / this.pieMenu.Radius; this.pieMenu.HandleInput(input, selectionVector); if (input.CurrentMouseState.LeftButton == ButtonState.Pressed && input.LastMouseState.LeftButton == ButtonState.Released && !this.pieMenu.Visible) { this.SelectedShip = (Ship)null; this.SelectedPlanet = (Planet)null; this.SelectedFleet = (Fleet)null; this.SelectedFlank = (List<Fleet.Squad>)null; this.SelectedSystem = (SolarSystem)null; this.SelectedItem = (UniverseScreen.ClickableItemUnderConstruction)null; this.ProjectingPosition = false; this.projectedGroup = (ShipGroup)null; bool flag1 = false; if (this.viewState >= UniverseScreen.UnivScreenState.SectorView) { lock (GlobalStats.ClickableSystemsLock) { for (int local_2 = 0; local_2 < this.ClickableSystems.Count; ++local_2) { UniverseScreen.ClickableSystem local_3 = this.ClickableSystems[local_2]; if ((double)Vector2.Distance(input.CursorPosition, local_3.ScreenPos) <= (double)local_3.Radius) { AudioManager.PlayCue("mouse_over4"); this.SelectedSystem = local_3.systemToClick; this.sInfoUI.SetSystem(this.SelectedSystem); flag1 = true; } } } } bool flag2 = false; if (!flag1) { foreach (UniverseScreen.ClickableFleet clickableFleet in this.ClickableFleetsList) { if ((double)Vector2.Distance(input.CursorPosition, clickableFleet.ScreenPos) <= (double)clickableFleet.ClickRadius) { this.SelectedShipList.Clear(); this.SelectedFleet = clickableFleet.fleet; flag2 = true; this.pickedSomethingThisFrame = true; AudioManager.PlayCue("techy_affirm1"); using (List<Ship>.Enumerator enumerator = this.SelectedFleet.Ships.GetEnumerator()) { while (enumerator.MoveNext()) this.SelectedShipList.Add(enumerator.Current); break; } } } if (!flag2) { foreach (UniverseScreen.ClickableShip clickableShip in this.ClickableShipsList) { if ((double)Vector2.Distance(input.CursorPosition, clickableShip.ScreenPos) <= (double)clickableShip.Radius) { if (input.CurrentKeyboardState.IsKeyDown(Keys.LeftControl) && this.SelectedShipList.Count > 1 && this.SelectedShipList.Contains(clickableShip.shipToClick)) { this.SelectedShipList.Remove(clickableShip.shipToClick); this.pickedSomethingThisFrame = true; AudioManager.GetCue("techy_affirm1").Play(); break; } else { if (this.SelectedShipList.Count > 0 && !input.CurrentKeyboardState.IsKeyDown(Keys.LeftShift) && !this.pickedSomethingThisFrame) this.SelectedShipList.Clear(); this.pickedSomethingThisFrame = true; AudioManager.GetCue("techy_affirm1").Play(); this.SelectedShip = clickableShip.shipToClick; this.SelectedSomethingTimer = 3f; if (!this.SelectedShipList.Contains(clickableShip.shipToClick)) { if (clickableShip.shipToClick != null) { if (clickableShip.shipToClick.inSensorRange) { this.SelectedShipList.Add(clickableShip.shipToClick); break; } else break; } else break; } else break; } } } if (this.SelectedShip != null && this.SelectedShipList.Count == 1) this.ShipInfoUIElement.SetShip(this.SelectedShip); else if (this.SelectedShipList.Count > 1) this.shipListInfoUI.SetShipList((List<Ship>)this.SelectedShipList, false); bool flag3 = false; if (this.SelectedShipList.Count == 1) { if (this.SelectedShipList[0] == this.playerShip) this.LoadShipMenuNodes(1); else if (this.SelectedShipList[0].loyalty == this.player) this.LoadShipMenuNodes(1); else this.LoadShipMenuNodes(0); } else { lock (GlobalStats.ClickableSystemsLock) { foreach (UniverseScreen.ClickablePlanets item_2 in this.ClickPlanetList) { if ((double)Vector2.Distance(input.CursorPosition, item_2.ScreenPos) <= (double)item_2.Radius) { if ((double)this.ClickTimer2 < (double)this.TimerDelay) { this.SelectedPlanet = item_2.planetToClick; this.pInfoUI.SetPlanet(this.SelectedPlanet); this.SelectedSomethingTimer = 3f; flag3 = true; this.ViewPlanet((object)null); this.SelectionBox = new Rectangle(); } else { AudioManager.GetCue("techy_affirm1").Play(); this.SelectedPlanet = item_2.planetToClick; this.pInfoUI.SetPlanet(this.SelectedPlanet); this.SelectedSomethingTimer = 3f; flag3 = true; this.ClickTimer2 = 0.0f; } } } } } if (!flag3) { lock (GlobalStats.ClickableItemLocker) { for (int local_17 = 0; local_17 < this.ItemsToBuild.Count; ++local_17) { UniverseScreen.ClickableItemUnderConstruction local_18 = this.ItemsToBuild[local_17]; if (local_18 != null && (double)Vector2.Distance(input.CursorPosition, local_18.ScreenPos) <= (double)local_18.Radius) { AudioManager.GetCue("techy_affirm1").Play(); this.SelectedItem = local_18; } } } } } } } if (this.SelectedShip == null && this.SelectedShipList.Count == 0 && (this.SelectedPlanet != null && input.CurrentKeyboardState.IsKeyDown(Keys.Q)) && !input.LastKeyboardState.IsKeyDown(Keys.Q)) { if (!this.pieMenu.Visible) { this.pieMenu.RootNode = this.planetMenu; if (this.SelectedPlanet.Owner == null && this.SelectedPlanet.habitable) this.LoadMenuNodes(false, true); else this.LoadMenuNodes(false, false); this.pieMenu.Show(this.pieMenu.Position); } else this.pieMenu.ChangeTo((PieMenuNode)null); } if (input.CurrentMouseState.LeftButton == ButtonState.Pressed && input.LastMouseState.LeftButton == ButtonState.Released) this.SelectionBox = new Rectangle(input.CurrentMouseState.X, input.CurrentMouseState.Y, 0, 0); if (this.SelectedShipList.Count == 1) this.SelectedShip = this.SelectedShipList[0]; if (input.CurrentMouseState.LeftButton == ButtonState.Pressed) { this.SelectingWithBox = true; if (this.SelectionBox.X == 0 || this.SelectionBox.Y == 0) return; this.SelectionBox = new Rectangle(this.SelectionBox.X, this.SelectionBox.Y, input.CurrentMouseState.X - this.SelectionBox.X, input.CurrentMouseState.Y - this.SelectionBox.Y); } else if (input.CurrentKeyboardState.IsKeyDown(Keys.LeftShift) && input.CurrentMouseState.LeftButton == ButtonState.Released && input.LastMouseState.LeftButton == ButtonState.Pressed) { if (input.CurrentMouseState.X < this.SelectionBox.X) this.SelectionBox.X = input.CurrentMouseState.X; if (input.CurrentMouseState.Y < this.SelectionBox.Y) this.SelectionBox.Y = input.CurrentMouseState.Y; this.SelectionBox.Width = Math.Abs(this.SelectionBox.Width); this.SelectionBox.Height = Math.Abs(this.SelectionBox.Height); bool flag1 = true; List<Ship> list = new List<Ship>(); foreach (UniverseScreen.ClickableShip clickableShip in this.ClickableShipsList) { if (this.SelectionBox.Contains(new Point((int)clickableShip.ScreenPos.X, (int)clickableShip.ScreenPos.Y)) && !this.SelectedShipList.Contains(clickableShip.shipToClick)) { this.SelectedPlanet = (Planet)null; this.SelectedShipList.Add(clickableShip.shipToClick); this.SelectedSomethingTimer = 3f; list.Add(clickableShip.shipToClick); } } if (this.SelectedShipList.Count > 0 && flag1) { bool flag2 = false; bool flag3 = false; foreach (Ship ship in list) { if (ship.Role == "station" || ship.Role == "construction" || (ship.Role == "platform" || ship.Role == "supply")) flag2 = true; else flag3 = true; } if (flag3 && flag2) { foreach (Ship ship in (List<Ship>)this.SelectedShipList) { if (ship.Role == "station" || ship.Role == "construction" || (ship.Role == "platform" || ship.Role == "supply")) this.SelectedShipList.QueuePendingRemoval(ship); } } this.SelectedShipList.ApplyPendingRemovals(); } if (this.SelectedShipList.Count > 1) { bool flag2 = false; bool flag3 = false; foreach (Ship ship in (List<Ship>)this.SelectedShipList) { if (ship.loyalty == this.player) flag2 = true; if (ship.loyalty != this.player) flag3 = true; } if (flag2 && flag3) { foreach (Ship ship in (List<Ship>)this.SelectedShipList) { if (ship.loyalty != this.player) this.SelectedShipList.QueuePendingRemoval(ship); } this.SelectedShipList.ApplyPendingRemovals(); } this.SelectedShip = (Ship)null; this.shipListInfoUI.SetShipList((List<Ship>)this.SelectedShipList, true); } else if (this.SelectedShipList.Count == 1) { this.SelectedShip = this.SelectedShipList[0]; this.ShipInfoUIElement.SetShip(this.SelectedShip); } this.SelectionBox = new Rectangle(0, 0, -1, -1); } else { if (input.CurrentMouseState.LeftButton != ButtonState.Released || input.LastMouseState.LeftButton != ButtonState.Pressed) return; this.SelectingWithBox = false; if (input.CurrentMouseState.X < this.SelectionBox.X) this.SelectionBox.X = input.CurrentMouseState.X; if (input.CurrentMouseState.Y < this.SelectionBox.Y) this.SelectionBox.Y = input.CurrentMouseState.Y; this.SelectionBox.Width = Math.Abs(this.SelectionBox.Width); this.SelectionBox.Height = Math.Abs(this.SelectionBox.Height); bool flag1 = false; if (this.SelectedShipList.Count == 0) flag1 = true; foreach (UniverseScreen.ClickableShip clickableShip in this.ClickableShipsList) { if (this.SelectionBox.Contains(new Point((int)clickableShip.ScreenPos.X, (int)clickableShip.ScreenPos.Y))) { this.SelectedPlanet = (Planet)null; this.SelectedShipList.Add(clickableShip.shipToClick); this.SelectedSomethingTimer = 3f; } } if (this.SelectedShipList.Count > 0 && flag1) { bool flag2 = false; bool flag3 = false; try { foreach (Ship ship in (List<Ship>)this.SelectedShipList) { if (ship.Role == "station" || ship.Role == "construction" || (ship.Role == "platform" || ship.Role == "supply") || (ship.Role == "freighter" || ship.Role == "colony")) flag2 = true; else flag3 = true; } } catch { } if (flag3) { if (flag2) { try { foreach (Ship ship in (List<Ship>)this.SelectedShipList) { if (ship.Role == "station" || ship.Role == "construction" || (ship.Role == "platform" || ship.Role == "supply") || (ship.Role == "freighter" || ship.Role == "colony")) this.SelectedShipList.QueuePendingRemoval(ship); } } catch { } } } this.SelectedShipList.ApplyPendingRemovals(); } if (this.SelectedShipList.Count > 1) { bool flag2 = false; bool flag3 = false; foreach (Ship ship in (List<Ship>)this.SelectedShipList) { if (ship.loyalty == this.player) flag2 = true; if (ship.loyalty != this.player) flag3 = true; } if (flag2 && flag3) { foreach (Ship ship in (List<Ship>)this.SelectedShipList) { if (ship.loyalty != this.player) this.SelectedShipList.QueuePendingRemoval(ship); } this.SelectedShipList.ApplyPendingRemovals(); } this.SelectedShip = (Ship)null; bool flag4 = true; if (this.SelectedShipList.Count > 0) { if (this.SelectedShipList[0].fleet != null) { if (this.SelectedShipList.Count == this.SelectedShipList[0].fleet.Ships.Count) { try { foreach (Ship ship in (List<Ship>)this.SelectedShipList) { if (ship.fleet == null || ship.fleet != this.SelectedShipList[0].fleet) flag4 = false; } if (flag4) this.SelectedFleet = this.SelectedShipList[0].fleet; } catch { } } } if (this.SelectedFleet != null) this.shipListInfoUI.SetShipList((List<Ship>)this.SelectedShipList, true); else this.shipListInfoUI.SetShipList((List<Ship>)this.SelectedShipList, false); } if (this.SelectedFleet == null) this.ShipInfoUIElement.SetShip(this.SelectedShipList[0]); } else if (this.SelectedShipList.Count == 1) { this.SelectedShip = this.SelectedShipList[0]; this.ShipInfoUIElement.SetShip(this.SelectedShip); if (this.SelectedShipList[0] == this.playerShip) this.LoadShipMenuNodes(1); else if (this.SelectedShipList[0].loyalty == this.player) this.LoadShipMenuNodes(1); else this.LoadShipMenuNodes(0); } this.SelectionBox = new Rectangle(0, 0, -1, -1); } }
public void SetFleet(Fleet f) { this.CoreFleet = f; }
public override void ExitScreen() { if (this.MultiThread) { // this.ShipUpdateThread.Abort(); this.WorkerThread.Abort(); foreach (Thread thread in this.SystemUpdateThreadList) thread.Abort(); } this.EmpireUI.empire = (Empire)null; this.EmpireUI = (EmpireUIOverlay)null; UniverseScreen.DeepSpaceManager.CollidableObjects.Clear(); UniverseScreen.DeepSpaceManager.CollidableProjectiles.Clear(); UniverseScreen.ShipSpatialManager.CollidableObjects.Clear(); this.ScreenManager.Music.Stop(AudioStopOptions.Immediate); this.NebulousShit.Clear(); this.bloomComponent = (BloomComponent)null; this.bg3d.BGItems.Clear(); this.bg3d = (Background3D)null; this.playerShip = (Ship)null; this.ShipToView = (Ship)null; foreach (Ship ship in (List<Ship>)this.MasterShipList) ship.TotallyRemove(); this.MasterShipList.ApplyPendingRemovals(); this.MasterShipList.Clear(); foreach (SolarSystem solarSystem in UniverseScreen.SolarSystemList) { solarSystem.spatialManager.CollidableProjectiles.Clear(); solarSystem.spatialManager.CollidableObjects.Clear(); solarSystem.spatialManager.ClearBuckets(); solarSystem.spatialManager.Destroy(); solarSystem.spatialManager = (SpatialManager)null; solarSystem.FiveClosestSystems.Clear(); foreach (Planet planet in solarSystem.PlanetList) { planet.TilesList = new List<PlanetGridSquare>(); if (planet.SO != null) { planet.SO.Clear(); this.ScreenManager.inter.ObjectManager.Remove((ISceneObject)planet.SO); planet.SO = (SceneObject)null; } } foreach (Asteroid asteroid in (List<Asteroid>)solarSystem.AsteroidsList) { if (asteroid.GetSO() != null) { asteroid.GetSO().Clear(); this.ScreenManager.inter.ObjectManager.Remove((ISceneObject)asteroid.GetSO()); } } solarSystem.AsteroidsList.Clear(); foreach (Moon moon in solarSystem.MoonList) { if (moon.GetSO() != null) { moon.GetSO().Clear(); this.ScreenManager.inter.ObjectManager.Remove((ISceneObject)moon.GetSO()); } } solarSystem.MoonList.Clear(); } foreach (Empire empire in EmpireManager.EmpireList) empire.CleanOut(); foreach (SpaceJunk spaceJunk in (List<SpaceJunk>)UniverseScreen.JunkList) { spaceJunk.trailEmitter = (ParticleEmitter)null; spaceJunk.JunkSO.Clear(); this.ScreenManager.inter.ObjectManager.Remove((ISceneObject)spaceJunk.JunkSO); spaceJunk.JunkSO = (SceneObject)null; } UniverseScreen.JunkList.Clear(); this.SelectedShip = (Ship)null; this.SelectedFleet = (Fleet)null; this.SelectedPlanet = (Planet)null; this.SelectedSystem = (SolarSystem)null; ShieldManager.shieldList.Clear(); ShieldManager.PlanetaryShieldList.Clear(); this.PlanetsDict.Clear(); this.ClickableFleetsList.Clear(); this.ClickableShipsList.Clear(); this.ClickPlanetList.Clear(); this.ClickableSystems.Clear(); UniverseScreen.DeepSpaceManager.ClearBuckets(); UniverseScreen.DeepSpaceManager.CollidableObjects.Clear(); UniverseScreen.DeepSpaceManager.CollidableObjects.Clear(); UniverseScreen.DeepSpaceManager.CollidableProjectiles.Clear(); UniverseScreen.DeepSpaceManager.ClearBuckets(); UniverseScreen.DeepSpaceManager.Destroy(); UniverseScreen.DeepSpaceManager = (SpatialManager)null; UniverseScreen.SolarSystemList.Clear(); this.starfield.UnloadContent(); this.starfield.Dispose(); UniverseScreen.SolarSystemList.Clear(); this.beamflashes.UnloadContent(); this.explosionParticles.UnloadContent(); this.photonExplosionParticles.UnloadContent(); this.explosionSmokeParticles.UnloadContent(); this.projectileTrailParticles.UnloadContent(); this.fireTrailParticles.UnloadContent(); this.smokePlumeParticles.UnloadContent(); this.fireParticles.UnloadContent(); this.engineTrailParticles.UnloadContent(); this.flameParticles.UnloadContent(); this.sparks.UnloadContent(); this.lightning.UnloadContent(); this.flash.UnloadContent(); this.star_particles.UnloadContent(); this.neb_particles.UnloadContent(); this.SolarSystemDict.Clear(); ShipDesignScreen.screen = (UniverseScreen)null; Fleet.screen = (UniverseScreen)null; Bomb.screen = (UniverseScreen)null; Anomaly.screen = (UniverseScreen)null; PlanetScreen.screen = (UniverseScreen)null; MinimapButtons.screen = (UniverseScreen)null; Projectile.contentManager = this.ScreenManager.Content; Projectile.universeScreen = (UniverseScreen)null; ShipModule.universeScreen = (UniverseScreen)null; Asteroid.universeScreen = (UniverseScreen)null; Empire.universeScreen = (UniverseScreen)null; SpaceJunk.universeScreen = (UniverseScreen)null; ResourceManager.universeScreen = (UniverseScreen)null; Planet.universeScreen = (UniverseScreen)null; Weapon.universeScreen = (UniverseScreen)null; Ship.universeScreen = (UniverseScreen)null; ArtificialIntelligence.universeScreen = (UniverseScreen)null; MissileAI.universeScreen = (UniverseScreen)null; Moon.universeScreen = (UniverseScreen)null; CombatScreen.universeScreen = (UniverseScreen)null; MuzzleFlashManager.universeScreen = (UniverseScreen)null; FleetDesignScreen.screen = (UniverseScreen)null; ExplosionManager.universeScreen = (UniverseScreen)null; FTLManager.universeScreen = (UniverseScreen)null; DroneAI.universeScreen = (UniverseScreen)null; StatTracker.SnapshotsDict.Clear(); EmpireManager.EmpireList.Clear(); this.ScreenManager.inter.Unload(); //GC.Collect(2, GCCollectionMode.Optimized); this.Dispose(); base.ExitScreen(); }
protected void Dispose(bool disposing) { if (!disposed) { if (disposing) { if (this.OffensiveForcePool != null) this.OffensiveForcePool.Dispose(); if (this.DefensiveForcePool != null) this.DefensiveForcePool.Dispose(); if (this.CoreFleet != null) this.CoreFleet.Dispose(); } this.OffensiveForcePool = null; this.DefensiveForcePool = null; this.CoreFleet = null; this.disposed = true; } }
public void SetFleet(Fleet f) { this.fleet = f; }
public override void HandleInput(InputState input) { if (this.ScreenManager.input.CurrentKeyboardState.IsKeyDown(Keys.Space) && this.ScreenManager.input.LastKeyboardState.IsKeyUp(Keys.Space) && !GlobalStats.TakingInput) this.Paused = !this.Paused; for (int index = 0; index < this.SelectedShipList.Count; ++index) { Ship ship = this.SelectedShipList[index]; if (!ship.Active) this.SelectedShipList.QueuePendingRemoval(ship); } //CG: previous target code. if (this.previousSelection != null && input.CurrentMouseState.XButton1 == ButtonState.Pressed && input.LastMouseState.XButton1 == ButtonState.Released) { if (this.previousSelection.Active) { Ship tempship = this.previousSelection; if (this.SelectedShip != null && this.SelectedShip != this.previousSelection) this.previousSelection = this.SelectedShip; this.SelectedShip = tempship; this.ShipInfoUIElement.SetShip(this.SelectedShip); this.SelectedFleet = (Fleet)null; this.SelectedShipList.Clear(); this.SelectedItem = (UniverseScreen.ClickableItemUnderConstruction)null; this.SelectedSystem = (SolarSystem)null; this.SelectedPlanet = (Planet)null; this.SelectedShipList.Add(this.SelectedShip); } else this.SelectedShip = null; //fbedard: remove inactive ship } //fbedard: Set camera chase on ship if (input.CurrentMouseState.MiddleButton == ButtonState.Pressed) { this.ViewToShip(null); } this.input = input; this.ShowTacticalCloseup = input.CurrentKeyboardState.IsKeyDown(Keys.LeftAlt); // something nicer... //if (input.CurrentKeyboardState.IsKeyDown(Keys.P) && input.LastKeyboardState.IsKeyUp(Keys.P) && input.CurrentKeyboardState.IsKeyDown(Keys.LeftControl)) if (input.CurrentKeyboardState.IsKeyDown(Keys.F5) && input.LastKeyboardState.IsKeyUp(Keys.F5)) { if (this.UseRealLights) { this.UseRealLights = false; } else { this.UseRealLights = true; this.SetLighting(this.UseRealLights); } } if (input.CurrentKeyboardState.IsKeyDown(Keys.F6) && input.LastKeyboardState.IsKeyUp(Keys.F6) && !ExceptionTracker.active) { bool switchedmode = false; #if RELEASE //only switch screens in release if (Game1.Instance.graphics.IsFullScreen) { switchedmode = true; Game1.Instance.graphics.ToggleFullScreen(); } #endif Exception ex = new Exception("Manual Report"); ExceptionTracker.TrackException(ex); // if(ExceptionViewer.ActiveForm == null) { bool paused = false; if (!this.Paused) { paused = true; this.Paused = true; } ExceptionTracker.DisplayException(ex); if (paused) { this.Paused = false; } } if (switchedmode) { switchedmode = false; Game1.Instance.graphics.ToggleFullScreen(); } } if (input.CurrentKeyboardState.IsKeyDown(Keys.F7) && input.LastKeyboardState.IsKeyUp(Keys.F7) && !ExceptionTracker.active) { bool switchedmode = false; #if RELEASE //only switch screens in release if (Game1.Instance.graphics.IsFullScreen) { switchedmode = true; Game1.Instance.graphics.ToggleFullScreen(); } #endif Exception ex = new Exception("Kudos"); ExceptionTracker.TrackException(ex); ExceptionTracker.Kudos = true; // if(ExceptionViewer.ActiveForm == null) { bool paused = false; if (!this.Paused) { paused = true; this.Paused = true; } ExceptionTracker.DisplayException(ex); if (paused) { this.Paused = false; } } if (switchedmode) { switchedmode = false; Game1.Instance.graphics.ToggleFullScreen(); } } if (input.CurrentKeyboardState.IsKeyDown(Keys.OemTilde) && input.LastKeyboardState.IsKeyUp(Keys.OemTilde) && (input.CurrentKeyboardState.IsKeyDown(Keys.LeftControl) && input.CurrentKeyboardState.IsKeyDown(Keys.LeftShift))) { this.Debug = !this.Debug; UniverseScreen.debug = !this.Debug; foreach (SolarSystem solarSystem in UniverseScreen.SolarSystemList) solarSystem.ExploredDict[this.player] = true; GlobalStats.LimitSpeed = this.Debug; } if (this.Debug && input.CurrentKeyboardState.IsKeyDown(Keys.G) && input.LastKeyboardState.IsKeyUp(Keys.G)) { this.Memory = (float)GC.GetTotalMemory(true); this.Memory /= 1000f; } this.HandleEdgeDetection(input); if (input.CurrentKeyboardState.IsKeyDown(Keys.OemPlus) && input.LastKeyboardState.IsKeyUp(Keys.OemPlus)) { if (this.GameSpeed < 1.0) this.GameSpeed = 1f; else ++this.GameSpeed; if (this.GameSpeed > 4.0 && GlobalStats.LimitSpeed) this.GameSpeed = 4f; } if (input.CurrentKeyboardState.IsKeyDown(Keys.OemMinus) && input.LastKeyboardState.IsKeyUp(Keys.OemMinus)) { if (this.GameSpeed <= 1.0) this.GameSpeed = 0.5f; else --this.GameSpeed; } if (input.CurrentKeyboardState.IsKeyDown(Keys.Add) && input.LastKeyboardState.IsKeyUp(Keys.Add)) { if (this.GameSpeed < 1.0) this.GameSpeed = 1f; else ++this.GameSpeed; if (this.GameSpeed > 4.0 && GlobalStats.LimitSpeed) this.GameSpeed = 4f; } if (input.CurrentKeyboardState.IsKeyDown(Keys.Subtract) && input.LastKeyboardState.IsKeyUp(Keys.Subtract)) { if (this.GameSpeed <= 1.0) this.GameSpeed = 0.5f; else --this.GameSpeed; } //fbedard: Click button to Cycle through ships in Combat if (!HelperFunctions.CheckIntersection(this.ShipsInCombat.Rect, input.CursorPosition)) { this.ShipsInCombat.State = UIButton.PressState.Normal; } else { this.ShipsInCombat.State = UIButton.PressState.Hover; if (input.InGameSelect) { if (this.player.empireShipCombat > 0) { AudioManager.PlayCue("echo_affirm"); int nbrship = 0; if (lastshipcombat >= this.player.empireShipCombat) lastshipcombat = 0; foreach (Ship ship in EmpireManager.GetEmpireByName(this.PlayerLoyalty).GetShips()) { if (ship.fleet != null || !ship.InCombat || ship.Mothership != null || !ship.Active || ship.Name == "Subspace Projector") continue; else { if (nbrship == lastshipcombat) { if (this.SelectedShip != null && this.SelectedShip != this.previousSelection) this.previousSelection = this.SelectedShip; this.SelectedShip = ship; this.ViewToShip(null); this.SelectedShipList.Add(this.SelectedShip); lastshipcombat++; break; } else nbrship++; } } } else { AudioManager.PlayCue("blip_click"); } } } //fbedard: Click button to Cycle through Planets in Combat if (!HelperFunctions.CheckIntersection(this.PlanetsInCombat.Rect, input.CursorPosition)) { this.PlanetsInCombat.State = UIButton.PressState.Normal; } else { this.PlanetsInCombat.State = UIButton.PressState.Hover; if (input.InGameSelect) { if (this.player.empirePlanetCombat > 0) { AudioManager.PlayCue("echo_affirm"); Planet PlanetToView = (Planet)null; int nbrplanet = 0; if (lastplanetcombat >= this.player.empirePlanetCombat) lastplanetcombat = 0; bool flagPlanet; foreach (SolarSystem system in UniverseScreen.SolarSystemList) { foreach (Planet p in system.PlanetList) { if (p.ExploredDict[EmpireManager.GetEmpireByName(Empire.universeScreen.PlayerLoyalty)] && p.RecentCombat) { if (p.Owner == EmpireManager.GetEmpireByName(Empire.universeScreen.PlayerLoyalty)) { if (nbrplanet == lastplanetcombat) PlanetToView = p; else nbrplanet++; } else { flagPlanet = false; foreach (PlanetGridSquare planetGridSquare in p.TilesList) { if (!flagPlanet) { planetGridSquare.TroopsHere.thisLock.EnterReadLock(); foreach (Troop troop in planetGridSquare.TroopsHere) { if (troop.GetOwner() != null && troop.GetOwner() == EmpireManager.GetEmpireByName(Empire.universeScreen.PlayerLoyalty)) { flagPlanet = true; break; } } planetGridSquare.TroopsHere.thisLock.ExitReadLock(); } } if (flagPlanet) { if (nbrplanet == lastplanetcombat) PlanetToView = p; else nbrplanet++; } } } } } if (PlanetToView != null) { this.SelectedShip = (Ship)null; //this.ShipInfoUIElement.SetShip(this.SelectedShip); this.SelectedFleet = (Fleet)null; this.SelectedShipList.Clear(); this.SelectedItem = (UniverseScreen.ClickableItemUnderConstruction)null; this.SelectedSystem = (SolarSystem)null; this.SelectedPlanet = PlanetToView; this.pInfoUI.SetPlanet(PlanetToView); lastplanetcombat++; this.transitionDestination = new Vector3(this.SelectedPlanet.Position.X, this.SelectedPlanet.Position.Y, 9000f); this.LookingAtPlanet = false; this.transitionStartPosition = this.camPos; this.AdjustCamTimer = 2f; this.transitionElapsedTime = 0.0f; this.transDuration = 5f; this.returnToShip = false; this.ViewingShip = false; this.snappingToShip = false; this.SelectedItem = (UniverseScreen.ClickableItemUnderConstruction)null; //PlanetToView.OpenCombatMenu(null); } } else { AudioManager.PlayCue("blip_click"); } } } if (!this.LookingAtPlanet) { if (this.HandleGUIClicks(input)) { this.SkipRightOnce = true; this.NeedARelease = true; return; } } else { if (this.SelectedShip != null && this.SelectedShip != this.previousSelection) this.previousSelection = this.SelectedShip; this.SelectedFleet = (Fleet)null; this.SelectedShip = (Ship)null; this.SelectedShipList.Clear(); this.SelectedItem = (UniverseScreen.ClickableItemUnderConstruction)null; this.SelectedSystem = (SolarSystem)null; } if ((input.CurrentKeyboardState.IsKeyDown(Keys.Back) || input.CurrentKeyboardState.IsKeyDown(Keys.Delete)) && (this.SelectedItem != null && this.SelectedItem.AssociatedGoal.empire == this.player)) { this.player.GetGSAI().Goals.QueuePendingRemoval(this.SelectedItem.AssociatedGoal); bool flag = false; foreach (Ship ship in (List<Ship>)this.player.GetShips()) { if (ship.Role == "construction" && ship.GetAI().OrderQueue.Count > 0) { for (int index = 0; index < ship.GetAI().OrderQueue.Count; ++index) { if (Enumerable.ElementAt<ArtificialIntelligence.ShipGoal>((IEnumerable<ArtificialIntelligence.ShipGoal>)ship.GetAI().OrderQueue, index).goal == this.SelectedItem.AssociatedGoal) { flag = true; ship.GetAI().OrderScrapShip(); break; } } } } if (!flag) { foreach (Planet planet in this.player.GetPlanets()) { foreach (QueueItem queueItem in (List<QueueItem>)planet.ConstructionQueue) { if (queueItem.Goal == this.SelectedItem.AssociatedGoal) { planet.ProductionHere += queueItem.productionTowards; if ((double)planet.ProductionHere > (double)planet.MAX_STORAGE) planet.ProductionHere = planet.MAX_STORAGE; planet.ConstructionQueue.QueuePendingRemoval(queueItem); } } planet.ConstructionQueue.ApplyPendingRemovals(); } } lock (GlobalStats.ClickableItemLocker) { for (int local_10 = 0; local_10 < this.ItemsToBuild.Count; ++local_10) { UniverseScreen.ClickableItemUnderConstruction local_11 = this.ItemsToBuild[local_10]; if (local_11.BuildPos == this.SelectedItem.BuildPos) { this.ItemsToBuild.QueuePendingRemoval(local_11); AudioManager.PlayCue("blip_click"); } } this.ItemsToBuild.ApplyPendingRemovals(); } this.player.GetGSAI().Goals.ApplyPendingRemovals(); this.SelectedItem = (UniverseScreen.ClickableItemUnderConstruction)null; } if (input.CurrentKeyboardState.IsKeyDown(Keys.H) && !input.LastKeyboardState.IsKeyDown(Keys.H) && this.Debug) { this.debugwin = new DebugInfoScreen(this.ScreenManager, this); this.showdebugwindow = !this.showdebugwindow; } if (this.DefiningAO) { if (this.NeedARelease) { if (input.CurrentMouseState.LeftButton == ButtonState.Released) this.NeedARelease = false; } else { this.DefineAO(input); return; } } this.pickedSomethingThisFrame = false; this.input = input; if (this.LookingAtPlanet) this.workersPanel.HandleInput(input); if (this.IsActive) this.EmpireUI.HandleInput(input); if (this.ShowingPlanetToolTip && (double)Vector2.Distance(new Vector2((float)input.CurrentMouseState.X, (float)input.CurrentMouseState.Y), this.tippedPlanet.ScreenPos) > (double)this.tippedPlanet.Radius) { this.ShowingPlanetToolTip = false; this.TooltipTimer = 0.5f; } if (this.ShowingSysTooltip && (double)Vector2.Distance(new Vector2((float)input.CurrentMouseState.X, (float)input.CurrentMouseState.Y), this.tippedSystem.ScreenPos) > (double)this.tippedSystem.Radius) { this.ShowingSysTooltip = false; this.sTooltipTimer = 0.5f; } if (!this.LookingAtPlanet) { Vector3 position = this.ScreenManager.GraphicsDevice.Viewport.Unproject(new Vector3((float)input.CurrentMouseState.X, (float)input.CurrentMouseState.Y, 0.0f), this.projection, this.view, Matrix.Identity); Vector3 direction = this.ScreenManager.GraphicsDevice.Viewport.Unproject(new Vector3((float)input.CurrentMouseState.X, (float)input.CurrentMouseState.Y, 1f), this.projection, this.view, Matrix.Identity) - position; direction.Normalize(); Ray ray = new Ray(position, direction); float num = -ray.Position.Z / ray.Direction.Z; Vector3 vector3 = new Vector3(ray.Position.X + num * ray.Direction.X, ray.Position.Y + num * ray.Direction.Y, 0.0f); this.mouseWorldPos = new Vector2(vector3.X, vector3.Y); if (input.CurrentKeyboardState.IsKeyDown(Keys.B) && !input.LastKeyboardState.IsKeyDown(Keys.B)) { if (!this.showingDSBW) { this.dsbw = new DeepSpaceBuildingWindow(this.ScreenManager, this); AudioManager.PlayCue("echo_affirm"); this.showingDSBW = true; } else this.showingDSBW = false; } if (input.CurrentKeyboardState.IsKeyDown(Keys.L) && !input.LastKeyboardState.IsKeyDown(Keys.L)) { AudioManager.PlayCue("sd_ui_accept_alt3"); this.ScreenManager.AddScreen((GameScreen)new PlanetListScreen(this.ScreenManager, this.EmpireUI)); } if (input.CurrentKeyboardState.IsKeyDown(Keys.F1) && !input.LastKeyboardState.IsKeyDown(Keys.F1)) { AudioManager.PlayCue("sd_ui_accept_alt3"); if (!this.showingFTLOverlay) { this.showingFTLOverlay = true; } else this.showingFTLOverlay = false; } if (input.CurrentKeyboardState.IsKeyDown(Keys.F2) && !input.LastKeyboardState.IsKeyDown(Keys.F2)) { AudioManager.PlayCue("sd_ui_accept_alt3"); if (!this.showingRangeOverlay) { this.showingRangeOverlay = true; } else this.showingRangeOverlay = false; } if (input.CurrentKeyboardState.IsKeyDown(Keys.K) && !input.LastKeyboardState.IsKeyDown(Keys.K)) { AudioManager.PlayCue("sd_ui_accept_alt3"); this.ScreenManager.AddScreen((GameScreen)new ShipListScreen(this.ScreenManager, this.EmpireUI)); } if (input.CurrentKeyboardState.IsKeyDown(Keys.J) && !input.LastKeyboardState.IsKeyDown(Keys.J)) { AudioManager.PlayCue("sd_ui_accept_alt3"); this.ScreenManager.AddScreen((GameScreen)new FleetDesignScreen(this.EmpireUI)); FleetDesignScreen.Open = true; } if (input.CurrentKeyboardState.IsKeyDown(Keys.H) && !input.LastKeyboardState.IsKeyDown(Keys.H)) { AudioManager.PlayCue("sd_ui_accept_alt3"); this.aw.isOpen = !this.aw.isOpen; } if (input.CurrentKeyboardState.IsKeyDown(Keys.PageUp) && !input.LastKeyboardState.IsKeyDown(Keys.PageUp)) { AudioManager.PlayCue("sd_ui_accept_alt3"); this.AdjustCamTimer = 1f; this.transitionElapsedTime = 0.0f; this.transitionDestination.Z = 4500f; this.snappingToShip = true; this.ViewingShip = true; } if (input.CurrentKeyboardState.IsKeyDown(Keys.PageDown) && !input.LastKeyboardState.IsKeyDown(Keys.PageDown)) { AudioManager.PlayCue("sd_ui_accept_alt3"); this.AdjustCamTimer = 1f; this.transitionElapsedTime = 0.0f; this.transitionDestination.X = this.camPos.X; this.transitionDestination.Y = this.camPos.Y; this.transitionDestination.Z = 4200000f * UniverseScreen.GameScaleStatic; } if (this.Debug) { if (input.C) ResourceManager.CreateShipAtPoint("Kulrathi Assault Ship", this.player, this.mouseWorldPos); else if (input.CurrentKeyboardState.IsKeyDown(Keys.LeftShift) && input.C) ResourceManager.CreateShipAtPoint("Kulrathi Assault Ship", EmpireManager.GetEmpireByName("The Remnant"), this.mouseWorldPos); try { if (input.CurrentKeyboardState.IsKeyDown(Keys.LeftShift) && input.CurrentKeyboardState.IsKeyDown(Keys.Z) && !input.LastKeyboardState.IsKeyDown(Keys.Z)) HelperFunctions.CreateFleetAt("Fleet 2", EmpireManager.GetEmpireByName("The Remnant"), this.mouseWorldPos); else if (input.CurrentKeyboardState.IsKeyDown(Keys.Z) && !input.LastKeyboardState.IsKeyDown(Keys.Z)) HelperFunctions.CreateFleetAt("Fleet 1", this.player, this.mouseWorldPos); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.InnerException); } if (this.SelectedShip != null && this.Debug) { if (input.CurrentKeyboardState.IsKeyDown(Keys.X) && !input.LastKeyboardState.IsKeyDown(Keys.X)) this.SelectedShip.Die((GameplayObject)null, false); } else if (this.SelectedPlanet != null && this.Debug && (input.CurrentKeyboardState.IsKeyDown(Keys.X) && !input.LastKeyboardState.IsKeyDown(Keys.X))) { foreach (KeyValuePair<string, Troop> keyValuePair in ResourceManager.TroopsDict) this.SelectedPlanet.AssignTroopToTile(ResourceManager.CreateTroop(keyValuePair.Value, EmpireManager.GetEmpireByName("The Remnant"))); } if (input.CurrentKeyboardState.IsKeyDown(Keys.X) && !input.LastKeyboardState.IsKeyDown(Keys.X)) ResourceManager.CreateShipAtPoint("Target Dummy", EmpireManager.GetEmpireByName("The Remnant"), this.mouseWorldPos); if (input.CurrentKeyboardState.IsKeyDown(Keys.V) && !input.LastKeyboardState.IsKeyDown(Keys.V)) ResourceManager.CreateShipAtPoint("Remnant Mothership", EmpireManager.GetEmpireByName("The Remnant"), this.mouseWorldPos); } this.HandleFleetSelections(input); if (input.Escaped) { this.snappingToShip = false; this.ViewingShip = false; if ((double)this.camHeight < 1175000.0 && (double)this.camHeight > 146900.0) { this.AdjustCamTimer = 1f; this.transitionElapsedTime = 0.0f; this.transitionDestination = new Vector3(this.camPos.X, this.camPos.Y, 1175000f); } else if ((double)this.camHeight < 146900.0) { this.AdjustCamTimer = 1f; this.transitionElapsedTime = 0.0f; this.transitionDestination = new Vector3(this.camPos.X, this.camPos.Y, 147000f); } else if (this.viewState < UniverseScreen.UnivScreenState.SystemView) this.transitionDestination =new Vector3(this.camPos.X, this.camPos.Y, this.GetZfromScreenState(UnivScreenState.SystemView)); } if (input.Tab) this.ShowShipNames = !this.ShowShipNames; this.HandleRightMouseNew(input); if (input.CurrentMouseState.LeftButton == ButtonState.Pressed && input.LastMouseState.LeftButton == ButtonState.Released) { if ((double)this.ClickTimer < (double)this.TimerDelay) { this.SelectedShipList.Clear(); if (this.SelectedShip != null && this.SelectedShip != this.previousSelection) this.previousSelection = this.SelectedShip; this.SelectedShip = (Ship)null; if (this.viewState <= UniverseScreen.UnivScreenState.SystemView) { foreach (UniverseScreen.ClickablePlanets clickablePlanets in this.ClickPlanetList) { if ((double)Vector2.Distance(input.CursorPosition, clickablePlanets.ScreenPos) <= (double)clickablePlanets.Radius) { AudioManager.PlayCue("sub_bass_whoosh"); this.SelectedPlanet = clickablePlanets.planetToClick; if (!this.SnapBackToSystem) this.HeightOnSnap = this.camHeight; this.ViewPlanet((object)this.SelectedPlanet); } } } foreach (UniverseScreen.ClickableShip clickableShip in this.ClickableShipsList) { if ((double)Vector2.Distance(input.CursorPosition, clickableShip.ScreenPos) <= (double)clickableShip.Radius) { this.pickedSomethingThisFrame = true; this.SelectedShipList.Add(clickableShip.shipToClick); using (List<UniverseScreen.ClickableShip>.Enumerator enumerator = this.ClickableShipsList.GetEnumerator()) { while (enumerator.MoveNext()) { UniverseScreen.ClickableShip current = enumerator.Current; if (clickableShip.shipToClick != current.shipToClick && current.shipToClick.loyalty == clickableShip.shipToClick.loyalty && current.shipToClick.Role == clickableShip.shipToClick.Role) this.SelectedShipList.Add(current.shipToClick); } break; } } } if (this.viewState > UniverseScreen.UnivScreenState.SystemView) { lock (GlobalStats.ClickableSystemsLock) { for (int local_27 = 0; local_27 < this.ClickableSystems.Count; ++local_27) { UniverseScreen.ClickableSystem local_28 = this.ClickableSystems[local_27]; if ((double)Vector2.Distance(input.CursorPosition, local_28.ScreenPos) <= (double)local_28.Radius) { if (local_28.systemToClick.ExploredDict[this.player]) { AudioManager.GetCue("sub_bass_whoosh").Play(); this.HeightOnSnap = this.camHeight; this.ViewSystem(local_28.systemToClick); } else this.PlayNegativeSound(); } } } } } else if (this.SelectedShip !=null) this.ClickTimer = 0.0f; //this.ClickTimer = 0.5f; } this.HandleSelectionBox(input); this.HandleScrolls(input); } if (this.LookingAtPlanet) { if (input.Tab) this.ShowShipNames = !this.ShowShipNames; if ((input.Escaped || input.CurrentMouseState.RightButton == ButtonState.Pressed && input.LastMouseState.RightButton == ButtonState.Released || this.workersPanel is ColonyScreen && (this.workersPanel as ColonyScreen).close.HandleInput(input)) && (!(this.workersPanel is ColonyScreen) || !(this.workersPanel as ColonyScreen).ClickedTroop)) { if (this.workersPanel is ColonyScreen && (this.workersPanel as ColonyScreen).p.Owner == null) { this.AdjustCamTimer = 1f; if (this.returnToShip) { this.ViewingShip = true; this.returnToShip = false; this.snappingToShip = true; this.transitionDestination.Z = this.transitionStartPosition.Z; } else this.transitionDestination = this.transitionStartPosition; this.transitionElapsedTime = 0.0f; this.LookingAtPlanet = false; } else { this.AdjustCamTimer = 1f; if (this.returnToShip) { this.ViewingShip = true; this.returnToShip = false; this.snappingToShip = true; this.transitionDestination.Z = this.transitionStartPosition.Z; } else this.transitionDestination = this.transitionStartPosition; this.transitionElapsedTime = 0.0f; this.LookingAtPlanet = false; } } } if (input.InGameSelect && !this.pickedSomethingThisFrame && (!input.CurrentKeyboardState.IsKeyDown(Keys.LeftShift) && !this.pieMenu.Visible)) { if (this.SelectedShip != null && this.SelectedShip != this.previousSelection) this.previousSelection = this.SelectedShip; this.SelectedShip = (Ship)null; this.SelectedShipList.Clear(); this.SelectedFleet = (Fleet)null; lock (GlobalStats.FleetButtonLocker) { for (int local_31 = 0; local_31 < this.FleetButtons.Count; ++local_31) { UniverseScreen.FleetButton local_32 = this.FleetButtons[local_31]; if (HelperFunctions.CheckIntersection(local_32.ClickRect, input.CursorPosition)) { this.SelectedFleet = local_32.Fleet; this.SelectedShipList.Clear(); foreach (Ship item_7 in (List<Ship>)this.SelectedFleet.Ships) { if (item_7.inSensorRange) this.SelectedShipList.Add(item_7); } if (this.SelectedShipList.Count == 1) { this.SelectedShip = this.SelectedShipList[0]; this.ShipInfoUIElement.SetShip(this.SelectedShip); this.SelectedShipList.Clear(); } else if (this.SelectedShipList.Count > 1) this.shipListInfoUI.SetShipList((List<Ship>)this.SelectedShipList, true); this.SelectedSomethingTimer = 3f; if ((double)this.ClickTimer < (double)this.TimerDelay) { this.ViewingShip = false; this.AdjustCamTimer = 0.5f; this.transitionDestination.X = this.SelectedFleet.findAveragePosition().X; this.transitionDestination.Y = this.SelectedFleet.findAveragePosition().Y; if (this.viewState < UniverseScreen.UnivScreenState.SystemView) this.transitionDestination.Z = this.GetZfromScreenState(UniverseScreen.UnivScreenState.SystemView); } else this.ClickTimer = 0.0f; } } } } this.cState = this.SelectedShip != null || this.SelectedShipList.Count > 0 ? UniverseScreen.CursorState.Move : UniverseScreen.CursorState.Normal; if (this.SelectedShip == null && this.SelectedShipList.Count <= 0) return; foreach (UniverseScreen.ClickableShip clickableShip in this.ClickableShipsList) { if ((double)Vector2.Distance(input.CursorPosition, clickableShip.ScreenPos) <= (double)clickableShip.Radius) this.cState = UniverseScreen.CursorState.Follow; } if (this.cState == UniverseScreen.CursorState.Follow) return; lock (GlobalStats.ClickableSystemsLock) { foreach (UniverseScreen.ClickablePlanets item_9 in this.ClickPlanetList) { if ((double)Vector2.Distance(input.CursorPosition, item_9.ScreenPos) <= (double)item_9.Radius && item_9.planetToClick.habitable) this.cState = UniverseScreen.CursorState.Orbit; } } }
public FleetGoal(SolarSystem toAttack, Fleet fleet, Fleet.FleetGoalType t) { this.fleet = fleet; this.sysToAttack = toAttack; this.type = t; }
public void SnapViewSystem(SolarSystem system, UniverseScreen.UnivScreenState camHeight) { float x = this.GetZfromScreenState(camHeight); this.transitionDestination = new Vector3(system.Position.X, system.Position.Y + 400f, x);//80000);// this.transitionStartPosition = this.camPos; this.AdjustCamTimer = 2f; this.transitionElapsedTime = 0.0f; this.transDuration = 5f; this.ViewingShip = false; this.snappingToShip = false; if (this.ViewingShip) this.returnToShip = true; this.ViewingShip = false; this.snappingToShip = false; this.SelectedFleet = (Fleet)null; this.SelectedShip = (Ship)null; this.SelectedShipList.Clear(); this.SelectedItem = (UniverseScreen.ClickableItemUnderConstruction)null; //this.input.CursorPosition = //this.ClickTimer2 = this.TimerDelay; }
public void PushToStack(Fleet.FleetGoal g) { this.GoalStack.Push(g); }
public void ViewPlanet(object sender) { this.ShowShipNames = false; if (this.SelectedPlanet == null) return; if (!this.SelectedPlanet.system.ExploredDict[this.player]) { this.PlayNegativeSound(); } else { bool flag = false; foreach (Mole mole in (List<Mole>)this.player.data.MoleList) { if (mole.PlanetGuid == this.SelectedPlanet.guid) flag = true; } this.workersPanel = this.SelectedPlanet.Owner == this.player || flag || this.Debug && this.SelectedPlanet.Owner != null ? (PlanetScreen)new ColonyScreen(this.SelectedPlanet, this.ScreenManager, this.EmpireUI) : (this.SelectedPlanet.Owner == null ? (PlanetScreen)new UnexploredPlanetScreen(this.SelectedPlanet, this.ScreenManager) : (PlanetScreen)new UnownedPlanetScreen(this.SelectedPlanet, this.ScreenManager)); this.LookingAtPlanet = true; this.transitionStartPosition = this.camPos; this.transitionDestination = new Vector3(this.SelectedPlanet.Position.X, this.SelectedPlanet.Position.Y + 400f, 2500f); this.AdjustCamTimer = 2f; this.transitionElapsedTime = 0.0f; this.transDuration = 5f; if (this.ViewingShip) this.returnToShip = true; this.ViewingShip = false; this.snappingToShip = false; this.SelectedFleet = (Fleet)null; this.SelectedShip = (Ship)null; this.SelectedShipList.Clear(); this.SelectedItem = (UniverseScreen.ClickableItemUnderConstruction)null; } }
public void SetCombatStatusTo(Fleet.FleetCombatStatus fcs, List<Fleet.Squad> Flank) { if (this.CenterFlank == Flank) { this.CenterCS = fcs; foreach (Fleet.Squad squad in Flank) { foreach (Ship ship in (List<Ship>)squad.Ships) ship.FleetCombatStatus = fcs; } } else if (this.ScreenFlank == Flank) { this.ScreenCS = fcs; foreach (Fleet.Squad squad in Flank) { foreach (Ship ship in (List<Ship>)squad.Ships) ship.FleetCombatStatus = fcs; } } else if (this.LeftFlank == Flank) { this.LeftCS = fcs; foreach (Fleet.Squad squad in Flank) { foreach (Ship ship in (List<Ship>)squad.Ships) ship.FleetCombatStatus = fcs; } } else if (this.RightFlank == Flank) { this.RightCS = fcs; foreach (Fleet.Squad squad in Flank) { foreach (Ship ship in (List<Ship>)squad.Ships) ship.FleetCombatStatus = fcs; } } else if (this.RearFlank == Flank) { this.RearCS = fcs; foreach (Fleet.Squad squad in Flank) { foreach (Ship ship in (List<Ship>)squad.Ships) ship.FleetCombatStatus = fcs; } } else { foreach (Fleet.Squad squad in Flank) { foreach (Ship ship in (List<Ship>)squad.Ships) ship.FleetCombatStatus = fcs; } } }
public void ViewToShip(object sender) { if (this.SelectedShip == null) return; this.ShipToView = this.SelectedShip; this.ShipInfoUIElement.SetShip(this.SelectedShip); //fbedard: was not updating correctly from shiplist this.SelectedFleet = (Fleet)null; this.SelectedShipList.Clear(); this.SelectedItem = (UniverseScreen.ClickableItemUnderConstruction)null; this.SelectedSystem = (SolarSystem)null; this.SelectedPlanet = (Planet)null; this.snappingToShip = true; this.HeightOnSnap = this.camHeight; this.transitionDestination.Z = 3500f; this.AdjustCamTimer = 1.0f; this.transitionElapsedTime = 0.0f; this.transitionDestination.Z = 4500f; this.snappingToShip = true; this.ViewingShip = true; }
public static void CreateFleetFromDataAt(FleetDesign data, Empire Owner, Vector2 Position, float facing) { Fleet fleet = new Fleet() { Position = Position, facing = facing, Owner = Owner, DataNodes = new BatchRemovalCollection<FleetDataNode>() }; foreach (FleetDataNode node in data.Data) { fleet.DataNodes.Add(node); } fleet.AssignDataPositions(facing); fleet.Name = data.Name; fleet.FleetIconIndex = data.FleetIconIndex; fleet.DataNodes.thisLock.EnterWriteLock(); foreach (FleetDataNode node in fleet.DataNodes) { Ship s = ResourceManager.CreateShipAtPoint(node.ShipName, Owner, Position + node.OrdersOffset, facing); s.RelativeFleetOffset = node.FleetOffset; node.SetShip(s); fleet.AddShip(s); } fleet.DataNodes.thisLock.ExitWriteLock(); foreach (Ship s in Owner.GetFleetsDict()[1].Ships) { s.fleet = null; } Owner.GetFleetsDict()[1] = fleet; }
/** This method allocates any available manpower into a TaskForce for offensive measures; and de-allocates the TaskForce from other fleet contingents. Deprecated? --> DOToughtNutRequisition? */ private void DoToughNutRequisitionORIG() { float EnemyTroopStr = this.GetEnemyTroopStr(); float EnemyShipStr = this.GetEnemyStrAtTarget(); //create collection of sorted AOs IOrderedEnumerable<Ship_Game.Gameplay.AO> sorted = from ao in this.empire.GetGSAI().AreasOfOperations //foreach AO, order by enemy & distance, then "select" for addition into collection orderby Vector2.Distance(this.AO, ao.Position) select ao; //if target is empty, AO's absent, exit method call if (sorted.Count<Ship_Game.Gameplay.AO>() == 0) { return; } //else, there are targets List<Ship> Bombers = new List<Ship>(); List<Ship> EverythingElse = new List<Ship>(); List<Troop> Troops = new List<Troop>(); //calculate this faction's strength foreach (Ship_Game.Gameplay.AO area in sorted) { //claculate opposition fleet strength foreach (Ship ship in this.empire.GetShips()) { //if ship in ships in AO are null, or outside area of operation, or in combat , or in defensive DefensiveForcePool, increment to next ship //(unavilable to be requisitioned for offense) if (ship.GetStrength() == 0f || Vector2.Distance(ship.Center, area.Position) >= area.Radius || ship.InCombat || ship.fleet != null || this.empire.GetGSAI().DefensiveCoordinator.DefensiveForcePool.Contains(ship))// ship.GetAI().SystemToDefend !=null) //&& ship.fleet != null & ship.fleet.Task == null) //ships managed by the DefensiveCoordinator or unable to be re-allocated for offense { continue; } //for valid ships in this faction's empire if (ship.BombBays.Count <= 0) { EverythingElse.Add(ship); } else { Bombers.Add(ship); } } //claculate ground troops that may be allocated for offensive foreach (Planet p in area.GetPlanets()) { if (p.RecentCombat) { continue; } foreach (Troop t in p.TroopsHere) { if (t.GetOwner() != this.empire) { continue; } Troops.Add(t); } } } //determine TaskForce to match calculated opposition strength List<Ship> TaskForce = new List<Ship>(); float strAdded = 0f; List<Ship>.Enumerator enumerator = EverythingElse.GetEnumerator(); //enumerator returns position information try { do { // Returns: // true if the enumerator was successfully advanced to the next element; false if // the enumerator has passed the end of the collection. if (!enumerator.MoveNext()) { break; } Ship ship = enumerator.Current; TaskForce.Add(ship); //add ships that are idle (without destination ~ MoveNext) strAdded = strAdded + ship.GetStrength(); //sum the strength of the task force } while (strAdded <= EnemyShipStr );//* 1.65f); //continue requisitoining ships until TaskForceStrength is greater than EnemyShipStr } finally { ((IDisposable)enumerator).Dispose(); //de-allocate object } List<Ship> BombTaskForce = new List<Ship>(); int numBombs = 0; foreach (Ship ship in Bombers) { if (numBombs >= 20) { continue; //bomber fleet should consist of at max twenth bombers } BombTaskForce.Add(ship); numBombs = numBombs + ship.BombBays.Count; } List<Troop> PotentialTroops = new List<Troop>(); float troopStr = 0f; List<Troop>.Enumerator enumerator1 = Troops.GetEnumerator(); int numOfTroops=0; try { do { if (!enumerator1.MoveNext()) { break; } numOfTroops++; Troop t = enumerator1.Current; PotentialTroops.Add(t); troopStr = troopStr + t.Strength; } while (troopStr <= EnemyTroopStr * 1.25f || numOfTroops <15 ); //create sufficient ground force for offensive action } finally { ((IDisposable)enumerator1).Dispose(); } //if this faction ship strength is greater than opposition 160% of opposition //Ermenildo V. Castro, Jr. //07/25/15 //"* 1.65f" --> "* 3f" if (strAdded > EnemyShipStr * 3f)//1.65f) { if (this.TargetPlanet.Owner == null || this.TargetPlanet.Owner != null && !this.empire.GetRelations().ContainsKey(this.TargetPlanet.Owner)) { this.EndTask(); return; } if (this.empire.GetRelations()[this.TargetPlanet.Owner].PreparingForWar) { this.empire.GetGSAI().DeclareWarOn(this.TargetPlanet.Owner, this.empire.GetRelations()[this.TargetPlanet.Owner].PreparingForWarType); } //retrieve closest area of operations target Ship_Game.Gameplay.AO ClosestAO = sorted.First<Ship_Game.Gameplay.AO>(); //create assault MilitaryTask MilitaryTask assault = new MilitaryTask(this.empire) //declarative property instantiation, constructor supplement { AO = this.TargetPlanet.Position, AORadius = 75000f, type = MilitaryTask.TaskType.AssaultPlanet }; ClosestAO.GetCoreFleet().Owner.GetGSAI().TasksToAdd.Add(assault); assault.WhichFleet = ClosestAO.WhichFleet; //assault fleet, WhichFleet, is assigned the fleet closest to target AO ClosestAO.GetCoreFleet().Task = assault; assault.IsCoreFleetTask = true; assault.Step = 1; //Step, used for? assault.TargetPlanet = this.TargetPlanet; ClosestAO.GetCoreFleet().TaskStep = 0; ClosestAO.GetCoreFleet().Name = "Doom Fleet"; foreach (Ship ship in TaskForce) { if (ship.fleet != null) { ship.fleet.Ships.Remove(ship); //remove ship from global empire fleet pool } ship.GetAI().OrderQueue.Clear(); //ship, rescind previous orders this.empire.GetGSAI().DefensiveCoordinator.remove(ship); //remove ship from defensive coordinator pool //foreach (KeyValuePair<SolarSystem, SystemCommander> entry in this.empire.GetGSAI().DefensiveCoordinator.DefenseDict) //{ // List<Ship> toRemove = new List<Ship>(); // foreach (KeyValuePair<Guid, Ship> defender in entry.Value.ShipsDict) // { // if (defender.Key != ship.guid) // { // continue; // } // toRemove.Add(defender.Value); // } // foreach (Ship s in toRemove) // { // entry.Value.ShipsDict.Remove(s.guid); // } //} ship.fleet = null; //ship is unassigned to any fleet } //ASSIGN SHIPS foreach (Ship ship in TaskForce) { ClosestAO.GetCoreFleet().AddShip(ship); //TaskForce ship is added into the core fleet } //ASSIGN GROUND TROOPS foreach (Troop t in PotentialTroops) { if (t.GetPlanet() == null) { continue; } (new List<Troop>()).Add(t); Ship launched = t.Launch(); //launch troop from ground ClosestAO.GetCoreFleet().AddShip(launched); //add troop transport into core fleet } ClosestAO.GetCoreFleet().AutoArrange(); //ASSIGN BOMBERS if (Bombers.Count > 0 && numBombs > 6) { MilitaryTask GlassPlanet = new MilitaryTask(this.empire) //task this empire to glass opposition planet { //multiple properties assignment declaration AO = this.TargetPlanet.Position,//the target planet AORadius = 75000f, type = MilitaryTask.TaskType.GlassPlanet, TargetPlanet = this.TargetPlanet, WaitForCommand = true }; Fleet bomberFleet = new Fleet() { Owner = this.empire }; bomberFleet.Owner.GetGSAI().TasksToAdd.Add(GlassPlanet); GlassPlanet.WhichFleet = this.empire.GetUnusedKeyForFleet(); this.empire.GetFleetsDict().TryAdd(GlassPlanet.WhichFleet, bomberFleet); bomberFleet.Task = GlassPlanet; bomberFleet.Name = "Bomber Fleet"; foreach (Ship ship in BombTaskForce) { if (ship.fleet != null) { ship.fleet.Ships.Remove(ship); } ship.GetAI().OrderQueue.Clear(); this.empire.GetGSAI().DefensiveCoordinator.remove(ship); ship.fleet = null; } foreach (Ship ship in BombTaskForce) { bomberFleet.AddShip(ship); } bomberFleet.AutoArrange(); } this.Step = 1; //What is step for? this.empire.GetGSAI().TaskList.QueuePendingRemoval(this); //remove this MilitaryTask from queue } }