/// <summary>
        /// Refreshing the shipyard task groupbox will be necessary on player input.
        /// </summary>
        /// <param name="m_oSummaryPanel">The economics handler panel.</param>
        /// <param name="CurrentFaction">Selected faction from the economics handler.</param>
        /// <param name="CurrentPopulation">Selected population from the economics handler.</param>
        /// <param name="SYInfo">Shipyard information from the economics handler.</param>
        /// <param name="EligibleClassList">List of shipclasses that this shipyard can produce.</param>
        /// <param name="DamagedShipList">List of damaged ships in orbit.</param>
        /// <param name="ClassesInOrbit">List of shipclasses in orbit around CurrentPopulation.</param>
        /// <param name="ShipsOfClassInOrbit">List of ships in the selected shipclass in orbit around CurrentPopulation.</param>
        public static void RefreshSYTaskGroupBox(Panels.Eco_Summary m_oSummaryPanel, Faction CurrentFaction, Population CurrentPopulation, Installation.ShipyardInformation SYInfo,
                                                 ref BindingList<ShipClassTN> EligibleClassList, ref BindingList<ShipTN> DamagedShipList, ref BindingList<ShipClassTN> ClassesInOrbit,
                                                 ref BindingList<ShipTN>ShipsOfClassInOrbit)
        {
            if(m_oSummaryPanel.SYTaskTypeComboBox.SelectedIndex != -1)
            {
                Constants.ShipyardInfo.Task CurrentSYTask = (Constants.ShipyardInfo.Task)m_oSummaryPanel.SYTaskTypeComboBox.SelectedIndex;

                switch (CurrentSYTask)
                {
                    case Constants.ShipyardInfo.Task.Construction:                        
                        /// <summary>
                        /// Fill the taskgroups in orbit combo box.
                        /// </summary>
                        m_oSummaryPanel.SYTaskGroupComboBox.Items.Clear();
                        foreach (TaskGroupTN CurrentTaskGroup in CurrentPopulation.Planet.TaskGroupsInOrbit)
                        {
                            if(CurrentTaskGroup.TaskGroupFaction == CurrentFaction)
                                m_oSummaryPanel.SYTaskGroupComboBox.Items.Add(CurrentTaskGroup);
                        }
#warning later on look for Shipyard TG? and should shipyard TG be "special"?
                        if (m_oSummaryPanel.SYTaskGroupComboBox.Items.Count != 0)
                            m_oSummaryPanel.SYTaskGroupComboBox.SelectedIndex = 0;

                        if (SYInfo.AssignedClass != null)
                        {
                            m_oSummaryPanel.SYNewClassComboBox.Items.Clear();

                            GetEligibleClassList(CurrentFaction, SYInfo, ref EligibleClassList);

                            foreach (ShipClassTN CurrentClass in EligibleClassList)
                            {
                                m_oSummaryPanel.SYNewClassComboBox.Items.Add(CurrentClass);
                            }
                            if (m_oSummaryPanel.SYNewClassComboBox.Items.Count != 0)
                                m_oSummaryPanel.SYNewClassComboBox.SelectedIndex = 0;

                            int index = CurrentFaction.ShipDesigns.IndexOf(EligibleClassList[0]);
                            String Entry = String.Format("{0} {1}", CurrentFaction.ShipDesigns[index].Name,
                                                         (CurrentFaction.ShipDesigns[index].ShipsInClass.Count + CurrentFaction.ShipDesigns[index].ShipsUnderConstruction + 1));
                            m_oSummaryPanel.SYShipNameTextBox.Text = Entry;
                        }
                        break;
                    case Constants.ShipyardInfo.Task.Repair:
                        m_oSummaryPanel.RepairRefitScrapLabel.Text = "Repair";
                        GetDamagedShipList(CurrentFaction, CurrentPopulation, ref DamagedShipList);
                        m_oSummaryPanel.RepairRefitScrapShipComboBox.Items.Clear();
                        foreach (ShipTN CurrentShip in DamagedShipList)
                        {
                            m_oSummaryPanel.RepairRefitScrapShipComboBox.Items.Add(CurrentShip);
                        }
                        if (m_oSummaryPanel.RepairRefitScrapShipComboBox.Items.Count != 0)
                            m_oSummaryPanel.RepairRefitScrapShipComboBox.SelectedIndex = 0;
                        break;
                    case Constants.ShipyardInfo.Task.Refit:
                        m_oSummaryPanel.RepairRefitScrapLabel.Text = "Refit";
                        GetShipClassesInOrbit(CurrentFaction, CurrentPopulation, ref ClassesInOrbit);
                        m_oSummaryPanel.RepairRefitScrapClassComboBox.Items.Clear();
                        foreach (ShipClassTN CurrentClass in ClassesInOrbit)
                        {
                            m_oSummaryPanel.RepairRefitScrapClassComboBox.Items.Add(CurrentClass);
                        }
                        ShipClassTN CurrentRRSClass = null;
                        if (m_oSummaryPanel.RepairRefitScrapClassComboBox.Items.Count != 0)
                        {
                            m_oSummaryPanel.RepairRefitScrapClassComboBox.SelectedIndex = 0;
                            CurrentRRSClass = ClassesInOrbit[m_oSummaryPanel.RepairRefitScrapClassComboBox.SelectedIndex];
                        }

                        if (CurrentRRSClass != null)
                        {
                            GetShipsOfClassInOrbit(CurrentFaction, CurrentPopulation, CurrentRRSClass, ref ShipsOfClassInOrbit);
                            m_oSummaryPanel.RepairRefitScrapShipComboBox.Items.Clear();
                            foreach (ShipTN CurrentShip in ShipsOfClassInOrbit)
                            {
                                m_oSummaryPanel.RepairRefitScrapShipComboBox.Items.Add(CurrentShip);
                            }
                            if (m_oSummaryPanel.RepairRefitScrapShipComboBox.Items.Count != 0)
                                m_oSummaryPanel.RepairRefitScrapShipComboBox.SelectedIndex = 0;
                        }
                        break;
                    case Constants.ShipyardInfo.Task.Scrap:
                        m_oSummaryPanel.RepairRefitScrapLabel.Text = "Scrap";
                        GetShipClassesInOrbit(CurrentFaction, CurrentPopulation, ref ClassesInOrbit);
                        m_oSummaryPanel.RepairRefitScrapClassComboBox.Items.Clear();
                        foreach (ShipClassTN CurrentClass in ClassesInOrbit)
                        {
                            m_oSummaryPanel.RepairRefitScrapClassComboBox.Items.Add(CurrentClass);
                        }
                        CurrentRRSClass = null;
                        if (m_oSummaryPanel.RepairRefitScrapClassComboBox.Items.Count != 0)
                        {
                            m_oSummaryPanel.RepairRefitScrapClassComboBox.SelectedIndex = 0;
                            CurrentRRSClass = ClassesInOrbit[m_oSummaryPanel.RepairRefitScrapClassComboBox.SelectedIndex];
                        }

                        if(CurrentRRSClass != null)
                        {
                            GetShipsOfClassInOrbit(CurrentFaction, CurrentPopulation, CurrentRRSClass, ref ShipsOfClassInOrbit);
                            m_oSummaryPanel.RepairRefitScrapShipComboBox.Items.Clear();
                            foreach (ShipTN CurrentShip in ShipsOfClassInOrbit)
                            {
                                m_oSummaryPanel.RepairRefitScrapShipComboBox.Items.Add(CurrentShip);
                            }
                            if (m_oSummaryPanel.RepairRefitScrapShipComboBox.Items.Count != 0)
                                m_oSummaryPanel.RepairRefitScrapShipComboBox.SelectedIndex = 0;
                        }
                        break;
                }
            }
        }
        /// <summary>
        /// Refresh the shipyard tab.
        /// </summary>
        /// <param name="m_oSummaryPanel">The summary panel from the economics handler.</param>
        /// <param name="EligibleClassList">List of shipclasses that this shipyard can produce.</param>
        /// <param name="DamagedShipList">List of damaged ships in orbit.</param>
        /// <param name="ClassesInOrbit">List of shipclasses in orbit around CurrentPopulation.</param>
        /// <param name="ShipsOfClassInOrbit">List of ships in the selected shipclass in orbit around CurrentPopulation.</param>
        public static void RefreshShipyardTab(Panels.Eco_Summary m_oSummaryPanel, Faction CurrentFaction, Population CurrentPopulation, Installation.ShipyardInformation SYInfo,
                                              BindingList<ShipClassTN> RetoolTargets, ref BindingList<ShipClassTN> EligibleClassList, ref BindingList<ShipTN> DamagedShipList, 
                                              ref BindingList<ShipClassTN> ClassesInOrbit, ref BindingList<ShipTN> ShipsOfClassInOrbit)
        {
            /// <summary>
            /// Yeah, just going to constantly declare new variables to pass these along...
            /// </summary>
            ShipsOfClassInOrbit = new BindingList<ShipTN>();
            EligibleClassList = new BindingList<ShipClassTN>();
            DamagedShipList = new BindingList<ShipTN>();
            ClassesInOrbit = new BindingList<ShipClassTN>();

            if (CurrentFaction != null && CurrentPopulation != null && SYInfo != null)
            {
                RefreshShipyardDataGrid(m_oSummaryPanel, CurrentFaction, CurrentPopulation);
                RefreshSYCGroupBox(m_oSummaryPanel, CurrentFaction, CurrentPopulation, SYInfo, RetoolTargets);
                BuildSYCRequiredMinerals(m_oSummaryPanel, CurrentFaction, CurrentPopulation, SYInfo, RetoolTargets);
                RefreshSYTaskGroupBox(m_oSummaryPanel, CurrentFaction, CurrentPopulation, SYInfo, ref EligibleClassList, ref DamagedShipList, ref ClassesInOrbit,
                                                 ref ShipsOfClassInOrbit);
                BuildSYTRequiredMinerals(m_oSummaryPanel, CurrentFaction, CurrentPopulation, SYInfo, EligibleClassList, DamagedShipList, ClassesInOrbit,
                                                 ShipsOfClassInOrbit);

                String Entry = String.Format("Shipyard Complex Activity({0})", SYInfo.Name);
                m_oSummaryPanel.ShipyardTaskGroupBox.Text = Entry;

                Entry = String.Format("Create Task({0})", SYInfo.Name);
                m_oSummaryPanel.ShipyardCreateTaskGroupBox.Text = Entry;

                RefreshShipyardTasksTab(m_oSummaryPanel, CurrentFaction, CurrentPopulation);
            }
        }
        /// <summary>
        /// Need an updater function for this groupbox since the retool list can and will change.
        /// </summary>
        /// <param name="m_oSummaryPanel">Panel from economics</param>
        /// <param name="CurrentFaction">Current Faction</param>
        /// <param name="CurrentPopulation">Current Population</param>
        /// <param name="SYInfo">Shipyard information for the selected shipyard.</param>
        /// <param name="RetoolList">List of ships that this shipyard can be retooled to.</param>
        private static void RefreshSYCGroupBox(Panels.Eco_Summary m_oSummaryPanel, Faction CurrentFaction, Population CurrentPopulation, 
                                               Installation.ShipyardInformation SYInfo, BindingList<ShipClassTN> RetoolList)
        {
#warning this doesn't update when a new shipclass is added on its own. the econ page is "shared" by all factions so an event may not be possible there.
            if (RetoolList != null && CurrentFaction != null && SYInfo != null)
            {

                m_oSummaryPanel.NewShipClassComboBox.Items.Clear();
                RetoolList.Clear();
                foreach (ShipClassTN Ship in CurrentFaction.ShipDesigns)
                {
                    /// <summary>
                    /// Ships that are too big may not be in the retool list, and military ships may not be built at commercial yards.
                    /// Naval yards may build all classes of ships, but cap expansion for naval yards is very expensive.
                    /// </summary>
                    if (Ship.SizeTons <= SYInfo.Tonnage && !(Ship.IsMilitary == true && SYInfo.ShipyardType == Constants.ShipyardInfo.SYType.Commercial))
                    {
                        RetoolList.Add(Ship);
                    }
                }

                foreach (ShipClassTN Ship in RetoolList)
                {
                    m_oSummaryPanel.NewShipClassComboBox.Items.Add(Ship);
                }
                if (RetoolList.Count != 0)
                    m_oSummaryPanel.NewShipClassComboBox.SelectedIndex = 0;
            }
        }
