Exemple #1
0
 public void OnComponentInstallation(Entity parentEntity, ComponentInstance componentInstance)
 {
     if (!parentEntity.HasDataBlob <VolumeStorageDB>())
     {
         var newdb = new VolumeStorageDB();
         parentEntity.SetDataBlob(newdb);
     }
     StorageSpaceProcessor.RecalcVolumeCapacityAndRates(parentEntity);
 }
        internal static bool HasEntity(VolumeStorageDB storeDB, CargoAbleTypeDB item)
        {
            throw new NotImplementedException();

            /*
             * if(storeDB.TypeStores[item.CargoTypeID].CurrentStore.ContainsKey(item.ID))
             *  if (storeDB.TypeStores[item.CargoTypeID].CurrentStore[item.ID].Contains(item.OwningEntity))
             *      return true;
             * return false;
             */
        }
Exemple #3
0
 public VolumeStorageDB(VolumeStorageDB db)
 {
     TypeStores = new Dictionary <Guid, TypeStore>();
     foreach (var kvp in db.TypeStores)
     {
         TypeStores.Add(kvp.Key, kvp.Value.Clone());
     }
     TotalStoredMass     = db.TotalStoredMass;
     TransferRangeDv_mps = db.TransferRangeDv_mps;
     TransferRateInKgHr  = db.TransferRateInKgHr;
 }
Exemple #4
0
        /// <summary>
        /// Calculates the transfer rate.
        /// </summary>
        /// <returns>The transfer rate.</returns>
        /// <param name="dvDifference_mps">Dv difference in Km/s</param>
        /// <param name="from">From.</param>
        /// <param name="to">To.</param>
        public static int CalcTransferRate(double dvDifference_mps, VolumeStorageDB from, VolumeStorageDB to)
        {
            //var from = transferDB.CargoFromDB;
            //var to = transferDB.CargoToDB;
            var fromDVRange = from.TransferRangeDv_mps;
            var toDVRange   = to.TransferRangeDv_mps;

            double maxRange;
            double maxXferAtMaxRange;
            double bestXferRange_ms   = Math.Min(fromDVRange, toDVRange);
            double maxXferAtBestRange = from.TransferRateInKgHr + to.TransferRateInKgHr;

            double transferRate;

            if (from.TransferRangeDv_mps > to.TransferRangeDv_mps)
            {
                maxRange = fromDVRange;
                if (from.TransferRateInKgHr > to.TransferRateInKgHr)
                {
                    maxXferAtMaxRange = from.TransferRateInKgHr;
                }
                else
                {
                    maxXferAtMaxRange = to.TransferRateInKgHr;
                }
            }
            else
            {
                maxRange = toDVRange;
                if (to.TransferRateInKgHr > from.TransferRateInKgHr)
                {
                    maxXferAtMaxRange = to.TransferRateInKgHr;
                }
                else
                {
                    maxXferAtMaxRange = from.TransferRateInKgHr;
                }
            }

            if (dvDifference_mps < bestXferRange_ms)
            {
                transferRate = (int)maxXferAtBestRange;
            }
            else if (dvDifference_mps < maxRange)
            {
                transferRate = (int)maxXferAtMaxRange;
            }
            else
            {
                transferRate = 0;
            }
            return((int)transferRate);
        }
Exemple #5
0
        public void OnConstructionComplete(Entity industryEntity, VolumeStorageDB storage, Guid productionLine, IndustryJob batchJob, IConstrucableDesign designInfo)
        {
            var industryDB = industryEntity.GetDataBlob <IndustryAbilityDB>();
            ProcessedMaterialSD material = (ProcessedMaterialSD)designInfo;

            storage.AddCargoByUnit(material, OutputAmount);
            batchJob.ProductionPointsLeft = material.IndustryPointCosts; //and reset the points left for the next job in the batch.

            if (batchJob.NumberCompleted == batchJob.NumberOrdered)
            {
                industryDB.ProductionLines[productionLine].Jobs.Remove(batchJob);
                if (batchJob.Auto)
                {
                    industryDB.ProductionLines[productionLine].Jobs.Add(batchJob);
                }
            }
        }
        private void MineResources(Entity colonyEntity)
        {
            Dictionary <Guid, int> mineRates = colonyEntity.GetDataBlob <MiningDB>().MineingRate;
            Dictionary <Guid, MineralDepositInfo> planetMinerals = colonyEntity.GetDataBlob <ColonyInfoDB>().PlanetEntity.GetDataBlob <SystemBodyInfoDB>().Minerals;

            VolumeStorageDB stockpile   = colonyEntity.GetDataBlob <VolumeStorageDB>();
            float           mineBonuses = 1;//colonyEntity.GetDataBlob<ColonyBonusesDB>().GetBonus(AbilityType.Mine);

            foreach (var kvp in mineRates)
            {
                ICargoable mineral         = _minerals[kvp.Key];
                Guid       cargoTypeID     = mineral.CargoTypeID;
                double     itemMassPerUnit = mineral.MassPerUnit;

                double accessability        = planetMinerals[kvp.Key].Accessibility;
                double actualRate           = kvp.Value * mineBonuses * accessability;
                int    unitsMinableThisTick = (int)Math.Min(actualRate, planetMinerals[kvp.Key].Amount);

                if (!stockpile.TypeStores.ContainsKey(mineral.CargoTypeID))
                {
                    var    type  = StaticRefLib.StaticData.CargoTypes[mineral.CargoTypeID];
                    string erstr = "We didn't mine a potential " + unitsMinableThisTick + " of " + mineral.Name + " because we have no way to store " + type.Name + " cargo.";
                    StaticRefLib.EventLog.AddPlayerEntityErrorEvent(colonyEntity, erstr);
                    continue;    //can't store this mineral
                }

                var unitsMinedThisTick = stockpile.AddCargoByUnit(mineral, unitsMinableThisTick);

                if (unitsMinableThisTick > unitsMinedThisTick)
                {
                    var    dif   = unitsMinableThisTick - unitsMinedThisTick;
                    var    type  = StaticRefLib.StaticData.CargoTypes[mineral.CargoTypeID];
                    string erstr = "We didn't mine a potential " + dif + " of " + mineral.Name + " because we don't have enough space to store it.";
                    StaticRefLib.EventLog.AddPlayerEntityErrorEvent(colonyEntity, erstr);
                }

                MineralDepositInfo mineralDeposit = planetMinerals[kvp.Key];
                int newAmount = mineralDeposit.Amount -= unitsMinedThisTick;

                accessability = Math.Pow((float)mineralDeposit.Amount / mineralDeposit.HalfOriginalAmount, 3) * mineralDeposit.Accessibility;
                double newAccess = GMath.Clamp(accessability, 0.1, mineralDeposit.Accessibility);

                mineralDeposit.Amount        = newAmount;
                mineralDeposit.Accessibility = newAccess;
            }
        }
        public static CargoCapacityCheckResult GetAvailableSpace(VolumeStorageDB storeDB, Guid itemGuid, ICargoDefinitionsLibrary library)
        {
            var cargoDefinition = library.GetOther(itemGuid);

            if (cargoDefinition.MassPerUnit == 0)
            {
                return(new CargoCapacityCheckResult(itemGuid, long.MaxValue, long.MaxValue));
            }

            var  freeMass = storeDB.TypeStores[cargoDefinition.CargoTypeID].GetFreeMass(cargoDefinition);
            long count    = (long)(freeMass * cargoDefinition.MassPerUnit);

            return(new CargoCapacityCheckResult(
                       itemGuid,
                       count,
                       (long)freeMass));
        }
