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); } } }
/// <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); } } } } }
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; } } }
public static Entity DefaultHumans(Game game, Player owner, string name) { StarSystemFactory starfac = new StarSystemFactory(game); StarSystem sol = starfac.CreateSol(game); Entity earth = sol.SystemManager.Entities[3]; //should be fourth entity created Entity factionEntity = FactionFactory.CreatePlayerFaction(game, owner, name); Entity speciesEntity = SpeciesFactory.CreateSpeciesHuman(factionEntity, game.GlobalManager); Entity colonyEntity = ColonyFactory.CreateColony(factionEntity, speciesEntity, earth); ComponentTemplateSD mineSD = game.StaticData.ComponentTemplates[new Guid("f7084155-04c3-49e8-bf43-c7ef4befa550")]; ComponentDesign mineDesign = GenericComponentFactory.StaticToDesign(mineSD, factionEntity.GetDataBlob <FactionTechDB>(), game.StaticData); Entity mineEntity = GenericComponentFactory.DesignToDesignEntity(game, factionEntity, mineDesign); ComponentTemplateSD RefinerySD = game.StaticData.ComponentTemplates[new Guid("90592586-0BD6-4885-8526-7181E08556B5")]; ComponentDesign RefineryDesign = GenericComponentFactory.StaticToDesign(RefinerySD, factionEntity.GetDataBlob <FactionTechDB>(), game.StaticData); Entity RefineryEntity = GenericComponentFactory.DesignToDesignEntity(game, factionEntity, RefineryDesign); ComponentTemplateSD labSD = game.StaticData.ComponentTemplates[new Guid("c203b7cf-8b41-4664-8291-d20dfe1119ec")]; ComponentDesign labDesign = GenericComponentFactory.StaticToDesign(labSD, factionEntity.GetDataBlob <FactionTechDB>(), game.StaticData); Entity labEntity = GenericComponentFactory.DesignToDesignEntity(game, factionEntity, labDesign); ComponentTemplateSD facSD = game.StaticData.ComponentTemplates[new Guid("{07817639-E0C6-43CD-B3DC-24ED15EFB4BA}")]; ComponentDesign facDesign = GenericComponentFactory.StaticToDesign(facSD, factionEntity.GetDataBlob <FactionTechDB>(), game.StaticData); Entity facEntity = GenericComponentFactory.DesignToDesignEntity(game, factionEntity, facDesign); Entity scientistEntity = CommanderFactory.CreateScientist(game.GlobalManager, factionEntity); colonyEntity.GetDataBlob <ColonyInfoDB>().Scientists.Add(scientistEntity); FactionTechDB factionTech = factionEntity.GetDataBlob <FactionTechDB>(); //TechProcessor.ApplyTech(factionTech, game.StaticData.Techs[new Guid("35608fe6-0d65-4a5f-b452-78a3e5e6ce2c")]); //add conventional engine for testing. TechProcessor.MakeResearchable(factionTech); Entity fuelTank = DefaultFuelTank(game, factionEntity); Entity cargoInstalation = DefaultCargoInstalation(game, factionEntity); EntityManipulation.AddComponentToEntity(colonyEntity, mineEntity); EntityManipulation.AddComponentToEntity(colonyEntity, RefineryEntity); EntityManipulation.AddComponentToEntity(colonyEntity, labEntity); EntityManipulation.AddComponentToEntity(colonyEntity, facEntity); EntityManipulation.AddComponentToEntity(colonyEntity, fuelTank); EntityManipulation.AddComponentToEntity(colonyEntity, cargoInstalation); ReCalcProcessor.ReCalcAbilities(colonyEntity); colonyEntity.GetDataBlob <ColonyInfoDB>().Population[speciesEntity] = 9000000000; factionEntity.GetDataBlob <FactionInfoDB>().KnownSystems.Add(sol.Guid); //test systems factionEntity.GetDataBlob <FactionInfoDB>().KnownSystems.Add(starfac.CreateEccTest(game).Guid); factionEntity.GetDataBlob <FactionInfoDB>().KnownSystems.Add(starfac.CreateLongitudeTest(game).Guid); // Todo: handle this in CreateShip Entity shipClass = DefaultShipDesign(game, factionEntity); Entity gunShipClass = GunShipDesign(game, factionEntity); Vector4 position = earth.GetDataBlob <PositionDB>().AbsolutePosition; // Problem - the component instances, both the design and the instances themselves, are the same entities on each ship // IE, the fire control on ship1 is the same entity as on ship2 // Both the design and instances should be unique Entity ship1 = ShipFactory.CreateShip(shipClass, sol.SystemManager, factionEntity, position, sol, "Serial Peacemaker"); Entity ship2 = ShipFactory.CreateShip(shipClass, sol.SystemManager, factionEntity, position, sol, "Ensuing Calm"); StorageSpaceProcessor.AddItemToCargo(ship1.GetDataBlob <CargoStorageDB>(), new Guid("33e6ac88-0235-4917-a7ff-35c8886aad3a"), 200000000000); StorageSpaceProcessor.AddItemToCargo(ship2.GetDataBlob <CargoStorageDB>(), new Guid("33e6ac88-0235-4917-a7ff-35c8886aad3a"), 200000000000); // Strange bug - seems to update the ship orbit once, then never again // TODO: Fix to allow normal orbiting. //ship.SetDataBlob<OrbitDB>(new OrbitDB(earth.GetDataBlob<OrbitDB>())); Entity gunShip = ShipFactory.CreateShip(gunShipClass, sol.SystemManager, factionEntity, position, sol, "Prevailing Stillness"); StorageSpaceProcessor.AddItemToCargo(gunShipClass.GetDataBlob <CargoStorageDB>(), new Guid("33e6ac88-0235-4917-a7ff-35c8886aad3a"), 2000000000); sol.SystemManager.SetDataBlob(ship1.ID, new TransitableDB()); sol.SystemManager.SetDataBlob(ship2.ID, new TransitableDB()); sol.SystemManager.SetDataBlob(gunShip.ID, new TransitableDB()); //Entity ship = ShipFactory.CreateShip(shipClass, sol.SystemManager, factionEntity, position, sol, "Serial Peacemaker"); //ship.SetDataBlob(earth.GetDataBlob<PositionDB>()); //first ship reference PositionDB //Entity ship3 = ShipFactory.CreateShip(shipClass, sol.SystemManager, factionEntity, position, sol, "Contiual Pacifier"); //ship3.SetDataBlob((OrbitDB)earth.GetDataBlob<OrbitDB>().Clone());//second ship clone earth OrbitDB //sol.SystemManager.SetDataBlob(ship.ID, new TransitableDB()); Entity rock = AsteroidFactory.CreateAsteroid(sol, earth, game.CurrentDateTime + TimeSpan.FromDays(365)); return(factionEntity); }