-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathdeployGrid.java
More file actions
206 lines (159 loc) · 8.18 KB
/
deployGrid.java
File metadata and controls
206 lines (159 loc) · 8.18 KB
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
package gui;
import core.*;
import entity.constructionYard;
import entity.solidObject;
public class deployGrid {
public polygon3D[] polygons;
public boolean canBeDeployed;
public int[] gridArea;
public vector gridOneCenter;
public vector iDirection, jDirection, kDirection, start;
public vector clickPoint;
public constructionYard cy;
public int gridOneIndex;
public deployGrid(){
gridArea = new int[9];
iDirection = new vector(1,0,0);
jDirection = new vector(0,1,0);
kDirection = new vector(0,0,1);
start = new vector(0,0,0);
clickPoint = new vector(0,0,0);
makeGrid();
}
public void makeGrid(){
polygons = new polygon3D[9];
double w = 0;
double h = 0;
vector[] v = new vector[]{put(-0.1 + w, -0.5, 0.12 + h), put(0.1 + w, -0.5, 0.12 + h), put(0.12 + w, -0.5, 0.1 + h), put(0.12 + w, -0.5, -0.1 + h), put(0.1 + w, -0.5, -0.12 + h), put(-0.1 + w, -0.5, -0.12 + h), put(-0.12 + w, -0.5, -0.1 + h), put(-0.12 + w, -0.5, 0.1 + h)};
polygons[0] = new polygon3D(v, v[0], v[1], v [3], null, 1f,1f,10);
w = 0.25;
h = 0;
v = new vector[]{put(-0.1 + w, -0.5, 0.12 + h), put(0.1 + w, -0.5, 0.12 + h), put(0.12 + w, -0.5, 0.1 + h), put(0.12 + w, -0.5, -0.1 + h), put(0.1 + w, -0.5, -0.12 + h), put(-0.1 + w, -0.5, -0.12 + h), put(-0.12 + w, -0.5, -0.1 + h), put(-0.12 + w, -0.5, 0.1 + h)};
polygons[1] = new polygon3D(v, v[0], v[1], v [3], null, 1f,1f,10);
w = 0.5;
h = 0;
v = new vector[]{put(-0.1 + w, -0.5, 0.12 + h), put(0.1 + w, -0.5, 0.12 + h), put(0.12 + w, -0.5, 0.1 + h), put(0.12 + w, -0.5, -0.1 + h), put(0.1 + w, -0.5, -0.12 + h), put(-0.1 + w, -0.5, -0.12 + h), put(-0.12 + w, -0.5, -0.1 + h), put(-0.12 + w, -0.5, 0.1 + h)};
polygons[2] = new polygon3D(v, v[0], v[1], v [3], null, 1f,1f,10);
w = 0;
h = -0.25;
v = new vector[]{put(-0.1 + w, -0.5, 0.12 + h), put(0.1 + w, -0.5, 0.12 + h), put(0.12 + w, -0.5, 0.1 + h), put(0.12 + w, -0.5, -0.1 + h), put(0.1 + w, -0.5, -0.12 + h), put(-0.1 + w, -0.5, -0.12 + h), put(-0.12 + w, -0.5, -0.1 + h), put(-0.12 + w, -0.5, 0.1 + h)};
polygons[3] = new polygon3D(v, v[0], v[1], v [3], null, 1f,1f,10);
w = 0.25;
h = -0.25;
v = new vector[]{put(-0.1 + w, -0.5, 0.12 + h), put(0.1 + w, -0.5, 0.12 + h), put(0.12 + w, -0.5, 0.1 + h), put(0.12 + w, -0.5, -0.1 + h), put(0.1 + w, -0.5, -0.12 + h), put(-0.1 + w, -0.5, -0.12 + h), put(-0.12 + w, -0.5, -0.1 + h), put(-0.12 + w, -0.5, 0.1 + h)};
polygons[4] = new polygon3D(v, v[0], v[1], v [3], null, 1f,1f,10);
w = 0.5;
h = -0.25;
v = new vector[]{put(-0.1 + w, -0.5, 0.12 + h), put(0.1 + w, -0.5, 0.12 + h), put(0.12 + w, -0.5, 0.1 + h), put(0.12 + w, -0.5, -0.1 + h), put(0.1 + w, -0.5, -0.12 + h), put(-0.1 + w, -0.5, -0.12 + h), put(-0.12 + w, -0.5, -0.1 + h), put(-0.12 + w, -0.5, 0.1 + h)};
polygons[5] = new polygon3D(v, v[0], v[1], v [3], null, 1f,1f,10);
w = 0;
h = -0.5;
v = new vector[]{put(-0.1 + w, -0.5, 0.12 + h), put(0.1 + w, -0.5, 0.12 + h), put(0.12 + w, -0.5, 0.1 + h), put(0.12 + w, -0.5, -0.1 + h), put(0.1 + w, -0.5, -0.12 + h), put(-0.1 + w, -0.5, -0.12 + h), put(-0.12 + w, -0.5, -0.1 + h), put(-0.12 + w, -0.5, 0.1 + h)};
polygons[6] = new polygon3D(v, v[0], v[1], v [3], null, 1f,1f,10);
w = 0.25;
h = -0.5;
v = new vector[]{put(-0.1 + w, -0.5, 0.12 + h), put(0.1 + w, -0.5, 0.12 + h), put(0.12 + w, -0.5, 0.1 + h), put(0.12 + w, -0.5, -0.1 + h), put(0.1 + w, -0.5, -0.12 + h), put(-0.1 + w, -0.5, -0.12 + h), put(-0.12 + w, -0.5, -0.1 + h), put(-0.12 + w, -0.5, 0.1 + h)};
polygons[7] = new polygon3D(v, v[0], v[1], v [3], null, 1f,1f,10);
w = 0.5;
h = -0.5;
v = new vector[]{put(-0.1 + w, -0.5, 0.12 + h), put(0.1 + w, -0.5, 0.12 + h), put(0.12 + w, -0.5, 0.1 + h), put(0.12 + w, -0.5, -0.1 + h), put(0.1 + w, -0.5, -0.12 + h), put(-0.1 + w, -0.5, -0.12 + h), put(-0.12 + w, -0.5, -0.1 + h), put(-0.12 + w, -0.5, 0.1 + h)};
polygons[8] = new polygon3D(v, v[0], v[1], v [3], null, 1f,1f,10);
for(int i = 0; i < 9; i++)
polygons[i].color = 31 << 5;
gridOneCenter = new vector(0,0,0);
}
public void update(){
cy = mainThread.pc.selectedConstructionYard;
clickPoint.set(mainThread.my2Dto3DFactory.get3DLocation(mainThread.theAssetManager.Terrain.ground[0], inputHandler.mouse_x, inputHandler.mouse_y));
gridOneIndex = (int)(clickPoint.x*4) + (127 - (int)(clickPoint.z*4))*128;
clickPoint.x = (float)((int)(clickPoint.x*4))/4 + 0.125f;
clickPoint.z = (float)((int)(clickPoint.z*4))/4 + 0.125f;
float dx = clickPoint.x - gridOneCenter.x;
float dz = clickPoint.z - gridOneCenter.z;
for(int i = 0; i < 9; i++){
for(int j = 0; j < 8; j++){
polygons[i].vertex3D[j].x+=dx;
polygons[i].vertex3D[j].z+=dz;
}
}
gridOneCenter.x = clickPoint.x;
gridOneCenter.z = clickPoint.z;
if(cy != null){
canBeDeployed = true;
if(cy.powerPlantProgress == 240 || cy.communicationCenterProgress == 240 || cy.techCenterProgress == 240){
gridArea[0] = 1; if(!checkIfBlockIsFree(gridOneIndex)){ gridArea[0] = 2; canBeDeployed = false;}
gridArea[1] = 1; if(!checkIfBlockIsFree(gridOneIndex+1)){ gridArea[1] = 2; canBeDeployed = false;}
gridArea[2] = 0;
gridArea[3] = 1; if(!checkIfBlockIsFree(gridOneIndex + 128)){ gridArea[3] = 2; canBeDeployed = false;}
gridArea[4] = 1; if(!checkIfBlockIsFree(gridOneIndex + 129)){ gridArea[4] = 2; canBeDeployed = false;}
gridArea[5] = 0;
gridArea[6] = 0;
gridArea[7] = 0;
gridArea[8] = 0;
}else if(cy.refineryProgress == 240 || cy.factoryProgress == 240){
gridArea[0] = 1; if(!checkIfBlockIsFree(gridOneIndex)){ gridArea[0] = 2; canBeDeployed = false;}
gridArea[1] = 1; if(!checkIfBlockIsFree(gridOneIndex+1)){ gridArea[1] = 2; canBeDeployed = false;}
gridArea[2] = 1; if(!checkIfBlockIsFree(gridOneIndex+2)){ gridArea[2] = 2; canBeDeployed = false;}
gridArea[3] = 1; if(!checkIfBlockIsFree(gridOneIndex + 128)){ gridArea[3] = 2; canBeDeployed = false;}
gridArea[4] = 1; if(!checkIfBlockIsFree(gridOneIndex + 129)){ gridArea[4] = 2; canBeDeployed = false;}
gridArea[5] = 1; if(!checkIfBlockIsFree(gridOneIndex + 130)){ gridArea[5] = 2; canBeDeployed = false;}
gridArea[6] = 1; if(!checkIfBlockIsFree(gridOneIndex + 256)){ gridArea[6] = 2; canBeDeployed = false;}
gridArea[7] = 1; if(!checkIfBlockIsFree(gridOneIndex + 257)){ gridArea[7] = 2; canBeDeployed = false;}
gridArea[8] = 1; if(!checkIfBlockIsFree(gridOneIndex + 258)){ gridArea[8] = 2; canBeDeployed = false;}
}else if(cy.gunTurretProgress == 240 || cy.missileTurretProgress == 240){
gridArea[0] = 1; if(!checkIfBlockIsFree(gridOneIndex)){ gridArea[0] = 2; canBeDeployed = false;}
gridArea[1] = 0;
gridArea[2] = 0;
gridArea[3] = 0;
gridArea[4] = 0;
gridArea[5] = 0;
gridArea[6] = 0;
gridArea[7] = 0;
gridArea[8] = 0;
}
}
}
public void draw(){
for(int i = 0; i < 9; i++){
if(gridArea[i] >= 1){
polygons[i].update();
if(gridArea[i] == 1)
polygons[i].color = 31 << 5;
else
polygons[i].color = 31 << 10;
polygons[i].draw();
}
}
}
public boolean checkIfBlockIsFree(int index){
int y = index/128;
int x = index%128;
if(y > 0 && y < 127 && x > 0 && x < 127){
solidObject[] tile = mainThread.gridMap.tiles[index];
for(int j = 0; j < 5; j++){
if(tile[j] != null){
return false;
}
}
constructionYard[] cys = mainThread.theAssetManager.constructionYards;
for(int i = 0; i < cys.length; i++){
if(cys[i] != null && cys[i].teamNo == 0){
float xPos = x * 0.25f + 0.125f;
float yPos = (127 - y)*0.25f + 0.125f;
float distance = (float) Math.sqrt((cys[i].centre.x - xPos)*(cys[i].centre.x - xPos) + (cys[i].centre.z - yPos)*(cys[i].centre.z - yPos));
if(distance <= 2.75)
return true;
}
}
}
return false;
}
//create a arbitrary vertex
public vector put(double i, double j, double k){
vector temp = start.myClone();
temp.add(iDirection, (float)i);
temp.add(jDirection, (float)j);
temp.add(kDirection, (float)k);
return temp;
}
}