Changed where AI is stored, adjusted to work with Multiplayer
authorbrady <brady@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Tue, 27 Apr 2010 19:17:22 +0000 (19:17 +0000)
committerbrady <brady@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Tue, 27 Apr 2010 19:17:22 +0000 (19:17 +0000)
git-svn-id: https://bd85.net/svn/cs3505_group@165 92bb83a3-7c8f-8a45-bc97-515c4e399668

CarFire/CarFire/CarFire/Game.cs
CarFire/CarFire/CarFire/SaberMonster2.cs

index 9a44ff3..2d4c95c 100644 (file)
@@ -445,6 +445,8 @@ namespace CarFire
             */\r
         }\r
 \r
+        public AI AIData { get { return mAIData; } }\r
+\r
         public long CurrentFrameNumber\r
         {\r
             get { return State.FrameNumber; }\r
@@ -492,6 +494,7 @@ namespace CarFire
         {\r
             State.AdvanceFrame(mInputs, elapsedTime.Milliseconds);  // Apply the inputs, advance game state.\r
             State.mDisplay.Update(elapsedTime, mThisPlayerID);\r
+            /*\r
             State.Entities.ForEach(delegate(IEntity e) \r
             {\r
                 IMonster m = e as IMonster;\r
@@ -508,7 +511,8 @@ namespace CarFire
                 }\r
                 e.Update(elapsedTime); \r
             });\r
-            //State.Entities.ForEach(delegate(IEntity e) { e.Update(elapsedTime); });\r
+             */\r
+            State.Entities.ForEach(delegate(IEntity e) { e.Update(elapsedTime); });\r
             mInputs = new NextInputs(State.NumberOfPlayers);  // Start with inputs cleared on the next frame.\r
             //mDisplay.Update(elapsedTime);\r
             return State.FrameNumber;\r
index f522ab4..33f94d7 100644 (file)
@@ -42,7 +42,7 @@ namespace CarFire
         {\r
             mId = identifier;\r
             mMotion = new MovementManager(position);\r
-\r
+            \r
             // We need to keep the game reference in order to get the grid when we\r
             // need to find paths.\r
             mGame = game;\r
@@ -213,6 +213,29 @@ namespace CarFire
         /// <param name="timeSpan"></param>\r
         public void Update(TimeSpan timeSpan)\r
         {\r
+            int closestChar = 0;\r
+            int closestCharDist = 1000;\r
+            for (int c = 0; c < mGame.State.mCharacters.Length; c++)\r
+            {\r
+                if (mGame.State.mCharacters[c] != null && mGame.AIData.spaceVisible(Coordinates, mGame.State.mCharacters[c].Coordinates))\r
+                {\r
+                    if (PathFinder.GetManhattanDistance(Coordinates, mGame.State.mCharacters[c].Coordinates) < closestCharDist)\r
+                    {\r
+                        closestCharDist = PathFinder.GetManhattanDistance(Coordinates, mGame.State.mCharacters[c].Coordinates);\r
+                        closestChar = c;\r
+                    }\r
+                }\r
+            }\r
+\r
+            if (mGame.State.mCharacters[closestChar] != null && mGame.AIData.spaceVisible(Coordinates, mGame.State.mCharacters[closestChar].Coordinates))\r
+            {\r
+                Chasing(mGame.State.mCharacters[0].Coordinates);\r
+            }\r
+            else\r
+            {\r
+                DefaultAction();\r
+            }\r
+        \r
             switch (mState)\r
             {\r
                 case AiState.Pacing:\r
@@ -286,7 +309,7 @@ namespace CarFire
 \r
         char mId;\r
         MovementManager mMotion;\r
-\r
+        AI mAI;\r
         PathFinder pathFinder;\r
         List<Point> mIdlePath = new List<Point>();      // List of waypoints that we got from the map.\r
         int mIdlePathIndex;                             // Index to the waypoint we're heading for.\r
This page took 0.027091 seconds and 4 git commands to generate.