Пример #4
0
        /// <summary>
        /// Constructs TN facilities at this population center.
        /// </summary>
        /// <param name="Inst">Installation to be built</param>
        /// <param name="increment">Amount of said installation to be built</param>
        public void AddInstallation(Installation Inst, float increment)
        {
            int Index = (int)Inst.Type;

            switch (Inst.Type)
            {
            /// <summary>
            /// Conversions must be converted to the installation we are going to add. Subtraction should have been handled elsewhere.
            /// </summary>
            case Installation.InstallationType.ConvertCIToConstructionFactory:
                Index = (int)Installation.InstallationType.ConstructionFactory;
                break;

            case Installation.InstallationType.ConvertCIToFighterFactory:
                Index = (int)Installation.InstallationType.FighterFactory;
                break;

            case Installation.InstallationType.ConvertCIToFuelRefinery:
                Index = (int)Installation.InstallationType.FuelRefinery;
                break;

            case Installation.InstallationType.ConvertCIToMine:
                Index = (int)Installation.InstallationType.Mine;
                break;

            case Installation.InstallationType.ConvertCIToOrdnanceFactory:
                Index = (int)Installation.InstallationType.OrdnanceFactory;
                break;

            case Installation.InstallationType.ConvertMineToAutomated:
                Index = (int)Installation.InstallationType.AutomatedMine;
                break;


            case Installation.InstallationType.NavalShipyardComplex:
                /// <summary>
                /// Shipyards must have a shipyard info created for them.
                /// </summary>
                float Adjustment = (float)Math.Floor(Installations[Index].Number + increment) - (float)Math.Floor(Installations[Index].Number);
                int   Number     = (int)Math.Floor(Installations[Index].Number);
                if (Number == 0)
                {
                    Number++;
                }
                while (Adjustment >= 1.0f)
                {
                    Installation.ShipyardInformation SYI = new Installation.ShipyardInformation(Faction, Constants.ShipyardInfo.SYType.Naval, Number);
                    Number++;

                    Installations[Index].SYInfo.Add(SYI);

                    Adjustment = Adjustment - 1.0f;
                }
                break;

            case Installation.InstallationType.CommercialShipyard:
                /// <summary>
                /// Shipyards must have a shipyard info created for them.
                /// </summary>
                Adjustment = (float)Math.Floor(Installations[Index].Number + increment) - (float)Math.Floor(Installations[Index].Number);
                Number     = (int)Math.Floor(Installations[Index].Number);
                if (Number == 0)
                {
                    Number++;
                }
                while (Adjustment >= 1.0f)
                {
                    Installation.ShipyardInformation SYI = new Installation.ShipyardInformation(Faction, Constants.ShipyardInfo.SYType.Commercial, Number);
                    Number++;

                    Installations[Index].SYInfo.Add(SYI);

                    Adjustment = Adjustment - 1.0f;
                }
                break;
            }
            Installations[Index].Number = Installations[Index].Number + increment;
        }
        /// <summary>
        /// This function gets the list of shipclasses this shipyard can build. In order to be considered eligible the class must be locked, and thus not alterable.
        /// eligible classes are those that would cost within 20% of cost to refit this shipclass towards.
        /// </summary>
        /// <param name="CurrentFaction">Current faction from the economics handler.</param>
        /// <param name="SYInfo">Currently selected shipyard.</param>
        /// <param name="EligibleClassList">List of shipclasses that this shipyard can produce.</param>
        private static void GetEligibleClassList(Faction CurrentFaction, Installation.ShipyardInformation SYInfo, ref BindingList<ShipClassTN> EligibleClassList)
        {
            if (SYInfo.AssignedClass == null)
            {
                return;
            }

            EligibleClassList.Clear();

            /// <summary>
            /// Shipyards may always build the ship that they are tooled for.
            /// </summary>
            EligibleClassList.Add(SYInfo.AssignedClass);

            /// <summary>
            /// If the total refit cost is less than this, the CurrentClass is eligible.
            /// </summary>
            decimal RefitThreshold = SYInfo.AssignedClass.BuildPointCost * 0.2m;

            /// <summary>
            /// component definition and count lists for the assigned class. for refit purposes we don't care about any specialized component functionality, just cost here.
            /// </summary>
            BindingList<ComponentDefTN> AssignedClassComponents = SYInfo.AssignedClass.ListOfComponentDefs;
            BindingList<short> AssignedClassComponentCounts = SYInfo.AssignedClass.ListOfComponentDefsCount;

            foreach (ShipClassTN CurrentClass in CurrentFaction.ShipDesigns)
            {
                /// <summary>
                /// Assigned class is already set to be built, and shouldn't ever be an "eligible class"
                /// </summary>
                if (CurrentClass == SYInfo.AssignedClass)
                    continue;

                /// <summary>
                /// Military ships are not buildable at commercial yards. Naval yards can build commercial ships however.
                /// </summary>
                if (CurrentClass.IsMilitary == true && SYInfo.ShipyardType == Constants.ShipyardInfo.SYType.Commercial)
                    continue;

                /// <summary>
                /// unlocked classes can be edited so I do not wish to have them included here.
                /// </summary>
                if(CurrentClass.IsLocked == true)
                {
                    decimal TotalRefitCost = SYInfo.AssignedClass.GetRefitCost(CurrentClass);

                    if (TotalRefitCost <= RefitThreshold)
                        EligibleClassList.Add(CurrentClass);
                }
            }
        }
Пример #6
0
        /// <summary>
        /// Shipyard modifications are done here.
        /// </summary>
        /// <param name="CurrentFaction">Current faction this shipyard belongs to.</param>
        /// <param name="CurrentPopulation">Current population this shipyard is on.</param>
        /// <param name="SYInfo">The shipyard itself.</param>
        private static void PerformShipyardActivity(Faction CurrentFaction, Population CurrentPopulation, Installation.ShipyardInformation SYInfo)
        {
            if (SYInfo.CurrentActivity.Activity != Constants.ShipyardInfo.ShipyardActivity.NoActivity && SYInfo.CurrentActivity.Paused == false)
            {
                float SYBP = SYInfo.CalcAnnualSYProduction() * Constants.Colony.ConstructionCycleFraction;

                int Adjustment = 1;
                if (SYInfo.ShipyardType == Constants.ShipyardInfo.SYType.Naval)
                {
                    Adjustment = Constants.ShipyardInfo.NavalToCommercialRatio;
                }

                /// <summary>
                /// Don't bother with completion date, or progress, just add the capacity.
                /// </summary>
                if (SYInfo.CurrentActivity.Activity == Constants.ShipyardInfo.ShipyardActivity.CapExpansion || SYInfo.CurrentActivity.Activity ==
                     Constants.ShipyardInfo.ShipyardActivity.CapExpansionUntilX)
                {
                    /// <summary>
                    /// How many tons could this shipyard expand capacity by in this time increment? SYBP is the number of BP produced this cycle. BaseTotalCostOfExpansion is the cost for 500 tons.
                    /// Adjustment is the factor that accounts for whether or not this is a commercial yard or a naval yard.
                    /// </summary>
                    float BaseCostIncrement = SYBP / (float)(Constants.ShipyardInfo.BaseTotalCostOfExpansion * Adjustment);
                    float TonsPerCycle = BaseCostIncrement * (float)Constants.ShipyardInfo.TonnageDenominator;

                    /// <summary>
                    /// Don't build more than this many tons if the activity is CapX.
                    /// </summary>
                    if (SYInfo.CurrentActivity.Activity == Constants.ShipyardInfo.ShipyardActivity.CapExpansionUntilX)
                    {
                        if (SYInfo.Tonnage + (int)Math.Floor(TonsPerCycle) > SYInfo.CurrentActivity.CapExpansionLimit)
                        {
                            TonsPerCycle = SYInfo.CurrentActivity.CapExpansionLimit - SYInfo.Tonnage;
                        }

                        SYInfo.CurrentActivity.Progress = 1.0m - (((decimal)SYInfo.CurrentActivity.CapExpansionLimit - (decimal)(SYInfo.Tonnage + TonsPerCycle)) / (decimal)SYInfo.CurrentActivity.CapExpansionLimit);
                    }

                    decimal Cost = (Constants.ShipyardInfo.BaseTotalCostOfExpansion*Adjustment) * ((decimal)TonsPerCycle / (decimal)Constants.ShipyardInfo.TonnageDenominator) * SYInfo.Slipways * Adjustment;
                    decimal[] mCost = new decimal[(int)Constants.Minerals.MinerialNames.MinerialCount];
                    mCost[(int)Constants.Minerals.MinerialNames.Duranium] = Cost / 2.0m;
                    mCost[(int)Constants.Minerals.MinerialNames.Neutronium] = Cost / 2.0m;

                    /// <summary>
                    /// Can I build this tick's worth of production?
                    /// </summary>
                    bool CanBuild = CurrentPopulation.MineralRequirement(mCost, 1.0f);

                    if (CanBuild == true)
                    {
                        CurrentPopulation.HandleShipyardCost(Cost, mCost, 1.0f);
                        SYInfo.AddTonnage(CurrentFaction, (int)Math.Floor(TonsPerCycle));
                    }
                    else
                    {
                        String Entry = String.Format("Not enough minerals to finish task {0} at Shipyard {1} on Population {2}", SYInfo.CurrentActivity.Activity, SYInfo, CurrentPopulation);
                        MessageEntry NMsg = new MessageEntry(MessageEntry.MessageType.ColonyLacksMinerals, CurrentPopulation.Position.System, CurrentPopulation, GameState.Instance.GameDateTime,
                                                           GameState.Instance.LastTimestep, Entry);
                        GameState.Instance.Factions[0].MessageLog.Add(NMsg);
                    }
                }
                else
                {
                    /// <summary>
                    /// BP produced this construction cycle / the total cost of the activity.
                    /// </summary>
                    float CurrentProgress = SYBP / (float)SYInfo.CurrentActivity.CostOfActivity;

                    if ((SYInfo.CurrentActivity.Progress + (decimal)CurrentProgress) > 1.0m)
                    {
                        CurrentProgress = (float)(1.0m - SYInfo.CurrentActivity.Progress);
                    }

                    bool CanBuild = CurrentPopulation.MineralRequirement(SYInfo.CurrentActivity.minerialsCost, CurrentProgress);

                    if (CanBuild == true)
                    {
                        CurrentPopulation.HandleShipyardCost(SYInfo.CurrentActivity.CostOfActivity, SYInfo.CurrentActivity.minerialsCost, CurrentProgress);
                        SYInfo.CurrentActivity.Progress = SYInfo.CurrentActivity.Progress + (decimal)CurrentProgress;
                    }
                    else
                    {
                        String Entry = String.Format("Not enough minerals to finish task {0} at Shipyard {1} on Population {2}", SYInfo.CurrentActivity.Activity, SYInfo, CurrentPopulation);
                        MessageEntry NMsg = new MessageEntry(MessageEntry.MessageType.ColonyLacksMinerals, CurrentPopulation.Position.System, CurrentPopulation, GameState.Instance.GameDateTime,
                                                           GameState.Instance.LastTimestep, Entry);
                        GameState.Instance.Factions[0].MessageLog.Add(NMsg);
                    }

                    /// <summary>
                    /// handle standard task completion here.
                    /// </summary>
                    if (SYInfo.CurrentActivity.Progress >= 1.0m)
                    {
                        switch (SYInfo.CurrentActivity.Activity)
                        {
                            case Constants.ShipyardInfo.ShipyardActivity.AddSlipway:
                                SYInfo.Slipways = SYInfo.Slipways + 1;
                                break;
                            case Constants.ShipyardInfo.ShipyardActivity.Add500Tons:
                                SYInfo.AddTonnage(CurrentFaction, Constants.ShipyardInfo.TonnageDenominator);
                                break;
                            case Constants.ShipyardInfo.ShipyardActivity.Add1000Tons:
                                SYInfo.AddTonnage(CurrentFaction, (Constants.ShipyardInfo.TonnageDenominator * 2));
                                break;
                            case Constants.ShipyardInfo.ShipyardActivity.Add2000Tons:
                                SYInfo.AddTonnage(CurrentFaction, (Constants.ShipyardInfo.TonnageDenominator * 4));
                                break;
                            case Constants.ShipyardInfo.ShipyardActivity.Add5000Tons:
                                SYInfo.AddTonnage(CurrentFaction, (Constants.ShipyardInfo.TonnageDenominator * 10));
                                break;
                            case Constants.ShipyardInfo.ShipyardActivity.Add10000Tons:
                                SYInfo.AddTonnage(CurrentFaction, (Constants.ShipyardInfo.TonnageDenominator * 20));
                                break;
                            case Constants.ShipyardInfo.ShipyardActivity.Retool:
                                SYInfo.AssignedClass = SYInfo.CurrentActivity.TargetOfRetool;
                                if (SYInfo.AssignedClass.IsLocked == false)
                                    SYInfo.AssignedClass.IsLocked = true;
                                break;
                        }
                    }
                    else
                    {
                        /// <summary>
                        /// Update the timer since this project won't finish just yet.
                        /// </summary>
                        decimal CostLeft = SYInfo.CurrentActivity.CostOfActivity * (1.0m - SYInfo.CurrentActivity.Progress);
                        float YearsOfProduction = (float)CostLeft / SYInfo.CalcAnnualSYProduction();
                        
                        DateTime EstTime = GameState.Instance.GameDateTime;
                        if (YearsOfProduction < Constants.Colony.TimerYearMax)
                        {
                            float DaysInYear = (float)Constants.TimeInSeconds.RealYear / (float)Constants.TimeInSeconds.Day;
                            int TimeToBuild = (int)Math.Floor(YearsOfProduction * DaysInYear);
                            TimeSpan TS = new TimeSpan(TimeToBuild, 0, 0, 0);
                            EstTime = EstTime.Add(TS);
                        }
                        SYInfo.CurrentActivity.CompletionDate = EstTime;
                    }
                }

                /// <summary>
                /// Lastly clean up any completed activities.
                /// </summary>
                if (SYInfo.CurrentActivity.Activity == Constants.ShipyardInfo.ShipyardActivity.CapExpansionUntilX)
                {
                    if (SYInfo.Tonnage >= SYInfo.CurrentActivity.CapExpansionLimit)
                    {
                        /// <summary>
                        /// This activity has completed so end it.
                        /// </summary>
                        SYInfo.CurrentActivity = new Installation.ShipyardInformation.ShipyardActivity();
                    }
                }
                else if (SYInfo.CurrentActivity.Activity != Constants.ShipyardInfo.ShipyardActivity.CapExpansion &&
                        SYInfo.CurrentActivity.Activity != Constants.ShipyardInfo.ShipyardActivity.NoActivity)
                {
                    if (SYInfo.CurrentActivity.Progress >= 1.0m)
                    {
                        /// <summary>
                        /// This activity has completed so end it.
                        /// </summary>
                        SYInfo.CurrentActivity = new Installation.ShipyardInformation.ShipyardActivity();
                    }
                }
            }
        }