Exemple #8
0
 public void OnComponentInstallation(Entity parentEntity, ComponentInstance componentInstance)
 {
     if (!parentEntity.HasDataBlob <VolumeStorageDB>())
     {
         var newdb = new VolumeStorageDB(StoreTypeID, MaxVolume);
         parentEntity.SetDataBlob(newdb);
     }
     else
     {
         var db = parentEntity.GetDataBlob <VolumeStorageDB>();
         if (db.TypeStores.ContainsKey(StoreTypeID))
         {
             db.TypeStores[StoreTypeID].MaxVolume  += MaxVolume;
             db.TypeStores[StoreTypeID].FreeVolume += MaxVolume;
         }
         else
         {
             db.TypeStores.Add(StoreTypeID, new TypeStore(MaxVolume));
         }
     }
 }
        internal static void RecalcVolumeCapacityAndRates(Entity parentEntity)
        {
            VolumeStorageDB cargoStorageDB = parentEntity.GetDataBlob <VolumeStorageDB>();
            //Dictionary<Guid, CargoTypeStore> storageDBStoredCargos = cargoStorageDB.StoredCargoTypes;

            Dictionary <Guid, double> calculatedMaxStorage = new Dictionary <Guid, double>();

            var instancesDB = parentEntity.GetDataBlob <ComponentInstancesDB>();

            double transferRate  = 0;
            double transferRange = 0;



            if (instancesDB.TryGetComponentsByAttribute <VolumeStorageAtb>(out var componentInstances))
            {
                foreach (var instance in componentInstances)
                {
                    var design  = instance.Design;
                    var atbdata = design.GetAttribute <VolumeStorageAtb>();

                    if (instance.HealthPercent() > 0.75)
                    {
                        if (!calculatedMaxStorage.ContainsKey(atbdata.StoreTypeID))
                        {
                            calculatedMaxStorage[atbdata.StoreTypeID] = atbdata.MaxVolume;
                        }
                        else
                        {
                            calculatedMaxStorage[atbdata.StoreTypeID] += atbdata.MaxVolume;
                        }
                    }
                }
            }

            foreach (var kvp in calculatedMaxStorage)
            {
                if (!cargoStorageDB.TypeStores.ContainsKey(kvp.Key))
                {
                    cargoStorageDB.TypeStores.Add(kvp.Key, new TypeStore(kvp.Value));
                }

                else
                {
                    var stor = cargoStorageDB.TypeStores[kvp.Key];
                    var dif  = kvp.Value - stor.MaxVolume;
                    cargoStorageDB.ChangeMaxVolume(kvp.Key, dif);
                }
            }


            int i = 0;

            if (instancesDB.TryGetComponentsByAttribute <StorageTransferRateAtbDB>(out var componentTransferInstances))
            {
                foreach (var instance in componentInstances)
                {
                    var design = instance.Design;
                    if (!design.HasAttribute <StorageTransferRateAtbDB>())
                    {
                        continue;
                    }

                    var atbdata = design.GetAttribute <StorageTransferRateAtbDB>();
                    if (instance.HealthPercent() > 0.75)
                    {
                        transferRate  += atbdata.TransferRate_kgh;
                        transferRange += atbdata.TransferRange_ms;
                        i++;
                    }
                }

                cargoStorageDB.TransferRateInKgHr  = (int)(transferRate / i);
                cargoStorageDB.TransferRangeDv_mps = transferRange / i;
            }
        }