Added in pipes and added some optimization checks to searching out energy and fluid networks.

This commit is contained in:
JoshuaNavarro 2019-09-25 15:02:58 -07:00
parent ecfc595751
commit 32e1c9d3ac
9 changed files with 362 additions and 7 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 B

View File

@ -241,7 +241,7 @@ namespace Revitalize.Framework.Objects.Machines.EnergyGeneration
{
this.GetFluidManager().consumeFluid(ModCore.ObjectManager.resources.getFluid("Water"), 200);
this.GetFluidManager().produceFluid(ModCore.ObjectManager.resources.getFluid("Steam"), 100);
this.MinutesUntilReady -= 10;
this.containerObject.MinutesUntilReady -= 10;
}
}

View File

@ -0,0 +1,160 @@
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 StardewValley;
namespace Revitalize.Framework.Objects.Machines
{
public class Pipe:Machine
{
public Pipe() { }
public Pipe(CustomObjectData PyTKData, BasicItemInformation info) : base(PyTKData, info, null, 0, 0, true, "")
{
}
public Pipe(CustomObjectData PyTKData, BasicItemInformation info, Vector2 TileLocation, MultiTiledObject obj = null) : base(PyTKData, info, TileLocation, null, 0, 0, true, "", obj)
{
}
public Pipe(CustomObjectData PyTKData, BasicItemInformation info, Vector2 TileLocation, Vector2 offsetKey, MultiTiledObject obj = null) : base(PyTKData, info, TileLocation, offsetKey, null, 0, 0, true, "", obj)
{
}
public override bool minutesElapsed(int minutes, GameLocation environment)
{
this.updateInfo();
return false;
}
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);
return true;
}
/// <summary>
/// Creates the necessary components to display the machine menu properly.
/// </summary>
public override Item getOne()
{
Pipe component = new Pipe(this.data, this.info.Copy(), this.TileLocation, this.offsetKey, this.containerObject);
return component;
}
public override ICustomObject recreate(Dictionary<string, string> additionalSaveData, object replacement)
{
//instead of using this.offsetkey.x use get additional save data function and store offset key there
Vector2 offsetKey = new Vector2(Convert.ToInt32(additionalSaveData["offsetKeyX"]), Convert.ToInt32(additionalSaveData["offsetKeyY"]));
Pipe self = Revitalize.ModCore.Serializer.DeserializeGUID<Pipe>(additionalSaveData["GUID"]);
if (self == null)
{
return null;
}
if (!Revitalize.ModCore.ObjectGroups.ContainsKey(additionalSaveData["ParentGUID"]))
{
//Get new container
PipeMultiTiledObject obj = (PipeMultiTiledObject)Revitalize.ModCore.Serializer.DeserializeGUID<PipeMultiTiledObject>(additionalSaveData["ParentGUID"]);
self.containerObject = obj;
obj.addComponent(offsetKey, self);
//Revitalize.ModCore.log("ADD IN AN OBJECT!!!!");
Revitalize.ModCore.ObjectGroups.Add(additionalSaveData["ParentGUID"], (MultiTiledObject)obj);
}
else
{
self.containerObject = Revitalize.ModCore.ObjectGroups[additionalSaveData["ParentGUID"]];
Revitalize.ModCore.ObjectGroups[additionalSaveData["GUID"]].addComponent(offsetKey, self);
//Revitalize.ModCore.log("READD AN OBJECT!!!!");
}
return (ICustomObject)self;
}
public override void rebuild(Dictionary<string, string> additionalSaveData, object replacement)
{
base.rebuild(additionalSaveData, replacement);
}
public override Dictionary<string, string> getAdditionalSaveData()
{
Dictionary<string, string> saveData = base.getAdditionalSaveData();
Revitalize.ModCore.Serializer.SerializeGUID(this.containerObject.childrenGuids[this.offsetKey].ToString(), this);
this.containerObject.getAdditionalSaveData();
return saveData;
}
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;
}
//this.determineWireOrientation();
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);
try
{
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 bool canBePlacedInWater()
{
return true;
}
private void determinePipeOrientation()
{
//TODO: Make this so that the correct wire orientation is used if I want to get fancy with pipes and their graphics.
}
}
}

View File