Пример #7
0
        public Population(SystemBody a_oPlanet, Faction a_oFaction, String a_oName = "Earth", Species a_oSpecies = null)
        {
            Id = Guid.NewGuid();
            // initialise minerials:
            m_aiMinerials = new float[Constants.Minerals.NO_OF_MINERIALS];
            for (int i = 0; i < Constants.Minerals.NO_OF_MINERIALS; ++i)
            {
                m_aiMinerials[i] = 0;
            }

            m_aoInstallations = new Installation[Installation.NO_OF_INSTALLATIONS];
            for (int i = 0; i < Installation.NO_OF_INSTALLATIONS; ++i)
            {
                m_aoInstallations[i] = new Installation((Installation.InstallationType)i);
            }

            CivilianPopulation         = 0;
            PopulationGrowthRate       = 0.1f;
            FuelStockpile              = 0;
            MaintenanceSupplies        = 0;
            ModifierEconomicProduction = 1.0f;
            ModifierManfacturing       = 1.0f;
            ModifierPoliticalStability = 1.0f;
            ModifierProduction         = 1.0f;
            ModifierWealthAndTrade     = 1.0f;

            Name = a_oName;  // just a default Value!

            Faction = a_oFaction;
            Planet  = a_oPlanet;


            if (a_oSpecies == null)
            {
                Species = Faction.Species;
            }
            else
            {
                Species = a_oSpecies;
            }
            Planet.Populations.Add(this); // add us to the list of pops on the planet!
            Planet.Position.System.Populations.Add(this);
            Contact = new SystemContact(Faction, this);

            GovernorPresent = false;
            AdminRating     = 0;

            ComponentStockpile       = new BindingList <ComponentDefTN>();
            ComponentStockpileCount  = new BindingList <float>();
            ComponentStockpileLookup = new Dictionary <Guid, int>();
            MissileStockpile         = new Dictionary <OrdnanceDefTN, float>();

            OrbitalTerraformModules = 0.0f;

            PoliticalPopStatus = PoliticalStatus.Imperial;

            for (int InstallationIterator = 0; InstallationIterator < (int)Installation.InstallationType.InstallationCount; InstallationIterator++)
            {
                Installations[InstallationIterator].Number = 0.0f;
            }

            FuelStockpile              = 0.0f;
            MaintenanceSupplies        = 0.0f;
            EMSignature                = 0;
            ThermalSignature           = 0;
            ModifierEconomicProduction = 1.0f;
            ModifierManfacturing       = 1.0f;
            ModifierProduction         = 1.0f;
            ModifierWealthAndTrade     = 1.0f;
            ModifierPoliticalStability = 1.0f;

            ConstructionBuildQueue = new BindingList <ConstructionBuildQueueItem>();
            MissileBuildQueue      = new BindingList <MissileBuildQueueItem>();
            FighterBuildQueue      = new BindingList <FighterBuildQueueItem>();

            IsRefining = false;

            ShipyardTasks = new Dictionary <Installation.ShipyardInformation.ShipyardTask, Installation.ShipyardInformation>();

            SSEntity = StarSystemEntityType.Population;
        }
