[customwars] r763 committed - Unit isDirect would return true for an anti tank, fixed by adding an e...

0 views
Skip to first unread message

codesite...@google.com

unread,
Oct 16, 2012, 2:45:43 PM10/16/12
to customwar...@googlegroups.com
Revision: 763
Author: ace.stef
Date: Tue Oct 16 11:45:20 2012
Log: Unit isDirect would return true for an anti tank, fixed by adding
an extra function to unit canFireOnAdjacentEnemies
http://code.google.com/p/customwars/source/detail?r=763

Modified:
/trunk/v2/src/com/customwars/client/model/gameobject/Unit.java
/trunk/v2/src/com/customwars/client/model/gameobject/Weapon.java

=======================================
--- /trunk/v2/src/com/customwars/client/model/gameobject/Unit.java Tue Oct
16 10:46:08 2012
+++ /trunk/v2/src/com/customwars/client/model/gameobject/Unit.java Tue Oct
16 11:45:20 2012
@@ -288,14 +288,14 @@
/**
* This unit can counter Attack when:
* #1 it is not destroyed
- * #2 it is direct
+ * #2 it is not indirect
* #3 the Attacker is also a defender
* #4 it has a weapon that can return fire to the attacker
*/
public boolean canCounterAttack(Attacker attacker) {
boolean attackerIsDefender = attacker instanceof Defender;
boolean canReturnFire = attackerIsDefender && !isDestroyed() &&
canFireOn((Defender) attacker);
- return canReturnFire && isDirect();
+ return canReturnFire && canFireOnAdjacentEnemies();
}

public List<Location> getAttackZone() {
@@ -980,7 +980,15 @@
}

/**
- * @return Can this unit fire only on adjacent enemies
+ * @return Can this unit fire on adjacent enemies
+ */
+ public boolean canFireOnAdjacentEnemies() {
+ Weapon weapon = getAvailableAttackWeapon();
+ return weapon != null && weapon.canFireOnAdjacentEnemies();
+ }
+
+ /**
+ * @return Can this unit fire on enemies that are max 1 tile away
*/
public boolean isDirect() {
Weapon weapon = getAvailableAttackWeapon();
=======================================
--- /trunk/v2/src/com/customwars/client/model/gameobject/Weapon.java Sat
Jul 10 10:38:41 2010
+++ /trunk/v2/src/com/customwars/client/model/gameobject/Weapon.java Tue
Oct 16 11:45:20 2012
@@ -131,8 +131,12 @@
/**
* @return Can this weapon fire on adjacent enemies
*/
+ public boolean canFireOnAdjacentEnemies() {
+ return fireRange.isInRange(1);
+ }
+
public boolean isDirect() {
- return fireRange.isInRange(1);
+ return fireRange.getMinRange() == 1 && fireRange.getMaxRange() == 1;
}

/**
@@ -148,8 +152,7 @@
if (!(o instanceof Weapon)) return false;

Weapon weapon = (Weapon) o;
-
- return name == weapon.name;
+ return name.equals(weapon.name);
}

@Override
Reply all
Reply to author
Forward
0 new messages