diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2015-12-07 16:29:09 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2015-12-07 16:29:09 +0100 |
commit | 850611c14531be449fb2d1c71815eea44bc982df (patch) | |
tree | 4fc4eda315d81b913b643b63418443ea17c957cb | |
parent | cfe450c416539a029ac8b3e0068f88d02f15539f (diff) | |
download | RustAndDust-850611c14531be449fb2d1c71815eea44bc982df.zip RustAndDust-850611c14531be449fb2d1c71815eea44bc982df.tar.gz |
add MapRules: that holds engagement specific rules
-rw-r--r-- | core/src/ch/asynk/rustanddust/game/Map.java | 73 | ||||
-rw-r--r-- | core/src/ch/asynk/rustanddust/game/battles/Map00.java | 2 | ||||
-rw-r--r-- | core/src/ch/asynk/rustanddust/game/battles/MapRules.java | 93 |
3 files changed, 97 insertions, 71 deletions
diff --git a/core/src/ch/asynk/rustanddust/game/Map.java b/core/src/ch/asynk/rustanddust/game/Map.java index 60c445b..6a5c8a9 100644 --- a/core/src/ch/asynk/rustanddust/game/Map.java +++ b/core/src/ch/asynk/rustanddust/game/Map.java @@ -58,6 +58,8 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS private OrderList commands; protected abstract void setup(); + protected abstract void resolveEngagement(Engagement e); + protected abstract int engagementCost(Engagement e); public Map(final RustAndDust game, String map, String hex) { @@ -482,74 +484,6 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS } } - private void resolveEngagement(Engagement e) - { - int dice = e.d1 + e.d2; - - int distance = 0; - boolean mayReroll = false; - boolean night = (meteorology.day == Meteorology.Day.NIGHT); - boolean flankAttack = false; - boolean terrainBonus = true; - - for (Unit unit : activatedUnits) { - if (unit != e.attacker) - e.addAssist(unit); - if (unit.isAce()) - mayReroll = true; - if (unit.isFlankAttack()) - flankAttack = true; - if (unit.preventDefenseOn(e.defender.getTile())) - terrainBonus = false; - if (night) { - if (distance < unit.attackDistance()) - distance = unit.attackDistance(); - } - } - - int cnt = activatedUnits.size(); - int def = e.defender.getDefense(e.attacker.getTile()); - int flk = (flankAttack ? Unit.FLANK_ATTACK_BONUS : 0); - int tdf = (terrainBonus ? e.defender.getTile().defense() : 0); - int wdf = 0; - if (night) { - if (distance > 3) - wdf = 3; - else if (distance > 2) - wdf = 2; - else if (distance > 1) - wdf = 1; - } - int s1 = (dice + cnt + flk); - int s2 = (def + tdf + wdf); - - boolean success = false; - if (dice == 2) { - success = false; - } else if (dice == 12) { - success = true; - } else { - success = (s1 >= s2); - } - if (!success && mayReroll) { - dice = e.d3 + e.d4; - s1 = (dice + cnt + flk); - if (dice == 2) { - success = false; - } else if (dice == 12) { - success = true; - } else { - success = (s1 >= s2); - } - } else { - e.d3 = 0; - e.d4 = 0; - } - - e.set(cnt, flk, def, tdf, wdf); - e.success = success; - } - private int doEngagement(Engagement e) { breakthroughUnits.clear(); @@ -575,8 +509,7 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS ctrl.hud.engagementSummary(e, ctrl.cfg.fxVolume); addEngagementAnimation(e.defender); - // do not consume action points - if ((activatedUnits.size() == 1) && e.attacker.isA(Unit.UnitType.AT_GUN) && e.defender.isHardTarget()) + if (engagementCost(e) == 0) activatedUnits.clear(); return (e.success ? 1 : 0); diff --git a/core/src/ch/asynk/rustanddust/game/battles/Map00.java b/core/src/ch/asynk/rustanddust/game/battles/Map00.java index 618fe45..a9126bd 100644 --- a/core/src/ch/asynk/rustanddust/game/battles/Map00.java +++ b/core/src/ch/asynk/rustanddust/game/battles/Map00.java @@ -6,7 +6,7 @@ import ch.asynk.rustanddust.engine.Orientation; import ch.asynk.rustanddust.game.Map; import ch.asynk.rustanddust.game.Hex; -public class Map00 extends Map +public class Map00 extends MapRules { public Map00(final RustAndDust game, String map, String hex) { diff --git a/core/src/ch/asynk/rustanddust/game/battles/MapRules.java b/core/src/ch/asynk/rustanddust/game/battles/MapRules.java new file mode 100644 index 0000000..3426701 --- /dev/null +++ b/core/src/ch/asynk/rustanddust/game/battles/MapRules.java @@ -0,0 +1,93 @@ +package ch.asynk.rustanddust.game.battles; + +import ch.asynk.rustanddust.RustAndDust; + +import ch.asynk.rustanddust.game.Map; +import ch.asynk.rustanddust.game.Unit; +import ch.asynk.rustanddust.game.Engagement; + +abstract public class MapRules extends Map +{ + public MapRules(final RustAndDust game, String map, String hex) + { + super(game, map, hex); + } + + @Override + protected int engagementCost(Engagement e) + { + if ((activatedUnits.size() == 1) && e.attacker.isA(Unit.UnitType.AT_GUN) && e.defender.isHardTarget()) + return 0; + return 1; + } + + @Override + protected void resolveEngagement(Engagement e) + { + int dice = e.d1 + e.d2; + + int distance = 0; + boolean mayReroll = false; + boolean night = meteorology.isNight(); + boolean flankAttack = false; + boolean terrainBonus = true; + + for (Unit unit : activatedUnits) { + if (unit != e.attacker) + e.addAssist(unit); + if (unit.isAce()) + mayReroll = true; + if (unit.isFlankAttack()) + flankAttack = true; + if (unit.preventDefenseOn(e.defender.getTile())) + terrainBonus = false; + if (night) { + if (distance < unit.attackDistance()) + distance = unit.attackDistance(); + } + } + + int cnt = activatedUnits.size(); + int def = e.defender.getDefense(e.attacker.getTile()); + int flk = (flankAttack ? Unit.FLANK_ATTACK_BONUS : 0); + int tdf = (terrainBonus ? e.defender.getTile().defense() : 0); + int wdf = 0; + if (night) { + if (distance > 3) + wdf = 3; + else if (distance > 2) + wdf = 2; + else if (distance > 1) + wdf = 1; + } + int s1 = (dice + cnt + flk); + int s2 = (def + tdf + wdf); + + boolean success = false; + if (dice == 2) { + success = false; + } else if (dice == 12) { + success = true; + } else { + success = (s1 >= s2); + } + if (!success && mayReroll) { + dice = e.d3 + e.d4; + s1 = (dice + cnt + flk); + if (dice == 2) { + success = false; + } else if (dice == 12) { + success = true; + } else { + success = (s1 >= s2); + } + } else { + e.d3 = 0; + e.d4 = 0; + } + + e.set(cnt, flk, def, tdf, wdf); + e.success = success; + } + +} |