コード例 #1
0
        internal static void AddCargo(CargoStorageDB storeDB, ICargoable item, long amount)
        {
            if (item is CargoAbleTypeDB)
            {
                CargoAbleTypeDB cargoItem = (CargoAbleTypeDB)item;
                if (cargoItem.MustBeSpecificCargo)
                {
                    if (!storeDB.StoredCargoTypes[item.CargoTypeID].SpecificEntites.ContainsKey(cargoItem.ID))
                    {
                        storeDB.StoredCargoTypes[item.CargoTypeID].SpecificEntites.Add(cargoItem.ID, new List <Entity>());
                    }
                    storeDB.StoredCargoTypes[item.CargoTypeID].SpecificEntites[cargoItem.ID].Add(cargoItem.OwningEntity);
                }
            }
            if (!storeDB.StoredCargoTypes.ContainsKey(item.CargoTypeID))
            {
                storeDB.StoredCargoTypes.Add(item.CargoTypeID, new CargoTypeStore());
            }
            else if (!storeDB.StoredCargoTypes[item.CargoTypeID].ItemsAndAmounts.ContainsKey(item.ID))
            {
                storeDB.StoredCargoTypes[item.CargoTypeID].ItemsAndAmounts.Add(item.ID, 0);
            }

            storeDB.StoredCargoTypes[item.CargoTypeID].ItemsAndAmounts[item.ID] += amount;
            //FreeCapacity is *MASS*
            storeDB.StoredCargoTypes[item.CargoTypeID].FreeCapacityKg -= item.Mass * amount;
        }
コード例 #2
0
        /// <summary>
        /// Checks storage capacity and transferes either the amount or the amount that toCargo is capable of storing.
        /// </summary>
        /// <param name="fromCargo"></param>
        /// <param name="toCargo"></param>
        /// <param name="item"></param>
        /// <param name="amount"></param>
        internal static void TransferCargo(CargoStorageDB fromCargo, CargoStorageDB toCargo, ICargoable item, int amount)
        {
            Guid  cargoTypeID = item.CargoTypeID;
            float itemWeight  = item.Mass;
            Guid  itemID      = item.ID;

            long  remainingWeightCapacity = RemainingCapacity(toCargo, cargoTypeID);
            long  remainingNumCapacity    = (long)(remainingWeightCapacity / itemWeight);
            float amountWeight            = amount * itemWeight;

            if (remainingNumCapacity >= amount)
            {
                //AddToCargo(toCargo, item, amount);
                //fromCargo.MinsAndMatsByCargoType[cargoTypeID][itemID] -= amount;
                long amountRemoved = SubtractValue(fromCargo, itemID, amount);
                AddValue(toCargo, item, amountRemoved);
            }
            else
            {
                //AddToCargo(toCargo, item, remainingNumCapacity);
                //fromCargo.MinsAndMatsByCargoType[cargoTypeID][itemID] -= remainingNumCapacity;
                long amountRemoved = SubtractValue(fromCargo, itemID, remainingNumCapacity);
                AddValue(toCargo, item, amountRemoved);
            }
        }
コード例 #3
0
        private static void BatchJobItemComplete(Entity colonyEntity, CargoStorageDB storage, ConstructionJob batchJob, ComponentInfoDB designInfo)
        {
            var colonyConstruction = colonyEntity.GetDataBlob <ColonyConstructionDB>();

            batchJob.NumberCompleted++;
            batchJob.PointsLeft       = designInfo.BuildPointCost;
            batchJob.MineralsRequired = designInfo.MinerialCosts;
            batchJob.MineralsRequired = designInfo.MaterialCosts;
            batchJob.MineralsRequired = designInfo.ComponentCosts;
            var    factionInfo       = colonyEntity.GetDataBlob <OwnedDB>().ObjectOwner.GetDataBlob <FactionInfoDB>();
            Entity designEntity      = factionInfo.ComponentDesigns[batchJob.ItemGuid];
            Entity specificComponent = ComponentInstanceFactory.NewInstanceFromDesignEntity(designEntity, colonyEntity.GetDataBlob <OwnedDB>().ObjectOwner);

            if (batchJob.InstallOn != null)
            {
                if (batchJob.InstallOn == colonyEntity || StorageSpaceProcessor.HasEntity(storage, colonyEntity))
                {
                    EntityManipulation.AddComponentToEntity(batchJob.InstallOn, specificComponent);
                    ReCalcProcessor.ReCalcAbilities(batchJob.InstallOn);
                }
            }
            else
            {
                StorageSpaceProcessor.AddItemToCargo(storage, specificComponent);
            }

            if (batchJob.NumberCompleted == batchJob.NumberOrdered)
            {
                colonyConstruction.JobBatchList.Remove(batchJob);
                if (batchJob.Auto)
                {
                    colonyConstruction.JobBatchList.Add(batchJob);
                }
            }
        }
