public RefitToWindow(Ship ship) { this.shiptorefit = ship; base.IsPopup = true; base.TransitionOnTime = TimeSpan.FromSeconds(0.25); base.TransitionOffTime = TimeSpan.FromSeconds(0.25); }
public Beam(Vector2 srcCenter, int Thickness, Ship Owner, GameplayObject target) { this.Target = target; this.owner = Owner; Vector2 TargetPosition = Vector2.Normalize(target.Center); if (Owner.InFrustum) { this.DamageToggleSound = AudioManager.GetCue("sd_shield_static_1"); } if (this.owner.isInDeepSpace || this.owner.GetSystem() == null) { UniverseScreen.DeepSpaceManager.BeamList.Add(this); } else { this.system = this.owner.GetSystem(); this.system.spatialManager.BeamList.Add(this); } this.Source = srcCenter; this.BeamOffsetAngle = Owner.Rotation - MathHelper.ToRadians(HelperFunctions.findAngleToTarget(srcCenter, TargetPosition)); this.Destination = HelperFunctions.findPointFromAngleAndDistanceUsingRadians(srcCenter, Owner.Rotation + this.BeamOffsetAngle, this.range); this.ActualHitDestination = this.Destination; this.Vertices = new VertexPositionNormalTexture[4]; this.Indexes = new int[6]; this.BeamZ = RandomMath2.RandomBetween(-1f, 1f); Vector3[] points = HelperFunctions.BeamPoints(srcCenter, TargetPosition, (float)Thickness, new Vector2[4], 0, this.BeamZ); this.UpperLeft = points[0]; this.UpperRight = points[1]; this.LowerLeft = points[2]; this.LowerRight = points[3]; this.FillVertices(); }
public Goal(string ShipType, string forWhat, Empire e) { this.ToBuildUID = ShipType; this.empire = e; this.beingBuilt = ResourceManager.ShipsDict[ShipType]; this.GoalName = forWhat; this.Evaluate(); }
public RefitToWindow(ShipListScreenEntry entry, ShipListScreen screen) { this.screen = screen; this.shiptorefit = entry.ship; base.IsPopup = true; base.TransitionOnTime = TimeSpan.FromSeconds(0.25); base.TransitionOffTime = TimeSpan.FromSeconds(0.25); }
public Goal(Planet toColonize, Empire e) { this.empire = e; this.GoalName = "MarkForColonization"; this.type = GoalType.Colonize; this.markedPlanet = toColonize; this.colonyShip = (Ship)null; }
public DimensionalPrison(Vector2 Position) { this.p1 = Position + new Vector2(0f, -400f); this.p2 = Position + new Vector2(-400f, 400f); this.p3 = Position + new Vector2(400f, 400f); this.s1 = ResourceManager.CreateShipAtPoint(this.PlatformName, EmpireManager.GetEmpireByName("Unknown"), this.p1); this.s2 = ResourceManager.CreateShipAtPoint(this.PlatformName, EmpireManager.GetEmpireByName("Unknown"), this.p2); this.s3 = ResourceManager.CreateShipAtPoint(this.PlatformName, EmpireManager.GetEmpireByName("Unknown"), this.p3); this.Position = Position; Rectangle r = new Rectangle((int)Position.X - 200, (int)Position.Y - 200, 400, 400); this.Prison = new BackgroundItem(); this.Prison.LoadContent(Anomaly.screen.ScreenManager, Anomaly.screen.view, Anomaly.screen.projection); this.Prison.UpperLeft = new Vector3((float)r.X, (float)r.Y, 0f); this.Prison.LowerLeft = this.Prison.UpperLeft + new Vector3(0f, (float)r.Height, 0f); this.Prison.UpperRight = this.Prison.UpperLeft + new Vector3((float)r.Width, 0f, 0f); this.Prison.LowerRight = this.Prison.UpperLeft + new Vector3((float)r.Width, (float)r.Height, 0f); this.Prison.Texture = ResourceManager.TextureDict["Textures/star_neutron"]; this.Prison.FillVertices(); this.b1 = new Beam(this.p1, Position, 50, this.s1) { weapon = ResourceManager.WeaponsDict["AncientRepulsor"] }; this.b1.LoadContent(Anomaly.screen.ScreenManager, Anomaly.screen.view, Anomaly.screen.projection); this.s1.Beams.Add(this.b1); this.b1.infinite = true; this.b1.range = 2500f; this.b1.thickness = 75; this.b1.PowerCost = 0f; this.b1.damageAmount = 0f; this.b2 = new Beam(this.p2, Position, 50, this.s2) { weapon = ResourceManager.WeaponsDict["AncientRepulsor"] }; this.b2.LoadContent(Anomaly.screen.ScreenManager, Anomaly.screen.view, Anomaly.screen.projection); this.b2.infinite = true; this.s2.Beams.Add(this.b2); this.b2.range = 2500f; this.b2.thickness = 75; this.b2.PowerCost = 0f; this.b2.damageAmount = 0f; this.b3 = new Beam(this.p3, Position, 50, this.s3) { weapon = ResourceManager.WeaponsDict["AncientRepulsor"] }; this.b3.LoadContent(Anomaly.screen.ScreenManager, Anomaly.screen.view, Anomaly.screen.projection); this.b3.infinite = true; this.s3.Beams.Add(this.b3); this.b3.range = 2500f; this.b3.thickness = 75; this.b3.PowerCost = 0f; this.b3.damageAmount = 0f; }
public List<Ship> GetNearby(Ship obj) { List<Ship> objects = new List<Ship>(); foreach (int item in this.GetIdForObj(obj)) { if (!this.Buckets.ContainsKey(item)) { continue; } objects.AddRange(this.Buckets[item]); } return objects; }
public void AddShip(Ship ship) { if (ship.BaseStrength == 0) return; if (this.ThreatLevel < this.CoreFleet.GetStrength()) { this.OffensiveForcePool.Add(ship); this.Flip = !this.Flip; return; } if (this.CoreFleet.Task == null && ship.fleet == null) { ship.GetAI().OrderQueue.Clear(); ship.GetAI().HasPriorityOrder = false; this.CoreFleet.AddShip(ship); foreach (Ship waiting in this.ShipsWaitingForCoreFleet) { if (waiting.fleet != null) { continue; } this.CoreFleet.AddShip(waiting); waiting.GetAI().OrderQueue.Clear(); waiting.GetAI().HasPriorityOrder = false; } this.CoreFleet.Position = this.CoreWorld.Position; this.CoreFleet.AutoArrange(); this.CoreFleet.MoveToNow(this.Position, 0f, new Vector2(0f, -1f)); this.ShipsWaitingForCoreFleet.Clear(); } else if (ship.fleet == null) { this.ShipsWaitingForCoreFleet.Add(ship); this.OffensiveForcePool.Add(ship); } this.Flip = !this.Flip; }
public ShipListScreenEntry(Ship s, int x, int y, int width1, int height, ShipListScreen caller) { this.screen = caller; this.ship = s; this.TotalEntrySize = new Rectangle(x, y, width1 - 60, height); this.SysNameRect = new Rectangle(x, y, (int)((float)this.TotalEntrySize.Width * 0.10f), height); this.ShipNameRect = new Rectangle(x + this.SysNameRect.Width, y, (int)((float)this.TotalEntrySize.Width * 0.175f), height); this.RoleRect = new Rectangle(x + this.SysNameRect.Width + this.ShipNameRect.Width, y, (int)((float)this.TotalEntrySize.Width * 0.05f), height); this.OrdersRect = new Rectangle(x + this.SysNameRect.Width + this.ShipNameRect.Width + this.RoleRect.Width, y, (int)((float)this.TotalEntrySize.Width * 0.175f), height); this.RefitRect = new Rectangle(this.OrdersRect.X + this.OrdersRect.Width, y, 125, height); this.STRRect = new Rectangle(this.RefitRect.X + this.RefitRect.Width, y, 60, height); this.MaintRect = new Rectangle(this.STRRect.X + this.STRRect.Width, y, 60, height); this.TroopRect = new Rectangle(this.MaintRect.X + this.MaintRect.Width, y, 60, height); this.FTLRect = new Rectangle(this.TroopRect.X + this.TroopRect.Width, y, 60, height); this.STLRect = new Rectangle(this.FTLRect.X + this.FTLRect.Width, y, 60, height); this.Status_Text = ShipListScreenEntry.GetStatusText(this.ship); this.ShipIconRect = new Rectangle(this.ShipNameRect.X + 5, this.ShipNameRect.Y + 2, 28, 28); string shipName = (!string.IsNullOrEmpty(this.ship.VanityName) ? this.ship.VanityName : this.ship.Name); this.ShipNameEntry.ClickableArea = new Rectangle(this.ShipIconRect.X + this.ShipIconRect.Width + 10, 2 + this.SysNameRect.Y + this.SysNameRect.Height / 2 - Fonts.Arial20Bold.LineSpacing / 2, (int)Fonts.Arial20Bold.MeasureString(shipName).X, Fonts.Arial20Bold.LineSpacing); this.ShipNameEntry.Text = shipName; float width = (float)((int)((float)this.OrdersRect.Width * 0.8f)); while (width % 10f != 0f) { width = width + 1f; } Rectangle refit = new Rectangle(this.RefitRect.X + this.RefitRect.Width / 2 - 5 - ResourceManager.TextureDict["NewUI/icon_queue_rushconstruction_hover1"].Width, this.RefitRect.Y + this.RefitRect.Height / 2 - ResourceManager.TextureDict["NewUI/icon_queue_rushconstruction_hover2"].Height / 2, ResourceManager.TextureDict["NewUI/icon_queue_rushconstruction_hover2"].Width, ResourceManager.TextureDict["NewUI/icon_queue_rushconstruction_hover2"].Height); this.ExploreButton = new TexturedButton(refit, "NewUI/icon_order_explore", "NewUI/icon_order_explore_hover1", "NewUI/icon_order_explore_hover2"); this.PatrolButton = new TexturedButton(refit, "NewUI/icon_order_patrol", "NewUI/icon_order_patrol_hover1", "NewUI/icon_order_patrol_hover2"); this.RefitButton = new TexturedButton(refit, "NewUI/icon_queue_rushconstruction", "NewUI/icon_queue_rushconstruction_hover1", "NewUI/icon_queue_rushconstruction_hover2"); this.ScrapButton = new TexturedButton(refit, "NewUI/icon_queue_delete", "NewUI/icon_queue_delete_hover1", "NewUI/icon_queue_delete_hover2"); if (this.ship.Role == "station" || this.ship.Role == "platform" || this.ship.Thrust <= 0f) { this.isScuttle = true; } }
//added by gremlin ExplorationTarget public SolarSystem AssignExplorationTarget(Ship queryingShip) { List<SolarSystem> Potentials = new List<SolarSystem>(); foreach (SolarSystem s in UniverseScreen.SolarSystemList) { if (s.ExploredDict[this.empire]) { continue; } Potentials.Add(s); } this.MarkedForExploration.thisLock.EnterReadLock(); foreach (SolarSystem s in this.MarkedForExploration) { Potentials.Remove(s); } this.MarkedForExploration.thisLock.ExitReadLock(); IOrderedEnumerable<SolarSystem> sortedList = from system in Potentials orderby Vector2.Distance(this.empire.GetWeightedCenter(), system.Position) select system; if (sortedList.Count<SolarSystem>() <= 0) { queryingShip.GetAI().OrderQueue.Clear(); return null; } //SolarSystem nearesttoScout = sortedList.OrderBy(furthest => Vector2.Distance(queryingShip.Center, furthest.Position)).FirstOrDefault(); SolarSystem nearesttoHome = sortedList.OrderBy(furthest => Vector2.Distance(this.empire.GetWeightedCenter(), furthest.Position)).FirstOrDefault(); ; //SolarSystem potentialTarget = null; foreach (SolarSystem nearest in sortedList) { if (nearest.CombatInSystem) continue; float distanceToScout = Vector2.Distance(queryingShip.Center, nearest.Position); float distanceToEarth = Vector2.Distance(this.empire.GetWeightedCenter(), nearest.Position); if (distanceToScout > distanceToEarth + 50000f) { continue; } nearesttoHome = nearest; break; } this.MarkedForExploration.Add(nearesttoHome); return nearesttoHome; }
public override bool HandleInput(InputState input) { List<Ship> ships = new List<Ship>(); bool reset = false; for (int i = this.SelectedShipsSL.indexAtTop; i < this.SelectedShipsSL.Entries.Count && i < this.SelectedShipsSL.indexAtTop + this.SelectedShipsSL.entriesToDisplay; i++) { foreach (SkinnableButton button in (this.SelectedShipsSL.Entries[i].item as SelectedShipEntry).ShipButtons) { if ((button.ReferenceObject as Ship).Active) { continue; } reset = true; break; } if (reset) { break; } } if (reset) { this.SetShipList(this.ShipList, this.isFleet); } if (this.screen.SelectedShipList.Count == 0 || this.screen.SelectedShipList.Count == 1) { return false; } if (this.ShipList == null || this.ShipList.Count == 0) { return false; } if (this.gridbutton.HandleInput(input)) { AudioManager.PlayCue("sd_ui_accept_alt3"); this.ShowModules = !this.ShowModules; if (!this.ShowModules) { this.gridbutton.Active = false; } else { this.gridbutton.Active = true; } return true; } if (this.AllShipsMine) { foreach (ToggleButton button in this.CombatStatusButtons) { if (!HelperFunctions.CheckIntersection(button.r, input.CursorPosition)) { button.Hover = false; } else { button.Hover = true; if (button.HasToolTip) { ToolTip.CreateTooltip(button.WhichToolTip, this.ScreenManager); } if (input.InGameSelect) { AudioManager.PlayCue("sd_ui_accept_alt3"); string action = button.Action; string str = action; if (action != null) { if (str == "attack") { foreach (Ship ship in this.ShipList) { ship.GetAI().CombatState = CombatState.AttackRuns; } } else if (str == "arty") { foreach (Ship ship in this.ShipList) { ship.GetAI().CombatState = CombatState.Artillery; } } else if (str == "hold") { foreach (Ship ship in this.ShipList) { ship.GetAI().CombatState = CombatState.HoldPosition; } } else if (str == "orbit_left") { foreach (Ship ship in this.ShipList) { ship.GetAI().CombatState = CombatState.OrbitLeft; } } else if (str == "broadside_left") { foreach (Ship ship in this.ShipList) { ship.GetAI().CombatState = CombatState.BroadsideLeft; } } else if (str == "orbit_right") { foreach (Ship ship in this.ShipList) { ship.GetAI().CombatState = CombatState.OrbitRight; } } else if (str == "broadside_right") { foreach (Ship ship in this.ShipList) { ship.GetAI().CombatState = CombatState.BroadsideRight; } } else if (str == "evade") { foreach (Ship ship in this.ShipList) { ship.GetAI().CombatState = CombatState.Evade; } } } } } if (this.HoveredShip == null) { button.Active = false; } else { string action1 = button.Action; string str1 = action1; if (action1 == null) { continue; } if (str1 == "attack") { if (this.HoveredShip.GetAI().CombatState != CombatState.AttackRuns) { button.Active = false; } else { button.Active = true; } } else if (str1 == "arty") { if (this.HoveredShip.GetAI().CombatState != CombatState.Artillery) { button.Active = false; } else { button.Active = true; } } else if (str1 == "hold") { if (this.HoveredShip.GetAI().CombatState != CombatState.HoldPosition) { button.Active = false; } else { button.Active = true; } } else if (str1 == "orbit_left") { if (this.HoveredShip.GetAI().CombatState != CombatState.OrbitLeft) { button.Active = false; } else { button.Active = true; } } else if (str1 == "broadside_left") { if (this.HoveredShip.GetAI().CombatState != CombatState.BroadsideLeft) { button.Active = false; } else { button.Active = true; } } else if (str1 != "orbit_right") { if (str1 == "evade") { if (this.HoveredShip.GetAI().CombatState != CombatState.Evade) { button.Active = false; } else { button.Active = true; } } } else if (str1 == "broadside_right") { if (this.HoveredShip.GetAI().CombatState != CombatState.BroadsideRight) { button.Active = false; } else { button.Active = true; } } else if (this.HoveredShip.GetAI().CombatState != CombatState.OrbitRight) { button.Active = false; } else { button.Active = true; } } } if (this.sliding_element.HandleInput(input)) { if (!this.sliding_element.Open) { base.State = UIElement.ElementState.TransitionOff; } else { base.State = UIElement.ElementState.TransitionOn; } return true; } if (base.State == UIElement.ElementState.Open) { bool orderhover = false; foreach (OrdersButton ob in this.Orders) { if (!ob.HandleInput(input, this.ScreenManager)) { continue; } orderhover = true; } if (orderhover) { return true; } } } this.SelectedShipsSL.HandleInput(input); this.HoveredShipLast = this.HoveredShip; this.HoveredShip = null; for (int i = this.SelectedShipsSL.indexAtTop; i < this.SelectedShipsSL.Entries.Count && i < this.SelectedShipsSL.indexAtTop + this.SelectedShipsSL.entriesToDisplay; i++) { try { foreach (SkinnableButton button in (this.SelectedShipsSL.Entries[i].item as SelectedShipEntry).ShipButtons) { if (!HelperFunctions.CheckIntersection(button.r, input.CursorPosition)) { button.Hover = false; } else { if (this.HoveredShipLast != (Ship)button.ReferenceObject) { AudioManager.PlayCue("sd_ui_mouseover"); } button.Hover = true; this.HoveredShip = (Ship)button.ReferenceObject; if (!input.InGameSelect) { continue; } //added by gremlin filter by selected ship in shiplist. if (input.CurrentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift)) { foreach(Ship filter in this.screen.SelectedShipList) { if(filter.Role != this.HoveredShip.Role) { this.screen.SelectedShipList.QueuePendingRemoval(filter); } } this.screen.SelectedShipList.ApplyPendingRemovals(); this.SetShipList(this.screen.SelectedShipList, false); this.SelectedShipsSL.indexAtTop = 0; this.SelectedShipsSL.ScrollBar.Y = this.SelectedShipsSL.ScrollBarHousing.Y; continue; } else { this.screen.SelectedFleet = null; this.screen.SelectedShipList.Clear(); this.screen.SelectedShip = this.HoveredShip; //fbedard: multi-select if (this.screen.SelectedShip != null && this.screen.SelectedShip != this.screen.previousSelection) this.screen.previousSelection = this.screen.SelectedShip; this.screen.ShipInfoUIElement.SetShip(this.HoveredShip); } return true; } } } catch { } } foreach (ShipListInfoUIElement.TippedItem ti in this.ToolTipItems) { if (!HelperFunctions.CheckIntersection(ti.r, input.CursorPosition)) { continue; } ToolTip.CreateTooltip(ti.TIP_ID, this.ScreenManager); } if (HelperFunctions.CheckIntersection(this.ElementRect, input.CursorPosition)) { return true; } return false; }
public void SetParent(Ship ship) { this.Parent = ship; }
public void SetParent(Ship p) { this.Parent = p; }
public void SetHangarShip(Ship ship) { this.hangarShip = ship; }
private void DoBuildConstructionShip() { switch (this.Step) { case 0: List<Planet> list = new List<Planet>(); foreach (Planet planet in this.empire.GetPlanets()) { if (planet.HasShipyard) list.Add(planet); } IOrderedEnumerable<Planet> orderedEnumerable = Enumerable.OrderByDescending<Planet, float>((IEnumerable<Planet>)list, (Func<Planet, float>)(planet => planet.ConstructionQueue.Count ));//Vector2.Distance(planet.Position, this.BuildPosition))); if (Enumerable.Count<Planet>((IEnumerable<Planet>)orderedEnumerable) <= 0) break; this.PlanetBuildingAt = Enumerable.ElementAt<Planet>((IEnumerable<Planet>)orderedEnumerable, 0); QueueItem queueItem = new QueueItem(); queueItem.isShip = true; queueItem.DisplayName = "Construction Ship"; queueItem.QueueNumber = Enumerable.ElementAt<Planet>((IEnumerable<Planet>)orderedEnumerable, 0).ConstructionQueue.Count; queueItem.sData = ResourceManager.ShipsDict[EmpireManager.GetEmpireByName(Ship.universeScreen.PlayerLoyalty).data.CurrentConstructor].GetShipData(); queueItem.Goal = this; queueItem.Cost = ResourceManager.ShipsDict[this.ToBuildUID].GetCost(this.empire); queueItem.NotifyOnEmpty = false; if (!string.IsNullOrEmpty(this.empire.data.CurrentConstructor) && ResourceManager.ShipsDict.ContainsKey(this.empire.data.CurrentConstructor)) { this.beingBuilt = ResourceManager.ShipsDict[this.empire.data.CurrentConstructor]; } else { this.beingBuilt = null; string empiredefaultShip = this.empire.data.DefaultConstructor; if (string.IsNullOrEmpty(empiredefaultShip)) { empiredefaultShip = this.empire.data.DefaultSmallTransport; } ResourceManager.ShipsDict.TryGetValue(empiredefaultShip, out this.beingBuilt); //if(this.beingBuilt == null) //{ // ResourceManager.ShipsDict.TryGetValue(ResourceManager.GetEmpireByName(this.empire.data.Traits.Name).DefaultSmallTransport, out this.beingBuilt); //} this.empire.data.DefaultConstructor = empiredefaultShip; } Enumerable.ElementAt<Planet>((IEnumerable<Planet>)orderedEnumerable, 0).ConstructionQueue.Add(queueItem); ++this.Step; break; case 4: this.empire.GetGSAI().Goals.QueuePendingRemoval(this); break; } }
private bool shipIsGoodForGoals(Ship ship) { if (ship.BaseStrength > 0f && ship.shipData.ShipStyle != "Platforms" && !ship.shipData.CarrierShip && ship.BaseCanWarp && !ship.Inhibited && ship.ModulePowerDraw * this.empire.data.FTLPowerDrainModifier <= ship.PowerFlowMax || (ship.ModulePowerDraw * this.empire.data.FTLPowerDrainModifier > ship.PowerFlowMax && ship.PowerStoreMax / (ship.ModulePowerDraw * this.empire.data.FTLPowerDrainModifier - ship.PowerFlowMax) * ship.velocityMaximum > minimumWarpRange)) return true; return false; }
public void AddShipORIG(Ship shiptoadd) { this.Ships.Add(shiptoadd); shiptoadd.fleet = this; IOrderedEnumerable<Ship> orderedEnumerable = Enumerable.OrderBy<Ship, float>((IEnumerable<Ship>)this.Ships, (Func<Ship, float>)(ship => ship.speed)); this.speed = Enumerable.Count<Ship>((IEnumerable<Ship>)orderedEnumerable) > 0 ? Enumerable.ElementAt<Ship>((IEnumerable<Ship>)orderedEnumerable, 0).speed : 200f; Vector2 vector2 = shiptoadd.RelativeFleetOffset; this.AssignPositions(this.facing); }
public void SetShip(Ship s) { this.ship = s; }
public void SetBeingBuilt(Ship s) { this.beingBuilt = s; }
private void DoMarkedColonizeGoal() { switch (this.Step) { case 0: bool flag1 = false; foreach (Ship ship in (List<Ship>)this.empire.GetShips()) { if (ship.isColonyShip && !ship.isPlayerShip() && (ship.GetAI() != null && ship.GetAI().State != AIState.Colonize)) { this.colonyShip = ship; flag1 = true; } } Planet planet1 = (Planet)null; if (!flag1) { 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) { int num2 = 0; foreach (QueueItem queueItem in (List<QueueItem>)planet2.ConstructionQueue) num2 += (int)(((double)queueItem.Cost - (double)queueItem.productionTowards) / (double)planet2.NetProductionPerTurn); if (num2 < num1) { num1 = num2; planet1 = planet2; } } if (planet1 == null) break; if (this.empire.isPlayer && ResourceManager.ShipsDict.ContainsKey(this.empire.data.CurrentAutoColony)) { planet1.ConstructionQueue.Add(new QueueItem() { isShip = true, QueueNumber = planet1.ConstructionQueue.Count, sData = ResourceManager.ShipsDict[this.empire.data.CurrentAutoColony].GetShipData(), Goal = this, Cost = ResourceManager.ShipsDict[this.empire.data.CurrentAutoColony].GetCost(this.empire) }); this.PlanetBuildingAt = planet1; ++this.Step; break; } else { QueueItem queueItem = new QueueItem(); queueItem.isShip = true; queueItem.QueueNumber = planet1.ConstructionQueue.Count; if (ResourceManager.ShipsDict.ContainsKey(this.empire.data.DefaultColonyShip)) { queueItem.sData = ResourceManager.ShipsDict[this.empire.data.DefaultColonyShip].GetShipData(); } else { queueItem.sData = ResourceManager.ShipsDict[ResourceManager.GetEmpireByName(this.empire.data.Traits.Name).DefaultColonyShip].GetShipData(); this.empire.data.DefaultColonyShip = ResourceManager.GetEmpireByName(this.empire.data.Traits.Name).DefaultColonyShip; } queueItem.Goal = this; queueItem.NotifyOnEmpty = false; queueItem.Cost = ResourceManager.ShipsDict[this.empire.data.DefaultColonyShip].GetCost(this.empire); planet1.ConstructionQueue.Add(queueItem); this.PlanetBuildingAt = planet1; ++this.Step; break; } } else { this.Step = 2; this.DoMarkedColonizeGoal(); break; } case 1: bool flag2 = false; foreach (QueueItem queueItem in (List<QueueItem>)this.PlanetBuildingAt.ConstructionQueue) { if (queueItem.isShip && ResourceManager.ShipsDict[queueItem.sData.Name].isColonyShip) flag2 = true; } if (!flag2) { this.PlanetBuildingAt = (Planet)null; this.Step = 0; } if (this.markedPlanet.Owner == null) break; foreach (KeyValuePair<Empire, Relationship> Them in this.empire.GetRelations()) this.empire.GetGSAI().CheckClaim(Them, this.markedPlanet); this.empire.GetGSAI().Goals.QueuePendingRemoval(this); break; case 2: if (this.markedPlanet.Owner != null) { foreach (KeyValuePair<Empire, Relationship> Them in this.empire.GetRelations()) this.empire.GetGSAI().CheckClaim(Them, this.markedPlanet); this.empire.GetGSAI().Goals.QueuePendingRemoval(this); break; } else { bool flag3; if (this.colonyShip == null) { flag3 = false; foreach (Ship ship in (List<Ship>)this.empire.GetShips()) { if (ship.isColonyShip && !ship.isPlayerShip() && (ship.GetAI() != null && ship.GetAI().State != AIState.Colonize)) { this.colonyShip = ship; flag3 = true; } } } else flag3 = true; if (flag3) { this.colonyShip.DoColonize(this.markedPlanet, this); this.Step = 3; break; } else { this.Step = 0; break; } } case 3: if (this.colonyShip == null) { this.Step = 0; break; } else if (this.colonyShip != null && this.colonyShip.Active && this.colonyShip.GetAI().State != AIState.Colonize) { this.Step = 0; break; } else if (this.colonyShip != null && !this.colonyShip.Active && this.markedPlanet.Owner == null) { this.Step = 0; break; } else { if (this.markedPlanet.Owner == null) break; foreach (KeyValuePair<Empire, Relationship> Them in this.empire.GetRelations()) this.empire.GetGSAI().CheckClaim(Them, this.markedPlanet); this.empire.GetGSAI().Goals.QueuePendingRemoval(this); this.colonyShip.GetAI().State = AIState.AwaitingOrders; this.Step = 4; break; } } }
public void SetColonyShip(Ship s) { this.colonyShip = s; }
private void DoIncreasePassTranGoal() { switch (this.Step) { case 0: bool flag1 = false; foreach (Ship ship in (List<Ship>)this.empire.GetShips()) { if (!ship.isColonyShip && ship.Role == "freighter" && (!ship.isPlayerShip() && ship.GetAI() != null) && (ship.GetAI().State != AIState.PassengerTransport && ship.GetAI().State != AIState.SystemTrader)) { this.passTran = ship; flag1 = true; } } if (flag1) { this.Step = 2; break; } else { List<Planet> list1 = new List<Planet>(); foreach (Planet planet in this.empire.GetPlanets()) { if (planet.HasShipyard) list1.Add(planet); } Planet planet1 = (Planet)null; int num1 = 9999999; foreach (Planet planet2 in list1) { int num2 = 0; foreach (QueueItem queueItem in (List<QueueItem>)planet2.ConstructionQueue) num2 += (int)(((double)queueItem.Cost - (double)queueItem.productionTowards) / (double)planet2.NetProductionPerTurn); if (num2 < num1) { num1 = num2; planet1 = planet2; } } if (planet1 == null) break; if (this.empire.isPlayer && this.empire.AutoFreighters && ResourceManager.ShipsDict.ContainsKey(this.empire.data.CurrentAutoFreighter)) { planet1.ConstructionQueue.Add(new QueueItem() { isShip = true, QueueNumber = planet1.ConstructionQueue.Count, sData = ResourceManager.ShipsDict[this.empire.data.CurrentAutoFreighter].GetShipData(), Goal = this, Cost = ResourceManager.ShipsDict[this.empire.data.CurrentAutoFreighter].GetCost(this.empire), NotifyOnEmpty=false }); ++this.Step; break; } else { List<Ship> list2 = new List<Ship>(); foreach (string index in this.empire.ShipsWeCanBuild) { if (!ResourceManager.ShipsDict[index].isColonyShip && ResourceManager.ShipsDict[index].Role == "freighter") list2.Add(ResourceManager.ShipsDict[index]); } IOrderedEnumerable<Ship> orderedEnumerable1 = Enumerable.OrderByDescending<Ship, float>((IEnumerable<Ship>)list2, (Func<Ship, float>)(ship => ship.CargoSpace_Max)); List<Ship> list3 = new List<Ship>(); foreach (Ship ship in (IEnumerable<Ship>)orderedEnumerable1) { if (!ship.isColonyShip && (double)ship.CargoSpace_Max >= (double)Enumerable.First<Ship>((IEnumerable<Ship>)orderedEnumerable1).CargoSpace_Max) list3.Add(ship); } IOrderedEnumerable<Ship> orderedEnumerable2 = Enumerable.OrderByDescending<Ship, float>((IEnumerable<Ship>)list2, (Func<Ship, float>)(ship => ship.WarpThrust / ship.Mass)); if (Enumerable.Count<Ship>((IEnumerable<Ship>)orderedEnumerable2) <= 0) break; planet1.ConstructionQueue.Add(new QueueItem() { isShip = true, QueueNumber = planet1.ConstructionQueue.Count, sData = ResourceManager.ShipsDict[Enumerable.First<Ship>((IEnumerable<Ship>)orderedEnumerable2).Name].GetShipData(), Goal = this, Cost = ResourceManager.ShipsDict[Enumerable.First<Ship>((IEnumerable<Ship>)orderedEnumerable2).Name].GetCost(this.empire) }); ++this.Step; break; } } case 2: bool flag2 = false; foreach (Ship ship in (List<Ship>)this.empire.GetShips()) { if (!ship.isColonyShip && ship.Role == "freighter" && (!ship.isPlayerShip() && ship.GetAI() != null) && (ship.GetAI().State != AIState.PassengerTransport && ship.GetAI().State != AIState.SystemTrader && (!ship.GetAI().HasPriorityOrder && ship.GetAI().State != AIState.Refit)) && ship.GetAI().State != AIState.Scrap) { this.passTran = ship; flag2 = true; } } if (flag2) { this.passTran.GetAI().OrderTransportPassengers(); this.empire.ReportGoalComplete(this); break; } else { this.Step = 0; break; } } }
public SolarSystem AssignExplorationTargetORIG(Ship queryingShip) { List<SolarSystem> Potentials = new List<SolarSystem>(); foreach (SolarSystem s in UniverseScreen.SolarSystemList) { if (s.ExploredDict[this.empire]) { continue; } Potentials.Add(s); } foreach (SolarSystem s in this.MarkedForExploration) { Potentials.Remove(s); } IOrderedEnumerable<SolarSystem> sortedList = from system in Potentials orderby Vector2.Distance(this.empire.GetWeightedCenter(), system.Position) select system; if (sortedList.Count<SolarSystem>() <= 0) { queryingShip.GetAI().OrderQueue.Clear(); return null; } this.MarkedForExploration.Add(sortedList.First<SolarSystem>()); return sortedList.First<SolarSystem>(); }
public void LaunchBoardingPartyORIG(Troop troop) { if (this.IsTroopBay && this.Powered) { if (this.hangarShip != null) { this.hangarShip.DoEscort(this.Parent); return; } if (this.hangarTimer <= 0f && this.hangarShip == null) { this.hangarShip = Ship_Game.ResourceManager.CreateTroopShipAtPoint(this.Parent.loyalty.data.StartingScout, this.Parent.loyalty, this.Center, troop); this.hangarShip.VanityName = "Assault Ship"; this.hangarShip.Mothership = this.Parent; this.hangarShip.DoEscort(this.Parent); this.hangarShip.Velocity = (((this.Parent.GetSystem() != null ? this.Parent.GetSystem().RNG : Ship.universeScreen.DeepSpaceRNG)).RandomDirection() * this.hangarShip.speed) + this.Parent.Velocity; if (this.hangarShip.Velocity.Length() > this.hangarShip.velocityMaximum) { this.hangarShip.Velocity = Vector2.Normalize(this.hangarShip.Velocity) * this.hangarShip.speed; } this.installedSlot.HangarshipGuid = this.hangarShip.guid; this.hangarTimer = this.hangarTimerConstant; } } }
public void AssignShipToForce(Ship toAdd) { int numWars = 0; foreach (KeyValuePair<Empire, Ship_Game.Gameplay.Relationship> Relationship in this.empire.GetRelations()) { if (!Relationship.Value.AtWar || Relationship.Key.isFaction) { continue; } numWars++; } float baseDefensePct = 0.1f; baseDefensePct = baseDefensePct + 0.15f * (float)numWars; float defStr = this.DefensiveCoordinator.GetForcePoolStrength(); if (baseDefensePct > 0.35f) { baseDefensePct = 0.35f; } float EntireStrength = 0f; foreach (Ship ship in this.empire.GetShips()) { EntireStrength = EntireStrength + ship.GetStrength(); } //added by gremlin dont add zero strength ships to defensive force pool //if (this.DefensiveCoordinator.GetForcePoolStrength() / EntireStrength <= baseDefensePct if ((this.DefensiveCoordinator.defenseDeficit > 0 && this.DefensiveCoordinator.GetForcePoolStrength() < EntireStrength * baseDefensePct) && (toAdd.BombBays.Count == 0 || toAdd.WarpThrust <= 0f) &&toAdd.GetStrength()>0 && toAdd.BaseCanWarp) // { this.DefensiveCoordinator.DefensiveForcePool.Add(toAdd); toAdd.GetAI().SystemToDefend = null; toAdd.GetAI().SystemToDefendGuid = Guid.Empty; toAdd.GetAI().HasPriorityOrder = false; toAdd.GetAI().State = AIState.SystemDefender; this.DefensiveCoordinator.defenseDeficit-=toAdd.BaseStrength; return; } IOrderedEnumerable<AO> sorted = from ao in this.empire.GetGSAI().AreasOfOperations orderby Vector2.Distance(toAdd.Position, ao.Position) select ao; if (sorted.Count<AO>() <= 0) { this.empire.GetForcePool().Add(toAdd); return; } //sorted.First().AddShip(toAdd);// First<AO>().AddShip(toAdd); sorted.ElementAt(0).AddShip(toAdd); }
public void ScrambleFightersORIG() { if (!this.IsTroopBay && this.Powered && !this.IsSupplyBay) { if (this.hangarShip != null && this.hangarShip.Active) { this.hangarShip.DoEscort(this.Parent); return; } if (this.hangarTimer <= 0f && (this.hangarShip == null || this.hangarShip != null && !this.hangarShip.Active)) { this.hangarShip = Ship_Game.ResourceManager.CreateShipFromHangar(this.hangarShipUID, this.Parent.loyalty, this.Center, this.Parent); if (this.hangarShip != null) { this.hangarShip.DoEscort(this.Parent); this.hangarShip.Velocity = (((this.Parent.GetSystem() != null ? this.Parent.GetSystem().RNG : Ship.universeScreen.DeepSpaceRNG)).RandomDirection() * this.hangarShip.speed) + this.Parent.Velocity; if (this.hangarShip.Velocity.Length() > this.hangarShip.velocityMaximum) { this.hangarShip.Velocity = Vector2.Normalize(this.hangarShip.Velocity) * this.hangarShip.speed; } this.hangarShip.Mothership = this.Parent; this.installedSlot.HangarshipGuid = this.hangarShip.guid; this.hangarTimer = this.hangarTimerConstant; } } } }
public void AddShip(Ship shiptoadd) { if (shiptoadd.Role == "station" || shiptoadd.IsPlatform) { return; } this.Ships.Add(shiptoadd); shiptoadd.fleet = this; IOrderedEnumerable<Ship> speedSorted = from ship in this.Ships orderby ship.speed select ship; this.speed = (speedSorted.Count<Ship>() > 0 ? speedSorted.ElementAt<Ship>(0).speed : 200f); Vector2 relativeFleetOffset = shiptoadd.RelativeFleetOffset; this.AssignPositions(this.facing); }
private void DoBuildScoutGoal() { switch (this.Step) { case 0: List<Planet> list1 = new List<Planet>(); foreach (Planet planet in this.empire.GetPlanets()) { if (planet.HasShipyard) list1.Add(planet); } Planet planet1 = (Planet)null; int num1 = 9999999; foreach (Planet planet2 in list1) { int num2 = 0; foreach (QueueItem queueItem in (List<QueueItem>)planet2.ConstructionQueue) num2 += (int)(((double)queueItem.Cost - (double)queueItem.productionTowards) / (double)planet2.NetProductionPerTurn); if (num2 < num1) { num1 = num2; planet1 = planet2; } } if (planet1 == null) break; if (EmpireManager.GetEmpireByName(Ship.universeScreen.PlayerLoyalty) == this.empire && ResourceManager.ShipsDict.ContainsKey(EmpireManager.GetEmpireByName(Ship.universeScreen.PlayerLoyalty).data.CurrentAutoScout)) { planet1.ConstructionQueue.Add(new QueueItem() { isShip = true, QueueNumber = planet1.ConstructionQueue.Count, sData = ResourceManager.ShipsDict[EmpireManager.GetEmpireByName(Ship.universeScreen.PlayerLoyalty).data.CurrentAutoScout].GetShipData(), Goal = this, Cost = ResourceManager.ShipsDict[EmpireManager.GetEmpireByName(Ship.universeScreen.PlayerLoyalty).data.CurrentAutoScout].GetCost(this.empire), NotifyOnEmpty=false }); ++this.Step; break; } else { List<Ship> list2 = new List<Ship>(); foreach (string index in this.empire.ShipsWeCanBuild) { if (ResourceManager.ShipsDict[index].Role == "scout") list2.Add(ResourceManager.ShipsDict[index]); } IOrderedEnumerable<Ship> orderedEnumerable = Enumerable.OrderByDescending<Ship, float>((IEnumerable<Ship>)list2, (Func<Ship, float>)(ship => ship.PowerFlowMax - ship.ModulePowerDraw)); if (Enumerable.Count<Ship>((IEnumerable<Ship>)orderedEnumerable) <= 0) break; planet1.ConstructionQueue.Add(new QueueItem() { isShip = true, QueueNumber = planet1.ConstructionQueue.Count, sData = ResourceManager.ShipsDict[Enumerable.First<Ship>((IEnumerable<Ship>)orderedEnumerable).Name].GetShipData(), Goal = this, Cost = ResourceManager.ShipsDict[Enumerable.First<Ship>((IEnumerable<Ship>)orderedEnumerable).Name].GetCost(this.empire) }); ++this.Step; break; } case 2: bool flag = false; foreach (Ship ship in (List<Ship>)this.empire.GetShips()) { if ((ship.Role == "scout" || ship.Name == EmpireManager.GetEmpireByName(Ship.universeScreen.PlayerLoyalty).data.CurrentAutoScout) && !ship.isPlayerShip()) { this.freighter = ship; flag = true; } } if (!flag) break; this.freighter.GetAI().OrderExplore(); this.empire.ReportGoalComplete(this); break; } }
private void EvaluateTask(float elapsedTime) { if (this.Ships.Count == 0) this.Task.EndTask(); if (this.Task == null) return; switch (this.Task.type) { case MilitaryTask.TaskType.ClearAreaOfEnemies: this.DoClearAreaOfEnemies(this.Task); break; case MilitaryTask.TaskType.AssaultPlanet: this.DoAssaultPlanet(this.Task); break; case MilitaryTask.TaskType.CorsairRaid: #region MyRegion if (this.TaskStep != 0) break; this.Task.TaskTimer -= elapsedTime; if ((double)this.Task.TaskTimer <= 0.0) { Ship ship1 = new Ship(); foreach (Ship ship2 in (List<Ship>)this.Owner.GetShips()) { if (ship2.Name == "Corsair Asteroid Base") { ship1 = ship2; break; } } if (ship1 != null) { this.AssembleFleet(0.0f, Vector2.One); this.FormationWarpTo(ship1.Position, 0.0f, Vector2.One); this.Task.EndTaskWithMove(); } else this.Task.EndTask(); } if (this.Ships.Count != 0) break; this.Task.EndTask(); break; #endregion case MilitaryTask.TaskType.CohesiveClearAreaOfEnemies: this.DoCohesiveClearAreaOfEnemies(this.Task); break; case MilitaryTask.TaskType.Exploration: this.DoExplorePlanet(this.Task); break; case MilitaryTask.TaskType.DefendSystem: this.DoDefendSystem(this.Task); break; case MilitaryTask.TaskType.DefendClaim: this.DoClaimDefense(this.Task); break; case MilitaryTask.TaskType.DefendPostInvasion: this.DoPostInvasionDefense(this.Task); break; case MilitaryTask.TaskType.GlassPlanet: this.DoGlassPlanet(this.Task); break; } }
//added by gremlin boarding parties public void LaunchBoardingParty(Troop troop) { if (this.IsTroopBay && this.Powered) { if (this.hangarShip != null) { //this.hangarShip.GetAI().State == AIState.AssaultPlanet || this.hangarShip.GetAI().State == AIState.Boarding || if (this.hangarShip.GetAI().State == AIState.ReturnToHangar || this.hangarShip.GetAI().EscortTarget != null || this.hangarShip.GetAI().OrbitTarget != null) return; this.hangarShip.DoEscort(this.Parent); return; } if (this.hangarTimer <= 0f && this.hangarShip == null) { this.hangarShip = ResourceManager.CreateTroopShipAtPoint(this.Parent.loyalty.data.StartingScout, this.Parent.loyalty, this.Center, troop); this.hangarShip.VanityName = "Assault Ship"; this.hangarShip.Mothership = this.Parent; this.hangarShip.DoEscort(this.Parent); this.hangarShip.Velocity = (((this.Parent.GetSystem() != null ? this.Parent.GetSystem().RNG : Ship.universeScreen.DeepSpaceRNG)).RandomDirection() * this.hangarShip.speed) + this.Parent.Velocity; if (this.hangarShip.Velocity.Length() > this.hangarShip.velocityMaximum) { this.hangarShip.Velocity = Vector2.Normalize(this.hangarShip.Velocity) * this.hangarShip.speed; } this.installedSlot.HangarshipGuid = this.hangarShip.guid; this.hangarTimer = this.hangarTimerConstant; //if (this.Parent.GetAI().Target != null && this.Parent.GetAI().Target is Ship && (this.Parent.GetAI().Target as Ship).loyalty != this.Parent.loyalty) //{ // this.hangarShip.GetAI().OrderTroopToBoardShip(this.Parent.GetAI().Target as Ship); //} } } }