From: brady Date: Tue, 27 Apr 2010 19:17:22 +0000 (+0000) Subject: Changed where AI is stored, adjusted to work with Multiplayer X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=7431a91b0db64e69e994a2bfced6516b2891086e;p=chaz%2Fcarfire Changed where AI is stored, adjusted to work with Multiplayer git-svn-id: https://bd85.net/svn/cs3505_group@165 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- diff --git a/CarFire/CarFire/CarFire/Game.cs b/CarFire/CarFire/CarFire/Game.cs index 9a44ff3..2d4c95c 100644 --- a/CarFire/CarFire/CarFire/Game.cs +++ b/CarFire/CarFire/CarFire/Game.cs @@ -445,6 +445,8 @@ namespace CarFire */ } + public AI AIData { get { return mAIData; } } + public long CurrentFrameNumber { get { return State.FrameNumber; } @@ -492,6 +494,7 @@ namespace CarFire { State.AdvanceFrame(mInputs, elapsedTime.Milliseconds); // Apply the inputs, advance game state. State.mDisplay.Update(elapsedTime, mThisPlayerID); + /* State.Entities.ForEach(delegate(IEntity e) { IMonster m = e as IMonster; @@ -508,7 +511,8 @@ namespace CarFire } e.Update(elapsedTime); }); - //State.Entities.ForEach(delegate(IEntity e) { e.Update(elapsedTime); }); + */ + State.Entities.ForEach(delegate(IEntity e) { e.Update(elapsedTime); }); mInputs = new NextInputs(State.NumberOfPlayers); // Start with inputs cleared on the next frame. //mDisplay.Update(elapsedTime); return State.FrameNumber; diff --git a/CarFire/CarFire/CarFire/SaberMonster2.cs b/CarFire/CarFire/CarFire/SaberMonster2.cs index f522ab4..33f94d7 100644 --- a/CarFire/CarFire/CarFire/SaberMonster2.cs +++ b/CarFire/CarFire/CarFire/SaberMonster2.cs @@ -42,7 +42,7 @@ namespace CarFire { mId = identifier; mMotion = new MovementManager(position); - + // We need to keep the game reference in order to get the grid when we // need to find paths. mGame = game; @@ -213,6 +213,29 @@ namespace CarFire /// public void Update(TimeSpan timeSpan) { + int closestChar = 0; + int closestCharDist = 1000; + for (int c = 0; c < mGame.State.mCharacters.Length; c++) + { + if (mGame.State.mCharacters[c] != null && mGame.AIData.spaceVisible(Coordinates, mGame.State.mCharacters[c].Coordinates)) + { + if (PathFinder.GetManhattanDistance(Coordinates, mGame.State.mCharacters[c].Coordinates) < closestCharDist) + { + closestCharDist = PathFinder.GetManhattanDistance(Coordinates, mGame.State.mCharacters[c].Coordinates); + closestChar = c; + } + } + } + + if (mGame.State.mCharacters[closestChar] != null && mGame.AIData.spaceVisible(Coordinates, mGame.State.mCharacters[closestChar].Coordinates)) + { + Chasing(mGame.State.mCharacters[0].Coordinates); + } + else + { + DefaultAction(); + } + switch (mState) { case AiState.Pacing: @@ -286,7 +309,7 @@ namespace CarFire char mId; MovementManager mMotion; - + AI mAI; PathFinder pathFinder; List mIdlePath = new List(); // List of waypoints that we got from the map. int mIdlePathIndex; // Index to the waypoint we're heading for.