コード例 #4
0
 /// <summary>
 /// must be mins or mats
 /// </summary>
 /// <param name="fromCargo"></param>
 /// <param name="amounts">must be mins or mats</param>
 internal static void RemoveResources(CargoStorageDB fromCargo, Dictionary <Guid, int> amounts)
 {
     foreach (var item in amounts)
     {
         SubtractValue(fromCargo, item.Key, item.Value);
     }
 }
コード例 #5
0
ファイル: CargoStorageVM.cs プロジェクト: mqrause/Pulsar4x
 public CargoStorageVM(StaticDataStore staticData, CommandReferences cmdRef, CargoStorageDB storeDB)
 {
     _staticData      = staticData;
     _storageDatablob = storeDB;
     CmdRef           = cmdRef;
     Update();
 }
コード例 #6
0
        public static void StartNonNewtTranslation(Entity entity)
        {
            var moveDB       = entity.GetDataBlob <TranslateMoveDB>();
            var propulsionDB = entity.GetDataBlob <PropulsionAbilityDB>();
            var positionDB   = entity.GetDataBlob <PositionDB>();
            var maxSpeedMS   = propulsionDB.MaximumSpeed_MS;

            positionDB.SetParent(null);
            Vector3 targetPosMt       = Distance.AuToMt(moveDB.TranslateExitPoint_AU);
            Vector3 currentPositionMt = Distance.AuToMt(positionDB.AbsolutePosition_AU);

            Vector3 postionDelta  = currentPositionMt - targetPosMt;
            double  totalDistance = postionDelta.Length();

            double maxKMeters        = ShipMovementProcessor.CalcMaxFuelDistance_KM(entity);
            double fuelMaxDistanceMt = maxKMeters * 1000;

            if (fuelMaxDistanceMt >= totalDistance)
            {
                var currentVelocityMS = Vector3.Normalise(targetPosMt - currentPositionMt) * maxSpeedMS;
                propulsionDB.CurrentVectorMS       = currentVelocityMS;
                moveDB.CurrentNonNewtonionVectorMS = currentVelocityMS;
                moveDB.LastProcessDateTime         = entity.Manager.ManagerSubpulses.StarSysDateTime;

                CargoStorageDB storedResources = entity.GetDataBlob <CargoStorageDB>();
                foreach (var item in propulsionDB.FuelUsePerKM)
                {
                    var fuel = staticData.GetICargoable(item.Key);
                    StorageSpaceProcessor.RemoveCargo(storedResources, fuel, (long)(item.Value * totalDistance / 1000));
                }
            }
        }