Пример #8
0
        /// <summary>
        /// Load cargo loads a specified installation type from a population, up to the limit in installations if possible.
        /// </summary>
        /// <param name="Pop">Population to load from.</param>
        /// <param name="InstType">installation type to load.</param>
        /// <param name="Limit">Limit in number of facilities to load.</param>
        public void LoadCargo(Population Pop, Installation.InstallationType InstType, int Limit)
        {
            int RemainingTaskGroupTonnage = TotalCargoTonnage - CurrentCargoTonnage;
            int TotalMass = TaskGroupFaction.InstallationTypes[(int)InstType].Mass * Limit;
            int AvailableMass = (int)(Pop.Installations[(int)InstType].Number * (float)TaskGroupFaction.InstallationTypes[(int)InstType].Mass);

            int MassToLoad = 0;

            /// <summary>
            /// In this case load as much as possible up to AvailableMass.
            /// </summary>
            if (Limit == 0)
            {
                MassToLoad = Math.Min(RemainingTaskGroupTonnage, AvailableMass);

            }
            /// <summary>
            /// In this case only load up to Total mass.
            /// </summary>
            else
            {
                MassToLoad = Math.Min(RemainingTaskGroupTonnage, TotalMass);
            }

            /// <summary>
            /// Mark the taskgroup total cargo tonnage
            /// </summary>
            CurrentCargoTonnage = CurrentCargoTonnage + MassToLoad;

            /// <summary>
            /// Decrement the installation count on the planet.
            /// </summary>
            Pop.LoadInstallation(InstType, MassToLoad);

            /// <summary>
            /// Now start loading mass onto each ship.
            /// </summary>
            for (int loop = 0; loop < Ships.Count; loop++)
            {
                int RemainingShipTonnage = Ships[loop].ShipClass.TotalCargoCapacity - Ships[loop].CurrentCargoTonnage;
                if (Ships[loop].ShipClass.TotalCargoCapacity != 0 && RemainingShipTonnage != 0)
                {
                    int ShipMassToLoad = Math.Min(MassToLoad, RemainingShipTonnage);

                    /// <summary>
                    /// Load the mass onto the taskgroup as a whole for display purposes.
                    /// The actual mass will go into the ship cargoholds.
                    /// </summary>
                    if (Ships[loop].CargoList.ContainsKey(InstType))
                    {
                        CargoListEntryTN CLE = Ships[loop].CargoList[InstType];
                        CLE.tons = CLE.tons + ShipMassToLoad;

                    }
                    else
                    {
                        CargoListEntryTN CargoListEntry = new CargoListEntryTN(InstType, ShipMassToLoad);
                        Ships[loop].CargoList.Add(InstType, CargoListEntry);
                    }

                    MassToLoad = MassToLoad - ShipMassToLoad;
                    Ships[loop].CurrentCargoTonnage = ShipMassToLoad;
                }
            }
        }
Пример #9
0
        /// <summary>
        /// Unload Cargo unloads a specified installation type from the taskgroup to a population. either all installations in this type are unloaded, or merely the limit are unloaded.
        /// </summary>
        /// <param name="Pop">Population to unload to.</param>
        /// <param name="InstType">Installation type.</param>
        /// <param name="Limit">Number of installations to unload.</param>
        public void UnloadCargo(Population Pop, Installation.InstallationType InstType, int Limit)
        {
            int TotalMass = TaskGroupFaction.InstallationTypes[(int)InstType].Mass * Limit;
            for (int loop = 0; loop < Ships.Count; loop++)
            {
                if (Ships[loop].ShipClass.TotalCargoCapacity != 0 && Ships[loop].CurrentCargoTonnage != 0 && Ships[loop].CargoList.ContainsKey(InstType) == true)
                {
                    CargoListEntryTN CLE = Ships[loop].CargoList[InstType];
                    int ShipMassToUnload = 0;

                    if (Limit == 0)
                    {
                        ShipMassToUnload = CLE.tons;
                    }
                    else
                    {
                        ShipMassToUnload = Math.Min(CLE.tons, TotalMass);
                        TotalMass = TotalMass - ShipMassToUnload;
                    }

                    if (ShipMassToUnload == CLE.tons)
                    {
                        Ships[loop].CargoList.Remove(InstType);
                    }

                    CLE.tons = CLE.tons - ShipMassToUnload;
                    CurrentCargoTonnage = CurrentCargoTonnage - ShipMassToUnload;

                    Pop.UnloadInstallation(InstType, ShipMassToUnload);
                }
            }

        }
Пример #10
0
        /// <summary>
        /// Constructs TN facilities at this population center.
        /// </summary>
        /// <param name="Inst">Installation to be built</param>
        /// <param name="increment">Amount of said installation to be built</param>
        public void AddInstallation(Installation Inst, float increment)
        {
            int Index = (int)Inst.Type;
            switch (Inst.Type)
            {
                    /// <summary>
                    /// Conversions must be converted to the installation we are going to add. Subtraction should have been handled elsewhere.
                    /// </summary>
                case Installation.InstallationType.ConvertCIToConstructionFactory:
                    Index = (int)Installation.InstallationType.ConstructionFactory;
                    break;
                case Installation.InstallationType.ConvertCIToFighterFactory:
                    Index = (int)Installation.InstallationType.FighterFactory;
                    break;
                case Installation.InstallationType.ConvertCIToFuelRefinery:
                    Index = (int)Installation.InstallationType.FuelRefinery;
                    break;
                case Installation.InstallationType.ConvertCIToMine:
                    Index = (int)Installation.InstallationType.Mine;
                    break;
                case Installation.InstallationType.ConvertCIToOrdnanceFactory:
                    Index = (int)Installation.InstallationType.OrdnanceFactory;
                    break;
                case Installation.InstallationType.ConvertMineToAutomated:
                    Index = (int)Installation.InstallationType.AutomatedMine;
                    break;


                case Installation.InstallationType.NavalShipyardComplex:
                    /// <summary>
                    /// Shipyards must have a shipyard info created for them.
                    /// </summary>
                    float Adjustment = (float)Math.Floor(Installations[Index].Number + increment) - (float)Math.Floor(Installations[Index].Number);
                    int Number = (int)Math.Floor(Installations[Index].Number);
                    if (Number == 0)
                        Number++;
                    while (Adjustment >= 1.0f)
                    {
                        Installation.ShipyardInformation SYI = new Installation.ShipyardInformation(Faction, Constants.ShipyardInfo.SYType.Naval, Number);
                        Number++;
                        
                        Installations[Index].SYInfo.Add(SYI);

                        Adjustment = Adjustment - 1.0f;
                    }
                    break;
                case Installation.InstallationType.CommercialShipyard:
                    /// <summary>
                    /// Shipyards must have a shipyard info created for them.
                    /// </summary>
                    Adjustment = (float)Math.Floor(Installations[Index].Number + increment) - (float)Math.Floor(Installations[Index].Number);
                    Number = (int)Math.Floor(Installations[Index].Number);
                    if (Number == 0)
                        Number++;
                    while (Adjustment >= 1.0f)
                    {
                        Installation.ShipyardInformation SYI = new Installation.ShipyardInformation(Faction, Constants.ShipyardInfo.SYType.Commercial, Number);
                        Number++;

                        Installations[Index].SYInfo.Add(SYI);

                        Adjustment = Adjustment - 1.0f;
                    }
                    break;
                case Installation.InstallationType.DeepSpaceTrackingStation:
                    /// <summary>
                    /// A DSTS was given to this population, so tell the UI to display it.
                    /// </summary>
                    _SensorUpdateAck++; 
                    break;
            }
            Installations[Index].Number = Installations[Index].Number + increment;
        }
Пример #11
0
 /// <summary>
 /// When an installation is unloaded to this population run this function to handle incremented installation[].number and other conditions.
 /// </summary>
 /// <param name="iType">Type of installation</param>
 /// <param name="massToUnload">Total mass of said installation to unload. this can result in fractional changes to installation[].number</param>
 public void UnloadInstallation(Installation.InstallationType iType, int massToUnload)
 {
     Installations[(int)iType].Number = Installations[(int)iType].Number + (float)(massToUnload / Faction.InstallationTypes[(int)iType].Mass);
     switch(iType)
     {
         case Installation.InstallationType.DeepSpaceTrackingStation:
             /// <summary>
             /// A DSTS was given to this population, so tell the UI to display it.
             /// </summary>
             _SensorUpdateAck++;
         break;
     }
 }
