X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fcarfire;a=blobdiff_plain;f=CarFire%2FCarFire%2FCarFire%2FSaberMonster.cs;h=8d66efd1a64b12affd3fa48d2e5907a75b332b97;hp=69b42ca1a44f11d578af78fb4a92fcb5b52b5a9d;hb=8b6a959f18e80bc6fca70218e1749718ec2ac0b4;hpb=122c062297acac44673e947b666c1d72cd23fb1b
diff --git a/CarFire/CarFire/CarFire/SaberMonster.cs b/CarFire/CarFire/CarFire/SaberMonster.cs
index 69b42ca..8d66efd 100644
--- a/CarFire/CarFire/CarFire/SaberMonster.cs
+++ b/CarFire/CarFire/CarFire/SaberMonster.cs
@@ -8,6 +8,7 @@ using Microsoft.Xna.Framework.Graphics;
namespace CarFire
{
+ /*
///
/// A type for the states of an artificually intelligent entity.
///
@@ -20,7 +21,7 @@ namespace CarFire
Fighting,
Retreating
}
-
+ */
///
/// An example monster. This can serve as a starting place for
@@ -42,7 +43,7 @@ namespace CarFire
{
mId = identifier;
mMotion = new MovementManager(position);
- mRetryInterval = 20 + (position.X * 25789 + position.Y * 259) % 30;
+ mRetryInterval = 2 + (position.X * 25789 + position.Y * 259) % 30;
// We need to keep the game reference in order to get the grid when we
// need to find paths.
@@ -68,11 +69,19 @@ namespace CarFire
if (point != null) mWaypoints.Add(point.Value);
}
}
+ mPath = new List();
// Start doing something...
StartPacing();
}
+ public void DefaultAction()
+ {
+ }
+ public void Chasing(Point Chase)
+ {
+
+ }
///
/// Call this to switch the monster AI state to pacing and set up
@@ -105,38 +114,49 @@ namespace CarFire
Direction GetDirectionToNextCell()
{
- if (mPathIndex >= mPath.Count)
+ if (mPath != null)
{
- // We're done with the current path, so find the path to
- // the next waypoint... forever.
- mWaypointIndex++;
- ChartPath();
- }
+ if (mPathIndex >= mPath.Count)
+ {
+ // We're done with the current path, so find the path to
+ // the next waypoint... forever.
+ mWaypointIndex++;
+ ChartPath();
+ }
- // We need to make sure our direction is set to the next cell
- // we want to be. If our current coordinates match that, we need
- // to change our direction to get to the next cell.
- if (mPathIndex < mPath.Count && mPath[mPathIndex] == mMotion.Coordinates)
- {
- mPathIndex++;
- mPathDirection = MovementManager.GetDirection(mMotion.Coordinates, mPath[mPathIndex % mPath.Count]);
- }
+ // We need to make sure our direction is set to the next cell
+ // we want to be. If our current coordinates match that, we need
+ // to change our direction to get to the next cell.
+ else if (mPath[mPathIndex] == mMotion.Coordinates)
+ {
+ mPathIndex++;
+ mPathDirection = MovementManager.GetDirection(mMotion.Coordinates, mPath[mPathIndex % mPath.Count]);
+ }
- return mPathDirection;
+ return mPathDirection;
+ }
+ else return Direction.None;
}
void ChartPath()
{
- mPath = new List(32);
+ if (mPathSearch == null)
+ {
+ Point waypoint = mWaypoints[mWaypointIndex % mWaypoints.Count];
+ PathFinder pathFinder = new PathFinder(mGame.Grid);
+ Point? nearby = pathFinder.GetNearbyOpenCell(waypoint);
+ if (nearby != null) mPathSearch = pathFinder.GetPathAsync(mMotion.Coordinates, nearby.Value);
- Point waypoint = mWaypoints[mWaypointIndex % mWaypoints.Count];
- PathFinder pathFinder = new PathFinder(mGame.Grid);
- List path = pathFinder.GetPath(mMotion.Coordinates, waypoint);
- if (path != null) mPath.AddRange(path);
+ mPathIndex = 0;
+ mPath = null;
+ }
+ else if (mPathSearch.IsCompleted)
+ {
+ mPath = (List)mPathSearch.Path;
+ mPathSearch = null;
- mPathIndex = 0;
- if (mPathIndex < mPath.Count) mPathDirection = MovementManager.GetDirection(mMotion.Coordinates, mPath[mPathIndex]);
- else mPathDirection = Direction.None;
+ if (mPath != null) mPathDirection = MovementManager.GetDirection(mMotion.Coordinates, mPath[0]);
+ }
}
@@ -186,22 +206,8 @@ namespace CarFire
}
else
{
- if (mGame.CurrentFrameNumber % mRetryInterval == 0)
- {
- // Something is in our way, so let's chart a new course.
- ChartPath();
-
- direction = GetDirectionToNextCell();
- /*if (direction == Direction.None)
- {
- // If we still can't chart a course, just stand there
- // and try to chart again later.
- mState = AiState.Standing;
- }*/
-
- mMotion.Update(timeSpan, direction);
- }
- else mMotion.Update(timeSpan);
+ if (mGame.CurrentFrameNumber % mRetryInterval == 0) ChartPath();
+ mMotion.Update(timeSpan);
}
break;
@@ -275,15 +281,16 @@ namespace CarFire
List mWaypoints = new List(); // List of waypoints that we got from the map.
int mWaypointIndex; // Index to the waypoint we're heading for.
- List mPath; // List of cells in the path between the position between where
- // we started and the waypoint we're heading for.
- int mPathIndex; // Index to the cell we're heading for.
- Direction mPathDirection; // The direction between our current position and the place we're going.
+ List mPath; // List of cells in the path between the position between where
+ // we started and the waypoint we're heading for.
+ int mPathIndex; // Index to the cell we're heading for.
+ Direction mPathDirection; // The direction between our current position and the place we're going.
int mRetryInterval;
+ PathFinder.AsyncTask mPathSearch; // If a path search is in progress, this is the task object.
- AiState mState; // What is the monster doing?
+ AiState mState; // What is the monster doing?
- Texture2D mTexture; // Obvious.
+ Texture2D mTexture; // Obvious.
#endregion
}