/// <summary> /// Constructor for Component transfers. /// </summary> /// <param name="Type">Type of component</param> /// <param name="SizeInTons">Tons of said component</param> public CargoListEntryTN(ComponentDefTN Type, int SizeInTons) { CargoComponentType = Type; Tons = SizeInTons; }
/// <summary> /// Fill in the information about this row given a component, row number, rating strings, and the component iterator /// </summary> /// <param name="Comp">Component to add.</param> /// <param name="row">Row number.</param> /// <param name="RateType">Rating Type string.</param> /// <param name="RateValue">Rating Value String.</param> /// <param name="ComponentIterator">Component iterator, its place in its respective list in ComponentListTN.cs</param> private void PopulateComponentRow(ComponentDefTN Comp, int row, String RateType, String RateValue, int ComponentIterator, bool Insert = false) { using (DataGridViewRow NewRow = new DataGridViewRow()) { /// <summary> /// setup row height. note that by default they are 22 pixels in height! /// </summary> NewRow.Height = 18; if(Insert == false) m_oOptionsPanel.ComponentDataGrid.Rows.Add(NewRow); else m_oOptionsPanel.ComponentDataGrid.Rows.Insert(row, NewRow); m_oOptionsPanel.ComponentDataGrid.Rows[row].Cells[(int)ComponentCell.Name].Value = Comp.Name; m_oOptionsPanel.ComponentDataGrid.Rows[row].Cells[(int)ComponentCell.RatingType].Value = RateType; m_oOptionsPanel.ComponentDataGrid.Rows[row].Cells[(int)ComponentCell.Rating].Value = RateValue; m_oOptionsPanel.ComponentDataGrid.Rows[row].Cells[(int)ComponentCell.Cost].Value = Comp.cost.ToString(); m_oOptionsPanel.ComponentDataGrid.Rows[row].Cells[(int)ComponentCell.Size].Value = (Comp.size * Constants.ShipTN.TonsPerHS).ToString(); m_oOptionsPanel.ComponentDataGrid.Rows[row].Cells[(int)ComponentCell.Crew].Value = Comp.crew; m_oOptionsPanel.ComponentDataGrid.Rows[row].Cells[(int)ComponentCell.Materials].Value = BuildMineralCost(Comp); m_oOptionsPanel.ComponentDataGrid.Rows[row].Cells[(int)ComponentCell.CType].Value = ((int)Comp.componentType).ToString(); m_oOptionsPanel.ComponentDataGrid.Rows[row].Cells[(int)ComponentCell.CIndex].Value = ComponentIterator; m_oOptionsPanel.ComponentDataGrid.Rows[row].Cells[(int)ComponentCell.Obsolete].Value = Comp.isObsolete.ToString(); TotalComponents = TotalComponents + 1; } }
/// <summary> /// Builds the mineral cost for AuroraTN components. /// </summary> /// <param name="Comp">Component whos cost I want.</param> /// <returns>Mineral cost string.</returns> private String BuildMineralCost(ComponentDefTN Comp) { String MineralString = ""; for (int mineralIterator = 1; mineralIterator < (int)Constants.Minerals.MinerialNames.MinerialCount; mineralIterator++) { if (Comp.minerialsCost[mineralIterator] != 0) { MineralString = String.Format("{0} {1:N2}x {2}", MineralString, Comp.minerialsCost[mineralIterator], (Constants.Minerals.MinerialNames)mineralIterator); } } return MineralString; }
public CargoListEntryTN(ComponentDefTN Type, int SizeInTons) { CargoComponentType = Type; Tons = SizeInTons; }
/// <summary> /// General Class update function, many things will change as a result of adding components, this function handles them all. /// I think this function might be enough to handle subtracting components as well. Update: now subtracting. /// </summary> /// <param name="Component">Basic abstract class definition of the added component.</param> /// <param name="increment">The number of new components to be added.</param> /// <param name="isElectronic">Whether or not this component should go in the EDAC</param> private void UpdateClass(ComponentDefTN Component, short increment) { int CIndex = ListOfComponentDefs.IndexOf(Component); if (CIndex != -1) { ListOfComponentDefsCount[CIndex] = (short)(ListOfComponentDefsCount[CIndex] + increment); } if (CIndex == -1 && increment >= 1) { /// <summary> /// The damage allocation chart values will be recalculated later in this very function. A DAC of -1 is obviously indicative of an error. /// </summary> ListOfComponentDefs.Add(Component); ListOfComponentDefsCount.Add(increment); DamageAllocationChart.Add(Component, -1); if (Component.isElectronic == true) { ElectronicDamageAllocationChart.Add(Component, -1); } } else { if (CIndex != -1) { if (ListOfComponentDefsCount[CIndex] <= 0) { DamageAllocationChart.Remove(ListOfComponentDefs[CIndex]); if (Component.isElectronic == true) { ElectronicDamageAllocationChart.Remove(ListOfComponentDefs[CIndex]); } ListOfComponentDefsCount.RemoveAt(CIndex); ListOfComponentDefs.RemoveAt(CIndex); } } else { /// <summary> /// This is an error condition that may need to be handled at some point. /// </summary> return; } } /// <summary> /// Size of the craft has to be adjusted /// </summary> SizeHS = SizeHS + (Component.size * (float)increment); SizeTons = SizeHS * 50.0f; /// <summary> /// The ship has a new total required crew now. /// </summary> TotalRequiredCrew = TotalRequiredCrew + (Component.crew * increment); AccomHSRequirement = (((float)TotalRequiredCrew * TonsPerMan) / 50.0f); SpareCrewQuarters = TotalCrewQuarters - TotalRequiredCrew; /// <summary> /// The Cost of the ship has likewise gone up. /// </summary> BuildPointCost = BuildPointCost + (Component.cost * increment); /// <summary> /// Mineral cost is similarly increased. /// </summary> for(int mineralIterator = 0; mineralIterator < (int)Constants.Minerals.MinerialNames.MinerialCount; mineralIterator++) { m_aiMinerialsCost[mineralIterator] = m_aiMinerialsCost[mineralIterator] + (Component.minerialsCost[mineralIterator] * increment); } /// <summary> /// Update TotalHTK /// </summary> TotalHTK = TotalHTK + (Component.htk * increment); /// <summary> /// Update Military status. Does this craft suffer maintenance failures? /// </summary> if (Component.isMilitary == true) { MilitaryComponentCount = MilitaryComponentCount + increment; if (MilitaryComponentCount > 0) IsMilitary = true; else IsMilitary = false; } /// <summary> /// Armor requires that size and cost be subtracted from the ship before recalculation/readding. /// </summary> BuildPointCost = BuildPointCost - ShipArmorDef.cost; SizeHS = SizeHS - ShipArmorDef.size; ShipArmorDef.CalcArmor(ShipArmorDef.Name, ShipArmorDef.armorPerHS, SizeHS, ShipArmorDef.depth); BuildPointCost = BuildPointCost + ShipArmorDef.cost; SizeHS = SizeHS + ShipArmorDef.size; /// <summary> /// Due to the change in size the cross section will be different. /// </summary> TotalCrossSection = (int)Math.Ceiling(SizeHS); /// <summary> /// Likewise speed shall change. /// </summary> if (TotalCrossSection != 0) { if (ShipEngineDef != null) { MaxSpeed = (int)((1000.0f / (float)TotalCrossSection) * (float)MaxEnginePower); } else MaxSpeed = 1; } else { MaxSpeed = 0; } /// <summary> /// MSP capacity and later maintenance will change. ***The rest of maintenance is not yet finished***. /// </summary> if (EngineeringHS == 0.0f) { TotalMSPCapacity = 0; } else { TotalMSPCapacity = (int)((float)BuildPointCost * ((EngineeringHS / SizeHS) / 0.08f)); } /// <summary> /// Max repair can change. /// </summary> if (Component.cost > MaxRepair && increment >= 1) { MaxRepair = (int)Component.cost; } else { CIndex = ListOfComponentDefs.IndexOf(Component); if (CIndex == -1) { decimal tempCost = 0.0m; for (int loop = 0; loop < ListOfComponentDefs.Count; loop++) { if (ListOfComponentDefs[loop].cost > tempCost) { tempCost = ListOfComponentDefs[loop].cost; } } MaxRepair = (int)tempCost; } } CargoLoadTime = (TotalCargoCapacity * Constants.ShipTN.BaseCargoLoadTimePerTon) / TractorMultiplier; CryoLoadTime = (SpareCryoBerths * Constants.ShipTN.BaseCryoLoadTimePerPerson) / TractorMultiplier; TroopLoadTime = (TotalTroopCapacity * Constants.ShipTN.BaseTroopLoadTime) / TractorMultiplier; /// <summary> /// This code recalculates the entire DAC and EDAC every time a component is added or subtracted from the design. /// </summary> int DAC = 0; int EDAC = 0; for (int loop = 0; loop < ListOfComponentDefs.Count; loop++) { if (ListOfComponentDefs[loop].size < 1.0) { int localDAC = ListOfComponentDefsCount[loop]; DamageAllocationChart[ListOfComponentDefs[loop]] = localDAC + DAC; DAC = DAC + localDAC; if (ListOfComponentDefs[loop].isElectronic == true) { ElectronicDamageAllocationChart[ListOfComponentDefs[loop]] = localDAC + EDAC; EDAC = EDAC + localDAC; } } else { int localDAC = (int)(Math.Floor(ListOfComponentDefs[loop].size)) * ListOfComponentDefsCount[loop]; DamageAllocationChart[ListOfComponentDefs[loop]] = localDAC + DAC; DAC = DAC + localDAC; if (ListOfComponentDefs[loop].isElectronic == true) { ElectronicDamageAllocationChart[ListOfComponentDefs[loop]] = localDAC + EDAC; EDAC = EDAC + localDAC; } } } /// <summary> /// Ordnance Section /// </summary> while (TotalMagazineCapacity < PreferredOrdnanceSize) { int overrun = PreferredOrdnanceSize - TotalMagazineCapacity; foreach (KeyValuePair<OrdnanceDefTN, int> pair in ShipClassOrdnance) { int MissileSizeInMagazine = (int)Math.Ceiling(pair.Key.size); int SCOSize = (MissileSizeInMagazine * pair.Value); if (SCOSize <= overrun) { ShipClassOrdnance.Remove(pair.Key); overrun = overrun - SCOSize; PreferredOrdnanceSize = PreferredOrdnanceSize - SCOSize; PreferredOrdnanceCost = PreferredOrdnanceCost - (pair.Value * pair.Key.cost); break; } else { int reduction = (int)Math.Ceiling((float)(overrun) / (float)MissileSizeInMagazine); ShipClassOrdnance[pair.Key] = ShipClassOrdnance[pair.Key] - reduction; PreferredOrdnanceSize = PreferredOrdnanceSize - (reduction * MissileSizeInMagazine); PreferredOrdnanceCost = PreferredOrdnanceCost - (reduction * pair.Key.cost); break; } } } BuildClassSummary(); }
/// <summary> /// Unloads the specified component to population pop. /// </summary> /// <param name="Pop">Population receiving shipment.</param> /// <param name="Component">Component to be unloaded. I'm not particularly happy with how this is being done right now.</param> /// <param name="Limit">Limit to unloading.</param> public void UnloadComponents(Population Pop, ComponentDefTN Component, int Limit) { int TotalMass = (int)(Component.size * Constants.ShipTN.TonsPerHS * (float)Limit); for (int loop = 0; loop < Ships.Count; loop++) { if (Ships[loop].CurrentCargoTonnage != 0 && Ships[loop].CargoComponentList.ContainsKey(Component) == true) { CargoListEntryTN CLE = Ships[0].CargoComponentList[Component]; int ShipMassToUnload; /// <summary> /// Limit == 0 means unload all, else unload to limit if limit is lower than total tonnage. /// </summary> if (Limit == 0) { ShipMassToUnload = CLE.tons; } else { ShipMassToUnload = Math.Min(CLE.tons, TotalMass); TotalMass = TotalMass - ShipMassToUnload; } if (ShipMassToUnload == CLE.tons) { Ships[0].CargoComponentList.Remove(Component); } CLE.tons = CLE.tons - ShipMassToUnload; CurrentCargoTonnage = CurrentCargoTonnage - ShipMassToUnload; float ComponentUnloadCount = (float)(ShipMassToUnload / (Component.size * Constants.ShipTN.TonsPerHS)); Pop.AddComponentsToStockpile(Component, ComponentUnloadCount); } } }
/// <summary> /// TakeComponents from Stockpile takes the specified number of components out of the stockpile, and returns how many were subtracted. /// </summary> /// <param name="ComponentDef">Component def to be removed.</param> /// <param name="decrement">number to remove</param> /// <returns>number that were removed.</returns> public float TakeComponentsFromStockpile(ComponentDefTN ComponentDef, float decrement) { float Components = 0.0f; if (ComponentStockpileLookup.ContainsKey(ComponentDef.Id) == true) { Components = ComponentStockpileCount[ComponentStockpileLookup[ComponentDef.Id]]; if (Components - decrement <= 0.0f) { ComponentStockpile.RemoveAt(ComponentStockpileLookup[ComponentDef.Id]); ComponentStockpileCount.RemoveAt(ComponentStockpileLookup[ComponentDef.Id]); ComponentStockpileLookup.Remove(ComponentDef.Id); return Components; } else { Components = Components - decrement; ComponentStockpileCount[ComponentStockpileLookup[ComponentDef.Id]] = Components; } } else { /// <summary> /// Invalid remove request sent from somewhere. Error reporting? logs? /// </summary> return -1.0f; } return decrement; }
/// <summary> /// Add Components to stockpile places increment number of componentDefs into the planetary stockpile. /// </summary> /// <param name="ComponentDef">Component to be added. This is the class all components inherit from, not any particular type of component.</param> /// <param name="increment">Number to add to the stockpile.</param> public void AddComponentsToStockpile(ComponentDefTN ComponentDef, float increment) { if (ComponentStockpileLookup.ContainsKey(ComponentDef.Id) == true) { ComponentStockpileCount[ComponentStockpileLookup[ComponentDef.Id]] = ComponentStockpileCount[ComponentStockpileLookup[ComponentDef.Id]] + increment; } else { ComponentStockpile.Add(ComponentDef); ComponentStockpileCount.Add(increment); ComponentStockpileLookup.Add(ComponentDef.Id, ComponentStockpile.IndexOf(ComponentDef)); } }
/// <summary> /// Constructor for ship components. /// </summary> /// <param name="ComponentToBuild">Ship Component to build</param> public ConstructionBuildQueueItem(ComponentDefTN ComponentToBuild) : base() { Name = ComponentToBuild.Name; numToBuild = 0.0f; buildCapacity = 0.0f; productionRate = 0.0f; costPerItem = ComponentToBuild.cost; m_BuildType = CBType.ShipComponent; m_ComponentBuild = ComponentToBuild; }
/// <summary> /// Add a component to the build queue. /// </summary> /// <param name="ComponentDef">Component to add.</param> /// <param name="BuildAmt">number of components to construct.</param> /// <param name="RequestedBuildPercentage">Percent of construction factories, conventional industry, engineering teams to devote to construction.</param> public void BuildQueueAddComponent(ComponentDefTN ComponentDef, float BuildAmt, float RequestedBuildPercentage) { ConstructionBuildQueueItem NewCBQItem = new ConstructionBuildQueueItem(ComponentDef); NewCBQItem.UpdateBuildQueueInfo(BuildAmt, RequestedBuildPercentage, true,ComponentDef.cost); ConstructionBuildQueue.Add(NewCBQItem); }