コード例 #1
0
        public static void AddJob(StaticDataStore staticData, Entity colonyEntity, RefineingJob job)
        {
            RefiningDB refiningDB = colonyEntity.GetDataBlob <RefiningDB>();

            lock (refiningDB.JobBatchList) //prevent threaded race conditions
            {
                //check if the job materialguid is valid, then add it if so.
                if (staticData.CargoGoods.IsMaterial(job.ItemGuid))
                {
                    refiningDB.JobBatchList.Add(job);
                }
            }
        }
コード例 #2
0
 public RefiningVM(Game game, CommandReferences cmdRef, RefiningDB refiningDB)
 {
     _staticData   = game.StaticData;
     _refineDB     = refiningDB;
     _orderHandler = game.OrderHandler;
     _factionGuid  = refiningDB.OwningEntity.FactionOwner;
     _cmdRef       = cmdRef;
     foreach (var kvp in _staticData.CargoGoods.GetMaterials())
     {
         ItemDictionary.Add(kvp.Key, kvp.Value.Name);
     }
     ItemDictionary.SelectedIndex = 0;
     NewJobBatchCount             = 1;
     NewJobRepeat = false;
 }
コード例 #3
0
        /// <summary>
        /// Creates a new colony with zero population.
        /// </summary>
        /// <param name="systemEntityManager"></param>
        /// <param name="factionEntity"></param>
        /// <returns></returns>
        public static Entity CreateColony(Entity factionEntity, Entity speciesEntity, Entity planetEntity)
        {
            List <BaseDataBlob> blobs = new List <BaseDataBlob>();
            string planetName         = planetEntity.GetDataBlob <NameDB>().GetName(factionEntity.Guid);
            NameDB name = new NameDB(planetName + " Colony"); // TODO: Review default name.

            name.SetName(factionEntity.Guid, name.DefaultName);

            blobs.Add(name);
            ColonyInfoDB colonyInfoDB = new ColonyInfoDB(speciesEntity, 0, planetEntity);

            blobs.Add(colonyInfoDB);
            ColonyBonusesDB colonyBonuses = new ColonyBonusesDB();

            blobs.Add(colonyBonuses);
            MiningDB colonyMinesDB = new MiningDB();

            blobs.Add(colonyMinesDB);
            RefiningDB colonyRefining = new RefiningDB();

            blobs.Add(colonyRefining);
            ConstructionDB colonyConstruction = new ConstructionDB();

            blobs.Add(colonyConstruction);
            OrderableDB orderableDB = new OrderableDB();

            blobs.Add(orderableDB);
            MassVolumeDB mvDB = new MassVolumeDB();

            blobs.Add(mvDB);

            TeamsHousedDB th = new TeamsHousedDB();

            blobs.Add(th);

            //installations get added to the componentInstancesDB
            ComponentInstancesDB installations = new ComponentInstancesDB();

            blobs.Add(installations);

            Entity colonyEntity = new Entity(planetEntity.Manager, factionEntity.Guid, blobs);
            var    factionInfo  = factionEntity.GetDataBlob <FactionInfoDB>();

            factionInfo.Colonies.Add(colonyEntity);
            factionEntity.GetDataBlob <FactionOwnerDB>().SetOwned(colonyEntity);
            planetEntity.GetDataBlob <SystemBodyInfoDB>().Colonies.Add(colonyEntity);
            return(colonyEntity);
        }
コード例 #4
0
 public RefiningDB(RefiningDB db)
 {
     RefiningRates = new Dictionary <Guid, int>(db.RefiningRates);
     JobBatchList  = new List <RefineingJob>(db.JobBatchList);
 }
コード例 #5
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, Dictionary <Guid, ProcessedMaterialSD> processedMaterials)
        {
            CargoStorageDB  stockpiles     = colony.GetDataBlob <CargoStorageDB>();
            RefiningDB      refiningDB     = colony.GetDataBlob <RefiningDB>();
            StaticDataStore staticData     = colony.Manager.Game.StaticData;
            int             RefineryPoints = refiningDB.PointsPerTick;

            for (int jobIndex = 0; jobIndex < refiningDB.JobBatchList.Count; jobIndex++)
            {
                if (RefineryPoints > 0)
                {
                    var job = refiningDB.JobBatchList[jobIndex];
                    ProcessedMaterialSD material = processedMaterials[job.ItemGuid];
                    var costs = new Dictionary <Guid, int>(material.RawMineralCosts);
                    if (material.RefinedMateraialsCosts != null)
                    {
                        costs.Concat(new Dictionary <Guid, int>(material.RefinedMateraialsCosts));
                    }

                    Dictionary <ICargoable, int> cargoablecosts = new Dictionary <ICargoable, int>();
                    foreach (var kvp in material.RawMineralCosts)
                    {
                        ICargoable cargoItem = staticData.CargoGoods.GetMineral(kvp.Key);
                        cargoablecosts.Add(cargoItem, kvp.Value);
                    }

                    while (job.NumberCompleted < job.NumberOrdered && job.ProductionPointsLeft > 0)
                    {
                        if (job.ProductionPointsLeft == material.RefineryPointCost)
                        {
                            //consume all ingredients for this job on the first point use.
                            if (StorageSpaceProcessor.HasRequiredItems(stockpiles, cargoablecosts))
                            {
                                StorageSpaceProcessor.RemoveResources(stockpiles, cargoablecosts);
                            }
                            else
                            {
                                break;
                            }
                        }

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

                        //if job is complete
                        if (job.ProductionPointsLeft == 0)
                        {
                            job.NumberCompleted++;                                                       //complete job,
                            StorageSpaceProcessor.AddCargo(stockpiles, material, material.OutputAmount); //and add the product to the stockpile
                            job.ProductionPointsLeft = 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.ProductionPointsLeft = material.RefineryPointCost;
                            job.NumberCompleted      = 0;
                            refiningDB.JobBatchList.Add(job);
                        }
                    }
                }
            }
        }