/// <summary> /// LoadComponents picks up a set number of components from population pop's component stockpile. /// </summary> /// <param name="Pop">Population of the component pickup.</param> /// <param name="ComponentIndex">location in pop.ComponentStockpile.</param> /// <param name="Limit">Number of said components to pick up if not all of them.</param> public void LoadComponents(Population Pop, int ComponentIndex, int Limit) { int RemainingTonnage = TotalCargoTonnage - CurrentCargoTonnage; int TotalMass = (int)(Pop.ComponentStockpile[ComponentIndex].size * Constants.ShipTN.TonsPerHS * (float)Limit); int AvailableMass = (int)(Pop.ComponentStockpile[ComponentIndex].size * Constants.ShipTN.TonsPerHS * Pop.ComponentStockpileCount[ComponentIndex]); int MassToLoad = 0; /// <summary> /// In this case load as much as possible up to AvailableMass. /// </summary> if (Limit == 0) { MassToLoad = Math.Min(RemainingTonnage, AvailableMass); } /// <summary> /// In this case only load up to Total mass. /// </summary> else { MassToLoad = Math.Min(RemainingTonnage, TotalMass); } /// <summary> /// All of these may not be loaded. float ComponentLoadCount = (float)MassToLoad / (Pop.ComponentStockpile[ComponentIndex].size * Constants.ShipTN.TonsPerHS); for (int loop = 0; loop < Ships.Count; loop++) { if (Ships[loop].ShipClass.TotalCargoCapacity != 0) { int RemainingShipTonnage = Ships[loop].ShipClass.TotalCargoCapacity - Ships[loop].CurrentCargoTonnage; int ShipMassToLoad = Math.Min(MassToLoad, RemainingShipTonnage); float ShipComponentLoadCount = (float)ShipMassToLoad / (Pop.ComponentStockpile[ComponentIndex].size * Constants.ShipTN.TonsPerHS); /// <summary> /// Don't break up these components. /// </summary> if (Pop.ComponentStockpile[ComponentIndex].isDivisible == false) { ShipComponentLoadCount = (float)Math.Floor(ShipComponentLoadCount); } /// <summary> /// Tell the population to remove the specified components. ComponentLoadCount may be too high, in which case the lower value will be returned. /// Likewise mass to load will be updated based on this. /// </summary> ShipComponentLoadCount = Pop.TakeComponentsFromStockpile(Pop.ComponentStockpile[ComponentIndex], ShipComponentLoadCount); ShipMassToLoad = (int)(ShipComponentLoadCount * (Pop.ComponentStockpile[ComponentIndex].size * Constants.ShipTN.TonsPerHS)); if (Ships[loop].CargoComponentList.ContainsKey(Pop.ComponentStockpile[ComponentIndex])) { CargoListEntryTN CLE = Ships[loop].CargoComponentList[Pop.ComponentStockpile[ComponentIndex]]; CLE.tons = CLE.tons + ShipMassToLoad; } else { CargoListEntryTN CargoListEntry = new CargoListEntryTN(Pop.ComponentStockpile[ComponentIndex], ShipMassToLoad); Ships[loop].CargoComponentList.Add(Pop.ComponentStockpile[ComponentIndex], CargoListEntry); } /// <summary> /// CurrentCargoTonnage has to be added here, as non-divisible components may not be loadable. /// </summary> CurrentCargoTonnage = CurrentCargoTonnage + ShipMassToLoad; Ships[loop].CurrentCargoTonnage = Ships[loop].CurrentCargoTonnage + ShipMassToLoad; MassToLoad = MassToLoad - ShipMassToLoad; } } }
/// <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; } } }