1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
package ch.asynk.rustanddust.game;
import com.badlogic.gdx.graphics.Texture;
import ch.asynk.rustanddust.RustAndDust;
import ch.asynk.rustanddust.engine.SelectedTile;
import ch.asynk.rustanddust.engine.Meteorology;
import ch.asynk.rustanddust.game.Unit;
import ch.asynk.rustanddust.game.Engagement;
import ch.asynk.rustanddust.game.map.Map4Orders;
public abstract class Map extends Map4Orders
{
protected final Meteorology meteorology;
public Map(final RustAndDust game, String map, String hex)
{
super(game,
game.manager.get(map, Texture.class),
new SelectedTile(game.manager.get(hex, Texture.class), new float[] {.1f, .1f, .1f, .1f, .3f, .1f} )
);
meteorology = new Meteorology();
}
public void clearAll()
{
clearMoves();
clearUnits();
}
public void actionDone()
{
}
public void turnDone()
{
RustAndDust.debug("TurnDone", String.format(" Processed Orders : %d", ordersSize()));
game.ctrl.processTurn();
ordersClear();
}
@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.defender.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;
}
}
|