Now pathfinds to closest tree possible. Probably want to do the same for the other tasks.

This commit is contained in:
2017-11-30 16:06:19 -08:00
parent 992ef687e7
commit 38af511cfd
9 changed files with 639 additions and 55 deletions

View File

@ -803,5 +803,35 @@ namespace StardustCore
}
public static KeyValuePair<Vector2,TerrainFeature> checkRadiusForTerrainFeature(int radius, Type terrainType)
{
for (int x = -radius; x <= radius; x++)
{
for (int y = -radius; y <= radius; y++)
{
Vector2 pos = new Vector2((Game1.player.getTileX() + x), (Game1.player.getTileY() + y));
bool f = Game1.player.currentLocation.isTerrainFeatureAt((int)pos.X,(int)pos.Y);
if (f == false) continue;
TerrainFeature t = Game1.player.currentLocation.terrainFeatures[pos]; //((Game1.player.getTileX() + x) * Game1.tileSize, (Game1.player.getTileY() + y) * Game1.tileSize);
if (t == null) continue;
if (t.GetType() == terrainType)
{
return new KeyValuePair<Vector2, TerrainFeature> (pos,t);
}
}
}
return new KeyValuePair<Vector2, TerrainFeature>(new Vector2(),null);
}
public static bool doesLocationContainTerrainFeature(GameLocation location, Type terrain)
{
foreach (var v in location.terrainFeatures)
{
if (terrain == v.Value.GetType()) return true;
}
return false;
}
}
}

View File

@ -31,6 +31,10 @@ namespace StarAI
ModCore.CoreHelper.ConsoleCommands.Add("choptwigs", "Chop twigs.", new Action<string, string[]>(Commands.chopAllTwigs));
ModCore.CoreHelper.ConsoleCommands.Add("chopsticks", "Chop twigs.", new Action<string, string[]>(Commands.chopAllTwigs));
ModCore.CoreHelper.ConsoleCommands.Add("choptrees", "Chop trees down.", new Action<string, string[]>(Commands.chopAllTrees));
ModCore.CoreHelper.ConsoleCommands.Add("cuttrees", "Chop trees down.", new Action<string, string[]>(Commands.chopAllTrees));
ModCore.CoreHelper.ConsoleCommands.Add("breakstones", "Break small stones with pickaxe.", new Action<string, string[]>(Commands.breakAllStones));
ModCore.CoreHelper.ConsoleCommands.Add("cutweed", "Cut weeds with a tool.", new Action<string, string[]>(Commands.cutAllWeeds));
@ -47,6 +51,20 @@ namespace StarAI
ChestLogic.getAllSeasonalSeedsFromAllChestsAtLocation(Game1.player.currentLocation);
}
public static void chopAllTrees(string s, string[] args)
{
if (args.Length == 1)
{
if (args[0] == "All" || args[0] == "all")
{
ModCore.CoreMonitor.Log("CHOP ALL TREES");
DebrisLogic.getAllTreesToChop(Game1.player.currentLocation);
return;
}
}
DebrisLogic.getAllTreesToChopRadius(Game1.player.currentLocation);
}
public static void chopAllTwigs(string s, string[] args)
{
if (args.Length == 1)

View File

@ -30,7 +30,14 @@ namespace StarAI.ExecutionCore
objectTask = objTask;
objectParameterDataArray = arrayData;
this.taskMetaData = TaskMetaData;
this.taskMetaData.calculateTaskCost((TileNode)arrayData[0],true);
try
{
this.taskMetaData.calculateTaskCost((TileNode)arrayData[0], true);
}
catch(Exception err)
{
this.taskMetaData.calculateTaskCost((List<TileNode>)arrayData[0], true);
}
}
public CustomTask(VoidTask vTask, TaskMetaData TaskMetaData)

View File