@ -0,0 +1,181 @@
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 StardewValley;
namespace Revitalize.Framework.Objects.Machines
{
public class PipeMultiTiledObject:MultiTiledObject
{
public PipeMultiTiledObject() : base()
{
}
public PipeMultiTiledObject(CustomObjectData PyTKData, BasicItemInformation info)
: base(PyTKData, info)
{
}
public PipeMultiTiledObject(CustomObjectData PyTKData, BasicItemInformation info, Vector2 TileLocation)
: base(PyTKData, info, TileLocation)
{
}
public PipeMultiTiledObject(CustomObjectData PyTKData, BasicItemInformation info, Vector2 TileLocation, Dictionary<Vector2, MultiTiledComponent> ObjectsList)
: base(PyTKData, info, TileLocation, ObjectsList)
{
}
public override Item getOne()
{
Dictionary<Vector2, MultiTiledComponent> objs = new Dictionary<Vector2, MultiTiledComponent>();
foreach (var pair in this.objects)
{
objs.Add(pair.Key, (MultiTiledComponent)pair.Value.getOne());
}
return new PipeMultiTiledObject(this.data, this.info.Copy(), this.TileLocation, objs);
}
public override ICustomObject recreate(Dictionary<string, string> additionalSaveData, object replacement)
{
PipeMultiTiledObject obj = (PipeMultiTiledObject)Revitalize.ModCore.Serializer.DeserializeGUID<PipeMultiTiledObject>(additionalSaveData["GUID"]);
if (obj == null)
{
return null;
}
Dictionary<Vector2, Guid> guids = new Dictionary<Vector2, Guid>();
foreach (KeyValuePair<Vector2, Guid> pair in obj.childrenGuids)
{
guids.Add(pair.Key, pair.Value);
}
foreach (KeyValuePair<Vector2, Guid> pair in guids)
{
obj.childrenGuids.Remove(pair.Key);
MultiTiledComponent component = Revitalize.ModCore.Serializer.DeserializeGUID<MultiTiledComponent>(pair.Value.ToString());
component.InitNetFields();
obj.removeComponent(pair.Key);
obj.addComponent(pair.Key, component);
}
obj.InitNetFields();
if (!Revitalize.ModCore.ObjectGroups.ContainsKey(additionalSaveData["GUID"]))
{
Revitalize.ModCore.ObjectGroups.Add(additionalSaveData["GUID"], obj);
return obj;
}
else
{
return Revitalize.ModCore.ObjectGroups[additionalSaveData["GUID"]];
}
}
public override Dictionary<string, string> getAdditionalSaveData()
{
Dictionary<string, string> saveData = base.getAdditionalSaveData();
//saveData.Add("GUID", this.guid.ToString());
//Revitalize.ModCore.Serializer.SerializeGUID(this.guid.ToString(), this);
return saveData;
}
public override void rebuild(Dictionary<string, string> additionalSaveData, object replacement)
{
base.rebuild(additionalSaveData, replacement);
}
public override void draw(SpriteBatch spriteBatch, int x, int y, float alpha = 1)
{
this.updateInfo();
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
{
(pair.Value as MultiTiledComponent).draw(spriteBatch, x + ((int)pair.Key.X), y + ((int)pair.Key.Y), alpha);
}
}
public override void draw(SpriteBatch spriteBatch, int xNonTile, int yNonTile, float layerDepth, float alpha = 1)
{
this.updateInfo();
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
{
pair.Value.draw(spriteBatch, xNonTile + (int)pair.Key.X * Game1.tileSize, yNonTile + (int)pair.Key.Y * Game1.tileSize, layerDepth, alpha);
}
//base.draw(spriteBatch, xNonTile, yNonTile, layerDepth, alpha);
}
public override void drawInMenu(SpriteBatch spriteBatch, Vector2 location, float scaleSize, float transparency, float layerDepth, bool drawStackNumber, Color c, bool drawShadow)
{
this.updateInfo();
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
{
//ModCore.log(location + (pair.Key * 16) + new Vector2(32, 32));
pair.Value.drawInMenu(spriteBatch, location + (pair.Key * 16) + new Vector2(32, 32), 1.0f, transparency, layerDepth, drawStackNumber, c, drawShadow);
}
if (drawStackNumber && this.maximumStackSize() > 1 && ((double)scaleSize > 0.3 && this.Stack != int.MaxValue) && this.Stack > 1)
Utility.drawTinyDigits(this.Stack, spriteBatch, location + new Vector2((float)(Game1.tileSize - Utility.getWidthOfTinyDigitString(this.Stack, 3f * scaleSize)) + 3f * scaleSize, (float)((double)Game1.tileSize - 18.0 * (double)scaleSize + 2.0)), 3f * scaleSize, 1f, Color.White);
//base.drawInMenu(spriteBatch, location, scaleSize, transparency, layerDepth, drawStackNumber, c, drawShadow);
}
public override void drawWhenHeld(SpriteBatch spriteBatch, Vector2 objectPosition, Farmer f)
{
this.updateInfo();
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
pair.Value.drawWhenHeld(spriteBatch, objectPosition + (pair.Key * Game1.tileSize), f);
//base.drawWhenHeld(spriteBatch, objectPosition, f);
}
public override bool canStackWith(Item other)
{
if (other is PipeMultiTiledObject)
{
return (other as PipeMultiTiledObject).info.id == this.info.id && (other as PipeMultiTiledObject).info.DyedColor == this.info.DyedColor;
}
else return false;
}
public override int maximumStackSize()
{
return 999;
}
public override bool placementAction(GameLocation location, int x, int y, Farmer who = null)
{
this.updateInfo();
PipeMultiTiledObject m = (PipeMultiTiledObject)this.getOne();
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in m.objects)
{
/*
if ((pair.Value as CustomObject).info.ignoreBoundingBox)
{
pair.Value.placementAction(location, -1 * (x + (int)pair.Key.X * Game1.tileSize), -1 * (y + (int)pair.Key.Y * Game1.tileSize), who);
}
else
{
pair.Value.placementAction(location, x + (int)pair.Key.X * Game1.tileSize, y + (int)pair.Key.Y * Game1.tileSize, who);
}*/
(pair.Value as MultiTiledComponent).placementAction(location, x + (int)pair.Key.X * Game1.tileSize, y + (int)pair.Key.Y * Game1.tileSize, who);
//ModCore.log(pair.Value.TileLocation);
}
m.location = location;
return true;
//return base.placementAction(location, x, y, who);
}
}
}

