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
121
122
123
124
125
|
package ch.asynk.rustanddust.game.states;
import ch.asynk.rustanddust.engine.Orientation;
import ch.asynk.rustanddust.game.Hex;
import ch.asynk.rustanddust.game.Zone;
import ch.asynk.rustanddust.game.Unit;
import ch.asynk.rustanddust.game.UnitList;
import ch.asynk.rustanddust.game.Ctrl.MsgType;
import ch.asynk.rustanddust.game.hud.ActionButtons.Buttons;
public class StateDeployment extends StateCommon
{
private Zone entryZone;
private UnitList deployedUnits = new UnitList(10);
@Override
public void enterFrom(StateType prevState)
{
clear();
ctrl.hud.playerInfo.unitDock.show();
}
@Override
public boolean processMsg(MsgType msg, Object data)
{
switch(msg)
{
case UNIT_DOCK_SELECT:
showEntryZone((Unit) data);
return true;
case CANCEL:
if (activeUnit() != null)
undeployUnit();
return true;
case OK:
deployedUnits.clear();
ctrl.postTurnDone();
return true;
case UNIT_DEPLOYED:
deployedUnits.add((Unit) data);
return true;
case UNIT_UNDEPLOYED:
ctrl.battle.getPlayer().revertUnitEntry((Unit) data);
return true;
}
return false;
}
@Override
public void touch(Hex hex)
{
if (activeUnit() != null) {
deployUnit(Orientation.fromAdj(selectedHex, hex));
} else if ((selectedUnit() != null) && (entryZone != null)) {
if (hex.isEmpty() && entryZone.contains(hex)) {
showUnit(selectedUnit(), hex);
}
} else {
Unit unit = hex.getUnit();
if (deployedUnits.contains(unit))
showRotation(unit, hex);
}
}
private void showEntryZone(Unit unit)
{
select(unit);
if (entryZone != null)
entryZone.enable(Hex.AREA, false);
entryZone = unit.entryZone;
entryZone.enable(Hex.AREA, true);
}
private void showUnit(Unit unit, Hex hex)
{
activate(unit);
selectedHex = hex;
ctrl.battle.getPlayer().reinforcement.remove(unit);
map.setOnBoard(unit, hex, entryZone.orientation);
deployedUnits.add(unit);
entryZone.enable(Hex.AREA, false);
showRotation(unit, hex);
ctrl.hud.update();
}
private void showRotation(Unit unit, Hex hex)
{
activate(unit);
selectedHex = hex;
map.hexSelect(selectedHex);
map.hexDirectionsShow(selectedHex);
ctrl.hud.playerInfo.unitDock.hide();
ctrl.hud.actionButtons.show(Buttons.ABORT.b);
}
private void deployUnit(Orientation o)
{
if (o == Orientation.KEEP)
o = activeUnit().getOrientation();
ctrl.postOrder(map.getSetOrder(activeUnit(), selectedHex, o), StateType.DEPLOYMENT);
clear();
}
private void undeployUnit()
{
ctrl.postOrder(map.getRevertSetOrder(activeUnit()), StateType.DEPLOYMENT);
ctrl.hud.update();
clear();
ctrl.hud.playerInfo.unitDock.show();
}
private void clear()
{
if (selectedHex != null) {
map.hexUnselect(selectedHex);
map.hexDirectionsHide(selectedHex);
}
activate(null);
entryZone = null;
selectedHex = null;
select(null);
ctrl.hud.actionButtons.hide();
}
}
|