@ -34,18 +34,43 @@ namespace StarAI.ExecutionCore
{
if (removalList.Contains(task2)) continue;
object[] oArray = (object[])task2.objectParameterDataArray;
TileNode t =(TileNode) oArray[0];
task2.taskMetaData.calculateTaskCost(t,true);
try
{
TileNode t = (TileNode)oArray[0];
ModCore.CoreMonitor.Log("Premtive calculate 1");
task2.taskMetaData.calculateTaskCost(t, false);
object[] objArr = new object[3];
objArr[0] = (object)t;
objArr[1] = (object)task2.taskMetaData.path;
task2.objectParameterDataArray = objArr;
}
catch(Exception err)
{
List<TileNode> t = (List<TileNode>)oArray[0];
ModCore.CoreMonitor.Log("Premtive calculate 2");
foreach(var s in Utilities.tileExceptionList)
{
ModCore.CoreMonitor.Log(s.actionType);
}
task2.taskMetaData.calculateTaskCost(t, false);
object[] objArr = new object[3];
objArr[0] = (object)t; //List of trees to use for path calculations
objArr[1] = (object)task2.taskMetaData.path; //The path itself.
int malcolm = 0;
ModCore.CoreMonitor.Log("THIS IS MALCOLM:" + malcolm);
objArr[2] = (object)task2.taskMetaData.path.ElementAt(malcolm); //source of whatever is hit.
task2.objectParameterDataArray = objArr;
Utilities.tileExceptionList.Clear();
}
object[] objArr = new object[2];
objArr[0] = (object)t;
objArr[1]= (object)task2.taskMetaData.path;
task2.objectParameterDataArray = objArr;
//task.taskMetaData = new TaskMetaData(task.taskMetaData.name, PathFindingCore.Utilities.calculatePathCost(task.objectParameterDataArray), task.taskMetaData.staminaPrerequisite, task.taskMetaData.toolPrerequisite);
}
ModCore.CoreMonitor.Log("DONE CALCULATING JUNK NOW RUNNING TASK");
//Some really cool delegate magic that sorts in place by the cost of the action!!!!
taskList.Sort(delegate (CustomTask t1, CustomTask t2)
{

View File

@ -98,6 +98,14 @@ namespace StarAI.ExecutionCore
//this.path = Utilities.calculatePath(source, false);
}
public void calculateTaskCost(List<TileNode> source, bool unknownPath)
{
var pair = TaskMetaDataHeuristics.calculateTaskCost(source, this.toolPrerequisite, unknownPath);
this.cost = pair.Key;
this.path = pair.Value;
//this.path = Utilities.calculatePath(source, false);
}
private void setUpToolPrerequisiteIfNull()
{
if (this.toolPrerequisite == null)

View File

@ -67,7 +67,7 @@ namespace StarAI.ExecutionCore
{
if(unknownPath) PathFindingLogic.delay = 18;
else PathFindingLogic.delay = 0;
List<TileNode> idealPath = StarAI.PathFindingCore.Utilities.pathStuff(v);
List<TileNode> idealPath = StarAI.PathFindingCore.Utilities.getIdealPath(v);
int costCalculation;
if (idealPath.Count == 0) costCalculation = Int32.MaxValue;
@ -80,5 +80,22 @@ namespace StarAI.ExecutionCore
return new KeyValuePair<int,List<TileNode>>(((int)pathCost + (int)toolCost),idealPath);
}
public static KeyValuePair<int, List<TileNode>> calculateTaskCost(List<TileNode> v, ToolPrerequisite t, bool unknownPath)
{
if (unknownPath) PathFindingLogic.delay = 18;
else PathFindingLogic.delay = 0;
List<TileNode> idealPath = StarAI.PathFindingCore.Utilities.getIdealPath(v);
int costCalculation;
if (idealPath.Count == 0) costCalculation = Int32.MaxValue;
else costCalculation = idealPath.Count;
if (costCalculation == Int32.MaxValue) return new KeyValuePair<int, List<TileNode>>(Int32.MaxValue, new List<TileNode>());
float pathCost = costCalculation * pathCostMultiplier;
float toolCost = calculateToolCostMultiplier(t);
return new KeyValuePair<int, List<TileNode>>(((int)pathCost + (int)toolCost), idealPath);
}
}
}

View File

