/// <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();
            }
        }
예제 #2
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;
        }
        /// <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();
                }
            }
        }
예제 #4
0
        /// <summary>
        /// start without TN technology.
        /// </summary>
        public void ConventionalStart()
        {
            Installations[(int)Installation.InstallationType.ConventionalIndustry].Number = 1000.0f;
            Installations[(int)Installation.InstallationType.DeepSpaceTrackingStation].Number = 1.0f;
            Installations[(int)Installation.InstallationType.MilitaryAcademy].Number = 1.0f;
            Installations[(int)Installation.InstallationType.NavalShipyardComplex].Number = 1.0f;

            Installation.ShipyardInformation SYI = new Installation.ShipyardInformation(Faction, Constants.ShipyardInfo.SYType.Naval, 1);

            Installations[(int)Installation.InstallationType.NavalShipyardComplex].SYInfo.Add(SYI);

            Faction.AddNewTaskGroup("Shipyard TG", Planet, Planet.Position.System);

            Installations[(int)Installation.InstallationType.MaintenanceFacility].Number = 5.0f;
            Installations[(int)Installation.InstallationType.ResearchLab].Number = 5.0f;

            FuelStockpile = 0.0f;
            MaintenanceSupplies = 2000.0f;

            CivilianPopulation = 500.0f;

            IsRefining = true;

            /// <summary>
            /// A DSTS was given to this population, so tell the UI to display it.
            /// </summary>
            _SensorUpdateAck++; 
        }