From 57ba38f91476bf21ff72f387baaaa5577e31156d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Wed, 18 Feb 2015 11:27:55 +0100 Subject: Map: engagement code refactoring --- core/src/ch/asynk/tankontank/game/Map.java | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java index 3d16420..c19ee62 100644 --- a/core/src/ch/asynk/tankontank/game/Map.java +++ b/core/src/ch/asynk/tankontank/game/Map.java @@ -467,7 +467,7 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS } } - private boolean resolveFight(Unit unit, final Unit target, boolean mayReroll) + private boolean resolveFight(Unit unit, final Unit target, Engagement e) { int d1 = d6(); int d2 = d6(); @@ -476,11 +476,14 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS int dice = d1 + d2; int distance = 0; + boolean mayReroll = false; boolean night = (meteorology.day == Meteorology.Day.NIGHT); boolean flankAttack = false; boolean terrainBonus = true; - for (Pawn assist : activatedUnits) { + for (Unit assist : activatedUnits) { + if (assist.isAce()) + mayReroll = true; if (assist.isFlankAttack()) flankAttack = true; if (assist.isA(Unit.UnitType.INFANTRY)) @@ -531,24 +534,19 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS } } - engagement.set(d1, d2, d3, d4, cnt, flk, def, tdf, wdf); - engagement.success = success; - engagement.attacker = ctrl.player.army; - engagement.defender = ctrl.opponent.army; - ctrl.hud.engagementSummary(engagement, ctrl.cfg.fxVolume); + e.set(d1, d2, d3, d4, cnt, flk, def, tdf, wdf); + e.success = success; + e.attacker = ctrl.player.army; + e.defender = ctrl.opponent.army; + ctrl.hud.engagementSummary(e, ctrl.cfg.fxVolume); return success; } public boolean engageUnit(Unit unit, final Unit target) { - boolean mayReroll = false; - for (Unit assist : activatedUnits) { - if (assist.isAce()) - mayReroll = true; - } - boolean success = resolveFight(unit, target, mayReroll); + boolean success = resolveFight(unit, target, engagement); breakUnits.clear(); for (Unit u : activatedUnits) { -- cgit v1.1-2-g2b99