View File

@ -71,11 +71,11 @@ namespace Revitalize.Framework.Objects.Machines
if (!Revitalize.ModCore.ObjectGroups.ContainsKey(additionalSaveData["ParentGUID"]))
{
//Get new container
MultiTiledObject obj = (MultiTiledObject)Revitalize.ModCore.Serializer.DeserializeGUID<MultiTiledObject>(additionalSaveData["ParentGUID"]);
WireMultiTiledObject obj = (WireMultiTiledObject)Revitalize.ModCore.Serializer.DeserializeGUID<WireMultiTiledObject>(additionalSaveData["ParentGUID"]);
self.containerObject = obj;
obj.addComponent(offsetKey, self);
//Revitalize.ModCore.log("ADD IN AN OBJECT!!!!");
Revitalize.ModCore.ObjectGroups.Add(additionalSaveData["ParentGUID"], (MultiTiledObject)obj);
Revitalize.ModCore.ObjectGroups.Add(additionalSaveData["ParentGUID"], (WireMultiTiledObject)obj);
}
else
{

View File

@ -433,6 +433,7 @@ namespace Revitalize.Framework.Objects
{
if ((obj as MultiTiledComponent).GetEnergyManager().energyInteractionType == Enums.EnergyInteractionType.Produces || (obj as MultiTiledComponent).GetEnergyManager().energyInteractionType == Enums.EnergyInteractionType.Transfers || (obj as MultiTiledComponent).GetEnergyManager().energyInteractionType == Enums.EnergyInteractionType.Storage)
{
if ((obj as MultiTiledComponent).containerObject == this.containerObject) continue;
customObjects.Add((MultiTiledComponent)obj);
}
}
@ -471,6 +472,7 @@ namespace Revitalize.Framework.Objects
{
if ((obj as MultiTiledComponent).GetEnergyManager().energyInteractionType == Enums.EnergyInteractionType.Consumes || (obj as MultiTiledComponent).GetEnergyManager().energyInteractionType == Enums.EnergyInteractionType.Transfers || (obj as MultiTiledComponent).GetEnergyManager().energyInteractionType == Enums.EnergyInteractionType.Storage)
{
if ((obj as MultiTiledComponent).containerObject == this.containerObject) continue;
customObjects.Add((MultiTiledComponent)obj);
}
}
@ -714,12 +716,13 @@ namespace Revitalize.Framework.Objects
if ((obj as MultiTiledComponent).GetFluidManager().InteractsWithFluids)
{
if ((obj as MultiTiledComponent).containerObject == this.containerObject) continue;
customObjects.Add((MultiTiledComponent)obj);
//ModCore.log("Found a neighboring fluid manager");
}
else
{
ModCore.log("Found a neighboring object but it isn't a valid fluid manager.");
//ModCore.log("Found a neighboring object but it isn't a valid fluid manager.");
}
}
else continue;

View File

@ -168,7 +168,7 @@ namespace Revitalize.Framework.Objects
private void loadInMachines()
{
this.loadInWires();
this.loadInConnectionComponents();
@ -416,12 +416,17 @@ namespace Revitalize.Framework.Objects
this.AddItem("SteamBoilerV1", steamBoilerV1);
}
private void loadInWires()
private void loadInConnectionComponents()
{
WireMultiTiledObject copperWire = new WireMultiTiledObject(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Objects.Machines.Wires.CopperWire", TextureManager.GetTexture(ModCore.Manifest, "Machines", "CopperWire"), typeof(Wire), Color.White, true), new BasicItemInformation("Copper Wire", "Omegasis.Revitalize.Objects.Machines.Wire.CopperWire", "Wire made from copper bars. Transfers energy between sources.", "Machine", Color.SteelBlue, -300, 0, false, 15, true, true, TextureManager.GetTexture(ModCore.Manifest, "Machines", "CopperWire"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Machines", "CopperWire"), new Animation(0, 0, 16, 16)), Color.White, true, null, null, new Energy.EnergyManager(100, Enums.EnergyInteractionType.Transfers), false));
Wire copperWire_0_0 = new Wire(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Objects.Machines.Wires.CopperWire", TextureManager.GetTexture(ModCore.Manifest, "Machines", "CopperWire"), typeof(Wire), Color.White, true), new BasicItemInformation("Copper Wire", "Omegasis.Revitalize.Objects.Machines.Wire.CopperWire", "Wire made from copper bars. Transfers energy between sources.", "Machine", Color.SteelBlue, -300, 0, false, 15, true, true, TextureManager.GetTexture(ModCore.Manifest, "Machines", "CopperWire"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Machines", "CopperWire"), new Animation(0, 0, 16, 16)), Color.White, true, null, null, new Energy.EnergyManager(100, Enums.EnergyInteractionType.Transfers),false));
copperWire.addComponent(new Vector2(0, 0), copperWire_0_0);
this.AddItem("CopperWire", copperWire);
PipeMultiTiledObject ironPipe = new PipeMultiTiledObject(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Objects.Machines.Wires.IronPipe", TextureManager.GetTexture(ModCore.Manifest, "Machines", "IronPipe"), typeof(Pipe), Color.White, true), new BasicItemInformation("Iron Pipe", "Omegasis.Revitalize.Objects.Machines.Wire.Pipe", "Pipes made from iron. Transfers fluids between machines.", "Machine", Color.SteelBlue, -300, 0, false, 25, true, true, TextureManager.GetTexture(ModCore.Manifest, "Machines", "IronPipe"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Machines", "IronPipe"), new Animation(0, 0, 16, 16)), Color.White, true, null, null, null, false,null,null,new Managers.FluidManagerV2(0,false, Enums.FluidInteractionType.Transfers,false)));
Pipe ironPipe_0_0 = new Pipe(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Objects.Machines.Wires.IronPipe", TextureManager.GetTexture(ModCore.Manifest, "Machines", "IronPipe"), typeof(Pipe), Color.White, true), new BasicItemInformation("Iron Pipe", "Omegasis.Revitalize.Objects.Machines.Wire.Pipe", "Pipes made from iron. Transfers fluids between machines.", "Machine", Color.SteelBlue, -300, 0, false, 25, true, true, TextureManager.GetTexture(ModCore.Manifest, "Machines", "IronPipe"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Machines", "IronPipe"), new Animation(0, 0, 16, 16)), Color.White, true, null, null, null, false, null, null, new Managers.FluidManagerV2(0, false, Enums.FluidInteractionType.Transfers, false)));
ironPipe.addComponent(new Vector2(0, 0), ironPipe_0_0);
this.AddItem("IronPipe", ironPipe);
}
private void loadInTools()

View File

@ -601,7 +601,8 @@ namespace Revitalize
ModCore.ObjectManager.GetItem("AlloyFurnace"),
new StardewValley.Object((int)Enums.SDVObject.IronBar,100),
ModCore.ObjectManager.GetItem("WaterPumpV1"),
ModCore.ObjectManager.GetItem("SteamBoilerV1")
ModCore.ObjectManager.GetItem("SteamBoilerV1"),
ModCore.ObjectManager.GetItem("IronPipe",10)
});
}

View File

@ -169,6 +169,8 @@
<Compile Include="Framework\Objects\Machines\EnergyGeneration\SteamBoiler.cs" />
<Compile Include="Framework\Objects\Machines\Grinder.cs" />
<Compile Include="Framework\Objects\Machines\Machine.cs" />
<Compile Include="Framework\Objects\Machines\Pipe.cs" />
<Compile Include="Framework\Objects\Machines\PipeMultiTiledObject.cs" />
<Compile Include="Framework\Objects\Machines\WaterPump.cs" />
<Compile Include="Framework\Objects\Machines\Wire.cs" />
<Compile Include="Framework\Objects\Machines\WireMultiTiledObject.cs" />
@ -501,6 +503,9 @@
<Content Include="Content\Graphics\Objects\Machines\MiningDrillMachine.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Graphics\Objects\Machines\Pipes\IronPipe.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Graphics\Objects\Machines\Sandbox.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>