]> git.jsancho.org Git - lugaru.git/blob - Source/GameInitDispose.cpp
Applied clang-format on all files
[lugaru.git] / Source / GameInitDispose.cpp
1 /*
2 Copyright (C) 2003, 2010 - Wolfire Games
3 Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
4
5 This file is part of Lugaru.
6
7 Lugaru is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 Lugaru is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "Game.hpp"
22
23 #include "Animation/Animation.hpp"
24 #include "Audio/openal_wrapper.hpp"
25 #include "Graphic/Texture.hpp"
26 #include "Menu/Menu.hpp"
27 #include "Utils/Folders.hpp"
28
29 extern float screenwidth, screenheight;
30 extern float viewdistance;
31 extern XYZ viewer;
32 extern float fadestart;
33 extern float texscale;
34 extern float gravity;
35 extern Light light;
36 extern Terrain terrain;
37 extern int kTextureSize;
38 extern float texdetail;
39 extern float realtexdetail;
40 extern float volume;
41 extern int detail;
42 extern bool cellophane;
43 extern GLubyte bloodText[512 * 512 * 3];
44 extern GLubyte wolfbloodText[512 * 512 * 3];
45 extern bool ismotionblur;
46 extern bool trilinear;
47 extern bool musictoggle;
48 extern int environment;
49 extern bool ambientsound;
50 extern float multiplier;
51 extern int netdatanew;
52 extern float mapinfo;
53 extern bool stillloading;
54 extern int mainmenu;
55 extern bool visibleloading;
56 extern float flashamount, flashr, flashg, flashb;
57 extern int flashdelay;
58 extern int whichjointstartarray[26];
59 extern int whichjointendarray[26];
60 extern float slomospeed;
61 extern bool gamestarted;
62
63 extern float accountcampaignhighscore[10];
64 extern float accountcampaignfasttime[10];
65 extern float accountcampaignscore[10];
66 extern float accountcampaigntime[10];
67
68 extern int accountcampaignchoicesmade[10];
69 extern int accountcampaignchoices[10][5000];
70
71 void LOG(const std::string&, ...)
72 {
73     // !!! FIXME: write me.
74 }
75
76 void Dispose()
77 {
78     LOGFUNC;
79
80     if (Game::endgame == 2) {
81         Account::active().endGame();
82         Game::endgame = 0;
83     }
84
85     Account::saveFile(Folders::getUserSavePath());
86
87     //textures.clear();
88
89     LOG("Shutting down sound system...");
90
91     OPENAL_StopSound(OPENAL_ALL);
92
93 // this is causing problems on Linux, but we'll force an _exit() a little
94 //  later in the shutdown process.  --ryan.
95 #if !PLATFORM_LINUX
96
97     for (int i = 0; i < sounds_count; ++i) {
98         OPENAL_Sample_Free(samp[i]);
99     }
100
101     OPENAL_Close();
102 #endif
103 }
104
105 void Game::newGame()
106 {
107     text = new Text();
108     textmono = new Text();
109     skybox = new SkyBox();
110 }
111
112 void Game::deleteGame()
113 {
114     delete skybox;
115     delete text;
116     delete textmono;
117
118     glDeleteTextures(1, &screentexture);
119     glDeleteTextures(1, &screentexture2);
120
121     Dispose();
122 }
123
124 void LoadSave(const std::string& fileName, GLubyte* array)
125 {
126     LOGFUNC;
127
128     LOG(std::string("Loading (S)...") + fileName);
129
130     //Load Image
131     float temptexdetail = texdetail;
132     texdetail = 1;
133
134     //Load Image
135     ImageRec texture;
136     if (!load_image(Folders::getResourcePath(fileName).c_str(), texture)) {
137         texdetail = temptexdetail;
138         return;
139     }
140     texdetail = temptexdetail;
141
142     int bytesPerPixel = texture.bpp / 8;
143
144     int tempnum = 0;
145     for (int i = 0; i < (int)(texture.sizeY * texture.sizeX * bytesPerPixel); i++) {
146         if ((i + 1) % 4 || bytesPerPixel == 3) {
147             array[tempnum] = texture.data[i];
148             tempnum++;
149         }
150     }
151 }
152
153 //***************> ResizeGLScene() <******/
154 GLvoid Game::ReSizeGLScene(float fov, float pnear)
155 {
156     if (screenheight == 0) {
157         screenheight = 1;
158     }
159
160     glViewport(0, 0, screenwidth, screenheight);
161
162     glMatrixMode(GL_PROJECTION);
163     glLoadIdentity();
164
165     gluPerspective(fov, (GLfloat)screenwidth / (GLfloat)screenheight, pnear, viewdistance);
166
167     glMatrixMode(GL_MODELVIEW);
168     glLoadIdentity();
169 }
170
171 void Game::LoadingScreen()
172 {
173     if (!visibleloading) {
174         return;
175     }
176
177     static float loadprogress;
178     static AbsoluteTime frametime = { 0, 0 };
179     AbsoluteTime currTime = UpTime();
180     double deltaTime = (float)AbsoluteDeltaToDuration(currTime, frametime);
181
182     if (0 > deltaTime) // if negative microseconds
183         deltaTime /= -1000000.0;
184     else // else milliseconds
185         deltaTime /= 1000.0;
186
187     multiplier = deltaTime;
188     if (multiplier < .001)
189         multiplier = .001;
190     if (multiplier > 10)
191         multiplier = 10;
192     if (multiplier > .05) {
193         frametime = currTime; // reset for next time interval
194
195         glLoadIdentity();
196         //Clear to black
197         glClearColor(0, 0, 0, 1);
198         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
199
200         loadtime += multiplier * 4;
201
202         loadprogress = loadtime;
203         if (loadprogress > 100)
204             loadprogress = 100;
205
206         //Background
207
208         glEnable(GL_TEXTURE_2D);
209         loadscreentexture.bind();
210         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
211         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
212         glDisable(GL_DEPTH_TEST);
213         glDisable(GL_CULL_FACE);
214         glDisable(GL_LIGHTING);
215         glDepthMask(0);
216         glMatrixMode(GL_PROJECTION);
217         glPushMatrix();
218         glLoadIdentity();
219         glOrtho(0, screenwidth, 0, screenheight, -100, 100);
220         glMatrixMode(GL_MODELVIEW);
221         glPushMatrix();
222         glLoadIdentity();
223         glTranslatef(screenwidth / 2, screenheight / 2, 0);
224         glScalef((float)screenwidth / 2, (float)screenheight / 2, 1);
225         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
226         glDisable(GL_BLEND);
227         glColor4f(loadprogress / 100, loadprogress / 100, loadprogress / 100, 1);
228         glPushMatrix();
229         glBegin(GL_QUADS);
230         glTexCoord2f(.1 - loadprogress / 100, 0 + loadprogress / 100 + .3);
231         glVertex3f(-1, -1, 0.0f);
232         glTexCoord2f(.1 - loadprogress / 100, 0 + loadprogress / 100 + .3);
233         glVertex3f(1, -1, 0.0f);
234         glTexCoord2f(.1 - loadprogress / 100, 1 + loadprogress / 100 + .3);
235         glVertex3f(1, 1, 0.0f);
236         glTexCoord2f(.1 - loadprogress / 100, 1 + loadprogress / 100 + .3);
237         glVertex3f(-1, 1, 0.0f);
238         glEnd();
239         glPopMatrix();
240         glEnable(GL_BLEND);
241         glPushMatrix();
242         glBegin(GL_QUADS);
243         glTexCoord2f(.4 + loadprogress / 100, 0 + loadprogress / 100);
244         glVertex3f(-1, -1, 0.0f);
245         glTexCoord2f(.4 + loadprogress / 100, 0 + loadprogress / 100);
246         glVertex3f(1, -1, 0.0f);
247         glTexCoord2f(.4 + loadprogress / 100, 1 + loadprogress / 100);
248         glVertex3f(1, 1, 0.0f);
249         glTexCoord2f(.4 + loadprogress / 100, 1 + loadprogress / 100);
250         glVertex3f(-1, 1, 0.0f);
251         glEnd();
252         glPopMatrix();
253         glDisable(GL_TEXTURE_2D);
254         glMatrixMode(GL_PROJECTION);
255         glPopMatrix();
256         glMatrixMode(GL_MODELVIEW);
257         glPopMatrix();
258         glDisable(GL_BLEND);
259         glDepthMask(1);
260
261         glEnable(GL_TEXTURE_2D);
262         loadscreentexture.bind();
263         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
264         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
265         glDisable(GL_DEPTH_TEST);
266         glDisable(GL_CULL_FACE);
267         glDisable(GL_LIGHTING);
268         glDepthMask(0);
269         glMatrixMode(GL_PROJECTION);
270         glPushMatrix();
271         glLoadIdentity();
272         glOrtho(0, screenwidth, 0, screenheight, -100, 100);
273         glMatrixMode(GL_MODELVIEW);
274         glPushMatrix();
275         glLoadIdentity();
276         glTranslatef(screenwidth / 2, screenheight / 2, 0);
277         glScalef((float)screenwidth / 2 * (1.5 - (loadprogress) / 200), (float)screenheight / 2 * (1.5 - (loadprogress) / 200), 1);
278         glBlendFunc(GL_SRC_ALPHA, GL_ONE);
279         glEnable(GL_BLEND);
280         glColor4f(loadprogress / 100, loadprogress / 100, loadprogress / 100, 1);
281         glPushMatrix();
282         glBegin(GL_QUADS);
283         glTexCoord2f(0 + .5, 0 + .5);
284         glVertex3f(-1, -1, 0.0f);
285         glTexCoord2f(1 + .5, 0 + .5);
286         glVertex3f(1, -1, 0.0f);
287         glTexCoord2f(1 + .5, 1 + .5);
288         glVertex3f(1, 1, 0.0f);
289         glTexCoord2f(0 + .5, 1 + .5);
290         glVertex3f(-1, 1, 0.0f);
291         glEnd();
292         glPopMatrix();
293         glDisable(GL_TEXTURE_2D);
294         glMatrixMode(GL_PROJECTION);
295         glPopMatrix();
296         glMatrixMode(GL_MODELVIEW);
297         glPopMatrix();
298         glDisable(GL_BLEND);
299         glDepthMask(1);
300
301         glEnable(GL_TEXTURE_2D);
302         loadscreentexture.bind();
303         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
304         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
305         glDisable(GL_DEPTH_TEST);
306         glDisable(GL_CULL_FACE);
307         glDisable(GL_LIGHTING);
308         glDepthMask(0);
309         glMatrixMode(GL_PROJECTION);
310         glPushMatrix();
311         glLoadIdentity();
312         glOrtho(0, screenwidth, 0, screenheight, -100, 100);
313         glMatrixMode(GL_MODELVIEW);
314         glPushMatrix();
315         glLoadIdentity();
316         glTranslatef(screenwidth / 2, screenheight / 2, 0);
317         glScalef((float)screenwidth / 2 * (100 + loadprogress) / 100, (float)screenheight / 2 * (100 + loadprogress) / 100, 1);
318         glBlendFunc(GL_SRC_ALPHA, GL_ONE);
319         glEnable(GL_BLEND);
320         glColor4f(loadprogress / 100, loadprogress / 100, loadprogress / 100, .4);
321         glPushMatrix();
322         glBegin(GL_QUADS);
323         glTexCoord2f(0 + .2, 0 + .8);
324         glVertex3f(-1, -1, 0.0f);
325         glTexCoord2f(1 + .2, 0 + .8);
326         glVertex3f(1, -1, 0.0f);
327         glTexCoord2f(1 + .2, 1 + .8);
328         glVertex3f(1, 1, 0.0f);
329         glTexCoord2f(0 + .2, 1 + .8);
330         glVertex3f(-1, 1, 0.0f);
331         glEnd();
332         glPopMatrix();
333         glDisable(GL_TEXTURE_2D);
334         glMatrixMode(GL_PROJECTION);
335         glPopMatrix();
336         glMatrixMode(GL_MODELVIEW);
337         glPopMatrix();
338         glDisable(GL_BLEND);
339         glDepthMask(1);
340
341         //Text
342
343         if (flashamount > 0) {
344             if (flashamount > 1)
345                 flashamount = 1;
346             if (flashdelay <= 0)
347                 flashamount -= multiplier;
348             flashdelay--;
349             if (flashamount < 0)
350                 flashamount = 0;
351             glDisable(GL_DEPTH_TEST);
352             glDisable(GL_CULL_FACE);
353             glDisable(GL_LIGHTING);
354             glDisable(GL_TEXTURE_2D);
355             glDepthMask(0);
356             glMatrixMode(GL_PROJECTION);
357             glPushMatrix();
358             glLoadIdentity();
359             glOrtho(0, screenwidth, 0, screenheight, -100, 100);
360             glMatrixMode(GL_MODELVIEW);
361             glPushMatrix();
362             glLoadIdentity();
363             glScalef(screenwidth, screenheight, 1);
364             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
365             glEnable(GL_BLEND);
366             glColor4f(flashr, flashg, flashb, flashamount);
367             glBegin(GL_QUADS);
368             glVertex3f(0, 0, 0.0f);
369             glVertex3f(256, 0, 0.0f);
370             glVertex3f(256, 256, 0.0f);
371             glVertex3f(0, 256, 0.0f);
372             glEnd();
373             glMatrixMode(GL_PROJECTION);
374             glPopMatrix();
375             glMatrixMode(GL_MODELVIEW);
376             glPopMatrix();
377             glEnable(GL_DEPTH_TEST);
378             glEnable(GL_CULL_FACE);
379             glDisable(GL_BLEND);
380             glDepthMask(1);
381         }
382
383         swap_gl_buffers();
384     }
385 }
386
387 void FadeLoadingScreen(float howmuch)
388 {
389     static float loadprogress;
390
391     glLoadIdentity();
392     //Clear to black
393     glClearColor(0, 0, 0, 1);
394     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
395
396     loadprogress = howmuch;
397
398     //Background
399
400     glDisable(GL_TEXTURE_2D);
401     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
402     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
403     glDisable(GL_DEPTH_TEST);
404     glDisable(GL_CULL_FACE);
405     glDisable(GL_LIGHTING);
406     glDepthMask(0);
407     glMatrixMode(GL_PROJECTION);
408     glPushMatrix();
409     glLoadIdentity();
410     glOrtho(0, screenwidth, 0, screenheight, -100, 100);
411     glMatrixMode(GL_MODELVIEW);
412     glPushMatrix();
413     glLoadIdentity();
414     glTranslatef(screenwidth / 2, screenheight / 2, 0);
415     glScalef((float)screenwidth / 2, (float)screenheight / 2, 1);
416     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
417     glDisable(GL_BLEND);
418     glColor4f(loadprogress / 100, 0, 0, 1);
419     glPushMatrix();
420     glBegin(GL_QUADS);
421     glTexCoord2f(0, 0);
422     glVertex3f(-1, -1, 0.0f);
423     glTexCoord2f(1, 0);
424     glVertex3f(1, -1, 0.0f);
425     glTexCoord2f(1, 1);
426     glVertex3f(1, 1, 0.0f);
427     glTexCoord2f(0, 1);
428     glVertex3f(-1, 1, 0.0f);
429     glEnd();
430     glPopMatrix();
431     glDisable(GL_TEXTURE_2D);
432     glMatrixMode(GL_PROJECTION);
433     glPopMatrix();
434     glMatrixMode(GL_MODELVIEW);
435     glPopMatrix();
436     glDisable(GL_BLEND);
437     glDepthMask(1);
438     //Text
439     swap_gl_buffers();
440 }
441
442 void Game::InitGame()
443 {
444     LOGFUNC;
445
446     numchallengelevels = 14;
447
448     Account::loadFile(Folders::getUserSavePath());
449
450     whichjointstartarray[0] = righthip;
451     whichjointendarray[0] = rightfoot;
452
453     whichjointstartarray[1] = righthip;
454     whichjointendarray[1] = rightankle;
455
456     whichjointstartarray[2] = righthip;
457     whichjointendarray[2] = rightknee;
458
459     whichjointstartarray[3] = rightknee;
460     whichjointendarray[3] = rightankle;
461
462     whichjointstartarray[4] = rightankle;
463     whichjointendarray[4] = rightfoot;
464
465     whichjointstartarray[5] = lefthip;
466     whichjointendarray[5] = leftfoot;
467
468     whichjointstartarray[6] = lefthip;
469     whichjointendarray[6] = leftankle;
470
471     whichjointstartarray[7] = lefthip;
472     whichjointendarray[7] = leftknee;
473
474     whichjointstartarray[8] = leftknee;
475     whichjointendarray[8] = leftankle;
476
477     whichjointstartarray[9] = leftankle;
478     whichjointendarray[9] = leftfoot;
479
480     whichjointstartarray[10] = abdomen;
481     whichjointendarray[10] = rightshoulder;
482
483     whichjointstartarray[11] = abdomen;
484     whichjointendarray[11] = rightelbow;
485
486     whichjointstartarray[12] = abdomen;
487     whichjointendarray[12] = rightwrist;
488
489     whichjointstartarray[13] = abdomen;
490     whichjointendarray[13] = righthand;
491
492     whichjointstartarray[14] = rightshoulder;
493     whichjointendarray[14] = rightelbow;
494
495     whichjointstartarray[15] = rightelbow;
496     whichjointendarray[15] = rightwrist;
497
498     whichjointstartarray[16] = rightwrist;
499     whichjointendarray[16] = righthand;
500
501     whichjointstartarray[17] = abdomen;
502     whichjointendarray[17] = leftshoulder;
503
504     whichjointstartarray[18] = abdomen;
505     whichjointendarray[18] = leftelbow;
506
507     whichjointstartarray[19] = abdomen;
508     whichjointendarray[19] = leftwrist;
509
510     whichjointstartarray[20] = abdomen;
511     whichjointendarray[20] = lefthand;
512
513     whichjointstartarray[21] = leftshoulder;
514     whichjointendarray[21] = leftelbow;
515
516     whichjointstartarray[22] = leftelbow;
517     whichjointendarray[22] = leftwrist;
518
519     whichjointstartarray[23] = leftwrist;
520     whichjointendarray[23] = lefthand;
521
522     whichjointstartarray[24] = abdomen;
523     whichjointendarray[24] = neck;
524
525     whichjointstartarray[25] = neck;
526     whichjointendarray[25] = head;
527
528     FadeLoadingScreen(0);
529
530     stillloading = 1;
531
532     int temptexdetail = texdetail;
533     texdetail = 1;
534     text->LoadFontTexture("Textures/Font.png");
535     text->BuildFont();
536     textmono->LoadFontTexture("Textures/FontMono.png");
537     textmono->BuildFont();
538     texdetail = temptexdetail;
539
540     FadeLoadingScreen(10);
541
542     if (detail == 2) {
543         texdetail = 1;
544     }
545     if (detail == 1) {
546         texdetail = 2;
547     }
548     if (detail == 0) {
549         texdetail = 4;
550     }
551
552     LOG("Initializing sound system...");
553
554     OPENAL_Init(44100, 32, 0);
555
556     OPENAL_SetSFXMasterVolume((int)(volume * 255));
557     loadAllSounds();
558
559     if (musictoggle)
560         emit_stream_np(stream_menutheme);
561
562     cursortexture.load("Textures/Cursor.png", 0);
563
564     Mapcircletexture.load("Textures/MapCircle.png", 0);
565     Mapboxtexture.load("Textures/MapBox.png", 0);
566     Maparrowtexture.load("Textures/MapArrow.png", 0);
567
568     temptexdetail = texdetail;
569     if (texdetail > 2)
570         texdetail = 2;
571     Mainmenuitems[0].load("Textures/Lugaru.png", 0);
572     Mainmenuitems[1].load("Textures/NewGame.png", 0);
573     Mainmenuitems[2].load("Textures/Options.png", 0);
574     Mainmenuitems[3].load("Textures/Quit.png", 0);
575     Mainmenuitems[4].load("Textures/Eyelid.png", 0);
576     Mainmenuitems[5].load("Textures/Resume.png", 0);
577     Mainmenuitems[6].load("Textures/EndGame.png", 0);
578
579     texdetail = temptexdetail;
580
581     FadeLoadingScreen(95);
582
583     gameon = 0;
584     mainmenu = 1;
585
586     stillloading = 0;
587     firstLoadDone = false;
588
589     newdetail = detail;
590     newscreenwidth = screenwidth;
591     newscreenheight = screenheight;
592
593     Menu::Load();
594
595     Animation::loadAll();
596 }
597
598 void Game::LoadScreenTexture()
599 {
600     glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
601
602     if (!Game::screentexture)
603         glGenTextures(1, &Game::screentexture);
604     glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
605
606     glEnable(GL_TEXTURE_2D);
607     glBindTexture(GL_TEXTURE_2D, Game::screentexture);
608     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
609     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
610
611     glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);
612 }
613
614 //TODO: move LoadStuff() closer to GameTick.cpp to get rid of various vars shared in Game.hpp
615 /* Loads models and textures which only needs to be loaded once */
616 void Game::LoadStuff()
617 {
618     float temptexdetail;
619     float viewdistdetail;
620     float megascale = 1;
621
622     LOGFUNC;
623
624     loadtime = 0;
625
626     stillloading = 1;
627
628     visibleloading = false; //don't use loadscreentexture yet
629     loadscreentexture.load("Textures/Fire.jpg", 1);
630     visibleloading = true;
631
632     temptexdetail = texdetail;
633     texdetail = 1;
634     text->LoadFontTexture("Textures/Font.png");
635     text->BuildFont();
636     textmono->LoadFontTexture("Textures/FontMono.png");
637     textmono->BuildFont();
638     texdetail = temptexdetail;
639
640     viewdistdetail = 2;
641     viewdistance = 50 * megascale * viewdistdetail;
642
643     if (detail == 2) {
644         texdetail = 1;
645         kTextureSize = 1024;
646     } else if (detail == 1) {
647         texdetail = 2;
648         kTextureSize = 512;
649     } else {
650         texdetail = 4;
651         kTextureSize = 256;
652     }
653
654     realtexdetail = texdetail;
655
656     Weapon::Load();
657
658     terrain.shadowtexture.load("Textures/Shadow.png", 0);
659     terrain.bloodtexture.load("Textures/Blood.png", 0);
660     terrain.breaktexture.load("Textures/Break.png", 0);
661     terrain.bloodtexture2.load("Textures/Blood.png", 0);
662
663     terrain.footprinttexture.load("Textures/Footprint.png", 0);
664     terrain.bodyprinttexture.load("Textures/Bodyprint.png", 0);
665     hawktexture.load("Textures/Hawk.png", 0);
666
667     Sprite::cloudtexture.load("Textures/Cloud.png", 1);
668     Sprite::cloudimpacttexture.load("Textures/CloudImpact.png", 1);
669     Sprite::bloodtexture.load("Textures/BloodParticle.png", 1);
670     Sprite::snowflaketexture.load("Textures/SnowFlake.png", 1);
671     Sprite::flametexture.load("Textures/Flame.png", 1);
672     Sprite::bloodflametexture.load("Textures/BloodFlame.png", 1);
673     Sprite::smoketexture.load("Textures/Smoke.png", 1);
674     Sprite::shinetexture.load("Textures/Shine.png", 1);
675     Sprite::splintertexture.load("Textures/Splinter.png", 1);
676     Sprite::leaftexture.load("Textures/Leaf.png", 1);
677     Sprite::toothtexture.load("Textures/Tooth.png", 1);
678
679     yaw = 0;
680     pitch = 0;
681     ReSizeGLScene(90, .01);
682
683     viewer = 0;
684
685     //Set up distant light
686     light.color[0] = .95;
687     light.color[1] = .95;
688     light.color[2] = 1;
689     light.ambient[0] = .2;
690     light.ambient[1] = .2;
691     light.ambient[2] = .24;
692     light.location.x = 1;
693     light.location.y = 1;
694     light.location.z = -.2;
695     Normalise(&light.location);
696
697     LoadingScreen();
698
699     SetUpLighting();
700
701     fadestart = .6;
702     gravity = -10;
703
704     texscale = .2 / megascale / viewdistdetail;
705     terrain.scale = 3 * megascale * viewdistdetail;
706
707     viewer.x = terrain.size / 2 * terrain.scale;
708     viewer.z = terrain.size / 2 * terrain.scale;
709
710     hawk.load("Models/Hawk.solid");
711     hawk.Scale(.03, .03, .03);
712     hawk.Rotate(90, 1, 1);
713     hawk.CalculateNormals(0);
714     hawk.ScaleNormals(-1, -1, -1);
715     hawkcoords.x = terrain.size / 2 * terrain.scale - 5 - 7;
716     hawkcoords.z = terrain.size / 2 * terrain.scale - 5 - 7;
717     hawkcoords.y = terrain.getHeight(hawkcoords.x, hawkcoords.z) + 25;
718
719     eye.load("Models/Eye.solid");
720     eye.Scale(.03, .03, .03);
721     eye.CalculateNormals(0);
722
723     cornea.load("Models/Cornea.solid");
724     cornea.Scale(.03, .03, .03);
725     cornea.CalculateNormals(0);
726
727     iris.load("Models/Iris.solid");
728     iris.Scale(.03, .03, .03);
729     iris.CalculateNormals(0);
730
731     LoadSave("Textures/BloodFur.png", &bloodText[0]);
732     LoadSave("Textures/WolfBloodFur.png", &wolfbloodText[0]);
733
734     oldenvironment = -4;
735
736     gameon = 1;
737     mainmenu = 0;
738
739     //Fix knife stab, too lazy to do it manually
740     XYZ moveamount;
741     moveamount = 0;
742     moveamount.z = 2;
743     // FIXME - Why this uses skeleton.joints.size() and not Animation::numjoints? (are they equal?)
744     // It seems skeleton.joints.size() is 0 at this point, so this is useless.
745     for (unsigned i = 0; i < Person::players[0]->skeleton.joints.size(); i++) {
746         for (unsigned j = 0; j < Animation::animations[knifesneakattackanim].frames.size(); j++) {
747             Animation::animations[knifesneakattackanim].frames[j].joints[i].position += moveamount;
748         }
749     }
750
751     LoadingScreen();
752
753     for (unsigned i = 0; i < Person::players[0]->skeleton.joints.size(); i++) {
754         for (unsigned j = 0; j < Animation::animations[knifesneakattackedanim].frames.size(); j++) {
755             Animation::animations[knifesneakattackedanim].frames[j].joints[i].position += moveamount;
756         }
757     }
758
759     LoadingScreen();
760
761     for (unsigned i = 0; i < Person::players[0]->skeleton.joints.size(); i++) {
762         Animation::animations[dead1anim].frames[1].joints[i].position = Animation::animations[dead1anim].frames[0].joints[i].position;
763         Animation::animations[dead2anim].frames[1].joints[i].position = Animation::animations[dead2anim].frames[0].joints[i].position;
764         Animation::animations[dead3anim].frames[1].joints[i].position = Animation::animations[dead3anim].frames[0].joints[i].position;
765         Animation::animations[dead4anim].frames[1].joints[i].position = Animation::animations[dead4anim].frames[0].joints[i].position;
766     }
767     Animation::animations[dead1anim].frames[0].speed = 0.001;
768     Animation::animations[dead2anim].frames[0].speed = 0.001;
769     Animation::animations[dead3anim].frames[0].speed = 0.001;
770     Animation::animations[dead4anim].frames[0].speed = 0.001;
771
772     Animation::animations[dead1anim].frames[1].speed = 0.001;
773     Animation::animations[dead2anim].frames[1].speed = 0.001;
774     Animation::animations[dead3anim].frames[1].speed = 0.001;
775     Animation::animations[dead4anim].frames[1].speed = 0.001;
776
777     for (unsigned i = 0; i < Person::players[0]->skeleton.joints.size(); i++) {
778         for (unsigned j = 0; j < Animation::animations[swordsneakattackanim].frames.size(); j++) {
779             Animation::animations[swordsneakattackanim].frames[j].joints[i].position += moveamount;
780         }
781     }
782     LoadingScreen();
783     for (unsigned j = 0; j < Animation::animations[swordsneakattackanim].frames.size(); j++) {
784         Animation::animations[swordsneakattackanim].frames[j].weapontarget += moveamount;
785     }
786
787     LoadingScreen();
788
789     for (unsigned i = 0; i < Person::players[0]->skeleton.joints.size(); i++) {
790         for (unsigned j = 0; j < Animation::animations[swordsneakattackedanim].frames.size(); j++) {
791             Animation::animations[swordsneakattackedanim].frames[j].joints[i].position += moveamount;
792         }
793     }
794
795     LoadingScreen();
796
797     if (!screentexture) {
798         LoadScreenTexture();
799     }
800
801     if (targetlevel != 7) {
802         emit_sound_at(fireendsound);
803     }
804
805     stillloading = 0;
806     loading = 0;
807     changedelay = 1;
808
809     visibleloading = false;
810     firstLoadDone = true;
811 }