Changeset 4646
- Timestamp:
- 2013-07-24 23:56:47 (10 years ago)
- Location:
- 2013/30/DenisZ/CastleMaster/CastleMaster
- Files:
-
- 1 deleted
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Ai/AStar.cs
r4635 r4646 63 63 calls = 0; 64 64 65 if (ignoreSolidnessForEnd)65 if (ignoreSolidnessForEnd) 66 66 tiles[xEnd + zEnd * level.Width] = false; 67 67 … … 102 102 } 103 103 104 public void ApplySolidnessToPos(List<int> posList )104 public void ApplySolidnessToPos(List<int> posList, bool ignoreEndSolidness) 105 105 { 106 106 foreach (int i in posList) 107 107 tiles[i] = false; 108 109 if(ignoreEndSolidness) 110 tiles[xEnd + zEnd * level.Width] = true; 111 } 112 113 public void Reset() 114 { 115 Path.Clear(); 116 isPathFinding = false; 117 canPathFind = true; 108 118 } 109 119 … … 213 223 return result; 214 224 } 225 226 215 227 } 216 228 } -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Ai/Orders/OrderMove.cs
r4635 r4646 11 11 public class OrderMove : Order 12 12 { 13 private float x, z; 14 private int ppi = 0; 15 private bool excludeEndSolidness; 16 private float stopDistance; 17 private int moveFails = 0; 18 private float lastDist = 0.0F; 19 private bool shouldFindPath = false; 20 private bool createNewPathFinder; 13 protected float x, z; 14 protected int ppi = 0; 15 protected bool excludeEndSolidness; 16 protected float stopDistance; 17 protected int moveFails = 0; 18 protected float lastDist = 0.0F; 19 protected bool shouldFindPath = false; 20 protected bool createNewPathFinder; 21 protected float turnDistance; 22 protected bool stopOnMoveFail; 21 23 22 public OrderMove(float x, float z, float stopDistance = 2.0F, bool excludeEndSolidness = false, bool createNewPathFinder = true)24 public OrderMove(float x, float z, float stopDistance = 2.0F, float turnDistance = 8.0F, bool excludeEndSolidness = false, bool createNewPathFinder = true, bool stopOnMoveFail = false) 23 25 { 24 26 this.stopDistance = stopDistance; … … 27 29 this.x = x; 28 30 this.z = z; 31 this.turnDistance = turnDistance; 32 this.stopOnMoveFail = stopOnMoveFail; 29 33 } 30 34 … … 33 37 base.Initialize(mob); 34 38 35 if (createNewPathFinder && mob.DistanceTo(x, z) > 64.0F)39 if (createNewPathFinder) 36 40 { 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; 41 if (mob.DistanceTo(x, z) > 64.0F) 42 { 43 mob.PathFinder.InitializePathFinder((int)(mob.X / Viewport.TILESIZE), (int)(mob.Z / Viewport.TILESIZE), (int)(x / Viewport.TILESIZE), (int)(z / Viewport.TILESIZE), excludeEndSolidness); 44 shouldFindPath = true; 45 } 46 else 47 { 48 shouldFindPath = false; 49 mob.PathFinder.Reset(); 50 } 39 51 } 40 52 return this; … … 48 60 return; 49 61 if (mob.PathFinder.IsPathFinding) 50 mob.PathFinder.FindPath( 50);62 mob.PathFinder.FindPath(125); 51 63 } 52 64 53 if ( shouldFindPath &&mob.PathFinder.Path.Count > 0 && ppi < mob.PathFinder.Path.Count)65 if (mob.PathFinder.Path.Count > 0 && ppi < mob.PathFinder.Path.Count) 54 66 { 55 67 Node currentTarget = mob.PathFinder.Path[ppi]; … … 58 70 59 71 float dist = mob.DistanceTo(xtPoint, ztPoint); 60 if (dist > 8.0F)72 if (dist > turnDistance) 61 73 { 62 74 if (mob.TurnTowards(xtPoint, ztPoint)) … … 93 105 } 94 106 107 public bool FailingToMove { get { return moveFails > 20; } } 108 95 109 public override bool Finished 96 110 { 97 111 get 98 112 { 99 return (mob.DistanceTo(x, z) < stopDistance) || moveFails > 5 || !mob.PathFinder.CanFindPath;113 return (mob.DistanceTo(x, z) < stopDistance) || !mob.PathFinder.CanFindPath || (stopOnMoveFail && moveFails > 20); 100 114 } 101 115 } -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/CastleMaster.csproj
r4635 r4646 77 77 <Compile Include="Ai\Node.cs" /> 78 78 <Compile Include="Ai\Orders\Order.cs" /> 79 <Compile Include="Ai\Orders\OrderGoAround.cs" />80 79 <Compile Include="Ai\Orders\OrderMove.cs" /> 81 80 <Compile Include="Entities\Entity.cs" /> -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Entities/Entity.cs
r4635 r4646 84 84 } 85 85 86 public virtual void OnTriedExitLevel() { } 87 86 88 public bool Move(float xd, float zd) 87 89 { 88 90 if (xd == 0.0F && zd == 0.0F) return false; 89 91 90 if (BoundingRectangle.XRight + xd > level.Width * Viewport.TILESIZE) return false; 91 if (BoundingRectangle.XLeft + xd < 0.0F) return false; 92 if (BoundingRectangle.ZFar + zd < 0.0F) return false; 93 if (BoundingRectangle.ZNear + zd > level.Height * Viewport.TILESIZE) return false; 92 bool inLevel = true; 93 94 if (BoundingRectangle.XRight + xd > level.Width * Viewport.TILESIZE) inLevel = false; 95 else if (BoundingRectangle.XLeft + xd < 0.0F) inLevel = false; 96 else if (BoundingRectangle.ZFar + zd < 0.0F) inLevel = false; 97 else if (BoundingRectangle.ZNear + zd > level.Height * Viewport.TILESIZE) inLevel = false; 98 99 if (!inLevel) 100 { 101 OnTriedExitLevel(); 102 return false; 103 } 94 104 95 105 int moveSteps = (int)(Math.Sqrt(xd * xd + zd * zd) + 1); -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Entities/EntityArrow.cs
r4635 r4646 62 62 } 63 63 64 public override void OnTriedExitLevel() 65 { 66 Remove(); 67 } 68 64 69 public override void Update() 65 70 { -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Game.cs
r4635 r4646 64 64 graphics.PreferredBackBufferWidth = WIDTH; 65 65 graphics.PreferredBackBufferHeight = HEIGHT; 66 graphics.SynchronizeWithVerticalRetrace = true;66 graphics.SynchronizeWithVerticalRetrace = false; 67 67 graphics.ApplyChanges(); 68 68 Window.Title = TITLE; -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Players/PlayerReal.cs
r4635 r4646 82 82 selectedMobUnits.Clear(); 83 83 84 if (selectedUnit != null) 85 selectedUnit.IsSelected = false; 86 selectedUnit = null; 84 87 if (u != null) 85 88 { … … 97 100 { 98 101 if (selectedUnit != null) 99 selectedUnit.OnFunctionClick(camera.MouseWorldPos.X, camera.MouseWorldPos.Y, false);102 selectedUnit.OnFunctionClick(camera.MouseWorldPos.X, camera.MouseWorldPos.Y, 1, false); 100 103 else if (selectedMobUnits.Count > 0) 101 104 selectedMobUnits[0].OnGroupOrder(selectedMobUnits, camera.MouseWorldPos.X, camera.MouseWorldPos.Y); -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Units/Mobs/Mob.cs
r4635 r4646 82 82 protected virtual void OnSameTypeGroupOrder(List<Mob> mobs, float x, float z) 83 83 { 84 OnFunctionClick(x, z, false);84 OnFunctionClick(x, z, mobs.Count, false); 85 85 foreach (Mob m in mobs) 86 86 { 87 87 if (m == this) continue; 88 m.OnFunctionClick(x, z, true);88 m.OnFunctionClick(x, z, mobs.Count, true); 89 89 m.pathFinder = pathFinder; 90 90 } -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Units/Mobs/MobRanger.cs
r4635 r4646 8 8 using IsometricEngineTest.Ai.Orders; 9 9 using CastleMaster.Entities; 10 using CastleMaster.Ai.Orders; 10 11 11 12 namespace CastleMaster.Units.Mobs … … 13 14 public class MobRanger : Mob 14 15 { 15 private enum OrderType { ATTACK, WALK, NONE }16 private enum OrderType { ATTACK, WALK, AVOID, NONE } 16 17 17 private float ATTACK_RANGE_OFFSET = 20.0F;18 private float ATTACK_RANGE_OFFSET = 30.0F; 18 19 private float attackRange, attackRangeSqr; 19 20 … … 25 26 private int spriteX; 26 27 private float pushPower = 2.0F; 28 private int lastSameOrderAmount = 0; 29 private bool attack = false; 27 30 28 31 public MobRanger(Level level, Player owner) … … 75 78 } 76 79 77 private void CreateAttackOrder(Unit u, bool wasCalledBefore)80 private void CreateAttackOrder(Unit u, int orderAmount, bool wasCalledBefore) 78 81 { 79 82 currentOrderType = OrderType.ATTACK; 80 83 attackRange = u.Width + ATTACK_RANGE_OFFSET; 81 84 attackRangeSqr = attackRange * attackRange; 82 SetOrder(new OrderMove(u.X, u.Z, attackRange, true, !wasCalledBefore));85 SetOrder(new OrderMove(u.X, u.Z, attackRange, orderAmount * 2.0F, true, !wasCalledBefore)); 83 86 target = u; 84 87 } … … 88 91 base.Damage(attacker, damage, dir, pushPower); 89 92 if (!isAttacking && currentOrderType == OrderType.NONE) 90 CreateAttackOrder(attacker, false);93 CreateAttackOrder(attacker, 1, false); 91 94 } 92 95 … … 98 101 else if (currentOrderType == OrderType.WALK) 99 102 currentOrderType = OrderType.NONE; 103 else if (currentOrderType == OrderType.AVOID) 104 { 105 currentOrderType = OrderType.ATTACK; 106 attack = true; 107 } 100 108 } 101 109 102 public override void OnFunctionClick(float x, float z, bool wasCalledBefore) 110 public override Order GetNextOrder() 111 { 112 if (attack) 113 { 114 attack = false; 115 return new OrderMove(target.X, target.Z, attackRange, excludeEndSolidness: true); 116 } 117 return base.GetNextOrder(); 118 } 119 120 public override void OnFunctionClick(float x, float z, int sameOrders, bool wasCalledBefore) 103 121 { 104 122 Unit u = Owner.SelectUnit(Game.GetEnemyTeam(Owner.Team)); 105 123 if (u != null) 106 CreateAttackOrder(u, wasCalledBefore);124 CreateAttackOrder(u, sameOrders, wasCalledBefore); 107 125 else 108 126 { 109 127 if (target != null) StopAttack(); 110 128 currentOrderType = OrderType.WALK; 111 SetOrder(new OrderMove(x, z, createNewPathFinder: !wasCalledBefore ));129 SetOrder(new OrderMove(x, z, createNewPathFinder: !wasCalledBefore, stopOnMoveFail: true)); 112 130 } 131 lastSameOrderAmount = sameOrders; 113 132 } 114 133 … … 122 141 { 123 142 isAttacking = false; 124 CreateAttackOrder(target, false);143 CreateAttackOrder(target, 1, false); 125 144 } 126 145 else … … 131 150 StopAttack(); 132 151 } 152 if (target == null || target.Removed) 153 StopAttack(); 133 154 } 134 155 else if (!isAttacking && currentOrderType == OrderType.NONE) 135 156 { 136 List<Unit> units = level.GetNearbyEnemyUnits(Game.GetEnemyTeam(Owner.Team), (int)(x / Viewport.TILESIZE), (int)(z / Viewport.TILESIZE), 4);157 List<Unit> units = level.GetNearbyEnemyUnits(Game.GetEnemyTeam(Owner.Team), (int)(x / Viewport.TILESIZE), (int)(z / Viewport.TILESIZE), 5); 137 158 if (units.Count > 0) 138 CreateAttackOrder(units[0], false); 159 CreateAttackOrder(units[0], 1, false); 160 } 161 else if (!isAttacking && currentOrderType == OrderType.ATTACK) 162 { 163 float dist = lastSameOrderAmount * 20.0F; 164 if (currentOrder != null && currentOrder is OrderMove && ((OrderMove)currentOrder).FailingToMove && DistanceToSqr(target.X, target.Z) < attackRangeSqr + dist * dist) 165 { 166 int tp = level.GetClosestDiagonalOpenPos(this); 167 if (tp > 0) 168 { 169 currentOrderType = OrderType.AVOID; 170 SetOrder(new OrderMove(tp % level.Width * Viewport.TILESIZE, tp / level.Width * Viewport.TILESIZE, stopOnMoveFail: true)); 171 } 172 } 173 if (target == null || target.Removed) 174 { 175 StopAttack(); 176 StopCurrentOrder(); 177 } 139 178 } 140 179 -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Units/Mobs/MobWarrior.cs
r4635 r4646 8 8 using IsometricEngineTest.Ai.Orders; 9 9 using System.Diagnostics; 10 using CastleMaster.Ai.Orders; 10 11 11 12 namespace CastleMaster.Units.Mobs … … 13 14 public class MobWarrior : Mob 14 15 { 15 private enum OrderType { ATTACK, WALK, NONE }16 private enum OrderType { ATTACK, WALK, AVOID, NONE } 16 17 17 private float ATTACK_RANGE_OFFSET = 2 0.0F;18 private float ATTACK_RANGE_OFFSET = 25.0F; 18 19 private float attackRange, attackRangeSqr; 19 20 … … 25 26 private int spriteX; 26 27 private float pushPower = 5.0F; 28 private int lastSameOrderAmount = 0; 29 private bool engageAttack = false; 27 30 28 31 public MobWarrior(Level level, Player owner) … … 66 69 target = null; 67 70 currentOrderType = OrderType.NONE; 71 StopCurrentOrder(); 68 72 } 69 73 … … 75 79 } 76 80 77 private void CreateAttackOrder(Unit u, bool wasCalledBefore)81 private void CreateAttackOrder(Unit u, int orderAmount, bool wasCalledBefore) 78 82 { 79 83 currentOrderType = OrderType.ATTACK; 80 84 attackRange = u.Width / 2 + ATTACK_RANGE_OFFSET; 81 85 attackRangeSqr = attackRange * attackRange; 82 SetOrder(new OrderMove(u.X, u.Z, attackRange, true, !wasCalledBefore));86 SetOrder(new OrderMove(u.X, u.Z, attackRange, orderAmount * 2.0F, true, !wasCalledBefore)); 83 87 target = u; 84 88 } … … 88 92 base.Damage(attacker, damage, dir, pushPower); 89 93 if (!isAttacking && currentOrderType == OrderType.NONE) 90 CreateAttackOrder(attacker, false);94 CreateAttackOrder(attacker, 1, false); 91 95 } 92 96 … … 98 102 else if (currentOrderType == OrderType.WALK) 99 103 currentOrderType = OrderType.NONE; 104 else if (currentOrderType == OrderType.AVOID) 105 { 106 currentOrderType = OrderType.ATTACK; 107 engageAttack = true; 108 } 100 109 } 101 110 102 public override void OnFunctionClick(float x, float z, bool wasCalledBefore) 111 public override Order GetNextOrder() 112 { 113 if (engageAttack) 114 { 115 engageAttack = false; 116 return new OrderMove(target.X, target.Z, attackRange, excludeEndSolidness: true); 117 } 118 return base.GetNextOrder(); 119 } 120 121 public override void OnFunctionClick(float x, float z, int sameOrders, bool wasCalledBefore) 103 122 { 104 123 Unit u = Owner.SelectUnit(Game.GetEnemyTeam(Owner.Team)); 105 124 if (u != null) 106 CreateAttackOrder(u, wasCalledBefore);125 CreateAttackOrder(u, sameOrders, wasCalledBefore); 107 126 else 108 127 { 109 128 if (target != null) StopAttack(); 110 129 currentOrderType = OrderType.WALK; 111 SetOrder(new OrderMove(x, z, createNewPathFinder: !wasCalledBefore ));130 SetOrder(new OrderMove(x, z, createNewPathFinder: !wasCalledBefore, stopOnMoveFail: true)); 112 131 } 132 lastSameOrderAmount = sameOrders; 113 133 } 114 134 … … 122 142 { 123 143 isAttacking = false; 124 CreateAttackOrder(target, false);144 CreateAttackOrder(target, 1, false); 125 145 } 126 146 else … … 136 156 else if (!isAttacking && currentOrderType == OrderType.NONE) 137 157 { 138 List<Unit> units = level.GetNearbyEnemyUnits(Game.GetEnemyTeam(Owner.Team), (int)(x / Viewport.TILESIZE), (int)(z / Viewport.TILESIZE), 2);158 List<Unit> units = level.GetNearbyEnemyUnits(Game.GetEnemyTeam(Owner.Team), (int)(x / Viewport.TILESIZE), (int)(z / Viewport.TILESIZE), 3); 139 159 if (units.Count > 0) 140 CreateAttackOrder(units[0], false); 160 CreateAttackOrder(units[0], 1, false); 161 } 162 else if (!isAttacking && currentOrderType == OrderType.ATTACK) 163 { 164 float dist = lastSameOrderAmount * 12.0F; 165 if (currentOrder != null && currentOrder is OrderMove && ((OrderMove)currentOrder).FailingToMove && DistanceToSqr(target.X, target.Z) < attackRangeSqr + dist * dist) 166 { 167 int tp = level.GetClosestDiagonalOpenPos(this); 168 if (tp > 0) 169 { 170 currentOrderType = OrderType.AVOID; 171 SetOrder(new OrderMove(tp % level.Width * Viewport.TILESIZE, tp / level.Width * Viewport.TILESIZE, stopOnMoveFail: true)); 172 } 173 } 174 if (target == null || target.Removed) 175 StopAttack(); 141 176 } 142 177 -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Units/Mobs/MobWoodcutter.cs
r4635 r4646 9 9 using Microsoft.Xna.Framework; 10 10 using CastleMaster.Entities.TileEntities; 11 using CastleMaster.Ai.Orders; 11 12 12 13 namespace CastleMaster.Units.Mobs … … 14 15 public class MobWoodcutter : Mob 15 16 { 17 private enum OrderType { CHOP, MOVE, AVOID, NONE } 18 16 19 private TileEntityTree currentTarget; 17 private bool isChopping = false , isOrderedToChop = false;20 private bool isChopping = false; 18 21 private AnimationHelper choppingAnimation; 19 22 private int currentSpriteX; 23 private OrderType currentOrderType = OrderType.NONE; 24 private int lastSameOrderAmount = 0; 25 private bool engangeChopping = false; 20 26 21 27 public MobWoodcutter(Level level, Player owner) … … 63 69 { 64 70 isChopping = false; 65 isOrderedToChop = false;71 currentOrderType = OrderType.NONE; 66 72 choppingAnimation.Stop(); 67 73 choppingAnimation.Reset(); 68 74 } 69 75 70 public override void OnFunctionClick(float x, float z, bool wasCalledBefore)76 public override void OnFunctionClick(float x, float z, int sameOrderAmount, bool wasCalledBefore) 71 77 { 72 TileEntity te = level.GetTileEntity( (int)(x / Viewport.TILESIZE), (int)(z / Viewport.TILESIZE));78 TileEntity te = level.GetTileEntity(this, (int)(x / Viewport.TILESIZE), (int)(z / Viewport.TILESIZE)); 73 79 if (te != null && typeof(TileEntityTree).IsAssignableFrom(te.GetType())) 74 80 { 75 81 if (currentTarget != null) StopChopping(); 76 isOrderedToChop = true;82 currentOrderType = OrderType.CHOP; 77 83 currentTarget = (TileEntityTree)te; 78 SetOrder(new OrderMove(currentTarget.X, currentTarget.Z, 20.0F, true, !wasCalledBefore));84 SetOrder(new OrderMove(currentTarget.X, currentTarget.Z, 20.0F, sameOrderAmount * 4.0F, true, !wasCalledBefore)); 79 85 } 80 86 else … … 85 91 currentTarget = null; 86 92 } 87 SetOrder(new OrderMove(x, z, createNewPathFinder: !wasCalledBefore ));93 SetOrder(new OrderMove(x, z, createNewPathFinder: !wasCalledBefore, stopOnMoveFail: true)); 88 94 } 95 lastSameOrderAmount = sameOrderAmount; 89 96 } 90 97 91 98 protected override void OnOrderFinished() 92 99 { 93 if (isOrderedToChop) 100 base.OnOrderFinished(); 101 102 if (currentOrderType == OrderType.CHOP) 94 103 StartChopping(); 95 104 } … … 101 110 if (isChopping) 102 111 { 112 TurnTowards(currentTarget.X, currentTarget.Z); 103 113 choppingAnimation.UpdateStep(); 104 114 } 115 else if (!isChopping && currentOrderType == OrderType.CHOP) 116 { 117 if (currentOrder != null && currentOrder is OrderMove && ((OrderMove)currentOrder).FailingToMove) 118 { 119 StopChopping(); 120 StopCurrentOrder(); 121 } 122 } 123 105 124 106 125 currentSpriteX = isChopping ? choppingAnimation.CurrentFrame : walkingAnimation.CurrentFrame; -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Units/Unit.cs
r4635 r4646 83 83 } 84 84 85 public virtual void OnFunctionClick(float x, float z, bool wasCalledBefore) { }85 public virtual void OnFunctionClick(float x, float z, int sameOrderAmount, bool wasCalledBefore) { } 86 86 87 87 public override void Update() -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Units/UnitKing.cs
r4635 r4646 34 34 } 35 35 36 public override void OnRemoved() 37 { 38 int xTile = (int)(X / Viewport.TILESIZE); 39 int zTile = (int)(Z / Viewport.TILESIZE); 40 41 for (int x = xTile - 4; x <= xTile + 4; x++) 42 { 43 if (x < 0 || x >= level.Width) continue; 44 for (int z = zTile - 4; z <= zTile + 4; z++) 45 { 46 if (z < 0 || z >= level.Height) continue; 47 48 level.SetTile(x, z, 1); 49 level.SetData(x, z, 0); 50 } 51 } 52 53 level.RemoveUnit(this); 54 } 55 36 56 public override void Render(RenderHelper renderer) 37 57 { -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/World/Level.cs
r4635 r4646 32 32 if (br1.ZFar >= br2.ZNear) 33 33 { 34 if ((e1.Z + e1.X - e1.RenderOffset.Y) - e1.RenderOffset.Y < (e2.Z + e2.X - e2.RenderOffset.Y) - e2.RenderOffset.Y) return -1;34 //if ((e1.Z + e1.X - e1.RenderOffset.Y) - e1.RenderOffset.Y < (e2.Z + e2.X - e2.RenderOffset.Y) - e2.RenderOffset.Y) return -1; 35 35 return +1; 36 36 } … … 291 291 } 292 292 293 public TileEntity GetTileEntity(int xTile, int zTile) 294 { 293 public TileEntity GetTileEntity(Entity ent, int xTile, int zTile) 294 { 295 TileEntity te = null; 295 296 List<Entity> ents = entitiesInTiles[xTile + zTile * width]; 296 297 if (ents.Count > 0) 297 return ents[0] as TileEntity; 298 te = ents[0] as TileEntity; 299 if (te == null) return null; 300 301 for (int z = zTile - 1; z <= zTile + 1; z++) 302 { 303 if (z < 0 || z >= height) continue; 304 for (int x = xTile - 1; x <= xTile + 1; x++) 305 { 306 if (x < 0 || x >= width) continue; 307 308 ents = entitiesInTiles[x + z * width]; 309 310 if (ents.Count > 0) 311 { 312 Entity e = ents[0]; 313 if (e != te && !e.Blocks(te)) return te; 314 } 315 else return te; 316 } 317 } 298 318 299 319 return null; … … 401 421 402 422 return result; 423 } 424 425 public int GetClosestDiagonalOpenPos(Entity ent) 426 { 427 int xTile = (int)(ent.X / Viewport.TILESIZE); 428 int zTile = (int)(ent.Z / Viewport.TILESIZE); 429 430 bool blocks = false; 431 int tp; 432 433 for (int z = zTile - 1; z <= zTile + 1; z++) 434 { 435 if (z < 0 || z >= height) continue; 436 if (z == zTile) continue; 437 438 tp = xTile + z * width; 439 Tile t = registeredTiles[tiles[tp]]; 440 if (t.ID == TILE_VOID || t.IsSolidTo(ent)) blocks |= true; 441 442 List<Entity> ents = entitiesInTiles[tp]; 443 444 foreach (Entity e in ents) 445 { 446 if (e != ent) 447 blocks |= e.Blocks(ent); 448 } 449 if (!blocks) return tp; 450 } 451 452 blocks = false; 453 for (int x = xTile - 1; x <= xTile + 1; x++) 454 { 455 if (x < 0 || x >= width) continue; 456 if (x == xTile) continue; 457 458 tp = x + zTile * width; 459 Tile t = registeredTiles[tiles[tp]]; 460 if (t.ID == TILE_VOID || t.IsSolidTo(ent)) blocks |= true; 461 462 List<Entity> ents = entitiesInTiles[tp]; 463 464 foreach (Entity e in ents) 465 { 466 if (e != ent) 467 blocks |= e.Blocks(ent); 468 } 469 if (!blocks) return tp; 470 } 471 472 473 //for (int z = zTile - 1; z <= zTile + 1; z++) 474 //{ 475 // if (z < 0 || z >= height) continue; 476 // for (int x = xTile - 1; x <= xTile + 1; x++) 477 // { 478 // if (x < 0 || x >= width) continue; 479 // if (x == xTile && z == zTile) continue; 480 481 // tp = x + z * width; 482 // Tile t = registeredTiles[tiles[tp]]; 483 // if (t.ID == TILE_VOID || t.IsSolidTo(ent)) blocks |= true; 484 485 // List<Entity> ents = entitiesInTiles[tp]; 486 487 // foreach (Entity e in ents) 488 // { 489 // if (e != ent) 490 // blocks |= e.Blocks(ent); 491 // } 492 // if (!blocks) return tp; 493 // } 494 //} 495 496 return -1; 403 497 } 404 498 … … 426 520 } 427 521 428 429 522 return result; 430 523 } -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMasterContent/CastleMasterContent.contentproj
r4635 r4646 15 15 <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'"> 16 16 <PlatformTarget>x86</PlatformTarget> 17 <UseVSHostingProcess>true</UseVSHostingProcess> 17 18 </PropertyGroup> 18 19 <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
Note: See TracChangeset
for help on using the changeset viewer.