Пример #12
0
        /// <summary>
        /// Constructor for population.
        /// </summary>
        /// <param name="a_oPlanet">Planet this population is on</param>
        /// <param name="a_oFaction">Faction this population belongs to</param>
        /// <param name="CurrentTimeSlice">Tick this population was created</param>
        /// <param name="a_oName">Name of the population</param>
        /// <param name="a_oSpecies">Species that will reside on this population.</param>
        public Population(SystemBody a_oPlanet, Faction a_oFaction, int CurrentTimeSlice, String a_oName = "Earth", Species a_oSpecies = null)
        {
            Id = Guid.NewGuid();
            // initialise minerials:
            m_aiMinerials = new float[Constants.Minerals.NO_OF_MINERIALS];
            for (int i = 0; i < Constants.Minerals.NO_OF_MINERIALS; ++i)
            {
                m_aiMinerials[i] = 0;
            }

            m_aoInstallations = new Installation[Installation.NO_OF_INSTALLATIONS];
            for (int i = 0; i < Installation.NO_OF_INSTALLATIONS; ++i)
            {
                m_aoInstallations[i] = new Installation((Installation.InstallationType)i);
            }

            CivilianPopulation = 0;
            PopulationGrowthRate = 0.1f;
            FuelStockpile = 0;
            MaintenanceSupplies = 0;
            ModifierEconomicProduction = 1.0f;
            ModifierManfacturing = 1.0f;
            ModifierPoliticalStability = 1.0f;
            ModifierProduction = 1.0f;
            ModifierWealthAndTrade = 1.0f;

            Name = a_oName;  // just a default Value!

            Faction = a_oFaction;
            Planet = a_oPlanet;


            if (a_oSpecies == null)
            {
                Species = Faction.Species;
            }
            else
            {
                Species = a_oSpecies;
            }

            SSEntity = StarSystemEntityType.Population;

            Planet.Populations.Add(this); // add us to the list of pops on the planet!
            Planet.Position.System.Populations.Add(this);
            Contact = new SystemContact(Faction, this);
            Contact.Position.System = Planet.Position.System;
            Contact.Position.X = Planet.Position.X;
            Contact.Position.Y = Planet.Position.Y;
            Planet.Position.System.SystemContactList.Add(Contact);

            GovernorPresent = false;
            AdminRating = 0;

            ComponentStockpile = new BindingList<ComponentDefTN>();
            ComponentStockpileCount = new BindingList<float>();
            ComponentStockpileLookup = new Dictionary<Guid, int>();
            MissileStockpile = new Dictionary<OrdnanceDefTN, float>();

            _OrbitalTerraformModules = 0.0f;

            PoliticalPopStatus = PoliticalStatus.Imperial;

            for (int InstallationIterator = 0; InstallationIterator < (int)Installation.InstallationType.InstallationCount; InstallationIterator++)
            {
                Installations[InstallationIterator].Number = 0.0f;
            }

            FuelStockpile = 0.0f;
            MaintenanceSupplies = 0.0f;
            EMSignature = 0;
            ThermalSignature = 0;
            ModifierEconomicProduction = 1.0f;
            ModifierManfacturing = 1.0f;
            ModifierProduction = 1.0f;
            ModifierWealthAndTrade = 1.0f;
            ModifierPoliticalStability = 1.0f;

            ConstructionBuildQueue = new BindingList<ConstructionBuildQueueItem>();
            MissileBuildQueue = new BindingList<MissileBuildQueueItem>();
            FighterBuildQueue = new BindingList<FighterBuildQueueItem>();

            IsRefining = false;

            ShipyardTasks = new Dictionary<Installation.ShipyardInformation.ShipyardTask, Installation.ShipyardInformation>();

            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);
            }

            ShipsTargetting = new BindingList<ShipTN>();
            MissilesInFlight = new BindingList<OrdnanceGroupTN>();

            _SensorUpdateAck = 0;

            /// <summary>
            /// Terraforming Section:
            /// </summary>
            _GasAddSubtract = false;
            _GasAmt = 0.0f;
            _GasToAdd = null;
        }
Пример #13
0
        /// <summary>
        /// Constructor for Installations.
        /// </summary>
        /// <param name="InstallationToBuild">Installation to build</param>
        public ConstructionBuildQueueItem(Installation InstallationToBuild)
            : base()
        {
            Name = InstallationToBuild.Name;
            numToBuild = 0.0f;
            buildCapacity = 0.0f;
            productionRate = 0.0f;
            costPerItem = InstallationToBuild.Cost;

            m_BuildType = CBType.PlanetaryInstallation;
            m_InstallationBuild = InstallationToBuild;
        }
Пример #14
0
        /// <summary>
        /// Add an installation to the build queue.
        /// </summary>
        /// <param name="Install">Installation to add.</param>
        /// <param name="BuildAmt">number of such installations to construct.</param>
        /// <param name="RequestedBuildPercentage">Percent of construction factories, conventional industry, engineering teams to devote to construction.</param>
        public void BuildQueueAddInstallation(Installation Install, float BuildAmt, float RequestedBuildPercentage)
        {
            ConstructionBuildQueueItem NewCBQItem = new ConstructionBuildQueueItem(Install);
            NewCBQItem.UpdateBuildQueueInfo(BuildAmt, RequestedBuildPercentage, true,Install.Cost);

            ConstructionBuildQueue.Add(NewCBQItem);
        }
        /// <summary>
        /// Every task will cost resources, and this program will populate the required resources listbox.
        /// </summary>
        /// <param name="m_oSummaryPanel">Panel the economics handler will pass to us</param>
        /// <param name="CurrentFaction">Current Faction</param>
        /// <param name="CurrentPopulation">Currently selected population</param>
        /// <param name="SYInfo">Current Shipyard</param>
        /// <param name="Retool">Retool target if any</param>
        /// <param name="CapLimit">Cap expansion limit if any</param>
        public static void BuildSYCRequiredMinerals(Panels.Eco_Summary m_oSummaryPanel, Faction CurrentFaction, Population CurrentPopulation, Installation.ShipyardInformation SYInfo,
                                                    BindingList<ShipClassTN> PotentialRetoolTargets)
        {
            if (m_oSummaryPanel.SYCTaskTypeComboBox.SelectedIndex != -1  && SYInfo != null)
            {
                m_oSummaryPanel.SYCRequiredMaterialsListBox.Items.Clear();
                Constants.ShipyardInfo.ShipyardActivity Activity = (Constants.ShipyardInfo.ShipyardActivity)m_oSummaryPanel.SYCTaskTypeComboBox.SelectedIndex;

                if (Activity != Constants.ShipyardInfo.ShipyardActivity.CapExpansion && Activity != Constants.ShipyardInfo.ShipyardActivity.NoActivity)
                {
                    Installation.ShipyardInformation CostPrototyper = new Installation.ShipyardInformation(CurrentFaction, SYInfo.ShipyardType, 1);
                    CostPrototyper.Tonnage = SYInfo.Tonnage;
                    CostPrototyper.Slipways = SYInfo.Slipways;
                    CostPrototyper.ModRate = SYInfo.ModRate;
                    CostPrototyper.AssignedClass = SYInfo.AssignedClass;
                    ShipClassTN RetoolTarget = null;
                    if (PotentialRetoolTargets.Count != 0 && m_oSummaryPanel.NewShipClassComboBox.SelectedIndex != -1)
                    {
                        RetoolTarget = PotentialRetoolTargets[m_oSummaryPanel.NewShipClassComboBox.SelectedIndex];
                    }
                    int NewCapLimit = -1;
                    bool r = Int32.TryParse(m_oSummaryPanel.ExpandCapUntilXTextBox.Text, out NewCapLimit);

                    CostPrototyper.SetShipyardActivity(CurrentFaction, Activity, RetoolTarget, NewCapLimit);

                    for (int MineralIterator = 0; MineralIterator < Constants.Minerals.NO_OF_MINERIALS; MineralIterator++)
                    {

                        if (CostPrototyper.CurrentActivity.minerialsCost[MineralIterator] != 0.0m)
                        {
                            string FormattedMineralTotal = CostPrototyper.CurrentActivity.minerialsCost[MineralIterator].ToString("#,##0");

                            String CostString = String.Format("{0} {1} ({2})", (Constants.Minerals.MinerialNames)MineralIterator, FormattedMineralTotal, CurrentPopulation.Minerials[MineralIterator]);
                            m_oSummaryPanel.SYCRequiredMaterialsListBox.Items.Add(CostString);
                        }
                    }

                    m_oSummaryPanel.SYCBuildCostTextBox.Text = CostPrototyper.CurrentActivity.CostOfActivity.ToString();

                    float YearsOfProduction = (float)CostPrototyper.CurrentActivity.CostOfActivity / CostPrototyper.CalcAnnualSYProduction();
                    if (YearsOfProduction < Constants.Colony.TimerYearMax)
                    {
                        m_oSummaryPanel.SYCCompletionDateTextBox.Text = CostPrototyper.CurrentActivity.CompletionDate.ToShortDateString();
                    }
                    else
                    {
                        m_oSummaryPanel.SYCCompletionDateTextBox.Text = "N/A";
                    }

                    if ((Activity == Constants.ShipyardInfo.ShipyardActivity.Retool && RetoolTarget == null) ||
                        (Activity == Constants.ShipyardInfo.ShipyardActivity.CapExpansionUntilX && (r == false || (NewCapLimit <= SYInfo.Tonnage))))
                    {
                        m_oSummaryPanel.SYCCompletionDateTextBox.Text = "N/A";
                        m_oSummaryPanel.SYCRequiredMaterialsListBox.Items.Clear();
                    }

                    /// <summary>
                    /// This retool is free. or not necessary.
                    /// </summary>
                    if (Activity == Constants.ShipyardInfo.ShipyardActivity.Retool && ((RetoolTarget != null && SYInfo.AssignedClass == null) || RetoolTarget == SYInfo.AssignedClass))
                    {
                        m_oSummaryPanel.SYCBuildCostTextBox.Text = "N/A";
                        m_oSummaryPanel.SYCCompletionDateTextBox.Text = "N/A";
                        m_oSummaryPanel.SYCRequiredMaterialsListBox.Items.Clear();
                    }
                }
                else
                {
                    m_oSummaryPanel.SYCBuildCostTextBox.Text = "N/A";
                    m_oSummaryPanel.SYCCompletionDateTextBox.Text = "N/A";
                    m_oSummaryPanel.SYCRequiredMaterialsListBox.Items.Clear();
                }
            }
        }