@ -16,7 +16,7 @@ namespace StarAI.PathFindingCore.DebrisLogic
public static List<TileNode> sticksToChop = new List<TileNode>();
public static List<TileNode> stonesToBreak = new List<TileNode>();
public static List<TileNode> weedsToCut = new List<TileNode>();
public static List<TileNode> treesToChop = new List<TileNode>();
public static void getAllSticksToChop(GameLocation location)
{
@ -720,5 +720,291 @@ namespace StarAI.PathFindingCore.DebrisLogic
}
public static void getAllTreesToChopRadius(GameLocation location)
{
object[] arr = new object[1];
arr[0] = location;
getAllTreesToChopRadius(arr);
}
public static void getAllTreesToChopRadius(object obj)
{
int radius = 1;
int twingCount = 0;
object[] objArr = (object[])obj;
GameLocation location = (GameLocation)objArr[0];
// string targetName = "Weeds";
Type terrainType = typeof(StardewValley.TerrainFeatures.Tree);
if (StardustCore.Utilities.doesLocationContainTerrainFeature(location,terrainType))
{
KeyValuePair<Vector2, StardewValley.TerrainFeatures.TerrainFeature> pair = StardustCore.Utilities.checkRadiusForTerrainFeature(radius, terrainType);
Vector2 pos = pair.Key;
StardewValley.TerrainFeatures.TerrainFeature terrain = pair.Value;
while (terrain == null)
{
ModCore.CoreMonitor.Log(radius.ToString());
radius++;
pair= StardustCore.Utilities.checkRadiusForTerrainFeature(radius, terrainType);
pos = pair.Key;
terrain = pair.Value;
}
if (terrain.GetType() == terrainType)
{
ModCore.CoreMonitor.Log(terrain.GetType().ToString(), LogLevel.Warn);
ModCore.CoreMonitor.Log(pos.ToString(), LogLevel.Warn);
TileNode t = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.Brown));
t.fakePlacementAction(Game1.currentLocation, (int)pos.X, (int)pos.Y);
Utilities.tileExceptionList.Add(new TileExceptionMetaData(t, "ChopTree"));
treesToChop.Add(t);
twingCount++;
}
}
else
{
ModCore.CoreMonitor.Log("Trees not found at location.");
}
int ok = 0;
object[] objList = new object[2];
objList[0] = treesToChop;
// ExecutionCore.TaskList.taskList.Add(new Task(new Action<object>(waterSingleCrop), obj));
StardewValley.Tools.Axe w = new StardewValley.Tools.Axe();
ModCore.CoreMonitor.Log("Processing Trees:" + ok.ToString() + " / " + twingCount.ToString());
ok++;
int numberOfUses = 15;
ExecutionCore.CustomTask task = new ExecutionCore.CustomTask(chopSingleTree, objList, new ExecutionCore.TaskMetaData("ChopSingleTree", new StaminaPrerequisite(true, 2*numberOfUses), new ToolPrerequisite(true, w.GetType(), numberOfUses)));
objList[1] = task.taskMetaData.path;
task.objectParameterDataArray = objList;
if (task.taskMetaData.cost == Int32.MaxValue)
{
Utilities.clearExceptionListWithNames(true);
return;
}
ExecutionCore.TaskList.taskList.Add(task);
Utilities.clearExceptionListWithName("Child");
treesToChop.Clear();
}
public static void getAllTreesToChop(GameLocation location)
{
object[] arr = new object[1];
arr[0] = location;
getAllTreesToChop(arr);
}
public static void getAllTreesToChop(object obj)
{
int radius = 1;
int twingCount = 0;
object[] objArr = (object[])obj;
GameLocation location = (GameLocation)objArr[0];
// string targetName = "Weeds";
Type terrainType = typeof(StardewValley.TerrainFeatures.Tree);
if ((StardustCore.Utilities.doesLocationContainTerrainFeature(location, terrainType) == false))
{
ModCore.CoreMonitor.Log("Trees not found at location.");
return;
}
foreach (var v in location.terrainFeatures)
{
if (v.Value.GetType() != terrainType) continue;
//KeyValuePair<Vector2, StardewValley.TerrainFeatures.TerrainFeature> pair = StardustCore.Utilities.checkRadiusForTerrainFeature(radius, terrainType);
Vector2 pos = v.Key;
StardewValley.TerrainFeatures.TerrainFeature terrain = v.Value;
if (terrain.GetType() == terrainType)
{
ModCore.CoreMonitor.Log(terrain.GetType().ToString(), LogLevel.Warn);
ModCore.CoreMonitor.Log(pos.ToString(), LogLevel.Warn);
TileNode t = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.Brown));
t.fakePlacementAction(Game1.currentLocation, (int)pos.X, (int)pos.Y);
Utilities.tileExceptionList.Add(new TileExceptionMetaData(t, "ChopTree"));
treesToChop.Add(t);
twingCount++;
}
}
int ok = 0;
object[] objList = new object[3];
List<TileNode> tempTreesToChop = new List<TileNode>();
foreach(var v in treesToChop)
{
tempTreesToChop.Add(v);
}
objList[0] = tempTreesToChop;
// ExecutionCore.TaskList.taskList.Add(new Task(new Action<object>(waterSingleCrop), obj));
StardewValley.Tools.Axe w = new StardewValley.Tools.Axe();
ModCore.CoreMonitor.Log("Processing Trees:" + treesToChop.Count.ToString() + " / " + twingCount.ToString());
ok++;
int numberOfUses = 15;
ExecutionCore.CustomTask task = new ExecutionCore.CustomTask(chopSingleTree, objList, new ExecutionCore.TaskMetaData("ChopSingleTree", new StaminaPrerequisite(true, 2 * numberOfUses), new ToolPrerequisite(true, w.GetType(), numberOfUses)));
objList[1] = task.taskMetaData.path;
objList[2] = task.taskMetaData.path.ElementAt(0);
task.objectParameterDataArray = objList;
if (task.taskMetaData.cost == Int32.MaxValue)
{
Utilities.clearExceptionListWithNames(true);
return;
}
ExecutionCore.TaskList.taskList.Add(task);
Utilities.clearExceptionListWithName("Child");
treesToChop.Clear();
Utilities.tileExceptionList.Clear();
}
public static void chopSingleTree(TileNode v, List<TileNode> path)
{
object[] obj = new object[2];
obj[0] = v;
obj[1] = path;
chopSingleTree(obj);
}
public static void chopSingleTree(object obj)
{
object[] objArray = (object[])obj;
TileNode v = (TileNode)objArray[2];
List<TileNode> correctPath = (List<TileNode>)objArray[1];
foreach (var goodTile in correctPath)
{
StardustCore.ModCore.SerializationManager.trackedObjectList.Add(goodTile);
goodTile.placementAction(goodTile.thisLocation, (int)goodTile.tileLocation.X * Game1.tileSize, (int)goodTile.tileLocation.Y * Game1.tileSize);
}
PathFindingLogic.calculateMovement(correctPath);
Vector2 tileLocation = v.tileLocation;
ModCore.CoreMonitor.Log(tileLocation.ToString());
StardewValley.TerrainFeatures.TerrainFeature tree=new StardewValley.TerrainFeatures.Tree();
//if(v.thisLocation.isTerrainFeatureAt)
try
{
ModCore.CoreMonitor.Log("once");
ModCore.CoreMonitor.Log(v.thisLocation.terrainFeatures[new Vector2(tileLocation.X - 1, tileLocation.Y)].GetType().ToString());
if (v.thisLocation.terrainFeatures[new Vector2(tileLocation.X - 1, tileLocation.Y)] is StardewValley.TerrainFeatures.Tree)
{
ModCore.CoreMonitor.Log("onceGod");
tree = v.thisLocation.terrainFeatures[new Vector2(tileLocation.X - 1, tileLocation.Y)];
Game1.player.faceDirection(3);
}
}
catch(Exception err)
{
}
try
{
ModCore.CoreMonitor.Log("twice");
ModCore.CoreMonitor.Log(v.thisLocation.terrainFeatures[new Vector2(tileLocation.X +1, tileLocation.Y)].GetType().ToString());
if (v.thisLocation.terrainFeatures[new Vector2(tileLocation.X + 1, tileLocation.Y)] is StardewValley.TerrainFeatures.Tree)
{
ModCore.CoreMonitor.Log("twiceGood");
tree = v.thisLocation.terrainFeatures[new Vector2(tileLocation.X + 1, tileLocation.Y)];
Game1.player.faceDirection(1);
}
}
catch(Exception err)
{
}
try
{
ModCore.CoreMonitor.Log("thrice");
ModCore.CoreMonitor.Log(v.thisLocation.terrainFeatures[new Vector2(tileLocation.X, tileLocation.Y-1)].GetType().ToString());
if (v.thisLocation.terrainFeatures[new Vector2(tileLocation.X, tileLocation.Y - 1)] is StardewValley.TerrainFeatures.Tree)
{
ModCore.CoreMonitor.Log("thriceGood");
tree = v.thisLocation.terrainFeatures[new Vector2(tileLocation.X, tileLocation.Y - 1)];
Game1.player.faceDirection(0);
}
}
catch (Exception err) {
}
try
{
ModCore.CoreMonitor.Log("quad");
ModCore.CoreMonitor.Log(v.thisLocation.terrainFeatures[new Vector2(tileLocation.X, tileLocation.Y+1)].GetType().ToString());
if (v.thisLocation.terrainFeatures[new Vector2(tileLocation.X, tileLocation.Y + 1)] is StardewValley.TerrainFeatures.Tree)
{
ModCore.CoreMonitor.Log("quadGood");
tree = v.thisLocation.terrainFeatures[new Vector2(tileLocation.X, tileLocation.Y + 1)];
Game1.player.faceDirection(2);
}
}
catch(Exception err)
{
}
foreach (var item in Game1.player.items)
{
if (item is StardewValley.Tools.Axe)
{
Game1.player.CurrentToolIndex = Game1.player.getIndexOfInventoryItem(item);
}
}
while (v.thisLocation.terrainFeatures.ContainsValue(tree))
{
// if (!v.thisLocation.isTerrainFeatureAt((int)v.tileLocation.X, (int)v.tileLocation.Y)) break;
if (WindowsInput.InputSimulator.IsKeyDown(WindowsInput.VirtualKeyCode.VK_C) == false) WindowsInput.InputSimulator.SimulateKeyDown(WindowsInput.VirtualKeyCode.VK_C);
Vector2 center = new Vector2();
if (Game1.player.facingDirection == 2)
{
center = Utilities.parseCenterFromTile((int)v.tileLocation.X + 1, (int)v.tileLocation.Y);
continue;
}
if (Game1.player.facingDirection == 1)
{
center = Utilities.parseCenterFromTile((int)v.tileLocation.X - 1, (int)v.tileLocation.Y);
continue;
}
if (Game1.player.facingDirection == 0)
{
center = Utilities.parseCenterFromTile((int)v.tileLocation.X, (int)v.tileLocation.Y + 1);
continue;
}
if (Game1.player.facingDirection == 3)
{
center = Utilities.parseCenterFromTile((int)v.tileLocation.X, (int)v.tileLocation.Y - 1);
continue;
}
Game1.player.position = center;
//Game1.setMousePosition((int)v.tileLocation.X*Game1.tileSize/2,(int)v.tileLocation.Y*Game1.tileSize/2);
ModCore.CoreMonitor.Log("DOESNT Axe LIKE YOU THINK IT SHOULD");
ModCore.CoreMonitor.Log("player pos: " + Game1.player.position.ToString(), LogLevel.Warn);
ModCore.CoreMonitor.Log("TilePos: " + v.position.ToString(), LogLevel.Error);
}
Utilities.cleanExceptionList(v);
StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(v);
foreach (var goodTile in correctPath)
{
StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(goodTile);
goodTile.performRemoveAction(goodTile.tileLocation, goodTile.thisLocation);
}
WindowsInput.InputSimulator.SimulateKeyUp(WindowsInput.VirtualKeyCode.VK_C);
}
}
}

