1 package cz.cuni.amis.pogamut.defcon.communication.worldview.modules.grid.basic;
2
3 import cz.cuni.amis.pogamut.base3d.worldview.object.Location;
4 import cz.cuni.amis.pogamut.defcon.agent.module.sensor.GameInfo;
5 import cz.cuni.amis.pogamut.defcon.communication.worldview.modules.grid.IGridCell;
6 import cz.cuni.amis.pogamut.defcon.communication.worldview.modules.grid.IGridCellId;
7 import cz.cuni.amis.pogamut.defcon.communication.worldview.modules.grid.flags.BasicFlag;
8 import cz.cuni.amis.pogamut.defcon.consts.UnitType;
9
10
11
12
13
14
15
16 public class SymmetricGridCell implements IGridCell {
17
18
19
20
21
22
23 protected SymmetricGridCellId cellId;
24
25
26
27
28
29
30 protected static GameInfo gameInfo;
31
32 public static void setGameInfo(GameInfo gameInfo) {
33 SymmetricGridCell.gameInfo = gameInfo;
34 }
35
36 public SymmetricGridCell(SymmetricGridCellId cellId) {
37 this.cellId = cellId;
38 }
39
40 public SymmetricGridCell(float x, float y) {
41 cellId = new SymmetricGridCellId(x, y);
42 }
43
44
45
46
47
48
49
50
51
52
53
54 @Override
55 public boolean hasFlag(BasicFlag flag) {
56 return hasFlag(cellId.getX(), cellId.getY(), flag);
57 }
58
59 public static boolean hasFlag(Location location, BasicFlag flag) {
60 return location != null
61 && hasFlag(
62 (float) location.getX(),
63 (float) location.getY(),
64 flag);
65 }
66
67 public static boolean hasFlag(float x, float y, BasicFlag flag) {
68
69 if (x < -180f || x > 180f || y < -90f || y > 90f)
70 return false;
71
72 switch (flag) {
73 case SEA:
74 return gameInfo.isValidTerritory(-1, x, y, true);
75 case LAND:
76 return gameInfo.isValidTerritory(-1, x, y, false);
77 case OWN_TERRITORY: {
78 int id = gameInfo.getOwnTeamId();
79 return gameInfo.isValidTerritory(id, x, y, false)
80 || gameInfo.isValidTerritory(id, x, y, true);
81 }
82 case ENEMY_TERRITORY: {
83 Boolean ok = false;
84 for (int id : gameInfo.getEnemyTeamIds()) {
85 if (ok = gameInfo.isValidTerritory(id, x, y, false) ||
86 gameInfo.isValidTerritory(id, x, y, true))
87 break;
88 }
89 return ok;
90 }
91 case OWN_PLACEABLE_LAND: {
92 return gameInfo.isValidPlacementLocation(x, y, UnitType.RADAR);
93 }
94 case OWN_PLACEABLE_SEA:
95 return gameInfo.isValidPlacementLocation(
96 x, y, UnitType.BATTLE_SHIP);
97 }
98 return false;
99 }
100
101
102
103
104
105
106
107 /*
108 * @Override public boolean removeFlag(IGridCellFlag flag) { return
109 * complexFlags.remove(flag); }
110 */
111 @Override
112 public IGridCellId getCellId() {
113 return cellId;
114 }
115
116
117
118
119 }