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
|
package ch.asynk.rustanddust.game;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import ch.asynk.rustanddust.engine.Pawn;
import ch.asynk.rustanddust.engine.Tile;
import ch.asynk.rustanddust.engine.Orientation;
public class Hex extends Tile
{
public enum Terrain implements TileTerrain
{
OFFMAP,
BLOCKED,
CLEAR,
HILLS,
WOODS,
TOWN,
DEPRESSION
}
public static final int FOG = 0;
public static final int SELECT = 1;
public static final int AREA = 2;
public static final int MOVE = 3;
public static final int DIRECTIONS = 4;
public static final int EXIT = 5;
public static final int OBJECTIVE = 6;
public static final int OBJECTIVE_HOLD = 7;
public static final int OBJECTIVE_GE = 8;
public static final int OBJECTIVE_US = 9;
public Terrain terrain;
public int roads;
public String toString()
{
return String.format("(%d;%d) [%f;%f] t:%s r:%d", col, row, x, y, terrain, roads);
}
public String toShort()
{
return String.format("(%d;%d)", col, row);
}
public Hex(float x, float y, int col, int row, TextureAtlas atlas, Army defaultArmy)
{
super(x, y, col, row, atlas, defaultArmy);
this.terrain = Terrain.CLEAR;
this.roads = 0;
}
public Unit getUnit()
{
return (Unit) stack.peekFirst();
}
@Override
public boolean isA(TileTerrain terrain)
{
return (this.terrain == terrain);
}
@Override
public boolean isOffMap()
{
return isA(Terrain.OFFMAP);
}
@Override
public boolean blockLineOfSight(Tile from, Tile to)
{
if (isA(Terrain.DEPRESSION))
return false;
if (isA(Terrain.CLEAR) && (!hasUnits() || from.isA(Terrain.HILLS) || to.isA(Terrain.HILLS)))
return false;
return true;
}
@Override
public boolean atLeastOneMove(Pawn pawn)
{
if (hasUnits() || isA(Terrain.BLOCKED) || isA(Terrain.OFFMAP))
return false;
return true;
}
@Override
public boolean road(Orientation side)
{
return (side.s == (roads & side.s));
}
@Override
public int exitCost()
{
return 1;
}
@Override
public int costFrom(Pawn pawn, Orientation side)
{
if (side == Orientation.KEEP) return 0;
if (hasUnits()) return (Integer.MAX_VALUE / 2);
if (road(side)) return 1;
int c = 0;
switch(terrain) {
case CLEAR:
case HILLS:
c = 1;
break;
case WOODS:
case TOWN:
c = 2;
break;
case OFFMAP:
case BLOCKED:
c = (Integer.MAX_VALUE / 2);
break;
}
return c;
}
@Override
public int defense()
{
return (isA(Terrain.TOWN) ? 1 : 0);
}
}
|