From cacdf7f266c76c80efbdf3e8b3cbf3c81d762913 Mon Sep 17 00:00:00 2001 From: Retera Date: Sun, 24 Jan 2021 12:46:34 -0500 Subject: [PATCH] Disable auto attack for workers, fix NPE in return resources --- .../warsmash/viewer5/handlers/w3x/simulation/CUnit.java | 3 ++- .../w3x/simulation/behaviors/CBehaviorAttack.java | 4 +--- .../behaviors/harvest/CBehaviorReturnResources.java | 9 +++++++-- .../combat/attacks/CUnitAttackMissileSplash.java | 1 - 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/CUnit.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/CUnit.java index edcbc29..e16e779 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/CUnit.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/CUnit.java @@ -342,7 +342,8 @@ public class CUnit extends CWidget { } public boolean autoAcquireAttackTargets(final CSimulation game, final boolean disableMove) { - if (!this.unitType.getAttacks().isEmpty()) { + if (!this.unitType.getAttacks().isEmpty() + && !this.unitType.getClassifications().contains(CUnitClassification.PEON)) { if (this.collisionRectangle != null) { tempRect.set(this.collisionRectangle); } diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/behaviors/CBehaviorAttack.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/behaviors/CBehaviorAttack.java index 47faf30..6dab933 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/behaviors/CBehaviorAttack.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/behaviors/CBehaviorAttack.java @@ -47,10 +47,8 @@ public class CBehaviorAttack extends CAbstractRangedBehavior { if (simulation.getGameTurnTick() < this.unit.getCooldownEndTime()) { range += this.unitAttack.getRangeMotionBuffer(); } - final double rangeCheckDistance = this.unit.distance(this.target); - System.out.println("rangeCheckDistance=" + rangeCheckDistance); return this.unit.canReach(this.target, range) - && (rangeCheckDistance >= this.unit.getUnitType().getMinimumAttackRange()); + && (this.unit.distance(this.target) >= this.unit.getUnitType().getMinimumAttackRange()); } @Override diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/behaviors/harvest/CBehaviorReturnResources.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/behaviors/harvest/CBehaviorReturnResources.java index 294f3ba..31cef51 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/behaviors/harvest/CBehaviorReturnResources.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/behaviors/harvest/CBehaviorReturnResources.java @@ -26,8 +26,13 @@ public class CBehaviorReturnResources extends CAbstractRangedBehavior implements this.abilityHarvest = abilityHarvest; } - public CBehaviorReturnResources reset(final CSimulation simulation) { - innerReset(findNearestDropoffPoint(simulation)); + public CBehavior reset(final CSimulation simulation) { + final CUnit nearestDropoffPoint = findNearestDropoffPoint(simulation); + if (nearestDropoffPoint == null) { + // TODO it is unconventional not to return self here + return this.unit.pollNextOrderBehavior(simulation); + } + innerReset(nearestDropoffPoint); return this; } diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/combat/attacks/CUnitAttackMissileSplash.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/combat/attacks/CUnitAttackMissileSplash.java index 266d6da..5f0ae91 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/combat/attacks/CUnitAttackMissileSplash.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/combat/attacks/CUnitAttackMissileSplash.java @@ -133,7 +133,6 @@ public class CUnitAttackMissileSplash extends CUnitAttackMissile { public boolean call(final CUnit enumUnit) { if (enumUnit.canBeTargetedBy(this.simulation, this.source, this.attack.areaOfEffectTargets)) { final double distance = enumUnit.distance(this.x, this.y); - System.out.println("enum distance=" + distance); if (distance <= (this.attack.areaOfEffectFullDamage)) { enumUnit.damage(this.simulation, this.source, this.attack.getAttackType(), this.attack.getWeaponSound(), this.damage);