From 6c7f0e80991dd3efae70b94bde5f84b6018a425f Mon Sep 17 00:00:00 2001 From: JoshuaNavarro Date: Thu, 3 Oct 2019 23:42:16 -0700 Subject: [PATCH] Added in steam engine. Updated fluid graph search from output tanks for better optimization. --- .../Graphics/Objects/Machines/Capacitor.png | Bin 338 -> 335 bytes .../Graphics/Objects/Machines/SteamEngine.png | Bin 0 -> 648 bytes .../Framework/Configs/GlobalMachineConfig.cs | 5 + .../Framework/Managers/FluidManagerV2.cs | 25 ++ .../Menus/Machines/MachineSummaryMenu.cs | 2 +- .../Machines/EnergyGeneration/SteamEngine.cs | 294 ++++++++++++++++++ .../Framework/Objects/Machines/Machine.cs | 43 ++- .../Framework/Objects/MultiTiledComponent.cs | 41 ++- .../Framework/Objects/ObjectManager.cs | 7 + GeneralMods/Revitalize/ModCore.cs | 3 +- GeneralMods/Revitalize/Revitalize.csproj | 4 + 11 files changed, 407 insertions(+), 17 deletions(-) create mode 100644 GeneralMods/Revitalize/Content/Graphics/Objects/Machines/SteamEngine.png create mode 100644 GeneralMods/Revitalize/Framework/Objects/Machines/EnergyGeneration/SteamEngine.cs diff --git a/GeneralMods/Revitalize/Content/Graphics/Objects/Machines/Capacitor.png b/GeneralMods/Revitalize/Content/Graphics/Objects/Machines/Capacitor.png index 2662d05b74d1feaadd9f9f8092fff2ea7f6fec83..db85e09e6d4f3ccf453be0305cce296a29e0ea5c 100644 GIT binary patch delta 295 zcmV+?0oeZ10?z`FF@Fh3L_t(Ijm3|#N&`U{gue}e5LCitK_ny=ia}D@2=@$E`WC*B zzDR1DG*_k45MmI);}B&N_K=8NaaI?0?{*VAr`ciunfd33|Ar_@6h(K9*TwB$jpNx; z05nbW&Gjh&`uoRg?6g}YEylB@XjBEJITn5Eb%k32uFa;|rGIPss>Y&E?|6U=Bxa0K$sS+rS*UP@QiZ=zPP&)8|gJ z37v230D$~_L|01AdPCILI{@SJemzW%Q@d wRGJXX#st7k;Um`OYk>W;i>szK8+8}(14Q&`ppJPsEdT%j07*qoM6N<$f{ki}A^-pY diff --git a/GeneralMods/Revitalize/Content/Graphics/Objects/Machines/SteamEngine.png b/GeneralMods/Revitalize/Content/Graphics/Objects/Machines/SteamEngine.png new file mode 100644 index 0000000000000000000000000000000000000000..72ae0383697339c6a121cca1436fa566cc981be1 GIT binary patch literal 648 zcmV;30(bq1P)Px%LP|sdcv!OK!w9hRK)>eu^0%27k)n>p=f!X3ES8xezP1m7|@HWSdqLPV^+L=uw4PY@Px;Q z?2@VP)LE&ZRly3qn(cdSi`Q>5mbtD50A!cU*}x3>wF2czsVgrYjfi2Vn?p_q`ev)v zDhA%T+XJ*K5RXPgDxH-K21bVlwep690(pf}9)^LCiKikH42q?_xYhj2X061e+eful z;lacEc)jf04`3p`zVD=z(fNxPO^3;?uF1sIcMrYB~o|JnjTK62a;7s~~<>vhO2 z_ci%t@s{{Fa+RCcE=vG+6ZbkA)v^i4WEaJ90RaEhIaAz0x9t9Lw}<3v1$d_ko7caq zf$jQE-&iLusV2<3z)G;EfpTt{GVn<^)-B$H1no;D9*qc^?LBV?sdRS#E&v$uU$|lG iOFh2suZKF}LGcfJmE>^{mCs=S0000 /// Checks to see if the input tanks on this Fluid manager have the capacity to take in this Fluid at all. /// diff --git a/GeneralMods/Revitalize/Framework/Menus/Machines/MachineSummaryMenu.cs b/GeneralMods/Revitalize/Framework/Menus/Machines/MachineSummaryMenu.cs index 79f7a64d..3950c517 100644 --- a/GeneralMods/Revitalize/Framework/Menus/Machines/MachineSummaryMenu.cs +++ b/GeneralMods/Revitalize/Framework/Menus/Machines/MachineSummaryMenu.cs @@ -75,7 +75,7 @@ namespace Revitalize.Framework.Menus.Machines { get { - return this.energy.maxEnergy != 0 || ModCore.Configs.machinesConfig.doMachinesConsumeEnergy==false; + return this.energy.maxEnergy != 0 && ModCore.Configs.machinesConfig.doMachinesConsumeEnergy==true; } } diff --git a/GeneralMods/Revitalize/Framework/Objects/Machines/EnergyGeneration/SteamEngine.cs b/GeneralMods/Revitalize/Framework/Objects/Machines/EnergyGeneration/SteamEngine.cs new file mode 100644 index 00000000..26d0d1ab --- /dev/null +++ b/GeneralMods/Revitalize/Framework/Objects/Machines/EnergyGeneration/SteamEngine.cs @@ -0,0 +1,294 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using PyTK.CustomElementHandler; +using Revitalize.Framework.Managers; +using Revitalize.Framework.Objects.InformationFiles; +using Revitalize.Framework.Utilities; +using StardewValley; + +namespace Revitalize.Framework.Objects.Machines.EnergyGeneration +{ + public class SteamEngine:Machine + { + + public SteamEngine() { } + + public SteamEngine(CustomObjectData PyTKData, BasicItemInformation info, List ProducedResources = null, int EnergyRequiredPer10Minutes = 0, int TimeToProduce = 0, bool UpdatesContainer = false, string CraftingBook = "",Fluid FluidRequiredForOperation = null, int FluidAmountRequiredPerOperation=0) : base(PyTKData, info) + { + this.producedResources = ProducedResources ?? new List(); + this.energyRequiredPer10Minutes = EnergyRequiredPer10Minutes; + this.timeToProduce = TimeToProduce; + this.updatesContainerObjectForProduction = UpdatesContainer; + this.MinutesUntilReady = TimeToProduce; + this.craftingRecipeBook = CraftingBook; + this.createStatusBubble(); + this.requiredFluidForOperation = FluidRequiredForOperation; + this.amountOfFluidRequiredForOperation = FluidAmountRequiredPerOperation; + } + + public SteamEngine(CustomObjectData PyTKData, BasicItemInformation info, Vector2 TileLocation, List ProducedResources = null, int EnergyRequiredPer10Minutes = 0, int TimeToProduce = 0, bool UpdatesContainer = false, string CraftingBook = "", MultiTiledObject obj = null, Fluid FluidRequiredForOperation = null, int FluidAmountRequiredPerOperation = 0) : base(PyTKData, info, TileLocation) + { + this.containerObject = obj; + this.producedResources = ProducedResources ?? new List(); + this.energyRequiredPer10Minutes = EnergyRequiredPer10Minutes; + this.timeToProduce = TimeToProduce; + this.updatesContainerObjectForProduction = UpdatesContainer; + this.MinutesUntilReady = TimeToProduce; + this.craftingRecipeBook = CraftingBook; + this.createStatusBubble(); + this.requiredFluidForOperation = FluidRequiredForOperation; + this.amountOfFluidRequiredForOperation = FluidAmountRequiredPerOperation; + } + + public SteamEngine(CustomObjectData PyTKData, BasicItemInformation info, Vector2 TileLocation, Vector2 offsetKey, List ProducedResources = null, int EnergyRequiredPer10Minutes = 0, int TimeToProduce = 0, bool UpdatesContainer = false, string CraftingBook = "", MultiTiledObject obj = null, Fluid FluidRequiredForOperation = null, int FluidAmountRequiredPerOperation = 0) : base(PyTKData, info, TileLocation) + { + this.offsetKey = offsetKey; + this.containerObject = obj; + this.producedResources = ProducedResources ?? new List(); + this.energyRequiredPer10Minutes = EnergyRequiredPer10Minutes; + this.timeToProduce = TimeToProduce; + this.updatesContainerObjectForProduction = UpdatesContainer; + this.MinutesUntilReady = TimeToProduce; + this.craftingRecipeBook = CraftingBook; + this.createStatusBubble(); + this.requiredFluidForOperation = FluidRequiredForOperation; + this.amountOfFluidRequiredForOperation = FluidAmountRequiredPerOperation; + } + + public override void updateWhenCurrentLocation(GameTime time, GameLocation environment) + { + base.updateWhenCurrentLocation(time, environment); + + this.animationManager.prepareForNextUpdateTick(); + } + + + public override bool minutesElapsed(int minutes, GameLocation environment) + { + this.updateInfo(); + + /* + if (this.containerObject.MinutesUntilReady > 0) + { + this.animationManager.playAnimation("Working"); + } + else + { + this.animationManager.playDefaultAnimation(); + } + */ + this.pullFluidFromNetworkOutputs(ModCore.ObjectManager.resources.getFluid("Steam")); + + if (this.updatesContainerObjectForProduction) + { + int remaining = minutes; + while (remaining > 0) + { + if (this.GetEnergyManager().canReceieveEnergy == false) return false; + remaining -= 10; + int fluidAmount = this.GetFluidManager().getAmountOfFluidInInputTanks(this.requiredFluidForOperation); + if (this.GetFluidManager().doTheInputTanksHaveEnoughFluid(ModCore.ObjectManager.resources.getFluid(this.requiredFluidForOperation.name), this.amountOfFluidRequiredForOperation)) + { + this.GetFluidManager().consumeFluid(ModCore.ObjectManager.resources.getFluid(this.requiredFluidForOperation.name), this.amountOfFluidRequiredForOperation); + //this.GetFluidManager().produceFluid(ModCore.ObjectManager.resources.getFluid("Steam"), ModCore.Configs.machinesConfig.steamBoilerV1_producedSteamPerOperation); + this.produceEnergy(); + this.storeEnergyToNetwork(); + } + else if(fluidAmount>0) + { + //Try to always consume fluid if possible. + double ratio = (double)fluidAmount / (double)ModCore.Configs.machinesConfig.steamEngineV1_requiredSteamPerOperation; + int liquidToConsume = fluidAmount; + this.GetFluidManager().consumeFluid(ModCore.ObjectManager.resources.getFluid(this.requiredFluidForOperation.name), liquidToConsume); + this.produceEnergy(ratio); + this.storeEnergyToNetwork(); + } + } + return false; + } + else + { + + if (this.GetEnergyManager().energyInteractionType == Enums.EnergyInteractionType.Produces) + { + this.storeEnergyToNetwork(); + } + + return false; + } + + //return base.minutesElapsed(minutes, environment); + } + + public override bool rightClicked(Farmer who) + { + if (this.location == null) + this.location = Game1.player.currentLocation; + if (Game1.menuUp || Game1.currentMinigame != null) return false; + + //ModCore.playerInfo.sittingInfo.sit(this, Vector2.Zero); + this.createMachineMenu(); + return true; + } + + + public override Item getOne() + { + SteamEngine component = new SteamEngine(this.data, this.info.Copy(), this.producedResources, this.energyRequiredPer10Minutes, this.timeToProduce, this.updatesContainerObjectForProduction, this.craftingRecipeBook,this.requiredFluidForOperation,this.amountOfFluidRequiredForOperation); + component.containerObject = this.containerObject; + component.offsetKey = this.offsetKey; + return component; + return component; + } + + public override ICustomObject recreate(Dictionary additionalSaveData, object replacement) + { + Vector2 offsetKey = new Vector2(Convert.ToInt32(additionalSaveData["offsetKeyX"]), Convert.ToInt32(additionalSaveData["offsetKeyY"])); + string GUID = additionalSaveData["GUID"]; + SteamEngine self = Revitalize.ModCore.Serializer.DeserializeGUID(additionalSaveData["GUID"]); + if (ModCore.IsNullOrDefault(self)) return null; + try + { + if (!Revitalize.ModCore.ObjectGroups.ContainsKey(additionalSaveData["ParentGUID"])) + { + MultiTiledObject obj = (MultiTiledObject)Revitalize.ModCore.Serializer.DeserializeGUID(additionalSaveData["ParentGUID"]); + self.containerObject = obj; + self.containerObject.removeComponent(offsetKey); + self.containerObject.addComponent(offsetKey, self); + Revitalize.ModCore.ObjectGroups.Add(additionalSaveData["ParentGUID"], obj); + } + else + { + self.containerObject = Revitalize.ModCore.ObjectGroups[additionalSaveData["ParentGUID"]]; + self.containerObject.removeComponent(offsetKey); + self.containerObject.addComponent(offsetKey, self); + } + } + catch (Exception err) + { + ModCore.log(err); + } + + return self; + } + + public override void rebuild(Dictionary additionalSaveData, object replacement) + { + base.rebuild(additionalSaveData, replacement); + } + + public override void draw(SpriteBatch spriteBatch, int x, int y, float alpha = 1f) + { + this.updateInfo(); + + if (this.info == null) + { + Revitalize.ModCore.log("info is null"); + if (this.syncObject == null) Revitalize.ModCore.log("DEAD SYNC"); + } + if (this.animationManager == null) Revitalize.ModCore.log("Animation Manager Null"); + if (this.displayTexture == null) Revitalize.ModCore.log("Display texture is null"); + + //The actual planter box being drawn. + if (this.animationManager == null) + { + if (this.animationManager.getExtendedTexture() == null) + ModCore.ModMonitor.Log("Tex Extended is null???"); + + spriteBatch.Draw(this.displayTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * Game1.tileSize), y * Game1.tileSize)), new Rectangle?(this.animationManager.currentAnimation.sourceRectangle), this.info.DrawColor * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0f, (float)(y * Game1.tileSize) / 10000f)); + // Log.AsyncG("ANIMATION IS NULL?!?!?!?!"); + } + + else + { + //Log.AsyncC("Animation Manager is working!"); + float addedDepth = 0; + + + if (Revitalize.ModCore.playerInfo.sittingInfo.SittingObject == this.containerObject && this.info.facingDirection == Enums.Direction.Up) + { + addedDepth += (this.containerObject.Height - 1) - ((int)(this.offsetKey.Y)); + if (this.info.ignoreBoundingBox) addedDepth += 1.5f; + } + else if (this.info.ignoreBoundingBox) + { + addedDepth += 1.0f; + } + this.animationManager.draw(spriteBatch, this.displayTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * Game1.tileSize), y * Game1.tileSize)), new Rectangle?(this.animationManager.currentAnimation.sourceRectangle), this.info.DrawColor * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0f, (float)((y + addedDepth) * Game1.tileSize) / 10000f) + .00001f); + this.drawStatusBubble(spriteBatch, x, y, alpha); + + try + { + if (this.animationManager.canTickAnimation()) + { + this.animationManager.tickAnimation(); + } + // Log.AsyncC("Tick animation"); + } + catch (Exception err) + { + ModCore.ModMonitor.Log(err.ToString()); + } + } + + // spriteBatch.Draw(Game1.mouseCursors, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)((double)tileLocation.X * (double)Game1.tileSize + (((double)tileLocation.X * 11.0 + (double)tileLocation.Y * 7.0) % 10.0 - 5.0)) + (float)(Game1.tileSize / 2), (float)((double)tileLocation.Y * (double)Game1.tileSize + (((double)tileLocation.Y * 11.0 + (double)tileLocation.X * 7.0) % 10.0 - 5.0)) + (float)(Game1.tileSize / 2))), new Rectangle?(new Rectangle((int)((double)tileLocation.X * 51.0 + (double)tileLocation.Y * 77.0) % 3 * 16, 128 + this.whichForageCrop * 16, 16, 16)), Color.White, 0.0f, new Vector2(8f, 8f), (float)Game1.pixelZoom, SpriteEffects.None, (float)(((double)tileLocation.Y * (double)Game1.tileSize + (double)(Game1.tileSize / 2) + (((double)tileLocation.Y * 11.0 + (double)tileLocation.X * 7.0) % 10.0 - 5.0)) / 10000.0)); + + } + + public override void produceEnergy() + { + + if (this.GetEnergyManager().canReceieveEnergy) + { + this.GetEnergyManager().produceEnergy(this.energyRequiredPer10Minutes); + } + + } + + public virtual void processFluidLogic() + { + return; + if (this.GetFluidManager().doTheInputTanksHaveEnoughFluid(ModCore.ObjectManager.resources.getFluid("Water"), ModCore.Configs.machinesConfig.steamBoilerV1_requiredWaterPerOperation)) + { + this.GetFluidManager().consumeFluid(ModCore.ObjectManager.resources.getFluid("Water"), ModCore.Configs.machinesConfig.steamBoilerV1_requiredWaterPerOperation); + this.GetFluidManager().produceFluid(ModCore.ObjectManager.resources.getFluid("Steam"), ModCore.Configs.machinesConfig.steamBoilerV1_producedSteamPerOperation); + this.containerObject.MinutesUntilReady -= 10; + } + } + + public override void updateInfo() + { + return; + if (this.info == null || this.containerObject == null) + { + this.ItemInfo = this.text; + //ModCore.log("Updated item info!"); + return; + } + + if (this.requiresUpdate()) + { + //this.ItemInfo = this.text; + this.text = this.ItemInfo; + this.info.cleanAfterUpdate(); + //this.containerObject.updateInfo(); + //ModCore.log("Force an update for machine: " + this.info.name); + MultiplayerUtilities.RequestUpdateSync(this.guid); + } + } + + public override Dictionary getAdditionalSaveData() + { + Dictionary saveData = base.getAdditionalSaveData(); + Revitalize.ModCore.Serializer.SerializeGUID(this.containerObject.childrenGuids[this.offsetKey].ToString(), this); + this.containerObject.getAdditionalSaveData(); + return saveData; + + } + } +} diff --git a/GeneralMods/Revitalize/Framework/Objects/Machines/Machine.cs b/GeneralMods/Revitalize/Framework/Objects/Machines/Machine.cs index 0c381a04..31c849ba 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Machines/Machine.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Machines/Machine.cs @@ -8,6 +8,7 @@ using Microsoft.Xna.Framework.Graphics; using Newtonsoft.Json; using PyTK.CustomElementHandler; using Revitalize.Framework.Crafting; +using Revitalize.Framework.Managers; using Revitalize.Framework.Menus; using Revitalize.Framework.Menus.Machines; using Revitalize.Framework.Objects.InformationFiles; @@ -38,6 +39,8 @@ namespace Revitalize.Framework.Objects.Machines string energyRequired = this.energyRequiredPer10Minutes.ToString(); string timeToProduce = this.timeToProduce.ToString(); string updatesContainer = this.updatesContainerObjectForProduction.ToString(); + string fluidString = this.requiredFluidForOperation != null ? ModCore.Serializer.ToJSONString(this.amountOfFluidRequiredForOperation) : ""; + string fluidAmountString = this.amountOfFluidRequiredForOperation.ToString(); StringBuilder b = new StringBuilder(); b.Append(info); b.Append("<"); @@ -56,6 +59,10 @@ namespace Revitalize.Framework.Objects.Machines b.Append(updatesContainer); b.Append("<"); b.Append(this.craftingRecipeBook); + b.Append("<"); + b.Append(fluidString); + b.Append("<"); + b.Append(fluidAmountString); //ModCore.log("Setting info: " + b.ToString()); return b.ToString(); } @@ -72,12 +79,18 @@ namespace Revitalize.Framework.Objects.Machines string time = data[6]; string updates = data[7]; this.craftingRecipeBook = data[8]; + string fluid = data[9]; + string fluidAmount = data[10]; this.info = (BasicItemInformation)Revitalize.ModCore.Serializer.DeserializeFromJSONString(infoString, typeof(BasicItemInformation)); this.data = Revitalize.ModCore.Serializer.DeserializeFromJSONString(pyTKData); this.energyRequiredPer10Minutes = Convert.ToInt32(energyRequired); this.timeToProduce = Convert.ToInt32(time); this.updatesContainerObjectForProduction = Convert.ToBoolean(updates); - + if (string.IsNullOrEmpty(fluid) == false) + { + this.requiredFluidForOperation = ModCore.Serializer.DeserializeFromJSONString(fluid); + } + this.amountOfFluidRequiredForOperation= Convert.ToInt32(fluidAmount); if (string.IsNullOrEmpty(offsetVec)) return; if (string.IsNullOrEmpty(containerObject)) return; this.offsetKey = ModCore.Serializer.DeserializeFromJSONString(offsetVec); @@ -158,6 +171,9 @@ namespace Revitalize.Framework.Objects.Machines } } + public Fluid requiredFluidForOperation; + public int amountOfFluidRequiredForOperation; + [JsonIgnore] public bool ConsumesEnergy { @@ -191,7 +207,7 @@ namespace Revitalize.Framework.Objects.Machines public Machine() { } - public Machine(CustomObjectData PyTKData, BasicItemInformation info, List ProducedResources = null, int EnergyRequiredPer10Minutes = 0, int TimeToProduce = 0, bool UpdatesContainer = false, string CraftingBook = "") : base(PyTKData, info) + public Machine(CustomObjectData PyTKData, BasicItemInformation info, List ProducedResources = null, int EnergyRequiredPer10Minutes = 0, int TimeToProduce = 0, bool UpdatesContainer = false, string CraftingBook = "", Fluid FluidRequiredForOperation = null, int FluidAmountRequiredPerOperation =0) : base(PyTKData, info) { this.producedResources = ProducedResources ?? new List(); this.energyRequiredPer10Minutes = EnergyRequiredPer10Minutes; @@ -200,10 +216,11 @@ namespace Revitalize.Framework.Objects.Machines this.MinutesUntilReady = TimeToProduce; this.craftingRecipeBook = CraftingBook; this.createStatusBubble(); - + this.requiredFluidForOperation = FluidRequiredForOperation; + this.amountOfFluidRequiredForOperation = FluidAmountRequiredPerOperation; } - public Machine(CustomObjectData PyTKData, BasicItemInformation info, Vector2 TileLocation, List ProducedResources = null, int EnergyRequiredPer10Minutes = 0, int TimeToProduce = 0, bool UpdatesContainer = false, string CraftingBook = "", MultiTiledObject obj = null) : base(PyTKData, info, TileLocation) + public Machine(CustomObjectData PyTKData, BasicItemInformation info, Vector2 TileLocation, List ProducedResources = null, int EnergyRequiredPer10Minutes = 0, int TimeToProduce = 0, bool UpdatesContainer = false, string CraftingBook = "", MultiTiledObject obj = null, Fluid FluidRequiredForOperation = null, int FluidAmountRequiredPerOperation =0) : base(PyTKData, info, TileLocation) { this.containerObject = obj; this.producedResources = ProducedResources ?? new List(); @@ -213,9 +230,11 @@ namespace Revitalize.Framework.Objects.Machines this.MinutesUntilReady = TimeToProduce; this.craftingRecipeBook = CraftingBook; this.createStatusBubble(); + this.requiredFluidForOperation = FluidRequiredForOperation; + this.amountOfFluidRequiredForOperation = FluidAmountRequiredPerOperation; } - public Machine(CustomObjectData PyTKData, BasicItemInformation info, Vector2 TileLocation, Vector2 offsetKey, List ProducedResources = null, int EnergyRequiredPer10Minutes = 0, int TimeToProduce = 0, bool UpdatesContainer = false, string CraftingBook = "", MultiTiledObject obj = null) : base(PyTKData, info, TileLocation) + public Machine(CustomObjectData PyTKData, BasicItemInformation info, Vector2 TileLocation, Vector2 offsetKey, List ProducedResources = null, int EnergyRequiredPer10Minutes = 0, int TimeToProduce = 0, bool UpdatesContainer = false, string CraftingBook = "", MultiTiledObject obj = null, Fluid FluidRequiredForOperation = null, int FluidAmountRequiredPerOperation =0) : base(PyTKData, info, TileLocation) { this.offsetKey = offsetKey; this.containerObject = obj; @@ -226,6 +245,8 @@ namespace Revitalize.Framework.Objects.Machines this.MinutesUntilReady = TimeToProduce; this.craftingRecipeBook = CraftingBook; this.createStatusBubble(); + this.requiredFluidForOperation = FluidRequiredForOperation; + this.amountOfFluidRequiredForOperation = FluidAmountRequiredPerOperation; } protected virtual void createStatusBubble() @@ -367,7 +388,7 @@ namespace Revitalize.Framework.Objects.Machines public override Item getOne() { - Machine component = new Machine(this.data, this.info.Copy(), this.producedResources, this.energyRequiredPer10Minutes, this.timeToProduce, this.updatesContainerObjectForProduction, this.craftingRecipeBook); + Machine component = new Machine(this.data, this.info.Copy(), this.producedResources, this.energyRequiredPer10Minutes, this.timeToProduce, this.updatesContainerObjectForProduction, this.craftingRecipeBook,this.requiredFluidForOperation,this.amountOfFluidRequiredForOperation); component.containerObject = this.containerObject; component.offsetKey = this.offsetKey; return component; @@ -491,6 +512,16 @@ namespace Revitalize.Framework.Objects.Machines } + public virtual void produceEnergy(double ratio) + { + + if (this.GetEnergyManager().canReceieveEnergy) + { + this.GetEnergyManager().produceEnergy((int)(this.energyRequiredPer10Minutes * ratio)); + } + + } + protected virtual void drawStatusBubble(SpriteBatch b, int x, int y, float Alpha) { if (this.updatesContainerObjectForProduction == false) return; diff --git a/GeneralMods/Revitalize/Framework/Objects/MultiTiledComponent.cs b/GeneralMods/Revitalize/Framework/Objects/MultiTiledComponent.cs index 095c0b76..2db112c2 100644 --- a/GeneralMods/Revitalize/Framework/Objects/MultiTiledComponent.cs +++ b/GeneralMods/Revitalize/Framework/Objects/MultiTiledComponent.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -741,22 +742,44 @@ namespace Revitalize.Framework.Objects protected virtual List FluidGraphSearchForFluidFromOutputTanks(Fluid L) { List fluidSources = new List(); - List searchedComponents = new List(); - List entitiesToSearch = new List(); - entitiesToSearch.AddRange(this.GetNeighboringFluidManagers()); - searchedComponents.Add(this); + HashSet searchedComponents = new HashSet(); + Queue entitiesToSearch = new Queue(); + HashSet searchedObjects = new HashSet(); + foreach(MultiTiledComponent tile in this.GetNeighboringFluidManagers()) + { + entitiesToSearch.Enqueue(tile); + } + //entitiesToSearch.AddRange(this.GetNeighboringFluidManagers()); + searchedComponents.Add(this.guid); while (entitiesToSearch.Count > 0) { - MultiTiledComponent searchComponent = entitiesToSearch[0]; - entitiesToSearch.Remove(searchComponent); - if (searchedComponents.Contains(searchComponent)) + MultiTiledComponent searchComponent = entitiesToSearch.Dequeue(); + //entitiesToSearch.Remove(searchComponent); + if (searchedComponents.Contains(searchComponent.guid)) { continue; } + /* + else if (searchedObjects.Contains(searchComponent.containerObject)) + { + continue; + } + */ else { - searchedComponents.Add(searchComponent); - entitiesToSearch.AddRange(searchComponent.GetNeighboringFluidManagers()); + searchedComponents.Add(searchComponent.guid); + searchedObjects.Add(searchComponent.containerObject.guid); + + List neighbors = searchComponent.GetNeighboringFluidManagers(); + + foreach(MultiTiledComponent tile in neighbors) + { + if (searchedObjects.Contains(tile.containerObject.guid) || searchedComponents.Contains(tile.guid)) continue; + else + { + entitiesToSearch.Enqueue(tile); + } + } if (searchComponent.containerObject.info.fluidManager.doesThisOutputTankContainThisFluid(L)) { diff --git a/GeneralMods/Revitalize/Framework/Objects/ObjectManager.cs b/GeneralMods/Revitalize/Framework/Objects/ObjectManager.cs index 98091012..b623a78f 100644 --- a/GeneralMods/Revitalize/Framework/Objects/ObjectManager.cs +++ b/GeneralMods/Revitalize/Framework/Objects/ObjectManager.cs @@ -414,6 +414,13 @@ namespace Revitalize.Framework.Objects steamBoilerV1.addComponent(new Vector2(1, 2), steamBoilerV1_1_2); this.AddItem("SteamBoilerV1", steamBoilerV1); + + MultiTiledObject steamEngineV1 = new MultiTiledObject(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Objects.Machines.SteamEngineV1", TextureManager.GetTexture(ModCore.Manifest, "Machines", "SteamEngine"), typeof(MultiTiledObject), Color.White, true), new BasicItemInformation("Steam Engine", "Omegasis.Revitalize.Objects.Machines.SteamEngine", "Consumes steam in order to produce power.", "Machine", Color.SteelBlue, -300, 0, false, 500, true, true, TextureManager.GetTexture(ModCore.Manifest, "Machines", "SteamEngine"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Machines", "SteamEngine"), new Animation(0, 0, 16, 16)), Color.White, false, null, null, new Energy.EnergyManager(500, Enums.EnergyInteractionType.Produces), false, null, null, new Managers.FluidManagerV2(2000, false, Enums.FluidInteractionType.Machine, false))); + SteamEngine steamEngineV1_0_0 = new SteamEngine(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Objects.Machines.SteamEngineV1", TextureManager.GetTexture(ModCore.Manifest, "Machines", "SteamEngine"), typeof(MultiTiledObject), Color.White, true), new BasicItemInformation("Steam Engine", "Omegasis.Revitalize.Objects.Machines.SteamEngine", "Consumes steam in order to produce power.", "Machine", Color.SteelBlue, -300, 0, false, 500, true, true, TextureManager.GetTexture(ModCore.Manifest, "Machines", "SteamEngine"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Machines", "SteamEngine"), new Animation(0, 0, 16, 16)), Color.White, false, new InventoryManager(9, 3, 3), null, new Energy.EnergyManager(500, Enums.EnergyInteractionType.Produces), false, null, null, new Managers.FluidManagerV2(2000, false, Enums.FluidInteractionType.Machine, false)), null, ModCore.Configs.machinesConfig.steamEngineV1_powerGeneratedPerOperation, 0, true, "", ModCore.ObjectManager.resources.getFluid("Steam"), ModCore.Configs.machinesConfig.steamEngineV1_requiredSteamPerOperation); + SteamEngine steamEngineV1_1_0 = new SteamEngine(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Objects.Machines.SteamEngineV1", TextureManager.GetTexture(ModCore.Manifest, "Machines", "SteamEngine"), typeof(MultiTiledObject), Color.White, true), new BasicItemInformation("Steam Engine", "Omegasis.Revitalize.Objects.Machines.SteamEngine", "Consumes steam in order to produce power.", "Machine", Color.SteelBlue, -300, 0, false, 500, true, true, TextureManager.GetTexture(ModCore.Manifest, "Machines", "SteamEngine"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Machines", "SteamEngine"), new Animation(16, 0, 16, 16)), Color.White, false, new InventoryManager(9, 3, 3), null, new Energy.EnergyManager(500, Enums.EnergyInteractionType.Produces), false, null, null, new Managers.FluidManagerV2(2000, false, Enums.FluidInteractionType.Machine, false)), null, ModCore.Configs.machinesConfig.steamEngineV1_powerGeneratedPerOperation, 0, true, "", ModCore.ObjectManager.resources.getFluid("Steam"), ModCore.Configs.machinesConfig.steamEngineV1_requiredSteamPerOperation); + steamEngineV1.addComponent(new Vector2(0, 0), steamEngineV1_0_0); + steamEngineV1.addComponent(new Vector2(1, 0), steamEngineV1_1_0); + this.AddItem("SteamEngineV1", steamEngineV1); } private void loadInConnectionComponents() diff --git a/GeneralMods/Revitalize/ModCore.cs b/GeneralMods/Revitalize/ModCore.cs index 6b0a98aa..ecd11d81 100644 --- a/GeneralMods/Revitalize/ModCore.cs +++ b/GeneralMods/Revitalize/ModCore.cs @@ -602,7 +602,8 @@ namespace Revitalize new StardewValley.Object((int)Enums.SDVObject.IronBar,100), ModCore.ObjectManager.GetItem("WaterPumpV1"), ModCore.ObjectManager.GetItem("SteamBoilerV1"), - ModCore.ObjectManager.GetItem("IronPipe",10) + ModCore.ObjectManager.GetItem("IronPipe",100), + ModCore.ObjectManager.GetItem("SteamEngineV1") }); } diff --git a/GeneralMods/Revitalize/Revitalize.csproj b/GeneralMods/Revitalize/Revitalize.csproj index 9f73a218..aaf21f71 100644 --- a/GeneralMods/Revitalize/Revitalize.csproj +++ b/GeneralMods/Revitalize/Revitalize.csproj @@ -167,6 +167,7 @@ + @@ -518,6 +519,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest