Ejemplo n.º 1
0
        public void testEngine()
        {

            Faction newFaction = new Faction(0);

            StarSystem System1 = SystemGen.CreateSol();

            SystemBody pl1 = new SystemBody(System1.Stars[0], SystemBody.PlanetType.Terrestrial);
            System1.Stars[0].Planets.Add(pl1);

            TaskGroupTN newTG = new TaskGroupTN("TG", newFaction, System1.Stars[0].Planets[0], System1);

            ShipClassTN ts2 = new ShipClassTN("Test", newFaction);
            ShipTN ts = new ShipTN(ts2, 0, 0, newTG, newFaction, "Test Ship");

            ts2.ShipEngineDef = new EngineDefTN("3137.6 EP Inertial Fusion Drive", 32, 2.65f, 0.6f, 0.75f, 2, 37, -1.0f);
            ts2.ShipEngineCount = 1;

            EngineTN temp = new EngineTN(ts2.ShipEngineDef);

            ts.ShipEngine = new BindingList<EngineTN>();
            ts.ShipEngine.Add(temp);

            EngineDefTN tst = ts.ShipEngine[0].engineDef;

            Console.WriteLine("Name: {0}", tst.Name);
            Console.WriteLine("EngineBase: {0}, PowerMod: {1}, FuelConMod: {2}, ThermalReduction: {3}, Size: {4},HyperMod: {5}",
                              tst.engineBase, tst.powerMod, tst.fuelConsumptionMod, tst.thermalReduction, tst.size, tst.hyperDriveMod);
            Console.WriteLine("EnginePower: {0}, FuelUsePerHour: {1}", tst.enginePower, tst.fuelUsePerHour);
            Console.WriteLine("EngineSize: {0}, EngineHTK: {1}", tst.size, tst.htk);
            Console.WriteLine("ThermalSignature: {0}, ExpRisk: {1}", tst.thermalSignature, tst.expRisk);
            Console.WriteLine("IsMilitary: {0}", tst.isMilitary);
            Console.WriteLine("Crew: {0}", tst.crew);
            Console.WriteLine("Cost: {0}", tst.cost);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// ShipTN creates a ship of classDefinition in Index ShipIndex for the taskgroup ship list.
        /// </summary>
        /// <param name="ClassDefinition">Definition of the ship.</param>
        /// <param name="ShipIndex">Its index within the shiplist of the taskgroup.</param>
        /// <param name="CurrentTimeSlice">tick when this ship is created.</param>
        /// <param name="ShipTG">TG this ship belongs to.</param>
        /// <param name="ShipFact">Faction this ship belongs to.</param>
        /// <param name="Title">Name of the ship.</param>
        public ShipTN(ShipClassTN ClassDefinition, int ShipIndex, int CurrentTimeSlice, TaskGroupTN ShipTG, Faction ShipFact, String Title)
        {
            int index;
            Name = Title;

            /// <summary>
            /// create these or else anything that relies on a unique global id will break.
            /// </summary>
            Id = Guid.NewGuid();

            /// <summary>
            /// Set the class definition
            /// </summary>
            ShipClass = ClassDefinition;

            /// <summary>
            /// Inform the class that it has a new member.
            /// </summary>
            ClassDefinition.ShipsInClass.Add(this);

            /// <summary>
            /// Ships are standard crewed vessels for now.
            /// </summary>
            TypeOf = ShipType.Standard;

            /// <summary>
            /// Tell the Ship which TG it is a part of.
            /// </summary>
            ShipsTaskGroup = ShipTG;

            /// <summary>
            /// Likewise for Faction.
            /// </summary>
            ShipsFaction = ShipFact;

            /// <summary>
            /// Add this ship to the overall faction ship list.
            /// </summary>
            ShipsFaction.Ships.Add(this);

            /// <summary>
            /// Make sure to initialize this important variable that everything uses.
            /// </summary>
            ShipComponents = new BindingList<ComponentTN>();

            /// <summary>
            /// Initialize the list of Ship fire controls.
            /// </summary>
            ShipFireControls = new BindingList<ComponentTN>();

            /// <summary>
            /// Likewise the ListOfComponentDefs counterpart here is important.
            /// </summary>
            ComponentDefIndex = new BindingList<ushort>();
            for (int loop = 0; loop < ClassDefinition.ListOfComponentDefs.Count; loop++)
            {
                ComponentDefIndex.Add(0);
            }

            /// <summary>
            /// List of components that have been destroyed.
            /// </summary>
            DestroyedComponents = new BindingList<ushort>();

            DestroyedComponentsType = new BindingList<ComponentTypeTN>();

            /// <summary>
            /// How much damage can the ship take?
            /// </summary>
            ShipHTK = ShipClass.TotalHTK;

            /// <summary>
            /// When the destroyed components list is populated it can be selected from to put components here to be repaired.
            /// </summary>
            DamageControlQue = new BindingList<ushort>();

            /// <summary>
            /// Not yet set.
            /// </summary>
            DamageControlTarget = -1;


            /// <summary>
            /// All ships will have armor, and all ship defs should have armor before this point.
            /// </summary.
            ShipArmor = new ArmorTN(ClassDefinition.ShipArmorDef);

            /// <summary>
            /// Crew Quarters don't strictly have to be present, but will be in almost all designs.
            /// </summary>
            CrewQuarters = new BindingList<GeneralComponentTN>();
            AddComponents(CrewQuarters, ClassDefinition.CrewQuarters, ClassDefinition.CrewQuartersCount);

            /// <summary>
            /// Subtract crew from crew pool if ship is not conscript staffed Here:
            /// </summary>

            CurrentCrew = 0;
            SpareBerths = ShipClass.TotalCrewQuarters;
            CurrentCryoStorage = 0;
            CurrentDeployment = 0.0f;
            Morale = 100.0f;
            ShipGrade = 0.0f;
            TFTraining = 0.0f;

            /// <summary>
            ///Fuel Tanks don't have to be present, but will be in most designs.
            /// </summary>
            FuelTanks = new BindingList<GeneralComponentTN>();
            AddComponents(FuelTanks, ClassDefinition.FuelTanks, ClassDefinition.FuelTanksCount);
            CurrentFuel = 0.0f;
            CurrentFuelCapacity = ShipClass.TotalFuelCapacity;
            FuelCounter = 0;

            /// <summary>
            /// Engineering spaces must be on civ designs(atleast 1), but can be absent from military designs.
            /// </summary>
            EngineeringBays = new BindingList<GeneralComponentTN>();
            AddComponents(EngineeringBays, ClassDefinition.EngineeringBays, ClassDefinition.EngineeringBaysCount);
            CurrentDamageControlRating = ClassDefinition.MaxDamageControlRating;
            CurrentMSP = ShipClass.TotalMSPCapacity;
            CurrentMSPCapacity = ShipClass.TotalMSPCapacity;
            MaintenanceClock = 0.0f;

            /// <summary>
            /// All remaining components that are of a more specialized nature. These do not have to be present, except bridges on ships bigger than 1K tons.
            /// </summary>
            OtherComponents = new BindingList<GeneralComponentTN>();
            AddComponents(OtherComponents, ClassDefinition.OtherComponents, ClassDefinition.OtherComponentsCount);

            /// <summary>
            /// All mobile ships need engines, orbitals and PDCs don't however.
            /// </summary>
            ShipEngine = new BindingList<EngineTN>();
            index = ClassDefinition.ListOfComponentDefs.IndexOf(ClassDefinition.ShipEngineDef);
            if (index != -1)
                ComponentDefIndex[index] = (ushort)ShipComponents.Count;

            for (int loop = 0; loop < ClassDefinition.ShipEngineCount; loop++)
            {
                EngineTN Engine = new EngineTN(ClassDefinition.ShipEngineDef);
                Engine.componentIndex = ShipEngine.Count;
                ShipEngine.Add(Engine);
                ShipComponents.Add(Engine);
            }
            CurrentEnginePower = ClassDefinition.MaxEnginePower;
            CurrentMaxEnginePower = CurrentEnginePower;
            CurrentThermalSignature = ClassDefinition.MaxThermalSignature;
            CurrentMaxThermalSignature = CurrentThermalSignature;
            CurrentSpeed = ClassDefinition.MaxSpeed;
            CurrentMaxSpeed = CurrentSpeed;
            CurrentFuelUsePerHour = ClassDefinition.MaxFuelUsePerHour;
            CurrentMaxFuelUsePerHour = CurrentFuelUsePerHour;


            /// <summary>
            /// Usually only cargo ships and salvagers will have cargo holds.
            /// </summary>
            ShipCargo = new BindingList<CargoTN>();
            for (int loop = 0; loop < ClassDefinition.ShipCargoDef.Count; loop++)
            {
                index = ClassDefinition.ListOfComponentDefs.IndexOf(ClassDefinition.ShipCargoDef[loop]);
                ComponentDefIndex[index] = (ushort)ShipComponents.Count;
                for (int loop2 = 0; loop2 < ClassDefinition.ShipCargoCount[loop]; loop2++)
                {
                    CargoTN cargo = new CargoTN(ClassDefinition.ShipCargoDef[loop]);
                    cargo.componentIndex = ShipCargo.Count;
                    ShipCargo.Add(cargo);
                    ShipComponents.Add(cargo);
                }
            }
            CurrentCargoTonnage = 0;
            CargoList = new Dictionary<Installation.InstallationType, CargoListEntryTN>();
            CargoComponentList = new Dictionary<ComponentDefTN, CargoListEntryTN>();

            /// <summary>
            /// While only colonyships will have the major bays, just about any craft can have an emergency cryo bay.
            /// </summary>
            ShipColony = new BindingList<ColonyTN>();
            for (int loop = 0; loop < ClassDefinition.ShipColonyDef.Count; loop++)
            {
                index = ClassDefinition.ListOfComponentDefs.IndexOf(ClassDefinition.ShipColonyDef[loop]);
                ComponentDefIndex[index] = (ushort)ShipComponents.Count;
                for (int loop2 = 0; loop2 < ClassDefinition.ShipColonyCount[loop]; loop2++)
                {
                    ColonyTN colony = new ColonyTN(ClassDefinition.ShipColonyDef[loop]);
                    colony.componentIndex = ShipColony.Count;
                    ShipColony.Add(colony);
                    ShipComponents.Add(colony);
                }
            }
            CurrentCryoStorage = 0;

            /// <summary>
            /// Any ship with cargo holds, troop bays, cryo berths, or drop pods will benefit from a cargohandling system. though droppods benefit from the CHSes on other vessels as well.
            /// </summary>
            ShipCHS = new BindingList<CargoHandlingTN>();
            for (int loop = 0; loop < ClassDefinition.ShipCHSDef.Count; loop++)
            {
                index = ClassDefinition.ListOfComponentDefs.IndexOf(ClassDefinition.ShipCHSDef[loop]);
                ComponentDefIndex[index] = (ushort)ShipComponents.Count;
                for (int loop2 = 0; loop2 < ClassDefinition.ShipCHSCount[loop]; loop2++)
                {
                    CargoHandlingTN CHS = new CargoHandlingTN(ClassDefinition.ShipCHSDef[loop]);
                    CHS.componentIndex = ShipCHS.Count;
                    ShipCHS.Add(CHS);
                    ShipComponents.Add(CHS);
                }
            }
            CurrentTractorMultiplier = ShipClass.TractorMultiplier;

            /// <summary>
            /// Every ship will have a passive sensor rating, but very few will have specialized passive sensors.
            /// </summary>
            ShipPSensor = new BindingList<PassiveSensorTN>();
            for (int loop = 0; loop < ClassDefinition.ShipPSensorDef.Count; loop++)
            {
                index = ClassDefinition.ListOfComponentDefs.IndexOf(ClassDefinition.ShipPSensorDef[loop]);
                ComponentDefIndex[index] = (ushort)ShipComponents.Count;
                for (int loop2 = 0; loop2 < ClassDefinition.ShipPSensorCount[loop]; loop2++)
                {
                    PassiveSensorTN PSensor = new PassiveSensorTN(ClassDefinition.ShipPSensorDef[loop]);
                    PSensor.componentIndex = ShipPSensor.Count;
                    ShipPSensor.Add(PSensor);
                    ShipComponents.Add(PSensor);
                }
            }

            /// <summary>
            /// These two can and will change if the ship takes damage to its sensors.
            /// </summary>
            BestThermalRating = ClassDefinition.BestThermalRating;
            BestEMRating = ClassDefinition.BestEMRating;

            /// <summary>
            /// Active Sensors will be probably rarer than passive sensors, as they betray their location to any listener in range.
            /// And the listener may be far enough away that the active will not ping him.
            /// </summary>
            ShipASensor = new BindingList<ActiveSensorTN>();
            for (int loop = 0; loop < ClassDefinition.ShipASensorDef.Count; loop++)
            {
                index = ClassDefinition.ListOfComponentDefs.IndexOf(ClassDefinition.ShipASensorDef[loop]);
                ComponentDefIndex[index] = (ushort)ShipComponents.Count;
                for (int loop2 = 0; loop2 < ClassDefinition.ShipASensorCount[loop]; loop2++)
                {
                    ActiveSensorTN ASensor = new ActiveSensorTN(ClassDefinition.ShipASensorDef[loop]);
                    ASensor.componentIndex = ShipASensor.Count;

                    int ASIndex = loop2 + 1;
                    ASensor.Name = ASensor.aSensorDef.Name + " #" + ASIndex.ToString();

                    ShipASensor.Add(ASensor);
                    ShipComponents.Add(ASensor);
                }
            }

            /// <summary>
            /// This won't change, but it should be here for convenience during sensor sweeps.
            /// </summary>
            TotalCrossSection = ClassDefinition.TotalCrossSection;
            CurrentEMSignature = 0;

            /// <summary>
            /// Detection Statistics initialization:
            /// </summary>
            ThermalList = new LinkedListNode<int>(ShipIndex);
            EMList = new LinkedListNode<int>(ShipIndex);
            ActiveList = new LinkedListNode<int>(ShipIndex);

            ThermalDetection = new BindingList<int>();
            EMDetection = new BindingList<int>();
            ActiveDetection = new BindingList<int>();

            for (int loop = 0; loop < Constants.Faction.FactionMax; loop++)
            {
                ThermalDetection.Add(CurrentTimeSlice);
                EMDetection.Add(CurrentTimeSlice);
                ActiveDetection.Add(CurrentTimeSlice);
            }

            ShipCommanded = false;

            ShipBFC = new BindingList<BeamFireControlTN>();
            for (int loop = 0; loop < ClassDefinition.ShipBFCDef.Count; loop++)
            {
                index = ClassDefinition.ListOfComponentDefs.IndexOf(ClassDefinition.ShipBFCDef[loop]);
                ComponentDefIndex[index] = (ushort)ShipComponents.Count;
                for (int loop2 = 0; loop2 < ClassDefinition.ShipBFCCount[loop]; loop2++)
                {
                    BeamFireControlTN BFC = new BeamFireControlTN(ClassDefinition.ShipBFCDef[loop]);
                    BFC.componentIndex = ShipBFC.Count;

                    int BFCIndex = loop2 + 1;
                    BFC.Name = BFC.beamFireControlDef.Name + " #" + BFCIndex.ToString();

                    ShipBFC.Add(BFC);
                    ShipComponents.Add(BFC);
                    ShipFireControls.Add(BFC);
                }
            }

            ShipBeam = new BindingList<BeamTN>();
            for (int loop = 0; loop < ClassDefinition.ShipBeamDef.Count; loop++)
            {
                index = ClassDefinition.ListOfComponentDefs.IndexOf(ClassDefinition.ShipBeamDef[loop]);
                ComponentDefIndex[index] = (ushort)ShipComponents.Count;
                for (int loop2 = 0; loop2 < ClassDefinition.ShipBeamCount[loop]; loop2++)
                {
                    BeamTN Beam = new BeamTN(ClassDefinition.ShipBeamDef[loop]);
                    Beam.componentIndex = ShipBeam.Count;

                    int BeamIndex = loop2 + 1;
                    Beam.Name = Beam.beamDef.Name + " #" + BeamIndex.ToString();

                    ShipBeam.Add(Beam);
                    ShipComponents.Add(Beam);
                }
            }

            ShipReactor = new BindingList<ReactorTN>();
            for (int loop = 0; loop < ClassDefinition.ShipReactorDef.Count; loop++)
            {
                index = ClassDefinition.ListOfComponentDefs.IndexOf(ClassDefinition.ShipReactorDef[loop]);
                ComponentDefIndex[index] = (ushort)ShipComponents.Count;
                for (int loop2 = 0; loop2 < ClassDefinition.ShipReactorCount[loop]; loop2++)
                {
                    ReactorTN Reactor = new ReactorTN(ClassDefinition.ShipReactorDef[loop]);
                    Reactor.componentIndex = ShipReactor.Count;
                    ShipReactor.Add(Reactor);
                    ShipComponents.Add(Reactor);
                }
            }
            CurrentPowerGen = ClassDefinition.TotalPowerGeneration;

            ShipShield = new BindingList<ShieldTN>();
            index = ClassDefinition.ListOfComponentDefs.IndexOf(ClassDefinition.ShipShieldDef);
            if (index != -1)
                ComponentDefIndex[index] = (ushort)ShipComponents.Count;

            for (int loop = 0; loop < ClassDefinition.ShipShieldCount; loop++)
            {
                ShieldTN Shield = new ShieldTN(ClassDefinition.ShipShieldDef);
                Shield.componentIndex = ShipShield.Count;
                ShipShield.Add(Shield);
                ShipComponents.Add(Shield);
            }

            CurrentShieldPool = 0.0f;
            CurrentShieldPoolMax = ClassDefinition.TotalShieldPool;
            CurrentShieldGen = ClassDefinition.TotalShieldGenPerTick;
            CurrentShieldFuelUse = ClassDefinition.TotalShieldFuelCostPerTick;
            ShieldIsActive = false;


            ShipMLaunchers = new BindingList<MissileLauncherTN>();
            for (int loop = 0; loop < ClassDefinition.ShipMLaunchDef.Count; loop++)
            {
                index = ClassDefinition.ListOfComponentDefs.IndexOf(ClassDefinition.ShipMLaunchDef[loop]);
                ComponentDefIndex[index] = (ushort)ShipComponents.Count;
                for (int loop2 = 0; loop2 < ClassDefinition.ShipMLaunchCount[loop]; loop2++)
                {
                    MissileLauncherTN Tube = new MissileLauncherTN(ClassDefinition.ShipMLaunchDef[loop]);
                    Tube.componentIndex = ShipMLaunchers.Count;

                    int TubeIndex = loop2 + 1;
                    Tube.Name = Tube.missileLauncherDef.Name + " #" + TubeIndex.ToString();

                    ShipMLaunchers.Add(Tube);
                    ShipComponents.Add(Tube);
                }
            }

            ShipMagazines = new BindingList<MagazineTN>();
            for (int loop = 0; loop < ClassDefinition.ShipMagazineDef.Count; loop++)
            {
                index = ClassDefinition.ListOfComponentDefs.IndexOf(ClassDefinition.ShipMagazineDef[loop]);
                ComponentDefIndex[index] = (ushort)ShipComponents.Count;
                for (int loop2 = 0; loop2 < ClassDefinition.ShipMagazineCount[loop]; loop2++)
                {
                    MagazineTN Mag = new MagazineTN(ClassDefinition.ShipMagazineDef[loop]);
                    Mag.componentIndex = ShipMagazines.Count;
                    ShipMagazines.Add(Mag);
                    ShipComponents.Add(Mag);
                }
            }

            ShipMFC = new BindingList<MissileFireControlTN>();
            for (int loop = 0; loop < ClassDefinition.ShipMFCDef.Count; loop++)
            {
                index = ClassDefinition.ListOfComponentDefs.IndexOf(ClassDefinition.ShipMFCDef[loop]);
                ComponentDefIndex[index] = (ushort)ShipComponents.Count;
                for (int loop2 = 0; loop2 < ClassDefinition.ShipMFCCount[loop]; loop2++)
                {
                    MissileFireControlTN MFC = new MissileFireControlTN(ClassDefinition.ShipMFCDef[loop]);
                    MFC.componentIndex = ShipMFC.Count;

                    int MFCIndex = loop2 + 1;
                    MFC.Name = MFC.mFCSensorDef.Name + " #" + MFCIndex.ToString();

                    ShipMFC.Add(MFC);
                    ShipComponents.Add(MFC);
                    ShipFireControls.Add(MFC);
                }
            }

            ShipOrdnance = new Dictionary<OrdnanceDefTN, int>();

            CurrentMagazineCapacity = 0;
            CurrentMagazineCapacityMax = ClassDefinition.TotalMagazineCapacity;
            CurrentLauncherMagCapacityMax = ClassDefinition.LauncherMagSpace;
            CurrentMagazineMagCapacityMax = ClassDefinition.MagazineMagSpace;

            ShipCIWS = new BindingList<CIWSTN>();
            for (int loop = 0; loop < ClassDefinition.ShipCIWSDef.Count; loop++)
            {
                index = ClassDefinition.ListOfComponentDefs.IndexOf(ClassDefinition.ShipCIWSDef[loop]);
                ComponentDefIndex[index] = (ushort)ShipComponents.Count;
                for (int loop2 = 0; loop2 < ClassDefinition.ShipCIWSCount[loop]; loop2++)
                {
                    CIWSTN CIWS = new CIWSTN(ClassDefinition.ShipCIWSDef[loop]);
                    CIWS.componentIndex = ShipCIWS.Count;

                    int CIWSIndex = loop2 + 1;
                    CIWS.Name = CIWS.cIWSDef.Name + " #" + CIWSIndex.ToString();

                    ShipCIWS.Add(CIWS);
                    ShipComponents.Add(CIWS);
                }
            }
            ShipCIWSIndex = 0;

            ShipTurret = new BindingList<TurretTN>();
            for (int loop = 0; loop < ClassDefinition.ShipTurretDef.Count; loop++)
            {
                index = ClassDefinition.ListOfComponentDefs.IndexOf(ClassDefinition.ShipTurretDef[loop]);
                ComponentDefIndex[index] = (ushort)ShipComponents.Count;
                for (int loop2 = 0; loop2 < ClassDefinition.ShipTurretCount[loop]; loop2++)
                {
                    TurretTN Turret = new TurretTN(ClassDefinition.ShipTurretDef[loop]);
                    Turret.componentIndex = ShipTurret.Count;

                    int TurretIndex = loop2 + 1;
                    Turret.Name = Turret.turretDef.Name + " #" + TurretIndex.ToString();

                    ShipTurret.Add(Turret);
                    ShipComponents.Add(Turret);
                }
            }

            ShipJumpEngine = new BindingList<JumpEngineTN>();
            for (int loop = 0; loop < ClassDefinition.ShipJumpEngineDef.Count; loop++)
            {
                index = ClassDefinition.ListOfComponentDefs.IndexOf(ClassDefinition.ShipJumpEngineDef[loop]);
                ComponentDefIndex[index] = (ushort)ShipComponents.Count;
                for (int loop2 = 0; loop2 < ClassDefinition.ShipJumpEngineCount[loop]; loop2++)
                {
                    JumpEngineTN JumpEngine = new JumpEngineTN(ClassDefinition.ShipJumpEngineDef[loop]);
                    JumpEngine.componentIndex = ShipJumpEngine.Count;

                    int JumpEngineIndex = loop2 + 1;
                    JumpEngine.Name = JumpEngine.jumpEngineDef.Name + " #" + JumpEngineIndex.ToString();

                    ShipJumpEngine.Add(JumpEngine);
                    ShipComponents.Add(JumpEngine);
                }
            }
            JumpSickness = 0;

            IsDestroyed = false;

            ShipsTargetting = new BindingList<ShipTN>();

            TaskGroupsOrdered = new BindingList<TaskGroupTN>();
        }