v0.6.2b: improved how targeting traps determine distance

This commit is contained in:
Evan Debenham
2017-11-09 03:00:08 -05:00
committed by Evan Debenham
parent be198f1907
commit 0af31996a4
5 changed files with 12 additions and 4 deletions

View File

@@ -949,6 +949,14 @@ public abstract class Level implements Bundlable {
public boolean adjacent( int a, int b ) {
return distance( a, b ) == 1;
}
public int distNoDiag( int a, int b){
int ax = a % width();
int ay = a / width();
int bx = b % width();
int by = b / width();
return Math.abs( ax - bx ) + Math.abs( ay - by );
}
//returns true if the input is a valid tile within the level
public boolean insideMap( int tile ){

View File

@@ -60,7 +60,7 @@ public class DisintegrationTrap extends Trap {
for (Char ch : Actor.chars()){
Ballistica bolt = new Ballistica(pos, ch.pos, Ballistica.PROJECTILE);
if (bolt.collisionPos == ch.pos &&
(target == null || Dungeon.level.distance(pos, ch.pos) < Dungeon.level.distance(pos, target.pos))){
(target == null || Dungeon.level.distNoDiag(pos, ch.pos) < Dungeon.level.distNoDiag(pos, target.pos))){
target = ch;
}
}

View File

@@ -57,7 +57,7 @@ public class GrimTrap extends Trap {
for (Char ch : Actor.chars()){
Ballistica bolt = new Ballistica(pos, ch.pos, Ballistica.PROJECTILE);
if (bolt.collisionPos == ch.pos &&
(target == null || Dungeon.level.distance(pos, ch.pos) < Dungeon.level.distance(pos, target.pos))){
(target == null || Dungeon.level.distNoDiag(pos, ch.pos) < Dungeon.level.distNoDiag(pos, target.pos))){
target = ch;
}
}

View File

@@ -57,7 +57,7 @@ public class PoisonDartTrap extends Trap {
for (Char ch : Actor.chars()){
Ballistica bolt = new Ballistica(pos, ch.pos, Ballistica.PROJECTILE);
if (bolt.collisionPos == ch.pos &&
(target == null || Dungeon.level.distance(pos, ch.pos) < Dungeon.level.distance(pos, target.pos))){
(target == null || Dungeon.level.distNoDiag(pos, ch.pos) < Dungeon.level.distNoDiag(pos, target.pos))){
target = ch;
}
}

View File

@@ -55,7 +55,7 @@ public class WornDartTrap extends Trap {
for (Char ch : Actor.chars()){
Ballistica bolt = new Ballistica(pos, ch.pos, Ballistica.PROJECTILE);
if (bolt.collisionPos == ch.pos &&
(target == null || Dungeon.level.distance(pos, ch.pos) < Dungeon.level.distance(pos, target.pos))){
(target == null || Dungeon.level.distNoDiag(pos, ch.pos) < Dungeon.level.distNoDiag(pos, target.pos))){
target = ch;
}
}