Changeset 4635 for 2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Ai
- Timestamp:
- 2013-07-24 15:02:03 (8 years ago)
- Location:
- 2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Ai
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Ai/AStar.cs
r4593 r4635 57 57 public void InitializePathFinder(int xStart, int zStart, int xEnd, int zEnd, bool ignoreSolidnessForEnd) 58 58 { 59 tiles = level.BuildSolidnessTable(mob, ignoreSolidnessForEnd , xEnd, zEnd);59 tiles = level.BuildSolidnessTable(mob, ignoreSolidnessForEnd); 60 60 nodeMap = new Node[level.Width * level.Height]; 61 61 open.Clear(); … … 100 100 canPathFind = false; 101 101 } 102 } 103 104 public void ApplySolidnessToPos(List<int> posList) 105 { 106 foreach (int i in posList) 107 tiles[i] = false; 102 108 } 103 109 -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Ai/Orders/OrderMove.cs
r4592 r4635 17 17 private int moveFails = 0; 18 18 private float lastDist = 0.0F; 19 private bool shouldFindPath = false; 20 private bool createNewPathFinder; 19 21 20 public OrderMove(float x, float z, float stopDistance = 2.0F, bool excludeEndSolidness = false )22 public OrderMove(float x, float z, float stopDistance = 2.0F, bool excludeEndSolidness = false, bool createNewPathFinder = true) 21 23 { 22 24 this.stopDistance = stopDistance; 23 25 this.excludeEndSolidness = excludeEndSolidness; 26 this.createNewPathFinder = createNewPathFinder; 24 27 this.x = x; 25 28 this.z = z; … … 29 32 { 30 33 base.Initialize(mob); 31 mob.PathFinder.InitializePathFinder((int)(mob.X / Viewport.TILESIZE), (int)(mob.Z / Viewport.TILESIZE), (int)(x / Viewport.TILESIZE), (int)(z / Viewport.TILESIZE), excludeEndSolidness); 34 35 if (createNewPathFinder && mob.DistanceTo(x, z) > 64.0F) 36 { 37 mob.PathFinder.InitializePathFinder((int)(mob.X / Viewport.TILESIZE), (int)(mob.Z / Viewport.TILESIZE), (int)(x / Viewport.TILESIZE), (int)(z / Viewport.TILESIZE), excludeEndSolidness); 38 shouldFindPath = true; 39 } 32 40 return this; 33 41 } … … 35 43 public override void Update() 36 44 { 37 if (!mob.PathFinder.CanFindPath) 38 return; 39 if (mob.PathFinder.IsPathFinding) 40 mob.PathFinder.FindPath(50); 45 if (shouldFindPath) 46 { 47 if (!mob.PathFinder.CanFindPath) 48 return; 49 if (mob.PathFinder.IsPathFinding) 50 mob.PathFinder.FindPath(50); 51 } 41 52 42 if ( mob.PathFinder.Path.Count > 0 && ppi < mob.PathFinder.Path.Count)53 if (shouldFindPath && mob.PathFinder.Path.Count > 0 && ppi < mob.PathFinder.Path.Count) 43 54 { 44 55 Node currentTarget = mob.PathFinder.Path[ppi]; … … 86 97 get 87 98 { 88 return (mob.DistanceTo(x, z) < stopDistance) || moveFails > 10|| !mob.PathFinder.CanFindPath;99 return (mob.DistanceTo(x, z) < stopDistance) || moveFails > 5 || !mob.PathFinder.CanFindPath; 89 100 } 90 101 }
Note: See TracChangeset
for help on using the changeset viewer.