Fixed robot save mechanic to include nodes and their states.
This commit is contained in:
@@ -7,6 +7,7 @@ public class ExploreNode : ProgramNode
|
||||
public Vector3 startPosition;
|
||||
public Vector3I targetPosition;
|
||||
public List<Vector3> pathPoints;
|
||||
public bool hasTargetPosition;
|
||||
|
||||
public ExploreNode()
|
||||
{
|
||||
@@ -16,7 +17,7 @@ public class ExploreNode : ProgramNode
|
||||
|
||||
public override NodeResult Execute(Robot robot, double delta)
|
||||
{
|
||||
if (pathPoints == null && !TrySelectTarget())
|
||||
if (pathPoints == null && !hasTargetPosition && !TrySelectTarget())
|
||||
{
|
||||
lastExecutionMessage = "No tiles left to explore";
|
||||
return NodeResult.SUCCESS;
|
||||
@@ -52,6 +53,7 @@ public class ExploreNode : ProgramNode
|
||||
);
|
||||
if (!GameData.map[targetPosition.Y].tiles[targetPosition.X, targetPosition.Z].wasVisited)
|
||||
{
|
||||
hasTargetPosition = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -94,6 +96,7 @@ public class ExploreNode : ProgramNode
|
||||
|
||||
lastExecutionMessage = "Current exploration finished";
|
||||
pathPoints = null;
|
||||
hasTargetPosition = false;
|
||||
return NodeResult.RUNNING;
|
||||
}
|
||||
|
||||
@@ -119,7 +122,8 @@ public class ExploreNode : ProgramNode
|
||||
{
|
||||
return new ExploreNode
|
||||
{
|
||||
targetPosition = targetPosition
|
||||
targetPosition = targetPosition,
|
||||
hasTargetPosition = hasTargetPosition
|
||||
};
|
||||
}
|
||||
|
||||
@@ -127,4 +131,27 @@ public class ExploreNode : ProgramNode
|
||||
{
|
||||
return $"Name: {DisplayText}";
|
||||
}
|
||||
|
||||
public override NodeSaveData CreateSaveData()
|
||||
{
|
||||
NodeSaveData saveData = base.CreateSaveData();
|
||||
saveData.TargetX = targetPosition.X;
|
||||
saveData.TargetY = targetPosition.Y;
|
||||
saveData.TargetZ = targetPosition.Z;
|
||||
saveData.HasTargetPosition = hasTargetPosition || pathPoints != null;
|
||||
return saveData;
|
||||
}
|
||||
|
||||
public override void Load(NodeSaveData saveData)
|
||||
{
|
||||
base.Load(saveData);
|
||||
hasTargetPosition = saveData.HasTargetPosition;
|
||||
if (!hasTargetPosition) return;
|
||||
|
||||
targetPosition = new Vector3I(
|
||||
saveData.TargetX,
|
||||
saveData.TargetY,
|
||||
saveData.TargetZ
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user