summaryrefslogtreecommitdiffstats
path: root/old/BattleStabToTheFlank.java
blob: c45bac4147a00e80c2964dce2beb6ab7e9f6298f (plain)
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package ch.asynk.rustanddust.game.battles;

import ch.asynk.rustanddust.game.Zone;
import ch.asynk.rustanddust.game.Army;
import ch.asynk.rustanddust.game.Player;
import ch.asynk.rustanddust.game.Ctrl;
import ch.asynk.rustanddust.game.Map;
import ch.asynk.rustanddust.game.Hex;
import ch.asynk.rustanddust.game.HexSet;
import ch.asynk.rustanddust.game.Unit;
import ch.asynk.rustanddust.game.Unit.UnitId;
import ch.asynk.rustanddust.ui.Position;
import ch.asynk.rustanddust.engine.Orientation;

public class BattleStabToTheFlank extends BattleCommon
{
    public BattleStabToTheFlank(Factory factory)
    {
        super(factory);
        name = "Stab To The Flank";
        mapType = Factory.MapType.MAP_B;
    }

    @Override
    public Position getHudPosition(Player player)
    {
        return (player.is(Army.US) ? Position.TOP_RIGHT: Position.TOP_LEFT);
    }

    @Override
    public Player getPlayer()
    {
        if (!usPlayer.isDeploymentDone() || usPlayer.getCurrentTurn() == 1)
            return usPlayer;
        if (usPlayer.getTurnDone() > gePlayer.getTurnDone())
            return gePlayer;
        return usPlayer;
    }

    public Player checkVictory(Ctrl ctrl)
    {
        if (ctrl.opponent.unitsLeft() == 0)
            return ctrl.player;

        if ((ctrl.player.getTurnDone() < 9) || (ctrl.opponent.getTurnDone() < 9))
            return null;

        int gePoints = usPlayer.casualties();
        int usPoints = gePlayer.casualties();
        usPoints += ctrl.map.objectives.count(Army.US);

        int withdrawed = usPlayer.withdrawed();
        if (withdrawed == 0)
            gePoints += 1;
        else
            usPoints += withdrawed;

        if (usPoints > gePoints)
            return usPlayer;
        else
            return gePlayer;
    }

    @Override
    public boolean getReinforcement(Ctrl ctrl, Map map)
    {
        if (ctrl.player.is(Army.US))
            return false;
        if (ctrl.player.getCurrentTurn() != 3)
            return false;

        // hex rows I
        Zone geEntry = new Zone(map, 9);
        geEntry.allowedMoves = (Orientation.SOUTH_WEST.s | Orientation.NORTH_WEST.s);
        for (int i = 0; i < 10; i++)
            geEntry.add(map.getHex(i, 0));
        addEntryZone(geEntry);

        addReinforcement(gePlayer, geEntry, UnitId.GE_TIGER, true);

        return true;
    }

    @Override
    public void setup(Ctrl ctrl, Map map)
    {
        // F6, E6
        map.addHoldObjective(5, 3, Army.NONE);
        map.addObjective(6, 4, Army.NONE);

        // hex rows D-I
        Zone geEntry = new Zone(map, 57);
        geEntry.orientation = Orientation.NORTH;
        for (int i = 3; i < 12; i++)
            geEntry.add(map.getHex(i, 5));
        for (int i = 2; i < 12; i++)
            geEntry.add(map.getHex(i, 4));
        for (int i = 2; i < 11; i++)
            geEntry.add(map.getHex(i, 3));
        for (int i = 1; i < 11; i++)
            geEntry.add(map.getHex(i, 2));
        for (int i = 1; i < 10; i++)
            geEntry.add(map.getHex(i, 1));
        for (int i = 0; i < 10; i++)
            geEntry.add(map.getHex(i, 0));

        addReinforcement(gePlayer, geEntry, UnitId.GE_PANZER_IV_HQ);
        addReinforcement(gePlayer, geEntry, UnitId.GE_PANZER_IV_HQ);
        addReinforcement(gePlayer, geEntry, UnitId.GE_PANZER_IV);
        addReinforcement(gePlayer, geEntry, UnitId.GE_PANZER_IV);
        addReinforcement(gePlayer, geEntry, UnitId.GE_PANZER_IV);
        addReinforcement(gePlayer, geEntry, UnitId.GE_AT_GUN);
        addReinforcement(gePlayer, geEntry, UnitId.GE_INFANTRY);

        // hex row I
        Zone usExit = new Zone(map, 10);
        usExit.orientation = Orientation.NORTH_EAST;
        for (int i = 0; i < 10; i++)
            geEntry.add(map.getHex(i, 0));
        addExitZone(usExit);

        // hex rows A-B
        Zone usEntry = new Zone(map, 19);
        usEntry.orientation = Orientation.SOUTH_EAST;
        for (int i = 4; i < 13; i++) {
            usEntry.add(map.getHex(i, 8));
            usEntry.add(map.getHex(i, 7));
        }
        usEntry.add(map.getHex(13, 8));
        addEntryZone(usEntry);

        addReinforcement(usPlayer, usEntry, usExit, UnitId.US_SHERMAN_HQ);
        addReinforcement(usPlayer, usEntry, usExit, UnitId.US_SHERMAN_HQ);
        addReinforcement(usPlayer, usEntry, usExit, UnitId.US_SHERMAN);
        addReinforcement(usPlayer, usEntry, usExit, UnitId.US_SHERMAN);
        addReinforcement(usPlayer, usEntry, usExit, UnitId.US_SHERMAN);
        addReinforcement(usPlayer, usEntry, usExit, UnitId.US_SHERMAN);
        addReinforcement(usPlayer, usEntry, usExit, UnitId.US_SHERMAN);
        addReinforcement(usPlayer, usEntry, usExit, UnitId.US_INFANTRY);
        addReinforcement(usPlayer, usEntry, usExit, UnitId.US_INFANTRY);
        addReinforcement(usPlayer, usEntry, usExit, UnitId.US_PRIEST);
    }
}