1 #ifdef _WIN32
2 #include "windows.h"
3 #endif
4
5 #include "string.h"
6 #include "stdio.h"
7 #include "math.h"
8
9 #include "GL/gl.h"
10 #include "GL/glu.h"
11 #include "GL/glut.h"
12 #include "SDL/SDL.h"
13 #include "SDL/SDL_mixer.h"
14
15 #include "list.h"
16 #include "vector.h"
17 #include "cmc.h"
18 #include "3dobject.h"
19 #include "shadow3dobject.h"
20 #include "piece3dobject.h"
21 #include "myglutaux.h"
22 #include "nether.h"
23
24 #include "glprintf.h"
25
26
27 extern int frames_per_sec;
28 extern int shadows;
29 extern bool sound;
30 extern int up_key,down_key,left_key,right_key,fire_key;
31
32
construction_draw(int width,int height)33 void NETHER::construction_draw(int width,int height)
34 {
35 float lightpos2[4]={0,0,1000,1};
36 float tmpls[4]={1.0F,1.0F,1.0F,1.0};
37 float tmpld[4]={0.6F,0.6F,0.6F,1.0};
38 float tmpla[4]={0.1F,0.1F,0.1F,1.0};
39
40 /* Enable Lights, etc.: */
41 // glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
42 glEnable(GL_LIGHT0);
43 glLightfv(GL_LIGHT0,GL_AMBIENT,tmpla);
44 glLightfv(GL_LIGHT0,GL_DIFFUSE,tmpld);
45 glLightfv(GL_LIGHT0,GL_SPECULAR,tmpls);
46 glLightfv(GL_LIGHT0,GL_POSITION,lightpos2);
47 glEnable(GL_LIGHTING);
48 glEnable(GL_COLOR_MATERIAL);
49 glShadeModel( GL_SMOOTH );
50 glCullFace( GL_BACK );
51 glFrontFace( GL_CCW );
52 glEnable( GL_CULL_FACE );
53 glDisable( GL_SCISSOR_TEST );
54 glEnable( GL_DEPTH_TEST );
55 glDisable(GL_BLEND);
56
57 /* Draw the CONSTRUCTION screen: */
58 glClearColor(0,0,0.0,0);
59 glViewport(0,0,width,height);
60 glMatrixMode( GL_PROJECTION );
61 glLoadIdentity( );
62 gluPerspective( 30.0, float(width)/float(height), 1.0, 1024.0 );
63 gluLookAt(0,0,64,0,0,0,0,1,0);
64
65 /* Clear the color and depth buffers. */
66 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
67
68 glMatrixMode(GL_MODELVIEW);
69 glLoadIdentity();
70
71 glPushMatrix();
72 glColor3f(1.0f,1.0f,0.0);
73 glTranslatef(-12,5,0);
74 scaledglprintf(0.01f,0.01f,"-- RESOURCES --");
75 glTranslatef(0,-1.4,0);
76 scaledglprintf(0.01f,0.01f,"-- AVAILABLE --");
77
78 {
79 int i,total=0;
80 int res[7];
81
82 RobotCost(0,&in_construction,res);
83 for(i=0;i<7;i++) res[i]=resources[0][i]-res[i];
84
85 glColor3f(0.5f,1.0f,0.5f);
86 glTranslatef(0,-2.4,0);
87 scaledglprintf(0.01f,0.01f," GENERAL %.2i",res[0]);
88 glTranslatef(0,-2.4,0);
89 scaledglprintf(0.01f,0.01f,"ELECTRONICS %.2i",res[1]);
90 glTranslatef(0,-1.4,0);
91 scaledglprintf(0.01f,0.01f," NUCLEAR %.2i",res[2]);
92 glTranslatef(0,-1.4,0);
93 scaledglprintf(0.01f,0.01f," PHASERS %.2i",res[3]);
94 glTranslatef(0,-1.4,0);
95 scaledglprintf(0.01f,0.01f," MISSILES %.2i",res[4]);
96 glTranslatef(0,-1.4,0);
97 scaledglprintf(0.01f,0.01f," CANNON %.2i",res[5]);
98 glTranslatef(0,-1.4,0);
99 scaledglprintf(0.01f,0.01f," CHASSIS %.2i",res[6]);
100
101 for(i=0;i<7;i++) total+=res[i];
102
103 glTranslatef(0,-2.4,0);
104 scaledglprintf(0.01f,0.01f," TOTAL %.2i",total);
105 }
106
107 glColor3f(0.3f,0.8f,1.0f);
108 glTranslatef(0,-3,0);
109 scaledglprintf(0.01f,0.01f," EXIT START");
110 glTranslatef(0,-1.4,0);
111 scaledglprintf(0.01f,0.01f," MENU ROBOT");
112 glPopMatrix();
113
114 glPushMatrix();
115 glTranslatef(-10,12,0);
116 {
117 float angle=float(sin(animation_timer/2)*10);
118 float angle2=float(sin(animation_timer/4)*15);
119 glRotatef(angle2-10,1,0,0);
120 glRotatef(angle,0,1,0);
121 animation_timer+=0.02;
122 }
123 construction_tile[0]->draw(0.5f,0.5f,0.5f);
124 glTranslatef(0.0,-1.1,1);
125 construction_tile[1]->draw(0.8f,0.8f,0.8f);
126 glTranslatef(0.0,2.2,0);
127 construction_tile[2]->draw(0.8f,0.8f,0.8f);
128 glPopMatrix();
129
130 glPushMatrix();
131 glColor3f(1.0f,0.0f,0.0f);
132 glTranslatef(12,15,0);
133 in_construction.cmc=RobotCMC(&in_construction,0);
134 if (RobotCollision(&in_construction,true)) {
135 if ((int(animation_timer*4)%2)==0) scaledglprintf(0.01f,0.01f,"ENTRANCE BLOCKED!");
136 } /* if */
137
138 glColor3f(0.3f,0.8f,1.0f);
139 glTranslatef(3,-3,0);
140 scaledglprintf(0.01f,0.01f,"ELECTRONICS");
141 glTranslatef(0,-3.5,0);
142 scaledglprintf(0.01f,0.01f,"NUCLEAR");
143 glTranslatef(0,-3.5,0);
144 scaledglprintf(0.01f,0.01f,"PHASERS");
145 glTranslatef(0,-3.5,0);
146 scaledglprintf(0.01f,0.01f,"MISSILES");
147 glTranslatef(0,-3.5,0);
148 scaledglprintf(0.01f,0.01f,"CANNON");
149 glTranslatef(0,-3.5,0);
150 scaledglprintf(0.01f,0.01f,"ANTI-GRAV");
151 glTranslatef(0,-3.5,0);
152 scaledglprintf(0.01f,0.01f,"TRACKS");
153 glTranslatef(0,-3.5,0);
154 scaledglprintf(0.01f,0.01f,"BIPOD");
155 glPopMatrix();
156
157 glPushMatrix();
158 glColor3f(0.8f,0.3f,1.0f);
159 glTranslatef(15,10.6,0);
160 scaledglprintf(0.01f,0.01f,"3");
161 glTranslatef(0,-3.5,0);
162 scaledglprintf(0.01f,0.01f,"20");
163 glTranslatef(0,-3.5,0);
164 scaledglprintf(0.01f,0.01f,"4");
165 glTranslatef(0,-3.5,0);
166 scaledglprintf(0.01f,0.01f,"4");
167 glTranslatef(0,-3.5,0);
168 scaledglprintf(0.01f,0.01f,"2");
169 glTranslatef(0,-3.5,0);
170 scaledglprintf(0.01f,0.01f,"10");
171 glTranslatef(0,-3.5,0);
172 scaledglprintf(0.01f,0.01f,"5");
173 glTranslatef(0,-3.5,0);
174 scaledglprintf(0.01f,0.01f,"3");
175 glPopMatrix();
176
177 {
178 int i;
179 for(i=0;i<8;i++) {
180 glPushMatrix();
181 glTranslatef(6,-(13.5-i*3.5),0);
182 glScalef(2.4,2.4,2.4);
183 glRotatef(30,1,0,0);
184 glRotatef(animation_timer*32,0,1,0);
185 glRotatef(-90,1,0,0);
186 if (construction[i]) piece_tile[0][i]->draw_notexture(1.0,1.0,1.0);
187 else piece_tile[0][i]->draw_notexture(0.5,0.5,0.5);
188 glPopMatrix();
189 } /* for */
190
191 glPushMatrix();
192 glTranslatef(0,-8,0);
193 glScalef(4.0f,4.0f,4.0f);
194 glRotatef(30,1,0,0);
195 glRotatef(animation_timer*32,0,1,0);
196 glRotatef(-90,1,0,0);
197 DrawRobot(&in_construction,0,false);
198 glPopMatrix();
199 }
200
201 glPushMatrix();
202 glColor3f(0.75f,0.0,0.0);
203 if (construction_pointer==0) {
204 glTranslatef(-14,-14,-1);
205 glutSolidBox(3,2,0.5);
206 } /* if */
207 if (construction_pointer==10) {
208 glTranslatef(-7,-14,-1);
209 glutSolidBox(3,2,0.5);
210 } /* if */
211 if (construction_pointer==20) {
212 glTranslatef(15.3,-13,-1);
213 glutSolidBox(6,1.7,0.5);
214 } /* if */
215 if (construction_pointer==21) {
216 glTranslatef(15.3,-9.2,-1);
217 glutSolidBox(6,1.7,0.5);
218 } /* if */
219 if (construction_pointer==22) {
220 glTranslatef(15.3,-5.7,-1);
221 glutSolidBox(6,1.7,0.5);
222 } /* if */
223 if (construction_pointer==23) {
224 glTranslatef(15.3,-2.2,-1);
225 glutSolidBox(6,1.7,0.5);
226 } /* if */
227 if (construction_pointer==24) {
228 glTranslatef(15.3,1.2,-1);
229 glutSolidBox(6,1.7,0.5);
230 } /* if */
231 if (construction_pointer==25) {
232 glTranslatef(15.3,4.7,-1);
233 glutSolidBox(6,1.7,0.5);
234 } /* if */
235 if (construction_pointer==26) {
236 glTranslatef(15.3,8.2,-1);
237 glutSolidBox(6,1.7,0.5);
238 } /* if */
239 if (construction_pointer==27) {
240 glTranslatef(15.3,12,-1);
241 glutSolidBox(6,1.7,0.5);
242 } /* if */
243 glPopMatrix();
244
245 } /* NETHER::construction_draw */
246
247
248
construction_cycle(unsigned char * keyboard)249 bool NETHER::construction_cycle(unsigned char *keyboard)
250 {
251 if (construction_pointer==10 && keyboard[right_key] && !old_keyboard[right_key]) construction_pointer=20;
252 if (construction_pointer==0 && keyboard[right_key] && !old_keyboard[right_key]) construction_pointer=10;
253
254 if (construction_pointer==10 && keyboard[left_key] && !old_keyboard[left_key]) construction_pointer=0;
255 if (construction_pointer>=20 && keyboard[left_key] && !old_keyboard[left_key]) construction_pointer=10;
256
257 if (construction_pointer>=20 && construction_pointer<27 &&
258 keyboard[up_key] && !old_keyboard[up_key]) construction_pointer++;
259 if (construction_pointer>20 && construction_pointer<=27 &&
260 keyboard[down_key] && !old_keyboard[down_key]) construction_pointer--;
261
262 if (construction_pointer>=20 && keyboard[fire_key] && !old_keyboard[fire_key]) {
263 int i;
264 int cost[7];
265 bool tmp[8];
266 ROBOT r_tmp;
267 bool enoughresources=true;
268
269 r_tmp=in_construction;
270 for(i=0;i<8;i++) tmp[i]=construction[i];
271
272 if (construction[construction_pointer-20]) {
273 if (construction_pointer<=22) in_construction.traction=-1;
274 if (construction_pointer>=23) in_construction.pieces[construction_pointer-23]=false;
275 construction[construction_pointer-20]=false;
276 } else {
277 if (construction_pointer<=22) {
278 in_construction.traction=construction_pointer-20;
279 construction[0]=false;
280 construction[1]=false;
281 construction[2]=false;
282 } /* if */
283 if (construction_pointer>=23) in_construction.pieces[construction_pointer-23]=true;
284 construction[construction_pointer-20]=true;
285 } /* if */
286
287 RobotCost(0,&in_construction,cost);
288 enoughresources=true;
289 for(i=0;i<7;i++) {
290 if (resources[0][i]<cost[i]) {
291 int j;
292 /* Not enough resources! */
293 for(j=0;j<8;j++) {
294 in_construction=r_tmp;
295 construction[j]=tmp[j];
296 } /* for */
297 enoughresources=false;
298 } /* if */
299 } /* for */
300
301 if (enoughresources) {
302 if (S_select!=0 && sound) Mix_Volume(Mix_PlayChannel(-1,S_select,0),128);
303 } else {
304 if (S_wrong!=0 && sound) Mix_Volume(Mix_PlayChannel(-1,S_wrong,0),128);
305 } /* if */
306 } /* if */
307
308 if (construction_pointer==0 && keyboard[fire_key] && !old_keyboard[fire_key]) {
309 game_state=STATE_PLAYING;
310 shipp.z=2.0;
311 } /* if */
312
313 if (construction_pointer==10 && keyboard[fire_key] && !old_keyboard[fire_key]) {
314 if (in_construction.valid()) {
315 int i;
316 int cost[7];
317
318 /* Valid robot, build it: */
319 ROBOT *r;
320 r=new ROBOT();
321 *r=in_construction;
322 r->angle=0;
323 r->program=PROGRAM_FORWARD;
324 r->op=ROBOTOP_NONE;
325 r->cmc=RobotCMC(r,0);
326 r->shipover=false;
327
328 if (!RobotCollision(r,true)) {
329 robots[0].Add(r);
330 AI_newrobot(r->pos,0);
331
332 RobotCost(0,&in_construction,cost);
333 for(i=0;i<7;i++) resources[0][i]-=cost[i];
334
335 game_state=STATE_PLAYING;
336 shipp.z=2.0;
337 if (S_construction!=0 && sound) Mix_Volume(Mix_PlayChannel(-1,S_construction,0),128);
338 } else {
339 /* The factory entrance is blocked: */
340 delete r;
341 } /* if */
342 } else {
343 /* Wrong robot: */
344 if (S_wrong!=0 && sound) Mix_Volume(Mix_PlayChannel(-1,S_wrong,0),128);
345 } /* if */
346 } /* if */
347
348 redrawmenu=2;
349 redrawradar=1;
350 return true;
351 } /* NETHER::construction_cycle */
352
353
354