View File

@ -21,7 +21,7 @@ namespace StarAI.PathFindingCore
public static int delay;
public static int index = 0;
// public static int index = 0;
public static void pathFindToAllGoals()
@ -71,6 +71,7 @@ namespace StarAI.PathFindingCore
public static void pathFindToSingleGoal(object data)
{
int index = 0;
List<TileNode> path = new List<TileNode>();
//path.Clear();
ModCore.CoreMonitor.Log("LET'S GO!!!!", LogLevel.Error);
@ -299,6 +300,7 @@ namespace StarAI.PathFindingCore
public static List<TileNode> pathFindToSingleGoalReturnPath(object data)
{
int index = 0;
List<TileNode> path = new List<TileNode>();
//path.Clear();
ModCore.CoreMonitor.Log("LET'S GO!!!!", LogLevel.Error);
@ -324,6 +326,8 @@ namespace StarAI.PathFindingCore
queue.Add(currentNode);
index++;
bool goalFound = false;
Utilities.clearExceptionListWithName("Child");
Utilities.clearExceptionListWithName("Navigation");
while (currentNode.tileLocation != Goal.tileLocation && queue.Count != 0)
{
// ModCore.CoreMonitor.Log("LET'S GO PATH!!!!", LogLevel.Error);
@ -557,9 +561,10 @@ namespace StarAI.PathFindingCore
}
public static List<TileNode> pathFindToSingleGoalReturnPathList(object data)
{
int index = 0;
List<TileNode> path = new List<TileNode>();
//path.Clear();
ModCore.CoreMonitor.Log("LET'S GO!!!!", LogLevel.Error);
ModCore.CoreMonitor.Log("LET'S GO 2222!!!!", LogLevel.Error);
object[] obj = (object[])data;
TileNode Source = (TileNode)obj[0];
@ -579,13 +584,14 @@ namespace StarAI.PathFindingCore
bool placement = (bool)obj[3];
bool checkForUtility = (bool)obj[4];
queue.Add(currentNode);
index++;
// index++;
bool goalFound = false;
while (doesNodeEqualGoal(currentNode,Goals).Key==false && queue.Count != 0)
{
// ModCore.CoreMonitor.Log("LET'S GO PATH!!!!", LogLevel.Error);
//ModCore.CoreMonitor.Log("PATH FROM SOURCE: " + currentNode.tileLocation, LogLevel.Error);
//ModCore.CoreMonitor.Log("PATH To GOAL: " + Goal.tileLocation, LogLevel.Error);
// ModCore.CoreMonitor.Log("LET'S GO PATH!!!!", LogLevel.Error);
// ModCore.CoreMonitor.Log("PATH FROM SOURCE: " + currentNode.tileLocation, LogLevel.Error);
// ModCore.CoreMonitor.Log("THIS IS MY MISTAKE!!!!!!! " + Goals.Count, LogLevel.Error);
//Console.WriteLine("OK WTF IS GOING ON????");
//Add children to current node
int xMin = -1;
@ -609,7 +615,7 @@ namespace StarAI.PathFindingCore
//ModCore.CoreMonitor.Log("HERE1", LogLevel.Error);
TileNode.setSingleTileAsChild(currentNode, (int)currentNode.tileLocation.X + x, (int)currentNode.tileLocation.Y + y, checkForUtility, placement);
//ModCore.CoreMonitor.Log("OR NO?", LogLevel.Error);
// ModCore.CoreMonitor.Log("OR NO?", LogLevel.Error);
Vector2 check = new Vector2((int)currentNode.tileLocation.X + x, (int)currentNode.tileLocation.Y + y);
if (doesNodeEqualGoal(check,Goals).Key==true)
{
@ -676,6 +682,7 @@ namespace StarAI.PathFindingCore
}
catch (Exception err)
{
ModCore.CoreMonitor.Log("FUCK", LogLevel.Error);
break;
}
currentNode.drawColor = StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.Blue); //Working

View File

@ -296,14 +296,24 @@ namespace StarAI.PathFindingCore
return correctPath.Count;
}
public static List<TileNode> pathStuff(TileNode t)
/// <summary>
/// This is used to pathfind to a single explicit target.
/// </summary>
/// <param name="t"></param>
/// <returns></returns>
public static List<TileNode> getIdealPath(TileNode t)
{
object[] arr = new object[1];
arr[0] = t;
return pathStuff(arr);
return getIdealPath(arr);
}
public static List<TileNode> pathStuff(object obj)
/// <summary>
/// This is used to pathfind to a single explicit target.
/// </summary>
/// <param name="t"></param>
/// <returns></returns>
public static List<TileNode> getIdealPath(object obj)
{
object[] objArr = (object[])obj;
TileNode v = (TileNode)objArr[0];
@ -333,7 +343,7 @@ namespace StarAI.PathFindingCore
Vector2 pos = new Vector2(v.tileLocation.X + x, v.tileLocation.Y + y);
//ModCore.CoreMonitor.Log("AHHHHHHH POSITION: " + pos.ToString(), LogLevel.Alert);
bool f = PathFindingCore.TileNode.checkIfICanPlaceHere(v, pos * Game1.tileSize, v.thisLocation, true,utility);
bool f = PathFindingCore.TileNode.checkIfICanPlaceHere(v, pos * Game1.tileSize, v.thisLocation, true, utility);
// ModCore.CoreMonitor.Log("OK THIS IS THE RESULT F: " + f, LogLevel.Alert);
if (f == true)
{
@ -341,52 +351,52 @@ namespace StarAI.PathFindingCore
TileNode t = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.RosyBrown));
if (placement) t.placementAction(Game1.currentLocation, (int)pos.X * Game1.tileSize, (int)pos.Y * Game1.tileSize);
else t.fakePlacementAction(Game1.currentLocation, (int)pos.X, (int)pos.Y);
//StardustCore.Utilities.masterAdditionList.Add(new StardustCore.DataNodes.PlacementNode( t, Game1.currentLocation, (int)pos.X * Game1.tileSize, (int)pos.Y * Game1.tileSize));
//StardustCore.Utilities.masterAdditionList.Add(new StardustCore.DataNodes.PlacementNode( t, Game1.currentLocation, (int)pos.X * Game1.tileSize, (int)pos.Y * Game1.tileSize));
miniGoals.Add(t);
Utilities.tileExceptionList.Add(new TileExceptionMetaData(t, "Navigation"));
}
}
}
List<TileNode> removalList = new List<TileNode>();
Utilities.clearExceptionListWithName("Child");
Utilities.clearExceptionListWithName("Navigation");
TileNode tempSource = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.RosyBrown));
if (placement) tempSource.placementAction(Game1.player.currentLocation, Game1.player.getTileX() * Game1.tileSize, Game1.player.getTileY() * Game1.tileSize);
else tempSource.fakePlacementAction(Game1.player.currentLocation, Game1.player.getTileX(), Game1.player.getTileY());
Utilities.tileExceptionList.Add(new TileExceptionMetaData(tempSource, "Navigation"));
//StaardustCore.Utilities.masterAdditionList.Add(new StardustCore.DataNodes.PlacementNode(tempSource, Game1.currentLocation, Game1.player.getTileX() * Game1.tileSize, Game1.player.getTileY() * Game1.tileSize));
Utilities.clearExceptionListWithName("Child");
Utilities.clearExceptionListWithName("Navigation");
TileNode tempSource = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.RosyBrown));
if (placement) tempSource.placementAction(Game1.player.currentLocation, Game1.player.getTileX() * Game1.tileSize, Game1.player.getTileY() * Game1.tileSize);
else tempSource.fakePlacementAction(Game1.player.currentLocation, Game1.player.getTileX(), Game1.player.getTileY());
Utilities.tileExceptionList.Add(new TileExceptionMetaData(tempSource, "Navigation"));
//StaardustCore.Utilities.masterAdditionList.Add(new StardustCore.DataNodes.PlacementNode(tempSource, Game1.currentLocation, Game1.player.getTileX() * Game1.tileSize, Game1.player.getTileY() * Game1.tileSize));
//have this take in a list of goals and see which goal it reaches first
List<TileNode> path = PathFindingCore.PathFindingLogic.pathFindToSingleGoalReturnPath(tempSource, miniGoals, new List<TileNode>(), placement, utility);
if (path.Count == 0)
//have this take in a list of goals and see which goal it reaches first
List<TileNode> path = PathFindingCore.PathFindingLogic.pathFindToSingleGoalReturnPath(tempSource, miniGoals, new List<TileNode>(), placement, utility);
if (path.Count == 0)
{
ModCore.CoreMonitor.Log("NOPE, no path I guess.", LogLevel.Warn);
}
else
{
ModCore.CoreMonitor.Log("There is a path", LogLevel.Alert);
ModCore.CoreMonitor.Log("COST OF THE PATH IS: " + path.Count.ToString(), LogLevel.Alert);
}
if (path.Count != 0)
{
//ModCore.CoreMonitor.Log("PATH WAS NOT NULL", LogLevel.Warn);
paths.Add(path);
foreach (var someTile in path)
{
ModCore.CoreMonitor.Log("NOPE, no path I guess.", LogLevel.Warn);
}
else
{
ModCore.CoreMonitor.Log("There is a path", LogLevel.Alert);
ModCore.CoreMonitor.Log("COST OF THE PATH IS: " + path.Count.ToString(), LogLevel.Alert);
}
if (path.Count != 0)
{
//ModCore.CoreMonitor.Log("PATH WAS NOT NULL", LogLevel.Warn);
paths.Add(path);
foreach (var someTile in path)
{
removalList.Add(someTile);
StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(someTile);
if (placement) someTile.thisLocation.objects.Remove(someTile.tileLocation);
removalList.Add(someTile);
StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(someTile);
if (placement) someTile.thisLocation.objects.Remove(someTile.tileLocation);
//someTile.performRemoveAction(someTile.tileLocation, someTile.thisLocation);
//StardustCore.Utilities.masterRemovalList.Add(someTile);
//ModCore.CoreMonitor.Log("CAUGHT MY CULPERATE", LogLevel.Warn);
}
//someTile.performRemoveAction(someTile.tileLocation, someTile.thisLocation);
//StardustCore.Utilities.masterRemovalList.Add(someTile);
//ModCore.CoreMonitor.Log("CAUGHT MY CULPERATE", LogLevel.Warn);
}
}
/*
foreach (var nav in miniGoals) //change this??????
@ -434,7 +444,7 @@ namespace StarAI.PathFindingCore
foreach (var q in removalList)
{
StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(q);
if(placement) q.thisLocation.objects.Remove(q.tileLocation);
if (placement) q.thisLocation.objects.Remove(q.tileLocation);
}
removalList.Clear();
int pathCost = 999999999;
@ -455,6 +465,182 @@ namespace StarAI.PathFindingCore
}
/// <summary>
/// This is used to pathfind to any target that statisfies conditions. The first one hit becomes the new goal.
/// </summary>
/// <param name="t"></param>
/// <returns></returns>
public static List<TileNode> getIdealPath(List<TileNode> t)
{
object[] arr = new object[1];
arr[0] = t;
return getAnyIdealPath(arr);
}
/// <summary>
/// This is used to pathfind to any target that statisfies conditions. The first one hit becomes the new goal.
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public static List<TileNode> getAnyIdealPath(object obj)
{
object[] objArr = (object[])obj;
List<TileNode> vList = (List<TileNode>)objArr[0];
bool placement = false;
bool utility = true;
int xMin = -1;
int yMin = -1;
int xMax = 1;
int yMax = 1;
List<TileNode> miniGoals = new List<TileNode>();
List<List<TileNode>> paths = new List<List<TileNode>>();
//try to set children to tiles where children haven't been before
foreach (var v in vList)
{
for (int x = xMin; x <= xMax; x++)
{
for (int y = yMin; y <= yMax; y++)
{
if (x == 0 && y == 0) continue;
//Include these 4 checks for just left right up down movement. Remove them to enable 8 direction path finding
if (x == -1 && y == -1) continue; //upper left
if (x == -1 && y == 1) continue; //bottom left
if (x == 1 && y == -1) continue; //upper right
if (x == 1 && y == 1) continue; //bottom right
Vector2 pos = new Vector2(v.tileLocation.X + x, v.tileLocation.Y + y);
//ModCore.CoreMonitor.Log("AHHHHHHH POSITION: " + pos.ToString(), LogLevel.Alert);
bool f = PathFindingCore.TileNode.checkIfICanPlaceHere(v, pos * Game1.tileSize, v.thisLocation, true, utility);
// ModCore.CoreMonitor.Log("OK THIS IS THE RESULT F: " + f, LogLevel.Alert);
if (f == true)
{
TileNode t = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.RosyBrown));
if (placement) t.placementAction(Game1.currentLocation, (int)pos.X * Game1.tileSize, (int)pos.Y * Game1.tileSize);
else t.fakePlacementAction(Game1.currentLocation, (int)pos.X, (int)pos.Y);
//StardustCore.Utilities.masterAdditionList.Add(new StardustCore.DataNodes.PlacementNode( t, Game1.currentLocation, (int)pos.X * Game1.tileSize, (int)pos.Y * Game1.tileSize));
miniGoals.Add(t);
Utilities.tileExceptionList.Add(new TileExceptionMetaData(t, "Navigation"));
}
}
}
}
List<TileNode> removalList = new List<TileNode>();
Utilities.clearExceptionListWithName("Child");
Utilities.clearExceptionListWithName("Navigation");
TileNode tempSource = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.RosyBrown));
if (placement) tempSource.placementAction(Game1.player.currentLocation, Game1.player.getTileX() * Game1.tileSize, Game1.player.getTileY() * Game1.tileSize);
else tempSource.fakePlacementAction(Game1.player.currentLocation, Game1.player.getTileX(), Game1.player.getTileY());
Utilities.tileExceptionList.Add(new TileExceptionMetaData(tempSource, "Navigation"));
//StaardustCore.Utilities.masterAdditionList.Add(new StardustCore.DataNodes.PlacementNode(tempSource, Game1.currentLocation, Game1.player.getTileX() * Game1.tileSize, Game1.player.getTileY() * Game1.tileSize));
//have this take in a list of goals and see which goal it reaches first
List<TileNode> path = PathFindingCore.PathFindingLogic.pathFindToSingleGoalReturnPath(tempSource, miniGoals, new List<TileNode>(), placement, utility);
Utilities.clearExceptionListWithName("Child");
Utilities.clearExceptionListWithName("Navigation");
if (path.Count == 0)
{
ModCore.CoreMonitor.Log("NOPE, no path I guess.", LogLevel.Warn);
}
else
{
ModCore.CoreMonitor.Log("There is a path", LogLevel.Alert);
ModCore.CoreMonitor.Log("COST OF THE PATH IS: " + path.Count.ToString(), LogLevel.Alert);
}
if (path.Count != 0)
{
//ModCore.CoreMonitor.Log("PATH WAS NOT NULL", LogLevel.Warn);
paths.Add(path);
foreach (var someTile in path)
{
removalList.Add(someTile);
StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(someTile);
if (placement) someTile.thisLocation.objects.Remove(someTile.tileLocation);
//someTile.performRemoveAction(someTile.tileLocation, someTile.thisLocation);
//StardustCore.Utilities.masterRemovalList.Add(someTile);
//ModCore.CoreMonitor.Log("CAUGHT MY CULPERATE", LogLevel.Warn);
}
}
/*
foreach (var nav in miniGoals) //change this??????
{
Utilities.clearExceptionListWithName("Child");
Utilities.clearExceptionListWithName("Navigation");
TileNode tempSource = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.RosyBrown));
if(placement) tempSource.placementAction(Game1.player.currentLocation, Game1.player.getTileX() * Game1.tileSize, Game1.player.getTileY() * Game1.tileSize);
else tempSource.fakePlacementAction(Game1.player.currentLocation, Game1.player.getTileX(), Game1.player.getTileY());
Utilities.tileExceptionList.Add(new TileExceptionMetaData(tempSource, "Navigation"));
//StaardustCore.Utilities.masterAdditionList.Add(new StardustCore.DataNodes.PlacementNode(tempSource, Game1.currentLocation, Game1.player.getTileX() * Game1.tileSize, Game1.player.getTileY() * Game1.tileSize));
//have this take in a list of goals and see which goal it reaches first
List<TileNode> path = PathFindingCore.PathFindingLogic.pathFindToSingleGoalReturnPath(tempSource, nav, new List<TileNode>(), placement, utility);
if (path.Count == 0)
{
ModCore.CoreMonitor.Log("NOPE, no path I guess.",LogLevel.Warn);
}
else
{
ModCore.CoreMonitor.Log("There is a path", LogLevel.Alert);
ModCore.CoreMonitor.Log("COST OF THE PATH IS: "+path.Count.ToString(), LogLevel.Alert);
}
if (path.Count != 0)
{
//ModCore.CoreMonitor.Log("PATH WAS NOT NULL", LogLevel.Warn);
paths.Add(path);
foreach (var someTile in path)
{
if (someTile == nav) removalList.Add(someTile);
StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(someTile);
if(placement) someTile.thisLocation.objects.Remove(someTile.tileLocation);
//someTile.performRemoveAction(someTile.tileLocation, someTile.thisLocation);
//StardustCore.Utilities.masterRemovalList.Add(someTile);
//ModCore.CoreMonitor.Log("CAUGHT MY CULPERATE", LogLevel.Warn);
}
}
}
*/
Console.WriteLine("GOALS COUNT:" + miniGoals.Count);
foreach (var q in removalList)
{
StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(q);
if (placement) q.thisLocation.objects.Remove(q.tileLocation);
}
removalList.Clear();
int pathCost = 999999999;
List<TileNode> correctPath = new List<TileNode>();
foreach (var potentialPath in paths)
{
if (potentialPath.Count == 0) continue;
if (potentialPath.Count < pathCost)
{
pathCost = potentialPath.Count;
correctPath = potentialPath;
}
}
return correctPath;
}
}
}