Esempio n. 1
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);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// calculates, sets and returns DV.
        /// </summary>
        /// <param name="parentEntity"></param>
        /// <returns></returns>
        public static double CalcDeltaV(Entity parentEntity)
        {
            var db = parentEntity.GetDataBlob <NewtonThrustAbilityDB>();
            var ft = db.FuelType;
            var ev = db.ExhaustVelocity;

            var wetmass = parentEntity.GetDataBlob <MassVolumeDB>().Mass;
            ProcessedMaterialSD fuel = StaticRefLib.StaticData.CargoGoods.GetMaterials()[ft];
            var cargo      = parentEntity.GetDataBlob <CargoStorageDB>();
            var fuelAmount = StorageSpaceProcessor.GetAmount(cargo, fuel);
            var dryMass    = wetmass - fuelAmount;

            return(db.DeltaV = OrbitMath.TsiolkovskyRocketEquation(wetmass, dryMass, ev));
        }
Esempio n. 3
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);
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// calculates, sets and returns DV.
        /// </summary>
        /// <param name="parentEntity"></param>
        /// <returns></returns>
        public static void UpdateNewtonThrustAbilityDB(Entity parentEntity)
        {
            var db = parentEntity.GetDataBlob <NewtonThrustAbilityDB>();
            var ft = db.FuelType;
            var ev = db.ExhaustVelocity;

            db.DryMass_kg = parentEntity.GetDataBlob <MassVolumeDB>().MassDry;
            ProcessedMaterialSD fuel = StaticRefLib.StaticData.CargoGoods.GetMaterials()[ft];

            double fuelMass = 0;

            if (parentEntity.HasDataBlob <VolumeStorageDB>())
            {
                var cargo = parentEntity.GetDataBlob <VolumeStorageDB>();
                fuelMass = cargo.GetMassStored(fuel);
            }


            db.SetFuel(fuelMass);
        }