コード例 #7
0
        /// <summary>
        /// checks if the storage contains all the items and amounts in a given dictionary.
        /// note that this will not return true for unique(damaged) items.
        /// </summary>
        /// <param name="stockpile"></param>
        /// <param name="costs"></param>
        /// <returns></returns>
        public static bool HasRequiredItems(CargoStorageDB stockpile, Dictionary <ICargoable, int> costs)
        {
            if (costs == null)
            {
                return(true);
            }
            else
            {
                foreach (var costitem in costs)
                {
                    if (costitem.Value > 0)
                    {
                        if (stockpile.StoredCargoTypes.ContainsKey(costitem.Key.CargoTypeID) == false)
                        {
                            return(false);
                        }
                        if (stockpile.StoredCargoTypes[costitem.Key.CargoTypeID].ItemsAndAmounts.ContainsKey(costitem.Key.ID) == false)
                        {
                            return(false);
                        }
                    }

                    if (costitem.Value > stockpile.StoredCargoTypes[costitem.Key.CargoTypeID].ItemsAndAmounts[costitem.Key.ID].amount)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
コード例 #8
0
        private static void BatchJobItemComplete(Entity colonyEntity, CargoStorageDB storage, ConstructionJob batchJob, ComponentDesign designInfo)
        {
            var colonyConstruction = colonyEntity.GetDataBlob <ConstructionDB>();

            batchJob.NumberCompleted++;
            batchJob.ProductionPointsLeft = designInfo.BuildPointCost;
            batchJob.MineralsRequired     = designInfo.MineralCosts;
            batchJob.MineralsRequired     = designInfo.MaterialCosts;
            batchJob.MineralsRequired     = designInfo.ComponentCosts;

            ComponentInstance specificComponent = new ComponentInstance(designInfo);

            if (batchJob.InstallOn != null)
            {
                if (batchJob.InstallOn == colonyEntity || StorageSpaceProcessor.HasEntity(storage, colonyEntity.GetDataBlob <CargoAbleTypeDB>()))
                {
                    EntityManipulation.AddComponentToEntity(batchJob.InstallOn, specificComponent);
                    ReCalcProcessor.ReCalcAbilities(batchJob.InstallOn);
                }
            }
            else
            {
                StorageSpaceProcessor.AddCargo(storage, specificComponent, 1);
            }

            if (batchJob.NumberCompleted == batchJob.NumberOrdered)
            {
                colonyConstruction.JobBatchList.Remove(batchJob);
                if (batchJob.Auto)
                {
                    colonyConstruction.JobBatchList.Add(batchJob);
                }
            }
        }
コード例 #9
0
 /// <summary>
 /// consumes resources in the stockpile, and updates the dictionary.
 /// </summary>
 /// <param name="stockpile"></param>
 /// <param name="toUse"></param>
 private static void ConsumeResources(CargoStorageDB fromCargo, IDictionary <Guid, int> toUse)
 {
     foreach (KeyValuePair <Guid, int> kvp in toUse.ToArray())
     {
         ICargoable cargoItem          = fromCargo.OwningEntity.Manager.Game.StaticData.GetICargoable(kvp.Key);
         Guid       cargoTypeID        = cargoItem.CargoTypeID;
         int        amountUsedThisTick = 0;
         if (fromCargo.StoredCargoTypes.ContainsKey(cargoTypeID))
         {
             if (fromCargo.StoredCargoTypes[cargoTypeID].ItemsAndAmounts.ContainsKey(cargoItem.ID))
             {
                 if (fromCargo.StoredCargoTypes[cargoTypeID].ItemsAndAmounts[cargoItem.ID] >= kvp.Value)
                 {
                     amountUsedThisTick = kvp.Value;
                 }
                 else
                 {
                     amountUsedThisTick = (int)fromCargo.StoredCargoTypes[cargoTypeID].ItemsAndAmounts[cargoItem.ID];
                 }
             }
         }
         StorageSpaceProcessor.RemoveCargo(fromCargo, cargoItem, amountUsedThisTick);
         toUse[kvp.Key] -= amountUsedThisTick;
     }
 }
コード例 #10
0
        /// <summary>
        /// TODO: refineing rates should also limit the amount that can be refined for a specific mat each tick.
        /// </summary>
        internal static void RefineMaterials(Entity colony, Game game)
        {
            CargoStorageDB   stockpiles = colony.GetDataBlob <CargoStorageDB>();
            ColonyRefiningDB refiningDB = colony.GetDataBlob <ColonyRefiningDB>();
            int RefineryPoints          = refiningDB.PointsPerTick;

            for (int jobIndex = 0; jobIndex < refiningDB.JobBatchList.Count; jobIndex++)
            {
                if (RefineryPoints > 0)
                {
                    var job = refiningDB.JobBatchList[jobIndex];
                    ProcessedMaterialSD    material = game.StaticData.ProcessedMaterials[job.ItemGuid];
                    Dictionary <Guid, int> costs    = new Dictionary <Guid, int>(material.RawMineralCosts);
                    if (material.RefinedMateraialsCosts != null)
                    {
                        costs.Concat(new Dictionary <Guid, int>(material.RefinedMateraialsCosts));
                    }
                    while (job.NumberCompleted < job.NumberOrdered && job.PointsLeft > 0)
                    {
                        if (job.PointsLeft == material.RefineryPointCost)
                        {
                            //consume all ingredients for this job on the first point use.
                            if (StorageSpaceProcessor.HasReqiredItems(stockpiles, costs))
                            {
                                StorageSpaceProcessor.RemoveResources(stockpiles, costs);
                            }
                            else
                            {
                                break;
                            }
                        }

                        //use Refinery points
                        ushort pointsUsed = (ushort)Math.Min(job.PointsLeft, material.RefineryPointCost);
                        job.PointsLeft -= pointsUsed;
                        RefineryPoints -= pointsUsed;

                        //if job is complete
                        if (job.PointsLeft == 0)
                        {
                            job.NumberCompleted++;                                                                //complete job,
                            StorageSpaceProcessor.AddItemToCargo(stockpiles, material.ID, material.OutputAmount); //and add the product to the stockpile
                            job.PointsLeft = material.RefineryPointCost;                                          //and reset the points left for the next job in the batch.
                        }
                    }
                    //if the whole batch is completed
                    if (job.NumberCompleted == job.NumberOrdered)
                    {
                        //remove it from the list
                        refiningDB.JobBatchList.RemoveAt(jobIndex);
                        if (job.Auto) //but if it's set to auto, re-add it.
                        {
                            job.PointsLeft      = material.RefineryPointCost;
                            job.NumberCompleted = 0;
                            refiningDB.JobBatchList.Add(job);
                        }
                    }
                }
            }
        }
コード例 #11
0
ファイル: CargoStorageDB.cs プロジェクト: johny5w/Pulsar4x
 public CargoStorageDB(CargoStorageDB cargoDB)
 {
     CargoCapicity          = new PrIwObsDict <Guid, long>(cargoDB.CargoCapicity);
     MinsAndMatsByCargoType = new PrIwObsDict <Guid, PrIwObsDict <ICargoable, long> >(cargoDB.MinsAndMatsByCargoType);
     StoredEntities         = new PrIwObsDict <Guid, PrIwObsDict <Entity, PrIwObsList <Entity> > >(cargoDB.StoredEntities);
     ItemToTypeMap          = cargoDB.ItemToTypeMap; //note that this is not 'new', the dictionary referenced here is static and should be the same dictionary throughout the game.
 }
コード例 #12
0
 /// <summary>
 /// must be mins or mats DOES NOT CHECK Availiblity
 /// will throw normal dictionary exceptions.
 /// </summary>
 /// <param name="fromCargo"></param>
 /// <param name="amounts">must be mins or mats</param>
 internal static void RemoveResources(CargoStorageDB fromCargo, Dictionary <ICargoable, int> amounts)
 {
     foreach (var kvp in amounts)
     {
         RemoveCargo(fromCargo, kvp.Key, kvp.Value);
     }
 }
コード例 #13
0
ファイル: MineProcessor.cs プロジェクト: johny5w/Pulsar4x
        internal static void MineResources(Entity colonyEntity)
        {
            Dictionary <Guid, int> mineRates = colonyEntity.GetDataBlob <ColonyMinesDB>().MineingRate;
            Dictionary <Guid, MineralDepositInfo> planetMinerals = colonyEntity.GetDataBlob <ColonyInfoDB>().PlanetEntity.GetDataBlob <SystemBodyInfoDB>().Minerals;
            //Dictionary<Guid, int> colonyMineralStockpile = colonyEntity.GetDataBlob<ColonyInfoDB>().MineralStockpile;
            CargoStorageDB stockpile   = colonyEntity.GetDataBlob <CargoStorageDB>();
            float          mineBonuses = 1;//colonyEntity.GetDataBlob<ColonyBonusesDB>().GetBonus(AbilityType.Mine);

            foreach (var kvp in mineRates)
            {
                double accessability = planetMinerals[kvp.Key].Accessibility;
                double actualRate    = kvp.Value * mineBonuses * accessability;
                int    mineralsMined = (int)Math.Min(actualRate, planetMinerals[kvp.Key].Amount);
                long   capacity      = StorageSpaceProcessor.RemainingCapacity(stockpile, stockpile.CargoTypeID(kvp.Key));
                if (capacity > 0)
                {
                    //colonyMineralStockpile.SafeValueAdd<Guid>(kvp.Key, mineralsMined);
                    StorageSpaceProcessor.AddItemToCargo(stockpile, kvp.Key, mineralsMined);
                    MineralDepositInfo mineralDeposit = planetMinerals[kvp.Key];
                    int newAmount = mineralDeposit.Amount -= mineralsMined;

                    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;
                }
            }
        }
コード例 #14
0
        public static long RemainingCapacity(CargoStorageDB cargo, Guid typeID)
        {
            long capacity     = cargo.CargoCapicity[typeID];
            long storedWeight = NetWeight(cargo, typeID);

            return(capacity - storedWeight);
        }
コード例 #15
0
 /// <summary>
 /// consumes resources in the stockpile, and updates the dictionary.
 /// </summary>
 /// <param name="stockpile"></param>
 /// <param name="toUse"></param>
 private static void ConsumeResources(CargoStorageDB stockpile, IDictionary <Guid, int> toUse)
 {
     foreach (KeyValuePair <Guid, int> kvp in toUse.ToArray())
     {
         int amountUsedThisTick = (int)StorageSpaceProcessor.SubtractValue(stockpile, kvp.Key, kvp.Value);
         toUse[kvp.Key] -= amountUsedThisTick;
     }
 }
コード例 #16
0
        //public static Entity GetEntity(CargoStorageDB cargo, Entity entity)
        //{
        //    var designEntity = entity.GetDataBlob<DesignInfoDB>();
        //    var cargoableDB = entity.GetDataBlob<CargoAbleTypeDB>();
        //    if (cargo.StoredEntities.ContainsKey(cargoableDB.CargoTypeID))
        //        if (cargo.StoredEntities[cargoableDB.CargoTypeID].ContainsKey(designEntity.DesignEntity))
        //            if (cargo.StoredEntities[cargoableDB.CargoTypeID][designEntity.DesignEntity].Contains(entity))
        //                return cargo.StoredEntities[cargoableDB.CargoTypeID][designEntity.DesignEntity].Contains(entity);
        //    return false;
        //}

        /// <summary>
        /// a Dictionary of resources stored of a given cargotype
        /// </summary>
        /// <param name="typeID">cargo type guid</param>
        /// <returns>new dictionary of resources or an empty dictionary</returns>
        public static Dictionary <ICargoable, long> GetResourcesOfCargoType(CargoStorageDB fromCargo, Guid typeID)
        {
            if (fromCargo.MinsAndMatsByCargoType.ContainsKey(typeID))
            {
                return(new Dictionary <ICargoable, long>(fromCargo.MinsAndMatsByCargoType[typeID].GetInternalDictionary()));
            }
            return(new Dictionary <ICargoable, long>());
        }
コード例 #17
0
 public void OnComponentInstallation(Entity parentEntity, ComponentInstance componentInstance)
 {
     if (!parentEntity.HasDataBlob <CargoStorageDB>())
     {
         var db = new CargoStorageDB();
         parentEntity.SetDataBlob(db);
         StorageSpaceProcessor.ReCalcCapacity(parentEntity);
     }
 }
コード例 #18
0
 /// <summary>
 /// returns the number of items of a given ICargoable item,
 /// Not this will not count unique(damaged) items.
 /// </summary>
 /// <param name="storeDB"></param>
 /// <param name="item"></param>
 /// <returns></returns>
 public static long GetAmount(CargoStorageDB storeDB, ICargoable item)
 {
     if (storeDB.StoredCargoTypes.ContainsKey(item.CargoTypeID))
     {
         if (storeDB.StoredCargoTypes[item.CargoTypeID].ItemsAndAmounts.ContainsKey(item.ID))
         {
             return(storeDB.StoredCargoTypes[item.CargoTypeID].ItemsAndAmounts[item.ID].amount);
         }
     }
     return(0);
 }
コード例 #19
0
 /// <summary>
 /// returns the number of items of a given item guid,
 /// Not this will not count unique(damaged) items.
 /// </summary>
 /// <param name="storeDB"></param>
 /// <param name="storeTypeGuid"></param>
 /// <param name="itemGuid"></param>
 /// <returns></returns>
 public static long GetAmount(CargoStorageDB storeDB, Guid storeTypeGuid, Guid itemGuid)
 {
     if (storeDB.StoredCargoTypes.ContainsKey(storeTypeGuid))
     {
         if (storeDB.StoredCargoTypes[storeTypeGuid].ItemsAndAmounts.ContainsKey(itemGuid))
         {
             return(storeDB.StoredCargoTypes[storeTypeGuid].ItemsAndAmounts[itemGuid].amount);
         }
     }
     return(0);
 }
コード例 #20
0
 internal static bool HasEntity(CargoStorageDB storeDB, CargoAbleTypeDB item)
 {
     if (storeDB.StoredCargoTypes[item.CargoTypeID].SpecificEntites.ContainsKey(item.ID))
     {
         if (storeDB.StoredCargoTypes[item.CargoTypeID].SpecificEntites[item.ID].Contains(item.OwningEntity))
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #21
0
        internal static void ConstructStuff(Entity colony)
        {
            CargoStorageDB stockpile = colony.GetDataBlob <CargoStorageDB>();
            Entity         faction;

            colony.Manager.FindEntityByGuid(colony.FactionOwner, out faction);
            var factionInfo        = faction.GetDataBlob <FactionInfoDB>();
            var colonyConstruction = colony.GetDataBlob <ConstructionDB>();

            var pointRates = new Dictionary <ConstructionType, int>(colonyConstruction.ConstructionRates);
            int maxPoints  = colonyConstruction.PointsPerTick;

            List <ConstructionJob> constructionJobs = colonyConstruction.JobBatchList;

            foreach (ConstructionJob batchJob in constructionJobs.ToArray())
            {
                var designInfo           = factionInfo.ComponentDesigns[batchJob.ItemGuid];
                ConstructionType conType = batchJob.ConstructionType;
                //total number of resources requred for a single job in this batch
                int resourcePoints = designInfo.MineralCosts.Sum(item => item.Value);
                resourcePoints += designInfo.MaterialCosts.Sum(item => item.Value);
                resourcePoints += designInfo.ComponentCosts.Sum(item => item.Value);

                while ((pointRates[conType] > 0) && (maxPoints > 0) && (batchJob.NumberCompleted < batchJob.NumberOrdered))
                {
                    //gather availible resorces for this job.

                    ConsumeResources(stockpile, batchJob.MineralsRequired);
                    ConsumeResources(stockpile, batchJob.MaterialsRequired);
                    ConsumeResources(stockpile, batchJob.ComponentsRequired);

                    int useableResourcePoints = designInfo.MineralCosts.Sum(item => item.Value) - batchJob.MineralsRequired.Sum(item => item.Value);
                    useableResourcePoints += designInfo.MaterialCosts.Sum(item => item.Value) - batchJob.MaterialsRequired.Sum(item => item.Value);
                    useableResourcePoints += designInfo.ComponentCosts.Sum(item => item.Value) - batchJob.ComponentsRequired.Sum(item => item.Value);
                    //how many construction points each resourcepoint is worth.
                    int pointPerResource = designInfo.BuildPointCost / resourcePoints;

                    //calculate how many construction points each resource we've got stored for this job is worth
                    int pointsToUse = Math.Min(pointRates[conType], maxPoints);
                    pointsToUse = Math.Min(pointsToUse, batchJob.ProductionPointsLeft);
                    pointsToUse = Math.Min(pointsToUse, useableResourcePoints * pointPerResource);

                    //construct only enough for the amount of resources we have.
                    batchJob.ProductionPointsLeft -= pointsToUse;
                    pointRates[conType]           -= pointsToUse;
                    maxPoints -= pointsToUse;

                    if (batchJob.ProductionPointsLeft == 0)
                    {
                        BatchJobItemComplete(colony, stockpile, batchJob, designInfo);
                    }
                }
            }
        }
コード例 #22
0
        /// <summary>
        /// Calculates the transfer rate.
        /// </summary>
        /// <returns>The transfer rate.</returns>
        /// <param name="dvDifferenceKmPerSecond">Dv difference in Km/s</param>
        /// <param name="from">From.</param>
        /// <param name="to">To.</param>
        public static int CalcTransferRate(double dvDifferenceKmPerSecond, CargoStorageDB from, CargoStorageDB to)
        {
            //var from = transferDB.CargoFromDB;
            //var to = transferDB.CargoToDB;
            var fromRange = from.TransferRangeDv;
            var toRange   = to.TransferRangeDv;

            double maxRange;
            double maxXferAtMaxRange;
            double bestXferRange      = Math.Min(from.TransferRangeDv, to.TransferRangeDv);
            double maxXferAtBestRange = from.TransferRateInKgHr + to.TransferRateInKgHr;

            double transferRate;

            if (from.TransferRangeDv > to.TransferRangeDv)
            {
                maxRange = from.TransferRangeDv;
                if (from.TransferRateInKgHr > to.TransferRateInKgHr)
                {
                    maxXferAtMaxRange = from.TransferRateInKgHr;
                }
                else
                {
                    maxXferAtMaxRange = to.TransferRateInKgHr;
                }
            }
            else
            {
                maxRange = to.TransferRangeDv;
                if (to.TransferRateInKgHr > from.TransferRateInKgHr)
                {
                    maxXferAtMaxRange = to.TransferRateInKgHr;
                }
                else
                {
                    maxXferAtMaxRange = from.TransferRateInKgHr;
                }
            }

            if (dvDifferenceKmPerSecond < bestXferRange)
            {
                transferRate = (int)maxXferAtBestRange;
            }
            else if (dvDifferenceKmPerSecond < maxRange)
            {
                transferRate = (int)maxXferAtMaxRange;
            }
            else
            {
                transferRate = 0;
            }
            return((int)transferRate);
        }
コード例 #23
0
        public static CargoCapacityCheckResult GetAvailableSpace(CargoStorageDB storeDB, Guid itemGuid, ICargoDefinitionsLibrary library)
        {
            var cargoDefinition = library.GetOther(itemGuid);

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

            return(new CargoCapacityCheckResult(itemGuid,
                                                storeDB.StoredCargoTypes[cargoDefinition.CargoTypeID].FreeCapacityKg / cargoDefinition.Mass,
                                                storeDB.StoredCargoTypes[cargoDefinition.CargoTypeID].FreeCapacityKg));
        }
コード例 #24
0
        /// <summary>
        /// checks the toCargo and stores the item if there is enough space.
        /// </summary>
        /// <param name="toCargo"></param>
        /// <param name="entity"></param>
        /// <param name="cargoTypeDB"></param>
        /// <param name=""></param>
        internal static void AddItemToCargo(CargoStorageDB toCargo, Entity entity)
        {
            Entity     designEntity            = entity.GetDataBlob <DesignInfoDB>().DesignEntity;
            ICargoable cargoTypeDB             = designEntity.GetDataBlob <CargoAbleTypeDB>();
            float      amountWeight            = cargoTypeDB.Mass;
            long       remainingWeightCapacity = RemainingCapacity(toCargo, cargoTypeDB.CargoTypeID);
            int        remainingNumCapacity    = (int)(remainingWeightCapacity / amountWeight);

            if (remainingNumCapacity >= 1)
            {
                AddToCargo(toCargo, entity, cargoTypeDB);
            }
        }
コード例 #25
0
        /// <summary>
        /// a list of entities stored of a given cargotype
        /// </summary>
        /// <param name="typeID">cargo type guid</param>
        /// <returns>new list of Entites or an empty list</returns>
        public static List <Entity> GetEntitesOfCargoType(CargoStorageDB fromCargo, Guid typeID)
        {
            List <Entity> entityList = new List <Entity>();

            if (fromCargo.StoredEntities.ContainsKey(typeID))
            {
                foreach (var kvp in fromCargo.StoredEntities[typeID])
                {
                    entityList.AddRange(kvp.Value.GetInternalList());
                }
            }
            return(entityList);
        }
コード例 #26
0
 /// <summary>
 /// Does not check if cargo or cargotype exsists. will throw normal dictionary exptions if you try.
 /// just removes the amount from store and updates the free capacity
 /// </summary>
 /// <param name="storeDB"></param>
 /// <param name="item"></param>
 /// <param name="amount"></param>
 internal static void RemoveCargo(CargoStorageDB storeDB, ICargoable item, long amount)
 {
     if (item is CargoAbleTypeDB)
     {
         CargoAbleTypeDB cargoItem = (CargoAbleTypeDB)item;
         if (cargoItem.MustBeSpecificCargo)
         {
             storeDB.StoredCargoTypes[item.CargoTypeID].SpecificEntites[cargoItem.ID].Remove(cargoItem.OwningEntity);
         }
     }
     storeDB.StoredCargoTypes[item.CargoTypeID].ItemsAndAmounts[item.ID] -= amount;
     //FreeCapacity is *MASS*
     storeDB.StoredCargoTypes[item.CargoTypeID].FreeCapacityKg += item.Mass * amount;
 }
コード例 #27
0
        public static long NetWeight(CargoStorageDB cargo, Guid typeID)
        {
            long net = 0;

            if (cargo.MinsAndMatsByCargoType.ContainsKey(typeID))
            {
                net = StoredWeight(cargo.MinsAndMatsByCargoType, typeID);
            }
            else if (cargo.StoredEntities.ContainsKey(typeID))
            {
                net = StoredWeight(cargo.StoredEntities, typeID);
            }
            return(net);
        }
コード例 #28
0
        /// <summary>
        /// Checks storage capacity and stores either the amount or the amount that toCargo is capable of storing.
        /// </summary>
        /// <param name="toCargo"></param>
        /// <param name="item"></param>
        /// <param name="amount"></param>
        internal static void AddItemToCargo(CargoStorageDB toCargo, ICargoable item, int amount)
        {
            long  remainingWeightCapacity = RemainingCapacity(toCargo, item.CargoTypeID);
            int   remainingNumCapacity    = (int)(remainingWeightCapacity / item.Mass);
            float amountWeight            = amount * item.Mass;

            if (remainingNumCapacity >= amount)
            {
                AddValue(toCargo, item, amount);
            }
            else
            {
                AddValue(toCargo, item, remainingNumCapacity);
            }
        }
コード例 #29
0
        /// <summary>
        /// returns the amount of items for a given item guid.
        /// </summary>
        /// <param name="fromCargo"></param>
        /// <param name="itemID">a min or mat ID</param>
        /// <returns></returns>
        public static long GetAmountOf(CargoStorageDB fromCargo, Guid itemID)
        {
            Guid       cargoTypeID = fromCargo.ItemToTypeMap[itemID];
            ICargoable cargo       = fromCargo.OwningEntity.Manager.Game.StaticData.GetICargoable(itemID);
            long       returnValue = 0;

            if (fromCargo.MinsAndMatsByCargoType.ContainsKey(cargoTypeID))
            {
                if (fromCargo.MinsAndMatsByCargoType[cargoTypeID].ContainsKey(cargo))
                {
                    returnValue = fromCargo.MinsAndMatsByCargoType[cargoTypeID][cargo];
                }
            }
            return(returnValue);
        }
コード例 #30
0
        internal static void AddItemToCargo(CargoStorageDB toCargo, Guid itemID, long amount)
        {
            ICargoable item = (ICargoable)toCargo.OwningEntity.Manager.Game.StaticData.FindDataObjectUsingID(itemID);
            long       remainingWeightCapacity = RemainingCapacity(toCargo, item.CargoTypeID);
            long       remainingNumCapacity    = (long)(remainingWeightCapacity / item.Mass);
            float      amountWeight            = amount / item.Mass;

            if (remainingNumCapacity >= amount)
            {
                AddValue(toCargo, item, amount);
            }
            else
            {
                AddValue(toCargo, item, remainingNumCapacity);
            }
        }