public SystemMap() { m_oViewPortPanel = new Panels.SysMap_ViewPort(); m_oControlsPanel = new Panels.SysMap_Controls(); /// <summary> /// Add time button handlers to ViewPortPanel. /// </summary> m_oViewPortPanel.AdvanceTime5S.Click += new EventHandler(AdvanceTime5S_Click); m_oViewPortPanel.AdvanceTime30S.Click += new EventHandler(AdvanceTime30S_Click); m_oViewPortPanel.AdvanceTime2M.Click += new EventHandler(AdvanceTime2M_Click); m_oViewPortPanel.AdvanceTime5M.Click += new EventHandler(AdvanceTime5M_Click); m_oViewPortPanel.AdvanceTime20M.Click += new EventHandler(AdvanceTime20M_Click); m_oViewPortPanel.AdvanceTime1H.Click += new EventHandler(AdvanceTime1H_Click); m_oViewPortPanel.AdvanceTime3H.Click += new EventHandler(AdvanceTime3H_Click); m_oViewPortPanel.AdvanceTime8H.Click += new EventHandler(AdvanceTime8H_Click); m_oViewPortPanel.AdvanceTime1D.Click += new EventHandler(AdvanceTime1D_Click); m_oViewPortPanel.AdvanceTime5D.Click += new EventHandler(AdvanceTime5D_Click); m_oViewPortPanel.AdvanceTime30D.Click += new EventHandler(AdvanceTime30D_Click); m_oViewPortPanel.StartSim.Click += new EventHandler(StartSim_Click); // setup GL Canvas and insert it into the ViewPort: m_oGLCanvas = new GLCanvas(); m_oGLCanvas.Dock = DockStyle.Fill; m_oViewPortPanel.Controls.Add(m_oGLCanvas); // setup viewmodel: VM = new GLStarSystemViewModel(); // Bind System Selection Combo Box. m_oControlsPanel.SystemSelectionComboBox.Bind(c => c.DataSource, VM, d => d.StarSystems); m_oControlsPanel.SystemSelectionComboBox.Bind(c => c.SelectedItem, VM, d => d.CurrentStarSystem, DataSourceUpdateMode.OnPropertyChanged); m_oControlsPanel.SystemSelectionComboBox.DisplayMember = "Name"; VM.StarSystemChanged += (s, args) => CurrentStarSystem = VM.CurrentStarSystem; m_oCurrnetSystem = VM.CurrentStarSystem; m_oControlsPanel.SystemSelectionComboBox.SelectedIndexChanged += (s, args) => m_oControlsPanel.SystemSelectionComboBox.DataBindings["SelectedItem"].WriteValue(); // register event handlers:\ m_oGLCanvas.KeyDown += new KeyEventHandler(OnKeyDown); m_oGLCanvas.MouseDown += new MouseEventHandler(OnMouseDown); m_oGLCanvas.MouseMove += new MouseEventHandler(OnMouseMove); m_oGLCanvas.MouseUp += new MouseEventHandler(OnMouseUp); m_oGLCanvas.MouseHover += new EventHandler(OnMouseHover); m_oGLCanvas.MouseWheel += new MouseEventHandler(OnMouseWheel); m_oGLCanvas.Click += new EventHandler(m_oGLCanvas_Click); m_oViewPortPanel.SizeChanged += new EventHandler(ViewPort_SizeChanged); m_oControlsPanel.PanUpButton.Click += new EventHandler(PanUpButton_Click); m_oControlsPanel.PanDownButton.Click += new EventHandler(PanDownButton_Click); m_oControlsPanel.PanLeftButton.Click += new EventHandler(PanLeftButton_Click); m_oControlsPanel.PanRightButton.Click += new EventHandler(PanRightButton_Click); m_oControlsPanel.ZoomInButton.Click += new EventHandler(ZoomInButton_Click); m_oControlsPanel.ZoomOutButton.Click += new EventHandler(ZoomOutButton_Click); m_oControlsPanel.ResetViewButton.Click += new EventHandler(ResetViewButton_Click); m_oControlsPanel.CreateMapMarkerButton.Click += new EventHandler(CreateMapMarkerButton_Click); m_oControlsPanel.DeleteMapMarkerButton.Click += new EventHandler(DeleteMapMarkerButton_Click); m_oControlsPanel.SystemSelectionComboBox.SelectedIndexChanged += new EventHandler(SystemSelectComboBox_SelectedIndexChanged); }
public Star(string name, double radius, uint temp, float luminosity, SpectralType spectralType, StarSystem system) { Name = name; Position.System = system; Position.X = 0; Position.Y = 0; Temperature = temp; Luminosity = luminosity; SpectralType = spectralType; Radius = radius; Class = SpectralType.ToString(); Planets = new BindingList<SystemBody>(); SupportsPopulations = false; }
public Waypoint(String Title, StarSystem Sys, double X, double Y, int FactionID) { Name = Title; /// <summary> /// create these or else anything that relies on a unique global id will break. /// </summary> Id = Guid.NewGuid(); FactionId = FactionID; Position.System = Sys; Position.X = X; Position.Y = Y; SSEntity = StarSystemEntityType.Waypoint; }
/// <summary> /// Adds any detected ships to the system location box. /// </summary> private void AddContactsToList(StarSystem starsystem) { if (CurrentFaction.DetectedContactLists.ContainsKey(starsystem) == true) { foreach (KeyValuePair<ShipTN, FactionContact> pair in CurrentFaction.DetectedContactLists[CurrentTaskGroup.Contact.Position.System].DetectedContacts) { String TH = ""; if (pair.Value.thermal == true) { TH = String.Format("[Thermal {0}]", pair.Key.CurrentThermalSignature); } String EM = ""; if (pair.Value.EM == true) { EM = String.Format("[EM {0}]", pair.Key.CurrentEMSignature); } String ACT = ""; if (pair.Value.active == true) { ACT = String.Format("[ACT {0}]", pair.Key.TotalCrossSection); } String Entry = String.Format("{0} {1}{2}{3}", pair.Key.Name, TH, EM, ACT); //m_oTaskGroupPanel.SystemLocationsListBox.Items.Add(Entry); SystemListObject.ListEntityType entType = SystemListObject.ListEntityType.Contacts; SystemListObject valueObj = new SystemListObject(entType, pair.Key); //maybe this should be the value? though with the key I can *get* the value easly anyway. SystemLocationGuidDict.Add(pair.Key.Id, Entry); SystemLocationDict.Add(pair.Key.Id, valueObj); } foreach (KeyValuePair<Population, FactionContact> pair in CurrentFaction.DetectedContactLists[CurrentTaskGroup.Contact.Position.System].DetectedPopContacts) { String TH = ""; if (pair.Value.thermal == true) { TH = String.Format("[Thermal {0}]", pair.Key.ThermalSignature); } String EM = ""; if (pair.Value.EM == true) { EM = String.Format("[EM {0}]", pair.Key.EMSignature); } String ACT = ""; if (pair.Value.active == true) { ACT = String.Format("[Active Ping]"); } String Entry = String.Format("{0} {1}{2}{3}", pair.Key.Name, TH, EM, ACT); //m_oTaskGroupPanel.SystemLocationsListBox.Items.Add(Entry); SystemListObject.ListEntityType entType = SystemListObject.ListEntityType.Contacts; SystemListObject valueObj = new SystemListObject(entType, pair.Key); //maybe this should be the value? though with the key I can *get* the value easly anyway. SystemLocationGuidDict.Add(pair.Key.Id, Entry); SystemLocationDict.Add(pair.Key.Id, valueObj); } } }
public Star(string name, double radius, uint temp, float luminosity, SpectralType spectralType, StarSystem system) { Name = name; Position.System = system; Position.X = 0; Position.Y = 0; Temperature = temp; Luminosity = luminosity; SpectralType = spectralType; Radius = radius; Class = SpectralType.ToString(); Planets = new BindingList <SystemBody>(); SupportsPopulations = false; }
/// <summary> /// create factions fills in the factions, tgs, and ships. The design for ships should be modified here. /// </summary> /// <param name="P">Factions</param> /// <param name="Sol">Starting starsystem</param> /// <param name="factionCount"># of factions</param> /// <param name="TGCount"># of tgs</param> /// <param name="ShipCount"># of ships</param> /// <param name="RNG">"global" rng since it has to be done that way.</param> void createFactions(BindingList<Faction> P, StarSystem Sol, int factionCount, int TGCount, int ShipCount, Random RNG) { for (int loop = 0; loop < factionCount; loop++) { Faction P1 = new Faction(loop); P1.AddNewContactList(Sol); P1.AddNewShipDesign("Blucher"); P1.ShipDesigns[0].AddEngine(P1.ComponentList.Engines[0], 3); P1.ShipDesigns[0].AddCrewQuarters(P1.ComponentList.CrewQuarters[0], 1); P1.ShipDesigns[0].AddFuelStorage(P1.ComponentList.FuelStorage[0], 1); P1.ShipDesigns[0].AddEngineeringSpaces(P1.ComponentList.EngineeringSpaces[0], 1); P1.ShipDesigns[0].AddOtherComponent(P1.ComponentList.OtherComponents[0], 1); P1.ShipDesigns[0].AddActiveSensor(P1.ComponentList.ActiveSensorDef[0], 1); P1.ShipDesigns[0].AddBeamFireControl(P1.ComponentList.BeamFireControlDef[0], 1); P1.ShipDesigns[0].AddBeamWeapon(P1.ComponentList.BeamWeaponDef[0], 2); P1.ShipDesigns[0].AddReactor(P1.ComponentList.ReactorDef[0], 2); P1.ShipDesigns[0].NewArmor("Duranium", 5, 4); for (int loop2 = 0; loop2 < TGCount; loop2++) { int randx = RNG.Next(0, 100000); int randy = RNG.Next(0, 100000); float wx = ((float)randx / 50000.0f) - 1.0f; float wy = ((float)randy / 50000.0f) - 1.0f; SystemBody Start = new SystemBody(Sol.Stars[0], SystemBody.PlanetType.Terrestrial); Start.Position.X = wx; Start.Position.Y = wy; string ID1 = loop.ToString(); string TGName = "P" + ID1 + "TG 01"; P1.AddNewTaskGroup(TGName, Start, Sol); for (int loop3 = 0; loop3 < ShipCount; loop3++) { P1.TaskGroups[loop2].AddShip(P1.ShipDesigns[0], "Test Ship"); P1.TaskGroups[loop2].Ships[loop3].Refuel(200000.0f); P1.TaskGroups[loop2].SetActiveSensor(loop3, 0, true); } } P.Add(P1); } }
/// <summary> /// Final defensive fire scans through all potential FCs that could fire defensively on the incoming missile to see if it is intercepeted. /// All PD enabled FCs will attempt to shoot down this missile except ones from the same faction, as this missile is practically right on top of said FC. /// In other words allied/neutral status isn't taken into account. /// </summary> /// <param name="P">Faction list</param> /// <param name="Missile">Missile to try to intercept</param> /// <param name="RNG">Random Number Generator</param> /// <returns>Whether the missile has been intercepted</returns> public static bool FinalDefensiveFire(BindingList <Faction> P, OrdnanceTN Missile, Random RNG) { bool Intercept = false; StarSystem CurrentSystem = Missile.missileGroup.contact.Position.System; float PointBlank = 10000.0f / (float)Constants.Units.KM_PER_AU; /// <summary> /// loop through every faction. /// </summary> foreach (Faction faction in P) { /// <summary> /// Is the current faction different from the missile group faction, and does the faction have a detected contacts list for the current system? /// </summary> if (faction != Missile.missileGroup.ordnanceGroupFaction && faction.DetectedContactLists.ContainsKey(CurrentSystem) == true) { /// <summary> /// Is the Missile group in this detected contact list? /// </summary> if (faction.DetectedContactLists[CurrentSystem].DetectedMissileContacts.ContainsKey(Missile.missileGroup) == true) { /// <summary> /// Is the detection an active detection? /// </summary> if (faction.DetectedContactLists[CurrentSystem].DetectedMissileContacts[Missile.missileGroup].active == true) { /// <summary> /// Does this faction have any point defense enabled FCs in this system? /// </summary> if (faction.PointDefense.ContainsKey(CurrentSystem) == true) { /// <summary> /// loop through all the possible PD enabled FC. /// </summary> foreach (KeyValuePair <ComponentTN, ShipTN> pair in faction.PointDefense[CurrentSystem].PointDefenseFC) { ShipTN Ship = pair.Value; /// <summary> /// Ship jump sickness will prevent point defense from operating. /// </summary> if (Ship.IsJumpSick()) { continue; } /// <summary> /// Only want BFCs in FDF mode for now. /// </summary> if (faction.PointDefense[CurrentSystem].PointDefenseType[pair.Key] == false && pair.Value.ShipBFC[pair.Key.componentIndex].pDState == PointDefenseState.FinalDefensiveFire) { BeamFireControlTN ShipBeamFC = pair.Value.ShipBFC[pair.Key.componentIndex]; /// <summary> /// Do a distance check on pair.Value vs the missile itself. if that checks out to be less than 10k km(or equal to zero), then /// check to see if the FC can shoot down said missile. This should never be run before a sensor sweep /// </summary> float dist = -1; /// <summary> /// dist is in AU. /// </summary> Missile.missileGroup.contact.DistTable.GetDistance(Ship.ShipsTaskGroup.Contact, out dist); /// <summary> /// if distance is less than the 10k km threshold attempt to intercept at Point blank range. /// </summary> if (dist < PointBlank) { /// <summary> /// Finally intercept the target. /// </summary> bool WF = false; Intercept = ShipBeamFC.InterceptTarget(RNG, 0, Missile, Ship.ShipsFaction, Ship.ShipsTaskGroup.Contact, Ship, out WF); /// <summary> /// Add this ship to the weapon recharge list since it has fired. This is done here in Sim, or for FDF_Self in Ship.cs /// </summary> if (WF == true) { if (faction.RechargeList.ContainsKey(Ship) == true) { /// <summary> /// If our recharge value does not have Recharge beams in it(bitflag 2 for now), then add it. /// </summary> if ((faction.RechargeList[pair.Value] & (int)Faction.RechargeStatus.Weapons) != (int)Faction.RechargeStatus.Weapons) { faction.RechargeList[pair.Value] = (faction.RechargeList[pair.Value] + (int)Faction.RechargeStatus.Weapons); } } else { faction.RechargeList.Add(pair.Value, (int)Faction.RechargeStatus.Weapons); } } /// <summary> /// break out of the first foreach loop. /// </summary> if (Intercept == true) { break; } } } } } } } } /// <summary> /// now break out of the faction loop as this missile has been shot down. /// </summary> if (Intercept == true) { break; } } return(Intercept); }
/// <summary> /// Initilized constructor. /// </summary> /// <param name="system">StarSystem value.</param> /// <param name="x">X value.</param> /// <param name="y">Y value.</param> public SystemPosition(StarSystem system, double x, double y) : this() { System = system; X = x; Y = y; }
/// <summary> /// TaskGroupThermal Detection runs the thermal detection routine on TaskGroupToTest from CurrentTaskGroup /// </summary> /// <param name="System">Current System this is taking place in.</param> /// <param name="CurrentTaskGroup">TaskGroup that is performing the sensor sweep.</param> /// <param name="TaskGroupToTest">TaskGroup being tested against.</param> /// <param name="dist">Distance between these two taskgroups.</param> /// <param name="detListIterator">Iterator for where the TaskGroupToTest is in the various detection lists and the system contact list.</param> /// <param name="DetShipList">If a ship is detected it must be put into this list for the detectedContactsList later on.</param> private void TaskGroupThermalDetection(StarSystem System, TaskGroupTN CurrentTaskGroup, TaskGroupTN TaskGroupToTest, float dist, int detListIterator) { if (System.FactionDetectionLists[FactionID].Thermal[detListIterator] != GameState.Instance.CurrentSecond) { int sig = -1; int detection = -1; bool noDetection = false; bool allDetection = false; /// <summary> /// Get the best detection range for thermal signatures in loop. /// </summary> int ShipID = TaskGroupToTest.ThermalSortList.Last(); ShipTN scratch = TaskGroupToTest.Ships[ShipID]; sig = scratch.CurrentThermalSignature; /// <summary> /// Check to make sure the taskgroup has a thermal sensor available, otherwise use the default. /// </summary> if (CurrentTaskGroup.BestThermalCount != 0) { detection = CurrentTaskGroup.BestThermal.pSensorDef.GetPassiveDetectionRange(sig); } else { detection = ComponentList.DefaultPassives.GetPassiveDetectionRange(sig); } /// <summary> /// Test the biggest signature against the best sensor. /// </summary> bool det = LargeDetection(dist, detection); /// <summary> /// Good case, none of the ships are detected. /// </summary> if (det == false) { noDetection = true; } /// <summary> /// Atleast the biggest ship is detected. /// </summary if (noDetection == false) { ShipID = TaskGroupToTest.ThermalSortList.First(); scratch = TaskGroupToTest.Ships[ShipID]; sig = scratch.CurrentThermalSignature; /// <summary> /// Check to make sure the taskgroup has a thermal sensor available, otherwise use the default. /// </summary> if (CurrentTaskGroup.BestThermalCount != 0) { detection = CurrentTaskGroup.BestThermal.pSensorDef.GetPassiveDetectionRange(sig); } else { detection = ComponentList.DefaultPassives.GetPassiveDetectionRange(sig); } /// <summary> /// Now for the smallest vs the best. /// </summary> det = LargeDetection(dist, detection); /// <summary> /// Best case, everything is detected. /// </summary> if (det == true) { allDetection = true; for (int loop3 = 0; loop3 < TaskGroupToTest.Ships.Count; loop3++) { TaskGroupToTest.Ships[loop3].ThermalDetection[FactionID] = GameState.Instance.CurrentSecond; if (DetShipList.Contains(TaskGroupToTest.Ships[loop3]) == false) { DetShipList.Add(TaskGroupToTest.Ships[loop3]); } } System.FactionDetectionLists[FactionID].Thermal[detListIterator] = GameState.Instance.CurrentSecond; } else if (noDetection == false && allDetection == false) { /// <summary> /// Worst case. some are detected, some aren't. /// </summary> for (int loop3 = 0; loop3 < TaskGroupToTest.Ships.Count; loop3++) { LinkedListNode<int> node = TaskGroupToTest.ThermalSortList.Last; bool done = false; while (!done) { scratch = TaskGroupToTest.Ships[node.Value]; if (scratch.ThermalDetection[FactionID] != GameState.Instance.CurrentSecond) { sig = scratch.CurrentThermalSignature; if (CurrentTaskGroup.BestThermalCount != 0) { detection = CurrentTaskGroup.BestThermal.pSensorDef.GetPassiveDetectionRange(sig); } else { detection = ComponentList.DefaultPassives.GetPassiveDetectionRange(sig); } /// <summary> /// Test each ship until I get to one I don't see. /// </summary> det = LargeDetection(dist, detection); if (det == true) { scratch.ThermalDetection[FactionID] = GameState.Instance.CurrentSecond; if (DetShipList.Contains(scratch) == false) { DetShipList.Add(scratch); } } else { done = true; break; } } if (node == TaskGroupToTest.ThermalSortList.First) { /// <summary> /// This should not happen. /// </summary> String ErrorMessage = string.Format("Partial Thermal detect for TGs looped through every ship. {0} {1} {2} {3}", dist, detection, noDetection, allDetection); MessageEntry NMsg = new MessageEntry(MessageEntry.MessageType.Error, TaskGroupToTest.Contact.Position.System, TaskGroupToTest.Contact, GameState.Instance.GameDateTime, GameState.Instance.LastTimestep, ErrorMessage); MessageLog.Add(NMsg); done = true; break; } node = node.Previous; } } } /// <summary> /// End else /// </summary> } } }
public Sceen(StarSystem a_oStarSystem, GLEffect a_oDefaultEffect, Pulsar4X.UI.Handlers.SystemMap ParentSM) { // set member vars: m_v3ViewOffset = Vector3.Zero; MeasureMode = false; ParentSystemMap = ParentSM; SceenDefaultEffect = a_oDefaultEffect; /// <summary> /// These have to be initialized before the contactElements are created as contactElement uses these. /// </summary> ShowActives = true; ShowPassives = true; ShowPassiveSignatureRange = (int)Constants.SensorTN.DefaultPassiveSignature; // Set Sceen Vars: m_oSceenEntity = a_oStarSystem; SceenID = a_oStarSystem.Id; // Create measurement element: m_oMeasurementElement = new MeasurementElement(); m_oMeasurementElement.PrimaryPrimitive = new GLLine(a_oDefaultEffect, Vector3.Zero, new Vector2(1.0f, 1.0f), Color.Yellow, UIConstants.Textures.DEFAULT_TEXTURE); m_oMeasurementElement.AddPrimitive(m_oMeasurementElement.PrimaryPrimitive); m_oMeasurementElement.Lable = new GLUtilities.GLFont(a_oDefaultEffect, Vector3.Zero, UIConstants.DEFAULT_TEXT_SIZE, Color.Yellow, UIConstants.Textures.DEFAULT_GLFONT2, ""); // Creat Working Vars: //double dKMperAUdevby10 = (Pulsar4X.Constants.Units.KmPerAu / 10); // we scale everthing down by 10 to avoid float buffer overflows. int iStarCounter = 0; // Keeps track of the number of stars. int iPlanetCounter = 0; // Keeps track of the number of planets around the current star int iMoonCounter = 0; // Keeps track of the number of moons around the current planet. double dMaxOrbitDist = 0; // used for fit to zoom. Vector3 v3StarPos = new Vector3(0, 0, 0); // used for storing the psoition of the current star in the system float fStarSize = 0.0f; // Size of a star double dPlanetOrbitRadius = 0; // used for holding the orbit in Km for a planet. Vector3 v3PlanetPos = new Vector3(0, 0, 0); // Used to store the planet Pos. float fPlanetSize = 0; // used to hold the planets size. double dMoonOrbitRadius = 0; // used for holding the orbit in Km for a Moon. float fMoonSize = 0; // used to hold the Moons size. Vector3 v3MoonPos = Vector3.Zero; // Used to store the Moons Position. // start creating star branches in the sceen graph: SceenElement oRootStar; SceenElement oCurrStar; foreach (Pulsar4X.Entities.Star oStar in a_oStarSystem.Stars) { if (iStarCounter <= 0) { // then we have a secondary, etc star give random position around its orbit! oRootStar = new StarElement(oStar, a_oDefaultEffect, Vector3.Zero, Pulsar4X.Constants.StarColor.LookupColor(oStar), true); oCurrStar = oRootStar; } else { Random rnd = new Random(); v3StarPos.X = (float)(oStar.Position.X); v3StarPos.Y = (float)(oStar.Position.Y); MaxOrbitDistTest(ref dMaxOrbitDist, oStar.Orbit.SemiMajorAxis); oCurrStar = new StarElement(oStar, a_oDefaultEffect, v3StarPos, Pulsar4X.Constants.StarColor.LookupColor(oStar), false); } fStarSize = (float)(oStar.Radius * 2.0 * (Constants.Units.SolarRadiusInAu)); GLUtilities.GLQuad oStarQuad = new GLUtilities.GLQuad(a_oDefaultEffect, v3StarPos, new Vector2(fStarSize, fStarSize), Pulsar4X.Constants.StarColor.LookupColor(oStar), UIConstants.Textures.DEFAULT_PLANET_ICON); // create name lable: GLUtilities.GLFont oNameLable = new GLUtilities.GLFont(a_oDefaultEffect, new Vector3((float)(v3StarPos.X), (float)(v3StarPos.Y - (oStar.Radius / Constants.Units.KmPerAu)), 0), UIConstants.DEFAULT_TEXT_SIZE, Color.White, UIConstants.Textures.DEFAULT_GLFONT2, oStar.Name); oCurrStar.AddPrimitive(oStarQuad); // Add star icon to the Sceen element. oCurrStar.Lable = oNameLable; oCurrStar.PrimaryPrimitive = oStarQuad; oCurrStar.RealSize = new Vector2(fStarSize, fStarSize); this.AddElement(oCurrStar); // now go though and add each planet to render list. foreach (Pulsar4X.Entities.SystemBody oPlanet in oStar.Planets) { SceenElement oPlanetElement = new PlanetElement(a_oDefaultEffect, v3StarPos, oPlanet, Color.FromArgb(255, 0, 205, 0)); oPlanetElement.EntityID = oPlanet.Id; if (iPlanetCounter == 0) { oCurrStar.SmallestOrbit = (float)(oPlanet.Orbit.SemiMajorAxis * 2); } dPlanetOrbitRadius = oPlanet.Orbit.SemiMajorAxis; fPlanetSize = (float)((oPlanet.Radius * 2.0) / Constants.Units.KmPerAu); MaxOrbitDistTest(ref dMaxOrbitDist, dPlanetOrbitRadius); GLUtilities.GLQuad oPlanetQuad = new GLUtilities.GLQuad(a_oDefaultEffect, v3PlanetPos, new Vector2(fPlanetSize, fPlanetSize), Color.FromArgb(255, 0, 255, 0), // lime green UIConstants.Textures.DEFAULT_PLANET_ICON); // create name lable: GLUtilities.GLFont oPlanetNameLable = new GLUtilities.GLFont(a_oDefaultEffect, new Vector3((float)(v3PlanetPos.X), (float)(v3PlanetPos.Y - (oPlanet.Radius / Constants.Units.KmPerAu)), 0), UIConstants.DEFAULT_TEXT_SIZE, Color.AntiqueWhite, UIConstants.Textures.DEFAULT_GLFONT2, oPlanet.Name); oPlanetElement.AddPrimitive(oPlanetQuad); oPlanetElement.Lable = oPlanetNameLable; oPlanetElement.PrimaryPrimitive = oPlanetQuad; oPlanetElement.RealSize = new Vector2(fPlanetSize, fPlanetSize); oCurrStar.AddChildElement(oPlanetElement); iPlanetCounter++; // now again for the moons: foreach (Pulsar4X.Entities.SystemBody oMoon in oPlanet.Moons) { SceenElement oMoonElement = new PlanetElement(a_oDefaultEffect, v3PlanetPos, oMoon, Color.FromArgb(255, 0, 205, 0)); oMoonElement.EntityID = oMoon.Id; if (iMoonCounter == 0) { oPlanetElement.SmallestOrbit = (float)(oMoon.Orbit.SemiMajorAxis); } dMoonOrbitRadius = oMoon.Orbit.SemiMajorAxis; fMoonSize = (float)((oMoon.Radius * 2.0) / Constants.Units.KmPerAu); v3MoonPos = new Vector3((float)(oMoon.Position.X), (float)(oMoon.Position.Y), 0); oMoon.Position.X = oMoon.Position.X + v3PlanetPos.X; oMoon.Position.Y = oMoon.Position.Y + v3PlanetPos.Y; GLUtilities.GLQuad oMoonQuad = new GLUtilities.GLQuad(a_oDefaultEffect, v3MoonPos, // offset Pos by parent planet pos new Vector2(fMoonSize, fMoonSize), Color.FromArgb(255, 0, 205, 0), // lime green UIConstants.Textures.DEFAULT_PLANET_ICON); GLUtilities.GLFont oMoonNameLable = new GLUtilities.GLFont(a_oDefaultEffect, new Vector3((float)(v3MoonPos.X), (float)(v3MoonPos.Y - (oMoon.Radius / Constants.Units.KmPerAu)), 0), UIConstants.DEFAULT_TEXT_SIZE, Color.AntiqueWhite, UIConstants.Textures.DEFAULT_GLFONT2, oMoon.Name); oMoonElement.AddPrimitive(oMoonQuad); oMoonElement.Lable = oMoonNameLable; oMoonElement.PrimaryPrimitive = oMoonQuad; oMoonElement.RealSize = new Vector2(fMoonSize, fMoonSize); oPlanetElement.AddChildElement(oMoonElement); iMoonCounter++; } iMoonCounter = 0; } iPlanetCounter = 0; foreach (Pulsar4X.Entities.JumpPoint oJumpPoint in a_oStarSystem.JumpPoints) { CreateJumpPoint(oCurrStar, oJumpPoint); } iStarCounter++; } foreach (Pulsar4X.Entities.SystemContact systemContact in a_oStarSystem.SystemContactList) { AddContactElement(SceenDefaultEffect, systemContact); } a_oStarSystem.JumpPoints.ListChanged += JumpPoints_ListChanged; a_oStarSystem.SystemContactList.ListChanging += SystemContactList_ListChanging; // Set Sceen Size basd on Max Orbit: m_v2SceenSize = new Vector2d(dMaxOrbitDist * 2, dMaxOrbitDist * 2); }
public SystemMap() { m_oViewPortPanel = new Panels.SysMap_ViewPort(); m_oControlsPanel = new Panels.SysMap_Controls(); /// <summary> /// Add time button handlers to ViewPortPanel. /// </summary> m_oViewPortPanel.AdvanceTime5S.Click += new EventHandler(AdvanceTime5S_Click); m_oViewPortPanel.AdvanceTime30S.Click += new EventHandler(AdvanceTime30S_Click); m_oViewPortPanel.AdvanceTime2M.Click += new EventHandler(AdvanceTime2M_Click); m_oViewPortPanel.AdvanceTime5M.Click += new EventHandler(AdvanceTime5M_Click); m_oViewPortPanel.AdvanceTime20M.Click += new EventHandler(AdvanceTime20M_Click); m_oViewPortPanel.AdvanceTime1H.Click += new EventHandler(AdvanceTime1H_Click); m_oViewPortPanel.AdvanceTime3H.Click += new EventHandler(AdvanceTime3H_Click); m_oViewPortPanel.AdvanceTime8H.Click += new EventHandler(AdvanceTime8H_Click); m_oViewPortPanel.AdvanceTime1D.Click += new EventHandler(AdvanceTime1D_Click); m_oViewPortPanel.AdvanceTime5D.Click += new EventHandler(AdvanceTime5D_Click); m_oViewPortPanel.AdvanceTime30D.Click += new EventHandler(AdvanceTime30D_Click); m_oViewPortPanel.StartSim.Click += new EventHandler(StartSim_Click); // setup GL Canvas and insert it into the ViewPort: m_oGLCanvas = new GLCanvas(); m_oGLCanvas.Dock = DockStyle.Fill; m_oViewPortPanel.Controls.Add(m_oGLCanvas); // setup viewmodel: VM = new GLStarSystemViewModel(); // Bind System Selection Combo Box. m_oControlsPanel.SystemSelectionComboBox.Bind(c => c.DataSource, VM, d => d.StarSystems); m_oControlsPanel.SystemSelectionComboBox.Bind(c => c.SelectedItem, VM, d => d.CurrentStarSystem, DataSourceUpdateMode.OnPropertyChanged); m_oControlsPanel.SystemSelectionComboBox.DisplayMember = "Name"; VM.StarSystemChanged += (s, args) => CurrentStarSystem = VM.CurrentStarSystem; m_oCurrnetSystem = VM.CurrentStarSystem; m_oControlsPanel.SystemSelectionComboBox.SelectedIndexChanged += (s, args) => m_oControlsPanel.SystemSelectionComboBox.DataBindings["SelectedItem"].WriteValue(); // register event handlers:\ m_oGLCanvas.KeyDown += new KeyEventHandler(OnKeyDown); m_oGLCanvas.MouseDown += new MouseEventHandler(OnMouseDown); m_oGLCanvas.MouseMove += new MouseEventHandler(OnMouseMove); m_oGLCanvas.MouseUp += new MouseEventHandler(OnMouseUp); m_oGLCanvas.MouseHover += new EventHandler(OnMouseHover); m_oGLCanvas.MouseWheel += new MouseEventHandler(OnMouseWheel); m_oGLCanvas.Click += new EventHandler(m_oGLCanvas_Click); m_oViewPortPanel.SizeChanged += new EventHandler(ViewPort_SizeChanged); m_oControlsPanel.PanUpButton.Click += new EventHandler(PanUpButton_Click); m_oControlsPanel.PanDownButton.Click += new EventHandler(PanDownButton_Click); m_oControlsPanel.PanLeftButton.Click += new EventHandler(PanLeftButton_Click); m_oControlsPanel.PanRightButton.Click += new EventHandler(PanRightButton_Click); m_oControlsPanel.ZoomInButton.Click += new EventHandler(ZoomInButton_Click); m_oControlsPanel.ZoomOutButton.Click += new EventHandler(ZoomOutButton_Click); m_oControlsPanel.ResetViewButton.Click += new EventHandler(ResetViewButton_Click); m_oControlsPanel.CreateMapMarkerButton.Click += new EventHandler(CreateMapMarkerButton_Click); m_oControlsPanel.DeleteMapMarkerButton.Click += new EventHandler(DeleteMapMarkerButton_Click); m_oControlsPanel.SystemSelectionComboBox.SelectedIndexChanged += new EventHandler(SystemSelectComboBox_SelectedIndexChanged); m_oControlsPanel.ShowActiveSensorsCheckBox.CheckedChanged += new EventHandler(ShowActiveSensorsCheckBox_CheckedChanged); m_oControlsPanel.ShowPassiveSensorsCheckBox.CheckedChanged += new EventHandler(ShowPassiveSensorsCheckBox_CheckedChanged); }
/// <summary> /// Constructor for the taskgroup, sets name, faction, planet the TG starts in orbit of. /// </summary> /// <param name="Title">Name</param> /// <param name="FID">Faction</param> /// <param name="StartingBody">body taskgroup will orbit at creation.</param> public TaskGroupTN(string Title, Faction FID, OrbitingEntity StartingBody, StarSystem StartingSystem) { Name = Title; /// <summary> /// create these or else anything that relies on a unique global id will break. /// </summary> Id = Guid.NewGuid(); TaskGroupFaction = FID; IsOrbiting = true; OrbitingBody = StartingBody; (OrbitingBody as SystemBody).TaskGroupsInOrbit.Add(this); SSEntity = StarSystemEntityType.TaskGroup; Position.System = StartingSystem; Position.X = OrbitingBody.Position.X; Position.Y = OrbitingBody.Position.Y; Contact = new SystemContact(TaskGroupFaction, this); Contact.LastPosition.X = Contact.Position.X; Contact.LastPosition.Y = Contact.Position.Y; StartingSystem.SystemContactList.Add(Contact); DrawTravelLine = 3; CurrentSpeed = 1; MaxSpeed = 1; CurrentSpeedX = 0.0; CurrentSpeedY = 0.0; CurrentHeading = 0.0; TimeRequirement = 0; TaskGroupOrders = new BindingList<Order>(); TotalOrderDistance = 0.0; /// <summary> /// Change this for PDCS and starbases. /// </summary> CanOrder = Constants.ShipTN.OrderState.AcceptOrders; /// <summary> /// Ships start in the unordered state, so new orders will have to have GetHeading/speed/other functionality performed. /// </summary> NewOrders = true; Ships = new BindingList<ShipTN>(); ShipOutOfFuel = false; ActiveSensorQue = new BindingList<ActiveSensorTN>(); ActiveSensorCount = new BindingList<int>(); TaskGroupLookUpST = new BindingList<int>(); /// <summary> /// Resolution Max needs to go into global constants, or ship constants I think. /// </summary> for (int loop = 0; loop < Constants.ShipTN.ResolutionMax; loop++) { /// <summary> /// TaskGroupLookUpST will be initialized to zero. /// </summary> TaskGroupLookUpST.Add(0); } TaskGroupLookUpMT = new BindingList<int>(); for (int loop = 0; loop < 15; loop++) { /// <summary> /// TaskGroupLookUpMT will be initialized to zero. /// </summary> TaskGroupLookUpMT.Add(0); } BestThermalCount = 0; BestEMCount = 0; ThermalSortList = new LinkedList<int>(); EMSortList = new LinkedList<int>(); ActiveSortList = new LinkedList<int>(); TotalCargoTonnage = 0; CurrentCargoTonnage = 0; TotalCryoCapacity = 0; CurrentCryoStorage = 0; TaskGroupsOrdered = new BindingList<TaskGroupTN>(); TaskGroupPDL = new PointDefenseList(); IsInShipyard = false; SensorUpdateAck = 0; //add default legal order for targeting TGs. _legalOrders.Add(Constants.ShipTN.OrderType.Follow); _legalOrders.Add(Constants.ShipTN.OrderType.Join); _legalOrders.Add(Constants.ShipTN.OrderType.Absorb); _legalOrders.Add(Constants.ShipTN.OrderType.RefuelTargetFleet); _legalOrders.Add(Constants.ShipTN.OrderType.ResupplyTargetFleet); _legalOrders.Add(Constants.ShipTN.OrderType.ReloadTargetFleet); _legalOrders.Add(Constants.ShipTN.OrderType.LandOnAssignedMothership); _legalOrders.Add(Constants.ShipTN.OrderType.LandOnMotherShipNoAssign); _legalOrders.Add(Constants.ShipTN.OrderType.LandOnMothershipAssign); _legalOrders.Add(Constants.ShipTN.OrderType.TractorSpecifiedShip); _legalOrders.Add(Constants.ShipTN.OrderType.TractorSpecifiedShipyard); }
/// <summary> /// Handles connecting unconnected jump points. /// This function only handles the connection of JumpPoints to new JumpPoints/Systems /// </summary> public void CreateConnection() { int systemIndex = -1; StarSystem connectedSystem = null; if (Constants.GameSettings.JumpPointLocalGroupConnectionChance >= GameState.RNG.Next(101)) { do { // We will connect to an 'existing system' // Note, existing system doesn't necessarily exist. systemIndex = Position.System.SystemIndex + GameState.RNG.Next(-Constants.GameSettings.JumpPointLocalGroupSize / 2, (Constants.GameSettings.JumpPointLocalGroupSize / 2) + 1); if (systemIndex < 0) { // Sorry, we gotta keep you positive. systemIndex = Math.Abs(systemIndex); } } // Prevent linking to self. while (systemIndex == Position.System.SystemIndex); } else { // Generating a 'new system' // Note, new system isn't necessarily non-existant. systemIndex = GameState.Instance.StarSystemCurrentIndex; } if (systemIndex >= GameState.Instance.StarSystemCurrentIndex) { if (systemIndex == GameState.Instance.StarSystemCurrentIndex) { // We're connecting to the next system on the list. // This system will be generated, so increase our current index. // This can happen with either 'existing system' or 'new system' // however, it is intended for 'new system' generation. GameState.Instance.StarSystemCurrentIndex++; } while (systemIndex > GameState.Instance.StarSystems.Count) { // We're connecting to an 'existing system' that doesn't exist. // If systemIndex 15 was selected above, and we've only got 10 systems, fill in the gap with new systems. SystemGen.CreateSystem("Unexplored System S-" + GameState.Instance.StarSystems.Count); // Note, we didn't set our StarSystemCurrentIndex. This is intentional. // When we make another connection, and we RNG a 'new system' connection, we may have just made the 'new system' here. // Since we want 'existing system' to make 2 links once all JP's are explored, we ensure // the 'new system' connection will actually connect to the 'existing system'. } } if (systemIndex == GameState.Instance.StarSystems.Count) { // Generate a new system. connectedSystem = SystemGen.CreateSystem("Unexplored System S-" + GameState.Instance.StarSystems.Count); } else { // Select an existing system. connectedSystem = GameState.Instance.StarSystems[systemIndex]; } // Choose a random jump point in the new system. JumpPoint connectedJP = null; List <JumpPoint> systemJumpPoints = new List <JumpPoint>(); systemJumpPoints.AddRange(connectedSystem.JumpPoints); // Deep copy so we don't ruin the connectedSystem.JumpPoints list. while (systemJumpPoints.Count > 0) { // Select a random jump point. int i = GameState.RNG.Next(systemJumpPoints.Count); if (systemJumpPoints[i].Connect == null) { // If selected JP doesn't have a connection, we use it. connectedJP = systemJumpPoints[i]; break; } // If selected JP has a connection, remove it from the list, and select another. systemJumpPoints.RemoveAt(i); } if (connectedJP == null) { // All JP's are already connected, create a new one. Star parentStar = connectedSystem.Stars[GameState.RNG.Next(connectedSystem.Stars.Count)]; connectedJP = SystemGen.GenerateJumpPoint(connectedSystem); } // Connect us to them. Connect = connectedJP; Name = Name + "(" + Connect.Position.System.Name + ")"; // Connect them to us. Connect.Connect = this; Connect.Name = Connect.Name + "(" + Position.System.Name + ")"; }
/// <summary> /// MessageEntry constructs a specific message with the relevant location, time, and entity(if applicable). /// </summary> /// <param name="Loc">Starsystem message is from.</param> /// <param name="Ref">Starsystementity the message refers to.</param> /// <param name="Time">Game time of message.</param> /// <param name="timeSlice">Time since last increment.</param> /// <param name="text">text of the message.</param> public MessageEntry(MessageType Type, StarSystem Loc, StarSystemEntity Ref, DateTime Time, int timeSlice, string text) { TypeOf = Type; Location = Loc; entity = Ref; TimeOfMessage = Time; TimeSlice = timeSlice; Text = text; #if LOG4NET_ENABLED if (TypeOf == MessageType.Error) { String Entry = String.Format("Faction Message Logging Error: Type:{0} | Time:{1} | Location:{2} - TimeSlice:{3}: Text:{4}\n", TypeOf, TimeOfMessage, Location, TimeSlice, Text); logger.Debug(Entry); } #endif }
/// <summary> /// Adds friendly taskgroups to the system location box /// </summary> private void AddTaskGroupsToList(StarSystem starsystem) { foreach(SystemContact contact in starsystem.SystemContactList) { if (contact.SSEntity == StarSystemEntityType.TaskGroup) { TaskGroupTN TaskGroup = contact.Entity as TaskGroupTN; if (CurrentTaskGroup != TaskGroup && TaskGroup.TaskGroupFaction == CurrentFaction) { //m_oTaskGroupPanel.SystemLocationsListBox.Items.Add(CurrentTaskGroup.Contact.Position.System.SystemContactList[loop].TaskGroup); string keyName = TaskGroup.Name; StarSystemEntity entObj = TaskGroup; SystemListObject valueObj = new SystemListObject(SystemListObject.ListEntityType.TaskGroups, entObj); SystemLocationGuidDict.Add(entObj.Id, keyName); SystemLocationDict.Add(entObj.Id, valueObj); } } } }
/// <summary> /// Adds user generated waypoints to the location list. /// </summary> private void AddWaypointsToList(StarSystem starsystem) { foreach (Waypoint waypoint in starsystem.Waypoints) { if (waypoint.FactionId == CurrentTaskGroup.TaskGroupFaction.FactionID) { string keyName = waypoint.Name; StarSystemEntity entObj = waypoint; SystemListObject valueObj = new SystemListObject(SystemListObject.ListEntityType.Waypoints, entObj); SystemLocationGuidDict.Add(entObj.Id, keyName); SystemLocationDict.Add(entObj.Id, valueObj); } } }
/// <summary> /// TaskGroupEM Detection runs the EM detection routine on TaskGroupToTest from CurrentTaskGroup. This differs from Thermal in that we use the ship EM linked list as well as the faction EM /// Detection list. /// </summary> /// <param name="System">Current System this is taking place in.</param> /// <param name="CurrentTaskGroup">TaskGroup that is performing the sensor sweep.</param> /// <param name="TaskGroupToTest">TaskGroup being tested against.</param> /// <param name="dist">Distance between these two taskgroups.</param> /// <param name="detListIterator">Iterator for where the TaskGroupToTest is in the various detection lists and the system contact list.</param> /// <param name="DetShipList">If a ship is detected it must be put into this list for the detectedContactsList later on.</param> private void TaskGroupEMDetection(StarSystem System, TaskGroupTN CurrentTaskGroup, TaskGroupTN TaskGroupToTest, float dist, int detListIterator) { if (System.FactionDetectionLists[FactionID].EM[detListIterator] != GameState.Instance.CurrentSecond) { int sig = -1; int detection = -1; bool noDetection = false; bool allDetection = false; /// <summary> /// Get the best detection range for EM signatures in loop. /// </summary> int ShipID = TaskGroupToTest.EMSortList.Last(); ShipTN scratch = TaskGroupToTest.Ships[ShipID]; sig = scratch.CurrentEMSignature; /// <summary> /// Check to see if the taskgroup has an em sensor, and that said em sensor is not destroyed. /// otherwise use the default passive detection range. /// </summary> if (CurrentTaskGroup.BestEMCount > 0) { detection = CurrentTaskGroup.BestEM.pSensorDef.GetPassiveDetectionRange(sig); } else { detection = ComponentList.DefaultPassives.GetPassiveDetectionRange(sig); } bool det = LargeDetection(dist, detection); /// <summary> /// Good case, none of the ships are detected. /// </summary> if (det == false) { noDetection = true; } /// <summary> /// Atleast the biggest ship is detected. /// </summary if (noDetection == false) { ShipID = TaskGroupToTest.EMSortList.First(); scratch = TaskGroupToTest.Ships[ShipID]; sig = scratch.CurrentEMSignature; /// <summary> /// once again we must check here to make sure that the taskgroup does have a passive suite, or else use the default one. /// </summary> if (CurrentTaskGroup.BestEMCount > 0) { detection = CurrentTaskGroup.BestEM.pSensorDef.GetPassiveDetectionRange(sig); } else { detection = ComponentList.DefaultPassives.GetPassiveDetectionRange(sig); } det = LargeDetection(dist, detection); /// <summary> /// Best case, everything is detected. /// </summary> if (det == true) { allDetection = true; for (int loop3 = 0; loop3 < TaskGroupToTest.Ships.Count; loop3++) { TaskGroupToTest.Ships[loop3].EMDetection[FactionID] = GameState.Instance.CurrentSecond; if (DetShipList.Contains(TaskGroupToTest.Ships[loop3]) == false) { DetShipList.Add(TaskGroupToTest.Ships[loop3]); } } System.FactionDetectionLists[FactionID].EM[detListIterator] = GameState.Instance.CurrentSecond; } else if (noDetection == false && allDetection == false) { /// <summary> /// Worst case. some are detected, some aren't. /// </summary> for (int loop3 = 0; loop3 < TaskGroupToTest.Ships.Count; loop3++) { LinkedListNode<int> node = TaskGroupToTest.EMSortList.Last; bool done = false; while (!done) { scratch = TaskGroupToTest.Ships[node.Value]; if (scratch.EMDetection[FactionID] != GameState.Instance.CurrentSecond) { sig = scratch.CurrentEMSignature; /// <summary> /// here is where EM detection differs from Thermal detection: /// If a ship has a signature of 0 by this point(and we didn't already hit noDetection above, /// it means that one ship is emitting a signature, but that no other ships are. /// Mark the group as totally detected, but not the ships, this serves to tell me that the ships are undetectable /// in this case. /// </summary> if (sig == 0) { /// <summary> /// The last signature we looked at was the ship emitting an EM sig, and this one is not. /// Mark the entire group as "spotted" because no other detection will occur. /// </summary> if (TaskGroupToTest.Ships[node.Next.Value].EMDetection[FactionID] == GameState.Instance.CurrentSecond) { System.FactionDetectionLists[FactionID].EM[detListIterator] = GameState.Instance.CurrentSecond; } break; } if (CurrentTaskGroup.BestEMCount > 0) { detection = CurrentTaskGroup.BestEM.pSensorDef.GetPassiveDetectionRange(sig); } else { detection = ComponentList.DefaultPassives.GetPassiveDetectionRange(sig); } det = LargeDetection(dist, detection); if (det == true) { scratch.EMDetection[FactionID] = GameState.Instance.CurrentSecond; if (DetShipList.Contains(scratch) == false) { DetShipList.Add(scratch); } } else { done = true; break; } } if (node == TaskGroupToTest.EMSortList.First) { /// <summary> /// This should not happen. /// </summary> String ErrorMessage = string.Format("Partial EM detect for TGs looped through every ship. {0} {1} {2} {3}", dist, detection, noDetection, allDetection); MessageEntry NMsg = new MessageEntry(MessageEntry.MessageType.Error, CurrentTaskGroup.Contact.Position.System, CurrentTaskGroup.Contact, GameState.Instance.GameDateTime, GameState.Instance.LastTimestep, ErrorMessage); MessageLog.Add(NMsg); done = true; break; } node = node.Previous; } } } /// <summary> /// End else /// </summary> } } }
/// <summary> /// Taskgroup active detection will handle the active detection sensor sweeps, Resolution represents the biggest difference for TG Active detection vs passive detection. /// There isn't simply a best active sensor, and the correct one has to be searched for. luckily that work is already done by the taskgroup itself. /// </summary> /// <param name="System">Current System.</param> /// <param name="CurrentTaskGroup">Scanning Taskgroup</param> /// <param name="TaskGroupToTest">Taskgroup to test if detected.</param> /// <param name="dist">Distance between the two taskgroups</param> /// <param name="detListIterator">location of the test taskgroup in the detection lists</param> private void TaskGroupActiveDetection(StarSystem System, TaskGroupTN CurrentTaskGroup, TaskGroupTN TaskGroupToTest, float dist, int detListIterator) { if (System.FactionDetectionLists[FactionID].Active[detListIterator] != GameState.Instance.CurrentSecond && CurrentTaskGroup.ActiveSensorQue.Count > 0) { int sig = -1; int detection = -1; bool noDetection = false; bool allDetection = false; /// <summary> /// Get the best detection range for thermal signatures in loop. /// </summary> int ShipID = TaskGroupToTest.ActiveSortList.Last(); ShipTN scratch = TaskGroupToTest.Ships[ShipID]; sig = scratch.TotalCrossSection - 1; if (sig > Constants.ShipTN.ResolutionMax - 1) sig = Constants.ShipTN.ResolutionMax - 1; detection = CurrentTaskGroup.ActiveSensorQue[CurrentTaskGroup.TaskGroupLookUpST[sig]].aSensorDef.GetActiveDetectionRange(sig, -1); bool det = LargeDetection(dist, detection); /// <summary> /// Good case, none of the ships are detected. /// </summary> if (det == false) { noDetection = true; } /// <summary> /// Atleast the biggest ship is detected. /// </summary if (noDetection == false) { ShipID = TaskGroupToTest.ActiveSortList.First(); scratch = TaskGroupToTest.Ships[ShipID]; sig = scratch.TotalCrossSection - 1; if (sig > Constants.ShipTN.ResolutionMax - 1) sig = Constants.ShipTN.ResolutionMax - 1; detection = CurrentTaskGroup.ActiveSensorQue[CurrentTaskGroup.TaskGroupLookUpST[sig]].aSensorDef.GetActiveDetectionRange(sig, -1); det = LargeDetection(dist, detection); /// <summary> /// Best case, everything is detected. /// </summary> if (det == true) { allDetection = true; for (int loop3 = 0; loop3 < TaskGroupToTest.Ships.Count; loop3++) { TaskGroupToTest.Ships[loop3].ActiveDetection[FactionID] = GameState.Instance.CurrentSecond; if (DetShipList.Contains(TaskGroupToTest.Ships[loop3]) == false) { DetShipList.Add(TaskGroupToTest.Ships[loop3]); } } /// <summary> /// FactionSystemDetection entry. I hope to deprecate this at some point. /// Be sure to erase the factionDetectionSystem entry first, to track down everywhere this overbloated thing is. /// update, not happening. FactionDetectionList is too important. /// </summary> System.FactionDetectionLists[FactionID].Active[detListIterator] = GameState.Instance.CurrentSecond; } else if (noDetection == false && allDetection == false) { /// <summary> /// Worst case. some are detected, some aren't. /// </summary> for (int loop3 = 0; loop3 < TaskGroupToTest.Ships.Count; loop3++) { LinkedListNode<int> node = TaskGroupToTest.ActiveSortList.Last; bool done = false; while (!done) { scratch = TaskGroupToTest.Ships[node.Value]; if (scratch.ActiveDetection[FactionID] != GameState.Instance.CurrentSecond) { sig = scratch.TotalCrossSection - 1; if (sig > Constants.ShipTN.ResolutionMax - 1) sig = Constants.ShipTN.ResolutionMax - 1; detection = CurrentTaskGroup.ActiveSensorQue[CurrentTaskGroup.TaskGroupLookUpST[sig]].aSensorDef.GetActiveDetectionRange(sig, -1); det = LargeDetection(dist, detection); if (det == true) { scratch.ActiveDetection[FactionID] = GameState.Instance.CurrentSecond; if (DetShipList.Contains(scratch) == false) { DetShipList.Add(scratch); } } else { done = true; break; } } if (node == TaskGroupToTest.ActiveSortList.First) { /// <summary> /// This should not happen. /// </summary> String ErrorMessage = string.Format("Partial Active detect for TGs looped through every ship. {0} {1} {2} {3}", dist, detection, noDetection, allDetection); MessageEntry NMsg = new MessageEntry(MessageEntry.MessageType.Error, CurrentTaskGroup.Contact.Position.System, CurrentTaskGroup.Contact, GameState.Instance.GameDateTime, GameState.Instance.LastTimestep, ErrorMessage); MessageLog.Add(NMsg); done = true; break; } node = node.Previous; } } } /// <summary> /// End else /// </summary> } } }
/// <summary> /// Area defensive fire will sweep through a faction's list of BFCs and MFCs to fire at detected ordnance in range. /// </summary> /// <param name="Fact">Faction to search for fire controls of</param> /// <param name="RNG">"global" rng from further up.</param> public static void AreaDefensiveFire(Faction Fact, Random RNG) { /// <summary> /// No point defense set FCs, just return. /// </summary> if (Fact.PointDefense.Count == 0) { return; } /// <summary> /// Look through each starsystem with a point defense list. /// </summary> foreach (KeyValuePair <StarSystem, PointDefenseList> pair in Fact.PointDefense) { StarSystem CurrentSystem = pair.Key; /// <summary> /// No detected contacts in this system. /// </summary> if (Fact.DetectedContactLists.ContainsKey(CurrentSystem) == false) { break; } /// <summary> /// No missile contacts in this system. /// </summary> if (Fact.DetectedContactLists[CurrentSystem].DetectedMissileContacts.Count == 0) { break; } /// <summary> /// now loop through each FC in the current starsystem. /// </summary> foreach (KeyValuePair <ComponentTN, ShipTN> pair2 in pair.Value.PointDefenseFC) { /// <summary> /// The firing ship. /// </summary> ShipTN Ship = pair2.Value; /// <summary> /// Ship jump sickness will prevent point defense from operating. /// </summary> if (Ship.IsJumpSick()) { continue; } /// <summary> /// BFC set to Area defense mode /// </summary> if (pair.Value.PointDefenseType[pair2.Key] == false && pair2.Value.ShipBFC[pair2.Key.componentIndex].pDState == PointDefenseState.AreaDefense) { BeamFireControlTN ShipBeamFC = pair2.Value.ShipBFC[pair2.Key.componentIndex]; /// <summary> /// loop through every missile contact. will have to do distance checks here. /// </summary> foreach (KeyValuePair <OrdnanceGroupTN, FactionContact> MisPair in Fact.DetectedContactLists[CurrentSystem].DetectedMissileContacts) { OrdnanceGroupTN DetectedMissileGroup = MisPair.Key; /// <summary> /// This missile group is already destroyed and will be cleaned up by sim later. /// </summary> if (DetectedMissileGroup.missilesDestroyed == DetectedMissileGroup.missiles.Count) { break; } /// <summary> /// Do a distance check on pair.Value vs the missile itself. if that checks out to be less than 10k km(or equal to zero), then /// check to see if the FC can shoot down said missile. This should never be run before a sensor sweep /// </summary> float dist; DetectedMissileGroup.contact.DistTable.GetDistance(Ship.ShipsTaskGroup.Contact, out dist); /// <summary> /// Only bother with checks here that are within the maximum beam distance. /// </summary> if (dist <= Constants.Units.BEAM_AU_MAX) { /// <summary> /// Value is in units of 10k km /// </summary> float rangeAreaDefenseKm; /// <summary> /// The user put in an absurdly large value. for convienence, just do this to get maximum range. /// </summary> if (ShipBeamFC.pDRange > (float)Constants.Units.TEN_KM_MAX) { /// <summary> /// Max possible beam range in KM. /// </summary> rangeAreaDefenseKm = (float)Constants.Units.BEAM_KM_MAX; } else { #warning magic number related to 10k rangeAreaDefenseKm = ShipBeamFC.pDRange * 10000.0f; } float distKM = dist * (float)Constants.Units.KM_PER_AU; /// <summary> /// Additional paranoia check of range, I need to fix Area defense PD range values to ship bfc range in any event, that hasn't been done yet. /// </summary> #warning magic number for total bfc range. float totalRange = ShipBeamFC.beamFireControlDef.range * 2.0f; float range = Math.Min(totalRange, rangeAreaDefenseKm); /// <summary> /// the BFC is set for range defense and is in range of this missile. /// </summary> if (distKM <= range) { #warning magic number related to 10k km increments. /// <summary> /// Increment is a 10k km unit, so distance must be divided by 10000 to yield the appropriate number. /// </summary> int increment = (int)Math.Floor((float)distKM / 10000.0f); bool Intercept = false; int MissilesToDestroy = 0; /// <summary> /// Can't foreach this one, as I do not want every missile, only the ones not destroyed. /// </summary> for (int MissileIterator = DetectedMissileGroup.missilesDestroyed; MissileIterator < DetectedMissileGroup.missiles.Count; MissileIterator++) { bool WF = false; Intercept = ShipBeamFC.InterceptTarget(RNG, increment, DetectedMissileGroup.missiles[MissileIterator], Ship.ShipsFaction, Ship.ShipsTaskGroup.Contact, Ship, out WF); /// <summary> /// Add this ship to the weapon recharge list since it has fired. This is done here in Sim, or for FDF_Self in Ship.cs /// </summary> if (WF == true) { if (Fact.RechargeList.ContainsKey(Ship) == true) { /// <summary> /// If our recharge value does not have Recharge beams in it(bitflag 2 for now), then add it. /// </summary> if ((Fact.RechargeList[Ship] & (int)Faction.RechargeStatus.Weapons) != (int)Faction.RechargeStatus.Weapons) { Fact.RechargeList[Ship] = (Fact.RechargeList[Ship] + (int)Faction.RechargeStatus.Weapons); } } else { Fact.RechargeList.Add(Ship, (int)Faction.RechargeStatus.Weapons); } } if (Intercept == true) { /// <summary> /// Destroy the missile, check if the ordnance group should be removed, if its gone also remove it from the detected contacts list and break that loop. /// </summary> MissilesToDestroy++; } else if (Intercept == false) { /// <summary> /// This FC can't intercept any more missiles, advance to the next one. /// </summary> break; } } /// <summary> /// Set the missiles destroyed count as appropriate. /// </summary> DetectedMissileGroup.missilesDestroyed = DetectedMissileGroup.missilesDestroyed + MissilesToDestroy; if (DetectedMissileGroup.missilesDestroyed != 0 && Fact.MissileRemoveList.Contains(DetectedMissileGroup) == false) { /// <summary> /// Tell sim to remove missiles from this group, or remove it entirely. /// </summary> Fact.MissileRemoveList.Add(DetectedMissileGroup); } if (Intercept == false) { /// <summary> /// This condition means advance to the next FC. /// </summary> break; } } } } } /// <summary> /// MFC set to any pd mode that can be applied: 1v2 up to 5v1. /// </summary> else if (pair.Value.PointDefenseType[pair2.Key] == true && pair2.Value.ShipMFC[pair2.Key.componentIndex].pDState >= PointDefenseState.AMM1v2 && pair2.Value.ShipMFC[pair2.Key.componentIndex].pDState <= PointDefenseState.AMM5v1) { MissileFireControlTN ShipMissileFC = pair2.Value.ShipMFC[pair2.Key.componentIndex]; int MissilesLaunched = 0; int MissilesToLaunch = 0; foreach (KeyValuePair <OrdnanceGroupTN, FactionContact> MisPair in Fact.DetectedContactLists[CurrentSystem].DetectedMissileContacts) { OrdnanceGroupTN DetectedMissileGroup = MisPair.Key; /// <summary> /// Advance to next missile group. /// </summary> if (DetectedMissileGroup.missilesDestroyed == DetectedMissileGroup.missiles.Count) { break; } /// <summary> /// Do a distance check on pair.Value vs the missile itself. if that checks out to be less than 10k km(or equal to zero), then /// check to see if the FC can shoot down said missile. This should never be run before a sensor sweep /// </summary> float dist; DetectedMissileGroup.contact.DistTable.GetDistance(Ship.ShipsTaskGroup.Contact, out dist); float MFCEngageDistKm = ShipMissileFC.mFCSensorDef.maxRange; float rangeAreaDefenseKm = ShipMissileFC.pDRange; /// <summary> /// Range is in 10K units so it has to be adjusted to AU for later down. /// </summary> #warning magic 10k number here float range = (Math.Min(MFCEngageDistKm, rangeAreaDefenseKm) / (float)Constants.Units.KM_PER_AU); range = range * 10000.0f; int MSize = 0; int AltMSize = 0; #warning the +6 is another magic number. if ((int)Math.Ceiling(DetectedMissileGroup.missiles[0].missileDef.size) <= (Constants.OrdnanceTN.MissileResolutionMinimum + 6)) { MSize = Constants.OrdnanceTN.MissileResolutionMinimum; AltMSize = 0; } else if ((int)Math.Ceiling(DetectedMissileGroup.missiles[0].missileDef.size) <= (Constants.OrdnanceTN.MissileResolutionMaximum + 6)) { MSize = (int)Math.Ceiling(DetectedMissileGroup.missiles[0].missileDef.size); AltMSize = 0; } else if ((int)Math.Ceiling(DetectedMissileGroup.missiles[0].missileDef.size) > (Constants.OrdnanceTN.MissileResolutionMaximum + 6)) { MSize = -1; AltMSize = (int)Math.Ceiling(Math.Ceiling(DetectedMissileGroup.missiles[0].missileDef.size) / (Constants.OrdnanceTN.MissileResolutionMaximum + 6)); } int MFCRange = ShipMissileFC.mFCSensorDef.GetActiveDetectionRange(AltMSize, MSize); bool CanDetect = Fact.LargeDetection(dist, MFCRange); /// <summary> /// Can this MFC fire on the targetted missile? /// </summary> if (CanDetect == true && dist <= range) { /// <summary> /// Do AMM defense here. Check to see how many amms are targeted on this missile, if less than defense setting fire more. /// How do I handle 1v2 mode? rounding obviously. if more than 1 missile in group send half, send atleast 1 for 1, and round for odd missile amounts. /// missiles won't be destroyed here, as they were in beam fire mode, this will just launch amms at missile groups. /// </summary> /// <summary> /// Get total missiles currently targetted on this group. Keeping track of a total missiles incoming variable would mean handling a lot of interactions where /// missiles can be destroyed, run out of fuel, etc. so I'll just loop through this for now. /// </summary> #warning this missile count can be optimized, but it would be difficult to do so. int TotalCount = 0; foreach (OrdnanceGroupTN OrdGroupTargetting in DetectedMissileGroup.ordGroupsTargetting) { TotalCount = TotalCount + OrdGroupTargetting.missiles.Count; } float Value = TotalCount / DetectedMissileGroup.missiles.Count; switch (ShipMissileFC.pDState) { #warning more magic numbers in how point defense states are handled. case PointDefenseState.AMM1v2: if (Value < 0.5f) { int Max = (int)Math.Ceiling((float)DetectedMissileGroup.missiles.Count / 2.0f); MissilesToLaunch = Max - TotalCount; } break; case PointDefenseState.AMM1v1: if (Value < 1.0f) { int Max = DetectedMissileGroup.missiles.Count; MissilesToLaunch = Max - TotalCount; } break; case PointDefenseState.AMM2v1: if (Value < 2.0f) { int Max = DetectedMissileGroup.missiles.Count * 2; MissilesToLaunch = Max - TotalCount; } break; case PointDefenseState.AMM3v1: if (Value < 3.0f) { int Max = DetectedMissileGroup.missiles.Count * 3; MissilesToLaunch = Max - TotalCount; } break; case PointDefenseState.AMM4v1: if (Value < 4.0f) { int Max = DetectedMissileGroup.missiles.Count * 4; MissilesToLaunch = Max - TotalCount; } break; case PointDefenseState.AMM5v1: if (Value < 5.0f) { int Max = DetectedMissileGroup.missiles.Count * 5; MissilesToLaunch = Max - TotalCount; } break; } if (MissilesToLaunch != 0) { /// <summary> /// launch up to MissilesToLaunch amms in a new ord group at the target. /// <summary> MissilesLaunched = ShipMissileFC.FireWeaponsPD(Ship.ShipsTaskGroup, Ship, DetectedMissileGroup, MissilesToLaunch); /// <summary> /// Add this ship to the weapon recharge list since it has fired. This is done here in Sim, or for FDF_Self in Ship.cs /// </summary> if (MissilesLaunched != 0) { if (Fact.RechargeList.ContainsKey(Ship) == true) { /// <summary> /// If our recharge value does not have Recharge beams in it(bitflag 2 for now), then add it. /// </summary> if ((Fact.RechargeList[Ship] & (int)Faction.RechargeStatus.Weapons) != (int)Faction.RechargeStatus.Weapons) { Fact.RechargeList[Ship] = (Fact.RechargeList[Ship] + (int)Faction.RechargeStatus.Weapons); } } else { Fact.RechargeList.Add(Ship, (int)Faction.RechargeStatus.Weapons); } } /// <summary> /// This FC can no longer fire at ordnance groups in range. /// </summary> if (MissilesLaunched != MissilesToLaunch) { break; } } } /// <summary> /// advance to the next FC. /// </summary> if (MissilesLaunched != MissilesToLaunch && MissilesToLaunch != 0) { break; } } } } } }
/// <summary> /// Adds a new taskgroup to the taskgroups list at location StartBody in System StartSystem. /// </summary> /// <param name="Title">Name.</param> /// <param name="StartBody">Body with population that built the ship that will be put into the TG.</param> /// <param name="StartSystem">System in which the TG starts in.</param> public void AddNewTaskGroup(String Title, OrbitingEntity StartBody, StarSystem StartSystem) { TaskGroupTN TG = new TaskGroupTN(Title, this, StartBody, StartSystem); TaskGroups.Add(TG); }
/// <summary> /// Adds a list of contacts to the faction. /// </summary> /// <param name="system">Starsystem for the contacts.</param> public void AddNewContactList(StarSystem system) { if (SystemContacts.ContainsKey(system) == false) { FactionSystemDetection NewContact = new FactionSystemDetection(this, system); system.FactionDetectionLists.Add(NewContact); SystemContacts.Add(system, NewContact); } }
/// <summary> /// Add every planet in the system that this TG is in to the list. /// Eventually jump orders will modify this. to be the system at the end of the order stack. /// </summary> private void AddPlanetsToList(StarSystem starsystem) { foreach (Star star in starsystem.Stars) { foreach (SystemBody planet in star.Planets) { int PopCount = 0; string keyName = "N/A"; foreach(Population CurrentPopulation in planet.Populations) { if (CurrentPopulation.Faction == CurrentFaction) { keyName = string.Format("{0} - {1}",CurrentPopulation.Name, CurrentPopulation.Species.Name); if(CurrentFaction.Capitol == CurrentPopulation) keyName = string.Format("{0}(Capitol)", keyName); keyName = string.Format("{0}: {1:n2}m", keyName, CurrentPopulation.CivilianPopulation); StarSystemEntity entObj = CurrentPopulation; SystemListObject.ListEntityType entType = SystemListObject.ListEntityType.Colonies; SystemListObject valueObj = new SystemListObject(entType, entObj); SystemLocationGuidDict.Add(entObj.Id, keyName); SystemLocationDict.Add(entObj.Id, valueObj); PopCount++; } } if (PopCount == 0) { //m_oTaskGroupPanel.SystemLocationsListBox.Items.Add(CurrentTaskGroup.Contact.Position.System.Stars[loop].Planets[loop2]); keyName = planet.Name;//CurrentTaskGroup.Contact.Position.System.Stars[loop].Planets[loop2].Name; StarSystemEntity entObj = planet;//CurrentTaskGroup.Contact.Position.System.Stars[loop].Planets[loop2]; SystemListObject.ListEntityType entType = SystemListObject.ListEntityType.Planets; SystemListObject valueObj = new SystemListObject(entType, entObj); SystemLocationGuidDict.Add(entObj.Id, keyName); SystemLocationDict.Add(entObj.Id, valueObj); } } } }
public void OrdnanceTest() { /// <summary> /// Need to hook missiles into the distance table calculations, as well as sensor model. /// </summary> /// <summary> ///The Damage table MUST be initialized. /// </summary> DamageValuesTN.init(); /// <summary> /// Factions ARE necessary. /// </summary> Faction PlayerFaction1 = new Faction(0); Faction PlayerFaction2 = new Faction(1); /// <summary> /// No StarSystem no contacts! /// </summary> StarSystem System1 = new StarSystem("This is not Sol", 0); System1.Populations = new BindingList<Population>(); Star S1 = new Star(); System1.Stars.Add(S1); PlayerFaction1.AddNewContactList(System1); PlayerFaction2.AddNewContactList(System1); /// <summary> /// No global RNG, no Damage or tohit. /// </summary> Random RNG = new Random(); /// <summary> /// Planets and populations are needed for house keeping. /// </summary> SystemBody pl1 = new SystemBody(System1.Stars[0], SystemBody.PlanetType.Terrestrial); SystemBody pl2 = new SystemBody(System1.Stars[0], SystemBody.PlanetType.Terrestrial); pl1.Position.System = System1; pl2.Position.System = System1; System1.Stars[0].Planets.Add(pl1); System1.Stars[0].Planets.Add(pl2); Population P1 = new Population(System1.Stars[0].Planets[0], PlayerFaction1,0); Population P2 = new Population(System1.Stars[0].Planets[1], PlayerFaction2,0); System1.Stars[0].Planets[0].Position.X = 1.0; System1.Stars[0].Planets[0].Position.Y = 1.0; System1.Stars[0].Planets[1].Position.X = 1.04; System1.Stars[0].Planets[1].Position.Y = 1.04; PlayerFaction1.AddNewShipDesign("Blucher"); PlayerFaction2.AddNewShipDesign("Tribal"); MissileEngineDefTN TestMissileEngine = new MissileEngineDefTN("Testbed", 5.0f, 4.0f, 1.0f, 1.0f); OrdnanceSeriesTN Series = new OrdnanceSeriesTN("BLANK STANDIN"); OrdnanceDefTN TestMissile = new OrdnanceDefTN("Test Missile", Series, 1.0f, 0, 1.0f, 1.0f, 0, 0.0f, 0, 0.0f, 0, 0.0f, 0, 0.0f, 0, 1, 0, 0.0f, 0.0f, 0, false, 0, false, 0, TestMissileEngine, 1); ActiveSensorDefTN Spotter = new ActiveSensorDefTN("Spotter", 6.0f, 12, 6, 19, false, 1.0f, 0); ActiveSensorDefTN FControl = new ActiveSensorDefTN("FCtrl", 6.0f, 12, 6, 19, true, 1.0f, 0); PlayerFaction1.ShipDesigns[0].AddEngine(PlayerFaction1.ComponentList.Engines[0], 1); PlayerFaction1.ShipDesigns[0].AddCrewQuarters(PlayerFaction1.ComponentList.CrewQuarters[0], 2); PlayerFaction1.ShipDesigns[0].AddFuelStorage(PlayerFaction1.ComponentList.FuelStorage[0], 2); PlayerFaction1.ShipDesigns[0].AddEngineeringSpaces(PlayerFaction1.ComponentList.EngineeringSpaces[0], 2); PlayerFaction1.ShipDesigns[0].AddOtherComponent(PlayerFaction1.ComponentList.OtherComponents[0], 1); PlayerFaction1.ShipDesigns[0].AddMagazine(PlayerFaction1.ComponentList.MagazineDef[0], 1); PlayerFaction1.ShipDesigns[0].AddLauncher(PlayerFaction1.ComponentList.MLauncherDef[0], 1); PlayerFaction1.ShipDesigns[0].AddMFC(FControl, 1); PlayerFaction1.ShipDesigns[0].AddActiveSensor(Spotter, 1); PlayerFaction2.ShipDesigns[0].AddEngine(PlayerFaction1.ComponentList.Engines[0], 1); PlayerFaction2.ShipDesigns[0].AddCrewQuarters(PlayerFaction1.ComponentList.CrewQuarters[0], 2); PlayerFaction2.ShipDesigns[0].AddFuelStorage(PlayerFaction1.ComponentList.FuelStorage[0], 2); PlayerFaction2.ShipDesigns[0].AddEngineeringSpaces(PlayerFaction1.ComponentList.EngineeringSpaces[0], 2); PlayerFaction2.ShipDesigns[0].AddOtherComponent(PlayerFaction1.ComponentList.OtherComponents[0], 1); PlayerFaction2.ShipDesigns[0].NewArmor("Duranium", 5, 4); PlayerFaction1.ShipDesigns[0].SetPreferredOrdnance(TestMissile, 3); PlayerFaction1.AddNewTaskGroup("P1 TG 01", System1.Stars[0].Planets[0], System1); PlayerFaction2.AddNewTaskGroup("P2 TG 01", System1.Stars[0].Planets[1], System1); PlayerFaction1.TaskGroups[0].AddShip(PlayerFaction1.ShipDesigns[0], "Test Ship 1"); PlayerFaction2.TaskGroups[0].AddShip(PlayerFaction2.ShipDesigns[0], "Test Ship 2"); PlayerFaction1.TaskGroups[0].Ships[0].Refuel(200000.0f); PlayerFaction2.TaskGroups[0].Ships[0].Refuel(200000.0f); System1.Stars[0].Planets[0].Populations[0].LoadMissileToStockpile(TestMissile, 4); Order Load = new Order(Constants.ShipTN.OrderType.LoadOrdnanceFromColony, -1, -1, 0, System1.Stars[0].Planets[0].Populations[0]); PlayerFaction1.TaskGroups[0].IssueOrder(Load); while (PlayerFaction1.TaskGroups[0].TaskGroupOrders.Count > 0) { PlayerFaction1.TaskGroups[0].FollowOrders(Constants.TimeInSeconds.TwentyMinutes); } /// <summary> /// Magazine loading isn't handled anywhere. /// </summary> PlayerFaction1.TaskGroups[0].Ships[0].ShipMLaunchers[0].loadedOrdnance = TestMissile; PlayerFaction1.TaskGroups[0].Ships[0].ShipMLaunchers[0].AssignMFC(PlayerFaction1.TaskGroups[0].Ships[0].ShipMFC[0]); PlayerFaction1.TaskGroups[0].Ships[0].ShipMFC[0].assignLaunchTube(PlayerFaction1.TaskGroups[0].Ships[0].ShipMLaunchers[0]); PlayerFaction1.TaskGroups[0].Ships[0].ShipMFC[0].assignTarget(PlayerFaction2.TaskGroups[0].Ships[0]); PlayerFaction1.TaskGroups[0].Ships[0].ShipMFC[0].openFire = true; PlayerFaction1.TaskGroups[0].SetActiveSensor(0, 0, true); GameState.Instance.CurrentSecond += 10; GameState.Instance.LastTimestep = 10; PlayerFaction1.SensorSweep(); bool ret = PlayerFaction1.TaskGroups[0].Ships[0].ShipFireWeapons(RNG); Console.WriteLine("Did we fire: {0} Detected Contacts:{1}", ret, PlayerFaction1.DetectedContactLists.Count); bool done = false; while (!done) { Console.WriteLine("TimeStep:{0} {1} Detected Contacts:{2}", GameState.Instance.CurrentSecond, GameState.Instance.LastTimestep, PlayerFaction1.DetectedContactLists.Count); PlayerFaction1.SensorSweep(); PlayerFaction1.MissileGroups[0].ProcessOrder((uint)GameState.Instance.LastTimestep, RNG); Console.WriteLine("{0} {1} {2} {3} {4} {5} {6} {7}", PlayerFaction1.MissileGroups[0].currentHeading, PlayerFaction1.MissileGroups[0].currentSpeedX, PlayerFaction1.MissileGroups[0].currentSpeedY, PlayerFaction1.MissileGroups[0].timeReq, PlayerFaction1.MissileGroups[0].dx, PlayerFaction1.MissileGroups[0].dy, PlayerFaction1.MissileGroups[0].missiles.Count, PlayerFaction1.MissileGroups[0].missilesDestroyed); GameState.Instance.CurrentSecond += 5; GameState.Instance.LastTimestep = 5; if (PlayerFaction1.MissileGroups[0].missiles.Count == PlayerFaction1.MissileGroups[0].missilesDestroyed) { PlayerFaction1.MissileGroups.Clear(); done = true; } } Console.WriteLine("Armor:"); for (int loop = 0; loop < PlayerFaction2.TaskGroups[0].Ships[0].ShipArmor.armorColumns.Count; loop++) { Console.WriteLine("{0} ", PlayerFaction2.TaskGroups[0].Ships[0].ShipArmor.armorColumns[loop]); } }
/// <summary> /// Add jump points to the available locations list. /// </summary> /// <param name="starsystem"></param> #warning check to see if jump point is detected eventually when grav survey is implemented private void AddJumpPointsToList(StarSystem starsystem) { foreach (JumpPoint jp in starsystem.JumpPoints) { StarSystemEntity entObj = jp; SystemListObject.ListEntityType entType = SystemListObject.ListEntityType.JumpPoint; SystemListObject valueObj = new SystemListObject(entType, entObj); SystemLocationGuidDict.Add(entObj.Id, jp.Name); SystemLocationDict.Add(entObj.Id, valueObj); } }
public GLStarSystemViewModel() { CurrentStarSystem = GameState.Instance.StarSystems.FirstOrDefault(); StarSystems = GameState.Instance.StarSystems; }
/// <summary> /// Creates a faction contact list for the specified system. /// </summary> /// <param name="system">System indicated.</param> public FactionSystemDetection(Faction Fact, StarSystem system) { Faction = Fact; System = system; Thermal = new BindingList<int>(); EM = new BindingList<int>(); Active = new BindingList<int>(); Thermal.RaiseListChangedEvents = false; EM.RaiseListChangedEvents = false; Active.RaiseListChangedEvents = false; for (int loop = 0; loop < system.SystemContactList.Count; loop++) { Thermal.Add(0); EM.Add(0); Active.Add(0); } Thermal.RaiseListChangedEvents = true; EM.RaiseListChangedEvents = true; Active.RaiseListChangedEvents = true; Thermal.ResetBindings(); EM.ResetBindings(); Active.ResetBindings(); }