private static SampleShip HookUpShip(SampleShip ship) { ship.Cooler.ConnectedSystems = ship.Systems; ship.Engine.ConnectedSystems = ship.Systems; float avalableCoolant = ship.Cooler.UnallocatedCoolant(); foreach (ShipSystem system in ship.Systems) { system.SetDesiredPower(system.MinimumPower); ship.Cooler.SetSystemCoolant(system, avalableCoolant / ship.Systems.Count); } return ship; }
public static SampleShip Setup(DirectoryInfo dirToCheck) { FileInfo file = null; if (dirToCheck.Exists) { file = new FileInfo(Path.Combine(dirToCheck.FullName, ShipXMLFile)); if (file.Exists) { try { XmlSerializer xml = new XmlSerializer(typeof(SampleShip)); FileStream fs = file.OpenRead(); SampleShip s = xml.Deserialize(fs) as SampleShip; fs.Close(); if (s != null) return HookUpShip(s); } catch(SystemException /*e*/) { } } } SampleShip ship = new SampleShip(); ship.Systems.Clear(); ship.Systems.Add(new ShipSystem("Thrusters")); ship.Systems.Add(new ShipSystem("LifeSupport",true,25)); ship.Systems.Add(new ShipSystem("Sensors")); ship.Systems.Add(new ShipSystem("Missiles")); ShipSystem fSheilds = new ShipSystem("Forward Shields"); fSheilds.MaxCoolantFlow = 200; fSheilds.NominalPower = 200; fSheilds.MaxPower = 400; fSheilds.ActivationHeat = 100; fSheilds.NominalTemp = 200; ship.Systems.Add(fSheilds); ShipSystem rSheilds = new ShipSystem("Rear Shields"); rSheilds.MaxCoolantFlow = 200; rSheilds.NominalPower = 200; rSheilds.MaxPower = 400; rSheilds.ActivationHeat = 100; rSheilds.NominalTemp = 200; ship.Systems.Add(rSheilds); ShipSystem ftl = new ShipSystem("FTL"); ftl.MaxCoolantFlow = 300; ftl.NominalPower = 1000; ftl.MaxPower = 5000; ftl.HeatDamageFactor = 0.01f; ftl.NominalTemp = 400; ftl.HeatGeneratedPerSecondPerPower = 0.05f; ship.Systems.Add(ftl); ShipSystem beams = new ShipSystem("Beams"); beams.MaxCoolantFlow = 200; beams.NominalPower = 300; beams.MaxPower = 1000; beams.ActivationHeat = 100; beams.NominalTemp = 200; ship.Systems.Add(beams); ship.Cooler.MaxCoolant = 200; ship.Cooler.TotalCoolant = 100; ship.Cooler.AddReservoir(new CoolantSystem.Reservoir(100)); ship.Cooler.AddReservoir(new CoolantSystem.Reservoir(100)); if (dirToCheck.Exists) ship.Save(file); return HookUpShip(ship); }
private void Form1_Load(object sender, EventArgs e) { Ship = SampleShip.Setup(new DirectoryInfo(Path.GetDirectoryName(Application.ExecutablePath))); foreach (ShipSystem system in Ship.Systems) { ShipSystemInspector inspector = new ShipSystemInspector(system); inspector.SetCoolant += inspector_SetCoolant; inspector.SetPower += inspector_SetPower; inspector.Activate += inspector_Activate; ShipSystems.Controls.Add(inspector); } for (int i = 0; i < Ship.Cooler.Reservoirs.Count; i++) ReservoirsContainer.Controls.Add(new ResevoirInspector(Ship.Cooler, i)); CoolantBar.Maximum = (int)Ship.Cooler.MaxCoolant; CoolantBar.Minimum = 0; UnallocatedCoolantBar.Maximum = CoolantBar.Maximum; UnallocatedCoolantBar.Minimum = 0; TempBar.Maximum = (int)Ship.Cooler.NominalTemp * 3; TempBar.Minimum = 0; HeatSinkFactor.Value = (decimal)Ship.Cooler.HeatSyncRemovalFactor; DoUpdate(); Clock.Start(); LastUpdateTime = Seconds(); timer1.Start(); }