/// <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); } } } } }
public static void AddJob(StaticDataStore staticData, Entity colonyEntity, RefineingJob job) { ColonyRefiningDB refiningDB = colonyEntity.GetDataBlob <ColonyRefiningDB>(); lock (refiningDB.JobBatchList) //prevent threaded race conditions { //check if the job materialguid is valid, then add it if so. if (staticData.ProcessedMaterials.ContainsKey(job.ItemGuid)) { refiningDB.JobBatchList.Add(job); } } }
/// <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); var OwnedDB = new OwnedDB(factionEntity); blobs.Add(OwnedDB); NameDB name = new NameDB(planetName + " Colony"); // TODO: Review default name. blobs.Add(name); ColonyInfoDB colonyInfoDB = new ColonyInfoDB(speciesEntity, 0, planetEntity); blobs.Add(colonyInfoDB); ColonyBonusesDB colonyBonuses = new ColonyBonusesDB(); blobs.Add(colonyBonuses); ColonyMinesDB colonyMinesDB = new ColonyMinesDB(); blobs.Add(colonyMinesDB); ColonyRefiningDB colonyRefining = new ColonyRefiningDB(); blobs.Add(colonyRefining); ColonyConstructionDB colonyConstruction = new ColonyConstructionDB(); blobs.Add(colonyConstruction); MassVolumeDB mvDB = new MassVolumeDB(); blobs.Add(mvDB); //installations get added to the componentInstancesDB ComponentInstancesDB installations = new ComponentInstancesDB(); blobs.Add(installations); Entity colonyEntity = new Entity(planetEntity.Manager, blobs); factionEntity.GetDataBlob <FactionInfoDB>().Colonies.Add(colonyEntity); return(colonyEntity); }
public ColonyRefiningDB(ColonyRefiningDB db) { RefiningRates = new Dictionary <Guid, int>(db.RefiningRates); JobBatchList = new List <RefineingJob>(db.JobBatchList); }