Exemplo n.º 1
0
        /// <summary>
        /// Add or removes cargo from storage, ignores transfer rate.
        /// </summary>
        /// <param name="cargoItem"></param>
        /// <param name="mass">negitive to remove</param>
        /// <returns>amount succesfully added or removed</returns>
        internal double AddRemoveCargoByMass(ICargoable cargoItem, double mass)
        {
            //check we're actualy capable of

            if (!TypeStores.ContainsKey(cargoItem.CargoTypeID))
            {
                var    type      = StaticRefLib.StaticData.CargoTypes[cargoItem.CargoTypeID];
                string errString = "Can't add or remove " + cargoItem.Name + " because this entity cannot even store " + type.Name + " types of cargo";
                StaticRefLib.EventLog.AddPlayerEntityErrorEvent(OwningEntity, errString);
                return(0);
            }
            TypeStore store = TypeStores[cargoItem.CargoTypeID];


            double unitsToTryStore = cargoItem.MassPerUnit * mass;
            double unitsStorable   = store.FreeVolume / cargoItem.VolumePerUnit;

            int    unitsStoring  = (int)Math.Min(unitsToTryStore, unitsStorable);
            double volumeStoring = unitsStoring * cargoItem.VolumePerUnit;
            double massStoring   = unitsStoring * cargoItem.MassPerUnit;

            if (!store.CurrentStoreInUnits.ContainsKey(cargoItem.ID))
            {
                store.CurrentStoreInUnits.Add(cargoItem.ID, unitsStoring);
                store.Cargoables.Add(cargoItem.ID, cargoItem);
            }
            else
            {
                store.CurrentStoreInUnits[cargoItem.ID] += unitsStoring;
            }

            store.FreeVolume -= volumeStoring;
            TotalStoredMass  += massStoring;

            return(massStoring);
        }