Пример #16
0
        /// <summary>
        /// Constructor for basic faction.
        /// </summary>
        /// <param name="ID">placement of this faction in the factionsystemdetection lists. must be in order.</param>
        public Faction(int ID, string name = "Human Federation", Species species = null)
            : base()
        {
            Name = name;
            if (species == null)
                Species = new Species(); // go with the default Species!
            else
                Species = species;

            KnownSystems = new BindingList<StarSystem>();
            TaskForces = new BindingList<TaskForce>();
            Commanders = new BindingList<Commander>();
            Populations = new BindingList<Population>();

            ComponentList = new ComponentDefListTN();
            ShipDesigns = new BindingList<ShipClassTN>();
            TaskGroups = new BindingList<TaskGroupTN>();
            Ships = new BindingList<ShipTN>();
            ComponentList.AddInitialComponents();

            SystemContacts = new Dictionary<StarSystem, FactionSystemDetection>();
            DetectedContactLists = new Dictionary<StarSystem, DetectedContactsList>();

            FactionID = ID;

            InstallationTypes = new BindingList<Installation>();
            for (int loop = 0; loop < (int)Installation.InstallationType.InstallationCount; loop++)
            {
                Installation NewInst = new Installation((Installation.InstallationType)loop);
                InstallationTypes.Add(NewInst);
            }

            MessageLog = new BindingList<MessageEntry>();

            MissileGroups = new BindingList<OrdnanceGroupTN>();

            OrdnanceSeries = new BindingList<OrdnanceSeriesTN>();
            OrdnanceSeriesTN NewOrd = new OrdnanceSeriesTN("No Series Selected");
            OrdnanceSeries.Add(NewOrd);

            BaseTracking = Constants.GameSettings.FactionBaseTrackingSpeed;

            OpenFireFC = new Dictionary<ComponentTN, ShipTN>();
            OpenFireFCType = new Dictionary<ComponentTN, bool>();

            PointDefense = new Dictionary<StarSystem, PointDefenseList>();

            MissileRemoveList = new BindingList<OrdnanceGroupTN>();

            RechargeList = new Dictionary<ShipTN, int>();

            FactionTechLevel = new BindingList<SByte>();

            for (int loop = 0; loop < (int)FactionTechnology.Count; loop++)
            {
                FactionTechLevel.Add(-1);
            }

            /// <summary>
            /// Hardening is a special case that must start at zero and not negative 1.
            /// </summary>
            FactionTechLevel[(int)Faction.FactionTechnology.Hardening] = 0;

            /// <summary>
            /// These are conventional tech starts, each conventional faction starts with them researched.
            /// If anyone has a better idea about how these should be organized feel free, but note that changing this will have repercussions in Component design(specifically components.cs)
            /// </summary>
            FactionTechLevel[(int)Faction.FactionTechnology.ThermalSensorSensitivity] = 0;
            FactionTechLevel[(int)Faction.FactionTechnology.EMSensorSensitivity] = 0;
            FactionTechLevel[(int)Faction.FactionTechnology.FuelConsumption] = 0;
            FactionTechLevel[(int)Faction.FactionTechnology.ThermalReduction] = 0;
            FactionTechLevel[(int)Faction.FactionTechnology.CapacitorChargeRate] = 0;
            FactionTechLevel[(int)Faction.FactionTechnology.EngineBaseTech] = 0;
            FactionTechLevel[(int)Faction.FactionTechnology.ReducedSizeLaunchers] = 0;
            FactionTechLevel[(int)Faction.FactionTechnology.ArmourProtection] = 0;
            FactionTechLevel[(int)Faction.FactionTechnology.WarheadStrength] = 0;
            FactionTechLevel[(int)Faction.FactionTechnology.MissileAgility] = 0;
            FactionTechLevel[(int)Faction.FactionTechnology.TurretTracking] = 0;
            FactionTechLevel[(int)Faction.FactionTechnology.ECCM] = 0;
            FactionTechLevel[(int)Faction.FactionTechnology.DSTSSensorStrength] = 0;
            FactionTechLevel[(int)Faction.FactionTechnology.MinJumpEngineSize] = 0;
            FactionTechLevel[(int)Faction.FactionTechnology.ShipProdRate] = 0;

            ShipBPTotal = Constants.GameSettings.FactionStartingShipBP;
            PDCBPTotal = Constants.GameSettings.FactionStartingPDCBP;


            FactionWealth = Constants.Faction.StartingWealth;

            /// <summary>
            /// Ships and missiles are added to these two binding lists. this is for later to help the detected contact list.
            /// </summary>
            DetShipList = new BindingList<ShipTN>();
            DetMissileList = new BindingList<OrdnanceGroupTN>();
            DetPopList = new BindingList<Population>();

            GameState.Instance.Factions.Add(this);

            foreach (StarSystem system in GameState.Instance.StarSystems)
            {
                AddNewContactList(system);
            }
        }
        /// <summary>
        /// Build the Shipyard task required minerals box.
        /// </summary>
        /// <param name="m_oSummaryPanel">Panel from the economics handler</param>
        /// <param name="CurrentFaction">Currently selected faction.</param>
        /// <param name="CurrentPopulation">Currently selected population</param>
        /// <param name="SYInfo">Currently selected shipyard on currently selected population belonging to currently selected faction</param>
        /// <param name="EligibleClassList">List of shipclasses that this shipyard can produce.</param>
        /// <param name="DamagedShipList">List of damaged ships in orbit.</param>
        /// <param name="ClassesInOrbit">List of shipclasses in orbit around CurrentPopulation.</param>
        /// <param name="ShipsOfClassInOrbit">List of ships in the selected shipclass in orbit around CurrentPopulation.</param> 
        public static void BuildSYTRequiredMinerals(Panels.Eco_Summary m_oSummaryPanel, Faction CurrentFaction, Population CurrentPopulation, Installation.ShipyardInformation SYInfo,
                                                    BindingList<ShipClassTN> EligibleClassList, BindingList<ShipTN> DamagedShipList, BindingList<ShipClassTN> ClassesInOrbit,
                                                    BindingList<ShipTN> ShipsOfClassInOrbit)
        {
            if (m_oSummaryPanel.SYTaskTypeComboBox.SelectedIndex != -1 && m_oSummaryPanel.SYTaskGroupComboBox.SelectedIndex != -1 && SYInfo != null &&
                (m_oSummaryPanel.SYNewClassComboBox.SelectedIndex != -1 || m_oSummaryPanel.RepairRefitScrapShipComboBox.SelectedIndex != -1))
            {
                m_oSummaryPanel.ShipRequiredMaterialsListBox.Items.Clear();

                Installation.ShipyardInformation CostPrototyper = new Installation.ShipyardInformation(CurrentFaction, SYInfo.ShipyardType,1);
                CostPrototyper.Tonnage = SYInfo.Tonnage;
                CostPrototyper.Slipways = SYInfo.Slipways;
                CostPrototyper.ModRate = SYInfo.ModRate;
                CostPrototyper.AssignedClass = SYInfo.AssignedClass;

                ShipTN CurrentShip = null;
                ShipClassTN ConstructRefit = null;
                TaskGroupTN TargetTG = null;
                int TGIndex = -1;

                /// <summary>
                /// I'm not storing a faction only list of taskgroups in orbit anywhere, so lets calculate that here.
                /// </summary>
                foreach (TaskGroupTN CurrentTaskGroup in CurrentPopulation.Planet.TaskGroupsInOrbit)
                {
                    if (CurrentTaskGroup.TaskGroupFaction == CurrentFaction)
                    {
                        if (TGIndex == m_oSummaryPanel.SYTaskGroupComboBox.SelectedIndex)
                        {
                            TargetTG = CurrentTaskGroup;
                            break;
                        }
                        TGIndex++;
                    }
                }

                /// <summary>
                /// No TG was found so create one, the shipyard will want a tg in any event.
                /// </summary>
                if (TGIndex == -1)
                {
                    CurrentFaction.AddNewTaskGroup("Shipyard TG", CurrentPopulation.Planet, CurrentPopulation.Planet.Position.System);

                    /// <summary>
                    /// Run this loop again as a different faction could have a taskgroup in orbit.
                    /// </summary>
                    foreach (TaskGroupTN CurrentTaskGroup in CurrentPopulation.Planet.TaskGroupsInOrbit)
                    {
                        if (CurrentTaskGroup.TaskGroupFaction == CurrentFaction)
                        {
                            TGIndex++;
                            if (TGIndex == m_oSummaryPanel.SYTaskGroupComboBox.SelectedIndex)
                            {
                                TargetTG = CurrentTaskGroup;
                                break;
                            }
                        }
                    }
                }

                Constants.ShipyardInfo.Task SYITask = (Constants.ShipyardInfo.Task)m_oSummaryPanel.SYTaskTypeComboBox.SelectedIndex;


                int BaseBuildRate = SYInfo.CalcShipBuildRate(CurrentFaction, CurrentPopulation);

                if ((int)SYITask != -1)
                {
                    switch (SYITask)
                    {
                        case Constants.ShipyardInfo.Task.Construction:
                            int newShipIndex = m_oSummaryPanel.SYNewClassComboBox.SelectedIndex;
                            if (newShipIndex != -1 && EligibleClassList.Count > newShipIndex)
                            {
                                ConstructRefit = EligibleClassList[newShipIndex];
                            }
                            break;
                        case Constants.ShipyardInfo.Task.Repair:
                            int CurrentShipIndex = m_oSummaryPanel.RepairRefitScrapShipComboBox.SelectedIndex;
                            if (CurrentShipIndex != -1 && DamagedShipList.Count > CurrentShipIndex)
                            {
                                CurrentShip = DamagedShipList[CurrentShipIndex];
                            }
                            break;
                        case Constants.ShipyardInfo.Task.Refit:
                            newShipIndex = m_oSummaryPanel.SYNewClassComboBox.SelectedIndex;
                            if (newShipIndex != -1 && EligibleClassList.Count > newShipIndex)
                            {
                                ConstructRefit = EligibleClassList[newShipIndex];
                            }

                            CurrentShipIndex = m_oSummaryPanel.RepairRefitScrapShipComboBox.SelectedIndex;
                            if (CurrentShipIndex != -1 && ShipsOfClassInOrbit.Count > CurrentShipIndex)
                            {
                                CurrentShip = ShipsOfClassInOrbit[CurrentShipIndex];
                            }
                            break;
                        case Constants.ShipyardInfo.Task.Scrap:
                            CurrentShipIndex = m_oSummaryPanel.RepairRefitScrapShipComboBox.SelectedIndex;
                            if (CurrentShipIndex != -1 && ShipsOfClassInOrbit.Count > CurrentShipIndex)
                            {
                                CurrentShip = ShipsOfClassInOrbit[CurrentShipIndex];
                            }
                            break;
                    }

                    /// <summary>
                    /// Faction swapping can cause some problems.
                    /// </summary>
                    if (CurrentShip == null && ConstructRefit == null)
                        return;

                    Installation.ShipyardInformation.ShipyardTask NewTask = new Installation.ShipyardInformation.ShipyardTask(CurrentShip, SYITask, TargetTG, BaseBuildRate, m_oSummaryPanel.SYShipNameTextBox.Text, ConstructRefit);
                    CostPrototyper.BuildingShips.Add(NewTask);

                    m_oSummaryPanel.SYTaskCostTextBox.Text = CostPrototyper.BuildingShips[0].Cost.ToString();
                    m_oSummaryPanel.SYTaskCompletionDateTextBox.Text = CostPrototyper.BuildingShips[0].CompletionDate.ToShortDateString();

                    for (int MineralIterator = 0; MineralIterator < Constants.Minerals.NO_OF_MINERIALS; MineralIterator++)
                    {

                        if (CostPrototyper.BuildingShips[0].minerialsCost[MineralIterator] != 0.0m)
                        {
                            string FormattedMineralTotal = CostPrototyper.BuildingShips[0].minerialsCost[MineralIterator].ToString("#,##0");

                            String CostString = String.Format("{0} {1} ({2})", (Constants.Minerals.MinerialNames)MineralIterator, FormattedMineralTotal, CurrentPopulation.Minerials[MineralIterator]);
                            m_oSummaryPanel.ShipRequiredMaterialsListBox.Items.Add(CostString);
                        }
                    }
                }
            }
            else
            {
                /// <summary>
                /// There is no cost to calculate so print this instead.
                /// </summary>
                m_oSummaryPanel.SYTaskCostTextBox.Text = "N/A";
                m_oSummaryPanel.SYTaskCompletionDateTextBox.Text = "N/A";
                m_oSummaryPanel.ShipRequiredMaterialsListBox.Items.Clear();
            }
        }
Пример #18
0
 /// <summary>
 /// Constructor for Installations.
 /// </summary>
 /// <param name="InstallationToBuild">Installation to build</param>
 public ConstructionBuildQueueItem(Installation InstallationToBuild)
 {
     m_BuildType         = CBType.PlanetaryInstallation;
     m_InstallationBuild = InstallationToBuild;
 }