1 /*
2  * GameInitDispose.cpp
3  * Copyright (C) 2007 by Bryan Duff <duff0097@gmail.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA
19  */
20 #include <ctype.h>
21 #include <time.h>
22 
23 #include "Weapon.h"
24 #include "Game.h"
25 
26 extern unsigned int gSourceID[100];
27 
28 extern unsigned int gSampleSet[100];
29 
30 extern Camera camera;
31 extern Skeleton testskeleton;
32 extern Sprites sprites;
33 extern Decals decals;
34 extern Environment environment;
35 extern Config config;
36 extern Font font;
37 
38 /*********************> InitGame()<*****/
39 
40 extern Model skeletonmodels[10];
41 extern Model gunmodels[10];
42 extern Costume costume[10];
43 extern Animation animation[30];
44 extern Fog fog;
45 extern Mission mission;
46 
47 extern bool blood;
48 
49 extern float soundscalefactor;
50 
51 extern int slomo;
52 
53 extern int forwardskey;
54 extern int backwardskey;
55 extern int leftkey;
56 extern int rightkey;
57 extern int aimkey;
58 extern int psychicaimkey;
59 extern int psychickey;
60 extern int helpkey;
61 
62 void LoadSounds(bool musictoggle);
63 
LoadSounds(bool musictoggle)64 void LoadSounds(bool musictoggle)
65 {
66   char *pBuffer1;
67   long lBuffer1Len;
68 
69   ALenum formatBuffer1;
70   ALsizei freqBuffer1;
71   SInt16 iNumSources, iNumSampleSets;
72 
73   // initialize OpenAL
74   alutInit(NULL, 0);
75 
76   // load up some audio data...
77 
78   // generate ten OpenAL sample sets and two sources
79   iNumSources = 37;
80   iNumSampleSets = 37;
81 
82   alGenSources(iNumSources, &gSourceID[0]);
83   alGenBuffers(iNumSampleSets, &gSampleSet[0]);
84 
85 #ifdef NOOGG
86 
87 #define loadwav(file, sound) do {\
88   alutLoadWAVFile((char *)file, &formatBuffer1, \
89                   (void **)&pBuffer1, (unsigned int *)&lBuffer1Len, \
90                   &freqBuffer1); \
91   alBufferData(gSampleSet[sound], formatBuffer1, pBuffer1, lBuffer1Len, \
92                freqBuffer1); \
93   alSourcei(gSourceID[sound], AL_BUFFER, gSampleSet[sound]); \
94   alutUnloadWAV(formatBuffer1, pBuffer1, lBuffer1Len, freqBuffer1); \
95   } while(0)
96 
97   loadwav(":Data:Sounds:underwater.wav", visionsound);
98   loadwav(":Data:Sounds:soulin.wav", soulinsound);
99   loadwav(":Data:Sounds:soulout.wav", souloutsound);
100   loadwav(":Data:Sounds:footstep1.wav", footstepsound);
101   loadwav(":Data:Sounds:footstep2.wav", footstepsound + 1);
102   loadwav(":Data:Sounds:footstep3.wav", footstepsound + 2);
103   loadwav(":Data:Sounds:footstep4.wav", footstepsound + 3);
104   loadwav(":Data:Sounds:footstep5.wav", footstepsound + 4);
105   loadwav(":Data:Sounds:bodyland.wav", bodylandsound);
106   loadwav(":Data:Sounds:headland.wav", headlandsound);
107   loadwav(":Data:Sounds:sniperrifle.wav", riflesound);
108   loadwav(":Data:Sounds:BodyHit.wav", bodyhitsound);
109   loadwav(":Data:Sounds:WallHit.wav", wallhitsound);
110   loadwav(":Data:Sounds:machinegun.wav", machinegunsound);
111   loadwav(":Data:Sounds:Nearbullet.wav", nearbulletsound);
112   loadwav(":Data:Sounds:riflewhack.wav", headwhacksound);
113   loadwav(":Data:Sounds:headshot.wav", headshotsound);
114   loadwav(":Data:Sounds:reload.wav", reloadsound);
115   loadwav(":Data:Sounds:click.wav", clicksound);
116   loadwav(":Data:Sounds:SW.wav", pistol1sound);
117   loadwav(":Data:Sounds:glock.wav", pistol2sound);
118   loadwav(":Data:Sounds:pinpull.wav", pinpullsound);
119   loadwav(":Data:Sounds:pinreplace.wav", pinreplacesound);
120   loadwav(":Data:Sounds:handlerelease.wav", grenadethrowsound);
121   loadwav(":Data:Sounds:bounce.wav", bouncesound);
122   loadwav(":Data:Sounds:bounce2.wav", bounce2sound);
123   loadwav(":Data:Sounds:explosion.wav", explosionsound);
124   loadwav(":Data:Sounds:headland.wav", bodywhacksound);
125   loadwav(":Data:Sounds:rain.wav", rainsound);
126   loadwav(":Data:Sounds:Lose.wav", losesound);
127   loadwav(":Data:Sounds:Disguisekill.wav", disguisekillsound);
128   loadwav(":Data:Sounds:knifeslash.wav", knifeslashsound);
129   loadwav(":Data:Sounds:shotgun.wav", shotgunsound);
130 
131   if(musictoggle) {
132     loadwav(":Data:Sounds:mainmenusong.wav", mainmenusong);
133     loadwav(":Data:Sounds:shootsong.wav", shootsong);
134     loadwav(":Data:Sounds:zombiesong.wav", zombiesong);
135     loadwav(":Data:Sounds:knifesong.wav", knifesong);
136   }
137 #else
138 
139 #define loadogg(file, sound) do {\
140   LoadOGG_CFH((char *)file, &formatBuffer1, \
141               (void **)&pBuffer1, (unsigned int *)&lBuffer1Len, &freqBuffer1); \
142   alBufferData(gSampleSet[sound], formatBuffer1, pBuffer1, lBuffer1Len, \
143                freqBuffer1); \
144   alSourcei(gSourceID[sound], AL_BUFFER, gSampleSet[sound]); \
145   FreeOGG(formatBuffer1, pBuffer1, lBuffer1Len, freqBuffer1); \
146   } while(0)
147 
148   loadogg(":Data:Sounds:underwater.ogg", visionsound);
149   loadogg(":Data:Sounds:soulin.ogg", soulinsound);
150   loadogg(":Data:Sounds:soulout.ogg", souloutsound);
151   loadogg(":Data:Sounds:footstep1.ogg", footstepsound);
152   loadogg(":Data:Sounds:footstep2.ogg", footstepsound + 1);
153   loadogg(":Data:Sounds:footstep3.ogg", footstepsound + 2);
154   loadogg(":Data:Sounds:footstep4.ogg", footstepsound + 3);
155   loadogg(":Data:Sounds:footstep5.ogg", footstepsound + 4);
156   loadogg(":Data:Sounds:bodyland.ogg", bodylandsound);
157   loadogg(":Data:Sounds:headland.ogg", headlandsound);
158   loadogg(":Data:Sounds:sniperrifle.ogg", riflesound);
159   loadogg(":Data:Sounds:BodyHit.ogg", bodyhitsound);
160   loadogg(":Data:Sounds:WallHit.ogg", wallhitsound);
161   loadogg(":Data:Sounds:machinegun.ogg", machinegunsound);
162   loadogg(":Data:Sounds:Nearbullet.ogg", nearbulletsound);
163   loadogg(":Data:Sounds:riflewhack.ogg", headwhacksound);
164   loadogg(":Data:Sounds:headshot.ogg", headshotsound);
165   loadogg(":Data:Sounds:reload.ogg", reloadsound);
166   loadogg(":Data:Sounds:click.ogg", clicksound);
167   loadogg(":Data:Sounds:SW.ogg", pistol1sound);
168   loadogg(":Data:Sounds:glock.ogg", pistol2sound);
169   loadogg(":Data:Sounds:pinpull.ogg", pinpullsound);
170   loadogg(":Data:Sounds:pinreplace.ogg", pinreplacesound);
171   loadogg(":Data:Sounds:handlerelease.ogg", grenadethrowsound);
172   loadogg(":Data:Sounds:bounce.ogg", bouncesound);
173   loadogg(":Data:Sounds:bounce2.ogg", bounce2sound);
174   loadogg(":Data:Sounds:explosion.ogg", explosionsound);
175   loadogg(":Data:Sounds:headland.ogg", bodywhacksound);
176   loadogg(":Data:Sounds:rain.ogg", rainsound);
177   loadogg(":Data:Sounds:Lose.ogg", losesound);
178   loadogg(":Data:Sounds:Disguisekill.ogg", disguisekillsound);
179   loadogg(":Data:Sounds:knifeslash.ogg", knifeslashsound);
180   loadogg(":Data:Sounds:shotgun.ogg", shotgunsound);
181 
182   if(musictoggle) {
183     loadogg(":Data:Sounds:mainmenusong.ogg", mainmenusong);
184     loadogg(":Data:Sounds:shootsong.ogg", shootsong);
185     loadogg(":Data:Sounds:zombiesong.ogg", zombiesong);
186     loadogg(":Data:Sounds:knifesong.ogg", knifesong);
187   }
188 #endif
189 
190   float gLoc[3];
191 
192   gLoc[0] = 0;
193   gLoc[1] = 0;
194   gLoc[2] = 0;
195 
196   alSourcefv(gSourceID[visionsound], AL_POSITION, gLoc);
197   alSourcei(gSourceID[visionsound], AL_LOOPING, 1);
198   alSourcef(gSourceID[visionsound], AL_MIN_GAIN, 1);
199 
200   alSourcefv(gSourceID[soulinsound], AL_POSITION, gLoc);
201   alSourcei(gSourceID[soulinsound], AL_LOOPING, 0);
202   alSourcef(gSourceID[soulinsound], AL_MIN_GAIN, 1);
203 
204   alSourcefv(gSourceID[souloutsound], AL_POSITION, gLoc);
205   alSourcei(gSourceID[souloutsound], AL_LOOPING, 0);
206   alSourcef(gSourceID[souloutsound], AL_MIN_GAIN, 1);
207 
208   for(int i = 0; i < 5; i++) {
209     alSourcefv(gSourceID[footstepsound + i], AL_POSITION, gLoc);
210     alSourcei(gSourceID[footstepsound + i], AL_LOOPING, 0);
211     alSourcef(gSourceID[footstepsound + i], AL_MIN_GAIN, 0);
212   }
213 
214   alSourcefv(gSourceID[bodylandsound], AL_POSITION, gLoc);
215   alSourcei(gSourceID[bodylandsound], AL_LOOPING, 0);
216   alSourcef(gSourceID[bodylandsound], AL_MIN_GAIN, 0);
217 
218   alSourcefv(gSourceID[headlandsound], AL_POSITION, gLoc);
219   alSourcei(gSourceID[headlandsound], AL_LOOPING, 0);
220   alSourcef(gSourceID[headlandsound], AL_MIN_GAIN, 0);
221 
222   alSourcefv(gSourceID[riflesound], AL_POSITION, gLoc);
223   alSourcei(gSourceID[riflesound], AL_LOOPING, 0);
224   alSourcef(gSourceID[riflesound], AL_MIN_GAIN, 0);
225 
226   alSourcefv(gSourceID[bodyhitsound], AL_POSITION, gLoc);
227   alSourcei(gSourceID[bodyhitsound], AL_LOOPING, 0);
228   alSourcef(gSourceID[bodyhitsound], AL_MIN_GAIN, .1);
229 
230   alSourcefv(gSourceID[wallhitsound], AL_POSITION, gLoc);
231   alSourcei(gSourceID[wallhitsound], AL_LOOPING, 0);
232   alSourcef(gSourceID[wallhitsound], AL_MIN_GAIN, 0);
233   alSourcef(gSourceID[wallhitsound], AL_MAX_GAIN, .6);
234 
235   alSourcefv(gSourceID[machinegunsound], AL_POSITION, gLoc);
236   alSourcei(gSourceID[machinegunsound], AL_LOOPING, 0);
237   alSourcef(gSourceID[machinegunsound], AL_MIN_GAIN, 0);
238 
239   alSourcefv(gSourceID[nearbulletsound], AL_POSITION, gLoc);
240   alSourcei(gSourceID[nearbulletsound], AL_LOOPING, 0);
241   alSourcef(gSourceID[nearbulletsound], AL_MIN_GAIN, 0);
242 
243   alSourcefv(gSourceID[headwhacksound], AL_POSITION, gLoc);
244   alSourcei(gSourceID[headwhacksound], AL_LOOPING, 0);
245   alSourcef(gSourceID[headwhacksound], AL_MIN_GAIN, 0);
246 
247   alSourcefv(gSourceID[headshotsound], AL_POSITION, gLoc);
248   alSourcei(gSourceID[headshotsound], AL_LOOPING, 0);
249   alSourcef(gSourceID[headshotsound], AL_MIN_GAIN, 0);
250 
251   alSourcefv(gSourceID[reloadsound], AL_POSITION, gLoc);
252   alSourcei(gSourceID[reloadsound], AL_LOOPING, 0);
253   alSourcef(gSourceID[reloadsound], AL_MIN_GAIN, 0);
254 
255   alSourcefv(gSourceID[clicksound], AL_POSITION, gLoc);
256   alSourcei(gSourceID[clicksound], AL_LOOPING, 0);
257   alSourcef(gSourceID[clicksound], AL_MIN_GAIN, 0);
258 
259   alSourcefv(gSourceID[pistol1sound], AL_POSITION, gLoc);
260   alSourcei(gSourceID[pistol1sound], AL_LOOPING, 0);
261   alSourcef(gSourceID[pistol1sound], AL_MIN_GAIN, 0);
262 
263   alSourcefv(gSourceID[pistol2sound], AL_POSITION, gLoc);
264   alSourcei(gSourceID[pistol2sound], AL_LOOPING, 0);
265   alSourcef(gSourceID[pistol2sound], AL_MIN_GAIN, 0);
266 
267   alSourcefv(gSourceID[pinpullsound], AL_POSITION, gLoc);
268   alSourcei(gSourceID[pinpullsound], AL_LOOPING, 0);
269   alSourcef(gSourceID[pinpullsound], AL_MIN_GAIN, 0);
270 
271   alSourcefv(gSourceID[pinreplacesound], AL_POSITION, gLoc);
272   alSourcei(gSourceID[pinreplacesound], AL_LOOPING, 0);
273   alSourcef(gSourceID[pinreplacesound], AL_MIN_GAIN, 0);
274 
275   alSourcefv(gSourceID[grenadethrowsound], AL_POSITION, gLoc);
276   alSourcei(gSourceID[grenadethrowsound], AL_LOOPING, 0);
277   alSourcef(gSourceID[grenadethrowsound], AL_MIN_GAIN, 0);
278 
279   alSourcefv(gSourceID[bouncesound], AL_POSITION, gLoc);
280   alSourcei(gSourceID[bouncesound], AL_LOOPING, 0);
281   alSourcef(gSourceID[bouncesound], AL_MIN_GAIN, 0);
282 
283   alSourcefv(gSourceID[bounce2sound], AL_POSITION, gLoc);
284   alSourcei(gSourceID[bounce2sound], AL_LOOPING, 0);
285   alSourcef(gSourceID[bounce2sound], AL_MIN_GAIN, 0);
286 
287   alSourcefv(gSourceID[explosionsound], AL_POSITION, gLoc);
288   alSourcei(gSourceID[explosionsound], AL_LOOPING, 0);
289   alSourcef(gSourceID[explosionsound], AL_MIN_GAIN, 0);
290 
291   alSourcefv(gSourceID[bodywhacksound], AL_POSITION, gLoc);
292   alSourcei(gSourceID[bodywhacksound], AL_LOOPING, 0);
293   alSourcef(gSourceID[bodywhacksound], AL_MIN_GAIN, 0);
294 
295   alSourcefv(gSourceID[rainsound], AL_POSITION, gLoc);
296   alSourcei(gSourceID[rainsound], AL_LOOPING, 1);
297   alSourcef(gSourceID[rainsound], AL_MIN_GAIN, .3);
298 
299   alSourcefv(gSourceID[losesound], AL_POSITION, gLoc);
300   alSourcei(gSourceID[losesound], AL_LOOPING, 0);
301   alSourcef(gSourceID[losesound], AL_MIN_GAIN, 1);
302 
303   alSourcefv(gSourceID[disguisekillsound], AL_POSITION, gLoc);
304   alSourcei(gSourceID[disguisekillsound], AL_LOOPING, 0);
305   alSourcef(gSourceID[disguisekillsound], AL_MIN_GAIN, 1);
306 
307   alSourcefv(gSourceID[knifeslashsound], AL_POSITION, gLoc);
308   alSourcei(gSourceID[knifeslashsound], AL_LOOPING, 0);
309   alSourcef(gSourceID[knifeslashsound], AL_MIN_GAIN, 0);
310 
311   alSourcefv(gSourceID[shotgunsound], AL_POSITION, gLoc);
312   alSourcei(gSourceID[shotgunsound], AL_LOOPING, 0);
313   alSourcef(gSourceID[shotgunsound], AL_MIN_GAIN, 0);
314 
315   alSourcefv(gSourceID[knifesong], AL_POSITION, gLoc);
316   alSourcei(gSourceID[knifesong], AL_LOOPING, 1);
317   alSourcef(gSourceID[knifesong], AL_MIN_GAIN, 1);
318 
319   alSourcefv(gSourceID[mainmenusong], AL_POSITION, gLoc);
320   alSourcei(gSourceID[mainmenusong], AL_LOOPING, 1);
321   alSourcef(gSourceID[mainmenusong], AL_MIN_GAIN, 1);
322 
323   alSourcefv(gSourceID[zombiesong], AL_POSITION, gLoc);
324   alSourcei(gSourceID[zombiesong], AL_LOOPING, 1);
325   alSourcef(gSourceID[zombiesong], AL_MIN_GAIN, 1);
326 
327   alSourcefv(gSourceID[shootsong], AL_POSITION, gLoc);
328   alSourcei(gSourceID[shootsong], AL_LOOPING, 1);
329   alSourcef(gSourceID[shootsong], AL_MIN_GAIN, 1);
330 }
331 
332 void LoadPersonSpriteTexture(char *fileName, GLuint * textureid);
333 
LoadPersonSpriteTexture(char * fileName,GLuint * textureid)334 void LoadPersonSpriteTexture(char *fileName, GLuint * textureid)
335 {
336   TGAImageRec *tempTexture;
337   GLuint type;
338 
339   //Load Image
340   tempTexture = LoadTGA(fileName);
341 
342   //Is it valid?
343   if(tempTexture) {
344     //Alpha channel?
345     if(tempTexture->bpp == 24)
346       type = GL_RGB;
347     else
348       type = GL_RGBA;
349 
350     glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
351 
352     glGenTextures(1, textureid);
353 
354     glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
355 
356     glBindTexture(GL_TEXTURE_2D, *textureid);
357 
358     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
359     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
360 
361     gluBuild2DMipmaps(GL_TEXTURE_2D, type, tempTexture->sizeX,
362                       tempTexture->sizeY, type, GL_UNSIGNED_BYTE,
363                       tempTexture->data);
364 
365     free(tempTexture->data);
366     free(tempTexture);
367   }
368 }
369 
InitGame()370 void Game::InitGame()
371 {
372   screenwidth = config.screenwidth;
373   screenheight = config.screenheight;
374 
375   shotcount = 1; //first screenshot
376 
377   //test class is deprecated
378   //needed here for the loading screen
379   text.LoadFontTexture(":Data:Textures:Font.tga");
380   text.BuildFont();
381 
382   //Setup loading screen
383   float loadingscreenamount = 0;
384   float loadingscreenamounttotal = 200;
385 
386   if(initialized)
387     loadingscreenamounttotal = 20;
388 
389   if(!initialized) {
390     LoadingScreen(loadingscreenamount / loadingscreenamounttotal * 100);
391   }
392 
393   //Set up rain and snow
394   environment.precipitationhorz = 60;
395   environment.precipitationvert = 40;
396   environment.precipitationdensity = 25;
397 
398   //Bodyguard stats
399   person[0].playercoords = camera.position;
400   person[0].oldplayercoords = person[0].playercoords;
401   person[0].type = playertype;
402   person[0].existing = 1;
403 
404   for(int i = 0; i < 10; i++) {
405     person[0].reloads[i] = 0;
406   }
407 
408   //Level setup
409   //TODO: add level class
410   if(config.customlevels) {            //Load custom levels
411     nummissions = 1;            //Default level in case of load failure
412 
413     type = randomshoot_type;
414 
415     possiblegun[0] = handgun1;
416     possiblegun[1] = handgun2;
417     possiblegun[2] = shotgun;
418 
419     numpossibleguns = 3;
420 
421     evilprobability = 6;
422 
423     person[0].weapon.type = knife;
424     person[0].reloads[person[0].weapon.type] = 6;
425 
426     if(!gameinprogress)
427       score = 0;
428 
429     timeremaining = 50;
430 
431     difficulty = .8;
432 
433     ifstream ipstream("Data/customlevels.txt");
434 
435     if(!ipstream) {
436       config.customlevels = 0;
437     }
438     ///FIXME: set environment correctly
439     if(ipstream) {
440 
441       ipstream.ignore(256, '\n');       //ignore descriptive text
442 
443       ipstream >> nummissions;
444 
445       for(int j = 0; j < mission + 1; j++) {
446 
447         ipstream.ignore(256, '\n');
448         ipstream.ignore(256, '\n');
449 
450         ipstream >> type;
451 
452         ipstream.ignore(256, '\n');
453         ipstream.ignore(256, '\n');
454 
455         ipstream >> environment.type;
456 
457         ipstream.ignore(256, '\n');
458         ipstream.ignore(256, '\n');
459 
460         ipstream >> numpossibleguns;
461 
462         ipstream.ignore(256, '\n');
463         ipstream.ignore(256, '\n');
464 
465         for(int i = 0; i < numpossibleguns; i++) {
466           ipstream >> possiblegun[i];
467         }
468 
469         ipstream.ignore(256, '\n');
470         ipstream.ignore(256, '\n');
471 
472         ipstream >> evilprobability;
473 
474         ipstream.ignore(256, '\n');
475         ipstream.ignore(256, '\n');
476 
477         ipstream >> person[0].weapon.type;
478 
479         ipstream.ignore(256, '\n');
480         ipstream.ignore(256, '\n');
481 
482         ipstream >> person[0].reloads[person[0].weapon.type];
483 
484         ipstream.ignore(256, '\n');
485         ipstream.ignore(256, '\n');
486 
487         ipstream >> timeremaining;
488 
489         ipstream.ignore(256, '\n');
490         ipstream.ignore(256, '\n');
491 
492         ipstream >> difficulty;
493 
494         ipstream.ignore(256, '\n');
495       }
496 
497       ipstream.close();
498     }
499   }
500 
501   if(!config.customlevels) {           //Setup hardcoded default levels
502 
503     if(mission == 0) {
504 
505       environment.type = sunny_environment;
506 
507       type = randomshoot_type;
508 
509       possiblegun[0] = handgun1;
510       possiblegun[1] = handgun2;
511       possiblegun[2] = shotgun;
512 
513       numpossibleguns = 3;
514 
515       evilprobability = 6;
516 
517       person[0].weapon.type = assaultrifle;
518       person[0].reloads[person[0].weapon.type] = 6;
519 
520       if(!gameinprogress)
521         score = 0;
522 
523       timeremaining = 50;
524 
525       difficulty = .6;
526     }
527 
528     if(mission == 1) {
529 
530       environment.type = snowy_environment;
531 
532       type = randomshoot_type;
533 
534       possiblegun[0] = knife;
535       possiblegun[1] = assaultrifle;
536 
537       numpossibleguns = 2;
538 
539       evilprobability = 5;
540 
541       person[0].weapon.type = handgun2;
542       person[0].reloads[person[0].weapon.type] = 3;
543 
544       if(!gameinprogress)
545         score = 0;
546 
547       timeremaining = 40;
548 
549       difficulty = .6;
550     }
551 
552     if(mission == 2) {
553 
554       environment.type = foggy_environment;
555 
556       type = randomshoot_type;
557 
558       possiblegun[0] = sniperrifle;
559 
560       numpossibleguns = 1;
561 
562       evilprobability = 5;
563 
564       person[0].weapon.type = sniperrifle;
565       person[0].reloads[person[0].weapon.type] = 4;
566 
567       if(!gameinprogress)
568         score = 0;
569 
570       timeremaining = 50;
571 
572       difficulty = 0.9;
573     }
574 
575     if(mission == 3) {
576 
577       environment.type = firey_environment;
578 
579       type = zombie_type;
580 
581       numpossibleguns = 0;
582 
583       evilprobability = 5;
584 
585       person[0].weapon.type = shotgun;
586       person[0].reloads[person[0].weapon.type] = 5;
587 
588       if(!gameinprogress)
589         score = 0;
590 
591       timeremaining = 35;
592 
593       difficulty = .7;
594     }
595 
596     if(mission == 4) {
597 
598       environment.type = snowy_environment;
599 
600       type = randomshoot_type;
601 
602       possiblegun[0] = sniperrifle;
603       possiblegun[1] = assaultrifle;
604 
605       numpossibleguns = 2;
606 
607       evilprobability = 5;
608 
609       person[0].weapon.type = grenade;
610 
611       person[0].reloads[person[0].weapon.type] = 20;
612 
613       if(!gameinprogress)
614         score = 0;
615 
616       timeremaining = 30;
617 
618       difficulty = .5;
619 
620     }
621 
622     if(mission == 5) {
623 
624       environment.type = rainy_environment;
625 
626       type = randomshoot_type;
627 
628       possiblegun[0] = handgun1;
629       possiblegun[1] = shotgun;
630       possiblegun[2] = assaultrifle;
631 
632       numpossibleguns = 3;
633 
634       evilprobability = 6;
635 
636       person[0].weapon.type = knife;
637       person[0].reloads[person[0].weapon.type] = 3;
638 
639       if(!gameinprogress)
640         score = 0;
641 
642       timeremaining = 40;
643 
644       difficulty = .8;
645     }
646 
647     if(mission == 6) {
648 
649       environment.type = night_environment;
650 
651       type = randomshoot_type;
652 
653       possiblegun[1] = handgun1;
654       possiblegun[2] = handgun2;
655       possiblegun[3] = shotgun;
656 
657       numpossibleguns = 3;
658 
659       evilprobability = 5;
660 
661       person[0].weapon.type = handgun1;
662       person[0].reloads[person[0].weapon.type] = 4;
663 
664       if(!gameinprogress)
665         score = 0;
666 
667       timeremaining = 30;
668 
669       difficulty = 1;
670     }
671 
672     if(mission == 7) {
673 
674       environment.type = firey_environment;
675 
676       type = zombie_type;
677 
678       person[0].weapon.type = assaultrifle;
679       person[0].reloads[person[0].weapon.type] = 5;
680 
681       if(!gameinprogress)
682         score = 0;
683 
684       timeremaining = 30;
685 
686       difficulty = 1;
687     }
688 
689     if(mission == 8) {
690 
691       environment.type = rainy_environment;
692 
693       type = randomshoot_type;
694 
695       possiblegun[0] = handgun1;
696       possiblegun[1] = handgun2;
697       possiblegun[2] = shotgun;
698       possiblegun[3] = sniperrifle;
699       possiblegun[4] = assaultrifle;
700 
701       numpossibleguns = 5;
702 
703       evilprobability = 5;
704 
705       person[0].weapon.type = nogun;
706       person[0].reloads[person[0].weapon.type] = 3;
707 
708       if(!gameinprogress)
709         score = 0;
710 
711       timeremaining = 40;
712 
713       difficulty = .8;
714 
715     }
716 
717     if(mission == 9) {
718 
719       environment.type = snowy_environment;
720 
721       type = randomshoot_type;
722 
723       possiblegun[0] = knife;
724       possiblegun[1] = handgun1;
725       possiblegun[2] = handgun2;
726       possiblegun[3] = shotgun;
727       possiblegun[4] = sniperrifle;
728       possiblegun[5] = assaultrifle;
729 
730       numpossibleguns = 6;
731 
732       evilprobability = 4;
733 
734       person[0].weapon.type = handgun1;
735       person[0].reloads[person[0].weapon.type] = 3;
736 
737       if(!gameinprogress)
738         score = 0;
739 
740       timeremaining = 90;
741 
742       difficulty = 1;
743     }
744 
745     if(mission == 10) {
746 
747       environment.type = night_environment;
748 
749       type = randomshoot_type;
750 
751       possiblegun[0] = sniperrifle;
752 
753       numpossibleguns = 1;
754 
755       evilprobability = 5;
756 
757       person[0].weapon.type = sniperrifle;
758       person[0].reloads[person[0].weapon.type] = 4;
759 
760       if(!gameinprogress)
761         score = 0;
762 
763       timeremaining = 30;
764 
765       difficulty = 1.3;
766     }
767 
768     if(mission == 11) {
769 
770       environment.type = sunny_environment;
771 
772       type = randomshoot_type;
773 
774       possiblegun[0] = knife;
775       possiblegun[1] = sniperrifle;
776 
777       numpossibleguns = 2;
778 
779       evilprobability = 4;
780 
781       person[0].weapon.type = knife;
782 
783       if(!gameinprogress)
784         score = 0;
785 
786       timeremaining = 30;
787 
788       difficulty = 1.5;
789     }
790 
791     if(mission == 12) {
792 
793       environment.type = firey_environment;
794 
795       type = zombie_type;
796 
797       possiblegun[0] = knife;
798       possiblegun[1] = sniperrifle;
799 
800       person[0].weapon.type = handgun2;
801       person[0].reloads[person[0].weapon.type] = 10;
802 
803       if(!gameinprogress)
804         score = 0;
805 
806       timeremaining = 60;
807 
808       difficulty = 1.5;
809     }
810 
811     nummissions = 13;
812   }
813 
814   //setup env: sunny, night, snowy, foggy, rainy, firey
815   switch (environment.type) {
816     case sunny_environment:
817       environment.viewdistance = 2000;
818       environment.fogcolor.setColor(0.5, 0.5, 0.8);
819       break;
820     case night_environment:
821       environment.viewdistance = 500;
822       environment.fogcolor.setColor(0.15, 0.15, 0.3);
823       break;
824     case snowy_environment:
825       environment.viewdistance = 800;
826       environment.fogcolor.setColor(0.5, 0.5, 0.5);
827       break;
828     case foggy_environment:
829       environment.viewdistance = 500;
830       environment.fogcolor.setColor(0.5, 0.5, 0.5);
831       break;
832     case rainy_environment:
833       environment.viewdistance = 700;
834       environment.fogcolor.setColor(0.3, 0.3, 0.3);
835       break;
836     case firey_environment:
837       environment.viewdistance = 600;
838       environment.fogcolor.setColor(0.3, 0.1, 0.0);
839       break;
840     default:
841       //set a default?
842       break;
843   }
844 
845   //visions off by default
846   config.visions = 0;
847 
848   //Setup bounding cylinder model
849   float boundingscale = 3;
850 
851   if(!initialized) {
852     boundingpoints[0] = 0;      //x
853     boundingpoints[0].z = boundingscale;
854     boundingpoints[0].y = 0;
855 
856     for(int i = 1; i < 8; i++) {
857       boundingpoints[i] = DoRotation(boundingpoints[0], 0, i * 360 / 7, 0);
858     }
859   }
860 
861   civkills = 0;
862   badkills = 0;
863   goodkills = 0;
864   enemystate = 2;
865 
866   if(!initialized) {
867 
868     if(!azertykeyboard) {
869       forwardskey = MAC_W_KEY;
870       backwardskey = MAC_S_KEY;
871       leftkey = MAC_A_KEY;
872       rightkey = MAC_D_KEY;
873       aimkey = MAC_Q_KEY;
874       psychicaimkey = MAC_E_KEY;
875       psychickey = MAC_Z_KEY;
876       helpkey = MAC_F1_KEY;
877     } else if(azertykeyboard) {
878       forwardskey = MAC_Z_KEY;
879       backwardskey = MAC_S_KEY;
880       leftkey = MAC_Q_KEY;
881       rightkey = MAC_D_KEY;
882       aimkey = MAC_A_KEY;
883       psychicaimkey = MAC_E_KEY;
884       psychickey = MAC_W_KEY;
885       helpkey = MAC_F1_KEY;
886     }
887 
888     soundscalefactor = soundscalefactordefault; //Setup sound falloff
889 
890     gQuit = false;
891 
892     //Sounds
893     LoadSounds(config.musictoggle);
894 
895     //Play correct song
896     if(environment.type == rainy_environment)
897       alSourcePlay(gSourceID[rainsound]);
898 
899     if(environment.type != rainy_environment)
900       alSourcePause(gSourceID[rainsound]);
901 
902     alSourceStop(gSourceID[whichsong]);
903 
904     alSourcef(gSourceID[whichsong], AL_MIN_GAIN, 0);
905     alSourcef(gSourceID[whichsong], AL_MAX_GAIN, 0);
906 
907     whichsong = mainmenusong;
908 
909     alSourceStop(gSourceID[whichsong]);
910 
911     alSourcef(gSourceID[whichsong], AL_PITCH, 1);
912 
913     alSourcePlay(gSourceID[whichsong]);
914 
915     alSourcef(gSourceID[whichsong], AL_MIN_GAIN, 1);
916     alSourcef(gSourceID[whichsong], AL_MAX_GAIN, 1);
917   }
918 
919   loadingscreenamount += 5;
920 
921   if(!initialized)
922     LoadingScreen(loadingscreenamount / loadingscreenamounttotal * 100);
923 
924   //Setup random seed
925   srand(time(NULL));
926 
927   gamespeed = 1;
928 
929   //Setup camera
930   camera.position = 0;
931   camera.position.x = num_blocks / 2 * block_spacing + block_spacing / 2;
932   camera.position.z = num_blocks / 2 * block_spacing + block_spacing / 2;
933   camera.position.y = 30;
934   camera.oldposition = camera.position;
935 
936   numpeople = 1;
937 
938   //Setup path to walk around blocks
939   path.load((unsigned char *)":Data:Models:path.solid");
940   path.Rotate(90, 0, 0);
941   path.Scale(.8, .8, .8);
942   path.CalculateNormals();
943 
944   loadingscreenamount += 5;
945 
946   if(!initialized)
947     LoadingScreen(loadingscreenamount / loadingscreenamounttotal * 100);
948 
949   person[0].speedmult = 1.3;
950 
951   //Add vip
952   person[numpeople].playerrotation = 0;
953   person[numpeople].whichcostume = vipcostume;
954 
955   person[numpeople].whichblockx =
956       (int)((person[0].playercoords.x + block_spacing / 2) / block_spacing);
957 
958   person[numpeople].whichblocky =
959       (int)((person[0].playercoords.x + block_spacing / 2) / block_spacing);
960 
961   person[numpeople].pathnum = -1;
962   person[numpeople].oldpathnum = -1;
963   person[numpeople].oldoldpathnum = -1;
964   person[numpeople].oldoldoldpathnum = -1;
965 
966   while(person[numpeople].pathnum < 0
967         || person[numpeople].pathnum >= path.vertexNum
968         || person[numpeople].pathnum == 1) {
969 
970     person[numpeople].pathnum = Random() % path.vertexNum;
971   }
972 
973   person[numpeople].pathtarget.x = path.vertex[person[numpeople].pathnum].x;
974   person[numpeople].pathtarget.z = path.vertex[person[numpeople].pathnum].z;
975   person[numpeople].pathsize = .98 + float (abs(Random() % 20)) / 400;
976   person[numpeople].pathtarget *= person[numpeople].pathsize;
977 
978   person[numpeople].pathtarget.x +=
979       person[numpeople].whichblockx * block_spacing;
980 
981   person[numpeople].pathtarget.z +=
982       person[numpeople].whichblocky * block_spacing;
983 
984   person[numpeople].playercoords = person[numpeople].pathtarget;
985   person[numpeople].oldplayercoords = person[numpeople].playercoords;
986 
987   person[0].playercoords = person[numpeople].playercoords;
988   person[0].playercoords.x += 1;
989   person[0].playercoords.z += 1;
990 
991   person[0].oldplayercoords = person[0].playercoords;
992 
993   person[numpeople].skeleton.free = 0;
994   person[numpeople].targetanimation = walkanim;
995   person[numpeople].speed = 1;
996   person[numpeople].existing = 0;
997   person[numpeople].speedmult = 1;
998 
999   if(type == zombie_type)
1000     person[numpeople].speedmult = .8;
1001 
1002   person[numpeople].health = 100;
1003   person[numpeople].playerrotation2 = 0;        //20;
1004 
1005   person[numpeople].lastdistancevictim = 200000;
1006 
1007   if(person[numpeople].skeleton.broken)
1008     person[numpeople].skeleton.Load((char *)":Data:Skeleton:Basic Figure");
1009 
1010   person[numpeople].type = viptype;
1011   person[numpeople].weapon.type = nogun;
1012   person[numpeople].aiming = 0;
1013   person[numpeople].killtarget = -1;
1014   person[numpeople].existing = 1;
1015 
1016   citypeoplenum[person[numpeople].whichblockx][person[numpeople].whichblocky]++;
1017 
1018   numpeople++;
1019 
1020   spawndelay = .1;
1021 
1022   XYZ vipdistance;
1023 
1024   vipdistance = 0;
1025   vipdistance.x = 10000000;
1026 
1027   vipgoal =
1028       person[1].playercoords + DoRotation(vipdistance, 0, Random() % 360, 0);
1029 
1030   //Setup block models
1031 
1032   if(!initialized) {
1033     blocks[0].load((unsigned char *)":Data:Models:Block1.solid");
1034     blocks[0].Rotate(90, 0, 0);
1035     blocks[0].Scale(.8, .8, .8);
1036     blocks[0].CalculateNormals();
1037 
1038     blocks[1].load((unsigned char *)":Data:Models:Block2.solid");
1039     blocks[1].Rotate(90, 0, 0);
1040     blocks[1].Scale(.8, .8, .8);
1041     blocks[1].CalculateNormals();
1042 
1043     loadingscreenamount += 5;
1044 
1045     if(!initialized)
1046       LoadingScreen(loadingscreenamount / loadingscreenamounttotal * 100);
1047 
1048     blocks[2].load((unsigned char *)":Data:Models:Block3.solid");
1049     blocks[2].Rotate(90, 0, 0);
1050     blocks[2].Scale(.8, .8, .8);
1051     blocks[2].CalculateNormals();
1052 
1053     blocks[3].load((unsigned char *)":Data:Models:Block4.solid");
1054     blocks[3].Rotate(90, 0, 0);
1055     blocks[3].Scale(.8, .8, .8);
1056     blocks[3].CalculateNormals();
1057 
1058     loadingscreenamount += 5;
1059 
1060     if(!initialized)
1061       LoadingScreen(loadingscreenamount / loadingscreenamounttotal * 100);
1062 
1063     sidewalkcollide.
1064         load((unsigned char *)":Data:Models:Lowheightcollide.solid");
1065     sidewalkcollide.Rotate(90, 0, 0);
1066     sidewalkcollide.Scale(.8, .8, .8);
1067     sidewalkcollide.CalculateNormals();
1068 
1069     blockwalls[0].load((unsigned char *)":Data:Models:Block1collide.solid");
1070     blockwalls[0].Rotate(90, 0, 0);
1071     blockwalls[0].Scale(.8, .75, .8);
1072     blockwalls[0].CalculateNormals();
1073 
1074     blockwalls[0].load((unsigned char *)":Data:Models:Block2collide.solid");
1075     blockwalls[0].Rotate(90, 0, 0);
1076     blockwalls[0].Scale(.8, .75, .8);
1077     blockwalls[0].CalculateNormals();
1078 
1079     blockwalls[0].load((unsigned char *)":Data:Models:Block3collide.solid");
1080     blockwalls[0].Rotate(90, 0, 0);
1081     blockwalls[0].Scale(.8, .75, .8);
1082     blockwalls[0].CalculateNormals();
1083 
1084     blockwalls[0].load((unsigned char *)":Data:Models:Block4collide.solid");
1085     blockwalls[0].Rotate(90, 0, 0);
1086     blockwalls[0].Scale(.8, .75, .8);
1087     blockwalls[0].CalculateNormals();
1088 
1089     loadingscreenamount += 5;
1090 
1091     if(!initialized)
1092       LoadingScreen(loadingscreenamount / loadingscreenamounttotal * 100);
1093 
1094     blockroofs[0].load((unsigned char *)":Data:Models:Highblock1collide.solid");
1095     blockroofs[0].Rotate(90, 0, 0);
1096     blockroofs[0].Scale(.8, .8, .8);
1097     blockroofs[0].CalculateNormals();
1098 
1099     blockroofs[1].load((unsigned char *)":Data:Models:Highblock2collide.solid");
1100     blockroofs[1].Rotate(90, 0, 0);
1101     blockroofs[1].Scale(.8, .8, .8);
1102     blockroofs[1].CalculateNormals();
1103 
1104     blockroofs[2].load((unsigned char *)":Data:Models:Highblock3collide.solid");
1105     blockroofs[2].Rotate(90, 0, 0);
1106     blockroofs[2].Scale(.8, .8, .8);
1107     blockroofs[2].CalculateNormals();
1108 
1109     blockroofs[3].load((unsigned char *)":Data:Models:Highblock4collide.solid");
1110     blockroofs[3].Rotate(90, 0, 0);
1111     blockroofs[3].Scale(.8, .8, .8);
1112     blockroofs[3].CalculateNormals();
1113 
1114     blockcollide[0].load((unsigned char *)":Data:Models:block1complete.solid");
1115     blockcollide[0].Rotate(90, 0, 0);
1116     blockcollide[0].Scale(.8, .8, .8);
1117     blockcollide[0].CalculateNormals();
1118 
1119     blockcollide[1].load((unsigned char *)":Data:Models:block2complete.solid");
1120     blockcollide[1].Rotate(90, 0, 0);
1121     blockcollide[1].Scale(.8, .8, .8);
1122     blockcollide[1].CalculateNormals();
1123 
1124     blockcollide[2].load((unsigned char *)":Data:Models:block3complete.solid");
1125     blockcollide[2].Rotate(90, 0, 0);
1126     blockcollide[2].Scale(.8, .8, .8);
1127     blockcollide[2].CalculateNormals();
1128 
1129     blockcollide[3].load((unsigned char *)":Data:Models:block4complete.solid");
1130     blockcollide[3].Rotate(90, 0, 0);
1131     blockcollide[3].Scale(.8, .8, .8);
1132     blockcollide[3].CalculateNormals();
1133 
1134     loadingscreenamount += 5;
1135 
1136     if(!initialized)
1137       LoadingScreen(loadingscreenamount / loadingscreenamounttotal * 100);
1138 
1139     blocksimplecollide[0].
1140         load((unsigned char *)":Data:Models:lowsimplecollide1.solid");
1141     blocksimplecollide[0].Rotate(90, 0, 0);
1142     blocksimplecollide[0].Scale(.8, .8, .8);
1143     blocksimplecollide[0].CalculateNormals();
1144 
1145     blocksimplecollide[1].
1146         load((unsigned char *)":Data:Models:lowsimplecollide2.solid");
1147     blocksimplecollide[1].Rotate(90, 0, 0);
1148     blocksimplecollide[1].Scale(.8, .8, .8);
1149     blocksimplecollide[1].CalculateNormals();
1150 
1151     blocksimplecollide[2].
1152         load((unsigned char *)":Data:Models:lowsimplecollide3.solid");
1153     blocksimplecollide[2].Rotate(90, 0, 0);
1154     blocksimplecollide[2].Scale(.8, .8, .8);
1155     blocksimplecollide[2].CalculateNormals();
1156 
1157     blocksimplecollide[3].
1158         load((unsigned char *)":Data:Models:lowsimplecollide4.solid");
1159     blocksimplecollide[3].Rotate(90, 0, 0);
1160     blocksimplecollide[3].Scale(.8, .8, .8);
1161     blocksimplecollide[3].CalculateNormals();
1162 
1163     loadingscreenamount += 5;
1164 
1165     if(!initialized)
1166       LoadingScreen(loadingscreenamount / loadingscreenamounttotal * 100);
1167 
1168     blockocclude.load((unsigned char *)":Data:Models:blockocclude.solid");
1169     blockocclude.Rotate(90, 0, 0);
1170     blockocclude.Scale(.8, .8, .8);
1171     blockocclude.CalculateNormals();
1172 
1173     blocksimple.load((unsigned char *)":Data:Models:blocksimple.solid");
1174     blocksimple.Rotate(90, 0, 0);
1175     blocksimple.Scale(.8, 2, .8);
1176     blocksimple.CalculateNormals();
1177 
1178     street.load((unsigned char *)":Data:Models:streetsubdivided2.solid");
1179     street.Rotate(90, 0, 0);
1180     street.Scale(.01, .01, .01);
1181     street.CalculateNormals();
1182 
1183     Bigstreet = street;
1184     Bigstreet.Scale(10000, 10000, 10000);
1185 
1186     loadingscreenamount += 5;
1187 
1188     if(!initialized)
1189       LoadingScreen(loadingscreenamount / loadingscreenamounttotal * 100);
1190 
1191     path.load((unsigned char *)":Data:Models:path.solid");
1192     path.Rotate(90, 0, 0);
1193     path.Scale(.8, .8, .8);
1194     path.CalculateNormals();
1195 
1196     //Fix block radius
1197 
1198     for(int i = 0; i < 4; i++) {
1199       blocks[i].boundingspherecenter.x = 0;
1200       blocks[i].boundingspherecenter.z = 0;
1201       blocks[i].boundingsphereradius = 0;
1202 
1203       for(int x = 0; i < blocks[x].vertexNum; x++) {
1204         if(findDistancefast(blocks[i].boundingspherecenter, blocks[i].vertex[x])
1205            > blocks[i].boundingsphereradius) {
1206           blocks[i].boundingsphereradius =
1207               findDistancefast(blocks[i].boundingspherecenter,
1208                                blocks[i].vertex[x]);
1209         }
1210       }
1211 
1212       blocks[i].boundingsphereradius = sqrt(blocks[i].boundingsphereradius);
1213     }
1214   }
1215 
1216   //FIXME: why is the user specified value being overridden?
1217   mousesensitivity = 1;
1218 
1219   //init city block rotations
1220   for(int i = 0; i < num_blocks; i++) {
1221     for(int j = 0; j < num_blocks; j++) {
1222       cityrotation[i][j] = Random() % 4;
1223       citytype[i][j] = Random() % 4;
1224 
1225       citypeoplenum[i][j] = 0;
1226 
1227       if(citytype[i][j] < 0)
1228         citytype[i][j] = 0;
1229 
1230       if(citytype[i][j] > 3)
1231         citytype[i][j] = 3;
1232     }
1233   }
1234 
1235   if(!initialized) {
1236 
1237     //Load player model
1238     skeletonmodels[0].load((unsigned char *)":Data:Models:Head.solid");
1239     skeletonmodels[0].Rotate(90, 0, 0);
1240     skeletonmodels[0].Scale(.02, .02, .02);
1241     skeletonmodels[0].CalculateNormals();
1242 
1243     skeletonmodels[1].load((unsigned char *)":Data:Models:Chest.solid");
1244     skeletonmodels[1].Rotate(90, 0, 0);
1245     skeletonmodels[1].Scale(.02, .02, .02);
1246     skeletonmodels[1].CalculateNormals();
1247 
1248     skeletonmodels[2].load((unsigned char *)":Data:Models:Abdomen.solid");
1249     skeletonmodels[2].Rotate(90, 0, 0);
1250     skeletonmodels[2].Scale(.02, .02, .02);
1251     skeletonmodels[2].CalculateNormals();
1252 
1253     skeletonmodels[3].load((unsigned char *)":Data:Models:Upper arm.solid");
1254     skeletonmodels[3].Rotate(90, 0, 0);
1255     skeletonmodels[3].Scale(.02, .02, .02);
1256     skeletonmodels[3].CalculateNormals();
1257 
1258     skeletonmodels[4].load((unsigned char *)":Data:Models:Lower arm.solid");
1259     skeletonmodels[4].Rotate(90, 0, 0);
1260     skeletonmodels[4].Scale(.02, .02, .02);
1261     skeletonmodels[4].CalculateNormals();
1262 
1263     skeletonmodels[5].load((unsigned char *)":Data:Models:Hand.solid");
1264     skeletonmodels[5].Rotate(90, 0, 0);
1265     skeletonmodels[5].Scale(.02, .02, .02);
1266     skeletonmodels[5].CalculateNormals();
1267 
1268     skeletonmodels[6].load((unsigned char *)":Data:Models:Upper leg.solid");
1269     skeletonmodels[6].Rotate(90, 0, 0);
1270     skeletonmodels[6].Scale(.02, .02, .02);
1271     skeletonmodels[6].CalculateNormals();
1272 
1273     skeletonmodels[7].load((unsigned char *)":Data:Models:Lower leg.solid");
1274     skeletonmodels[7].Rotate(90, 0, 0);
1275     skeletonmodels[7].Scale(.02, .02, .02);
1276     skeletonmodels[7].CalculateNormals();
1277 
1278     skeletonmodels[8].load((unsigned char *)":Data:Models:Foot.solid");
1279     skeletonmodels[8].Rotate(90, 0, 0);
1280     skeletonmodels[8].Scale(.02, .02, .02);
1281     skeletonmodels[8].CalculateNormals();
1282 
1283     skeletonmodels[9].load((unsigned char *)":Data:Models:Shades.solid");
1284     skeletonmodels[9].Rotate(90, 0, 0);
1285     skeletonmodels[9].Scale(.02, .02, .02);
1286     skeletonmodels[9].CalculateNormals();
1287 
1288     //Load gun models
1289     loadingscreenamount += 5;
1290 
1291     if(!initialized)
1292       LoadingScreen(loadingscreenamount / loadingscreenamounttotal * 100);
1293 
1294     gunmodels[sniperriflemodel].
1295         load((unsigned char *)":Data:Models:sniperrifle.solid");
1296     gunmodels[sniperriflemodel].Rotate(0, 0, 90);
1297     gunmodels[sniperriflemodel].Scale(.001, .001, .001);
1298     gunmodels[sniperriflemodel].CalculateNormals();
1299 
1300     gunmodels[assaultriflemodel].
1301         load((unsigned char *)":Data:Models:assaultrifle.solid");
1302     gunmodels[assaultriflemodel].Rotate(0, 0, 90);
1303     gunmodels[assaultriflemodel].Scale(.01, .01, .01);
1304     gunmodels[assaultriflemodel].CalculateNormals();
1305 
1306     gunmodels[handgunbasemodel].
1307         load((unsigned char *)":Data:Models:Handgunbase.solid");
1308     gunmodels[handgunbasemodel].Rotate(0, 0, 90);
1309     gunmodels[handgunbasemodel].Rotate(180, 0, 0);
1310     gunmodels[handgunbasemodel].Scale(.014, .014, .014);
1311     gunmodels[handgunbasemodel].CalculateNormals();
1312     gunmodels[handgunbasemodel].MultColor(.6);
1313 
1314     loadingscreenamount += 5;
1315 
1316     if(!initialized)
1317       LoadingScreen(loadingscreenamount / loadingscreenamounttotal * 100);
1318 
1319     gunmodels[handgunslidemodel].
1320         load((unsigned char *)":Data:Models:Handgunslide.solid");
1321     gunmodels[handgunslidemodel].Rotate(0, 0, 90);
1322     gunmodels[handgunslidemodel].Rotate(180, 0, 0);
1323     gunmodels[handgunslidemodel].Scale(.014, .014, .014);
1324     gunmodels[handgunslidemodel].CalculateNormals();
1325     gunmodels[handgunslidemodel].MultColor(.6);
1326 
1327     gunmodels[handgun2basemodel].
1328         load((unsigned char *)":Data:Models:glockbase.solid");
1329     gunmodels[handgun2basemodel].Rotate(0, 0, 90);
1330     gunmodels[handgun2basemodel].Rotate(180, 0, 0);
1331     gunmodels[handgun2basemodel].Scale(.014, .014, .014);
1332     gunmodels[handgun2basemodel].CalculateNormals();
1333     gunmodels[handgun2basemodel].MultColor(.6);
1334 
1335     gunmodels[handgun2slidemodel].
1336         load((unsigned char *)":Data:Models:glockslide.solid");
1337     gunmodels[handgun2slidemodel].Rotate(0, 0, 90);
1338     gunmodels[handgun2slidemodel].Rotate(180, 0, 0);
1339     gunmodels[handgun2slidemodel].Scale(.014, .014, .014);
1340     gunmodels[handgun2slidemodel].CalculateNormals();
1341     gunmodels[handgun2slidemodel].MultColor(.6);
1342 
1343     loadingscreenamount += 5;
1344 
1345     if(!initialized)
1346       LoadingScreen(loadingscreenamount / loadingscreenamounttotal * 100);
1347 
1348     gunmodels[grenadebasemodel].
1349         load((unsigned char *)":Data:Models:grenadebase.solid");
1350     gunmodels[grenadebasemodel].Rotate(0, 0, 90);
1351     gunmodels[grenadebasemodel].Rotate(180, 0, 0);
1352     gunmodels[grenadebasemodel].Scale(.014, .014, .014);
1353     gunmodels[grenadebasemodel].CalculateNormals();
1354 
1355     gunmodels[grenadepinmodel].
1356         load((unsigned char *)":Data:Models:grenadepin.solid");
1357     gunmodels[grenadepinmodel].Rotate(0, 0, 90);
1358     gunmodels[grenadepinmodel].Rotate(180, 0, 0);
1359     gunmodels[grenadepinmodel].Scale(.014, .014, .014);
1360     gunmodels[grenadepinmodel].CalculateNormals();
1361 
1362     gunmodels[grenadespoonmodel].
1363         load((unsigned char *)":Data:Models:grenadespoon.solid");
1364     gunmodels[grenadespoonmodel].Rotate(0, 0, 90);
1365     gunmodels[grenadespoonmodel].Rotate(180, 0, 0);
1366     gunmodels[grenadespoonmodel].Scale(.014, .014, .014);
1367     gunmodels[grenadespoonmodel].CalculateNormals();
1368 
1369     gunmodels[knifemodel].load((unsigned char *)":Data:Models:Knife.solid");
1370     gunmodels[knifemodel].Rotate(0, 0, 90);
1371     gunmodels[knifemodel].Rotate(180, 0, 0);
1372     gunmodels[knifemodel].Scale(.014, .014, .014);
1373     gunmodels[knifemodel].CalculateNormals();
1374 
1375     gunmodels[shotgunmodel].load((unsigned char *)":Data:Models:shotgun.solid");
1376     gunmodels[shotgunmodel].Rotate(0, 0, 90);
1377     gunmodels[shotgunmodel].Scale(.001, .001, .001);
1378     gunmodels[shotgunmodel].CalculateNormals();
1379     gunmodels[shotgunmodel].MultColor(.6);
1380   }
1381 
1382   loadingscreenamount += 5;
1383 
1384   if(!initialized)
1385     LoadingScreen(loadingscreenamount / loadingscreenamounttotal * 100);
1386 
1387   //Setup costumes
1388   float headcolor[3];
1389   float footcolor[3];
1390   float handcolor[3];
1391   float topcolor[3];
1392   float bottomcolor[3];
1393 
1394   //Police
1395   headcolor[0] = (float)240 / 255;
1396   headcolor[1] = (float)183 / 255;
1397   headcolor[2] = (float)132 / 255;
1398 
1399   footcolor[0] = (float)119 / 255;
1400   footcolor[1] = (float)68 / 255;
1401   footcolor[2] = (float)18 / 255;
1402 
1403   handcolor[0] = (float)240 / 255;
1404   handcolor[1] = (float)183 / 255;
1405   handcolor[2] = (float)132 / 255;
1406 
1407   topcolor[0] = (float)14 / 255;
1408   topcolor[1] = (float)18 / 255;
1409   topcolor[2] = (float)195 / 255;
1410 
1411   bottomcolor[0] = (float)14 / 255;
1412   bottomcolor[1] = (float)18 / 255;
1413   bottomcolor[2] = (float)195 / 255;
1414 
1415   //Greenish skin if zombies
1416 
1417   if(type == zombie_type) {
1418     headcolor[0] = (float)223 / 255;
1419     headcolor[1] = (float)243 / 255;
1420     headcolor[2] = (float)197 / 255;
1421 
1422     handcolor[0] = (float)223 / 255;
1423     handcolor[1] = (float)243 / 255;
1424     handcolor[2] = (float)197 / 255;
1425   }
1426 
1427   costume[policecostume].headcolor[0] = headcolor[0];
1428   costume[policecostume].headcolor[1] = headcolor[1];
1429   costume[policecostume].headcolor[2] = headcolor[2];
1430 
1431   costume[policecostume].handcolor[0] = handcolor[0];
1432   costume[policecostume].handcolor[1] = handcolor[1];
1433   costume[policecostume].handcolor[2] = handcolor[2];
1434 
1435   costume[policecostume].chestcolor[0] = topcolor[0];
1436   costume[policecostume].chestcolor[1] = topcolor[1];
1437   costume[policecostume].chestcolor[2] = topcolor[2];
1438 
1439   costume[policecostume].abdomencolor[0] = topcolor[0];
1440   costume[policecostume].abdomencolor[1] = topcolor[1];
1441   costume[policecostume].abdomencolor[2] = topcolor[2];
1442 
1443   costume[policecostume].upperarmcolor[0] = topcolor[0];
1444   costume[policecostume].upperarmcolor[1] = topcolor[1];
1445   costume[policecostume].upperarmcolor[2] = topcolor[2];
1446 
1447   costume[policecostume].lowerarmcolor[0] = topcolor[0];
1448   costume[policecostume].lowerarmcolor[1] = topcolor[1];
1449   costume[policecostume].lowerarmcolor[2] = topcolor[2];
1450 
1451   costume[policecostume].upperlegcolor[0] = bottomcolor[0];
1452   costume[policecostume].upperlegcolor[1] = bottomcolor[1];
1453   costume[policecostume].upperlegcolor[2] = bottomcolor[2];
1454 
1455   costume[policecostume].lowerlegcolor[0] = bottomcolor[0];
1456   costume[policecostume].lowerlegcolor[1] = bottomcolor[1];
1457   costume[policecostume].lowerlegcolor[2] = bottomcolor[2];
1458 
1459   costume[policecostume].footcolor[0] = footcolor[0];
1460   costume[policecostume].footcolor[1] = footcolor[1];
1461   costume[policecostume].footcolor[2] = footcolor[2];
1462 
1463   //casual
1464   topcolor[0] = (float)14 / 255;
1465   topcolor[1] = (float)200 / 255;
1466   topcolor[2] = (float)30 / 255;
1467 
1468   bottomcolor[0] = (float)14 / 255;
1469   bottomcolor[1] = (float)18 / 255;
1470   bottomcolor[2] = (float)195 / 255;
1471 
1472   costume[casualcostumes].headcolor[0] = headcolor[0];
1473   costume[casualcostumes].headcolor[1] = headcolor[1];
1474   costume[casualcostumes].headcolor[2] = headcolor[2];
1475 
1476   costume[casualcostumes].handcolor[0] = handcolor[0];
1477   costume[casualcostumes].handcolor[1] = handcolor[1];
1478   costume[casualcostumes].handcolor[2] = handcolor[2];
1479 
1480   costume[casualcostumes].chestcolor[0] = topcolor[0];
1481   costume[casualcostumes].chestcolor[1] = topcolor[1];
1482   costume[casualcostumes].chestcolor[2] = topcolor[2];
1483 
1484   costume[casualcostumes].abdomencolor[0] = topcolor[0];
1485   costume[casualcostumes].abdomencolor[1] = topcolor[1];
1486   costume[casualcostumes].abdomencolor[2] = topcolor[2];
1487 
1488   costume[casualcostumes].upperarmcolor[0] = topcolor[0];
1489   costume[casualcostumes].upperarmcolor[1] = topcolor[1];
1490   costume[casualcostumes].upperarmcolor[2] = topcolor[2];
1491 
1492   costume[casualcostumes].lowerarmcolor[0] = handcolor[0];
1493   costume[casualcostumes].lowerarmcolor[1] = handcolor[1];
1494   costume[casualcostumes].lowerarmcolor[2] = handcolor[2];
1495 
1496   costume[casualcostumes].upperlegcolor[0] = bottomcolor[0];
1497   costume[casualcostumes].upperlegcolor[1] = bottomcolor[1];
1498   costume[casualcostumes].upperlegcolor[2] = bottomcolor[2];
1499 
1500   costume[casualcostumes].lowerlegcolor[0] = bottomcolor[0];
1501   costume[casualcostumes].lowerlegcolor[1] = bottomcolor[1];
1502   costume[casualcostumes].lowerlegcolor[2] = bottomcolor[2];
1503 
1504   costume[casualcostumes].footcolor[0] = footcolor[0];
1505   costume[casualcostumes].footcolor[1] = footcolor[1];
1506   costume[casualcostumes].footcolor[2] = footcolor[2];
1507 
1508   //casual 2
1509 
1510   topcolor[0] = (float)140 / 255;
1511   topcolor[1] = (float)55 / 255;
1512   topcolor[2] = (float)4 / 255;
1513 
1514   bottomcolor[0] = (float)14 / 255;
1515   bottomcolor[1] = (float)18 / 255;
1516   bottomcolor[2] = (float)135 / 255;
1517 
1518   costume[casualcostumes + 1].headcolor[0] = headcolor[0];
1519   costume[casualcostumes + 1].headcolor[1] = headcolor[1];
1520   costume[casualcostumes + 1].headcolor[2] = headcolor[2];
1521 
1522   costume[casualcostumes + 1].handcolor[0] = handcolor[0];
1523   costume[casualcostumes + 1].handcolor[1] = handcolor[1];
1524   costume[casualcostumes + 1].handcolor[2] = handcolor[2];
1525 
1526   costume[casualcostumes + 1].chestcolor[0] = topcolor[0];
1527   costume[casualcostumes + 1].chestcolor[1] = topcolor[1];
1528   costume[casualcostumes + 1].chestcolor[2] = topcolor[2];
1529 
1530   costume[casualcostumes + 1].abdomencolor[0] = topcolor[0];
1531   costume[casualcostumes + 1].abdomencolor[1] = topcolor[1];
1532   costume[casualcostumes + 1].abdomencolor[2] = topcolor[2];
1533 
1534   costume[casualcostumes + 1].upperarmcolor[0] = topcolor[0];
1535   costume[casualcostumes + 1].upperarmcolor[1] = topcolor[1];
1536   costume[casualcostumes + 1].upperarmcolor[2] = topcolor[2];
1537 
1538   costume[casualcostumes + 1].lowerarmcolor[0] = topcolor[0];
1539   costume[casualcostumes + 1].lowerarmcolor[1] = topcolor[1];
1540   costume[casualcostumes + 1].lowerarmcolor[2] = topcolor[2];
1541 
1542   costume[casualcostumes + 1].upperlegcolor[0] = bottomcolor[0];
1543   costume[casualcostumes + 1].upperlegcolor[1] = bottomcolor[1];
1544   costume[casualcostumes + 1].upperlegcolor[2] = bottomcolor[2];
1545 
1546   costume[casualcostumes + 1].lowerlegcolor[0] = bottomcolor[0];
1547   costume[casualcostumes + 1].lowerlegcolor[1] = bottomcolor[1];
1548   costume[casualcostumes + 1].lowerlegcolor[2] = bottomcolor[2];
1549 
1550   costume[casualcostumes + 1].footcolor[0] = footcolor[0];
1551   costume[casualcostumes + 1].footcolor[1] = footcolor[1];
1552   costume[casualcostumes + 1].footcolor[2] = footcolor[2];
1553 
1554   //casual 3
1555   topcolor[0] = (float)134 / 255;
1556   topcolor[1] = (float)80 / 255;
1557   topcolor[2] = (float)3 / 255;
1558 
1559   bottomcolor[0] = (float)30 / 255;
1560   bottomcolor[1] = (float)30 / 255;
1561   bottomcolor[2] = (float)30 / 255;
1562 
1563   footcolor[0] = (float)20 / 255;
1564   footcolor[1] = (float)20 / 255;
1565   footcolor[2] = (float)20 / 255;
1566 
1567   costume[casualcostumes + 2].headcolor[0] = headcolor[0];
1568   costume[casualcostumes + 2].headcolor[1] = headcolor[1];
1569   costume[casualcostumes + 2].headcolor[2] = headcolor[2];
1570 
1571   costume[casualcostumes + 2].handcolor[0] = handcolor[0];
1572   costume[casualcostumes + 2].handcolor[1] = handcolor[1];
1573   costume[casualcostumes + 2].handcolor[2] = handcolor[2];
1574 
1575   costume[casualcostumes + 2].chestcolor[0] = topcolor[0];
1576   costume[casualcostumes + 2].chestcolor[1] = topcolor[1];
1577   costume[casualcostumes + 2].chestcolor[2] = topcolor[2];
1578 
1579   costume[casualcostumes + 2].abdomencolor[0] = topcolor[0];
1580   costume[casualcostumes + 2].abdomencolor[1] = topcolor[1];
1581   costume[casualcostumes + 2].abdomencolor[2] = topcolor[2];
1582 
1583   costume[casualcostumes + 2].upperarmcolor[0] = topcolor[0];
1584   costume[casualcostumes + 2].upperarmcolor[1] = topcolor[1];
1585   costume[casualcostumes + 2].upperarmcolor[2] = topcolor[2];
1586 
1587   costume[casualcostumes + 2].lowerarmcolor[0] = topcolor[0];
1588   costume[casualcostumes + 2].lowerarmcolor[1] = topcolor[1];
1589   costume[casualcostumes + 2].lowerarmcolor[2] = topcolor[2];
1590 
1591   costume[casualcostumes + 2].upperlegcolor[0] = bottomcolor[0];
1592   costume[casualcostumes + 2].upperlegcolor[1] = bottomcolor[1];
1593   costume[casualcostumes + 2].upperlegcolor[2] = bottomcolor[2];
1594 
1595   costume[casualcostumes + 2].lowerlegcolor[0] = bottomcolor[0];
1596   costume[casualcostumes + 2].lowerlegcolor[1] = bottomcolor[1];
1597   costume[casualcostumes + 2].lowerlegcolor[2] = bottomcolor[2];
1598 
1599   costume[casualcostumes + 2].footcolor[0] = footcolor[0];
1600   costume[casualcostumes + 2].footcolor[1] = footcolor[1];
1601   costume[casualcostumes + 2].footcolor[2] = footcolor[2];
1602 
1603   //casual 4
1604 
1605   topcolor[0] = (float)228 / 255;
1606   topcolor[1] = (float)220 / 255;
1607   topcolor[2] = (float)0 / 255;
1608 
1609   bottomcolor[0] = (float)20 / 255;
1610   bottomcolor[1] = (float)20 / 255;
1611   bottomcolor[2] = (float)20 / 255;
1612 
1613   footcolor[0] = (float)119 / 255;
1614   footcolor[1] = (float)68 / 255;
1615   footcolor[2] = (float)18 / 255;
1616 
1617   costume[casualcostumes + 3].headcolor[0] = headcolor[0];
1618   costume[casualcostumes + 3].headcolor[1] = headcolor[1];
1619   costume[casualcostumes + 3].headcolor[2] = headcolor[2];
1620 
1621   costume[casualcostumes + 3].handcolor[0] = handcolor[0];
1622   costume[casualcostumes + 3].handcolor[1] = handcolor[1];
1623   costume[casualcostumes + 3].handcolor[2] = handcolor[2];
1624 
1625   costume[casualcostumes + 3].chestcolor[0] = topcolor[0];
1626   costume[casualcostumes + 3].chestcolor[1] = topcolor[1];
1627   costume[casualcostumes + 3].chestcolor[2] = topcolor[2];
1628 
1629   costume[casualcostumes + 3].abdomencolor[0] = topcolor[0];
1630   costume[casualcostumes + 3].abdomencolor[1] = topcolor[1];
1631   costume[casualcostumes + 3].abdomencolor[2] = topcolor[2];
1632 
1633   costume[casualcostumes + 3].upperarmcolor[0] = topcolor[0];
1634   costume[casualcostumes + 3].upperarmcolor[1] = topcolor[1];
1635   costume[casualcostumes + 3].upperarmcolor[2] = topcolor[2];
1636 
1637   costume[casualcostumes + 3].lowerarmcolor[0] = handcolor[0];
1638   costume[casualcostumes + 3].lowerarmcolor[1] = handcolor[1];
1639   costume[casualcostumes + 3].lowerarmcolor[2] = handcolor[2];
1640 
1641   costume[casualcostumes + 3].upperlegcolor[0] = bottomcolor[0];
1642   costume[casualcostumes + 3].upperlegcolor[1] = bottomcolor[1];
1643   costume[casualcostumes + 3].upperlegcolor[2] = bottomcolor[2];
1644 
1645   costume[casualcostumes + 3].lowerlegcolor[0] = bottomcolor[0];
1646   costume[casualcostumes + 3].lowerlegcolor[1] = bottomcolor[1];
1647   costume[casualcostumes + 3].lowerlegcolor[2] = bottomcolor[2];
1648 
1649   costume[casualcostumes + 3].footcolor[0] = footcolor[0];
1650   costume[casualcostumes + 3].footcolor[1] = footcolor[1];
1651   costume[casualcostumes + 3].footcolor[2] = footcolor[2];
1652 
1653   if(!initialized) {
1654 
1655     //vip
1656     topcolor[0] = (float)235 / 255;
1657     topcolor[1] = (float)235 / 255;
1658     topcolor[2] = (float)235 / 255;
1659 
1660     bottomcolor[0] = (float)200 / 255;
1661     bottomcolor[1] = (float)200 / 255;
1662     bottomcolor[2] = (float)200 / 255;
1663 
1664     footcolor[0] = (float)119 / 255;
1665     footcolor[1] = (float)68 / 255;
1666     footcolor[2] = (float)18 / 255;
1667 
1668     headcolor[0] = (float)240 / 255;
1669     headcolor[1] = (float)183 / 255;
1670     headcolor[2] = (float)132 / 255;
1671 
1672     footcolor[0] = (float)119 / 255;
1673     footcolor[1] = (float)68 / 255;
1674     footcolor[2] = (float)18 / 255;
1675 
1676     handcolor[0] = (float)240 / 255;
1677     handcolor[1] = (float)183 / 255;
1678     handcolor[2] = (float)132 / 255;
1679 
1680     costume[vipcostume].headcolor[0] = headcolor[0];
1681     costume[vipcostume].headcolor[1] = headcolor[1];
1682     costume[vipcostume].headcolor[2] = headcolor[2];
1683 
1684     costume[vipcostume].handcolor[0] = handcolor[0];
1685     costume[vipcostume].handcolor[1] = handcolor[1];
1686     costume[vipcostume].handcolor[2] = handcolor[2];
1687 
1688     costume[vipcostume].chestcolor[0] = topcolor[0];
1689     costume[vipcostume].chestcolor[1] = topcolor[1];
1690     costume[vipcostume].chestcolor[2] = topcolor[2];
1691 
1692     costume[vipcostume].abdomencolor[0] = topcolor[0];
1693     costume[vipcostume].abdomencolor[1] = topcolor[1];
1694     costume[vipcostume].abdomencolor[2] = topcolor[2];
1695 
1696     costume[vipcostume].upperarmcolor[0] = topcolor[0];
1697     costume[vipcostume].upperarmcolor[1] = topcolor[1];
1698     costume[vipcostume].upperarmcolor[2] = topcolor[2];
1699 
1700     costume[vipcostume].lowerarmcolor[0] = topcolor[0];
1701     costume[vipcostume].lowerarmcolor[1] = topcolor[1];
1702     costume[vipcostume].lowerarmcolor[2] = topcolor[2];
1703 
1704     costume[vipcostume].upperlegcolor[0] = bottomcolor[0];
1705     costume[vipcostume].upperlegcolor[1] = bottomcolor[1];
1706     costume[vipcostume].upperlegcolor[2] = bottomcolor[2];
1707 
1708     costume[vipcostume].lowerlegcolor[0] = bottomcolor[0];
1709     costume[vipcostume].lowerlegcolor[1] = bottomcolor[1];
1710     costume[vipcostume].lowerlegcolor[2] = bottomcolor[2];
1711 
1712     costume[vipcostume].footcolor[0] = footcolor[0];
1713     costume[vipcostume].footcolor[1] = footcolor[1];
1714     costume[vipcostume].footcolor[2] = footcolor[2];
1715 
1716     //Bodyguard
1717     topcolor[0] = (float)50 / 255;
1718     topcolor[1] = (float)50 / 255;
1719     topcolor[2] = (float)50 / 255;
1720 
1721     bottomcolor[0] = (float)30 / 255;
1722     bottomcolor[1] = (float)30 / 255;
1723     bottomcolor[2] = (float)30 / 255;
1724 
1725     footcolor[0] = (float)20 / 255;
1726     footcolor[1] = (float)20 / 255;
1727     footcolor[2] = (float)20 / 255;
1728 
1729     costume[bodyguardcostume].headcolor[0] = headcolor[0];
1730     costume[bodyguardcostume].headcolor[1] = headcolor[1];
1731     costume[bodyguardcostume].headcolor[2] = headcolor[2];
1732 
1733     costume[bodyguardcostume].handcolor[0] = handcolor[0];
1734     costume[bodyguardcostume].handcolor[1] = handcolor[1];
1735     costume[bodyguardcostume].handcolor[2] = handcolor[2];
1736 
1737     costume[bodyguardcostume].chestcolor[0] = topcolor[0];
1738     costume[bodyguardcostume].chestcolor[1] = topcolor[1];
1739     costume[bodyguardcostume].chestcolor[2] = topcolor[2];
1740 
1741     costume[bodyguardcostume].abdomencolor[0] = topcolor[0];
1742     costume[bodyguardcostume].abdomencolor[1] = topcolor[1];
1743     costume[bodyguardcostume].abdomencolor[2] = topcolor[2];
1744 
1745     costume[bodyguardcostume].upperarmcolor[0] = topcolor[0];
1746     costume[bodyguardcostume].upperarmcolor[1] = topcolor[1];
1747     costume[bodyguardcostume].upperarmcolor[2] = topcolor[2];
1748 
1749     costume[bodyguardcostume].lowerarmcolor[0] = topcolor[0];
1750     costume[bodyguardcostume].lowerarmcolor[1] = topcolor[1];
1751     costume[bodyguardcostume].lowerarmcolor[2] = topcolor[2];
1752 
1753     costume[bodyguardcostume].upperlegcolor[0] = bottomcolor[0];
1754     costume[bodyguardcostume].upperlegcolor[1] = bottomcolor[1];
1755     costume[bodyguardcostume].upperlegcolor[2] = bottomcolor[2];
1756 
1757     costume[bodyguardcostume].lowerlegcolor[0] = bottomcolor[0];
1758     costume[bodyguardcostume].lowerlegcolor[1] = bottomcolor[1];
1759     costume[bodyguardcostume].lowerlegcolor[2] = bottomcolor[2];
1760 
1761     costume[bodyguardcostume].footcolor[0] = footcolor[0];
1762     costume[bodyguardcostume].footcolor[1] = footcolor[1];
1763     costume[bodyguardcostume].footcolor[2] = footcolor[2];
1764 
1765     //Load animations
1766 
1767     loadingscreenamount += 5;
1768 
1769     if(!initialized)
1770       LoadingScreen(loadingscreenamount / loadingscreenamounttotal * 100);
1771 
1772     testskeleton.Load((char *)":Data:Skeleton:Basic Figure");
1773     animation[idleanim].Load((char *)":Data:Animations:Breathe");
1774     animation[joganim].Load((char *)":Data:Animations:Run");
1775     animation[pistolaimanim].Load((char *)":Data:Animations:PistolAim");
1776 
1777     loadingscreenamount += 5;
1778 
1779     if(!initialized)
1780       LoadingScreen(loadingscreenamount / loadingscreenamounttotal * 100);
1781 
1782     animation[walkanim].Load((char *)":Data:Animations:Walk");
1783     animation[rifleholdanim].Load((char *)":Data:Animations:Riflehold");
1784     animation[rifleaimanim].Load((char *)":Data:Animations:Rifleaim");
1785     animation[assaultrifleaimanim].
1786         Load((char *)":Data:Animations:AssaultRifleaim");
1787 
1788     animation[crouchanim].Load((char *)":Data:Animations:Crouch");
1789 
1790     loadingscreenamount += 5;
1791 
1792     if(!initialized)
1793       LoadingScreen(loadingscreenamount / loadingscreenamounttotal * 100);
1794 
1795     animation[headpainanim].Load((char *)":Data:Animations:Headshot");
1796     animation[chestpainanim].Load((char *)":Data:Animations:Chestshot");
1797     animation[stomachpainanim].Load((char *)":Data:Animations:Stomachshot");
1798     animation[rightarmpainanim].Load((char *)":Data:Animations:Rightarmshot");
1799     animation[leftarmpainanim].Load((char *)":Data:Animations:Leftarmshot");
1800 
1801     loadingscreenamount += 5;
1802 
1803     if(!initialized)
1804       LoadingScreen(loadingscreenamount / loadingscreenamounttotal * 100);
1805 
1806     animation[rightlegpainanim].Load((char *)":Data:Animations:Rightlegshot");
1807     animation[leftlegpainanim].Load((char *)":Data:Animations:Leftlegshot");
1808     animation[riflehitanim].Load((char *)":Data:Animations:Riflehit");
1809     animation[grenadeaimanim].Load((char *)":Data:Animations:grenadeaim");
1810     animation[grenadechargeanim].Load((char *)":Data:Animations:grenadecharge");
1811 
1812     loadingscreenamount += 5;
1813 
1814     if(!initialized)
1815       LoadingScreen(loadingscreenamount / loadingscreenamounttotal * 100);
1816 
1817     animation[grenadethrowanim].Load((char *)":Data:Animations:grenadethrow");
1818     animation[zombieeatanim].Load((char *)":Data:Animations:Zombiemunch");
1819     animation[zombiejoganim].Load((char *)":Data:Animations:ZombieRun");
1820     animation[zombiewalkanim].Load((char *)":Data:Animations:Zombiewalk");
1821 
1822     loadingscreenamount += 5;
1823 
1824     if(!initialized)
1825       LoadingScreen(loadingscreenamount / loadingscreenamounttotal * 100);
1826 
1827     animation[getupfrontanim].Load((char *)":Data:Animations:Getupfromfront");
1828     animation[getupbackanim].Load((char *)":Data:Animations:Getupfromback",
1829                                   180);
1830     animation[diveanim].Load((char *)":Data:Animations:Dive");
1831     animation[throwanim].Load((char *)":Data:Animations:Aikidothrow");
1832     animation[thrownanim].Load((char *)":Data:Animations:Aikidothrown");
1833   }
1834   //Setup people
1835   for(int i = 0; i < max_people; i++) {
1836     if(i == 0) {
1837       person[i].whichcostume = bodyguardcostume;
1838     }
1839 
1840     if(i > 1) {
1841       person[i].whichcostume = casualcostumes + abs(Random()) % numcasual;
1842     }
1843     //person[i].firstlongdead=0;
1844     person[i].dead = 0;
1845     person[i].health = 100;
1846     person[i].skeleton.free = 0;
1847     person[i].weapon.ammo = 0;
1848     person[i].velocity = 0;
1849 
1850     //Load skeleton structure
1851     if(!initialized)
1852       person[i].skeleton.Load((char *)":Data:Skeleton:Basic Figure");
1853 
1854     if(i % 5 == 0) {
1855       loadingscreenamount += 5;
1856       if(!initialized)
1857         LoadingScreen(loadingscreenamount / loadingscreenamounttotal * 100);
1858     }
1859   }
1860 
1861   loadingscreenamount += 5;
1862 
1863   if(!initialized)
1864     LoadingScreen(loadingscreenamount / loadingscreenamounttotal * 100);
1865 
1866   if(initialized)
1867     person[0].skeleton.Load((char *)":Data:Skeleton:Basic Figure");
1868 
1869   person[0].attackframe = -1;
1870 
1871   spawndelay = 0;
1872 
1873   fog.SetFog(fog.fogcolor.r, fog.fogcolor.g, fog.fogcolor.b, 0,
1874              environment.viewdistance * .8, .1);
1875 
1876   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1877 
1878   //light
1879   GLfloat LightAmbient[] = { .3, .3, .3, 1.0f };
1880   GLfloat LightDiffuse[] = { 1, 1, 1, 1.0f };
1881 
1882   glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient);
1883   glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse);
1884 
1885   glEnable(GL_LIGHT0);
1886 
1887   loadingscreenamount += 5;
1888 
1889   //Load some textures
1890   if(!initialized) {
1891     LoadingScreen(loadingscreenamount / loadingscreenamounttotal * 100);
1892 
1893     LoadPersonSpriteTexture(":Data:Textures:Personsprite.tga",
1894                             &personspritetextureptr);
1895 
1896     LoadPersonSpriteTexture(":Data:Textures:DeadPersonsprite.tga",
1897                             &deadpersonspritetextureptr);
1898 
1899     LoadPersonSpriteTexture(":Data:Textures:Scope.tga", &scopetextureptr);
1900     LoadPersonSpriteTexture(":Data:Textures:Flare.tga", &flaretextureptr);
1901 
1902     //used by the mainmenu
1903     sprites.LoadSmokeTexture(":Data:Textures:Smoke.tga");
1904     sprites.LoadFlareTexture(":Data:Textures:HitFlash.tga");
1905 
1906     sprites.LoadMuzzleFlareTexture(":Data:Textures:MuzzleFlash.tga");
1907     sprites.LoadBloodTexture(":Data:Textures:Blood.tga");
1908     sprites.LoadRainTexture(":Data:Textures:rain.tga");
1909     sprites.LoadSnowTexture(":Data:Textures:snow.tga");
1910 
1911     decals.LoadBulletHoleTexture(":Data:Textures:BulletHole.tga");
1912 
1913     decals.LoadCraterTexture(":Data:Textures:Crater.tga");
1914 
1915     decals.LoadBloodTexture(":Data:Textures:Blood:Blood1.tga", 0);
1916     decals.LoadBloodTexture(":Data:Textures:Blood:Blood2.tga", 1);
1917     decals.LoadBloodTexture(":Data:Textures:Blood:Blood3.tga", 2);
1918     decals.LoadBloodTexture(":Data:Textures:Blood:Blood4.tga", 3);
1919     decals.LoadBloodTexture(":Data:Textures:Blood:Blood5.tga", 4);
1920     decals.LoadBloodTexture(":Data:Textures:Blood:Blood6.tga", 5);
1921     decals.LoadBloodTexture(":Data:Textures:Blood:Blood7.tga", 6);
1922     decals.LoadBloodTexture(":Data:Textures:Blood:Blood8.tga", 7);
1923     decals.LoadBloodTexture(":Data:Textures:Blood:Blood9.tga", 8);
1924     decals.LoadBloodTexture(":Data:Textures:Blood:Blood10.tga", 9);
1925     decals.LoadBloodTexture(":Data:Textures:Blood:Blood11.tga", 10);
1926   }
1927   //Setup clip plane equation
1928   eqn[0] = 0;
1929   eqn[1] = 1;
1930   eqn[2] = 0;
1931   eqn[3] = 0;
1932 
1933   glClearColor(fog.fogcolor.r, fog.fogcolor.g, fog.fogcolor.b, 1);
1934 
1935   if(!initialized)
1936     InitMouse();
1937 
1938   //Draw city one frame to fix evil menu bug
1939   //if(!initialized)
1940   //  mainmenu = 2;
1941 
1942   if(!initialized) {
1943     LoadingScreen(loadingscreenamount / loadingscreenamounttotal * 100);
1944 
1945     flashamount = 1;
1946 
1947     flashr = 1;
1948     flashg = 1;
1949     flashb = 1;
1950 
1951     alSourcePlay(gSourceID[soulinsound]);
1952   }
1953 
1954   initialized = 1;
1955 
1956   loadingscreenamount += 5;
1957 
1958   decals.howmanydecals = 0;
1959   sprites.howmanysprites = 0;
1960 
1961   losedelay = 1;
1962 
1963   oldscore = score;
1964 
1965   //done loading, now get into the game...
1966   if(config.mainmenuness && !gameinprogress) {
1967     state = MAINMENU;
1968   } else {
1969     gameinprogress = 1;
1970     state = GAME;
1971   }
1972 }
1973 
1974 /* initialize all GUI elements
1975  * - mainmenu
1976  * - in game
1977  * - help
1978  */
InitGUI()1979 void Game::InitGUI()
1980 {
1981   font.LoadFontTexture(":Data:Textures:Font.tga");
1982   font.BuildFont();
1983 
1984   Window *mainmenu = new Window();
1985   mainmenu->setName("mainmenu");
1986 
1987   Button *button = new Button();
1988   button->setName("button1");
1989   button->setButton(0.1875, 0.49, 0.6875, 0.145);
1990   mainmenu->attach(button);
1991 
1992   button = new Button();
1993   button->setName("button2");
1994   button->setButton(0.1875, 0.233, 0.6875, 0.195);
1995   mainmenu->attach(button);
1996 
1997   Label *label = new Label();
1998   label->setName("title");
1999   label->setFont(1, font.base, font.FontTexture);
2000   label->setLabel(0.156, 0.365, 2 * (screenheight / 480));
2001   label->setText("Black Shades");
2002   mainmenu->attach(label);
2003 
2004   Image *image = new Image();
2005   image->setName("title_image1");
2006   image->setDim(0.094, 0.698, 0.781, 0.146);
2007   image->setImage(sprites.smoketextureptr, 0);
2008   label->attach(image);
2009 
2010   image = new Image();
2011   image->setName("title_image2");
2012   image->setDim(0.094, 0.698, 0.828, 0.1);
2013   image->setImage(flaretextureptr, 0);
2014   label->attach(image);
2015 
2016   label = new Label();
2017   label->setName("game");
2018   label->setFont(1, font.base, font.FontTexture);
2019   label->setLabel(0.308, 0.35, 1.5);
2020   mainmenu->attach(label);
2021 
2022   image = new Image();
2023   image->setName("game_image1");
2024   image->setDim(0.1875, 0.49, 0.688, 0.146);
2025   image->setImage(sprites.smoketextureptr, 0);
2026   image->setImage(flaretextureptr, 1);
2027   image->setColor(Color(1.0, 0.0, 0.0, 1.0));
2028   label->attach(image);
2029 
2030   image = new Image();
2031   image->setName("game_image2");
2032   image->setDim(0.1875, 0.49, 0.719, 0.1);
2033   image->setImage(sprites.smoketextureptr, 0);
2034   image->setImage(flaretextureptr, 1);
2035   image->setColor(Color(1.0, 0.0, 0.0, 1.0));
2036   label->attach(image);
2037 
2038   label = new Label();
2039   label->setName("quit");
2040   label->setFont(1, font.base, font.FontTexture);
2041   label->setLabel(0.308, 0.181, 1.5);
2042   mainmenu->attach(label);
2043 
2044   image = new Image();
2045   image->setName("quit_image1");
2046   image->setDim(0.1875, 0.233, 0.688, 0.146);
2047   image->setImage(sprites.smoketextureptr, 0);
2048   image->setImage(flaretextureptr, 1);
2049   image->setColor(Color(1.0, 0.0, 0.0, 1.0));
2050   label->attach(image);
2051 
2052   image = new Image();
2053   image->setName("quit_image2");
2054   image->setDim(0.1875, 0.233, 0.719, 0.1);
2055   image->setImage(sprites.smoketextureptr, 0);
2056   image->setImage(flaretextureptr, 1);
2057   image->setColor(Color(1.0, 0.0, 0.0, 1.0));
2058   label->attach(image);
2059 
2060   WindowMgr::getInstance().getRoot()->attach(mainmenu);
2061 
2062   ///TODO: Add sub windows to easily not draw certain windows
2063   Window *ingame = new Window();
2064   ingame->setName("ingame");
2065 
2066   label = new Label();
2067   label->setName("weapon");
2068   label->setFont(1, font.base, font.FontTexture);
2069   label->setColor(Color(1.0, 1.0, 1.0, 1.0));
2070   label->setLabel(0.016, 0.1875, 0.8);
2071   ingame->attach(label);
2072 
2073   label = new Label();
2074   label->setName("magazines");
2075   label->setFont(0, font.base, font.FontTexture);
2076   label->setColor(Color(0.0, 1.0, 0.0, 1.0));
2077   label->setLabel(0.016, 0.140, 0.8);
2078   ingame->attach(label);
2079 
2080   label = new Label();
2081   label->setName("magazines_num");
2082   label->setFont(1, font.base, font.FontTexture);
2083   label->setColor(Color(1.0, 1.0, 1.0, 1.0));
2084   label->setLabel(0.016, 0.085, 1.0);
2085   ingame->attach(label);
2086 
2087   label = new Label();
2088   label->setName("ammo");
2089   label->setFont(0, font.base, font.FontTexture);
2090   label->setColor(Color(0.0, 1.0, 0.0, 1.0));
2091   label->setLabel(0.016, 0.060, 0.8);
2092   ingame->attach(label);
2093 
2094   label = new Label();
2095   label->setName("ammo_num");
2096   label->setFont(1, font.base, font.FontTexture);
2097   label->setColor(Color(1.0, 1.0, 1.0, 1.0));
2098   label->setLabel(0.016, 0.020, 1.0);
2099   ingame->attach(label);
2100 
2101   label = new Label();
2102   label->setName("score");
2103   label->setFont(0, font.base, font.FontTexture);
2104   label->setColor(Color(1.0, 1.0, 0.0, 1.0));
2105   label->setLabel(1.133, 1.198, 0.8);
2106   label->setText("Score");
2107   ingame->attach(label);
2108 
2109   label = new Label();
2110   label->setName("score_val");
2111   label->setFont(1, font.base, font.FontTexture);
2112   label->setColor(Color(1.0, 1.0, 1.0, 1.0));
2113   label->setLabel(0.906, 0.917, 1.0);
2114   ingame->attach(label);
2115 
2116   label = new Label();
2117   label->setName("time");
2118   label->setFont(0, font.base, font.FontTexture);
2119   label->setColor(Color(1.0, 1.0, 0.0, 1.0));
2120   label->setLabel(0.07, 1.198, 0.8);
2121   label->setText("Time Remaining");
2122   ingame->attach(label);
2123 
2124   label = new Label();
2125   label->setName("time_val");
2126   label->setFont(1, font.base, font.FontTexture);
2127   label->setColor(Color(1.0, 1.0, 1.0, 1.0));
2128   label->setLabel(0.1, 0.917, 1.0);
2129   ingame->attach(label);
2130 
2131   label = new Label();
2132   label->setName("help_me");
2133   label->setFont(1, font.base, font.FontTexture);
2134   label->setColor(Color(1.0, 1.0, 1.0, 1.0));
2135   label->setLabel(0.94, 0.02, 0.9);
2136   label->setText("Help = F1");
2137   ingame->attach(label);
2138 
2139   label = new Label();
2140   label->setName("mission");
2141   label->setFont(1, font.base, font.FontTexture);
2142   label->setColor(Color(1.0, 1.0, 1.0, 1.0));
2143   label->setLabel(0.94, 0.12, 0.9);
2144   ingame->attach(label);
2145 
2146   WindowMgr::getInstance().getRoot()->attach(ingame);
2147 
2148   Window *help_screen = new Window();
2149   help_screen->setName("helpscreen");
2150 
2151   label = new Label();
2152   label->setName("controls");
2153   label->setFont(1, font.base, font.FontTexture);
2154   label->setLabel(0.01, 1.04, 0.9);
2155   label->setColor(Color(0.5, 0.5, 0.5, 1.0));
2156   label->setText("Controls");
2157   help_screen->attach(label);
2158 
2159   label = new Label();
2160   label->setName("move");
2161   label->setFont(1, font.base, font.FontTexture);
2162   label->setLabel(0.02, 1.12, 0.8);
2163   label->setColor(Color(0.5, 0.5, 0.5, 1.0));
2164   label->setText("WASD = walk");
2165   help_screen->attach(label);
2166 
2167   label = new Label();
2168   label->setName("run");
2169   label->setFont(1, font.base, font.FontTexture);
2170   label->setLabel(0.02, 1.08, 0.8);
2171   label->setColor(Color(0.5, 0.5, 0.5, 1.0));
2172   label->setText("shift = run");
2173   help_screen->attach(label);
2174 
2175   label = new Label();
2176   label->setName("crouch");
2177   label->setFont(1, font.base, font.FontTexture);
2178   label->setLabel(0.02, 1.04, 0.8);
2179   label->setColor(Color(0.5, 0.5, 0.5, 1.0));
2180   label->setText("control = crouch/zoom");
2181   help_screen->attach(label);
2182 
2183   label = new Label();
2184   label->setName("click");
2185   label->setFont(1, font.base, font.FontTexture);
2186   label->setLabel(0.02, 1.00, 0.8);
2187   label->setColor(Color(0.5, 0.5, 0.5, 1.0));
2188   label->setText("click = fire (while aiming) or smash (while running) or");
2189   help_screen->attach(label);
2190 
2191   label = new Label();
2192   label->setName("click");
2193   label->setFont(1, font.base, font.FontTexture);
2194   label->setLabel(0.02, 0.96, 0.8);
2195   label->setColor(Color(0.5, 0.5, 0.5, 1.0));
2196   label->setText("pick up gun (crouching, not aim) or disarm (not aim)");
2197   help_screen->attach(label);
2198 
2199   label = new Label();
2200   label->setName("aim");
2201   label->setFont(1, font.base, font.FontTexture);
2202   label->setLabel(0.02, 0.92, 0.8);
2203   label->setColor(Color(0.5, 0.5, 0.5, 1.0));
2204   label->setText("q = aim or un-aim (important for picking up guns)");
2205   help_screen->attach(label);
2206 
2207   label = new Label();
2208   label->setName("reload");
2209   label->setFont(1, font.base, font.FontTexture);
2210   label->setLabel(0.02, 0.88, 0.8);
2211   label->setColor(Color(0.5, 0.5, 0.5, 1.0));
2212   label->setText("r = reload");
2213   help_screen->attach(label);
2214 
2215   label = new Label();
2216   label->setName("psychic");
2217   label->setFont(1, font.base, font.FontTexture);
2218   label->setLabel(0.02, 0.84, 0.8);
2219   label->setColor(Color(0.5, 0.5, 0.5, 1.0));
2220   label->setText("e = psychic aim");
2221   help_screen->attach(label);
2222 
2223   label = new Label();
2224   label->setName("soul");
2225   label->setFont(1, font.base, font.FontTexture);
2226   label->setLabel(0.02, 0.80, 0.8);
2227   label->setColor(Color(0.5, 0.5, 0.5, 1.0));
2228   label->setText("z = toggle soul release");
2229   help_screen->attach(label);
2230 
2231   label = new Label();
2232   label->setName("dive");
2233   label->setFont(1, font.base, font.FontTexture);
2234   label->setLabel(0.02, 0.76, 0.8);
2235   label->setColor(Color(0.5, 0.5, 0.5, 1.0));
2236   label->setText("space = dive (while running forwards)");
2237   help_screen->attach(label);
2238 
2239   label = new Label();
2240   label->setName("3rd");
2241   label->setFont(1, font.base, font.FontTexture);
2242   label->setLabel(0.02, 0.72, 0.8);
2243   label->setColor(Color(0.5, 0.5, 0.5, 1.0));
2244   label->setText("tab = 3rd person toggle");
2245   help_screen->attach(label);
2246 
2247   label = new Label();
2248   label->setName("laser");
2249   label->setFont(1, font.base, font.FontTexture);
2250   label->setLabel(0.02, 0.68, 0.8);
2251   label->setColor(Color(0.5, 0.5, 0.5, 1.0));
2252   label->setText("l = lasersight");
2253   help_screen->attach(label);
2254 
2255   label = new Label();
2256   label->setName("screenshot");
2257   label->setFont(1, font.base, font.FontTexture);
2258   label->setLabel(0.02, 0.64, 0.8);
2259   label->setColor(Color(0.5, 0.5, 0.5, 1.0));
2260   label->setText("F12 = screenshot");
2261   help_screen->attach(label);
2262 
2263   WindowMgr::getInstance().getRoot()->attach(help_screen);
2264 }
2265 
Dispose()2266 void Game::Dispose()
2267 {
2268   //Delete sound sources
2269   alDeleteSources(100, gSourceID);
2270 
2271   //FIXME: dunno if window deleting is done correctly
2272   //delete WindowMgr::getInstance().getRoot();
2273 }
2274 
2275 
2276