/// <summary> /// Attempts to ad numToAdd objects of CargoType type /// Returns true if succesful /// </summary> /// <param name="type"></param> /// <param name="numToAdd"></param> /// <returns></returns> public override CargoResult AddStatelessCargo(StatelessCargoTypes type, float numToAdd, bool suspendBoundsChecking) { if (_model.StatelessCargo.ContainsKey(type))//If there is already at least one of this item type on the ship { _model.StatelessCargo[type].Quantity += numToAdd; } else { _model.StatelessCargo.Add(type, new StatelessCargo(type, numToAdd)); } _model.FilledHolds += numToAdd * StatelessCargo.SpacePerObject(type); if (StatelessCargoPriceGetter != null) { SetCargoPurchasePrice(PortHelper.GetPortWareIdentifier(type), StatelessCargoPriceGetter(new StatelessCargo(_model.StatelessCargo[type]), PriceType.PortPurchasing)); SetCargoSalePrice(PortHelper.GetPortWareIdentifier(type), StatelessCargoPriceGetter(new StatelessCargo(_model.StatelessCargo[type]), PriceType.PortSelling)); } PortWareIdentifier portGoodIdentifier; if (Enum.TryParse(type.ToString(), out portGoodIdentifier)) { UpdateGoodCounts(portGoodIdentifier, numToAdd); UpdateUIStatLists(portGoodIdentifier, _model.StatelessCargo[type]); } return(CargoResult.Success); }
public virtual bool CheckCargoSpace(Dictionary <StatelessCargoTypes, float> typesAndQuantities, ref float spaceOccupied) { foreach (var t in typesAndQuantities) { spaceOccupied += StatelessCargo.SpacePerObject(t.Key) * t.Value; } return(spaceOccupied <= _model.TotalHolds - _model.FilledHolds); }
/// <summary> /// Checks to see if the ship has the cargo type and whether it has at least numToRemove /// Returns true is remove is succesful /// </summary> /// <param name="type"></param> /// <param name="numToRemove"></param> /// <returns></returns> public override CargoResult RemoveStatelessCargo(StatelessCargoTypes type, float numToRemove) { CargoResult result; if (!_model.StatelessCargo.ContainsKey(type)) { result = CargoResult.CargoNotInHolds; } else if (_model.StatelessCargo[type].Quantity > numToRemove)//At least one item will remain { _model.StatelessCargo[type].Quantity -= numToRemove; _model.FilledHolds -= numToRemove * StatelessCargo.SpacePerObject(type); if (StatelessCargoPriceGetter != null) { SetCargoPurchasePrice(PortHelper.GetPortWareIdentifier(type), StatelessCargoPriceGetter(new StatelessCargo(_model.StatelessCargo[type]), PriceType.PortPurchasing)); SetCargoSalePrice(PortHelper.GetPortWareIdentifier(type), StatelessCargoPriceGetter(new StatelessCargo(_model.StatelessCargo[type]), PriceType.PortSelling)); } result = CargoResult.Success; } else if (_model.StatelessCargo[type].Quantity == numToRemove)//Last item will be removed { _model.StatelessCargo.Remove(type); _model.FilledHolds -= numToRemove * StatelessCargo.SpacePerObject(type); _model.Prices_ShipSaleToPort.Remove(PortHelper.GetPortWareIdentifier(type)); result = CargoResult.Success; } result = CargoResult.CargoNotInHolds; if (result == CargoResult.Success) { PortWareIdentifier identifier; if (Enum.TryParse(type.ToString(), out identifier)) { UpdateGoodCounts(identifier, -numToRemove); } } return(result); }
/// <summary> /// Checks to see if the ship has the cargo type and whether it has at least numToRemove /// Returns true is remove is succesful /// </summary> /// <param name="type"></param> /// <param name="numToRemove"></param> /// <returns></returns> public virtual CargoResult RemoveStatelessCargo(StatelessCargoTypes type, float numToRemove) { if (!_model.StatelessCargo.ContainsKey(type)) { return(CargoResult.CargoNotInHolds); } else if (_model.StatelessCargo[type].Quantity > numToRemove)//At least one item will remain { _model.StatelessCargo[type].Quantity -= numToRemove; _model.FilledHolds -= numToRemove * StatelessCargo.SpacePerObject(type); return(CargoResult.Success); } else if (_model.StatelessCargo[type].Quantity == numToRemove)//Last item will be removed { _model.StatelessCargo.Remove(type); _model.FilledHolds -= numToRemove * StatelessCargo.SpacePerObject(type); return(CargoResult.Success); } return(CargoResult.CargoNotInHolds); }
/// <summary> /// Attempts to add numToAdd objects of CargoType type. If suspendBoundsChecking, cargo is added without checking cargo space. Used for temporarily overflowing trades /// Returns true if succesful /// </summary> /// <param name="type"></param> /// <param name="numToAdd"></param> /// <returns></returns> public virtual CargoResult AddStatelessCargo(StatelessCargoTypes type, float numToAdd, bool suspendBoundsChecking) { #if !ADMIN if (suspendBoundsChecking || CheckCargoSpace(type, numToAdd))//Check if there is enough space to add the cargo { #endif if (_model.StatelessCargo.ContainsKey(type))//If there is already at least one of this item type on the ship { _model.StatelessCargo[type].Quantity += numToAdd; } else { _model.StatelessCargo.Add(type, new StatelessCargo(type, numToAdd)); } _model.FilledHolds += numToAdd * StatelessCargo.SpacePerObject(type); return(CargoResult.Success); #if !ADMIN } return(CargoResult.NotEnoughCargoSpace); #endif }
/// <summary> /// Checks if there is enough cargo space to add spaceOccupied + cargo space occupied by the specified cargo /// Increments spaceOccupied. /// returns true if there is enough space /// </summary> /// <param name="type"></param> /// <param name="quantity"></param> /// <param name="spaceOccupied">Adds the space occupied by the specified cargo</param> /// <returns></returns> public virtual bool CheckCargoSpace(StatelessCargoTypes type, float quantity, ref float spaceOccupied) { spaceOccupied += quantity * StatelessCargo.SpacePerObject(type); return(spaceOccupied <= _model.TotalHolds - _model.FilledHolds); }