/// <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(); } }
/// <summary> /// Build, repair, refit, or scrap a ship at the selected shipyard. This will put the specified ship's taskgroup into the shipyard, which should prevent it from carrying out orders. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddTaskButton_Click(object sender, EventArgs e) { /// <summary> /// This index should never ever be -1. /// </summary> if (m_oSummaryPanel.SYTaskTypeComboBox.SelectedIndex != -1 && m_oSummaryPanel.SYTaskGroupComboBox.SelectedIndex != -1 && CurrentSYInfo != null && CurrentPopulation != null && CurrentFaction != null && (m_oSummaryPanel.SYNewClassComboBox.SelectedIndex != -1 || m_oSummaryPanel.RepairRefitScrapShipComboBox.SelectedIndex != -1)) { m_oSummaryPanel.ShipRequiredMaterialsListBox.Items.Clear(); 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) { TGIndex++; if (TGIndex == m_oSummaryPanel.SYTaskGroupComboBox.SelectedIndex) { TargetTG = CurrentTaskGroup; break; } } } /// <summary> /// Ok, if there is no TG then one needs to be created here. /// </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 = CurrentSYInfo.CalcShipBuildRate(CurrentFaction, CurrentPopulation); if ((int)SYITask != -1) { switch ((Constants.ShipyardInfo.Task)SYITask) { case Constants.ShipyardInfo.Task.Construction: int newShipIndex = m_oSummaryPanel.SYNewClassComboBox.SelectedIndex; if (newShipIndex != -1) { ConstructRefit = EligibleClassList[newShipIndex]; } break; case Constants.ShipyardInfo.Task.Repair: int CurrentShipIndex = m_oSummaryPanel.RepairRefitScrapShipComboBox.SelectedIndex; if (CurrentShipIndex != -1) { CurrentShip = DamagedShipList[CurrentShipIndex]; } break; case Constants.ShipyardInfo.Task.Refit: newShipIndex = m_oSummaryPanel.SYNewClassComboBox.SelectedIndex; if (newShipIndex != -1) { ConstructRefit = EligibleClassList[newShipIndex]; } CurrentShipIndex = m_oSummaryPanel.RepairRefitScrapShipComboBox.SelectedIndex; if (CurrentShipIndex != -1) { CurrentShip = ShipsOfClassInOrbit[CurrentShipIndex]; } break; case Constants.ShipyardInfo.Task.Scrap: CurrentShipIndex = m_oSummaryPanel.RepairRefitScrapShipComboBox.SelectedIndex; if (CurrentShipIndex != -1) { CurrentShip = ShipsOfClassInOrbit[CurrentShipIndex]; } break; } /// <summary> /// if a slipway is available build the new ship. /// </summary> if (CurrentSYInfo.Slipways > CurrentSYInfo.BuildingShips.Count) { Installation.ShipyardInformation.ShipyardTask NewTask = new Installation.ShipyardInformation.ShipyardTask(CurrentShip, SYITask, TargetTG, BaseBuildRate, m_oSummaryPanel.SYShipNameTextBox.Text, ConstructRefit); CurrentSYInfo.BuildingShips.Add(NewTask); CurrentPopulation.ShipyardTasks.Add(NewTask, CurrentSYInfo); /// <summary> /// Cost display for the new order. /// </summary> m_oSummaryPanel.SYTaskCostTextBox.Text = CurrentSYInfo.BuildingShips[0].Cost.ToString(); m_oSummaryPanel.SYTaskCompletionDateTextBox.Text = CurrentSYInfo.BuildingShips[0].CompletionDate.ToShortDateString(); for (int MineralIterator = 0; MineralIterator < Constants.Minerals.NO_OF_MINERIALS; MineralIterator++) { if (CurrentSYInfo.BuildingShips[0].minerialsCost[MineralIterator] != 0.0m) { string FormattedMineralTotal = CurrentSYInfo.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); } } /// <summary> /// So. I want the eco_SY tab handler to be able to populate these lists as needed. /// So. they have to be refs. /// But they are properties. /// So kludge. /// </summary> BindingList<ShipClassTN> ECL = EligibleClassList; BindingList<ShipClassTN> CIO = ClassesInOrbit; BindingList<ShipTN> DSL = DamagedShipList; BindingList<ShipTN> SCO = ShipsOfClassInOrbit; Eco_ShipyardTabHandler.RefreshShipyardTab(m_oSummaryPanel, CurrentFaction, CurrentPopulation, CurrentSYInfo, PotentialRetoolTargets, ref ECL, ref DSL, ref CIO, ref SCO); EligibleClassList = ECL; ClassesInOrbit = CIO; DamagedShipList = DSL; ShipsOfClassInOrbit = SCO; } } } }