Fixed a really dumb stack overflow error on pathfinding across the world. THANK YOU.

This commit is contained in:
2017-12-02 21:53:30 -08:00
parent 31ddb0e7f1
commit ea2e7c134f
9 changed files with 273 additions and 58 deletions

View File

@ -0,0 +1,36 @@
using StardewValley;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StarAI.CheatCore
{
class DoorsToWarps
{
public static void makeAllDoorsWarps()
{
foreach(var v in Game1.locations)
{
foreach(var door in v.doors)
{
ModCore.CoreMonitor.Log(v.name.ToString());
ModCore.CoreMonitor.Log(door.Key.ToString());
ModCore.CoreMonitor.Log(door.Value);
foreach(var warp in Game1.getLocationFromName(door.Value).warps)
{
if (warp.TargetName == v.name && warp.TargetX==door.Key.X&& warp.TargetY==door.Key.Y+1)
{
Warp w = new Warp(door.Key.X, door.Key.Y, door.Value, warp.X, warp.Y - 1,false);
v.warps.Add(w);
}
}
}
}
}
}
}

View File

@ -42,7 +42,7 @@ namespace StarAI
PathFindingCore.Utilities.initializeTileExceptionList();
ExecutionCore.TaskMetaDataHeuristics.initializeToolCostDictionary();
//throw new NotImplementedException();
StardewModdingAPI.Events.LocationEvents.CurrentLocationChanged += LocationEvents_CurrentLocationChanged;
//StardewModdingAPI.Events.LocationEvents.CurrentLocationChanged += LocationEvents_CurrentLocationChanged;
StardewModdingAPI.Events.ControlEvents.KeyPressed += ControlEvents_KeyPressed;
StardewModdingAPI.Events.SaveEvents.AfterLoad += SaveEvents_AfterLoad;
@ -50,6 +50,7 @@ namespace StarAI
StardewModdingAPI.Events.SaveEvents.BeforeSave += SaveEvents_BeforeSave;
StardustCore.ModCore.SerializationManager.acceptedTypes.Add("StarAI.PathFindingCore.TileNode", new StardustCore.Serialization.SerializerDataNode(new StardustCore.Serialization.SerializerDataNode.SerializingFunction(StarAI.PathFindingCore.TileNode.Serialize), new StardustCore.Serialization.SerializerDataNode.ParsingFunction(StarAI.PathFindingCore.TileNode.ParseIntoInventory), new StardustCore.Serialization.SerializerDataNode.WorldParsingFunction(StarAI.PathFindingCore.TileNode.SerializeFromWorld), new StardustCore.Serialization.SerializerDataNode.SerializingToContainerFunction(StarAI.PathFindingCore.TileNode.Serialize)));
}
private void SaveEvents_BeforeSave(object sender, EventArgs e)
@ -81,6 +82,7 @@ namespace StarAI
private void SaveEvents_AfterLoad(object sender, EventArgs e)
{
loadExceptionTiles();
CheatCore.DoorsToWarps.makeAllDoorsWarps();
}
public void loadExceptionTiles()
@ -138,10 +140,7 @@ namespace StarAI
//K key for placing a tile.
#region
if (e.KeyPressed == Microsoft.Xna.Framework.Input.Keys.H)
{
CoreMonitor.Log(Game1.player.position.ToString());
}
if (e.KeyPressed == Microsoft.Xna.Framework.Input.Keys.K)
{
CoreMonitor.Log("OK THE K KEY WAS PRESSED!");
@ -198,12 +197,12 @@ namespace StarAI
ModCore.CoreMonitor.Log("SHITTTTTT: " + layer, LogLevel.Error);
}
int tileIndex = Game1.player.currentLocation.getTileIndexAt((int)Game1.player.getTileX() / Game1.tileSize, (int)Game1.player.getTileY() / Game1.tileSize, layer);
int tileIndex = Game1.player.currentLocation.getTileIndexAt((int)Game1.player.getTileX(), (int)Game1.player.getTileY(), layer);
if (tileIndex == -1) continue;
//ModCore.CoreMonitor.Log("Position: " + (Game1.player.getTileLocation() / Game1.tileSize).ToString(), LogLevel.Warn);
//ModCore.CoreMonitor.Log("Layer: " + layer, LogLevel.Warn);
//ModCore.CoreMonitor.Log("Index: " + tileIndex.ToString(), LogLevel.Warn);
//ModCore.CoreMonitor.Log("Image Source: " + v.ImageSource, LogLevel.Warn);
ModCore.CoreMonitor.Log("Position: " + (Game1.player.getTileLocation()).ToString(), LogLevel.Warn);
ModCore.CoreMonitor.Log("Layer: " + layer, LogLevel.Warn);
ModCore.CoreMonitor.Log("Index: " + tileIndex.ToString(), LogLevel.Warn);
ModCore.CoreMonitor.Log("Image Source: " + v.ImageSource, LogLevel.Warn);
if (layer == "Buildings")
{
@ -216,8 +215,8 @@ namespace StarAI
return; //tile is already initialized.
}
}
PathFindingCore.Utilities.ignoreCheckTiles.Add(tileException);
tileException.serializeJson(Path.Combine(ModCore.CoreHelper.DirectoryPath, PathFindingCore.Utilities.folderForExceptionTiles));
//PathFindingCore.Utilities.ignoreCheckTiles.Add(tileException);
// tileException.serializeJson(Path.Combine(ModCore.CoreHelper.DirectoryPath, PathFindingCore.Utilities.folderForExceptionTiles));
//StardustCore.ModCore.SerializationManager.
}
}

View File

@ -16,6 +16,10 @@ namespace StarAI.PathFindingCore.MapTransitionLogic
public Warp warp;
public List<WarpGoal> childrenWarps;
public static List<GameLocation> checkedLocations = new List<GameLocation>();
public static List<Warp> exploredLocations = new List<Warp>();
public WarpGoal(WarpGoal Parent, Warp CurrentWarp)
{
this.parentWarpGoal = Parent;
@ -26,6 +30,7 @@ namespace StarAI.PathFindingCore.MapTransitionLogic
public static void getWarpChain(GameLocation location, string mapName)
{
List<GameLocation> blerp = new List<GameLocation>();
GameLocation check = Game1.getLocationFromName(mapName);
if (check == null)
{
@ -43,11 +48,16 @@ namespace StarAI.PathFindingCore.MapTransitionLogic
TransitionLogic.transitionToAdjacentMap(location, mapName);
return;
}
exploredLocations.Add(Warp);
}
//keep chaining children
//exploredLocations.Add(location);
checkedLocations.Add(location);
List<WarpGoal> warpChain = okBye(startinggoals, mapName, location,checkedLocations);
List<WarpGoal> warpChain = okBye(startinggoals, mapName);
checkedLocations.Clear();
exploredLocations.Clear();
if (warpChain == null)
{
ModCore.CoreMonitor.Log("NULL WARP CHAIN");
@ -177,6 +187,9 @@ namespace StarAI.PathFindingCore.MapTransitionLogic
public static List<List<TileNode>> getWarpChainReturn(GameLocation location,string mapName)
{
GameLocation check = Game1.getLocationFromName(mapName);
List<GameLocation> blerp = new List<GameLocation>();
if (check.isStructure) mapName = check.uniqueName;
if (check == null)
{
ModCore.CoreMonitor.Log("INVALID LOCATION");
@ -188,6 +201,7 @@ namespace StarAI.PathFindingCore.MapTransitionLogic
{
WarpGoal child = new WarpGoal(null, Warp);
startinggoals.Add(child);
exploredLocations.Add(Warp);
/*
if (Warp.TargetName == mapName)
{
@ -200,8 +214,11 @@ namespace StarAI.PathFindingCore.MapTransitionLogic
}
//keep chaining children
List<WarpGoal> warpChain= okBye(startinggoals, mapName);
// exploredLocations.Add(location);
checkedLocations.Add(location);
List<WarpGoal> warpChain= okBye(startinggoals, mapName,location,checkedLocations);
checkedLocations.Clear();
exploredLocations.Clear();
if (warpChain == null)
{
ModCore.CoreMonitor.Log("NULL WARP CHAIN");
@ -396,43 +413,135 @@ namespace StarAI.PathFindingCore.MapTransitionLogic
//Do final location walk to stuff here.
}
public static List<WarpGoal> okBye(List<WarpGoal> param,string targetMapName)
/*
public static List<WarpGoal> okByeGOODLOCATION(List<WarpGoal> param, string targetMapName, GameLocation lastCheckedLocation)
{
bool found = false;
WarpGoal theOne= new WarpGoal(null,null);
List<WarpGoal> warpChain = new List<WarpGoal>();
foreach (WarpGoal w in param)
List<GameLocation> placesToExplore = new List<GameLocation>();
List<GameLocation> placesIHaveBeen = new List<GameLocation>();
foreach(var warpGoal in param)
{
GameLocation loc = Game1.getLocationFromName(w.warp.TargetName);
foreach (var v in loc.warps)
ModCore.CoreMonitor.Log(warpGoal.warp.TargetName);
placesToExplore.Add(Game1.getLocationFromName(warpGoal.warp.TargetName));
}
placesIHaveBeen.Add(lastCheckedLocation);
while (placesToExplore.Count != 0)
{
WarpGoal ok = new WarpGoal(w, v);
w.childrenWarps.Add(ok);
if (v.TargetName == targetMapName)
GameLocation currentCheckingLocation = placesToExplore.ElementAt(0);
while(checkedLocations.Contains(currentCheckingLocation))
{
found = true;
theOne = ok;
break;
placesToExplore.Remove(currentCheckingLocation);
currentCheckingLocation = placesToExplore.ElementAt(0);
ModCore.CoreMonitor.Log("REMOVING " + currentCheckingLocation.name, StardewModdingAPI.LogLevel.Warn);
}
foreach(var warp in currentCheckingLocation.warps)
{
bool addNewLocation = true;
foreach (var checkedPlace in placesIHaveBeen)
{
if (checkedPlace.name == warp.TargetName)
{
addNewLocation = false;
continue;
}
}
if (found == false)
foreach(var location in placesToExplore)
{
return okBye(w.childrenWarps,targetMapName);
}
if (found == true)
if(location.name== warp.TargetName)
{
while (theOne.parentWarpGoal != null)
addNewLocation = false;
continue;
}
}
if (addNewLocation == true)
{
warpChain.Add(theOne);
theOne = theOne.parentWarpGoal;
placesToExplore.Add(Game1.getLocationFromName(warp.TargetName));
ModCore.CoreMonitor.Log("ADDING NEW LOCATION" + warp.TargetName, StardewModdingAPI.LogLevel.Error);
}
warpChain.Add(theOne);
else
{
ModCore.CoreMonitor.Log("ALREADY BEEN AT THIS LOCATION: " + currentCheckingLocation.name, StardewModdingAPI.LogLevel.Warn);
}
return warpChain;
//recursively call this logic???
}
placesIHaveBeen.Add(currentCheckingLocation);
placesToExplore.Remove(currentCheckingLocation);
ModCore.CoreMonitor.Log("CHECKING LOCATION: " + currentCheckingLocation.name,StardewModdingAPI.LogLevel.Alert);
}
return new List<WarpGoal>();
}
*/
public static List<WarpGoal> okBye(List<WarpGoal> param, string targetMapName, GameLocation lastCheckedLocation,List<GameLocation> place)
{
// List<GameLocation> placesToExplore = new List<GameLocation>();
List<GameLocation> placesIHaveBeen = place;
List<GameLocation> initialLocations = new List<GameLocation>();
placesIHaveBeen.Add(lastCheckedLocation);
bool found = false;
if (param.Count == 0)
{
return new List<WarpGoal>();
}
foreach(var warpGoal in param)
{
WarpGoal lastWarp = warpGoal;
GameLocation targetLocation = Game1.getLocationFromName(warpGoal.warp.TargetName);
if (targetLocation.name == targetMapName)
{
List<WarpGoal> hate = new List<WarpGoal>();
while (lastWarp.parentWarpGoal!=null)
{
hate.Add(lastWarp);
lastWarp = lastWarp.parentWarpGoal;
}
hate.Add(lastWarp);
return hate;
}
bool ignore = false;
foreach (var v in placesIHaveBeen)
{
if (v.name == targetLocation.name)
{
ModCore.CoreMonitor.Log("I guve ps"+v.name);
ignore = true;
break;
}
}
if (ignore == true) continue;
ModCore.CoreMonitor.Log("I AM HERE:"+targetLocation.name);
foreach (Warp warp in targetLocation.warps)
{
WarpGoal fun = new WarpGoal(warpGoal, warp);
warpGoal.childrenWarps.Add(fun);
}
placesIHaveBeen.Add(targetLocation);
List<WarpGoal> idk = okBye(lastWarp.childrenWarps, targetMapName, targetLocation,placesIHaveBeen);
if (idk.Count == 0) continue;
if (idk.ElementAt(0).warp.TargetName == targetMapName) return idk;
// placesIHaveBeen.Clear();
}
return new List<WarpGoal>();
}
}
}

View File

@ -87,6 +87,7 @@ namespace StarAI.PathFindingCore
if (t.thisLocation.isObjectAt((int)pos.X, (int)pos.Y))
{
// ModCore.CoreMonitor.Log("OBJECt??? " + t.thisLocation.name, LogLevel.Error);
//ModCore.CoreMonitor.Log("Object at this tile position!: " + t.thisLocation.objects[new Vector2(pos.X/Game1.tileSize,pos.Y/Game1.tileSize)].name, LogLevel.Warn);
if (cry == true) t.thisLocation = null;
return false;
@ -96,8 +97,17 @@ namespace StarAI.PathFindingCore
foreach (var v in Utilities.tileExceptionList)
{
// ModCore.CoreMonitor.Log(v.actionType);
if (v.tile.position == pos) return false;
if (v.tile.tileLocation == pos / Game1.tileSize) return false;
// ModCore.CoreMonitor.Log("UTILITY????: " + t.thisLocation.name, LogLevel.Error);
if (v.tile.position == pos)
{
// ModCore.CoreMonitor.Log("DERP????: " + t.thisLocation.name, LogLevel.Error);
return false;
}
if (v.tile.tileLocation == pos / Game1.tileSize)
{
// ModCore.CoreMonitor.Log("BLURP " + t.thisLocation.name, LogLevel.Error);
return false;
}
}
}
@ -105,30 +115,34 @@ namespace StarAI.PathFindingCore
if (terrainFeature)
{
TerrainFeature terrain = t.thisLocation.terrainFeatures[pos / Game1.tileSize];
// ModCore.CoreMonitor.Log("TERRAIN NOPE!: " + t.thisLocation.name, LogLevel.Error);
if (terrain.isPassable()) return true;
}
if (t.thisLocation.isTileOccupied(pos / Game1.tileSize))
{
// ModCore.CoreMonitor.Log("Tile occupied!: " + t.thisLocation.name, LogLevel.Error);
if (isTileExempt(t,pos)) return true;
if (cry == true) t.thisLocation = null;
return false;
}
/*
if (t.thisLocation.isTilePlaceable(pos / Game1.tileSize) == false)
{
// ModCore.CoreMonitor.Log("Tile Not placeable at location. " + t.thisLocation.name, LogLevel.Error);
if (cry == true) t.thisLocation = null;
return false;
}
*/
if (t.thisLocation.isTilePassable(new xTile.Dimensions.Location((int)(pos.X/Game1.tileSize), (int)(pos.Y/Game1.tileSize)), Game1.viewport)==false)
{
//ModCore.CoreMonitor.Log("Tile not passable check 2?????!!!!: " + t.thisLocation.name, LogLevel.Error);
if (isTileExempt(t,pos)) return true;
if (cry == true) t.thisLocation = null;
return false;
else return false;
}
@ -137,6 +151,44 @@ namespace StarAI.PathFindingCore
return true;
}
public static bool isTileExempt(TileNode t,Vector2 pos)
{
foreach (var v in Game1.player.currentLocation.map.TileSheets)
{
foreach (var q in Game1.player.currentLocation.map.Layers)
{
string[] s = q.ToString().Split(':');
string layer = s[1].Trim();
int tileIndex = t.thisLocation.getTileIndexAt((int)pos.X/Game1.tileSize, (int)pos.Y / Game1.tileSize, layer);
if (tileIndex == -1) continue;
//ModCore.CoreMonitor.Log("Position: " + (Game1.player.getTileLocation() / Game1.tileSize).ToString(), LogLevel.Warn);
//ModCore.CoreMonitor.Log("Layer: " + layer, LogLevel.Warn);
//ModCore.CoreMonitor.Log("Index: " + tileIndex.ToString(), LogLevel.Warn);
//ModCore.CoreMonitor.Log("Image Source: " + v.ImageSource, LogLevel.Warn);
if (layer == "Buildings")
{
TileExceptionNode tileException = new TileExceptionNode(v.ImageSource, tileIndex);
foreach (var tile in PathFindingCore.Utilities.ignoreCheckTiles)
{
if (tile.imageSource == tileException.imageSource && tile.index == tileException.index)
{
ModCore.CoreMonitor.Log("Tile exception already initialized!");
return true; //tile is already initialized.
}
}
// PathFindingCore.Utilities.ignoreCheckTiles.Add(tileException);
//tileException.serializeJson(Path.Combine(ModCore.CoreHelper.DirectoryPath, PathFindingCore.Utilities.folderForExceptionTiles));
//StardustCore.ModCore.SerializationManager.
}
}
}
return false;
}
public static void setSingleTileAsChild(TileNode t,int x, int y,bool checkForUtility,bool placementAction=true)
{

View File

@ -34,7 +34,25 @@ namespace StarAI.PathFindingCore
public static void initializeTileExceptionList()
{
ignoreCheckTiles.Add(new TileExceptionNode("Maps\\spring_outdoorsTileSheet", 779));
ignoreCheckTiles.Add(new TileExceptionNode("Maps\\spring_outdoorsTileSheet", 780));
ignoreCheckTiles.Add(new TileExceptionNode("Maps\\spring_outdoorsTileSheet", 781));
ignoreCheckTiles.Add(new TileExceptionNode("Maps\\spring_outdoorsTileSheet", 782));
ignoreCheckTiles.Add(new TileExceptionNode("Maps\\summer_outdoorsTileSheet", 779));
ignoreCheckTiles.Add(new TileExceptionNode("Maps\\summer_outdoorsTileSheet", 780));
ignoreCheckTiles.Add(new TileExceptionNode("Maps\\summer_outdoorsTileSheet", 781));
ignoreCheckTiles.Add(new TileExceptionNode("Maps\\summer_outdoorsTileSheet", 782));
ignoreCheckTiles.Add(new TileExceptionNode("Maps\\fall_outdoorsTileSheet", 779));
ignoreCheckTiles.Add(new TileExceptionNode("Maps\\fall_outdoorsTileSheet", 780));
ignoreCheckTiles.Add(new TileExceptionNode("Maps\\fall_outdoorsTileSheet", 781));
ignoreCheckTiles.Add(new TileExceptionNode("Maps\\fall_outdoorsTileSheet", 782));
ignoreCheckTiles.Add(new TileExceptionNode("Maps\\winter_outdoorsTileSheet", 779));
ignoreCheckTiles.Add(new TileExceptionNode("Maps\\winter_outdoorsTileSheet", 780));
ignoreCheckTiles.Add(new TileExceptionNode("Maps\\winter_outdoorsTileSheet", 781));
ignoreCheckTiles.Add(new TileExceptionNode("Maps\\winter_outdoorsTileSheet", 782));
}

View File

@ -56,6 +56,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CheatCore\DoorsToWarps.cs" />
<Compile Include="Commands.cs" />
<Compile Include="ExecutionCore\CustomTask.cs" />
<Compile Include="ExecutionCore\TaskList.cs" />
@ -76,10 +77,10 @@
<Compile Include="PathFindingCore\MapTransitionLogic\TransitionLogic.cs" />
<Compile Include="PathFindingCore\MapTransitionLogic\WarpGoal.cs" />
<Compile Include="PathFindingCore\PathFindingLogic.cs" />
<Compile Include="PathFindingCore\PlacementNode.cs" />
<Compile Include="PathFindingCore\TileExceptionMetaData.cs" />
<Compile Include="PathFindingCore\TileExceptionNode.cs" />
<Compile Include="PathFindingCore\TileNodeObject.cs" />
<Compile Include="PathFindingCore\TileNodes\PlacementNode.cs" />
<Compile Include="PathFindingCore\TileNodes\TileExceptionMetaData.cs" />
<Compile Include="PathFindingCore\TileNodes\TileExceptionNode.cs" />
<Compile Include="PathFindingCore\TileNodes\TileNodeObject.cs" />
<Compile Include="PathFindingCore\Utilities.cs" />
<Compile Include="PathFindingCore\WaterLogic\WaterLogic.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />