1 #include "Enums.h"
2 
3 #include "Game.h"
4 #include "Graphics.h"
5 #include "Entity.h"
6 #include "Map.h"
7 
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 
12 #include <sstream>
13 
14 #include "FileSystemUtils.h"
15 
16 #include "tinyxml.h"
17 
18 #include "Network.h"
19 
20 #include "MakeAndPlay.h"
21 
22 // lol, Win32 -flibit
23 #ifdef _WIN32
24 #define strcasecmp stricmp
25 #endif
26 
27 //TODO: Non Urgent code cleanup
BoolToString(bool _b)28 const char* BoolToString(bool _b)
29 {
30     if(_b)
31     {
32         return "1";
33     }
34     else
35     {
36         return "0";
37     }
38 }
39 
GetButtonFromString(const char * pText,SDL_GameControllerButton * button)40 bool GetButtonFromString(const char *pText, SDL_GameControllerButton *button)
41 {
42 	if (	*pText == '0' ||
43 		*pText == 'a' ||
44 		*pText == 'A'	)
45 	{
46 		*button = SDL_CONTROLLER_BUTTON_A;
47 		return true;
48 	}
49 	if (	strcmp(pText, "1") == 0 ||
50 		*pText == 'b' ||
51 		*pText == 'B'	)
52 	{
53 		*button = SDL_CONTROLLER_BUTTON_B;
54 		return true;
55 	}
56 	if (	*pText == '2' ||
57 		*pText == 'x' ||
58 		*pText == 'X'	)
59 	{
60 		*button = SDL_CONTROLLER_BUTTON_X;
61 		return true;
62 	}
63 	if (	*pText == '3' ||
64 		*pText == 'y' ||
65 		*pText == 'Y'	)
66 	{
67 		*button = SDL_CONTROLLER_BUTTON_Y;
68 		return true;
69 	}
70 	if (	*pText == '4' ||
71 		strcasecmp(pText, "BACK") == 0	)
72 	{
73 		*button = SDL_CONTROLLER_BUTTON_BACK;
74 		return true;
75 	}
76 	if (	*pText == '5' ||
77 		strcasecmp(pText, "GUIDE") == 0	)
78 	{
79 		*button = SDL_CONTROLLER_BUTTON_GUIDE;
80 		return true;
81 	}
82 	if (	*pText == '6' ||
83 		strcasecmp(pText, "START") == 0	)
84 	{
85 		*button = SDL_CONTROLLER_BUTTON_START;
86 		return true;
87 	}
88 	if (	*pText == '7' ||
89 		strcasecmp(pText, "LS") == 0	)
90 	{
91 		*button = SDL_CONTROLLER_BUTTON_LEFTSTICK;
92 		return true;
93 	}
94 	if (	*pText == '8' ||
95 		strcasecmp(pText, "RS") == 0	)
96 	{
97 		*button = SDL_CONTROLLER_BUTTON_RIGHTSTICK;
98 		return true;
99 	}
100 	if (	*pText == '9' ||
101 		strcasecmp(pText, "LB") == 0	)
102 	{
103 		*button = SDL_CONTROLLER_BUTTON_LEFTSHOULDER;
104 		return true;
105 	}
106 	if (	strcmp(pText, "10") == 0 ||
107 		strcasecmp(pText, "RB") == 0	)
108 	{
109 		*button = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER;
110 		return true;
111 	}
112 	return false;
113 }
114 
115 
Game(void)116 Game::Game(void):
117     mutebutton(0)
118 {
119     infocus = true;
120     paused = false;
121     muted = false;
122     globalsound = 128;
123     m_globalVol = 1.0f;
124 
125     timerStartTime= SDL_GetTicks();
126 
127 		glitchrunkludge = false;
128     hascontrol = true;
129     jumpheld = false;
130     advancetext = false;
131     jumppressed = 0;
132     gravitycontrol = 0;
133     teleport = false;
134     edteleportent = 0; //Added in the port!
135     companion = 0;
136     roomchange = false;
137 
138 
139     teleportscript = "";
140     savemystats = false;
141     menukludge = false;
142     quickrestartkludge = false;
143 
144     tapleft = 0;
145     tapright = 0;
146 
147     press_right = 0;
148     press_left = 0;
149 
150 
151     recording = 0;
152     recordinit = false;
153     playbackfinished = false;
154     recordstring = "";
155 
156     advancetext = false;
157     pausescript = false;
158     completestop = false;
159     activeactivity = -1;
160     act_fade = 0;
161     backgroundtext = false;
162     startscript = false;
163     newscript = "";
164     inintermission = false;
165 
166     alarmon = false;
167     alarmdelay = 0;
168     blackout = false;
169     creditposx = 0;
170     creditposy = 0;
171     creditposdelay = 0;
172 
173     useteleporter = false;
174     teleport_to_teleporter = 0;
175 
176     activetele = false;
177     readytotele = 0;
178     activity_lastprompt = "";
179     activity_r = 0;
180     activity_g = 0;
181     activity_b = 0;
182     creditposition = 0;
183     bestgamedeaths = -1;
184 
185     fullScreenEffect_badSignal = false;
186 
187     //Accessibility Options
188     colourblindmode = false;
189     noflashingmode = false;
190     slowdown = 30;
191     gameframerate=34;
192 
193     fullscreen = false;// true; //Assumed true at first unless overwritten at some point!
194     stretchMode = 0;
195     useLinearFilter = false;
196     advanced_mode = false;
197     fullScreenEffect_badSignal = false;
198 	// 0..5
199 	controllerSensitivity = 2;
200 
201     nodeathmode = false;
202     nocutscenes = false;
203 
204     for(int i=0; i<50; i++)
205     {
206         customscript[i]="";
207     }
208     customcol=0;
209 
210     for (int i = 0; i < 6; i++)
211     {
212         bool cstats;
213         cstats = false;
214         crewstats.push_back(cstats);
215         tele_crewstats.push_back(false);
216         quick_crewstats.push_back(false);
217         besttimes.push_back( -1);
218         besttrinkets.push_back( -1);
219         bestlives.push_back( -1);
220         bestrank.push_back( -1);
221     }
222     crewstats[0] = true;
223     lastsaved = 0;
224 
225     tele_gametime = "00:00";
226     tele_trinkets = 0;
227     tele_currentarea = "Error! Error!";
228     quick_gametime = "00:00";
229     quick_trinkets = 0;
230     quick_currentarea = "Error! Error!";
231 
232     //Menu stuff initiliased here:
233     for (int mi = 0; mi < 25; mi++)
234     {
235         menuoptions.push_back(std::string());
236         menuoptionsactive.push_back(bool());
237 
238         bool nb1, nb2;
239         nb1 = false;
240         nb2 = false;
241         unlock.push_back(nb1);
242         unlocknotify.push_back(nb2);
243     }
244 
245     for (int ui = 0; ui < 25; ui++)
246     {
247         unlock[ui] = false;
248         unlocknotify[ui] = false;
249     }
250 
251     nummenuoptions = 0;
252     currentmenuoption = 0;
253     menuselection = "null";
254     currentmenuname = "null";
255     menuxoff = 0;
256     menuyoff = 0;
257     menucountdown = 0;
258     menudest="null";
259     levelpage=0;
260     playcustomlevel=0;
261     customleveltitle="";
262     createmenu("mainmenu");
263 
264     deathcounts = 0;
265     gameoverdelay = 0;
266     frames = 0;
267     seconds = 0;
268     minutes = 0;
269     hours = 0;
270     gamesaved = false;
271     savetime = "00:00";
272     savearea = "nowhere";
273     savetrinkets = 0;
274 
275     intimetrial = false;
276     timetrialcountdown = 0;
277     timetrialshinytarget = 0;
278     timetrialparlost = false;
279     timetrialpar = 0;
280     timetrialresulttime = 0;
281 
282     totalflips = 0;
283     hardestroom = "Welcome Aboard";
284     hardestroomdeaths = 0;
285     currentroomdeaths=0;
286 
287     sfpsmode = false; //by default, play at 30 fps
288     inertia = 1.1f;
289     swnmode = false;
290     swntimer = 0;
291     swngame = 0;//Not playing sine wave ninja!
292     swnstate = 0;
293     swnstate2 = 0;
294     swnstate3 = 0;
295     swnstate4 = 0;
296     swndelay = 0;
297     swndeaths = 0;
298     supercrewmate = false;
299     scmhurt = false;
300     scmprogress = 0;
301     scmmoveme = false;
302     swncolstate = 0;
303     swncoldelay = 0;
304     swnrecord = 0;
305     swnbestrank = 0;
306     swnrank = 0;
307     swnmessage = 0;
308 
309     clearcustomlevelstats();
310 
311     saveFilePath = FILESYSTEM_getUserSaveDirectory();
312 
313     TiXmlDocument doc((saveFilePath + "qsave.vvv").c_str());
314     if (!doc.LoadFile())
315     {
316         quickcookieexists = false;
317         quicksummary = "";
318         printf("Quick Save Not Found\n");
319     }
320     else
321     {
322         quickcookieexists = true;
323         TiXmlHandle hDoc(&doc);
324         TiXmlElement* pElem;
325         TiXmlHandle hRoot(0);
326 
327         pElem=hDoc.FirstChildElement().Element();
328         if (!pElem)
329         {
330             printf("Quick Save Appears Corrupted: No XML Root\n");
331         }
332 
333         // save this for later
334         hRoot=TiXmlHandle(pElem);
335 
336         for( pElem = hRoot.FirstChild( "Data" ).FirstChild().Element(); pElem; pElem=pElem->NextSiblingElement())
337         {
338             std::string pKey(pElem->Value());
339             const char* pText = pElem->GetText() ;
340 
341             if (pKey == "summary")
342             {
343                 quicksummary = pText;
344             }
345 
346 
347         }
348     }
349 
350 
351     TiXmlDocument docTele((saveFilePath+"tsave.vvv").c_str());
352     if (!docTele.LoadFile())
353     {
354         telecookieexists = false;
355         telesummary = "";
356         printf("Teleporter Save Not Found\n");
357     }
358     else
359     {
360         telecookieexists = true;
361         TiXmlHandle hDoc(&docTele);
362         TiXmlElement* pElem;
363         TiXmlHandle hRoot(0);
364 
365 
366         {
367             pElem=hDoc.FirstChildElement().Element();
368             // should always have a valid root but handle gracefully if it does
369             if (!pElem)
370             {
371                 printf("Teleporter Save Appears Corrupted: No XML Root\n");
372             }
373 
374             // save this for later
375             hRoot=TiXmlHandle(pElem);
376         }
377 
378         for( pElem = hRoot.FirstChild( "Data" ).FirstChild().Element(); pElem; pElem=pElem->NextSiblingElement())
379         {
380             std::string pKey(pElem->Value());
381             const char* pText = pElem->GetText() ;
382 
383             if (pKey == "summary")
384             {
385                 telesummary = pText;
386             }
387 
388 
389         }
390     }
391 
392     //if (telecookie.data.savex == undefined) {
393     // telecookieexists = false; telesummary = "";
394     //} else {
395     // telecookieexists = true; telesummary = telecookie.data.summary;
396     //}
397 
398     //if (quickcookie.data.savex == undefined) {
399     // quickcookieexists = false; quicksummary = "";
400     //} else {
401     // quickcookieexists = true; quicksummary = quickcookie.data.summary;
402     //}
403 
404     screenshake = flashlight = 0 ;
405 
406     stat_trinkets = 0;
407 
408     test = false;
409     teststring = "TEST = True";
410     state = 1;
411     statedelay = 0;
412     //updatestate(dwgfx, map, obj, help, music);
413 }
414 
~Game(void)415 Game::~Game(void)
416 {
417 }
418 
lifesequence(entityclass & obj)419 void Game::lifesequence( entityclass& obj )
420 {
421     if (lifeseq > 0)
422     {
423         int i = obj.getplayer();
424         obj.entities[i].invis = false;
425         if (lifeseq == 2) obj.entities[i].invis = true;
426         if (lifeseq == 6) obj.entities[i].invis = true;
427         if (lifeseq >= 8) obj.entities[i].invis = true;
428         if (lifeseq > 5) gravitycontrol = savegc;
429 
430         lifeseq--;
431         if (lifeseq <= 0)
432         {
433             obj.entities[i].invis = false;
434         }
435     }
436 }
437 
clearcustomlevelstats()438 void Game::clearcustomlevelstats()
439 {
440     //just clearing the arrays
441     for(int i=0; i<200; i++)
442     {
443         customlevelstats[i]="";
444         customlevelscore[i]=0;
445     }
446     numcustomlevelstats=0;
447 
448     customlevelstatsloaded=false; //To ensure we don't load it where it isn't needed
449 }
450 
451 
updatecustomlevelstats(std::string clevel,int cscore)452 void Game::updatecustomlevelstats(std::string clevel, int cscore)
453 {
454     if (clevel.find("levels/") != std::string::npos)
455     {
456         clevel = clevel.substr(7);
457     }
458     int tvar=-1;
459     for(int j=0; j<numcustomlevelstats; j++)
460     {
461         if(clevel==customlevelstats[j])
462         {
463             tvar=j;
464             j=numcustomlevelstats+1;
465         }
466     }
467     if(tvar>=0)
468     {
469         //update existing entry
470         customlevelscore[tvar]=cscore;
471     }
472     else
473     {
474         //add a new entry
475         if(numcustomlevelstats<200)
476         {
477             customlevelstats[numcustomlevelstats]=clevel;
478             customlevelscore[numcustomlevelstats]=cscore;
479             numcustomlevelstats++;
480         }
481     }
482     savecustomlevelstats();
483 }
484 
loadcustomlevelstats()485 void Game::loadcustomlevelstats()
486 {
487     //testing
488     if(!customlevelstatsloaded)
489     {
490         TiXmlDocument doc((saveFilePath+"levelstats.vvv").c_str());
491         if (!doc.LoadFile())
492         {
493             //No levelstats file exists; start new
494             numcustomlevelstats=0;
495             savecustomlevelstats();
496         }
497         else
498         {
499             TiXmlHandle hDoc(&doc);
500             TiXmlElement* pElem;
501             TiXmlHandle hRoot(0);
502 
503             {
504                 pElem=hDoc.FirstChildElement().Element();
505                 // should always have a valid root but handle gracefully if it does
506                 if (!pElem)
507                 {
508                     printf("Error: Levelstats file corrupted\n");
509                 }
510 
511                 // save this for later
512                 hRoot=TiXmlHandle(pElem);
513             }
514 
515 
516             for( pElem = hRoot.FirstChild( "Data" ).FirstChild().Element(); pElem; pElem=pElem->NextSiblingElement())
517             {
518                 std::string pKey(pElem->Value());
519                 const char* pText = pElem->GetText() ;
520                 if(pText == NULL)
521                 {
522                     pText = "";
523                 }
524 
525                 if (pKey == "numcustomlevelstats")
526                 {
527                     numcustomlevelstats = atoi(pText);
528                     if(numcustomlevelstats>=200) numcustomlevelstats=199;
529                 }
530 
531                 if (pKey == "customlevelscore")
532                 {
533                     std::string TextString = (pText);
534                     if(TextString.length())
535                     {
536                         std::vector<std::string> values = split(TextString,',');
537                         for(size_t i = 0; i < values.size(); i++)
538                         {
539                             if(i<200) customlevelscore[i]=(atoi(values[i].c_str()));
540                         }
541                     }
542                 }
543 
544                 if (pKey == "customlevelstats")
545                 {
546                     std::string TextString = (pText);
547                     if(TextString.length())
548                     {
549                         std::vector<std::string> values = split(TextString,'|');
550                         for(size_t i = 0; i < values.size(); i++)
551                         {
552                             if(i<200) customlevelstats[i]=values[i];
553                         }
554                     }
555                 }
556             }
557         }
558     }
559 }
560 
savecustomlevelstats()561 void Game::savecustomlevelstats()
562 {
563     TiXmlDocument doc;
564     TiXmlElement* msg;
565     TiXmlDeclaration* decl = new TiXmlDeclaration( "1.0", "", "" );
566     doc.LinkEndChild( decl );
567 
568     TiXmlElement * root = new TiXmlElement( "Levelstats" );
569     doc.LinkEndChild( root );
570 
571     TiXmlComment * comment = new TiXmlComment();
572     comment->SetValue(" Levelstats Save file " );
573     root->LinkEndChild( comment );
574 
575     TiXmlElement * msgs = new TiXmlElement( "Data" );
576     root->LinkEndChild( msgs );
577 
578     if(numcustomlevelstats>=200)numcustomlevelstats=199;
579     msg = new TiXmlElement( "numcustomlevelstats" );
580     msg->LinkEndChild( new TiXmlText( UtilityClass::String(numcustomlevelstats).c_str() ));
581     msgs->LinkEndChild( msg );
582 
583     std::string customlevelscorestr;
584     for(int i = 0; i < numcustomlevelstats; i++ )
585     {
586         customlevelscorestr += UtilityClass::String(customlevelscore[i]) + ",";
587     }
588     msg = new TiXmlElement( "customlevelscore" );
589     msg->LinkEndChild( new TiXmlText( customlevelscorestr.c_str() ));
590     msgs->LinkEndChild( msg );
591 
592     std::string customlevelstatsstr;
593     for(int i = 0; i < numcustomlevelstats; i++ )
594     {
595         customlevelstatsstr += customlevelstats[i] + "|";
596     }
597     msg = new TiXmlElement( "customlevelstats" );
598     msg->LinkEndChild( new TiXmlText( customlevelstatsstr.c_str() ));
599     msgs->LinkEndChild( msg );
600 
601     if(doc.SaveFile( (saveFilePath+"levelstats.vvv").c_str() ))
602     {
603         printf("Level stats saved\n");
604     }
605     else
606     {
607         printf("Could Not Save level stats!\n");
608         printf("Failed: %s%s\n", saveFilePath.c_str(), "levelstats.vvv");
609     }
610 }
611 
updatestate(Graphics & dwgfx,mapclass & map,entityclass & obj,UtilityClass & help,musicclass & music)612 void Game::updatestate( Graphics& dwgfx, mapclass& map, entityclass& obj, UtilityClass& help, musicclass& music )
613 {
614     int i;
615     statedelay--;
616     if(statedelay<=0){
617 		  statedelay=0;
618 			glitchrunkludge=false;
619 		}
620     if (statedelay <= 0)
621     {
622         switch(state)
623         {
624         case 0:
625             //Do nothing here! Standard game state
626             break;
627         case 1:
628             //Game initilisation
629             state = 0;
630             break;
631         case 2:
632             //Opening cutscene
633             advancetext = true;
634             hascontrol = false;
635             state = 3;
636             dwgfx.createtextbox("To do: write quick", 50, 80, 164, 164, 255);
637             dwgfx.addline("intro to story!");
638             //Oh no! what happen to rest of crew etc crash into dimension
639             break;
640         case 4:
641             //End of opening cutscene for now
642             dwgfx.createtextbox("  Press arrow keys or WASD to move  ", -1, 195, 174, 174, 174);
643             dwgfx.textboxtimer(60);
644             state = 0;
645             break;
646         case 5:
647             //Demo over
648             advancetext = true;
649             hascontrol = false;
650             /*dwgfx.createtextbox("   Prototype Complete    ", 50, 80, 164, 164, 255);
651             dwgfx.addline("Congrats! More Info Soon!");
652             dwgfx.textboxcenter();
653             */
654 
655             startscript = true;
656             newscript="returntohub";
657             obj.removetrigger(5);
658             state = 6;
659             break;
660         case 7:
661             //End of opening cutscene for now
662             dwgfx.textboxremove();
663             hascontrol = true;
664             advancetext = false;
665             state = 0;
666             break;
667         case 8:
668             //Enter dialogue
669             obj.removetrigger(8);
670             if (obj.flags[13] == 0)
671             {
672                 obj.changeflag(13, 1);
673                 dwgfx.createtextbox("  Press ENTER to view map  ", -1, 155, 174, 174, 174);
674                 dwgfx.addline("      and quicksave");
675                 dwgfx.textboxtimer(60);
676             }
677             state = 0;
678             break;
679 
680         case 9:
681             //Start SWN Minigame Mode B
682             obj.removetrigger(9);
683 
684             swnmode = true;
685             swngame = 6;
686             swndelay = 150;
687             swntimer = 60 * 30;
688 
689             //set the checkpoint in the middle of the screen
690             savepoint = 0;
691             savex = 148;
692             savey = 100;
693             savegc = 0;
694             saverx = roomx;
695             savery = roomy;
696             savedir = 0;
697 
698             state = 0;
699             break;
700 
701         case 10:
702             //Start SWN Minigame Mode A
703             obj.removetrigger(10);
704 
705             swnmode = true;
706             swngame = 4;
707             swndelay = 150;
708             swntimer = 60 * 30;
709 
710             //set the checkpoint in the middle of the screen
711             savepoint = 0;
712             savex = 148;
713             savey = 100;
714             savegc = 0;
715             saverx = roomx;
716             savery = roomy;
717             savedir = 0;
718 
719             state = 0;
720             break;
721 
722         case 11:
723             //Intermission 1 instructional textbox, depends on last saved
724             dwgfx.textboxremovefast();
725             dwgfx.createtextbox("   When you're NOT standing on   ", -1, 3, 174, 174, 174);
726             if (dwgfx.flipmode)
727             {
728                 if (lastsaved == 2)
729                 {
730                     dwgfx.addline("   the ceiling, Vitellary will");
731                 }
732                 else if (lastsaved == 3)
733                 {
734                     dwgfx.addline("   the ceiling, Vermilion will");
735                 }
736                 else if (lastsaved == 4)
737                 {
738                     dwgfx.addline("   the ceiling, Verdigris will");
739                 }
740                 else if (lastsaved == 5)
741                 {
742                     dwgfx.addline("   the ceiling, Victoria will");
743                 }
744             }
745             else
746             {
747                 if (lastsaved == 2)
748                 {
749                     dwgfx.addline("    the floor, Vitellary will");
750                 }
751                 else if (lastsaved == 3)
752                 {
753                     dwgfx.addline("    the floor, Vermilion will");
754                 }
755                 else if (lastsaved == 4)
756                 {
757                     dwgfx.addline("    the floor, Verdigris will");
758                 }
759                 else if (lastsaved == 5)
760                 {
761                     dwgfx.addline("    the floor, Victoria will");
762                 }
763             }
764 
765             dwgfx.addline("     stop and wait for you.");
766             dwgfx.textboxtimer(180);
767             state = 0;
768             break;
769         case 12:
770             //Intermission 1 instructional textbox, depends on last saved
771             obj.removetrigger(12);
772             if (obj.flags[61] == 0)
773             {
774                 obj.changeflag(61, 1);
775                 dwgfx.textboxremovefast();
776                 dwgfx.createtextbox("  You can't continue to the next   ", -1, 8, 174, 174, 174);
777                 if (lastsaved == 5)
778                 {
779                     dwgfx.addline("  room until she is safely across. ");
780                 }
781                 else
782                 {
783                     dwgfx.addline("  room until he is safely across.  ");
784                 }
785                 dwgfx.textboxtimer(120);
786             }
787             state = 0;
788             break;
789         case 13:
790             //textbox removal
791             obj.removetrigger(13);
792             dwgfx.textboxremovefast();
793             state = 0;
794             break;
795         case 14:
796             //Intermission 1 instructional textbox, depends on last saved
797             if (dwgfx.flipmode)
798             {
799                 dwgfx.createtextbox(" When you're standing on the ceiling, ", -1, 3, 174, 174, 174);
800             }
801             else
802             {
803                 dwgfx.createtextbox(" When you're standing on the floor, ", -1, 3, 174, 174, 174);
804             }
805             if (lastsaved == 2)
806             {
807                 dwgfx.addline(" Vitellary will try to walk to you. ");
808             }
809             else if (lastsaved == 3)
810             {
811                 dwgfx.addline(" Vermilion will try to walk to you. ");
812             }
813             else if (lastsaved == 4)
814             {
815                 dwgfx.addline(" Verdigris will try to walk to you. ");
816             }
817             else if (lastsaved == 5)
818             {
819                 dwgfx.addline(" Victoria will try to walk to you. ");
820             }
821             dwgfx.textboxtimer(280);
822 
823             state = 0;
824             break;
825 
826         case 15:
827             //leaving the naughty corner
828             obj.entities[obj.getplayer()].tile = 0;
829             state = 0;
830             break;
831         case 16:
832             //entering the naughty corner
833             if(obj.entities[obj.getplayer()].tile == 0)
834             {
835                 obj.entities[obj.getplayer()].tile = 144;
836                 music.playef(2, 10);
837             }
838             state = 0;
839             break;
840 
841         case 17:
842             //Arrow key tutorial
843             obj.removetrigger(17);
844             dwgfx.createtextbox(" If you prefer, you can press UP or ", -1, 195, 174, 174, 174);
845             dwgfx.addline("   DOWN instead of ACTION to flip.");
846             dwgfx.textboxtimer(100);
847             state = 0;
848             break;
849 
850         case 20:
851             if (obj.flags[1] == 0)
852             {
853                 obj.changeflag(1, 1);
854                 state = 0;
855                 dwgfx.textboxremove();
856             }
857             obj.removetrigger(20);
858             break;
859         case 21:
860             if (obj.flags[2] == 0)
861             {
862                 obj.changeflag(2, 1);
863                 state = 0;
864                 dwgfx.textboxremove();
865             }
866             obj.removetrigger(21);
867             break;
868         case 22:
869             if (obj.flags[3] == 0)
870             {
871                 dwgfx.textboxremovefast();
872                 obj.changeflag(3, 1);
873                 state = 0;
874                 dwgfx.createtextbox("  Press ACTION to flip  ", -1, 25, 174, 174, 174);
875                 dwgfx.textboxtimer(60);
876             }
877             obj.removetrigger(22);
878             break;
879 
880         case 30:
881             //Generic "run script"
882             if (obj.flags[4] == 0)
883             {
884                 obj.changeflag(4, 1);
885                 startscript = true;
886                 newscript="firststeps";
887                 state = 0;
888             }
889             obj.removetrigger(30);
890             state = 0;
891             break;
892         case 31:
893             //state = 55;  statedelay = 50;
894             state = 0;
895             statedelay = 0;
896             if (obj.flags[6] == 0)
897             {
898                 obj.changeflag(6, 1);
899 
900                 obj.changeflag(5, 1);
901                 startscript = true;
902                 newscript="communicationstation";
903                 state = 0;
904                 statedelay = 0;
905             }
906             obj.removetrigger(31);
907             break;
908         case 32:
909             //Generic "run script"
910             if (obj.flags[7] == 0)
911             {
912                 obj.changeflag(7, 1);
913                 startscript = true;
914                 newscript="teleporterback";
915                 state = 0;
916             }
917             obj.removetrigger(32);
918             state = 0;
919             break;
920         case 33:
921             //Generic "run script"
922             if (obj.flags[9] == 0)
923             {
924                 obj.changeflag(9, 1);
925                 startscript = true;
926                 newscript="rescueblue";
927                 state = 0;
928             }
929             obj.removetrigger(33);
930             state = 0;
931             break;
932         case 34:
933             //Generic "run script"
934             if (obj.flags[10] == 0)
935             {
936                 obj.changeflag(10, 1);
937                 startscript = true;
938                 newscript="rescueyellow";
939                 state = 0;
940             }
941             obj.removetrigger(34);
942             state = 0;
943             break;
944         case 35:
945             //Generic "run script"
946             if (obj.flags[11] == 0)
947             {
948                 obj.changeflag(11, 1);
949                 startscript = true;
950                 newscript="rescuegreen";
951                 state = 0;
952             }
953             obj.removetrigger(35);
954             state = 0;
955             break;
956         case 36:
957             //Generic "run script"
958             if (obj.flags[8] == 0)
959             {
960                 obj.changeflag(8, 1);
961                 startscript = true;
962                 newscript="rescuered";
963                 state = 0;
964             }
965             obj.removetrigger(36);
966             state = 0;
967             break;
968 
969         case 37:
970             //Generic "run script"
971             if (companion == 0)
972             {
973                 startscript = true;
974                 newscript="int2_yellow";
975                 state = 0;
976             }
977             obj.removetrigger(37);
978             state = 0;
979             break;
980         case 38:
981             //Generic "run script"
982             if (companion == 0)
983             {
984                 startscript = true;
985                 newscript="int2_red";
986                 state = 0;
987             }
988             obj.removetrigger(38);
989             state = 0;
990             break;
991         case 39:
992             //Generic "run script"
993             if (companion == 0)
994             {
995                 startscript = true;
996                 newscript="int2_green";
997                 state = 0;
998             }
999             obj.removetrigger(39);
1000             state = 0;
1001             break;
1002         case 40:
1003             //Generic "run script"
1004             if (companion == 0)
1005             {
1006                 startscript = true;
1007                 newscript="int2_blue";
1008                 state = 0;
1009             }
1010             obj.removetrigger(40);
1011             state = 0;
1012             break;
1013 
1014         case 41:
1015             //Generic "run script"
1016             if (obj.flags[60] == 0)
1017             {
1018                 obj.changeflag(60, 1);
1019                 startscript = true;
1020                 if (lastsaved == 2)
1021                 {
1022                     newscript = "int1yellow_2";
1023                 }
1024                 else if (lastsaved == 3)
1025                 {
1026                     newscript = "int1red_2";
1027                 }
1028                 else if (lastsaved == 4)
1029                 {
1030                     newscript = "int1green_2";
1031                 }
1032                 else if (lastsaved == 5)
1033                 {
1034                     newscript = "int1blue_2";
1035                 }
1036                 state = 0;
1037             }
1038             obj.removetrigger(41);
1039             state = 0;
1040             break;
1041         case 42:
1042             //Generic "run script"
1043             if (obj.flags[62] == 0)
1044             {
1045                 obj.changeflag(62, 1);
1046                 startscript = true;
1047                 if (lastsaved == 2)
1048                 {
1049                     newscript = "int1yellow_3";
1050                 }
1051                 else if (lastsaved == 3)
1052                 {
1053                     newscript = "int1red_3";
1054                 }
1055                 else if (lastsaved == 4)
1056                 {
1057                     newscript = "int1green_3";
1058                 }
1059                 else if (lastsaved == 5)
1060                 {
1061                     newscript = "int1blue_3";
1062                 }
1063                 state = 0;
1064             }
1065             obj.removetrigger(42);
1066             state = 0;
1067             break;
1068         case 43:
1069             //Generic "run script"
1070             if (obj.flags[63] == 0)
1071             {
1072                 obj.changeflag(63, 1);
1073                 startscript = true;
1074                 if (lastsaved == 2)
1075                 {
1076                     newscript = "int1yellow_4";
1077                 }
1078                 else if (lastsaved == 3)
1079                 {
1080                     newscript = "int1red_4";
1081                 }
1082                 else if (lastsaved == 4)
1083                 {
1084                     newscript = "int1green_4";
1085                 }
1086                 else if (lastsaved == 5)
1087                 {
1088                     newscript = "int1blue_4";
1089                 }
1090                 state = 0;
1091             }
1092             obj.removetrigger(43);
1093             state = 0;
1094             break;
1095         case 44:
1096             //Generic "run script"
1097             if (obj.flags[64] == 0)
1098             {
1099                 obj.changeflag(64, 1);
1100                 startscript = true;
1101                 if (lastsaved == 2)
1102                 {
1103                     newscript = "int1yellow_5";
1104                 }
1105                 else if (lastsaved == 3)
1106                 {
1107                     newscript = "int1red_5";
1108                 }
1109                 else if (lastsaved == 4)
1110                 {
1111                     newscript = "int1green_5";
1112                 }
1113                 else if (lastsaved == 5)
1114                 {
1115                     newscript = "int1blue_5";
1116                 }
1117                 state = 0;
1118             }
1119             obj.removetrigger(44);
1120             state = 0;
1121             break;
1122         case 45:
1123             //Generic "run script"
1124             if (obj.flags[65] == 0)
1125             {
1126                 obj.changeflag(65, 1);
1127                 startscript = true;
1128                 if (lastsaved == 2)
1129                 {
1130                     newscript = "int1yellow_6";
1131                 }
1132                 else if (lastsaved == 3)
1133                 {
1134                     newscript = "int1red_6";
1135                 }
1136                 else if (lastsaved == 4)
1137                 {
1138                     newscript = "int1green_6";
1139                 }
1140                 else if (lastsaved == 5)
1141                 {
1142                     newscript = "int1blue_6";
1143                 }
1144                 state = 0;
1145             }
1146             obj.removetrigger(45);
1147             state = 0;
1148             break;
1149         case 46:
1150             //Generic "run script"
1151             if (obj.flags[66] == 0)
1152             {
1153                 obj.changeflag(66, 1);
1154                 startscript = true;
1155                 if (lastsaved == 2)
1156                 {
1157                     newscript = "int1yellow_7";
1158                 }
1159                 else if (lastsaved == 3)
1160                 {
1161                     newscript = "int1red_7";
1162                 }
1163                 else if (lastsaved == 4)
1164                 {
1165                     newscript = "int1green_7";
1166                 }
1167                 else if (lastsaved == 5)
1168                 {
1169                     newscript = "int1blue_7";
1170                 }
1171                 state = 0;
1172             }
1173             obj.removetrigger(46);
1174             state = 0;
1175             break;
1176 
1177         case 47:
1178             //Generic "run script"
1179             if (obj.flags[69] == 0)
1180             {
1181                 obj.changeflag(69, 1);
1182                 startscript = true;
1183                 newscript="trenchwarfare";
1184                 state = 0;
1185             }
1186             obj.removetrigger(47);
1187             state = 0;
1188             break;
1189         case 48:
1190             //Generic "run script"
1191             if (obj.flags[70] == 0)
1192             {
1193                 obj.changeflag(70, 1);
1194                 startscript = true;
1195                 newscript="trinketcollector";
1196                 state = 0;
1197             }
1198             obj.removetrigger(48);
1199             state = 0;
1200             break;
1201         case 49:
1202             //Start final level music
1203             if (obj.flags[71] == 0)
1204             {
1205                 obj.changeflag(71, 1);
1206                 music.niceplay(15);  //Final level remix
1207                 state = 0;
1208             }
1209             obj.removetrigger(49);
1210             state = 0;
1211             break;
1212 
1213         case 50:
1214             music.playef(15, 10);
1215             dwgfx.createtextbox("Help! Can anyone hear", 35, 15, 255, 134, 255);
1216             dwgfx.addline("this message?");
1217             dwgfx.textboxtimer(60);
1218             state++;
1219             statedelay = 100;
1220             break;
1221         case 51:
1222             music.playef(15, 10);
1223             dwgfx.createtextbox("Verdigris? Are you out", 30, 12, 255, 134, 255);
1224             dwgfx.addline("there? Are you ok?");
1225             dwgfx.textboxtimer(60);
1226             state++;
1227             statedelay = 100;
1228             break;
1229         case 52:
1230             music.playef(15, 10);
1231             dwgfx.createtextbox("Please help us! We've crashed", 5, 22, 255, 134, 255);
1232             dwgfx.addline("and need assistance!");
1233             dwgfx.textboxtimer(60);
1234             state++;
1235             statedelay = 100;
1236             break;
1237         case 53:
1238             music.playef(15, 10);
1239             dwgfx.createtextbox("Hello? Anyone out there?", 40, 15, 255, 134, 255);
1240             dwgfx.textboxtimer(60);
1241             state++;
1242             statedelay = 100;
1243             break;
1244         case 54:
1245             music.playef(15, 10);
1246             dwgfx.createtextbox("This is Doctor Violet from the", 5, 8, 255, 134, 255);
1247             dwgfx.addline("D.S.S. Souleye! Please respond!");
1248             dwgfx.textboxtimer(60);
1249             state++;
1250             statedelay = 100;
1251             break;
1252         case 55:
1253             music.playef(15, 10);
1254             dwgfx.createtextbox("Please... Anyone...", 45, 14, 255, 134, 255);
1255             dwgfx.textboxtimer(60);
1256             state++;
1257             statedelay = 100;
1258             break;
1259         case 56:
1260             music.playef(15, 10);
1261             dwgfx.createtextbox("Please be alright, everyone...", 25, 18, 255, 134, 255);
1262             dwgfx.textboxtimer(60);
1263             state=50;
1264             statedelay = 100;
1265             break;
1266 
1267 
1268         case 80:
1269             //Used to return to menu from the game
1270             if(dwgfx.fademode == 1)	state++;
1271             break;
1272         case 81:
1273             gamestate = 1;
1274             dwgfx.fademode = 4;
1275             music.play(6);
1276             dwgfx.backgrounddrawn = false;
1277             map.tdrawback = true;
1278             dwgfx.flipmode = false;
1279             createmenu("mainmenu");
1280             state = 0;
1281             break;
1282 
1283         case 82:
1284             //Time Trial Complete!
1285             obj.removetrigger(82);
1286             hascontrol = false;
1287             timetrialresulttime = seconds + (minutes * 60);
1288             timetrialrank = 0;
1289             if (timetrialresulttime <= timetrialpar) timetrialrank++;
1290             if (trinkets >= timetrialshinytarget) timetrialrank++;
1291             if (deathcounts == 0) timetrialrank++;
1292 
1293             if (timetrialresulttime < besttimes[timetriallevel] || besttimes[timetriallevel]==-1)
1294             {
1295                 besttimes[timetriallevel] = timetrialresulttime;
1296             }
1297             if (trinkets > besttrinkets[timetriallevel] || besttrinkets[timetriallevel]==-1)
1298             {
1299                 besttrinkets[timetriallevel] = trinkets;
1300             }
1301             if (deathcounts < bestlives[timetriallevel] || bestlives[timetriallevel]==-1)
1302             {
1303                 bestlives[timetriallevel] = deathcounts;
1304             }
1305             if (timetrialrank > bestrank[timetriallevel] || bestrank[timetriallevel]==-1)
1306             {
1307                 bestrank[timetriallevel] = timetrialrank;
1308 								if(timetrialrank>=3){
1309 									if(timetriallevel==0) NETWORK_unlockAchievement("vvvvvvtimetrial_station1_fixed");
1310 									if(timetriallevel==1) NETWORK_unlockAchievement("vvvvvvtimetrial_lab_fixed");
1311 									if(timetriallevel==2) NETWORK_unlockAchievement("vvvvvvtimetrial_tower_fixed");
1312 									if(timetriallevel==3) NETWORK_unlockAchievement("vvvvvvtimetrial_station2_fixed");
1313 									if(timetriallevel==4) NETWORK_unlockAchievement("vvvvvvtimetrial_warp_fixed");
1314 									if(timetriallevel==5) NETWORK_unlockAchievement("vvvvvvtimetrial_final_fixed");
1315 								}
1316             }
1317 
1318             savestats(map, dwgfx);
1319 
1320             dwgfx.fademode = 2;
1321             music.fadeout();
1322             state++;
1323             break;
1324         case 83:
1325             frames--;
1326             if(dwgfx.fademode == 1)	state++;
1327             break;
1328         case 84:
1329             dwgfx.flipmode = false;
1330             gamestate = 1;
1331             dwgfx.fademode = 4;
1332             dwgfx.backgrounddrawn = true;
1333             map.tdrawback = true;
1334             createmenu("timetrialcomplete");
1335             state = 0;
1336             break;
1337 
1338 
1339         case 85:
1340             //Cutscene skip version of final level change
1341             obj.removetrigger(85);
1342             //Init final stretch
1343             state++;
1344             music.playef(9, 10);
1345             music.play(2);
1346             obj.flags[72] = 1;
1347 
1348             screenshake = 10;
1349             flashlight = 5;
1350             map.finalstretch = true;
1351             map.warpx = false;
1352             map.warpy = false;
1353             map.background = 6;
1354 
1355             map.final_colormode = true;
1356             map.final_colorframe = 1;
1357 
1358             state = 0;
1359             break;
1360 
1361             //From 90-100 are run scripts for the eurogamer expo only, remove later
1362         case 90:
1363             //Generic "run script"
1364             startscript = true;
1365             newscript="startexpolevel_station1";
1366             obj.removetrigger(90);
1367             state = 0;
1368             break;
1369         case 91:
1370             //Generic "run script"
1371             startscript = true;
1372             newscript="startexpolevel_lab";
1373             obj.removetrigger(91);
1374             state = 0;
1375             break;
1376         case 92:
1377             //Generic "run script"
1378             startscript = true;
1379             newscript="startexpolevel_warp";
1380             obj.removetrigger(92);
1381             state = 0;
1382             break;
1383         case 93:
1384             //Generic "run script"
1385             startscript = true;
1386             newscript="startexpolevel_tower";
1387             obj.removetrigger(93);
1388             state = 0;
1389             break;
1390         case 94:
1391             //Generic "run script"
1392             startscript = true;
1393             newscript="startexpolevel_station2";
1394             obj.removetrigger(94);
1395             state = 0;
1396             break;
1397         case 95:
1398             //Generic "run script"
1399             startscript = true;
1400             newscript="startexpolevel_final";
1401             obj.removetrigger(95);
1402             state = 0;
1403             break;
1404 
1405         case 96:
1406             //Used to return to gravitron to game
1407             if(dwgfx.fademode == 1)	state++;
1408             break;
1409         case 97:
1410             gamestate = 0;
1411             dwgfx.fademode = 4;
1412             startscript = true;
1413             newscript="returntolab";
1414             state = 0;
1415             break;
1416 
1417         case 100:
1418             //
1419             //                       Meeting crewmate in the warpzone
1420             //
1421             obj.removetrigger(100);
1422             if (obj.flags[4] == 0)
1423             {
1424                 obj.changeflag(4, 1);
1425                 state++;
1426             }
1427             break;
1428         case 101:
1429         {
1430 
1431 
1432             i = obj.getplayer();
1433             hascontrol = false;
1434             if (obj.entities[i].onroof > 0 && gravitycontrol == 1)
1435             {
1436                 gravitycontrol = 0;
1437                 music.playef(1, 10);
1438             }
1439             if (obj.entities[i].onground > 0)
1440             {
1441                 state++;
1442             }
1443         }
1444         break;
1445         case 102:
1446         {
1447 
1448 
1449             companion = 6;
1450             i = obj.getcompanion(6);
1451             obj.entities[i].tile = 0;
1452             obj.entities[i].state = 1;
1453 
1454             advancetext = true;
1455             hascontrol = false;
1456 
1457             dwgfx.createtextbox("Captain! I've been so worried!", 60, 90, 164, 255, 164);
1458             state++;
1459             music.playef(12, 10);
1460         }
1461         break;
1462         case 104:
1463             dwgfx.createtextbox("I'm glad you're ok!", 135, 152, 164, 164, 255);
1464             state++;
1465             music.playef(11, 10);
1466             dwgfx.textboxactive();
1467             break;
1468         case 106:
1469         {
1470             dwgfx.createtextbox("I've been trying to find a", 74, 70, 164, 255, 164);
1471             dwgfx.addline("way out, but I keep going");
1472             dwgfx.addline("around in circles...");
1473             state++;
1474             music.playef(2, 10);
1475             dwgfx.textboxactive();
1476             i = obj.getcompanion(6);
1477             obj.entities[i].tile = 54;
1478             obj.entities[i].state = 0;
1479         }
1480         break;
1481         case 108:
1482             dwgfx.createtextbox("Don't worry! I have a", 125, 152, 164, 164, 255);
1483             dwgfx.addline("teleporter key!");
1484             state++;
1485             music.playef(11, 10);
1486             dwgfx.textboxactive();
1487             break;
1488         case 110:
1489         {
1490 
1491             i = obj.getcompanion(6);
1492             obj.entities[i].tile = 0;
1493             obj.entities[i].state = 1;
1494             dwgfx.createtextbox("Follow me!", 185, 154, 164, 164, 255);
1495             state++;
1496             music.playef(11, 10);
1497             dwgfx.textboxactive();
1498 
1499         }
1500         break;
1501         case 112:
1502             dwgfx.textboxremove();
1503             hascontrol = true;
1504             advancetext = false;
1505 
1506             state = 0;
1507             break;
1508 
1509         case 115:
1510             //
1511             //                       Test script for space station, totally delete me!
1512             //
1513         {
1514             i = obj.getplayer();
1515             hascontrol = false;
1516             state++;
1517         }
1518         break;
1519         case 116:
1520             advancetext = true;
1521             hascontrol = false;
1522 
1523             dwgfx.createtextbox("Sorry Eurogamers! Teleporting around", 60 - 20, 200, 255, 64, 64);
1524             dwgfx.addline("the map doesn't work in this version!");
1525             dwgfx.textboxcenterx();
1526             state++;
1527             break;
1528         case 118:
1529             dwgfx.textboxremove();
1530             hascontrol = true;
1531             advancetext = false;
1532 
1533             state = 0;
1534             break;
1535 
1536         case 120:
1537             //
1538             //                       Meeting crewmate in the space station
1539             //
1540             obj.removetrigger(120);
1541             if (obj.flags[5] == 0)
1542             {
1543                 obj.changeflag(5, 1);
1544                 state++;
1545             }
1546             break;
1547         case 121:
1548         {
1549 
1550             i = obj.getplayer();
1551             hascontrol = false;
1552             if (obj.entities[i].onground > 0 && gravitycontrol == 0)
1553             {
1554                 gravitycontrol = 1;
1555                 music.playef(1, 10);
1556             }
1557             if (obj.entities[i].onroof > 0)
1558             {
1559                 state++;
1560             }
1561 
1562         }
1563         break;
1564         case 122:
1565             companion = 7;
1566             i = obj.getcompanion(7);
1567             obj.entities[i].tile = 6;
1568             obj.entities[i].state = 1;
1569 
1570             advancetext = true;
1571             hascontrol = false;
1572 
1573             dwgfx.createtextbox("Captain! You're ok!", 60-10, 90-40, 255, 255, 134);
1574             state++;
1575             music.playef(14, 10);
1576             break;
1577         case 124:
1578             dwgfx.createtextbox("I've found a teleporter, but", 60-20, 90 - 40, 255, 255, 134);
1579             dwgfx.addline("I can't get it to go anywhere...");
1580             state++;
1581             music.playef(2, 10);
1582             dwgfx.textboxactive();
1583             i = obj.getcompanion(7);	//obj.entities[i].tile = 66;	obj.entities[i].state = 0;
1584             break;
1585         case 126:
1586             dwgfx.createtextbox("I can help with that!", 125, 152-40, 164, 164, 255);
1587             state++;
1588             music.playef(11, 10);
1589             dwgfx.textboxactive();
1590             break;
1591         case 128:
1592             dwgfx.createtextbox("I have the teleporter", 130, 152-35, 164, 164, 255);
1593             dwgfx.addline("codex for our ship!");
1594             state++;
1595             music.playef(11, 10);
1596             dwgfx.textboxactive();
1597             break;
1598 
1599         case 130:
1600             dwgfx.createtextbox("Yey! Let's go home!", 60-30, 90-35, 255, 255, 134);
1601             state++;
1602             music.playef(14, 10);
1603             dwgfx.textboxactive();
1604             i = obj.getcompanion(7);
1605             obj.entities[i].tile = 6;
1606             obj.entities[i].state = 1;
1607             break;
1608         case 132:
1609             dwgfx.textboxremove();
1610             hascontrol = true;
1611             advancetext = false;
1612 
1613             state = 0;
1614             break;
1615 
1616         case 200:
1617             //Init final stretch
1618             state++;
1619             music.playef(9, 10);
1620             //music.play(2);
1621             obj.flags[72] = 1;
1622 
1623             screenshake = 10;
1624             flashlight = 5;
1625             map.finalstretch = true;
1626             map.warpx = false;
1627             map.warpy = false;
1628             map.background = 6;
1629 
1630             map.final_colormode = true;
1631             map.final_colorframe = 1;
1632 
1633             startscript = true;
1634             newscript="finalterminal_finish";
1635             state = 0;
1636             break;
1637 
1638 
1639         case 300:
1640             startscript = true;
1641             newscript="custom_"+customscript[0];
1642             obj.removetrigger(300);
1643             state = 0;
1644             break;
1645         case 301:
1646             startscript = true;
1647             newscript="custom_"+customscript[1];
1648             obj.removetrigger(301);
1649             state = 0;
1650             break;
1651         case 302:
1652             startscript = true;
1653             newscript="custom_"+customscript[2];
1654             obj.removetrigger(302);
1655             state = 0;
1656             break;
1657         case 303:
1658             startscript = true;
1659             newscript="custom_"+customscript[3];
1660             obj.removetrigger(303);
1661             state = 0;
1662             break;
1663         case 304:
1664             startscript = true;
1665             newscript="custom_"+customscript[4];
1666             obj.removetrigger(304);
1667             state = 0;
1668             break;
1669         case 305:
1670             startscript = true;
1671             newscript="custom_"+customscript[5];
1672             obj.removetrigger(305);
1673             state = 0;
1674             break;
1675         case 306:
1676             startscript = true;
1677             newscript="custom_"+customscript[6];
1678             obj.removetrigger(306);
1679             state = 0;
1680             break;
1681         case 307:
1682             startscript = true;
1683             newscript="custom_"+customscript[7];
1684             obj.removetrigger(307);
1685             state = 0;
1686             break;
1687         case 308:
1688             startscript = true;
1689             newscript="custom_"+customscript[8];
1690             obj.removetrigger(308);
1691             state = 0;
1692             break;
1693         case 309:
1694             startscript = true;
1695             newscript="custom_"+customscript[9];
1696             obj.removetrigger(309);
1697             state = 0;
1698             break;
1699         case 310:
1700             startscript = true;
1701             newscript="custom_"+customscript[10];
1702             obj.removetrigger(310);
1703             state = 0;
1704             break;
1705         case 311:
1706             startscript = true;
1707             newscript="custom_"+customscript[11];
1708             obj.removetrigger(311);
1709             state = 0;
1710             break;
1711         case 312:
1712             startscript = true;
1713             newscript="custom_"+customscript[12];
1714             obj.removetrigger(312);
1715             state = 0;
1716             break;
1717         case 313:
1718             startscript = true;
1719             newscript="custom_"+customscript[13];
1720             obj.removetrigger(313);
1721             state = 0;
1722             break;
1723         case 314:
1724             startscript = true;
1725             newscript="custom_"+customscript[14];
1726             obj.removetrigger(314);
1727             state = 0;
1728             break;
1729         case 315:
1730             startscript = true;
1731             newscript="custom_"+customscript[15];
1732             obj.removetrigger(315);
1733             state = 0;
1734             break;
1735         case 316:
1736             startscript = true;
1737             newscript="custom_"+customscript[16];
1738             obj.removetrigger(316);
1739             state = 0;
1740             break;
1741         case 317:
1742             startscript = true;
1743             newscript="custom_"+customscript[17];
1744             obj.removetrigger(317);
1745             state = 0;
1746             break;
1747         case 318:
1748             startscript = true;
1749             newscript="custom_"+customscript[18];
1750             obj.removetrigger(318);
1751             state = 0;
1752             break;
1753         case 319:
1754             startscript = true;
1755             newscript="custom_"+customscript[19];
1756             obj.removetrigger(319);
1757             state = 0;
1758             break;
1759         case 320:
1760             startscript = true;
1761             newscript="custom_"+customscript[20];
1762             obj.removetrigger(320);
1763             state = 0;
1764             break;
1765         case 321:
1766             startscript = true;
1767             newscript="custom_"+customscript[21];
1768             obj.removetrigger(321);
1769             state = 0;
1770             break;
1771         case 322:
1772             startscript = true;
1773             newscript="custom_"+customscript[22];
1774             obj.removetrigger(322);
1775             state = 0;
1776             break;
1777         case 323:
1778             startscript = true;
1779             newscript="custom_"+customscript[23];
1780             obj.removetrigger(323);
1781             state = 0;
1782             break;
1783         case 324:
1784             startscript = true;
1785             newscript="custom_"+customscript[24];
1786             obj.removetrigger(324);
1787             state = 0;
1788             break;
1789         case 325:
1790             startscript = true;
1791             newscript="custom_"+customscript[25];
1792             obj.removetrigger(325);
1793             state = 0;
1794             break;
1795         case 326:
1796             startscript = true;
1797             newscript="custom_"+customscript[26];
1798             obj.removetrigger(326);
1799             state = 0;
1800             break;
1801         case 327:
1802             startscript = true;
1803             newscript="custom_"+customscript[27];
1804             obj.removetrigger(327);
1805             state = 0;
1806             break;
1807         case 328:
1808             startscript = true;
1809             newscript="custom_"+customscript[28];
1810             obj.removetrigger(328);
1811             state = 0;
1812             break;
1813         case 329:
1814             startscript = true;
1815             newscript="custom_"+customscript[29];
1816             obj.removetrigger(329);
1817             state = 0;
1818             break;
1819         case 330:
1820             startscript = true;
1821             newscript="custom_"+customscript[30];
1822             obj.removetrigger(330);
1823             state = 0;
1824             break;
1825         case 331:
1826             startscript = true;
1827             newscript="custom_"+customscript[31];
1828             obj.removetrigger(331);
1829             state = 0;
1830             break;
1831         case 332:
1832             startscript = true;
1833             newscript="custom_"+customscript[32];
1834             obj.removetrigger(332);
1835             state = 0;
1836             break;
1837         case 333:
1838             startscript = true;
1839             newscript="custom_"+customscript[33];
1840             obj.removetrigger(333);
1841             state = 0;
1842             break;
1843         case 334:
1844             startscript = true;
1845             newscript="custom_"+customscript[34];
1846             obj.removetrigger(334);
1847             state = 0;
1848             break;
1849         case 335:
1850             startscript = true;
1851             newscript="custom_"+customscript[35];
1852             obj.removetrigger(335);
1853             state = 0;
1854             break;
1855         case 336:
1856             startscript = true;
1857             newscript="custom_"+customscript[36];
1858             obj.removetrigger(336);
1859             state = 0;
1860             break;
1861 
1862         case 1000:
1863             dwgfx.showcutscenebars = true;
1864             hascontrol = false;
1865             completestop = true;
1866             state++;
1867             statedelay = 15;
1868             break;
1869         case 1001:
1870             //Found a trinket!
1871             advancetext = true;
1872             state++;
1873             if (dwgfx.flipmode)
1874             {
1875                 dwgfx.createtextbox("        Congratulations!       ", 50, 105, 174, 174, 174);
1876                 dwgfx.addline("");
1877                 dwgfx.addline("You have found a shiny trinket!");
1878                 dwgfx.textboxcenterx();
1879 
1880                 if(map.custommode)
1881                 {
1882                     dwgfx.createtextbox(" " + help.number(trinkets) + " out of " + help.number(map.customtrinkets)+ " ", 50, 65, 174, 174, 174);
1883                     dwgfx.textboxcenterx();
1884                 }
1885                 else
1886                 {
1887                     dwgfx.createtextbox(" " + help.number(trinkets) + " out of Twenty ", 50, 65, 174, 174, 174);
1888                     dwgfx.textboxcenterx();
1889                 }
1890             }
1891             else
1892             {
1893                 dwgfx.createtextbox("        Congratulations!       ", 50, 85, 174, 174, 174);
1894                 dwgfx.addline("");
1895                 dwgfx.addline("You have found a shiny trinket!");
1896                 dwgfx.textboxcenterx();
1897 
1898                 if(map.custommode)
1899                 {
1900                     dwgfx.createtextbox(" " + help.number(trinkets) + " out of " + help.number(map.customtrinkets)+ " ", 50, 135, 174, 174, 174);
1901                     dwgfx.textboxcenterx();
1902                 }
1903                 else
1904                 {
1905                     dwgfx.createtextbox(" " + help.number(trinkets) + " out of Twenty ", 50, 135, 174, 174, 174);
1906                     dwgfx.textboxcenterx();
1907                 }
1908             }
1909             break;
1910         case 1003:
1911             dwgfx.textboxremove();
1912             hascontrol = true;
1913             advancetext = false;
1914             completestop = false;
1915             state = 0;
1916             //music.play(music.resumesong);
1917             if(!muted && music.currentsong>-1) music.fadeMusicVolumeIn(3000);
1918             dwgfx.showcutscenebars = false;
1919             break;
1920 
1921         case 1010:
1922             dwgfx.showcutscenebars = true;
1923             hascontrol = false;
1924             completestop = true;
1925             state++;
1926             statedelay = 15;
1927             break;
1928         case 1011:
1929             //Found a trinket!
1930             advancetext = true;
1931             state++;
1932             if (dwgfx.flipmode)
1933             {
1934                 dwgfx.createtextbox("        Congratulations!       ", 50, 105, 174, 174, 174);
1935                 dwgfx.addline("");
1936                 dwgfx.addline("You have found a lost crewmate!");
1937                 dwgfx.textboxcenterx();
1938 
1939                 if(int(map.customcrewmates-crewmates)==0)
1940                 {
1941                     dwgfx.createtextbox("     All crewmates rescued!    ", 50, 135, 174, 174, 174);
1942                 }
1943                 else if(map.customcrewmates-crewmates==1)
1944                 {
1945                     dwgfx.createtextbox("    " + help.number(int(map.customcrewmates-crewmates))+ " remains    ", 50, 135, 174, 174, 174);
1946                 }
1947                 else
1948                 {
1949                     dwgfx.createtextbox("     " + help.number(int(map.customcrewmates-crewmates))+ " remain    ", 50, 135, 174, 174, 174);
1950                 }
1951                 dwgfx.textboxcenterx();
1952 
1953             }
1954             else
1955             {
1956                 dwgfx.createtextbox("        Congratulations!       ", 50, 85, 174, 174, 174);
1957                 dwgfx.addline("");
1958                 dwgfx.addline("You have found a lost crewmate!");
1959                 dwgfx.textboxcenterx();
1960 
1961                 if(int(map.customcrewmates-crewmates)==0)
1962                 {
1963                     dwgfx.createtextbox("     All crewmates rescued!    ", 50, 135, 174, 174, 174);
1964                 }
1965                 else if(map.customcrewmates-crewmates==1)
1966                 {
1967                     dwgfx.createtextbox("    " + help.number(int(map.customcrewmates-crewmates))+ " remains    ", 50, 135, 174, 174, 174);
1968                 }
1969                 else
1970                 {
1971                     dwgfx.createtextbox("     " + help.number(int(map.customcrewmates-crewmates))+ " remain    ", 50, 135, 174, 174, 174);
1972                 }
1973                 dwgfx.textboxcenterx();
1974             }
1975             break;
1976         case 1013:
1977             dwgfx.textboxremove();
1978             hascontrol = true;
1979             advancetext = false;
1980             completestop = false;
1981             state = 0;
1982 
1983             if(map.customcrewmates-crewmates==0)
1984             {
1985                 if(map.custommodeforreal)
1986                 {
1987                     dwgfx.fademode = 2;
1988                     if(!muted && ed.levmusic>0) music.fadeMusicVolumeIn(3000);
1989                     if(ed.levmusic>0) music.fadeout();
1990                     state=1014;
1991                 }
1992                 else
1993                 {
1994                     gamestate = EDITORMODE;
1995                     dwgfx.backgrounddrawn=false;
1996                     if(!muted && ed.levmusic>0) music.fadeMusicVolumeIn(3000);
1997                     if(ed.levmusic>0) music.fadeout();
1998                 }
1999             }
2000             else
2001             {
2002                 if(!muted && ed.levmusic>0) music.fadeMusicVolumeIn(3000);
2003             }
2004             dwgfx.showcutscenebars = false;
2005             break;
2006         case 1014:
2007             frames--;
2008             if(dwgfx.fademode == 1)	state++;
2009             break;
2010         case 1015:
2011             dwgfx.flipmode = false;
2012             gamestate = TITLEMODE;
2013             dwgfx.fademode = 4;
2014             music.play(6);
2015             dwgfx.backgrounddrawn = true;
2016             map.tdrawback = true;
2017             //Update level stats
2018             if(map.customcrewmates-crewmates==0)
2019             {
2020                 //Finished level
2021                 if(map.customtrinkets-trinkets==0)
2022                 {
2023                     //and got all the trinkets!
2024                     updatecustomlevelstats(customlevelfilename, 3);
2025                 }
2026                 else
2027                 {
2028                     updatecustomlevelstats(customlevelfilename, 1);
2029                 }
2030             }
2031             createmenu("levellist");
2032             state = 0;
2033             break;
2034 
2035 
2036         case 2000:
2037             //Game Saved!
2038             if (intimetrial || nodeathmode || inintermission)
2039             {
2040                 state = 0;
2041             }
2042             else
2043             {
2044                 savetele(map, obj, music);
2045                 if (dwgfx.flipmode)
2046                 {
2047                     dwgfx.createtextbox("    Game Saved    ", -1, 202, 174, 174, 174);
2048                     dwgfx.textboxtimer(25);
2049                 }
2050                 else
2051                 {
2052                     dwgfx.createtextbox("    Game Saved    ", -1, 12, 174, 174, 174);
2053                     dwgfx.textboxtimer(25);
2054                 }
2055                 state = 0;
2056             }
2057             break;
2058 
2059         case 2500:
2060 
2061             music.play(5);
2062             //Activating a teleporter (appear)
2063             state++;
2064             statedelay = 15;
2065             flashlight = 5;
2066             screenshake = 90;
2067             music.playef(9, 10);
2068             break;
2069         case 2501:
2070             //Activating a teleporter 2
2071             state++;
2072             statedelay = 0;
2073             flashlight = 5;
2074             screenshake = 0;
2075             //we're done here!
2076             music.playef(10, 10);
2077             break;
2078         case 2502:
2079             //Activating a teleporter 2
2080             state++;
2081             statedelay = 5;
2082 
2083             i = obj.getplayer();
2084             obj.entities[i].colour = 0;
2085             obj.entities[i].invis = false;
2086 
2087             obj.entities[i].xp = obj.entities[obj.getteleporter()].xp+44;
2088             obj.entities[i].yp = obj.entities[obj.getteleporter()].yp+44;
2089             obj.entities[i].ay = -6;
2090             obj.entities[i].ax = 6;
2091             obj.entities[i].vy = -6;
2092             obj.entities[i].vx = 6;
2093 
2094             i = obj.getteleporter();
2095             obj.entities[i].tile = 1;
2096             obj.entities[i].colour = 101;
2097             break;
2098         case 2503:
2099             state++;
2100             i = obj.getplayer();
2101             obj.entities[i].xp += 10;
2102             break;
2103         case 2504:
2104             state++;
2105             i = obj.getplayer();
2106             //obj.entities[i].xp += 10;
2107             break;
2108         case 2505:
2109             state++;
2110             i = obj.getplayer();
2111             obj.entities[i].xp += 8;
2112             break;
2113         case 2506:
2114             state++;
2115             i = obj.getplayer();
2116             obj.entities[i].xp += 6;
2117             break;
2118         case 2507:
2119             state++;
2120             i = obj.getplayer();
2121             //obj.entities[i].xp += 4;
2122             break;
2123         case 2508:
2124             state++;
2125             i = obj.getplayer();
2126             obj.entities[i].xp += 2;
2127             break;
2128         case 2509:
2129             state++;
2130             statedelay = 15;
2131             i = obj.getplayer();
2132             obj.entities[i].xp += 1;
2133             break;
2134         case 2510:
2135             advancetext = true;
2136             hascontrol = false;
2137             dwgfx.createtextbox("Hello?", 125+24, 152-20, 164, 164, 255);
2138             state++;
2139             music.playef(11, 10);
2140             dwgfx.textboxactive();
2141             break;
2142         case 2512:
2143             advancetext = true;
2144             hascontrol = false;
2145             dwgfx.createtextbox("Is anyone there?", 125+8, 152-24, 164, 164, 255);
2146             state++;
2147             music.playef(11, 10);
2148             dwgfx.textboxactive();
2149             break;
2150         case 2514:
2151             dwgfx.textboxremove();
2152             hascontrol = true;
2153             advancetext = false;
2154 
2155             state = 0;
2156             music.play(3);
2157             break;
2158 
2159 
2160         case 3000:
2161             //Activating a teleporter (long version for level complete)
2162             state++;
2163             statedelay = 30;
2164             flashlight = 5;
2165             screenshake = 90;
2166             music.playef(9, 10);
2167             break;
2168         case 3001:
2169             //Activating a teleporter 2
2170             state++;
2171             statedelay = 15;
2172             flashlight = 5;
2173             music.playef(9, 10);
2174             break;
2175         case 3002:
2176             //Activating a teleporter 2
2177             state++;
2178             statedelay = 15;
2179             flashlight = 5;
2180             music.playef(9, 10);
2181             break;
2182         case 3003:
2183             //Activating a teleporter 2
2184             state++;
2185             statedelay = 15;
2186             flashlight = 5;
2187             music.playef(9, 10);
2188             break;
2189         case 3004:
2190             //Activating a teleporter 2
2191             state++;
2192             statedelay = 0;
2193             flashlight = 5;
2194             screenshake = 0;
2195             //we're done here!
2196             music.playef(10, 10);
2197             break;
2198         case 3005:
2199             //Activating a teleporter 2
2200             state++;
2201             statedelay = 50;
2202             //testing!
2203             //state = 3006; //Warp Zone
2204             //state = 3020; //Space Station
2205             switch(companion)
2206             {
2207             case 6:
2208                 state = 3006;
2209                 break; //Warp Zone
2210             case 7:
2211                 state = 3020;
2212                 break; //Space Station
2213             case 8:
2214                 state = 3040;
2215                 break; //Lab
2216             case 9:
2217                 state = 3060;
2218                 break; //Tower
2219             case 10:
2220                 state = 3080;
2221                 break; //Intermission 2
2222             case 11:
2223                 state = 3085;
2224                 break; //Intermission 1
2225             }
2226 
2227             i = obj.getplayer();
2228             obj.entities[i].colour = 0;
2229             obj.entities[i].invis = true;
2230 
2231             i = obj.getcompanion(companion);
2232             if(i>-1)
2233             {
2234                 obj.entities[i].active = false;
2235             }
2236 
2237             i = obj.getteleporter();
2238             obj.entities[i].tile = 1;
2239             obj.entities[i].colour = 100;
2240             break;
2241 
2242         case 3006:
2243             //Level complete! (warp zone)
2244             unlocknum(4, map, dwgfx);
2245             lastsaved = 4;
2246             music.play(0);
2247             state++;
2248             statedelay = 75;
2249 
2250             if (dwgfx.flipmode)
2251             {
2252                 dwgfx.createtextbox("", -1, 180, 165, 165, 255);
2253             }
2254             else
2255             {
2256                 dwgfx.createtextbox("", -1, 12, 165, 165, 255);
2257             }
2258             //dwgfx.addline("      Level Complete!      ");
2259             dwgfx.addline("                                   ");
2260             dwgfx.addline("");
2261             dwgfx.addline("");
2262             dwgfx.textboxcenterx();
2263 
2264             /*												advancetext = true;
2265             hascontrol = false;
2266             state = 3;
2267             dwgfx.createtextbox("To do: write quick", 50, 80, 164, 164, 255);
2268             dwgfx.addline("intro to story!");*/
2269             break;
2270         case 3007:
2271             state++;
2272             statedelay = 45;
2273 
2274             if (dwgfx.flipmode)
2275             {
2276                 dwgfx.createtextbox("", -1, 104, 175,174,174);
2277             }
2278             else
2279             {
2280                 dwgfx.createtextbox("", -1, 64+8+16, 175,174,174);
2281             }
2282             dwgfx.addline("     You have rescued  ");
2283             dwgfx.addline("      a crew member!   ");
2284             dwgfx.addline("");
2285             dwgfx.textboxcenterx();
2286             break;
2287         case 3008:
2288             state++;
2289             statedelay = 45;
2290 
2291             temp = 6 - crewrescued();
2292             if (temp == 1)
2293             {
2294                 tempstring = "  One remains  ";
2295                 if (dwgfx.flipmode)
2296                 {
2297                     dwgfx.createtextbox(tempstring, -1, 72, 174, 174, 174);
2298                 }
2299                 else
2300                 {
2301                     dwgfx.createtextbox(tempstring, -1, 128+16, 174, 174, 174);
2302                 }
2303             }
2304             else if (temp > 0)
2305             {
2306                 tempstring = "  " + help.number(temp) + " remain  ";
2307                 if (dwgfx.flipmode)
2308                 {
2309                     dwgfx.createtextbox(tempstring, -1, 72, 174, 174, 174);
2310                 }
2311                 else
2312                 {
2313                     dwgfx.createtextbox(tempstring, -1, 128+16, 174, 174, 174);
2314                 }
2315             }
2316             else
2317             {
2318                 if (dwgfx.flipmode)
2319                 {
2320                     dwgfx.createtextbox("  All Crew Members Rescued!  ", -1, 72, 174, 174, 174);
2321                 }
2322                 else
2323                 {
2324                     dwgfx.createtextbox("  All Crew Members Rescued!  ", -1, 128+16, 174, 174, 174);
2325                 }
2326             }
2327             dwgfx.textboxcenterx();
2328             break;
2329         case 3009:
2330             state++;
2331             statedelay = 0;
2332 
2333             if (dwgfx.flipmode)
2334             {
2335                 dwgfx.createtextbox(" Press ACTION to continue ", -1, 20, 164, 164, 255);
2336             }
2337             else
2338             {
2339                 dwgfx.createtextbox(" Press ACTION to continue ", -1, 196, 164, 164, 255);
2340             }
2341             dwgfx.textboxcenterx();
2342             break;
2343         case 3010:
2344             if (jumppressed)
2345             {
2346                 state++;
2347                 statedelay = 30;
2348                 dwgfx.textboxremove();
2349             }
2350             break;
2351         case 3011:
2352             state = 3070;
2353             statedelay = 0;
2354             break;
2355 
2356         case 3020:
2357             //Level complete! (Space Station 2)
2358             unlocknum(3, map, dwgfx);
2359             lastsaved = 2;
2360             music.play(0);
2361             state++;
2362             statedelay = 75;
2363 
2364 
2365             if (dwgfx.flipmode)
2366             {
2367                 dwgfx.createtextbox("", -1, 180, 165, 165, 255);
2368             }
2369             else
2370             {
2371                 dwgfx.createtextbox("", -1, 12, 165, 165, 255);
2372             }
2373             //dwgfx.addline("      Level Complete!      ");
2374             dwgfx.addline("                                   ");
2375             dwgfx.addline("");
2376             dwgfx.addline("");
2377             dwgfx.textboxcenterx();
2378 
2379             /*												advancetext = true;
2380             hascontrol = false;
2381             state = 3;
2382             dwgfx.createtextbox("To do: write quick", 50, 80, 164, 164, 255);
2383             dwgfx.addline("intro to story!");*/
2384             break;
2385         case 3021:
2386             state++;
2387             statedelay = 45;
2388 
2389             if (dwgfx.flipmode)
2390             {
2391                 dwgfx.createtextbox("", -1, 104, 174,175,174);
2392             }
2393             else
2394             {
2395                 dwgfx.createtextbox("", -1, 64+8+16, 174,175,174);
2396             }
2397             dwgfx.addline("     You have rescued  ");
2398             dwgfx.addline("      a crew member!   ");
2399             dwgfx.addline("");
2400             dwgfx.textboxcenterx();
2401             break;
2402         case 3022:
2403             state++;
2404             statedelay = 45;
2405 
2406             temp = 6 - crewrescued();
2407             if (temp == 1)
2408             {
2409                 tempstring = "  One remains  ";
2410                 if (dwgfx.flipmode)
2411                 {
2412                     dwgfx.createtextbox(tempstring, -1, 72, 174, 174, 174);
2413                 }
2414                 else
2415                 {
2416                     dwgfx.createtextbox(tempstring, -1, 128+16, 174, 174, 174);
2417                 }
2418             }
2419             else if (temp > 0)
2420             {
2421                 tempstring = "  " + help.number(temp) + " remain  ";
2422                 if (dwgfx.flipmode)
2423                 {
2424                     dwgfx.createtextbox(tempstring, -1, 72, 174, 174, 174);
2425                 }
2426                 else
2427                 {
2428                     dwgfx.createtextbox(tempstring, -1, 128+16, 174, 174, 174);
2429                 }
2430             }
2431             else
2432             {
2433                 if (dwgfx.flipmode)
2434                 {
2435                     dwgfx.createtextbox("  All Crew Members Rescued!  ", -1, 72, 174, 174, 174);
2436                 }
2437                 else
2438                 {
2439                     dwgfx.createtextbox("  All Crew Members Rescued!  ", -1, 128+16, 174, 174, 174);
2440                 }
2441             }
2442             dwgfx.textboxcenterx();
2443             break;
2444         case 3023:
2445             state++;
2446             statedelay = 0;
2447 
2448             if (dwgfx.flipmode)
2449             {
2450                 dwgfx.createtextbox(" Press ACTION to continue ", -1, 20, 164, 164, 255);
2451             }
2452             else
2453             {
2454                 dwgfx.createtextbox(" Press ACTION to continue ", -1, 196, 164, 164, 255);
2455             }
2456             dwgfx.textboxcenterx();
2457             break;
2458         case 3024:
2459             if (jumppressed)
2460             {
2461                 state++;
2462                 statedelay = 30;
2463                 dwgfx.textboxremove();
2464             }
2465             break;
2466         case 3025:
2467             state = 3070;
2468             statedelay = 0;
2469             break;
2470 
2471         case 3040:
2472             //Level complete! (Lab)
2473             unlocknum(1, map, dwgfx);
2474             lastsaved = 5;
2475             music.play(0);
2476             state++;
2477             statedelay = 75;
2478 
2479             if (dwgfx.flipmode)
2480             {
2481                 dwgfx.createtextbox("", -1, 180, 165, 165, 255);
2482             }
2483             else
2484             {
2485                 dwgfx.createtextbox("", -1, 12, 165, 165, 255);
2486             }
2487             //dwgfx.addline("      Level Complete!      ");
2488             dwgfx.addline("                                   ");
2489             dwgfx.addline("");
2490             dwgfx.addline("");
2491             dwgfx.textboxcenterx();
2492 
2493             /*												advancetext = true;
2494             hascontrol = false;
2495             state = 3;
2496             dwgfx.createtextbox("To do: write quick", 50, 80, 164, 164, 255);
2497             dwgfx.addline("intro to story!");*/
2498             break;
2499         case 3041:
2500             state++;
2501             statedelay = 45;
2502 
2503             if (dwgfx.flipmode)
2504             {
2505                 dwgfx.createtextbox("", -1, 104, 174,174,175);
2506             }
2507             else
2508             {
2509                 dwgfx.createtextbox("", -1, 64+8+16, 174,174,175);
2510             }
2511             dwgfx.addline("     You have rescued  ");
2512             dwgfx.addline("      a crew member!   ");
2513             dwgfx.addline("");
2514             dwgfx.textboxcenterx();
2515             break;
2516         case 3042:
2517             state++;
2518             statedelay = 45;
2519 
2520             temp = 6 - crewrescued();
2521             if (temp == 1)
2522             {
2523                 tempstring = "  One remains  ";
2524                 if (dwgfx.flipmode)
2525                 {
2526                     dwgfx.createtextbox(tempstring, -1, 72, 174, 174, 174);
2527                 }
2528                 else
2529                 {
2530                     dwgfx.createtextbox(tempstring, -1, 128+16, 174, 174, 174);
2531                 }
2532             }
2533             else if (temp > 0)
2534             {
2535                 tempstring = "  " + help.number(temp) + " remain  ";
2536                 if (dwgfx.flipmode)
2537                 {
2538                     dwgfx.createtextbox(tempstring, -1, 72, 174, 174, 174);
2539                 }
2540                 else
2541                 {
2542                     dwgfx.createtextbox(tempstring, -1, 128+16, 174, 174, 174);
2543                 }
2544             }
2545             else
2546             {
2547                 if (dwgfx.flipmode)
2548                 {
2549                     dwgfx.createtextbox("  All Crew Members Rescued!  ", -1, 72, 174, 174, 174);
2550                 }
2551                 else
2552                 {
2553                     dwgfx.createtextbox("  All Crew Members Rescued!  ", -1, 128+16, 174, 174, 174);
2554                 }
2555             }
2556             dwgfx.textboxcenterx();
2557             break;
2558         case 3043:
2559             state++;
2560             statedelay = 0;
2561 
2562             if (dwgfx.flipmode)
2563             {
2564                 dwgfx.createtextbox(" Press ACTION to continue ", -1, 20, 164, 164, 255);
2565             }
2566             else
2567             {
2568                 dwgfx.createtextbox(" Press ACTION to continue ", -1, 196, 164, 164, 255);
2569             }
2570             dwgfx.textboxcenterx();
2571             break;
2572         case 3044:
2573             if (jumppressed)
2574             {
2575                 state++;
2576                 statedelay = 30;
2577                 dwgfx.textboxremove();
2578             }
2579             break;
2580         case 3045:
2581             state = 3070;
2582             statedelay = 0;
2583             break;
2584 
2585         case 3050:
2586             //Level complete! (Space Station 1)
2587             unlocknum(0, map, dwgfx);
2588             lastsaved = 1;
2589             music.play(0);
2590             state++;
2591             statedelay = 75;
2592 
2593 
2594             if (dwgfx.flipmode)
2595             {
2596                 dwgfx.createtextbox("", -1, 180, 165, 165, 255);
2597             }
2598             else
2599             {
2600                 dwgfx.createtextbox("", -1, 12, 165, 165, 255);
2601             }
2602             //dwgfx.addline("      Level Complete!      ");
2603             dwgfx.addline("                                   ");
2604             dwgfx.addline("");
2605             dwgfx.addline("");
2606             dwgfx.textboxcenterx();
2607 
2608             /*												advancetext = true;
2609             hascontrol = false;
2610             state = 3;
2611             dwgfx.createtextbox("To do: write quick", 50, 80, 164, 164, 255);
2612             dwgfx.addline("intro to story!");*/
2613             break;
2614         case 3051:
2615             state++;
2616             statedelay = 45;
2617 
2618             if (dwgfx.flipmode)
2619             {
2620                 dwgfx.createtextbox("", -1, 104, 175,175,174);
2621             }
2622             else
2623             {
2624                 dwgfx.createtextbox("", -1, 64+8+16, 175,175,174);
2625             }
2626             dwgfx.addline("     You have rescued  ");
2627             dwgfx.addline("      a crew member!   ");
2628             dwgfx.addline("");
2629             dwgfx.textboxcenterx();
2630             break;
2631         case 3052:
2632             state++;
2633             statedelay = 45;
2634 
2635             temp = 6 - crewrescued();
2636             if (temp == 1)
2637             {
2638                 tempstring = "  One remains  ";
2639                 if (dwgfx.flipmode)
2640                 {
2641                     dwgfx.createtextbox(tempstring, -1, 72, 174, 174, 174);
2642                 }
2643                 else
2644                 {
2645                     dwgfx.createtextbox(tempstring, -1, 128+16, 174, 174, 174);
2646                 }
2647             }
2648             else if (temp > 0)
2649             {
2650                 tempstring = "  " + help.number(temp) + " remain  ";
2651                 if (dwgfx.flipmode)
2652                 {
2653                     dwgfx.createtextbox(tempstring, -1, 72, 174, 174, 174);
2654                 }
2655                 else
2656                 {
2657                     dwgfx.createtextbox(tempstring, -1, 128+16, 174, 174, 174);
2658                 }
2659             }
2660             else
2661             {
2662                 if (dwgfx.flipmode)
2663                 {
2664                     dwgfx.createtextbox("  All Crew Members Rescued!  ", -1, 72, 174, 174, 174);
2665                 }
2666                 else
2667                 {
2668                     dwgfx.createtextbox("  All Crew Members Rescued!  ", -1, 128+16, 174, 174, 174);
2669                 }
2670             }
2671             dwgfx.textboxcenterx();
2672             break;
2673         case 3053:
2674             state++;
2675             statedelay = 0;
2676 
2677             if (dwgfx.flipmode)
2678             {
2679                 dwgfx.createtextbox(" Press ACTION to continue ", -1, 20, 164, 164, 255);
2680             }
2681             else
2682             {
2683                 dwgfx.createtextbox(" Press ACTION to continue ", -1, 196, 164, 164, 255);
2684             }
2685             dwgfx.textboxcenterx();
2686             break;
2687         case 3054:
2688             if (jumppressed)
2689             {
2690                 state++;
2691                 statedelay = 30;
2692                 dwgfx.textboxremove();
2693                 crewstats[1] = 0; //Set violet's rescue script to 0 to make the next bit easier
2694                 teleportscript = "";
2695             }
2696             break;
2697         case 3055:
2698             dwgfx.fademode = 2;
2699             state++;
2700             statedelay = 10;
2701             break;
2702         case 3056:
2703             if(dwgfx.fademode==1)
2704             {
2705                 startscript = true;
2706                 if (nocutscenes)
2707                 {
2708                     newscript="bigopenworldskip";
2709                 }
2710                 else
2711                 {
2712                     newscript = "bigopenworld";
2713                 }
2714                 state = 0;
2715             }
2716             break;
2717 
2718 
2719         case 3060:
2720             //Level complete! (Tower)
2721             unlocknum(2, map, dwgfx);
2722             lastsaved = 3;
2723             music.play(0);
2724             state++;
2725             statedelay = 75;
2726 
2727             if (dwgfx.flipmode)
2728             {
2729                 dwgfx.createtextbox("", -1, 180, 165, 165, 255);
2730             }
2731             else
2732             {
2733                 dwgfx.createtextbox("", -1, 12, 165, 165, 255);
2734             }
2735             //dwgfx.addline("      Level Complete!      ");
2736             dwgfx.addline("                                   ");
2737             dwgfx.addline("");
2738             dwgfx.addline("");
2739             dwgfx.textboxcenterx();
2740 
2741             /*												advancetext = true;
2742             hascontrol = false;
2743             state = 3;
2744             dwgfx.createtextbox("To do: write quick", 50, 80, 164, 164, 255);
2745             dwgfx.addline("intro to story!");*/
2746             break;
2747         case 3061:
2748             state++;
2749             statedelay = 45;
2750 
2751             if (dwgfx.flipmode)
2752             {
2753                 dwgfx.createtextbox("", -1, 104, 175,174,175);
2754             }
2755             else
2756             {
2757                 dwgfx.createtextbox("", -1, 64+8+16, 175,174,175);
2758             }
2759             dwgfx.addline("     You have rescued  ");
2760             dwgfx.addline("      a crew member!   ");
2761             dwgfx.addline("");
2762             dwgfx.textboxcenterx();
2763             break;
2764         case 3062:
2765             state++;
2766             statedelay = 45;
2767 
2768             temp = 6 - crewrescued();
2769             if (temp == 1)
2770             {
2771                 tempstring = "  One remains  ";
2772                 if (dwgfx.flipmode)
2773                 {
2774                     dwgfx.createtextbox(tempstring, -1, 72, 174, 174, 174);
2775                 }
2776                 else
2777                 {
2778                     dwgfx.createtextbox(tempstring, -1, 128+16, 174, 174, 174);
2779                 }
2780             }
2781             else if (temp > 0)
2782             {
2783                 tempstring = "  " + help.number(temp) + " remain  ";
2784                 if (dwgfx.flipmode)
2785                 {
2786                     dwgfx.createtextbox(tempstring, -1, 72, 174, 174, 174);
2787                 }
2788                 else
2789                 {
2790                     dwgfx.createtextbox(tempstring, -1, 128+16, 174, 174, 174);
2791                 }
2792             }
2793             else
2794             {
2795                 if (dwgfx.flipmode)
2796                 {
2797                     dwgfx.createtextbox("  All Crew Members Rescued!  ", -1, 72, 174, 174, 174);
2798                 }
2799                 else
2800                 {
2801                     dwgfx.createtextbox("  All Crew Members Rescued!  ", -1, 128+16, 174, 174, 174);
2802                 }
2803             }
2804             dwgfx.textboxcenterx();
2805             break;
2806         case 3063:
2807             state++;
2808             statedelay = 0;
2809 
2810             if (dwgfx.flipmode)
2811             {
2812                 dwgfx.createtextbox(" Press ACTION to continue ", -1, 20, 164, 164, 255);
2813             }
2814             else
2815             {
2816                 dwgfx.createtextbox(" Press ACTION to continue ", -1, 196, 164, 164, 255);
2817             }
2818             dwgfx.textboxcenterx();
2819             break;
2820         case 3064:
2821             if (jumppressed)
2822             {
2823                 state++;
2824                 statedelay = 30;
2825                 dwgfx.textboxremove();
2826             }
2827             break;
2828         case 3065:
2829             state = 3070;
2830             statedelay = 0;
2831             break;
2832 
2833 
2834         case 3070:
2835             dwgfx.fademode = 2;
2836             state++;
2837             break;
2838         case 3071:
2839             if (dwgfx.fademode == 1) state++;
2840             break;
2841         case 3072:
2842             //Ok, we need to adjust some flags based on who've we've rescued. Some of there conversation options
2843             //change depending on when they get back to the ship.
2844             if (lastsaved == 2)
2845             {
2846                 if (crewstats[3]) obj.flags[25] = 1;
2847                 if (crewstats[4]) obj.flags[26] = 1;
2848                 if (crewstats[5]) obj.flags[24] = 1;
2849             }
2850             else if (lastsaved == 3)
2851             {
2852                 if (crewstats[2]) obj.flags[50] = 1;
2853                 if (crewstats[4]) obj.flags[49] = 1;
2854                 if (crewstats[5]) obj.flags[48] = 1;
2855             }
2856             else if (lastsaved == 4)
2857             {
2858                 if (crewstats[2]) obj.flags[54] = 1;
2859                 if (crewstats[3]) obj.flags[55] = 1;
2860                 if (crewstats[5]) obj.flags[56] = 1;
2861             }
2862             else if (lastsaved == 5)
2863             {
2864                 if (crewstats[2]) obj.flags[37] = 1;
2865                 if (crewstats[3]) obj.flags[38] = 1;
2866                 if (crewstats[4]) obj.flags[39] = 1;
2867             }
2868             //We're pitch black now, make a decision
2869             companion = 0;
2870             if (crewrescued() == 6)
2871             {
2872                 startscript = true;
2873                 newscript="startlevel_final";
2874                 state = 0;
2875             }
2876             else if (crewrescued() == 4)
2877             {
2878                 companion = 11;
2879                 supercrewmate = true;
2880                 scmprogress = 0;
2881 
2882                 startscript = true;
2883                 newscript = "intermission_1";
2884                 obj.flags[19] = 1;
2885                 if (lastsaved == 2) obj.flags[32] = 1;
2886                 if (lastsaved == 3) obj.flags[35] = 1;
2887                 if (lastsaved == 4) obj.flags[34] = 1;
2888                 if (lastsaved == 5) obj.flags[33] = 1;
2889                 state = 0;
2890             }
2891             else if (crewrescued() == 5)
2892             {
2893                 startscript = true;
2894                 newscript = "intermission_2";
2895                 obj.flags[20] = 1;
2896                 if (lastsaved == 2) obj.flags[32] = 1;
2897                 if (lastsaved == 3) obj.flags[35] = 1;
2898                 if (lastsaved == 4) obj.flags[34] = 1;
2899                 if (lastsaved == 5) obj.flags[33] = 1;
2900                 state = 0;
2901             }
2902             else
2903             {
2904                 startscript = true;
2905                 newscript="regularreturn";
2906                 state = 0;
2907             }
2908             break;
2909 
2910         case 3080:
2911             //returning from an intermission, very like 3070
2912             if (inintermission)
2913             {
2914                 dwgfx.fademode = 2;
2915                 companion = 0;
2916                 state=3100;
2917             }
2918             else
2919             {
2920                 unlocknum(7, map, dwgfx);
2921                 dwgfx.fademode = 2;
2922                 companion = 0;
2923                 state++;
2924             }
2925             break;
2926         case 3081:
2927             if (dwgfx.fademode == 1) state++;
2928             break;
2929         case 3082:
2930             map.finalmode = false;
2931             startscript = true;
2932             newscript="regularreturn";
2933             state = 0;
2934             break;
2935 
2936         case 3085:
2937             //returning from an intermission, very like 3070
2938             //return to menu from here
2939             if (inintermission)
2940             {
2941                 companion = 0;
2942                 supercrewmate = false;
2943                 state++;
2944                 dwgfx.fademode = 2;
2945                 music.fadeout();
2946                 state=3100;
2947             }
2948             else
2949             {
2950                 unlocknum(6, map, dwgfx);
2951                 dwgfx.fademode = 2;
2952                 companion = 0;
2953                 supercrewmate = false;
2954                 state++;
2955             }
2956             break;
2957         case 3086:
2958             if (dwgfx.fademode == 1) state++;
2959             break;
2960         case 3087:
2961             map.finalmode = false;
2962             startscript = true;
2963             newscript="regularreturn";
2964             state = 0;
2965             break;
2966 
2967         case 3100:
2968             if(dwgfx.fademode == 1)	state++;
2969             break;
2970         case 3101:
2971             dwgfx.flipmode = false;
2972             gamestate = 1;
2973             dwgfx.fademode = 4;
2974             dwgfx.backgrounddrawn = true;
2975             map.tdrawback = true;
2976             createmenu("play");
2977             music.play(6);
2978             state = 0;
2979             break;
2980 
2981             //startscript = true;	newscript="returntohub";
2982             //state = 0;
2983 
2984             /*case 3025:
2985             if (recording == 1) {
2986             //if recording the input, output it to debug here
2987             trace(recordstring);
2988             help.toclipboard(recordstring);
2989             }
2990             test = true; teststring = recordstring;
2991             dwgfx.createtextbox("   Congratulations!    ", 50, 80, 164, 164, 255);
2992             dwgfx.addline("");
2993             dwgfx.addline("Your play of this level has");
2994             dwgfx.addline("been copied to the clipboard.");
2995             dwgfx.addline("");
2996             dwgfx.addline("Please consider pasting and");
2997             dwgfx.addline("sending it to me! Even if you");
2998             dwgfx.addline("made a lot of mistakes - knowing");
2999             dwgfx.addline("exactly where people are having");
3000             dwgfx.addline("trouble is extremely useful!");
3001             dwgfx.textboxcenter();
3002             state = 0;
3003             break;*/
3004 
3005         case 3500:
3006             music.fadeout();
3007             state++;
3008             statedelay = 120;
3009             //state = 3511; //testing
3010             break;
3011         case 3501:
3012             //Game complete!
3013 						NETWORK_unlockAchievement("vvvvvvgamecomplete");
3014             unlocknum(5, map, dwgfx);
3015             crewstats[0] = true;
3016             state++;
3017             statedelay = 75;
3018             music.play(7);
3019 
3020             if (dwgfx.flipmode)
3021             {
3022                 dwgfx.createtextbox("", -1, 180, 164, 165, 255);
3023             }
3024             else
3025             {
3026                 dwgfx.createtextbox("", -1, 12, 164, 165, 255);
3027             }
3028             dwgfx.addline("                                   ");
3029             dwgfx.addline("");
3030             dwgfx.addline("");
3031             dwgfx.textboxcenterx();
3032             break;
3033         case 3502:
3034             state++;
3035             statedelay = 45+15;
3036 
3037             if (dwgfx.flipmode)
3038             {
3039                 dwgfx.createtextbox("  All Crew Members Rescued!  ", -1, 175-24, 0, 0, 0);
3040             }
3041             else
3042             {
3043                 dwgfx.createtextbox("  All Crew Members Rescued!  ", -1, 64, 0, 0, 0);
3044             }
3045             savetime = timestring(help);
3046             break;
3047         case 3503:
3048             state++;
3049             statedelay = 45;
3050 
3051             tempstring = help.number(trinkets);
3052             if (dwgfx.flipmode)
3053             {
3054                 dwgfx.createtextbox("Trinkets Found:", 48, 155-24, 0,0,0);
3055                 dwgfx.createtextbox(tempstring, 180, 155-24, 0, 0, 0);
3056             }
3057             else
3058             {
3059                 dwgfx.createtextbox("Trinkets Found:", 48, 84, 0,0,0);
3060                 dwgfx.createtextbox(tempstring, 180, 84, 0, 0, 0);
3061             }
3062             break;
3063         case 3504:
3064             state++;
3065             statedelay = 45+15;
3066 
3067             tempstring = savetime;
3068             if (dwgfx.flipmode)
3069             {
3070                 dwgfx.createtextbox("   Game Time:", 64, 143-24, 0,0,0);
3071                 dwgfx.createtextbox(tempstring, 180, 143-24, 0, 0, 0);
3072             }
3073             else
3074             {
3075                 dwgfx.createtextbox("   Game Time:", 64, 96, 0,0,0);
3076                 dwgfx.createtextbox(tempstring, 180, 96, 0, 0, 0);
3077             }
3078             break;
3079         case 3505:
3080             state++;
3081             statedelay = 45;
3082 
3083             if (dwgfx.flipmode)
3084             {
3085                 dwgfx.createtextbox(" Total Flips:", 64, 116-24, 0,0,0);
3086                 dwgfx.createtextbox(help.String(totalflips), 180, 116-24, 0, 0, 0);
3087             }
3088             else
3089             {
3090                 dwgfx.createtextbox(" Total Flips:", 64, 123, 0,0,0);
3091                 dwgfx.createtextbox(help.String(totalflips), 180, 123, 0, 0, 0);
3092             }
3093             break;
3094         case 3506:
3095             state++;
3096             statedelay = 45+15;
3097 
3098             if (dwgfx.flipmode)
3099             {
3100                 dwgfx.createtextbox("Total Deaths:", 64, 104-24, 0,0,0);
3101                 dwgfx.createtextbox(help.String(deathcounts), 180, 104-24, 0, 0, 0);
3102             }
3103             else
3104             {
3105                 dwgfx.createtextbox("Total Deaths:", 64, 135, 0,0,0);
3106                 dwgfx.createtextbox(help.String(deathcounts), 180, 135, 0, 0, 0);
3107             }
3108             break;
3109         case 3507:
3110             state++;
3111             statedelay = 45+15;
3112 
3113             if (dwgfx.flipmode)
3114             {
3115                 tempstring = "Hardest Room (with " + help.String(hardestroomdeaths) + " deaths)";
3116                 dwgfx.createtextbox(tempstring, -1, 81-24, 0,0,0);
3117                 dwgfx.createtextbox(hardestroom, -1, 69-24, 0, 0, 0);
3118             }
3119             else
3120             {
3121                 tempstring = "Hardest Room (with " + help.String(hardestroomdeaths) + " deaths)";
3122                 dwgfx.createtextbox(tempstring, -1, 158, 0,0,0);
3123                 dwgfx.createtextbox(hardestroom, -1, 170, 0, 0, 0);
3124             }
3125             break;
3126         case 3508:
3127             state++;
3128             statedelay = 0;
3129 
3130             if (dwgfx.flipmode)
3131             {
3132                 dwgfx.createtextbox(" Press ACTION to continue ", -1, 20, 164, 164, 255);
3133             }
3134             else
3135             {
3136                 dwgfx.createtextbox(" Press ACTION to continue ", -1, 196, 164, 164, 255);
3137             }
3138             dwgfx.textboxcenterx();
3139             break;
3140         case 3509:
3141             if (jumppressed)
3142             {
3143                 state++;
3144                 statedelay = 30;
3145                 dwgfx.textboxremove();
3146             }
3147             break;
3148         case 3510:
3149             //Save stats and stuff here
3150             if (obj.flags[73] == 0)
3151             {
3152                 //flip mode complete
3153 								NETWORK_unlockAchievement("vvvvvvgamecompleteflip");
3154                 unlock[19] = true;
3155             }
3156 
3157             if (bestgamedeaths == -1)
3158             {
3159                 bestgamedeaths = deathcounts;
3160             }
3161             else
3162             {
3163                 if (deathcounts < bestgamedeaths)
3164                 {
3165                     bestgamedeaths = deathcounts;
3166                 }
3167             }
3168 
3169 						if (bestgamedeaths > -1) {
3170 							if (bestgamedeaths <= 500) {
3171 							  NETWORK_unlockAchievement("vvvvvvcomplete500");
3172 							}
3173 							if (bestgamedeaths <= 250) {
3174 								NETWORK_unlockAchievement("vvvvvvcomplete250");
3175 							}
3176 							if (bestgamedeaths <= 100) {
3177 								NETWORK_unlockAchievement("vvvvvvcomplete100");
3178 							}
3179 							if (bestgamedeaths <= 50) {
3180 								NETWORK_unlockAchievement("vvvvvvcomplete50");
3181 							}
3182 						}
3183 
3184 
3185             savestats(map, dwgfx);
3186             if (nodeathmode)
3187             {
3188 								NETWORK_unlockAchievement("vvvvvvmaster"); //bloody hell
3189                 unlock[20] = true;
3190                 state = 3520;
3191                 statedelay = 0;
3192             }
3193             else
3194             {
3195                 statedelay = 120;
3196                 state++;
3197             }
3198             break;
3199         case 3511:
3200             //Activating a teleporter (long version for level complete)
3201             i = obj.getplayer();
3202             obj.entities[i].colour = 102;
3203 
3204             obj.flags[67] = 1;
3205 
3206             state++;
3207             statedelay = 30;
3208             flashlight = 5;
3209             screenshake = 90;
3210             music.playef(9, 10);
3211             break;
3212         case 3512:
3213             //Activating a teleporter 2
3214             state++;
3215             statedelay = 15;
3216             flashlight = 5;
3217             music.playef(9, 10);
3218             break;
3219         case 3513:
3220             //Activating a teleporter 2
3221             state++;
3222             statedelay = 15;
3223             flashlight = 5;
3224             music.playef(9, 10);
3225             break;
3226         case 3514:
3227             //Activating a teleporter 2
3228             state++;
3229             statedelay = 15;
3230             flashlight = 5;
3231             music.playef(9, 10);
3232             break;
3233         case 3515:
3234             //Activating a teleporter 2
3235             state++;
3236             statedelay = 0;
3237             flashlight = 5;
3238             screenshake = 0;
3239 
3240             i = obj.getplayer();
3241             obj.entities[i].colour = 0;
3242             obj.entities[i].invis = true;
3243 
3244             //we're done here!
3245             music.playef(10, 10);
3246             statedelay = 60;
3247             break;
3248         case 3516:
3249             dwgfx.fademode = 2;
3250             state++;
3251             break;
3252         case 3517:
3253             if (dwgfx.fademode == 1)
3254             {
3255                 state++;
3256                 statedelay = 30;
3257             }
3258             break;
3259         case 3518:
3260             dwgfx.fademode = 4;
3261             state = 0;
3262             statedelay = 30;
3263             //music.play(5);
3264             //music.play(10);
3265 
3266             map.finalmode = false;
3267             map.final_colormode = false;
3268             map.final_mapcol = 0;
3269             map.final_colorframe = 0;
3270             map.finalstretch = false;
3271             map.finalx = 100;
3272             map.finaly = 100;
3273 
3274             dwgfx.cutscenebarspos = 320;
3275 
3276             teleport_to_new_area = true;
3277             teleportscript = "gamecomplete";
3278             break;
3279 
3280         case 3520:
3281             //NO DEATH MODE COMPLETE JESUS
3282             hascontrol = false;
3283             crewstats[0] = true;
3284 
3285             dwgfx.fademode = 2;
3286             state++;
3287             break;
3288         case 3521:
3289             if(dwgfx.fademode == 1)	state++;
3290             break;
3291         case 3522:
3292             dwgfx.flipmode = false;
3293             gamestate = 1;
3294             dwgfx.fademode = 4;
3295             dwgfx.backgrounddrawn = true;
3296             map.tdrawback = true;
3297             createmenu("nodeathmodecomplete");
3298             state = 0;
3299             break;
3300 
3301         case 4000:
3302             //Activating a teleporter (short version)
3303             state++;
3304             statedelay = 10;
3305             flashlight = 5;
3306             screenshake = 10;
3307             music.playef(9, 10);
3308             break;
3309         case 4001:
3310             //Activating a teleporter 2
3311             state++;
3312             statedelay = 0;
3313             flashlight = 5;
3314             screenshake = 0;
3315             //we're done here!
3316             music.playef(10, 10);
3317             break;
3318         case 4002:
3319             //Activating a teleporter 2
3320             state++;
3321             statedelay = 10;
3322             //testing!
3323             //state = 3006; //Warp Zone
3324             //state = 3020; //Space Station
3325             //state = 3040; //Lab
3326 
3327             i = obj.getplayer();
3328             obj.entities[i].colour = 0;
3329             obj.entities[i].invis = true;
3330 
3331             i = obj.getteleporter();
3332             if(i>-1)
3333             {
3334                 obj.entities[i].tile = 1;
3335                 obj.entities[i].colour = 100;
3336             }
3337             break;
3338         case 4003:
3339             state = 0;
3340             statedelay = 0;
3341             teleport_to_new_area = true;
3342             break;
3343 
3344         case 4010:
3345             //Activating a teleporter (default appear)
3346             state++;
3347             statedelay = 15;
3348             flashlight = 5;
3349             screenshake = 90;
3350             music.playef(9, 10);
3351             break;
3352         case 4011:
3353             //Activating a teleporter 2
3354             state++;
3355             statedelay = 0;
3356             flashlight = 5;
3357             screenshake = 0;
3358             music.playef(10, 10);
3359             break;
3360         case 4012:
3361             //Activating a teleporter 2
3362             state++;
3363             statedelay = 5;
3364 
3365             i = obj.getplayer();
3366             j = obj.getteleporter();
3367             if (j != -1)
3368             {
3369                 obj.entities[i].xp = obj.entities[j].xp+44;
3370                 obj.entities[i].yp = obj.entities[j].yp+44;
3371                 obj.entities[j].tile = 2;
3372                 obj.entities[j].colour = 101;
3373             }
3374             obj.entities[i].colour = 0;
3375             obj.entities[i].invis = false;
3376             obj.entities[i].dir = 1;
3377 
3378             obj.entities[i].ay = -6;
3379             obj.entities[i].ax = 6;
3380             obj.entities[i].vy = -6;
3381             obj.entities[i].vx = 6;
3382             break;
3383         case 4013:
3384             state++;
3385             i = obj.getplayer();
3386             obj.entities[i].xp += 10;
3387             break;
3388         case 4014:
3389             state++;
3390             i = obj.getplayer();
3391             obj.entities[i].xp += 10;
3392             break;
3393         case 4015:
3394             state++;
3395             i = obj.getplayer();
3396             obj.entities[i].xp += 8;
3397             break;
3398         case 4016:
3399             state++;
3400             i = obj.getplayer();
3401             obj.entities[i].xp += 6;
3402             break;
3403         case 4017:
3404             state++;
3405             i = obj.getplayer();
3406             obj.entities[i].xp += 3;
3407             break;
3408         case 4018:
3409             state++;
3410             statedelay = 15;
3411             i = obj.getplayer();
3412             obj.entities[i].xp += 1;
3413             break;
3414         case 4019:
3415             if (intimetrial || nodeathmode || inintermission)
3416             {
3417             }
3418             else
3419             {
3420                 savetele(map, obj, music);
3421             }
3422             i = obj.getteleporter();
3423             activetele = true;
3424             teleblock.x = obj.entities[i].xp - 32;
3425             teleblock.y = obj.entities[i].yp - 32;
3426             teleblock.w = 160;
3427             teleblock.h = 160;
3428             hascontrol = true;
3429             advancetext = false;
3430             state = 0;
3431             break;
3432 
3433         case 4020:
3434             //Activating a teleporter (default appear)
3435             state++;
3436             statedelay = 15;
3437             flashlight = 5;
3438             screenshake = 90;
3439             music.playef(9, 10);
3440             break;
3441         case 4021:
3442             //Activating a teleporter 2
3443             state++;
3444             statedelay = 0;
3445             flashlight = 5;
3446             screenshake = 0;
3447             music.playef(10, 10);
3448             break;
3449         case 4022:
3450             //Activating a teleporter 2
3451             state++;
3452             statedelay = 5;
3453 
3454             i = obj.getplayer();
3455             j = obj.getteleporter();
3456             if (j != -1)
3457             {
3458                 obj.entities[i].xp = obj.entities[j].xp+44;
3459                 obj.entities[i].yp = obj.entities[j].yp+44;
3460                 obj.entities[j].tile = 2;
3461                 obj.entities[j].colour = 101;
3462             }
3463             obj.entities[i].colour = 0;
3464             obj.entities[i].invis = false;
3465             obj.entities[i].dir = 1;
3466 
3467             obj.entities[i].ay = -6;
3468             obj.entities[i].ax = 6;
3469             obj.entities[i].vy = -6;
3470             obj.entities[i].vx = 6;
3471             break;
3472         case 4023:
3473             state++;
3474             i = obj.getplayer();
3475             obj.entities[i].xp += 12;
3476             break;
3477         case 4024:
3478             state++;
3479             i = obj.getplayer();
3480             obj.entities[i].xp += 12;
3481             break;
3482         case 4025:
3483             state++;
3484             i = obj.getplayer();
3485             obj.entities[i].xp += 10;
3486             break;
3487         case 4026:
3488             state++;
3489             i = obj.getplayer();
3490             obj.entities[i].xp += 8;
3491             break;
3492         case 4027:
3493             state++;
3494             i = obj.getplayer();
3495             obj.entities[i].xp += 5;
3496             break;
3497         case 4028:
3498             state++;
3499             statedelay = 15;
3500             i = obj.getplayer();
3501             obj.entities[i].xp += 2;
3502             break;
3503         case 4029:
3504             hascontrol = true;
3505             advancetext = false;
3506             state = 0;
3507             break;
3508 
3509         case 4030:
3510             //Activating a teleporter (default appear)
3511             state++;
3512             statedelay = 15;
3513             flashlight = 5;
3514             screenshake = 90;
3515             music.playef(9, 10);
3516             break;
3517         case 4031:
3518             //Activating a teleporter 2
3519             state++;
3520             statedelay = 0;
3521             flashlight = 5;
3522             screenshake = 0;
3523             music.playef(10, 10);
3524             break;
3525         case 4032:
3526             //Activating a teleporter 2
3527             state++;
3528             statedelay = 5;
3529 
3530             i = obj.getplayer();
3531             j = obj.getteleporter();
3532             if (j != -1)
3533             {
3534                 obj.entities[i].xp = obj.entities[j].xp+44;
3535                 obj.entities[i].yp = obj.entities[j].yp+44;
3536                 obj.entities[j].tile = 2;
3537                 obj.entities[j].colour = 101;
3538             }
3539             obj.entities[i].colour = 0;
3540             obj.entities[i].invis = false;
3541             obj.entities[i].dir = 0;
3542 
3543             obj.entities[i].ay = -6;
3544             obj.entities[i].ax = -6;
3545             obj.entities[i].vy = -6;
3546             obj.entities[i].vx = -6;
3547             break;
3548         case 4033:
3549             state++;
3550             i = obj.getplayer();
3551             obj.entities[i].xp -= 12;
3552             break;
3553         case 4034:
3554             state++;
3555             i = obj.getplayer();
3556             obj.entities[i].xp -= 12;
3557             break;
3558         case 4035:
3559             state++;
3560             i = obj.getplayer();
3561             obj.entities[i].xp -= 10;
3562             break;
3563         case 4036:
3564             state++;
3565             i = obj.getplayer();
3566             obj.entities[i].xp -= 8;
3567             break;
3568         case 4037:
3569             state++;
3570             i = obj.getplayer();
3571             obj.entities[i].xp -= 5;
3572             break;
3573         case 4038:
3574             state++;
3575             statedelay = 15;
3576             i = obj.getplayer();
3577             obj.entities[i].xp -= 2;
3578             break;
3579         case 4039:
3580             hascontrol = true;
3581             advancetext = false;
3582             state = 0;
3583             break;
3584 
3585         case 4040:
3586             //Activating a teleporter (default appear)
3587             state++;
3588             statedelay = 15;
3589             flashlight = 5;
3590             screenshake = 90;
3591             music.playef(9, 10);
3592             break;
3593         case 4041:
3594             //Activating a teleporter 2
3595             state++;
3596             statedelay = 0;
3597             flashlight = 5;
3598             screenshake = 0;
3599             music.playef(10, 10);
3600             break;
3601         case 4042:
3602             //Activating a teleporter 2
3603             state++;
3604             statedelay = 5;
3605 
3606             i = obj.getplayer();
3607             j = obj.getteleporter();
3608             if (j != -1)
3609             {
3610                 obj.entities[i].xp = obj.entities[j].xp+44;
3611                 obj.entities[i].yp = obj.entities[j].yp+44;
3612                 obj.entities[j].tile = 2;
3613                 obj.entities[j].colour = 101;
3614             }
3615             obj.entities[i].colour = 0;
3616             obj.entities[i].invis = false;
3617             obj.entities[i].dir = 1;
3618 
3619             obj.entities[i].ay = -6;
3620             obj.entities[i].ax = 6;
3621             obj.entities[i].vy = -6;
3622             obj.entities[i].vx = 6;
3623             break;
3624         case 4043:
3625             state++;
3626             i = obj.getplayer();
3627             obj.entities[i].xp += 12;
3628             obj.entities[i].yp -= 15;
3629             break;
3630         case 4044:
3631             state++;
3632             i = obj.getplayer();
3633             obj.entities[i].xp += 12;
3634             obj.entities[i].yp -= 10;
3635             break;
3636         case 4045:
3637             state++;
3638             i = obj.getplayer();
3639             obj.entities[i].xp += 12;
3640             obj.entities[i].yp -= 10;
3641             break;
3642         case 4046:
3643             state++;
3644             i = obj.getplayer();
3645             obj.entities[i].xp += 8;
3646             obj.entities[i].yp -= 8;
3647             break;
3648         case 4047:
3649             state++;
3650             i = obj.getplayer();
3651             obj.entities[i].xp += 6;
3652             obj.entities[i].yp -= 8;
3653             break;
3654         case 4048:
3655             state++;
3656             statedelay = 15;
3657             i = obj.getplayer();
3658             obj.entities[i].xp += 3;
3659             break;
3660         case 4049:
3661             hascontrol = true;
3662             advancetext = false;
3663             state = 0;
3664             break;
3665 
3666         case 4050:
3667             //Activating a teleporter (default appear)
3668             state++;
3669             statedelay = 15;
3670             flashlight = 5;
3671             screenshake = 90;
3672             music.playef(9, 10);
3673             break;
3674         case 4051:
3675             //Activating a teleporter 2
3676             state++;
3677             statedelay = 0;
3678             flashlight = 5;
3679             screenshake = 0;
3680             music.playef(10, 10);
3681             break;
3682         case 4052:
3683             //Activating a teleporter 2
3684             state++;
3685             statedelay = 5;
3686 
3687             i = obj.getplayer();
3688             j = obj.getteleporter();
3689             if (j != -1)
3690             {
3691                 obj.entities[i].xp = obj.entities[j].xp+44;
3692                 obj.entities[i].yp = obj.entities[j].yp+44;
3693                 obj.entities[j].tile = 2;
3694                 obj.entities[j].colour = 101;
3695             }
3696             obj.entities[i].colour = 0;
3697             obj.entities[i].invis = false;
3698             obj.entities[i].dir = 1;
3699 
3700             obj.entities[i].ay = -6;
3701             obj.entities[i].ax = 6;
3702             obj.entities[i].vy = -6;
3703             obj.entities[i].vx = 6;
3704             break;
3705         case 4053:
3706             state++;
3707             i = obj.getplayer();
3708             obj.entities[i].xp += 4;
3709             obj.entities[i].yp -= 15;
3710             break;
3711         case 4054:
3712             state++;
3713             i = obj.getplayer();
3714             obj.entities[i].xp += 4;
3715             obj.entities[i].yp -= 10;
3716             break;
3717         case 4055:
3718             state++;
3719             i = obj.getplayer();
3720             obj.entities[i].xp += 4;
3721             obj.entities[i].yp -= 10;
3722             break;
3723         case 4056:
3724             state++;
3725             i = obj.getplayer();
3726             obj.entities[i].xp += 4;
3727             obj.entities[i].yp -= 8;
3728             break;
3729         case 4057:
3730             state++;
3731             i = obj.getplayer();
3732             obj.entities[i].xp += 2;
3733             obj.entities[i].yp -= 8;
3734             break;
3735         case 4058:
3736             state++;
3737             statedelay = 15;
3738             i = obj.getplayer();
3739             obj.entities[i].xp += 1;
3740             break;
3741         case 4059:
3742             hascontrol = true;
3743             advancetext = false;
3744             state = 0;
3745             break;
3746 
3747         case 4060:
3748             //Activating a teleporter (default appear)
3749             state++;
3750             statedelay = 15;
3751             flashlight = 5;
3752             screenshake = 90;
3753             music.playef(9, 10);
3754             break;
3755         case 4061:
3756             //Activating a teleporter 2
3757             state++;
3758             statedelay = 0;
3759             flashlight = 5;
3760             screenshake = 0;
3761             music.playef(10, 10);
3762             break;
3763         case 4062:
3764             //Activating a teleporter 2
3765             state++;
3766             statedelay = 5;
3767 
3768             i = obj.getplayer();
3769             j = obj.getteleporter();
3770             if (j != -1)
3771             {
3772                 obj.entities[i].xp = obj.entities[j].xp+44;
3773                 obj.entities[i].yp = obj.entities[j].yp+44;
3774                 obj.entities[j].tile = 2;
3775                 obj.entities[j].colour = 101;
3776             }
3777             obj.entities[i].colour = 0;
3778             obj.entities[i].invis = false;
3779             obj.entities[i].dir = 0;
3780 
3781             obj.entities[i].ay = -6;
3782             obj.entities[i].ax = -6;
3783             obj.entities[i].vy = -6;
3784             obj.entities[i].vx = -6;
3785             break;
3786         case 4063:
3787             state++;
3788             i = obj.getplayer();
3789             obj.entities[i].xp -= 28;
3790             obj.entities[i].yp -= 8;
3791             break;
3792         case 4064:
3793             state++;
3794             i = obj.getplayer();
3795             obj.entities[i].xp -= 28;
3796             obj.entities[i].yp -= 8;
3797             break;
3798         case 4065:
3799             state++;
3800             i = obj.getplayer();
3801             obj.entities[i].xp -= 25;
3802             break;
3803         case 4066:
3804             state++;
3805             i = obj.getplayer();
3806             obj.entities[i].xp -= 25;
3807             break;
3808         case 4067:
3809             state++;
3810             i = obj.getplayer();
3811             obj.entities[i].xp -= 20;
3812             break;
3813         case 4068:
3814             state++;
3815             statedelay = 15;
3816             i = obj.getplayer();
3817             obj.entities[i].xp -= 16;
3818             break;
3819         case 4069:
3820             hascontrol = true;
3821             advancetext = false;
3822             state = 0;
3823             break;
3824 
3825 
3826         case 4070:
3827             //Activating a teleporter (special for final script, player has colour changed to match rescued crewmate)
3828             state++;
3829             statedelay = 15;
3830             flashlight = 5;
3831             screenshake = 90;
3832             music.playef(9, 10);
3833             break;
3834         case 4071:
3835             //Activating a teleporter 2
3836             state++;
3837             statedelay = 0;
3838             flashlight = 5;
3839             screenshake = 0;
3840             music.playef(10, 10);
3841             break;
3842         case 4072:
3843             //Activating a teleporter 2
3844             state++;
3845             statedelay = 5;
3846 
3847             i = obj.getplayer();
3848             j = obj.getteleporter();
3849             if (j != -1)
3850             {
3851                 obj.entities[i].xp = obj.entities[j].xp+44;
3852                 obj.entities[i].yp = obj.entities[j].yp+44;
3853                 obj.entities[j].tile = 2;
3854                 obj.entities[j].colour = 101;
3855             }
3856             obj.entities[i].invis = false;
3857             obj.entities[i].dir = 1;
3858             obj.entities[i].colour = obj.crewcolour(lastsaved);
3859 
3860             obj.entities[i].ay = -6;
3861             obj.entities[i].ax = 6;
3862             obj.entities[i].vy = -6;
3863             obj.entities[i].vx = 6;
3864             break;
3865         case 4073:
3866             state++;
3867             i = obj.getplayer();
3868             obj.entities[i].xp += 10;
3869             break;
3870         case 4074:
3871             state++;
3872             i = obj.getplayer();
3873             obj.entities[i].xp += 10;
3874             break;
3875         case 4075:
3876             state++;
3877             i = obj.getplayer();
3878             obj.entities[i].xp += 8;
3879             break;
3880         case 4076:
3881             state++;
3882             i = obj.getplayer();
3883             obj.entities[i].xp += 6;
3884             break;
3885         case 4077:
3886             state++;
3887             i = obj.getplayer();
3888             obj.entities[i].xp += 3;
3889             break;
3890         case 4078:
3891             state++;
3892             statedelay = 15;
3893             i = obj.getplayer();
3894             obj.entities[i].xp += 1;
3895             break;
3896         case 4079:
3897             state = 0;
3898             startscript = true;
3899             newscript = "finallevel_teleporter";
3900             break;
3901 
3902         case 4080:
3903             //Activating a teleporter (default appear)
3904             state++;
3905             statedelay = 15;
3906             flashlight = 5;
3907             screenshake = 90;
3908             music.playef(9, 10);
3909             break;
3910         case 4081:
3911             //Activating a teleporter 2
3912             state++;
3913             statedelay = 0;
3914             flashlight = 5;
3915             screenshake = 0;
3916             music.playef(10, 10);
3917             break;
3918         case 4082:
3919             //Activating a teleporter 2
3920             state++;
3921             statedelay = 5;
3922 
3923             i = obj.getplayer();
3924             j = obj.getteleporter();
3925             if (j != -1)
3926             {
3927                 obj.entities[i].xp = obj.entities[j].xp+44;
3928                 obj.entities[i].yp = obj.entities[j].yp+44;
3929                 obj.entities[j].tile = 2;
3930                 obj.entities[j].colour = 101;
3931             }
3932             obj.entities[i].colour = 0;
3933             obj.entities[i].invis = false;
3934             obj.entities[i].dir = 1;
3935 
3936             obj.entities[i].ay = -6;
3937             obj.entities[i].ax = 6;
3938             obj.entities[i].vy = -6;
3939             obj.entities[i].vx = 6;
3940             break;
3941         case 4083:
3942             state++;
3943             i = obj.getplayer();
3944             obj.entities[i].xp += 10;
3945             break;
3946         case 4084:
3947             state++;
3948             i = obj.getplayer();
3949             obj.entities[i].xp += 10;
3950             break;
3951         case 4085:
3952             state++;
3953             i = obj.getplayer();
3954             obj.entities[i].xp += 8;
3955             break;
3956         case 4086:
3957             state++;
3958             i = obj.getplayer();
3959             obj.entities[i].xp += 6;
3960             break;
3961         case 4087:
3962             state++;
3963             i = obj.getplayer();
3964             obj.entities[i].xp += 3;
3965             break;
3966         case 4088:
3967             state++;
3968             statedelay = 15;
3969             i = obj.getplayer();
3970             obj.entities[i].xp += 1;
3971             break;
3972         case 4089:
3973             startscript = true;
3974             newscript = "gamecomplete_ending";
3975             state = 0;
3976             break;
3977 
3978         case 4090:
3979             //Activating a teleporter (default appear)
3980             state++;
3981             statedelay = 15;
3982             flashlight = 5;
3983             screenshake = 90;
3984             music.playef(9, 10);
3985             break;
3986         case 4091:
3987             //Activating a teleporter 2
3988             state++;
3989             statedelay = 0;
3990             flashlight = 5;
3991             screenshake = 0;
3992             music.playef(10, 10);
3993             break;
3994         case 4092:
3995             //Activating a teleporter 2
3996             state++;
3997             statedelay = 5;
3998 
3999             i = obj.getplayer();
4000             j = obj.getteleporter();
4001             if (j != -1)
4002             {
4003                 obj.entities[i].xp = obj.entities[j].xp+44;
4004                 obj.entities[i].yp = obj.entities[j].yp+44;
4005                 obj.entities[j].tile = 2;
4006                 obj.entities[j].colour = 101;
4007             }
4008             obj.entities[i].colour = 0;
4009             obj.entities[i].invis = false;
4010             obj.entities[i].dir = 1;
4011 
4012             obj.entities[i].ay = -6;
4013             obj.entities[i].ax = 6;
4014             obj.entities[i].vy = -6;
4015             obj.entities[i].vx = 6;
4016             break;
4017         case 4093:
4018             state++;
4019             i = obj.getplayer();
4020             obj.entities[i].xp += 10;
4021             break;
4022         case 4094:
4023             state++;
4024             i = obj.getplayer();
4025             obj.entities[i].xp += 10;
4026             break;
4027         case 4095:
4028             state++;
4029             i = obj.getplayer();
4030             obj.entities[i].xp += 8;
4031             break;
4032         case 4096:
4033             state++;
4034             i = obj.getplayer();
4035             obj.entities[i].xp += 6;
4036             break;
4037         case 4097:
4038             state++;
4039             i = obj.getplayer();
4040             obj.entities[i].xp += 3;
4041             break;
4042         case 4098:
4043             state++;
4044             statedelay = 15;
4045             i = obj.getplayer();
4046             obj.entities[i].xp += 1;
4047             break;
4048         case 4099:
4049             if (nocutscenes)
4050             {
4051                 startscript = true;
4052                 newscript = "levelonecompleteskip";
4053             }
4054             else
4055             {
4056                 startscript = true;
4057                 newscript = "levelonecomplete_ending";
4058             }
4059             state = 0;
4060             break;
4061         }
4062     }
4063 }
4064 
gethardestroom(mapclass & map)4065 void Game::gethardestroom( mapclass& map )
4066 {
4067     if (currentroomdeaths > hardestroomdeaths)
4068     {
4069         hardestroomdeaths = currentroomdeaths;
4070         hardestroom = map.roomname;
4071         if (map.roomname == "glitch")
4072         {
4073             if (roomx == 42 && roomy == 51)
4074             {
4075                 hardestroom = "Rear Vindow";
4076             }
4077             else if (roomx == 48 && roomy == 51)
4078             {
4079                 hardestroom = "On the Vaterfront";
4080             }
4081             else if (roomx == 49 && roomy == 51)
4082             {
4083                 hardestroom = "The Untouchavles";
4084             }
4085         }
4086         else if (map.roomname == "change")
4087         {
4088             if (roomx == 45 && roomy == 51) hardestroom =map.specialnames[3];
4089             if (roomx == 46 && roomy == 51) hardestroom =map.specialnames[4];
4090             if (roomx == 47 && roomy == 51) hardestroom =map.specialnames[5];
4091             if (roomx == 50 && roomy == 53) hardestroom =map.specialnames[6];
4092             if (roomx == 50 && roomy == 54) hardestroom = map.specialnames[7];
4093         }
4094     }
4095 }
4096 
deletestats(mapclass & map,Graphics & dwgfx)4097 void Game::deletestats( mapclass& map, Graphics& dwgfx )
4098 {
4099     for (int i = 0; i < 25; i++)
4100     {
4101         unlock[i] = false;
4102         unlocknotify[i] = false;
4103     }
4104     for (int i = 0; i < 6; i++)
4105     {
4106         besttimes[i] = -1;
4107         besttrinkets[i] = -1;
4108         bestlives[i] = -1;
4109         bestrank[i] = -1;
4110     }
4111     dwgfx.setflipmode = false;
4112     stat_trinkets = 0;
4113     savestats(map, dwgfx);
4114 }
4115 
unlocknum(int t,mapclass & map,Graphics & dwgfx)4116 void Game::unlocknum( int t, mapclass& map, Graphics& dwgfx )
4117 {
4118     unlock[t] = true;
4119     savestats(map, dwgfx);
4120 }
4121 
loadstats(mapclass & map,Graphics & dwgfx)4122 void Game::loadstats( mapclass& map, Graphics& dwgfx )
4123 {
4124     // TODO loadstats
4125     TiXmlDocument doc((saveFilePath+"unlock.vvv").c_str());
4126     if (!doc.LoadFile())
4127     {
4128         savestats(map, dwgfx);
4129         printf("No Stats found. Assuming a new player\n");
4130     }
4131 
4132     TiXmlHandle hDoc(&doc);
4133     TiXmlElement* pElem;
4134     TiXmlHandle hRoot(0);
4135 
4136 
4137     {
4138         pElem=hDoc.FirstChildElement().Element();
4139         // should always have a valid root but handle gracefully if it does
4140         if (!pElem)
4141         {
4142 
4143         }
4144         ;
4145 
4146         // save this for later
4147         hRoot=TiXmlHandle(pElem);
4148     }
4149 
4150     // WINDOW DIMS, ADDED AT PATCH 22
4151     int width = 320;
4152     int height = 240;
4153 
4154     for( pElem = hRoot.FirstChild( "Data" ).FirstChild().Element(); pElem; pElem=pElem->NextSiblingElement())
4155     {
4156         std::string pKey(pElem->Value());
4157         const char* pText = pElem->GetText() ;
4158 
4159         if (pKey == "unlock")
4160         {
4161             std::string TextString = (pText);
4162             if(TextString.length())
4163             {
4164                 std::vector<std::string> values = split(TextString,',');
4165                 unlock.clear();
4166                 for(size_t i = 0; i < values.size(); i++)
4167                 {
4168                     unlock.push_back(atoi(values[i].c_str()));
4169                 }
4170             }
4171         }
4172 
4173         if (pKey == "unlocknotify")
4174         {
4175             std::string TextString = (pText);
4176             if(TextString.length())
4177             {
4178                 std::vector<std::string> values = split(TextString,',');
4179                 unlocknotify.clear();
4180                 for(size_t i = 0; i < values.size(); i++)
4181                 {
4182                     unlocknotify.push_back(atoi(values[i].c_str()));
4183                 }
4184             }
4185         }
4186 
4187         if (pKey == "besttimes")
4188         {
4189             std::string TextString = (pText);
4190             if(TextString.length())
4191             {
4192                 std::vector<std::string> values = split(TextString,',');
4193                 besttimes.clear();
4194                 for(size_t i = 0; i < values.size(); i++)
4195                 {
4196                     besttimes.push_back(atoi(values[i].c_str()));
4197                 }
4198             }
4199         }
4200 
4201         if (pKey == "besttrinkets")
4202         {
4203             std::string TextString = (pText);
4204             if(TextString.length())
4205             {
4206                 std::vector<std::string> values = split(TextString,',');
4207                 besttrinkets.clear();
4208                 for(size_t i = 0; i < values.size(); i++)
4209                 {
4210                     besttrinkets.push_back(atoi(values[i].c_str()));
4211                 }
4212             }
4213         }
4214 
4215 
4216         if (pKey == "bestlives")
4217         {
4218             std::string TextString = (pText);
4219             if(TextString.length())
4220             {
4221                 std::vector<std::string> values = split(TextString,',');
4222                 bestlives.clear();
4223                 for(size_t i = 0; i < values.size(); i++)
4224                 {
4225                     bestlives.push_back(atoi(values[i].c_str()));
4226                 }
4227             }
4228         }
4229 
4230 
4231         if (pKey == "bestrank")
4232         {
4233             std::string TextString = (pText);
4234             if(TextString.length())
4235             {
4236                 std::vector<std::string> values = split(TextString,',');
4237                 bestrank.clear();
4238                 for(size_t i = 0; i < values.size(); i++)
4239                 {
4240                     bestrank.push_back(atoi(values[i].c_str()));
4241                 }
4242             }
4243         }
4244 
4245 
4246 
4247         if (pKey == "bestgamedeaths")
4248         {
4249             bestgamedeaths = atoi(pText);
4250         }
4251 
4252         if (pKey == "stat_trinkets")
4253         {
4254             stat_trinkets = atoi(pText);
4255         }
4256 
4257         if (pKey == "fullscreen")
4258         {
4259             fullscreen = atoi(pText);
4260         }
4261 
4262 	if (pKey == "stretch")
4263 	{
4264 		stretchMode = atoi(pText);
4265 	}
4266 
4267 	if (pKey == "useLinearFilter")
4268 	{
4269 		useLinearFilter = atoi(pText);
4270 	}
4271 
4272 	if (pKey == "window_width")
4273 	{
4274 		width = atoi(pText);
4275 	}
4276 	if (pKey == "window_height")
4277 	{
4278 		height = atoi(pText);
4279 	}
4280 
4281 
4282         if (pKey == "noflashingmode")
4283         {
4284             noflashingmode = atoi(pText);
4285         }
4286 
4287         if (pKey == "colourblindmode")
4288         {
4289             colourblindmode = atoi(pText);
4290         }
4291 
4292         if (pKey == "setflipmode")
4293         {
4294             dwgfx.setflipmode = atoi(pText);
4295         }
4296 
4297         if (pKey == "invincibility")
4298         {
4299             map.invincibility = atoi(pText);
4300         }
4301 
4302         if (pKey == "slowdown")
4303         {
4304             slowdown = atoi(pText);
4305             switch(slowdown)
4306             {
4307             case 30:
4308                 gameframerate=34;
4309                 break;
4310             case 24:
4311                 gameframerate=41;
4312                 break;
4313             case 18:
4314                 gameframerate=55;
4315                 break;
4316             case 12:
4317                 gameframerate=83;
4318                 break;
4319             default:
4320                 gameframerate=34;
4321                 break;
4322             }
4323 
4324         }
4325 
4326         if (pKey == "swnbestrank")
4327         {
4328             swnbestrank = atoi(pText);
4329         }
4330 
4331         if (pKey == "swnrecord")
4332         {
4333             swnrecord = atoi(pText);
4334         }
4335 
4336         if (pKey == "advanced_mode")
4337         {
4338             advanced_mode = atoi(pText);
4339         }
4340 
4341         if (pKey == "advanced_smoothing")
4342         {
4343             fullScreenEffect_badSignal = atoi(pText);
4344             dwgfx.screenbuffer->badSignalEffect = fullScreenEffect_badSignal;
4345         }
4346 
4347 				if (pKey == "usingmmmmmm")
4348         {
4349 					if(atoi(pText)>0){
4350             usingmmmmmm = 1;
4351 					}else{
4352 					  usingmmmmmm = 0;
4353 					}
4354         }
4355 
4356 		if (pKey == "flipButton")
4357 		{
4358 			SDL_GameControllerButton newButton;
4359 			if (GetButtonFromString(pText, &newButton))
4360 			{
4361 				controllerButton_flip.push_back(newButton);
4362 			}
4363 		}
4364 
4365 		if (pKey == "enterButton")
4366 		{
4367 			SDL_GameControllerButton newButton;
4368 			if (GetButtonFromString(pText, &newButton))
4369 			{
4370 				controllerButton_map.push_back(newButton);
4371 			}
4372 		}
4373 
4374 		if (pKey == "escButton")
4375 		{
4376 			SDL_GameControllerButton newButton;
4377 			if (GetButtonFromString(pText, &newButton))
4378 			{
4379 				controllerButton_esc.push_back(newButton);
4380 			}
4381 		}
4382 
4383 		if (pKey == "controllerSensitivity")
4384 		{
4385 			controllerSensitivity = atoi(pText);
4386 		}
4387 
4388     }
4389 
4390     if(fullscreen)
4391     {
4392         dwgfx.screenbuffer->toggleFullScreen();
4393     }
4394     for (int i = 0; i < stretchMode; i += 1)
4395     {
4396         dwgfx.screenbuffer->toggleStretchMode();
4397     }
4398     if (useLinearFilter)
4399     {
4400         dwgfx.screenbuffer->toggleLinearFilter();
4401     }
4402     dwgfx.screenbuffer->ResizeScreen(width, height);
4403 
4404     if (controllerButton_flip.size() < 1)
4405     {
4406         controllerButton_flip.push_back(SDL_CONTROLLER_BUTTON_A);
4407     }
4408     if (controllerButton_map.size() < 1)
4409     {
4410         controllerButton_map.push_back(SDL_CONTROLLER_BUTTON_Y);
4411     }
4412     if (controllerButton_esc.size() < 1)
4413     {
4414         controllerButton_esc.push_back(SDL_CONTROLLER_BUTTON_B);
4415     }
4416 }
4417 
savestats(mapclass & _map,Graphics & _dwgfx)4418 void Game::savestats( mapclass& _map, Graphics& _dwgfx )
4419 {
4420     TiXmlDocument doc;
4421     TiXmlElement* msg;
4422     TiXmlDeclaration* decl = new TiXmlDeclaration( "1.0", "", "" );
4423     doc.LinkEndChild( decl );
4424 
4425     TiXmlElement * root = new TiXmlElement( "Save" );
4426     doc.LinkEndChild( root );
4427 
4428     TiXmlComment * comment = new TiXmlComment();
4429     comment->SetValue(" Save file " );
4430     root->LinkEndChild( comment );
4431 
4432     TiXmlElement * dataNode = new TiXmlElement( "Data" );
4433     root->LinkEndChild( dataNode );
4434 
4435     std::string s_unlock;
4436     for(size_t i = 0; i < unlock.size(); i++ )
4437     {
4438         s_unlock += UtilityClass::String(unlock[i]) + ",";
4439     }
4440     msg = new TiXmlElement( "unlock" );
4441     msg->LinkEndChild( new TiXmlText( s_unlock.c_str() ));
4442     dataNode->LinkEndChild( msg );
4443 
4444     std::string s_unlocknotify;
4445     for(size_t i = 0; i < unlocknotify.size(); i++ )
4446     {
4447         s_unlocknotify += UtilityClass::String(unlocknotify[i]) + ",";
4448     }
4449     msg = new TiXmlElement( "unlocknotify" );
4450     msg->LinkEndChild( new TiXmlText( s_unlocknotify.c_str() ));
4451     dataNode->LinkEndChild( msg );
4452 
4453     std::string s_besttimes;
4454     for(size_t i = 0; i < besttrinkets.size(); i++ )
4455     {
4456         s_besttimes += UtilityClass::String(besttimes[i]) + ",";
4457     }
4458     msg = new TiXmlElement( "besttimes" );
4459     msg->LinkEndChild( new TiXmlText( s_besttimes.c_str() ));
4460     dataNode->LinkEndChild( msg );
4461 
4462     std::string s_besttrinkets;
4463     for(size_t i = 0; i < besttrinkets.size(); i++ )
4464     {
4465         s_besttrinkets += UtilityClass::String(besttrinkets[i]) + ",";
4466     }
4467     msg = new TiXmlElement( "besttrinkets" );
4468     msg->LinkEndChild( new TiXmlText( s_besttrinkets.c_str() ));
4469     dataNode->LinkEndChild( msg );
4470 
4471     std::string s_bestlives;
4472     for(size_t i = 0; i < bestlives.size(); i++ )
4473     {
4474         s_bestlives += UtilityClass::String(bestlives[i]) + ",";
4475     }
4476     msg = new TiXmlElement( "bestlives" );
4477     msg->LinkEndChild( new TiXmlText( s_bestlives.c_str() ));
4478     dataNode->LinkEndChild( msg );
4479 
4480     std::string s_bestrank;
4481     for(size_t i = 0; i < bestrank.size(); i++ )
4482     {
4483         s_bestrank += UtilityClass::String(bestrank[i]) + ",";
4484     }
4485     msg = new TiXmlElement( "bestrank" );
4486     msg->LinkEndChild( new TiXmlText( s_bestrank.c_str() ));
4487     dataNode->LinkEndChild( msg );
4488 
4489     //for itoa ops
4490     UtilityClass tu;
4491     msg = new TiXmlElement( "bestgamedeaths" );
4492     msg->LinkEndChild( new TiXmlText( tu.String(bestgamedeaths).c_str() ));
4493     dataNode->LinkEndChild( msg );
4494     msg = new TiXmlElement( "stat_trinkets" );
4495     msg->LinkEndChild( new TiXmlText( tu.String(stat_trinkets).c_str()));
4496     dataNode->LinkEndChild( msg );
4497 
4498     msg = new TiXmlElement( "fullscreen" );
4499     msg->LinkEndChild( new TiXmlText( tu.String(fullscreen).c_str()));
4500     dataNode->LinkEndChild( msg );
4501 
4502     msg = new TiXmlElement( "stretch" );
4503     msg->LinkEndChild( new TiXmlText( tu.String(stretchMode).c_str()));
4504     dataNode->LinkEndChild( msg );
4505 
4506     msg = new TiXmlElement( "useLinearFilter" );
4507     msg->LinkEndChild( new TiXmlText( tu.String(useLinearFilter).c_str()));
4508     dataNode->LinkEndChild( msg );
4509 
4510     int width, height;
4511     _dwgfx.screenbuffer->GetWindowSize(&width, &height);
4512     msg = new TiXmlElement( "window_width" );
4513     msg->LinkEndChild( new TiXmlText( tu.String(width).c_str()));
4514     dataNode->LinkEndChild( msg );
4515     msg = new TiXmlElement( "window_height" );
4516     msg->LinkEndChild( new TiXmlText( tu.String(height).c_str()));
4517     dataNode->LinkEndChild( msg );
4518 
4519     msg = new TiXmlElement( "noflashingmode" );
4520     msg->LinkEndChild( new TiXmlText( tu.String(noflashingmode).c_str()));
4521     dataNode->LinkEndChild( msg );
4522 
4523     msg = new TiXmlElement( "colourblindmode" );
4524     msg->LinkEndChild( new TiXmlText( tu.String(colourblindmode).c_str()));
4525     dataNode->LinkEndChild( msg );
4526 
4527     msg = new TiXmlElement( "setflipmode" );
4528     msg->LinkEndChild( new TiXmlText( tu.String(_dwgfx.setflipmode).c_str()));
4529     dataNode->LinkEndChild( msg );
4530 
4531     msg = new TiXmlElement( "invincibility" );
4532     msg->LinkEndChild( new TiXmlText( tu.String(_map.invincibility).c_str()));
4533     dataNode->LinkEndChild( msg );
4534 
4535     msg = new TiXmlElement( "slowdown" );
4536     msg->LinkEndChild( new TiXmlText( tu.String(slowdown).c_str()));
4537     dataNode->LinkEndChild( msg );
4538 
4539     msg = new TiXmlElement( "swnbestrank" );
4540     msg->LinkEndChild( new TiXmlText( tu.String(swnbestrank).c_str()));
4541     dataNode->LinkEndChild( msg );
4542 
4543     msg = new TiXmlElement( "swnrecord" );
4544     msg->LinkEndChild( new TiXmlText( tu.String(swnrecord).c_str()));
4545     dataNode->LinkEndChild( msg );
4546 
4547 
4548     msg = new TiXmlElement( "advanced_mode" );
4549     msg->LinkEndChild( new TiXmlText( tu.String(advanced_mode).c_str()));
4550     dataNode->LinkEndChild( msg );
4551 
4552     msg = new TiXmlElement( "advanced_smoothing" );
4553     msg->LinkEndChild( new TiXmlText( tu.String(fullScreenEffect_badSignal).c_str()));
4554     dataNode->LinkEndChild( msg );
4555 
4556 
4557     msg = new TiXmlElement( "usingmmmmmm" );
4558     msg->LinkEndChild( new TiXmlText( tu.String(usingmmmmmm).c_str()));
4559     dataNode->LinkEndChild( msg );
4560 
4561     for (size_t i = 0; i < controllerButton_flip.size(); i += 1)
4562     {
4563         msg = new TiXmlElement("flipButton");
4564         msg->LinkEndChild(new TiXmlText(tu.String((int) controllerButton_flip[i]).c_str()));
4565         dataNode->LinkEndChild(msg);
4566     }
4567     for (size_t i = 0; i < controllerButton_map.size(); i += 1)
4568     {
4569         msg = new TiXmlElement("enterButton");
4570         msg->LinkEndChild(new TiXmlText(tu.String((int) controllerButton_map[i]).c_str()));
4571         dataNode->LinkEndChild(msg);
4572     }
4573     for (size_t i = 0; i < controllerButton_esc.size(); i += 1)
4574     {
4575         msg = new TiXmlElement("escButton");
4576         msg->LinkEndChild(new TiXmlText(tu.String((int) controllerButton_esc[i]).c_str()));
4577         dataNode->LinkEndChild(msg);
4578     }
4579 
4580 	msg = new TiXmlElement( "controllerSensitivity" );
4581 	msg->LinkEndChild( new TiXmlText( tu.String(controllerSensitivity).c_str()));
4582 	dataNode->LinkEndChild( msg );
4583 
4584     doc.SaveFile( (saveFilePath+"unlock.vvv").c_str() );
4585 }
4586 
customstart(entityclass & obj,musicclass & music)4587 void Game::customstart( entityclass& obj, musicclass& music )
4588 {
4589     jumpheld = true;
4590 
4591     savex = edsavex;
4592     savey = edsavey;
4593     saverx = edsaverx;
4594     savery = edsavery;
4595 
4596     savegc = edsavegc;
4597     savedir = edsavedir; //Worldmap Start
4598     //savex = 6 * 8; savey = 15 * 8; saverx = 46; savery = 54; savegc = 0; savedir = 1; //Final Level Current
4599     savepoint = 0;
4600     gravitycontrol = savegc;
4601 
4602     coins = 0;
4603     trinkets = 0;
4604 
4605     //state = 2; deathseq = -1; lifeseq = 10; //Not dead, in game initilisation state
4606     state = 0;
4607     deathseq = -1;
4608     lifeseq = 0;
4609 
4610     //let's teleport in!
4611     //state = 2500;
4612     //if (!nocutscenes) music.play(5);
4613 }
4614 
start(entityclass & obj,musicclass & music)4615 void Game::start( entityclass& obj, musicclass& music )
4616 {
4617     jumpheld = true;
4618 
4619     savex = 232;
4620     savey = 113;
4621     saverx = 104;
4622     savery = 110;
4623     savegc = 0;
4624     savedir = 1; //Worldmap Start
4625     //savex = 6 * 8; savey = 15 * 8; saverx = 46; savery = 54; savegc = 0; savedir = 1; //Final Level Current
4626     savepoint = 0;
4627     gravitycontrol = savegc;
4628 
4629     coins = 0;
4630     trinkets = 0;
4631 
4632     //state = 2; deathseq = -1; lifeseq = 10; //Not dead, in game initilisation state
4633     state = 0;
4634     deathseq = -1;
4635     lifeseq = 0;
4636 
4637     //let's teleport in!
4638     //state = 2500;
4639     if (!nocutscenes) music.play(5);
4640 }
4641 
deathsequence(mapclass & map,entityclass & obj,musicclass & music)4642 void Game::deathsequence( mapclass& map, entityclass& obj, musicclass& music )
4643 {
4644     int i;
4645     if (supercrewmate && scmhurt)
4646     {
4647         i = obj.getscm();
4648     }
4649     else
4650     {
4651         i = obj.getplayer();
4652     }
4653     obj.entities[i].colour = 1;
4654 
4655     obj.entities[i].invis = false;
4656     if (deathseq == 30)
4657     {
4658         if (nodeathmode)
4659         {
4660             music.fadeout();
4661             gameoverdelay = 60;
4662         }
4663         deathcounts++;
4664         music.playef(2,10);
4665         obj.entities[i].invis = true;
4666         if (map.finalmode)
4667         {
4668             map.roomdeathsfinal[roomx - 41 + (20 * (roomy - 48))]++;
4669             currentroomdeaths = map.roomdeathsfinal[roomx - 41 + (20 * (roomy - 48))];
4670         }
4671         else
4672         {
4673             map.roomdeaths[roomx - 100 + (20*(roomy - 100))]++;
4674             currentroomdeaths = map.roomdeaths[roomx - 100 + (20 * (roomy - 100))];
4675         }
4676     }
4677     if (deathseq == 25) obj.entities[i].invis = true;
4678     if (deathseq == 20) obj.entities[i].invis = true;
4679     if (deathseq == 16) obj.entities[i].invis = true;
4680     if (deathseq == 14) obj.entities[i].invis = true;
4681     if (deathseq == 12) obj.entities[i].invis = true;
4682     if (deathseq < 10) obj.entities[i].invis = true;
4683     if (!nodeathmode)
4684     {
4685         if (deathseq <= 1) obj.entities[i].invis = false;
4686     }
4687     else
4688     {
4689         gameoverdelay--;
4690     }
4691 }
4692 
startspecial(int t,entityclass & obj,musicclass & music)4693 void Game::startspecial( int t, entityclass& obj, musicclass& music )
4694 {
4695     jumpheld = true;
4696 
4697     switch(t)
4698     {
4699     case 0: //Secret Lab
4700         savex = 104;
4701         savey = 169;
4702         saverx = 118;
4703         savery = 106;
4704         savegc = 0;
4705         savedir = 1;
4706         break;
4707     case 1: //Intermission 1 (any)
4708         savex = 80;
4709         savey = 57;
4710         saverx = 41;
4711         savery = 56;
4712         savegc = 0;
4713         savedir = 0;
4714         break;
4715     default:
4716         savex = 232;
4717         savey = 113;
4718         saverx = 104;
4719         savery = 110;
4720         savegc = 0;
4721         savedir = 1; //Worldmap Start
4722         break;
4723     }
4724 
4725     savepoint = 0;
4726     gravitycontrol = savegc;
4727     coins = 0;
4728     trinkets = 0;
4729     state = 0;
4730     deathseq = -1;
4731     lifeseq = 0;
4732 }
4733 
starttrial(int t,entityclass & obj,musicclass & music)4734 void Game::starttrial( int t, entityclass& obj, musicclass& music )
4735 {
4736     jumpheld = true;
4737 
4738     switch(t)
4739     {
4740     case 0: //Space Station 1
4741         savex = 200;
4742         savey = 161;
4743         saverx = 113;
4744         savery = 105;
4745         savegc = 0;
4746         savedir = 1;
4747         break;
4748     case 1: //Lab
4749         savex = 191;
4750         savey = 33;
4751         saverx = 102;
4752         savery = 116;
4753         savegc = 0;
4754         savedir = 1;
4755         break;
4756     case 2: //Tower
4757         savex = 84;
4758         savey = 193, saverx = 108;
4759         savery = 109;
4760         savegc = 0;
4761         savedir = 1;
4762         break;
4763     case 3: //Space Station 2
4764         savex = 148;
4765         savey = 38;
4766         saverx = 112;
4767         savery = 114;
4768         savegc = 1;
4769         savedir = 0;
4770         break;
4771     case 4: //Warp
4772         savex = 52;
4773         savey = 73;
4774         saverx = 114;
4775         savery = 101;
4776         savegc = 0;
4777         savedir = 1;
4778         break;
4779     case 5: //Final
4780         savex = 101;
4781         savey = 113;
4782         saverx = 46;
4783         savery = 54;
4784         savegc = 0;
4785         savedir = 1;
4786         break;
4787     default:
4788         savex = 232;
4789         savey = 113;
4790         saverx = 104;
4791         savery = 110;
4792         savegc = 0;
4793         savedir = 1; //Worldmap Start
4794         break;
4795     }
4796 
4797     savepoint = 0;
4798     gravitycontrol = savegc;
4799 
4800     coins = 0;
4801     trinkets = 0;
4802     crewmates = 0;
4803 
4804     //state = 2; deathseq = -1; lifeseq = 10; //Not dead, in game initilisation state
4805     state = 0;
4806     deathseq = -1;
4807     lifeseq = 0;
4808 }
4809 
loadquick(mapclass & map,entityclass & obj,musicclass & music)4810 void Game::loadquick( mapclass& map, entityclass& obj, musicclass& music )
4811 {
4812     TiXmlDocument doc((saveFilePath+"qsave.vvv").c_str());
4813     if (!doc.LoadFile()) return; ;
4814 
4815     TiXmlHandle hDoc(&doc);
4816     TiXmlElement* pElem;
4817     TiXmlHandle hRoot(0);
4818 
4819 
4820     {
4821         pElem=hDoc.FirstChildElement().Element();
4822         // should always have a valid root but handle gracefully if it does
4823         if (!pElem)
4824         {
4825             printf("Save Not Found\n");
4826         }
4827 
4828         // save this for later
4829         hRoot=TiXmlHandle(pElem);
4830     }
4831 
4832     for( pElem = hRoot.FirstChild( "Data" ).FirstChild().Element(); pElem; pElem=pElem->NextSiblingElement())
4833     {
4834         std::string pKey(pElem->Value());
4835         const char* pText = pElem->GetText() ;
4836         if(pText == NULL)
4837         {
4838             pText = "";
4839         }
4840 
4841         if (pKey == "worldmap")
4842         {
4843             std::string TextString = (pText);
4844             if(TextString.length()>1)
4845             {
4846                 std::vector<std::string> values = split(TextString,',');
4847                 map.explored.clear();
4848                 for(size_t i = 0; i < values.size(); i++)
4849                 {
4850                     map.explored.push_back(atoi(values[i].c_str()));
4851                 }
4852             }
4853         }
4854 
4855         if (pKey == "flags")
4856         {
4857             std::string TextString = (pText);
4858             if(TextString.length())
4859             {
4860                 std::vector<std::string> values = split(TextString,',');
4861                 obj.flags.clear();
4862                 for(size_t i = 0; i < values.size(); i++)
4863                 {
4864                     obj.flags.push_back(atoi(values[i].c_str()));
4865                 }
4866             }
4867         }
4868 
4869         if (pKey == "crewstats")
4870         {
4871             std::string TextString = (pText);
4872             if(TextString.length())
4873             {
4874                 std::vector<std::string> values = split(TextString,',');
4875                 crewstats.clear();
4876                 for(size_t i = 0; i < values.size(); i++)
4877                 {
4878                     crewstats.push_back(atoi(values[i].c_str()));
4879                 }
4880             }
4881         }
4882 
4883         if (pKey == "collect")
4884         {
4885             std::string TextString = (pText);
4886             if(TextString.length())
4887             {
4888                 std::vector<std::string> values = split(TextString,',');
4889                 obj.collect.clear();
4890                 for(size_t i = 0; i < values.size(); i++)
4891                 {
4892                     obj.collect.push_back(atoi(values[i].c_str()));
4893                 }
4894             }
4895         }
4896 
4897         if (pKey == "finalmode")
4898         {
4899             map.finalmode = atoi(pText);
4900         }
4901         if (pKey == "finalstretch")
4902         {
4903             map.finalstretch = atoi(pText);
4904         }
4905 
4906         if (pKey == "finalx")
4907         {
4908             map.finalx = atoi(pText);
4909         }
4910         else if (pKey == "finaly")
4911         {
4912             map.finaly = atoi(pText);
4913         }
4914         else if (pKey == "savex")
4915         {
4916             savex = atoi(pText);
4917         }
4918         else if (pKey == "savey")
4919         {
4920             savey = atoi(pText);
4921         }
4922         else if (pKey == "saverx")
4923         {
4924             saverx = atoi(pText);
4925         }
4926         else if (pKey == "savery")
4927         {
4928             savery = atoi(pText);
4929         }
4930         else if (pKey == "savegc")
4931         {
4932             savegc = atoi(pText);
4933         }
4934         else if (pKey == "savedir")
4935         {
4936             savedir= atoi(pText);
4937         }
4938         else if (pKey == "savepoint")
4939         {
4940             savepoint = atoi(pText);
4941         }
4942         else if (pKey == "trinkets")
4943         {
4944             trinkets = atoi(pText);
4945         }
4946         else if (pKey == "companion")
4947         {
4948             companion = atoi(pText);
4949         }
4950         else if (pKey == "lastsaved")
4951         {
4952             lastsaved = atoi(pText);
4953         }
4954         else if (pKey == "teleportscript")
4955         {
4956             teleportscript = pText;
4957         }
4958         else if (pKey == "supercrewmate")
4959         {
4960             supercrewmate = atoi(pText);
4961         }
4962         else if (pKey == "scmprogress")
4963         {
4964             scmprogress = atoi(pText);
4965         }
4966         else if (pKey == "scmmoveme")
4967         {
4968             scmmoveme = atoi(pText);
4969         }
4970         else if (pKey == "frames")
4971         {
4972             frames = atoi(pText);
4973 						frames = 0;
4974         }
4975         else if (pKey == "seconds")
4976         {
4977             seconds = atoi(pText);
4978         }
4979         else if (pKey == "minutes")
4980         {
4981             minutes = atoi(pText);
4982         }
4983         else if (pKey == "hours")
4984         {
4985             hours = atoi(pText);
4986         }
4987         else if (pKey == "deathcounts")
4988         {
4989             deathcounts = atoi(pText);
4990         }
4991         else if (pKey == "totalflips")
4992         {
4993             totalflips = atoi(pText);
4994         }
4995         else if (pKey == "hardestroom")
4996         {
4997             hardestroom = atoi(pText);
4998         }
4999         else if (pKey == "hardestroomdeaths")
5000         {
5001             hardestroomdeaths = atoi(pText);
5002         }
5003         else if (pKey == "currentsong")
5004         {
5005             music.play(atoi(pText));
5006         }
5007 
5008     }
5009 
5010     if (map.finalmode)
5011     {
5012         map.final_colormode = false;
5013         map.final_mapcol = 0;
5014         map.final_colorframe = 0;
5015     }
5016     if (map.finalstretch)
5017     {
5018         map.finalstretch = true;
5019         map.final_colormode = true;
5020         map.final_mapcol = 0;
5021         map.final_colorframe = 1;
5022     }
5023 
5024     map.showteleporters = true;
5025     if(obj.flags[12]==1) map.showtargets = true;
5026     if (obj.flags[42] == 1) map.showtrinkets = true;
5027 
5028 
5029 }
5030 
customloadquick(std::string savfile,mapclass & map,entityclass & obj,musicclass & music)5031 void Game::customloadquick(std::string savfile, mapclass& map, entityclass& obj, musicclass& music )
5032 {
5033     std::string levelfile = savfile.substr(7);
5034     TiXmlDocument doc((saveFilePath+levelfile+".vvv").c_str());
5035     if (!doc.LoadFile()) return; ;
5036 
5037     TiXmlHandle hDoc(&doc);
5038     TiXmlElement* pElem;
5039     TiXmlHandle hRoot(0);
5040 
5041 
5042     {
5043         pElem=hDoc.FirstChildElement().Element();
5044         // should always have a valid root but handle gracefully if it does
5045         if (!pElem)
5046         {
5047             printf("Save Not Found\n");
5048         }
5049 
5050         // save this for later
5051         hRoot=TiXmlHandle(pElem);
5052     }
5053 
5054     for( pElem = hRoot.FirstChild( "Data" ).FirstChild().Element(); pElem; pElem=pElem->NextSiblingElement())
5055     {
5056         std::string pKey(pElem->Value());
5057         const char* pText = pElem->GetText() ;
5058         if(pText == NULL)
5059         {
5060             pText = "";
5061         }
5062 
5063         if (pKey == "worldmap")
5064         {
5065             std::string TextString = (pText);
5066             if(TextString.length()>1)
5067             {
5068                 std::vector<std::string> values = split(TextString,',');
5069                 map.explored.clear();
5070                 for(size_t i = 0; i < values.size(); i++)
5071                 {
5072                     map.explored.push_back(atoi(values[i].c_str()));
5073                 }
5074             }
5075         }
5076 
5077         if (pKey == "flags")
5078         {
5079             std::string TextString = (pText);
5080             if(TextString.length())
5081             {
5082                 std::vector<std::string> values = split(TextString,',');
5083                 obj.flags.clear();
5084                 for(size_t i = 0; i < values.size(); i++)
5085                 {
5086                     obj.flags.push_back(atoi(values[i].c_str()));
5087                 }
5088             }
5089         }
5090 
5091         if (pKey == "moods")
5092         {
5093             std::string TextString = (pText);
5094             if(TextString.length())
5095             {
5096                 std::vector<std::string> values = split(TextString,',');
5097                 for(size_t i = 0; i < 6; i++)
5098                 {
5099                     obj.customcrewmoods[i]=atoi(values[i].c_str());
5100                 }
5101             }
5102         }
5103 
5104         if (pKey == "crewstats")
5105         {
5106             std::string TextString = (pText);
5107             if(TextString.length())
5108             {
5109                 std::vector<std::string> values = split(TextString,',');
5110                 crewstats.clear();
5111                 for(size_t i = 0; i < values.size(); i++)
5112                 {
5113                     crewstats.push_back(atoi(values[i].c_str()));
5114                 }
5115             }
5116         }
5117 
5118         if (pKey == "collect")
5119         {
5120             std::string TextString = (pText);
5121             if(TextString.length())
5122             {
5123                 std::vector<std::string> values = split(TextString,',');
5124                 obj.collect.clear();
5125                 for(size_t i = 0; i < values.size(); i++)
5126                 {
5127                     obj.collect.push_back(atoi(values[i].c_str()));
5128                 }
5129             }
5130         }
5131 
5132         if (pKey == "customcollect")
5133         {
5134             std::string TextString = (pText);
5135             if(TextString.length())
5136             {
5137                 std::vector<std::string> values = split(TextString,',');
5138                 obj.customcollect.clear();
5139                 for(size_t i = 0; i < values.size(); i++)
5140                 {
5141                     obj.customcollect.push_back(atoi(values[i].c_str()));
5142                 }
5143             }
5144         }
5145 
5146         if (pKey == "finalmode")
5147         {
5148             map.finalmode = atoi(pText);
5149         }
5150         if (pKey == "finalstretch")
5151         {
5152             map.finalstretch = atoi(pText);
5153         }
5154 
5155         if (map.finalmode)
5156         {
5157             map.final_colormode = false;
5158             map.final_mapcol = 0;
5159             map.final_colorframe = 0;
5160         }
5161         if (map.finalstretch)
5162         {
5163             map.finalstretch = true;
5164             map.final_colormode = true;
5165             map.final_mapcol = 0;
5166             map.final_colorframe = 1;
5167         }
5168 
5169 
5170         if (pKey == "finalx")
5171         {
5172             map.finalx = atoi(pText);
5173         }
5174         else if (pKey == "finaly")
5175         {
5176             map.finaly = atoi(pText);
5177         }
5178         else if (pKey == "savex")
5179         {
5180             savex = atoi(pText);
5181         }
5182         else if (pKey == "savey")
5183         {
5184             savey = atoi(pText);
5185         }
5186         else if (pKey == "saverx")
5187         {
5188             saverx = atoi(pText);
5189         }
5190         else if (pKey == "savery")
5191         {
5192             savery = atoi(pText);
5193         }
5194         else if (pKey == "savegc")
5195         {
5196             savegc = atoi(pText);
5197         }
5198         else if (pKey == "savedir")
5199         {
5200             savedir= atoi(pText);
5201         }
5202         else if (pKey == "savepoint")
5203         {
5204             savepoint = atoi(pText);
5205         }
5206         else if (pKey == "trinkets")
5207         {
5208             trinkets = atoi(pText);
5209         }
5210         else if (pKey == "crewmates")
5211         {
5212             crewmates = atoi(pText);
5213         }
5214         else if (pKey == "companion")
5215         {
5216             companion = atoi(pText);
5217         }
5218         else if (pKey == "lastsaved")
5219         {
5220             lastsaved = atoi(pText);
5221         }
5222         else if (pKey == "teleportscript")
5223         {
5224             teleportscript = pText;
5225         }
5226         else if (pKey == "supercrewmate")
5227         {
5228             supercrewmate = atoi(pText);
5229         }
5230         else if (pKey == "scmprogress")
5231         {
5232             scmprogress = atoi(pText);
5233         }
5234         else if (pKey == "scmmoveme")
5235         {
5236             scmmoveme = atoi(pText);
5237         }
5238         else if (pKey == "frames")
5239         {
5240             frames = atoi(pText);
5241 						frames = 0;
5242         }
5243         else if (pKey == "seconds")
5244         {
5245             seconds = atoi(pText);
5246         }
5247         else if (pKey == "minutes")
5248         {
5249             minutes = atoi(pText);
5250         }
5251         else if (pKey == "hours")
5252         {
5253             hours = atoi(pText);
5254         }
5255         else if (pKey == "deathcounts")
5256         {
5257             deathcounts = atoi(pText);
5258         }
5259         else if (pKey == "totalflips")
5260         {
5261             totalflips = atoi(pText);
5262         }
5263         else if (pKey == "hardestroom")
5264         {
5265             hardestroom = atoi(pText);
5266         }
5267         else if (pKey == "hardestroomdeaths")
5268         {
5269             hardestroomdeaths = atoi(pText);
5270         }
5271         else if (pKey == "currentsong")
5272         {
5273             music.play(atoi(pText));
5274         }
5275         else if (pKey == "showminimap")
5276         {
5277             map.customshowmm = atoi(pText);
5278         }
5279 
5280     }
5281 
5282     map.showteleporters = true;
5283     if(obj.flags[12]==1) map.showtargets = true;
5284     if (obj.flags[42] == 1) map.showtrinkets = true;
5285 
5286 }
5287 
5288 //TODO load summary
loadsummary(mapclass & map,UtilityClass & help)5289 void Game::loadsummary( mapclass& map, UtilityClass& help )
5290 {
5291     //quickcookie = SharedObject.getLocal("dwvvvvvv_quick");
5292     //telecookie = SharedObject.getLocal("dwvvvvvv_tele");
5293 
5294     //if (telecookie.data.savex == undefined) {
5295     //	telecookieexists = false; telesummary = "";
5296     //} else {
5297     //	telecookieexists = true; telesummary = telecookie.data.summary;
5298     //	tele_gametime = giventimestring(telecookie.data.hours, telecookie.data.minutes, telecookie.data.seconds, help);
5299     //	tele_trinkets = telecookie.data.trinkets;
5300     //	tele_currentarea = map.currentarea(map.area(telecookie.data.savex, telecookie.data.savey));
5301 
5302     //	summary_crewstats = telecookie.data.crewstats.slice();
5303     //	tele_crewstats = summary_crewstats.slice();
5304     //}
5305 
5306     //if (quickcookie.data.savex == undefined) {
5307     //	quickcookieexists = false; quicksummary = "";
5308     //} else {
5309     //	quickcookieexists = true; quicksummary = quickcookie.data.summary;
5310     //	quick_gametime = giventimestring(quickcookie.data.hours, quickcookie.data.minutes, quickcookie.data.seconds, help);
5311     //	quick_trinkets = quickcookie.data.trinkets;
5312     //	quick_currentarea = map.currentarea(map.area(quickcookie.data.savex, quickcookie.data.savey));
5313 
5314     //	summary_crewstats = quickcookie.data.crewstats.slice();
5315     //	quick_crewstats = summary_crewstats.slice();
5316     //}
5317 
5318     TiXmlDocument docTele((saveFilePath+"tsave.vvv").c_str());
5319     if (!docTele.LoadFile())
5320     {
5321         telecookieexists = false;
5322         telesummary = "";
5323     }
5324     else
5325     {
5326         telecookieexists = true;
5327         TiXmlHandle hDoc(&docTele);
5328         TiXmlElement* pElem;
5329         TiXmlHandle hRoot(0);
5330 
5331 
5332         {
5333             pElem=hDoc.FirstChildElement().Element();
5334             // should always have a valid root but handle gracefully if it does
5335             if (!pElem)
5336             {
5337                 printf("Save Not Found\n");
5338             }
5339 
5340             // save this for later
5341             hRoot=TiXmlHandle(pElem);
5342         }
5343         int l_minute, l_second, l_hours;
5344         l_minute = l_second= l_hours = 0;
5345         int l_saveX = 0;
5346         int l_saveY = 0;
5347         for( pElem = hRoot.FirstChild( "Data" ).FirstChild().Element(); pElem; pElem=pElem->NextSiblingElement())
5348         {
5349             std::string pKey(pElem->Value());
5350             const char* pText = pElem->GetText() ;
5351 
5352             if (pKey == "summary")
5353             {
5354                 telesummary = pText;
5355             }
5356 
5357             else if (pKey == "seconds")
5358             {
5359                 l_second = atoi(pText);
5360             }
5361             else if (pKey == "minutes")
5362             {
5363                 l_minute = atoi(pText);
5364             }
5365             else if (pKey == "hours")
5366             {
5367                 l_hours = atoi(pText);
5368             }
5369             else if (pKey == "savery")
5370             {
5371                 l_saveY = atoi(pText);
5372             }
5373             else if (pKey == "saverx")
5374             {
5375                 l_saveX = atoi(pText);
5376             }
5377             else if (pKey == "trinkets")
5378             {
5379                 tele_trinkets = atoi(pText);
5380             }
5381             else if (pKey == "finalmode")
5382             {
5383                 map.finalmode = atoi(pText);
5384             }
5385             else if (pKey == "finalstretch")
5386             {
5387                 map.finalstretch = atoi(pText);
5388             }
5389 
5390             if (pKey == "crewstats")
5391             {
5392                 std::string TextString = (pText);
5393                 if(TextString.length())
5394                 {
5395                     std::vector<std::string> values = split(TextString,',');
5396                     tele_crewstats.clear();
5397                     for(size_t i = 0; i < values.size(); i++)
5398                     {
5399                         tele_crewstats.push_back(atoi(values[i].c_str()));
5400                     }
5401                 }
5402             }
5403 
5404         }
5405         tele_gametime = giventimestring(l_hours,l_minute, l_second,help);
5406         tele_currentarea = map.currentarea(map.area(l_saveX, l_saveY));
5407     }
5408 
5409     TiXmlDocument doc((saveFilePath+"qsave.vvv").c_str());
5410     if (!doc.LoadFile())
5411     {
5412         quickcookieexists = false;
5413         quicksummary = "";
5414     }
5415     else
5416     {
5417         quickcookieexists = true;
5418         TiXmlHandle hDoc(&doc);
5419         TiXmlElement* pElem;
5420         TiXmlHandle hRoot(0);
5421 
5422 
5423         {
5424             pElem=hDoc.FirstChildElement().Element();
5425             // should always have a valid root but handle gracefully if it does
5426             if (!pElem)
5427             {
5428                 printf("Save Not Found\n");
5429             }
5430 
5431             // save this for later
5432             hRoot=TiXmlHandle(pElem);
5433         }
5434         int l_minute, l_second, l_hours;
5435         l_minute = l_second= l_hours = 0;
5436         int l_saveX = 0;
5437         int l_saveY = 0;
5438         for( pElem = hRoot.FirstChild( "Data" ).FirstChild().Element(); pElem; pElem=pElem->NextSiblingElement())
5439         {
5440             std::string pKey(pElem->Value());
5441             const char* pText = pElem->GetText() ;
5442 
5443             if (pKey == "summary")
5444             {
5445                 quicksummary = pText;
5446             }
5447 
5448             else if (pKey == "seconds")
5449             {
5450                 l_second = atoi(pText);
5451             }
5452             else if (pKey == "minutes")
5453             {
5454                 l_minute = atoi(pText);
5455             }
5456             else if (pKey == "hours")
5457             {
5458                 l_hours = atoi(pText);
5459             }
5460             else if (pKey == "savery")
5461             {
5462                 l_saveY = atoi(pText);
5463             }
5464             else if (pKey == "saverx")
5465             {
5466                 l_saveX = atoi(pText);
5467             }
5468             else if (pKey == "trinkets")
5469             {
5470                 quick_trinkets = atoi(pText);
5471             }
5472             else if (pKey == "finalmode")
5473             {
5474                 map.finalmode = atoi(pText);
5475             }
5476             else if (pKey == "finalstretch")
5477             {
5478                 map.finalstretch = atoi(pText);
5479             }
5480 
5481             if (pKey == "crewstats")
5482             {
5483                 std::string TextString = (pText);
5484                 if(TextString.length())
5485                 {
5486                     std::vector<std::string> values = split(TextString,',');
5487                     quick_crewstats.clear();
5488                     for(size_t i = 0; i < values.size(); i++)
5489                     {
5490                         quick_crewstats.push_back(atoi(values[i].c_str()));
5491                     }
5492                 }
5493             }
5494 
5495         }
5496 
5497         quick_gametime = giventimestring(l_hours,l_minute, l_second,help);
5498         quick_currentarea = map.currentarea(map.area(l_saveX, l_saveY));
5499     }
5500 
5501 
5502 
5503 }
5504 
initteleportermode(mapclass & map)5505 void Game::initteleportermode( mapclass& map )
5506 {
5507     //Set the teleporter variable to the right position!
5508     teleport_to_teleporter = 0;
5509 
5510     for (int i = 0; i < map.numteleporters; i++)
5511     {
5512         if (roomx == map.teleporters[i].x + 100 && roomy == map.teleporters[i].y + 100)
5513         {
5514             teleport_to_teleporter = i;
5515         }
5516     }
5517 }
5518 
savetele(mapclass & map,entityclass & obj,musicclass & music)5519 void Game::savetele( mapclass& map, entityclass& obj, musicclass& music )
5520 {
5521     //TODO make this code a bit cleaner.
5522 
5523     //telecookie = SharedObject.getLocal("dwvvvvvv_tele");
5524     //Save to the telesave cookie
5525     telecookieexists = true;
5526 
5527     TiXmlDocument doc;
5528     TiXmlElement* msg;
5529     TiXmlDeclaration* decl = new TiXmlDeclaration( "1.0", "", "" );
5530     doc.LinkEndChild( decl );
5531 
5532     TiXmlElement * root = new TiXmlElement( "Save" );
5533     doc.LinkEndChild( root );
5534 
5535     TiXmlComment * comment = new TiXmlComment();
5536     comment->SetValue(" Save file " );
5537     root->LinkEndChild( comment );
5538 
5539     TiXmlElement * msgs = new TiXmlElement( "Data" );
5540     root->LinkEndChild( msgs );
5541 
5542 
5543     //Flags, map and stats
5544     //savestate[1].explored = map.explored.slice();
5545     //savestate[1].flags = obj.flags.slice();
5546     //savestate[1].crewstats = crewstats.slice();
5547     //savestate[1].collect = obj.collect.slice();
5548 
5549     //telecookie.data.worldmap = savestate[1].explored.slice();
5550     //telecookie.data.flags = savestate[1].flags.slice();
5551     //telecookie.data.crewstats = savestate[1].crewstats.slice();
5552     //telecookie.data.collect = savestate[1].collect.slice();
5553 
5554     //telecookie.data.finalmode = map.finalmode;
5555     //telecookie.data.finalstretch = map.finalstretch;
5556 
5557     std::string mapExplored;
5558     for(size_t i = 0; i < map.explored.size(); i++ )
5559     {
5560         mapExplored += UtilityClass::String(map.explored[i]) + ",";
5561     }
5562     msg = new TiXmlElement( "worldmap" );
5563     msg->LinkEndChild( new TiXmlText( mapExplored.c_str() ));
5564     msgs->LinkEndChild( msg );
5565 
5566     std::string flags;
5567     for(size_t i = 0; i < obj.flags.size(); i++ )
5568     {
5569         flags += UtilityClass::String(obj.flags[i]) + ",";
5570     }
5571     msg = new TiXmlElement( "flags" );
5572     msg->LinkEndChild( new TiXmlText( flags.c_str() ));
5573     msgs->LinkEndChild( msg );
5574 
5575     std::string crewstatsString;
5576     for(size_t i = 0; i < crewstats.size(); i++ )
5577     {
5578         crewstatsString += UtilityClass::String(crewstats[i]) + ",";
5579     }
5580     msg = new TiXmlElement( "crewstats" );
5581     msg->LinkEndChild( new TiXmlText( crewstatsString.c_str() ));
5582     msgs->LinkEndChild( msg );
5583 
5584     std::string collect;
5585     for(size_t i = 0; i < obj.collect.size(); i++ )
5586     {
5587         collect += UtilityClass::String(obj.collect[i]) + ",";
5588     }
5589     msg = new TiXmlElement( "collect" );
5590     msg->LinkEndChild( new TiXmlText( collect.c_str() ));
5591     msgs->LinkEndChild( msg );
5592 
5593     //telecookie.data.finalx = map.finalx;
5594     //telecookie.data.finaly = map.finaly;
5595     //Position
5596     //telecookie.data.savex = savex;
5597     //telecookie.data.savey = savey;
5598 
5599     msg = new TiXmlElement( "finalx" );
5600     msg->LinkEndChild( new TiXmlText( UtilityClass::String(map.finalx).c_str() ));
5601     msgs->LinkEndChild( msg );
5602 
5603     msg = new TiXmlElement( "finaly" );
5604     msg->LinkEndChild( new TiXmlText( UtilityClass::String(map.finaly).c_str() ));
5605     msgs->LinkEndChild( msg );
5606 
5607     msg = new TiXmlElement( "savex" );
5608     msg->LinkEndChild( new TiXmlText( UtilityClass::String(savex).c_str() ));
5609     msgs->LinkEndChild( msg );
5610 
5611     msg = new TiXmlElement( "savey" );
5612     msg->LinkEndChild( new TiXmlText( UtilityClass::String(savey).c_str() ));
5613     msgs->LinkEndChild( msg );
5614 
5615     msg = new TiXmlElement( "saverx" );
5616     msg->LinkEndChild( new TiXmlText( UtilityClass::String(saverx).c_str() ));
5617     msgs->LinkEndChild( msg );
5618 
5619     msg = new TiXmlElement( "savery" );
5620     msg->LinkEndChild( new TiXmlText( UtilityClass::String(savery).c_str() ));
5621     msgs->LinkEndChild( msg );
5622 
5623     //telecookie.data.saverx = saverx;
5624     //telecookie.data.savery = savery;
5625     //telecookie.data.savegc = savegc;
5626     //telecookie.data.savedir = savedir;
5627     //telecookie.data.savepoint = savepoint;
5628     //telecookie.data.trinkets = trinkets;
5629 
5630     msg = new TiXmlElement( "savegc" );
5631     msg->LinkEndChild( new TiXmlText( UtilityClass::String(savegc).c_str() ));
5632     msgs->LinkEndChild( msg );
5633 
5634     msg = new TiXmlElement( "savedir" );
5635     msg->LinkEndChild( new TiXmlText( UtilityClass::String(savedir).c_str() ));
5636     msgs->LinkEndChild( msg );
5637 
5638     msg = new TiXmlElement( "savepoint" );
5639     msg->LinkEndChild( new TiXmlText( UtilityClass::String(savepoint).c_str() ));
5640     msgs->LinkEndChild( msg );
5641 
5642     msg = new TiXmlElement( "trinkets" );
5643     msg->LinkEndChild( new TiXmlText( UtilityClass::String(trinkets).c_str() ));
5644     msgs->LinkEndChild( msg );
5645 
5646 
5647     //if (music.nicechange != -1) {
5648     //telecookie.data.currentsong = music.nicechange;
5649     //}else{
5650     //telecookie.data.currentsong = music.currentsong;
5651     //}
5652     //telecookie.data.teleportscript = teleportscript;
5653 
5654     //Special stats
5655     //telecookie.data.companion = companion;
5656     //telecookie.data.lastsaved = lastsaved;
5657     //telecookie.data.supercrewmate = supercrewmate;
5658     //telecookie.data.scmprogress = scmprogress;
5659     //telecookie.data.scmmoveme = scmmoveme;
5660 
5661     if(music.nicefade==1)
5662     {
5663         msg = new TiXmlElement( "currentsong" );
5664         msg->LinkEndChild( new TiXmlText( UtilityClass::String(music.nicechange).c_str() ));
5665         msgs->LinkEndChild( msg );
5666     }
5667     else
5668     {
5669         msg = new TiXmlElement( "currentsong" );
5670         msg->LinkEndChild( new TiXmlText( UtilityClass::String(music.currentsong).c_str() ));
5671         msgs->LinkEndChild( msg );
5672     }
5673 
5674     msg = new TiXmlElement( "teleportscript" );
5675     msg->LinkEndChild( new TiXmlText( teleportscript.c_str() ));
5676     msgs->LinkEndChild( msg );
5677     msg = new TiXmlElement( "companion" );
5678     msg->LinkEndChild( new TiXmlText( UtilityClass::String(companion).c_str() ));
5679     msgs->LinkEndChild( msg );
5680 
5681     msg = new TiXmlElement( "lastsaved" );
5682     msg->LinkEndChild( new TiXmlText( UtilityClass::String(lastsaved).c_str() ));
5683     msgs->LinkEndChild( msg );
5684     msg = new TiXmlElement( "supercrewmate" );
5685     msg->LinkEndChild( new TiXmlText( BoolToString(supercrewmate) ));
5686     msgs->LinkEndChild( msg );
5687 
5688     msg = new TiXmlElement( "scmprogress" );
5689     msg->LinkEndChild( new TiXmlText( UtilityClass::String(scmprogress).c_str() ));
5690     msgs->LinkEndChild( msg );
5691     msg = new TiXmlElement( "scmmoveme" );
5692     msg->LinkEndChild( new TiXmlText( BoolToString(scmmoveme) ));
5693     msgs->LinkEndChild( msg );
5694 
5695 
5696     //telecookie.data.frames = frames; telecookie.data.seconds = seconds;
5697     //telecookie.data.minutes = minutes; telecookie.data.hours = hours;
5698 
5699     //telecookie.data.deathcounts = deathcounts;
5700     //telecookie.data.totalflips = totalflips;
5701     //telecookie.data.hardestroom = hardestroom; telecookie.data.hardestroomdeaths = hardestroomdeaths;
5702 
5703     //savearea = map.currentarea(map.area(roomx, roomy))
5704     //telecookie.data.summary = savearea + ", " + timestring(help);
5705     //telesummary = telecookie.data.summary;
5706 
5707 
5708     msg = new TiXmlElement( "frames" );
5709     msg->LinkEndChild( new TiXmlText( UtilityClass::String(frames).c_str() ));
5710     msgs->LinkEndChild( msg );
5711     msg = new TiXmlElement( "seconds" );
5712     msg->LinkEndChild( new TiXmlText( UtilityClass::String(seconds).c_str() ));
5713     msgs->LinkEndChild( msg );
5714 
5715     msg = new TiXmlElement( "minutes" );
5716     msg->LinkEndChild( new TiXmlText( UtilityClass::String(minutes).c_str()) );
5717     msgs->LinkEndChild( msg );
5718     msg = new TiXmlElement( "hours" );
5719     msg->LinkEndChild( new TiXmlText( UtilityClass::String(hours).c_str()) );
5720     msgs->LinkEndChild( msg );
5721 
5722     msg = new TiXmlElement( "deathcounts" );
5723     msg->LinkEndChild( new TiXmlText( UtilityClass::String(deathcounts).c_str() ));
5724     msgs->LinkEndChild( msg );
5725     msg = new TiXmlElement( "totalflips" );
5726     msg->LinkEndChild( new TiXmlText( UtilityClass::String(totalflips).c_str() ));
5727     msgs->LinkEndChild( msg );
5728 
5729     msg = new TiXmlElement( "hardestroom" );
5730     msg->LinkEndChild( new TiXmlText( hardestroom.c_str() ));
5731     msgs->LinkEndChild( msg );
5732     msg = new TiXmlElement( "hardestroomdeaths" );
5733     msg->LinkEndChild( new TiXmlText( UtilityClass::String(hardestroomdeaths).c_str() ));
5734     msgs->LinkEndChild( msg );
5735 
5736     msg = new TiXmlElement( "finalmode" );
5737     msg->LinkEndChild( new TiXmlText( BoolToString(map.finalmode)));
5738     msgs->LinkEndChild( msg );
5739     msg = new TiXmlElement( "finalstretch" );
5740     msg->LinkEndChild( new TiXmlText( BoolToString(map.finalstretch) ));
5741     msgs->LinkEndChild( msg );
5742 
5743 
5744     msg = new TiXmlElement( "summary" );
5745     UtilityClass tempUtil;
5746     std::string summary = savearea + ", " + timestring(tempUtil);
5747     msg->LinkEndChild( new TiXmlText( summary.c_str() ));
5748     msgs->LinkEndChild( msg );
5749 
5750     telesummary = summary;
5751     //telecookie.flush();
5752     //telecookie.close();
5753 
5754     if(doc.SaveFile( (saveFilePath+"tsave.vvv").c_str() ))
5755     {
5756         printf("Game saved\n");
5757     }
5758     else
5759     {
5760         printf("Could Not Save game!\n");
5761         printf("Failed: %s%s\n", saveFilePath.c_str(), "tsave.vvv");
5762     }
5763 }
5764 
5765 
savequick(mapclass & map,entityclass & obj,musicclass & music)5766 void Game::savequick( mapclass& map, entityclass& obj, musicclass& music )
5767 {
5768     quickcookieexists = true;
5769 
5770     TiXmlDocument doc;
5771     TiXmlElement* msg;
5772     TiXmlDeclaration* decl = new TiXmlDeclaration( "1.0", "", "" );
5773     doc.LinkEndChild( decl );
5774 
5775     TiXmlElement * root = new TiXmlElement( "Save" );
5776     doc.LinkEndChild( root );
5777 
5778     TiXmlComment * comment = new TiXmlComment();
5779     comment->SetValue(" Save file " );
5780     root->LinkEndChild( comment );
5781 
5782     TiXmlElement * msgs = new TiXmlElement( "Data" );
5783     root->LinkEndChild( msgs );
5784 
5785 
5786     //Flags, map and stats
5787     //savestate[1].explored = map.explored.slice();
5788     //savestate[1].flags = obj.flags.slice();
5789     //savestate[1].crewstats = crewstats.slice();
5790     //savestate[1].collect = obj.collect.slice();
5791 
5792     //telecookie.data.worldmap = savestate[1].explored.slice();
5793     //telecookie.data.flags = savestate[1].flags.slice();
5794     //telecookie.data.crewstats = savestate[1].crewstats.slice();
5795     //telecookie.data.collect = savestate[1].collect.slice();
5796 
5797     //telecookie.data.finalmode = map.finalmode;
5798     //telecookie.data.finalstretch = map.finalstretch;
5799 
5800     std::string mapExplored;
5801     for(size_t i = 0; i < map.explored.size(); i++ )
5802     {
5803         mapExplored += UtilityClass::String(map.explored[i]) + ",";
5804     }
5805     msg = new TiXmlElement( "worldmap" );
5806     msg->LinkEndChild( new TiXmlText( mapExplored.c_str() ));
5807     msgs->LinkEndChild( msg );
5808 
5809     std::string flags;
5810     for(size_t i = 0; i < obj.flags.size(); i++ )
5811     {
5812         flags += UtilityClass::String(obj.flags[i]) + ",";
5813     }
5814     msg = new TiXmlElement( "flags" );
5815     msg->LinkEndChild( new TiXmlText( flags.c_str() ));
5816     msgs->LinkEndChild( msg );
5817 
5818     std::string crewstatsString;
5819     for(size_t i = 0; i < crewstats.size(); i++ )
5820     {
5821         crewstatsString += UtilityClass::String(crewstats[i]) + ",";
5822     }
5823     msg = new TiXmlElement( "crewstats" );
5824     msg->LinkEndChild( new TiXmlText( crewstatsString.c_str() ));
5825     msgs->LinkEndChild( msg );
5826 
5827     std::string collect;
5828     for(size_t i = 0; i < obj.collect.size(); i++ )
5829     {
5830         collect += UtilityClass::String(obj.collect[i]) + ",";
5831     }
5832     msg = new TiXmlElement( "collect" );
5833     msg->LinkEndChild( new TiXmlText( collect.c_str() ));
5834     msgs->LinkEndChild( msg );
5835 
5836     //telecookie.data.finalx = map.finalx;
5837     //telecookie.data.finaly = map.finaly;
5838     //Position
5839     //telecookie.data.savex = savex;
5840     //telecookie.data.savey = savey;
5841 
5842     msg = new TiXmlElement( "finalx" );
5843     msg->LinkEndChild( new TiXmlText( UtilityClass::String(map.finalx).c_str() ));
5844     msgs->LinkEndChild( msg );
5845 
5846     msg = new TiXmlElement( "finaly" );
5847     msg->LinkEndChild( new TiXmlText( UtilityClass::String(map.finaly).c_str() ));
5848     msgs->LinkEndChild( msg );
5849 
5850     msg = new TiXmlElement( "savex" );
5851     msg->LinkEndChild( new TiXmlText( UtilityClass::String(savex).c_str() ));
5852     msgs->LinkEndChild( msg );
5853 
5854     msg = new TiXmlElement( "savey" );
5855     msg->LinkEndChild( new TiXmlText( UtilityClass::String(savey).c_str() ));
5856     msgs->LinkEndChild( msg );
5857 
5858     msg = new TiXmlElement( "saverx" );
5859     msg->LinkEndChild( new TiXmlText( UtilityClass::String(saverx).c_str() ));
5860     msgs->LinkEndChild( msg );
5861 
5862     msg = new TiXmlElement( "savery" );
5863     msg->LinkEndChild( new TiXmlText( UtilityClass::String(savery).c_str() ));
5864     msgs->LinkEndChild( msg );
5865 
5866     //telecookie.data.saverx = saverx;
5867     //telecookie.data.savery = savery;
5868     //telecookie.data.savegc = savegc;
5869     //telecookie.data.savedir = savedir;
5870     //telecookie.data.savepoint = savepoint;
5871     //telecookie.data.trinkets = trinkets;
5872 
5873     msg = new TiXmlElement( "savegc" );
5874     msg->LinkEndChild( new TiXmlText( UtilityClass::String(savegc).c_str() ));
5875     msgs->LinkEndChild( msg );
5876 
5877     msg = new TiXmlElement( "savedir" );
5878     msg->LinkEndChild( new TiXmlText( UtilityClass::String(savedir).c_str() ));
5879     msgs->LinkEndChild( msg );
5880 
5881     msg = new TiXmlElement( "savepoint" );
5882     msg->LinkEndChild( new TiXmlText( UtilityClass::String(savepoint).c_str() ));
5883     msgs->LinkEndChild( msg );
5884 
5885     msg = new TiXmlElement( "trinkets" );
5886     msg->LinkEndChild( new TiXmlText( UtilityClass::String(trinkets).c_str() ));
5887     msgs->LinkEndChild( msg );
5888 
5889 
5890     //if (music.nicechange != -1) {
5891     //telecookie.data.currentsong = music.nicechange;
5892     //}else{
5893     //telecookie.data.currentsong = music.currentsong;
5894     //}
5895     //telecookie.data.teleportscript = teleportscript;
5896 
5897     //Special stats
5898     //telecookie.data.companion = companion;
5899     //telecookie.data.lastsaved = lastsaved;
5900     //telecookie.data.supercrewmate = supercrewmate;
5901     //telecookie.data.scmprogress = scmprogress;
5902     //telecookie.data.scmmoveme = scmmoveme;
5903     if(music.nicefade==1)
5904     {
5905         msg = new TiXmlElement( "currentsong" );
5906         msg->LinkEndChild( new TiXmlText( UtilityClass::String(music.nicechange).c_str() ));
5907         msgs->LinkEndChild( msg );
5908     }
5909     else
5910     {
5911         msg = new TiXmlElement( "currentsong" );
5912         msg->LinkEndChild( new TiXmlText( UtilityClass::String(music.currentsong).c_str() ));
5913         msgs->LinkEndChild( msg );
5914     }
5915 
5916     msg = new TiXmlElement( "teleportscript" );
5917     msg->LinkEndChild( new TiXmlText( teleportscript.c_str() ));
5918     msgs->LinkEndChild( msg );
5919     msg = new TiXmlElement( "companion" );
5920     msg->LinkEndChild( new TiXmlText( UtilityClass::String(companion).c_str() ));
5921     msgs->LinkEndChild( msg );
5922 
5923     msg = new TiXmlElement( "lastsaved" );
5924     msg->LinkEndChild( new TiXmlText( UtilityClass::String(lastsaved).c_str() ));
5925     msgs->LinkEndChild( msg );
5926     msg = new TiXmlElement( "supercrewmate" );
5927     msg->LinkEndChild( new TiXmlText( BoolToString(supercrewmate) ));
5928     msgs->LinkEndChild( msg );
5929 
5930     msg = new TiXmlElement( "scmprogress" );
5931     msg->LinkEndChild( new TiXmlText( UtilityClass::String(scmprogress).c_str() ));
5932     msgs->LinkEndChild( msg );
5933     msg = new TiXmlElement( "scmmoveme" );
5934     msg->LinkEndChild( new TiXmlText( BoolToString(scmmoveme) ));
5935     msgs->LinkEndChild( msg );
5936 
5937 
5938     //telecookie.data.finalmode = map.finalmode;
5939     //telecookie.data.finalstretch = map.finalstretch;
5940 
5941     msg = new TiXmlElement( "finalmode" );
5942     msg->LinkEndChild( new TiXmlText( BoolToString(map.finalmode) ));
5943     msgs->LinkEndChild( msg );
5944     msg = new TiXmlElement( "finalstretch" );
5945     msg->LinkEndChild( new TiXmlText( BoolToString(map.finalstretch) ));
5946     msgs->LinkEndChild( msg );
5947 
5948     //telecookie.data.frames = frames; telecookie.data.seconds = seconds;
5949     //telecookie.data.minutes = minutes; telecookie.data.hours = hours;
5950 
5951     //telecookie.data.deathcounts = deathcounts;
5952     //telecookie.data.totalflips = totalflips;
5953     //telecookie.data.hardestroom = hardestroom; telecookie.data.hardestroomdeaths = hardestroomdeaths;
5954 
5955     //savearea = map.currentarea(map.area(roomx, roomy))
5956     //telecookie.data.summary = savearea + ", " + timestring(help);
5957     //telesummary = telecookie.data.summary;
5958 
5959 
5960     msg = new TiXmlElement( "frames" );
5961     msg->LinkEndChild( new TiXmlText( UtilityClass::String(frames).c_str() ));
5962     msgs->LinkEndChild( msg );
5963     msg = new TiXmlElement( "seconds" );
5964     msg->LinkEndChild( new TiXmlText( UtilityClass::String(seconds).c_str() ));
5965     msgs->LinkEndChild( msg );
5966 
5967     msg = new TiXmlElement( "minutes" );
5968     msg->LinkEndChild( new TiXmlText( UtilityClass::String(minutes).c_str()) );
5969     msgs->LinkEndChild( msg );
5970     msg = new TiXmlElement( "hours" );
5971     msg->LinkEndChild( new TiXmlText( UtilityClass::String(hours).c_str()) );
5972     msgs->LinkEndChild( msg );
5973 
5974     msg = new TiXmlElement( "deathcounts" );
5975     msg->LinkEndChild( new TiXmlText( UtilityClass::String(deathcounts).c_str() ));
5976     msgs->LinkEndChild( msg );
5977     msg = new TiXmlElement( "totalflips" );
5978     msg->LinkEndChild( new TiXmlText( UtilityClass::String(totalflips).c_str() ));
5979     msgs->LinkEndChild( msg );
5980 
5981     msg = new TiXmlElement( "hardestroom" );
5982     msg->LinkEndChild( new TiXmlText( hardestroom.c_str() ));
5983     msgs->LinkEndChild( msg );
5984     msg = new TiXmlElement( "hardestroomdeaths" );
5985     msg->LinkEndChild( new TiXmlText( UtilityClass::String(hardestroomdeaths).c_str() ));
5986     msgs->LinkEndChild( msg );
5987 
5988     msg = new TiXmlElement( "summary" );
5989     UtilityClass tempUtil;
5990     std::string summary = savearea + ", " + timestring(tempUtil);
5991     msg->LinkEndChild( new TiXmlText( summary.c_str() ));
5992     msgs->LinkEndChild( msg );
5993 
5994     quicksummary = summary;
5995     //telecookie.flush();
5996     //telecookie.close();
5997 
5998     if(doc.SaveFile( (saveFilePath+ "qsave.vvv").c_str() ))
5999     {
6000         printf("Game saved\n");
6001     }
6002     else
6003     {
6004         printf("Could Not Save game!\n");
6005         printf("Failed: %s%s\n", saveFilePath.c_str(), "qsave.vvv");
6006     }
6007 
6008 }
6009 
customsavequick(std::string savfile,mapclass & map,entityclass & obj,musicclass & music)6010 void Game::customsavequick(std::string savfile, mapclass& map, entityclass& obj, musicclass& music )
6011 {
6012     quickcookieexists = true;
6013 
6014     TiXmlDocument doc;
6015     TiXmlElement* msg;
6016     TiXmlDeclaration* decl = new TiXmlDeclaration( "1.0", "", "" );
6017     doc.LinkEndChild( decl );
6018 
6019     TiXmlElement * root = new TiXmlElement( "Save" );
6020     doc.LinkEndChild( root );
6021 
6022     TiXmlComment * comment = new TiXmlComment();
6023     comment->SetValue(" Save file " );
6024     root->LinkEndChild( comment );
6025 
6026     TiXmlElement * msgs = new TiXmlElement( "Data" );
6027     root->LinkEndChild( msgs );
6028 
6029 
6030     //Flags, map and stats
6031     //savestate[1].explored = map.explored.slice();
6032     //savestate[1].flags = obj.flags.slice();
6033     //savestate[1].crewstats = crewstats.slice();
6034     //savestate[1].collect = obj.collect.slice();
6035 
6036     //telecookie.data.worldmap = savestate[1].explored.slice();
6037     //telecookie.data.flags = savestate[1].flags.slice();
6038     //telecookie.data.crewstats = savestate[1].crewstats.slice();
6039     //telecookie.data.collect = savestate[1].collect.slice();
6040 
6041     //telecookie.data.finalmode = map.finalmode;
6042     //telecookie.data.finalstretch = map.finalstretch;
6043 
6044     std::string mapExplored;
6045     for(size_t i = 0; i < map.explored.size(); i++ )
6046     {
6047         mapExplored += UtilityClass::String(map.explored[i]) + ",";
6048     }
6049     msg = new TiXmlElement( "worldmap" );
6050     msg->LinkEndChild( new TiXmlText( mapExplored.c_str() ));
6051     msgs->LinkEndChild( msg );
6052 
6053     std::string flags;
6054     for(size_t i = 0; i < obj.flags.size(); i++ )
6055     {
6056         flags += UtilityClass::String(obj.flags[i]) + ",";
6057     }
6058     msg = new TiXmlElement( "flags" );
6059     msg->LinkEndChild( new TiXmlText( flags.c_str() ));
6060     msgs->LinkEndChild( msg );
6061 
6062     std::string moods;
6063     for(int i = 0; i < 6; i++ )
6064     {
6065         moods += UtilityClass::String(obj.customcrewmoods[i]) + ",";
6066     }
6067     msg = new TiXmlElement( "moods" );
6068     msg->LinkEndChild( new TiXmlText( moods.c_str() ));
6069     msgs->LinkEndChild( msg );
6070 
6071     std::string crewstatsString;
6072     for(size_t i = 0; i < crewstats.size(); i++ )
6073     {
6074         crewstatsString += UtilityClass::String(crewstats[i]) + ",";
6075     }
6076     msg = new TiXmlElement( "crewstats" );
6077     msg->LinkEndChild( new TiXmlText( crewstatsString.c_str() ));
6078     msgs->LinkEndChild( msg );
6079 
6080     std::string collect;
6081     for(size_t i = 0; i < obj.collect.size(); i++ )
6082     {
6083         collect += UtilityClass::String(obj.collect[i]) + ",";
6084     }
6085     msg = new TiXmlElement( "collect" );
6086     msg->LinkEndChild( new TiXmlText( collect.c_str() ));
6087     msgs->LinkEndChild( msg );
6088 
6089     std::string customcollect;
6090     for(size_t i = 0; i < obj.customcollect.size(); i++ )
6091     {
6092         customcollect += UtilityClass::String(obj.customcollect[i]) + ",";
6093     }
6094     msg = new TiXmlElement( "customcollect" );
6095     msg->LinkEndChild( new TiXmlText( customcollect.c_str() ));
6096     msgs->LinkEndChild( msg );
6097 
6098     //telecookie.data.finalx = map.finalx;
6099     //telecookie.data.finaly = map.finaly;
6100     //Position
6101     //telecookie.data.savex = savex;
6102     //telecookie.data.savey = savey;
6103 
6104     msg = new TiXmlElement( "finalx" );
6105     msg->LinkEndChild( new TiXmlText( UtilityClass::String(map.finalx).c_str() ));
6106     msgs->LinkEndChild( msg );
6107 
6108     msg = new TiXmlElement( "finaly" );
6109     msg->LinkEndChild( new TiXmlText( UtilityClass::String(map.finaly).c_str() ));
6110     msgs->LinkEndChild( msg );
6111 
6112     msg = new TiXmlElement( "savex" );
6113     msg->LinkEndChild( new TiXmlText( UtilityClass::String(savex).c_str() ));
6114     msgs->LinkEndChild( msg );
6115 
6116     msg = new TiXmlElement( "savey" );
6117     msg->LinkEndChild( new TiXmlText( UtilityClass::String(savey).c_str() ));
6118     msgs->LinkEndChild( msg );
6119 
6120     msg = new TiXmlElement( "saverx" );
6121     msg->LinkEndChild( new TiXmlText( UtilityClass::String(saverx).c_str() ));
6122     msgs->LinkEndChild( msg );
6123 
6124     msg = new TiXmlElement( "savery" );
6125     msg->LinkEndChild( new TiXmlText( UtilityClass::String(savery).c_str() ));
6126     msgs->LinkEndChild( msg );
6127 
6128     //telecookie.data.saverx = saverx;
6129     //telecookie.data.savery = savery;
6130     //telecookie.data.savegc = savegc;
6131     //telecookie.data.savedir = savedir;
6132     //telecookie.data.savepoint = savepoint;
6133     //telecookie.data.trinkets = trinkets;
6134 
6135     msg = new TiXmlElement( "savegc" );
6136     msg->LinkEndChild( new TiXmlText( UtilityClass::String(savegc).c_str() ));
6137     msgs->LinkEndChild( msg );
6138 
6139     msg = new TiXmlElement( "savedir" );
6140     msg->LinkEndChild( new TiXmlText( UtilityClass::String(savedir).c_str() ));
6141     msgs->LinkEndChild( msg );
6142 
6143     msg = new TiXmlElement( "savepoint" );
6144     msg->LinkEndChild( new TiXmlText( UtilityClass::String(savepoint).c_str() ));
6145     msgs->LinkEndChild( msg );
6146 
6147     msg = new TiXmlElement( "trinkets" );
6148     msg->LinkEndChild( new TiXmlText( UtilityClass::String(trinkets).c_str() ));
6149     msgs->LinkEndChild( msg );
6150 
6151     msg = new TiXmlElement( "crewmates" );
6152     msg->LinkEndChild( new TiXmlText( UtilityClass::String(crewmates).c_str() ));
6153     msgs->LinkEndChild( msg );
6154 
6155 
6156     //if (music.nicechange != -1) {
6157     //telecookie.data.currentsong = music.nicechange;
6158     //}else{
6159     //telecookie.data.currentsong = music.currentsong;
6160     //}
6161     //telecookie.data.teleportscript = teleportscript;
6162 
6163     //Special stats
6164     //telecookie.data.companion = companion;
6165     //telecookie.data.lastsaved = lastsaved;
6166     //telecookie.data.supercrewmate = supercrewmate;
6167     //telecookie.data.scmprogress = scmprogress;
6168     //telecookie.data.scmmoveme = scmmoveme;
6169     if(music.nicefade==1)
6170     {
6171         msg = new TiXmlElement( "currentsong" );
6172         msg->LinkEndChild( new TiXmlText( UtilityClass::String(music.nicechange).c_str() ));
6173         msgs->LinkEndChild( msg );
6174     }
6175     else
6176     {
6177         msg = new TiXmlElement( "currentsong" );
6178         msg->LinkEndChild( new TiXmlText( UtilityClass::String(music.currentsong).c_str() ));
6179         msgs->LinkEndChild( msg );
6180     }
6181 
6182     msg = new TiXmlElement( "teleportscript" );
6183     msg->LinkEndChild( new TiXmlText( teleportscript.c_str() ));
6184     msgs->LinkEndChild( msg );
6185     msg = new TiXmlElement( "companion" );
6186     msg->LinkEndChild( new TiXmlText( UtilityClass::String(companion).c_str() ));
6187     msgs->LinkEndChild( msg );
6188 
6189     msg = new TiXmlElement( "lastsaved" );
6190     msg->LinkEndChild( new TiXmlText( UtilityClass::String(lastsaved).c_str() ));
6191     msgs->LinkEndChild( msg );
6192     msg = new TiXmlElement( "supercrewmate" );
6193     msg->LinkEndChild( new TiXmlText( BoolToString(supercrewmate) ));
6194     msgs->LinkEndChild( msg );
6195 
6196     msg = new TiXmlElement( "scmprogress" );
6197     msg->LinkEndChild( new TiXmlText( UtilityClass::String(scmprogress).c_str() ));
6198     msgs->LinkEndChild( msg );
6199     msg = new TiXmlElement( "scmmoveme" );
6200     msg->LinkEndChild( new TiXmlText( BoolToString(scmmoveme) ));
6201     msgs->LinkEndChild( msg );
6202 
6203 
6204     //telecookie.data.frames = frames; telecookie.data.seconds = seconds;
6205     //telecookie.data.minutes = minutes; telecookie.data.hours = hours;
6206 
6207     //telecookie.data.deathcounts = deathcounts;
6208     //telecookie.data.totalflips = totalflips;
6209     //telecookie.data.hardestroom = hardestroom; telecookie.data.hardestroomdeaths = hardestroomdeaths;
6210 
6211     //savearea = map.currentarea(map.area(roomx, roomy))
6212     //telecookie.data.summary = savearea + ", " + timestring(help);
6213     //telesummary = telecookie.data.summary;
6214 
6215 
6216     msg = new TiXmlElement( "frames" );
6217     msg->LinkEndChild( new TiXmlText( UtilityClass::String(frames).c_str() ));
6218     msgs->LinkEndChild( msg );
6219     msg = new TiXmlElement( "seconds" );
6220     msg->LinkEndChild( new TiXmlText( UtilityClass::String(seconds).c_str() ));
6221     msgs->LinkEndChild( msg );
6222 
6223     msg = new TiXmlElement( "minutes" );
6224     msg->LinkEndChild( new TiXmlText( UtilityClass::String(minutes).c_str()) );
6225     msgs->LinkEndChild( msg );
6226     msg = new TiXmlElement( "hours" );
6227     msg->LinkEndChild( new TiXmlText( UtilityClass::String(hours).c_str()) );
6228     msgs->LinkEndChild( msg );
6229 
6230     msg = new TiXmlElement( "deathcounts" );
6231     msg->LinkEndChild( new TiXmlText( UtilityClass::String(deathcounts).c_str() ));
6232     msgs->LinkEndChild( msg );
6233     msg = new TiXmlElement( "totalflips" );
6234     msg->LinkEndChild( new TiXmlText( UtilityClass::String(totalflips).c_str() ));
6235     msgs->LinkEndChild( msg );
6236 
6237     msg = new TiXmlElement( "hardestroom" );
6238     msg->LinkEndChild( new TiXmlText( hardestroom.c_str() ));
6239     msgs->LinkEndChild( msg );
6240     msg = new TiXmlElement( "hardestroomdeaths" );
6241     msg->LinkEndChild( new TiXmlText( UtilityClass::String(hardestroomdeaths).c_str() ));
6242     msgs->LinkEndChild( msg );
6243 
6244     msg = new TiXmlElement( "showminimap" );
6245     msg->LinkEndChild( new TiXmlText( BoolToString(map.customshowmm) ));
6246     msgs->LinkEndChild( msg );
6247 
6248     msg = new TiXmlElement( "summary" );
6249     UtilityClass tempUtil;
6250     std::string summary = savearea + ", " + timestring(tempUtil);
6251     msg->LinkEndChild( new TiXmlText( summary.c_str() ));
6252     msgs->LinkEndChild( msg );
6253 
6254     customquicksummary = summary;
6255     //telecookie.flush();
6256     //telecookie.close();
6257 
6258     std::string levelfile = savfile.substr(7);
6259     if(doc.SaveFile( (saveFilePath+ levelfile+".vvv").c_str() ))
6260     {
6261         printf("Game saved\n");
6262     }
6263     else
6264     {
6265         printf("Could Not Save game!\n");
6266         printf("Failed: %s%s%s", saveFilePath.c_str(), levelfile.c_str(), ".vvv");
6267     }
6268 }
6269 
6270 
loadtele(mapclass & map,entityclass & obj,musicclass & music)6271 void Game::loadtele( mapclass& map, entityclass& obj, musicclass& music )
6272 {
6273     TiXmlDocument doc((saveFilePath+"tsave.vvv").c_str());
6274     if (!doc.LoadFile()) return; ;
6275 
6276     TiXmlHandle hDoc(&doc);
6277     TiXmlElement* pElem;
6278     TiXmlHandle hRoot(0);
6279 
6280 
6281     {
6282         pElem=hDoc.FirstChildElement().Element();
6283         // should always have a valid root but handle gracefully if it does
6284         if (!pElem)
6285         {
6286             printf("Save Not Found\n");
6287         }
6288 
6289         // save this for later
6290         hRoot=TiXmlHandle(pElem);
6291     }
6292 
6293 
6294     for( pElem = hRoot.FirstChild( "Data" ).FirstChild().Element(); pElem; pElem=pElem->NextSiblingElement())
6295     {
6296         std::string pKey(pElem->Value());
6297         const char* pText = pElem->GetText() ;
6298         if(pText == NULL)
6299         {
6300             pText = "";
6301         }
6302 
6303         if (pKey == "worldmap")
6304         {
6305             std::string TextString = (pText);
6306             if(TextString.length())
6307             {
6308                 std::vector<std::string> values = split(TextString,',');
6309                 map.explored.clear();
6310                 for(size_t i = 0; i < values.size(); i++)
6311                 {
6312                     map.explored.push_back(atoi(values[i].c_str()));
6313                 }
6314             }
6315         }
6316 
6317         if (pKey == "flags")
6318         {
6319             std::string TextString = (pText);
6320             if(TextString.length())
6321             {
6322                 std::vector<std::string> values = split(TextString,',');
6323                 obj.flags.clear();
6324                 for(size_t i = 0; i < values.size(); i++)
6325                 {
6326                     obj.flags.push_back(atoi(values[i].c_str()));
6327                 }
6328             }
6329         }
6330 
6331         if (pKey == "crewstats")
6332         {
6333             std::string TextString = (pText);
6334             if(TextString.length())
6335             {
6336                 std::vector<std::string> values = split(TextString,',');
6337                 crewstats.clear();
6338                 for(size_t i = 0; i < values.size(); i++)
6339                 {
6340                     crewstats.push_back(atoi(values[i].c_str()));
6341                 }
6342             }
6343         }
6344 
6345         if (pKey == "collect")
6346         {
6347             std::string TextString = (pText);
6348             if(TextString.length())
6349             {
6350                 std::vector<std::string> values = split(TextString,',');
6351                 obj.collect.clear();
6352                 for(size_t i = 0; i < values.size(); i++)
6353                 {
6354                     obj.collect.push_back(atoi(values[i].c_str()));
6355                 }
6356             }
6357         }
6358 
6359         if (pKey == "finalmode")
6360         {
6361             map.finalmode = atoi(pText);
6362         }
6363         if (pKey == "finalstretch")
6364         {
6365             map.finalstretch = atoi(pText);
6366         }
6367 
6368         if (map.finalmode)
6369         {
6370             map.final_colormode = false;
6371             map.final_mapcol = 0;
6372             map.final_colorframe = 0;
6373         }
6374         if (map.finalstretch)
6375         {
6376             map.finalstretch = true;
6377             map.final_colormode = true;
6378             map.final_mapcol = 0;
6379             map.final_colorframe = 1;
6380         }
6381 
6382 
6383         if (pKey == "finalx")
6384         {
6385             map.finalx = atoi(pText);
6386         }
6387         else if (pKey == "finaly")
6388         {
6389             map.finaly = atoi(pText);
6390         }
6391         else if (pKey == "savex")
6392         {
6393             savex = atoi(pText);
6394         }
6395         else if (pKey == "savey")
6396         {
6397             savey = atoi(pText);
6398         }
6399         else if (pKey == "saverx")
6400         {
6401             saverx = atoi(pText);
6402         }
6403         else if (pKey == "savery")
6404         {
6405             savery = atoi(pText);
6406         }
6407         else if (pKey == "savegc")
6408         {
6409             savegc = atoi(pText);
6410         }
6411         else if (pKey == "savedir")
6412         {
6413             savedir= atoi(pText);
6414         }
6415         else if (pKey == "savepoint")
6416         {
6417             savepoint = atoi(pText);
6418         }
6419         else if (pKey == "trinkets")
6420         {
6421             trinkets = atoi(pText);
6422         }
6423         else if (pKey == "companion")
6424         {
6425             companion = atoi(pText);
6426         }
6427         else if (pKey == "lastsaved")
6428         {
6429             lastsaved = atoi(pText);
6430         }
6431         else if (pKey == "teleportscript")
6432         {
6433             teleportscript = pText;
6434         }
6435         else if (pKey == "supercrewmate")
6436         {
6437             supercrewmate = atoi(pText);
6438         }
6439         else if (pKey == "scmprogress")
6440         {
6441             scmprogress = atoi(pText);
6442         }
6443         else if (pKey == "scmmoveme")
6444         {
6445             scmmoveme = atoi(pText);
6446         }
6447         else if (pKey == "frames")
6448         {
6449             frames = atoi(pText);
6450 						frames = 0;
6451         }
6452         else if (pKey == "seconds")
6453         {
6454             seconds = atoi(pText);
6455         }
6456         else if (pKey == "minutes")
6457         {
6458             minutes = atoi(pText);
6459         }
6460         else if (pKey == "hours")
6461         {
6462             hours = atoi(pText);
6463         }
6464         else if (pKey == "deathcounts")
6465         {
6466             deathcounts = atoi(pText);
6467         }
6468         else if (pKey == "totalflips")
6469         {
6470             totalflips = atoi(pText);
6471         }
6472         else if (pKey == "hardestroom")
6473         {
6474             hardestroom = pText;
6475         }
6476         else if (pKey == "hardestroomdeaths")
6477         {
6478             hardestroomdeaths = atoi(pText);
6479         }
6480         else if (pKey == "currentsong")
6481         {
6482             music.play(atoi(pText));
6483         }
6484 
6485     }
6486 
6487     map.showteleporters = true;
6488     if(obj.flags[12]==1) map.showtargets = true;
6489     if (obj.flags[42] == 1) map.showtrinkets = true;
6490 }
6491 
unrescued()6492 std::string Game::unrescued()
6493 {
6494     //Randomly return the name of an unrescued crewmate
6495     if (fRandom() * 100 > 50)
6496     {
6497         if (!crewstats[5]) return "Victoria";
6498         if (!crewstats[2]) return "Vitellary";
6499         if (!crewstats[4]) return "Verdigris";
6500         if (!crewstats[3]) return "Vermilion";
6501     }
6502     else
6503     {
6504         if (fRandom() * 100 > 50)
6505         {
6506             if (!crewstats[2]) return "Vitellary";
6507             if (!crewstats[4]) return "Verdigris";
6508             if (!crewstats[3]) return "Vermilion";
6509             if (!crewstats[5]) return "Victoria";
6510         }
6511         else
6512         {
6513             if (!crewstats[4]) return "Verdigris";
6514             if (!crewstats[3]) return "Vermilion";
6515             if (!crewstats[5]) return "Victoria";
6516             if (!crewstats[2]) return "Vitellary";
6517         }
6518     }
6519     return "you";
6520 }
6521 
gameclock()6522 void Game::gameclock()
6523 {
6524 /*
6525 test = true;
6526 std::ostringstream os;
6527 	os << hours << ":" << minutes << ":" << seconds << ", " << frames;
6528 teststring = os.str();
6529 */
6530   frames++;
6531 	if (frames >= 30)
6532 	{
6533 		frames -= 30;
6534 		seconds++;
6535 		if (seconds >= 60)
6536 		{
6537 			seconds -= 60;
6538 			minutes++;
6539 			if (minutes >= 60)
6540 			{
6541 				minutes -= 60;
6542 				hours++;
6543 			}
6544 		}
6545 	}
6546 }
6547 
giventimestring(int hrs,int min,int sec,UtilityClass & help)6548 std::string Game::giventimestring( int hrs, int min, int sec, UtilityClass& help )
6549 {
6550     tempstring = "";
6551     if (hrs > 0)
6552     {
6553         tempstring += help.String(hrs) + ":";
6554     }
6555     tempstring += help.twodigits(min) + ":" + help.twodigits(sec);
6556     return tempstring;
6557 }
6558 
timestring(UtilityClass & help)6559 std::string Game::timestring( UtilityClass& help )
6560 {
6561     tempstring = "";
6562     if (hours > 0)
6563     {
6564         tempstring += help.String(hours) + ":";
6565     }
6566     tempstring += help.twodigits(minutes) + ":" + help.twodigits(seconds);
6567     return tempstring;
6568 }
6569 
partimestring(UtilityClass & help)6570 std::string Game::partimestring( UtilityClass& help )
6571 {
6572     //given par time in seconds:
6573     tempstring = "";
6574     if (timetrialpar >= 60)
6575     {
6576         tempstring = help.twodigits(int((timetrialpar - (timetrialpar % 60)) / 60)) + ":" + help.twodigits(timetrialpar % 60);
6577     }
6578     else
6579     {
6580         tempstring = "00:" + help.twodigits(timetrialpar);
6581     }
6582     return tempstring;
6583 }
6584 
resulttimestring(UtilityClass & help)6585 std::string Game::resulttimestring( UtilityClass& help )
6586 {
6587     //given result time in seconds:
6588     tempstring = "";
6589     if (timetrialresulttime > 60)
6590     {
6591         tempstring = help.twodigits(int((timetrialresulttime - (timetrialresulttime % 60)) / 60)) + ":"
6592                      + help.twodigits(timetrialresulttime % 60);
6593     }
6594     else
6595     {
6596         tempstring = "00:" + help.twodigits(timetrialresulttime);
6597     }
6598     return tempstring;
6599 }
6600 
timetstring(int t,UtilityClass & help)6601 std::string Game::timetstring( int t, UtilityClass& help )
6602 {
6603     //given par time in seconds:
6604     tempstring = "";
6605     if (t >= 60)
6606     {
6607         tempstring = help.twodigits(int((t - (t % 60)) / 60)) + ":" + help.twodigits(t % 60);
6608     }
6609     else
6610     {
6611         tempstring = "00:" + help.twodigits(t);
6612     }
6613     return tempstring;
6614 }
6615 
createmenu(std::string t)6616 void Game::createmenu( std::string t )
6617 {
6618     currentmenuoption = 0;
6619     menuselection = "null";
6620     currentmenuname = t;
6621     menuxoff = 0;
6622     menuyoff = 0;
6623     menucountdown = 0;
6624     menudest="null";
6625 
6626     if (t == "mainmenu")
6627     {
6628 				#if defined(MAKEANDPLAY)
6629 					menuoptions[0] = "player levels";
6630 					menuoptionsactive[0] = true;
6631 					menuoptions[1] = "graphic options";
6632 					menuoptionsactive[1] = true;
6633 					menuoptions[2] = "game options";
6634 					menuoptionsactive[2] = true;
6635 					menuoptions[3] = "quit game";
6636 					menuoptionsactive[3] = true;
6637 					nummenuoptions = 4;
6638 					menuxoff = -16;
6639 					menuyoff = -10;
6640 				#elif !defined(MAKEANDPLAY)
6641 					menuoptions[0] = "start game";
6642 					menuoptionsactive[0] = true;
6643 					menuoptions[1] = "player levels";
6644 					menuoptionsactive[1] = true;
6645 					menuoptions[2] = "graphic options";
6646 					menuoptionsactive[2] = true;
6647 					menuoptions[3] = "game options";
6648 					menuoptionsactive[3] = true;
6649 					menuoptions[4] = "view credits";
6650 					menuoptionsactive[4] = true;
6651 					menuoptions[5] = "quit game";
6652 					menuoptionsactive[5] = true;
6653 					nummenuoptions = 6;
6654 					menuxoff = -16;
6655 					menuyoff = -10;
6656 				#endif
6657     }
6658     else if (t == "playerworlds")
6659     {
6660         menuoptions[0] = "play a level";
6661         menuoptionsactive[0] = true;
6662         menuoptions[1] = "level editor";
6663         menuoptionsactive[1] = true;
6664         //menuoptions[2] = "open level folder";
6665         //menuoptionsactive[2] = true;
6666         menuoptions[2] = "back to menu";
6667         menuoptionsactive[2] = true;
6668         nummenuoptions = 3;
6669         menuxoff = -30;
6670         menuyoff = -40;
6671     }
6672     else if (t == "quickloadlevel")
6673     {
6674         menuoptions[0] = "continue from save";
6675         menuoptionsactive[0] = true;
6676         menuoptions[1] = "start from beginning";
6677         menuoptionsactive[1] = true;
6678         menuoptions[2] = "back to levels";
6679         menuoptionsactive[2] = true;
6680         nummenuoptions = 3;
6681         menuxoff = -40;
6682         menuyoff = -30;
6683     }
6684     else if (t == "youwannaquit")
6685     {
6686         menuoptions[0] = "yes, quit";
6687         menuoptionsactive[0] = true;
6688         menuoptions[1] = "no, return";
6689         menuoptionsactive[1] = true;
6690         nummenuoptions = 2;
6691         menuxoff = 0;
6692         menuyoff = -20;
6693     }
6694     else if (t == "errornostart")
6695     {
6696         menuoptions[0] = "ok";
6697         menuoptionsactive[0] = true;
6698         nummenuoptions = 1;
6699         menuxoff = 0;
6700         menuyoff = -20;
6701     }
6702     else if (t == "levellist")
6703     {
6704         if(ed.ListOfMetaData.size()==0)
6705         {
6706             menuoptions[0] = "ok";
6707             menuoptionsactive[0] = true;
6708             nummenuoptions = 1;
6709             menuxoff = 0;
6710             menuyoff = -20;
6711         }
6712         else
6713         {
6714             int tcount=0;
6715             for(int i=0; i<(int) ed.ListOfMetaData.size(); i++) // FIXME: int/size_t! -flibit
6716             {
6717                 if(i>=levelpage*8 && i< (levelpage*8)+8)
6718                 {
6719                     //This is, er, suboptimal. Whatever, life optimisation and all that
6720                     int tvar=-1;
6721                     for(int j=0; j<numcustomlevelstats; j++)
6722                     {
6723                         if(ed.ListOfMetaData[i].filename.substr(7) == customlevelstats[j])
6724                         {
6725                             tvar=j;
6726                             j=numcustomlevelstats+1;
6727                         }
6728                     }
6729                     if(tvar>=0)
6730                     {
6731                         if(customlevelscore[tvar]==0)
6732                         {
6733                             menuoptions[tcount] = "   " + ed.ListOfMetaData[i].title;
6734                         }
6735                         else if(customlevelscore[tvar]==1)
6736                         {
6737                             menuoptions[tcount] = " * " + ed.ListOfMetaData[i].title;
6738                         }
6739                         else if(customlevelscore[tvar]==3)
6740                         {
6741                             menuoptions[tcount] = "** " + ed.ListOfMetaData[i].title;
6742                         }
6743                     }
6744                     else
6745                     {
6746                         menuoptions[tcount] = "   " + ed.ListOfMetaData[i].title;
6747                     }
6748                     menuoptionsactive[tcount] = true;
6749                     std::transform(menuoptions[tcount].begin(), menuoptions[tcount].end(), menuoptions[tcount].begin(), ::tolower);
6750                     tcount++;
6751                 }
6752             }
6753             if((size_t) ((levelpage*8)+8) <ed.ListOfMetaData.size())
6754             {
6755                 menuoptions[tcount] = "next page";
6756                 menuoptionsactive[tcount] = true;
6757                 tcount++;
6758             }
6759             else
6760             {
6761                 menuoptions[tcount] = "first page";
6762                 menuoptionsactive[tcount] = true;
6763                 tcount++;
6764             }
6765             menuoptions[tcount] = "return to menu";
6766             menuoptionsactive[tcount] = true;
6767             tcount++;
6768 
6769             nummenuoptions = tcount;
6770             menuxoff = -90;
6771             menuyoff = 70-(tcount*10);
6772         }
6773     }
6774     else if (t == "graphicoptions")
6775     {
6776         menuoptions[0] = "toggle fullscreen";
6777         menuoptionsactive[0] = true;
6778         menuoptions[1] = "toggle letterbox";
6779         menuoptionsactive[1] = true;
6780         menuoptions[2] = "toggle filter";
6781         menuoptionsactive[2] = true;
6782         menuoptions[3] = "toggle analogue";
6783         menuoptionsactive[3] = true;
6784         menuoptions[4] = "return";
6785         menuoptionsactive[4] = true;
6786         nummenuoptions = 5;
6787         menuxoff = -50;
6788         menuyoff = 8;
6789         /* Old stuff, not used anymore
6790         if (advanced_mode)
6791         {
6792         if(fullscreen)
6793         {
6794         menuoptions[0] = "change to windowed mode";
6795         menuoptionsactive[0] = true;
6796         }
6797         else
6798         {
6799         menuoptions[0] = "change to fullscreen";
6800         menuoptionsactive[0] = true;
6801         }
6802         menuoptions[1] = "enable acceleration";
6803         menuoptionsactive[1] = true;
6804         menuoptions[2] = "change scaling mode";
6805         menuoptionsactive[2] = true;
6806         if (advanced_smoothing)
6807         {
6808         menuoptions[3] = "disable smoothing";
6809         menuoptionsactive[3] = true;
6810         }
6811         else
6812         {
6813         menuoptions[3] = "enable smoothing";
6814         menuoptionsactive[3] = true;
6815         }
6816         menuoptions[4] = "return";
6817         menuoptionsactive[4] = true;
6818         nummenuoptions = 5;
6819         menuxoff = -50;
6820         menuyoff = 16;
6821         }
6822         else
6823         {
6824         if(fullscreen)
6825         {
6826         menuoptions[0] = "change to windowed mode";
6827         menuoptionsactive[0] = true;
6828         }
6829         else
6830         {
6831         menuoptions[0] = "change to fullscreen";
6832         menuoptionsactive[0] = true;
6833         }
6834         menuoptions[1] = "disable acceleration";
6835         menuoptionsactive[1] = true;
6836         menuoptions[2] = "return";
6837         menuoptionsactive[2] = true;
6838         nummenuoptions = 3;
6839         menuxoff = -50;
6840         menuyoff = 16;
6841         }
6842         */
6843     }
6844     else if (t == "ed_settings")
6845     {
6846         menuoptions[0] = "change description";
6847         menuoptionsactive[0] = true;
6848         menuoptions[1] = "edit scripts";
6849         menuoptionsactive[1] = true;
6850         menuoptions[2] = "change music";
6851         menuoptionsactive[2] = true;
6852         menuoptions[3] = "load level";
6853         menuoptionsactive[3] = true;
6854         menuoptions[4] = "save level";
6855         menuoptionsactive[4] = true;
6856         menuoptions[5] = "quit to main menu";
6857         menuoptionsactive[5] = true;
6858 
6859         nummenuoptions = 6;
6860         menuxoff = -50;
6861         menuyoff = -20;
6862     }
6863     else if (t == "ed_desc")
6864     {
6865         menuoptions[0] = "change name";
6866         menuoptionsactive[0] = true;
6867         menuoptions[1] = "change author";
6868         menuoptionsactive[1] = true;
6869         menuoptions[2] = "change description";
6870         menuoptionsactive[2] = true;
6871         menuoptions[3] = "change website";
6872         menuoptionsactive[3] = true;
6873         menuoptions[4] = "back to settings";
6874         menuoptionsactive[4] = true;
6875 
6876         nummenuoptions = 5;
6877         menuxoff = -40;
6878         menuyoff = 6;
6879     }
6880     else if (t == "ed_music")
6881     {
6882         menuoptions[0] = "next song";
6883         menuoptionsactive[0] = true;
6884         menuoptions[1] = "back";
6885         menuoptionsactive[1] = true;
6886         nummenuoptions = 2;
6887         menuxoff = -10;
6888         menuyoff = 16;
6889     }
6890     else if (t == "ed_quit")
6891     {
6892         menuoptions[0] = "yes, save and quit";
6893         menuoptionsactive[0] = true;
6894         menuoptions[1] = "no, quit without saving";
6895         menuoptionsactive[1] = true;
6896         menuoptions[2] = "return to editor";
6897         menuoptionsactive[2] = true;
6898         nummenuoptions = 3;
6899         menuxoff = -50;
6900         menuyoff = 8;
6901     }
6902     else if (t == "options")
6903     {
6904 				#if defined(MAKEANDPLAY)
6905 					menuoptions[0] = "accessibility options";
6906 					menuoptionsactive[0] = true;
6907 					menuoptions[1] = "game pad options";
6908 					menuoptionsactive[1] = true;
6909 					menuoptions[2] = "clear data";
6910 					menuoptionsactive[2] = true;
6911 					menuoptions[3] = "return";
6912 					menuoptionsactive[3] = true;
6913 					nummenuoptions = 4;
6914 					menuxoff = -40;
6915 					menuyoff = 0;
6916 				#elif !defined(MAKEANDPLAY)
6917 					menuoptions[0] = "accessibility options";
6918 					menuoptionsactive[0] = true;
6919 					menuoptions[1] = "unlock play modes";
6920 					menuoptionsactive[1] = true;
6921 					menuoptions[2] = "game pad options";
6922 					menuoptionsactive[2] = true;
6923 					menuoptions[3] = "clear data";
6924 					menuoptionsactive[3] = true;
6925 
6926 					menuoptions[4] = "return";
6927 					menuoptionsactive[4] = true;
6928 					nummenuoptions = 5;
6929 					menuxoff = -40;
6930 					menuyoff = 0;
6931 				#endif
6932     }
6933     else if (t == "accessibility")
6934     {
6935         menuoptions[0] = "animated backgrounds";
6936         menuoptionsactive[0] = true;
6937         menuoptions[1] = "screen effects";
6938         menuoptionsactive[1] = true;
6939         menuoptions[2] = "invincibility";
6940         menuoptionsactive[2] = true;
6941         menuoptions[3] = "slowdown";
6942         menuoptionsactive[3] = true;
6943         menuoptions[4] = "return";
6944         menuoptionsactive[4] = true;
6945         nummenuoptions = 5;
6946         menuxoff = -40;
6947         menuyoff = 16;
6948     }
6949 	else if(t == "controller")
6950 	{
6951 		menuoptions[0] = "analog stick sensitivity";
6952 		menuoptionsactive[0] = true;
6953 		menuoptions[1] = "bind flip";
6954 		menuoptionsactive[1] = true;
6955 		menuoptions[2] = "bind enter";
6956 		menuoptionsactive[2] = true;
6957 		menuoptions[3] = "bind menu";
6958 		menuoptionsactive[3] = true;
6959 		menuoptions[4] = "return";
6960 		menuoptionsactive[4] = true;
6961 		nummenuoptions = 5;
6962 		menuxoff = -40;
6963 		menuyoff = 10;
6964 	}
6965     else if (t == "cleardatamenu")
6966     {
6967         menuoptions[0] = "no! don't delete";
6968         menuoptionsactive[0] = true;
6969         menuoptions[1] = "yes, delete everything";
6970         menuoptionsactive[1] = true;
6971         nummenuoptions = 2;
6972         menuxoff = -30;
6973         menuyoff = 64;
6974     }
6975     else if (t == "setinvincibility")
6976     {
6977         menuoptions[0] = "no, return to options";
6978         menuoptionsactive[0] = true;
6979         menuoptions[1] = "yes, enable";
6980         menuoptionsactive[1] = true;
6981         nummenuoptions = 2;
6982         menuxoff = -30;
6983         menuyoff = 64;
6984     }
6985     else if (t == "setslowdown1")
6986     {
6987         menuoptions[0] = "no, return to options";
6988         menuoptionsactive[0] = true;
6989         menuoptions[1] = "yes, delete saves";
6990         menuoptionsactive[1] = true;
6991         nummenuoptions = 2;
6992         menuxoff = -30;
6993         menuyoff = 64;
6994     }
6995     else if (t == "setslowdown2")
6996     {
6997         menuoptions[0] = "normal speed";
6998         menuoptionsactive[0] = true;
6999         menuoptions[1] = "80% speed";
7000         menuoptionsactive[1] = true;
7001         menuoptions[2] = "60% speed";
7002         menuoptionsactive[2] = true;
7003         menuoptions[3] = "40% speed";
7004         menuoptionsactive[3] = true;
7005         nummenuoptions = 4;
7006         menuxoff = -40;
7007         menuyoff = 16;
7008     }
7009     else if (t == "unlockmenu")
7010     {
7011         menuoptions[0] = "unlock time trials";
7012         menuoptionsactive[0] = true;
7013         menuoptions[1] = "unlock intermissions";
7014         menuoptionsactive[1] = !unlock[16];
7015         menuoptions[2] = "unlock no death mode";
7016         menuoptionsactive[2] = !unlock[17];
7017         menuoptions[3] = "unlock flip mode";
7018         menuoptionsactive[3] = !unlock[18];
7019         menuoptions[4] = "unlock ship jukebox";
7020         menuoptionsactive[4] = (stat_trinkets<20);
7021         menuoptions[5] = "unlock secret lab";
7022         menuoptionsactive[5] = !unlock[8];
7023         menuoptions[6] = "return";
7024         menuoptionsactive[6] = true;
7025         nummenuoptions = 7;
7026         menuxoff = -70;
7027         menuyoff = -20;
7028     }
7029     else if (t == "credits")
7030     {
7031         menuoptions[0] = "next page";
7032         menuoptionsactive[0] = true;
7033         menuoptions[1] = "return";
7034         menuoptionsactive[1] = true;
7035         nummenuoptions = 2;
7036         menuxoff = 20;
7037         menuyoff = 64;
7038     }
7039     else if (t == "credits2")
7040     {
7041         menuoptions[0] = "next page";
7042         menuoptionsactive[0] = true;
7043         menuoptions[1] = "return";
7044         menuoptionsactive[1] = true;
7045         nummenuoptions = 2;
7046         menuxoff = 20;
7047         menuyoff = 64;
7048     }
7049     else if (t == "credits25")
7050     {
7051         menuoptions[0] = "next page";
7052         menuoptionsactive[0] = true;
7053         menuoptions[1] = "return";
7054         menuoptionsactive[1] = true;
7055         nummenuoptions = 2;
7056         menuxoff = 20;
7057         menuyoff = 64;
7058     }
7059     else if (t == "credits3")
7060     {
7061         menuoptions[0] = "next page";
7062         menuoptionsactive[0] = true;
7063         menuoptions[1] = "return";
7064         menuoptionsactive[1] = true;
7065         nummenuoptions = 2;
7066         menuxoff = 20;
7067         menuyoff = 64;
7068     }
7069     else if (t == "credits4")
7070     {
7071         menuoptions[0] = "next page";
7072         menuoptionsactive[0] = true;
7073         menuoptions[1] = "return";
7074         menuoptionsactive[1] = true;
7075         nummenuoptions = 2;
7076         menuxoff = 20;
7077         menuyoff = 64;
7078     }
7079     else if (t == "credits5")
7080     {
7081         menuoptions[0] = "next page";
7082         menuoptionsactive[0] = true;
7083         menuoptions[1] = "return";
7084         menuoptionsactive[1] = true;
7085         nummenuoptions = 2;
7086         menuxoff = 20;
7087         menuyoff = 64;
7088     }
7089     else if (t == "credits6")
7090     {
7091         menuoptions[0] = "next page";
7092         menuoptionsactive[0] = true;
7093         menuoptions[1] = "return";
7094         menuoptionsactive[1] = true;
7095         nummenuoptions = 2;
7096         menuxoff = 20;
7097         menuyoff = 64;
7098     }
7099     else if (t == "credits7")
7100     {
7101         menuoptions[0] = "next page";
7102         menuoptionsactive[0] = true;
7103         menuoptions[1] = "return";
7104         menuoptionsactive[1] = true;
7105         nummenuoptions = 2;
7106         menuxoff = 20;
7107         menuyoff = 64;
7108     }
7109     else if (t == "credits8")
7110     {
7111         menuoptions[0] = "next page";
7112         menuoptionsactive[0] = true;
7113         menuoptions[1] = "return";
7114         menuoptionsactive[1] = true;
7115         nummenuoptions = 2;
7116         menuxoff = 20;
7117         menuyoff = 64;
7118     }
7119     else if (t == "credits9")
7120     {
7121         menuoptions[0] = "first page";
7122         menuoptionsactive[0] = true;
7123         menuoptions[1] = "return";
7124         menuoptionsactive[1] = true;
7125         nummenuoptions = 2;
7126         menuxoff = 20;
7127         menuyoff = 64;
7128     }
7129     else if (t == "play")
7130     {
7131         //Ok, here's where the unlock stuff comes into it:
7132         //First up, time trials:
7133         temp = 0;
7134         if (unlock[0] && stat_trinkets >= 3 && !unlocknotify[9]) temp++;
7135         if (unlock[1] && stat_trinkets >= 6 && !unlocknotify[10]) temp++;
7136         if (unlock[2] && stat_trinkets >= 9 && !unlocknotify[11]) temp++;
7137         if (unlock[3] && stat_trinkets >= 12 && !unlocknotify[12]) temp++;
7138         if (unlock[4] && stat_trinkets >= 15 && !unlocknotify[13]) temp++;
7139         if (unlock[5] && stat_trinkets >= 18 && !unlocknotify[14]) temp++;
7140         if (temp > 0)
7141         {
7142             //you've unlocked a time trial!
7143             if (unlock[0] && stat_trinkets >= 3)
7144             {
7145                 unlocknotify[9] = true;
7146                 unlock[9] = true;
7147             }
7148             if (unlock[1] && stat_trinkets >= 6)
7149             {
7150                 unlocknotify[10] = true;
7151                 unlock[10] = true;
7152             }
7153             if (unlock[2] && stat_trinkets >= 9)
7154             {
7155                 unlocknotify[11] = true;
7156                 unlock[11] = true;
7157             }
7158             if (unlock[3] && stat_trinkets >= 12)
7159             {
7160                 unlocknotify[12] = true;
7161                 unlock[12] = true;
7162             }
7163             if (unlock[4] && stat_trinkets >= 15)
7164             {
7165                 unlocknotify[13] = true;
7166                 unlock[13] = true;
7167             }
7168             if (unlock[5] && stat_trinkets >= 18)
7169             {
7170                 unlocknotify[14] = true;
7171                 unlock[14] = true;
7172             }
7173 
7174             if (temp == 1)
7175             {
7176                 createmenu("unlocktimetrial");
7177                 savemystats = true;
7178             }
7179             else if (temp > 1)
7180             {
7181                 createmenu("unlocktimetrials");
7182                 savemystats = true;
7183             }
7184         }
7185         else
7186         {
7187             //Alright, we haven't unlocked any time trials. How about no death mode?
7188             temp = 0;
7189             if (bestrank[0] >= 2) temp++;
7190             if (bestrank[1] >= 2) temp++;
7191             if (bestrank[2] >= 2) temp++;
7192             if (bestrank[3] >= 2) temp++;
7193             if (bestrank[4] >= 2) temp++;
7194             if (bestrank[5] >= 2) temp++;
7195             if (temp >= 4 && !unlocknotify[17])
7196             {
7197                 //Unlock No Death Mode
7198                 unlocknotify[17] = true;
7199                 unlock[17] = true;
7200                 createmenu("unlocknodeathmode");
7201                 savemystats = true;
7202             }
7203             else
7204             {
7205                 //Alright then! Flip mode?
7206                 if (unlock[5] && !unlocknotify[18])
7207                 {
7208                     unlock[18] = true;
7209                     unlocknotify[18] = true;
7210                     createmenu("unlockflipmode");
7211                     savemystats = true;
7212                 }
7213                 else
7214                 {
7215                     //What about the intermission levels?
7216                     if (unlock[7] && !unlocknotify[16])
7217                     {
7218                         unlock[16] = true;
7219                         unlocknotify[16] = true;
7220                         createmenu("unlockintermission");
7221                         savemystats = true;
7222                     }
7223                     else
7224                     {
7225                         //ok, secret lab! no notification, but test:
7226                         if (unlock[8])
7227                         {
7228                             createmenu("playsecretlab");
7229                         }
7230                         else
7231                         {
7232                             menuoptions[0] = "continue";
7233                             menuoptionsactive[0] = true;
7234                             menuoptions[1] = "play modes";
7235                             menuoptionsactive[1] = true;
7236                             menuoptions[2] = "new game";
7237                             menuoptionsactive[2] = true;
7238                             menuoptions[3] = "return";
7239                             menuoptionsactive[3] = true;
7240                             nummenuoptions = 4;
7241                             menuxoff = -20;
7242                             menuyoff = -40;
7243                         }
7244                     }
7245                 }
7246             }
7247         }
7248     }
7249     else if (t == "unlocktimetrial" || t == "unlocktimetrials")
7250     {
7251         menuoptions[0] = "continue";
7252         menuoptionsactive[0] = true;
7253         nummenuoptions = 1;
7254         menuxoff = 20;
7255         menuyoff = 70;
7256     }
7257     else if (t == "unlocknodeathmode")
7258     {
7259         menuoptions[0] = "continue";
7260         menuoptionsactive[0] = true;
7261         nummenuoptions = 1;
7262         menuxoff = 20;
7263         menuyoff = 70;
7264     }
7265     else if (t == "unlockintermission")
7266     {
7267         menuoptions[0] = "continue";
7268         menuoptionsactive[0] = true;
7269         nummenuoptions = 1;
7270         menuxoff = 20;
7271         menuyoff = 70;
7272     }
7273     else if (t == "unlockflipmode")
7274     {
7275         menuoptions[0] = "continue";
7276         menuoptionsactive[0] = true;
7277         nummenuoptions = 1;
7278         menuxoff = 20;
7279         menuyoff = 70;
7280     }
7281     else if (t == "playsecretlab")
7282     {
7283         menuoptions[0] = "continue";
7284         menuoptionsactive[0] = true;
7285         menuoptions[1] = "secret lab";
7286         menuoptionsactive[1] = true;
7287         menuoptions[2] = "play modes";
7288         menuoptionsactive[2] = true;
7289         menuoptions[3] = "new game";
7290         menuoptionsactive[3] = true;
7291         menuoptions[4] = "return";
7292         menuoptionsactive[4] = true;
7293         nummenuoptions = 5;
7294         menuxoff = -40;
7295         menuyoff = -30;
7296     }
7297     else if (t == "newgamewarning")
7298     {
7299         menuoptions[0] = "start new game";
7300         menuoptionsactive[0] = true;
7301         menuoptions[1] = "return to menu";
7302         menuoptionsactive[1] = true;
7303         nummenuoptions = 2;
7304         menuxoff = -30;
7305         menuyoff = 64;
7306     }
7307     else if (t == "playmodes")
7308     {
7309         menuoptions[0] = "time trials";
7310         menuoptionsactive[0] = true;
7311         menuoptions[1] = "intermissions";
7312         menuoptionsactive[1] = unlock[16];
7313         menuoptions[2] = "no death mode";
7314         menuoptionsactive[2] = unlock[17];
7315         menuoptions[3] = "flip mode";
7316         menuoptionsactive[3] = unlock[18];
7317         menuoptions[4] = "return to play menu";
7318         menuoptionsactive[4] = true;
7319         nummenuoptions = 5;
7320         menuxoff = -70;
7321         menuyoff = 8;
7322     }
7323     else if (t == "intermissionmenu")
7324     {
7325         menuoptions[0] = "play intermission 1";
7326         menuoptionsactive[0] = true;
7327         menuoptions[1] = "play intermission 2";
7328         menuoptionsactive[1] = true;
7329         menuoptions[2] = "return to play menu";
7330         menuoptionsactive[2] = true;
7331         nummenuoptions = 3;
7332         menuxoff = -50;
7333         menuyoff = -35;
7334     }
7335     else if (t == "playint1")
7336     {
7337         menuoptions[0] = "Vitellary";
7338         menuoptionsactive[0] = true;
7339         menuoptions[1] = "Vermilion";
7340         menuoptionsactive[1] = true;
7341         menuoptions[2] = "Verdigris";
7342         menuoptionsactive[2] = true;
7343         menuoptions[3] = "Victoria";
7344         menuoptionsactive[3] = true;
7345         menuoptions[4] = "return";
7346         menuoptionsactive[4] = true;
7347         nummenuoptions = 5;
7348         menuxoff = -60;
7349         menuyoff = 10;
7350     }
7351     else if (t == "playint2")
7352     {
7353         menuoptions[0] = "Vitellary";
7354         menuoptionsactive[0] = true;
7355         menuoptions[1] = "Vermilion";
7356         menuoptionsactive[1] = true;
7357         menuoptions[2] = "Verdigris";
7358         menuoptionsactive[2] = true;
7359         menuoptions[3] = "Victoria";
7360         menuoptionsactive[3] = true;
7361         menuoptions[4] = "return";
7362         menuoptionsactive[4] = true;
7363         nummenuoptions = 5;
7364         menuxoff = -60;
7365         menuyoff = 10;
7366     }
7367     else if (t == "continue")
7368     {
7369         menuoptions[0] = "continue from teleporter";
7370         menuoptionsactive[0] = true;
7371         menuoptions[1] = "continue from quicksave";
7372         menuoptionsactive[1] = true;
7373         menuoptions[2] = "return to play menu";
7374         menuoptionsactive[2] = true;
7375         nummenuoptions = 3;
7376         menuxoff = -60;
7377         menuyoff = 20;
7378     }
7379     else if (t == "startnodeathmode")
7380     {
7381         menuoptions[0] = "disable cutscenes";
7382         menuoptionsactive[0] = true;
7383         menuoptions[1] = "enable cutscenes";
7384         menuoptionsactive[1] = true;
7385         menuoptions[2] = "return to play menu";
7386         menuoptionsactive[2] = true;
7387         nummenuoptions = 3;
7388         menuxoff = -60;
7389         menuyoff = 40;
7390     }
7391     else if (t == "gameover")
7392     {
7393         nummenuoptions = 0;
7394         menucountdown = 120;
7395         menudest="gameover2";
7396     }
7397     else if (t == "gameover2")
7398     {
7399         menuoptions[0] = "return to play menu";
7400         menuoptionsactive[0] = true;
7401         nummenuoptions = 1;
7402         menuxoff = -25;
7403         menuyoff = 80;
7404     }
7405     else if (t == "unlockmenutrials")
7406     {
7407         if (unlock[9])
7408         {
7409             menuoptions[0] = "space station 1";
7410             menuoptionsactive[0] = false;
7411         }
7412         else
7413         {
7414             menuoptions[0] = "space station 1";
7415             menuoptionsactive[0] = true;
7416         }
7417         if (unlock[10])
7418         {
7419             menuoptions[1] = "the laboratory";
7420             menuoptionsactive[1] = false;
7421         }
7422         else
7423         {
7424             menuoptions[1] = "the laboratory";
7425             menuoptionsactive[1] = true;
7426         }
7427         if (unlock[11])
7428         {
7429             menuoptions[2] = "the tower";
7430             menuoptionsactive[2] = false;
7431         }
7432         else
7433         {
7434             menuoptions[2] = "the tower";
7435             menuoptionsactive[2] = true;
7436         }
7437         if (unlock[12])
7438         {
7439             menuoptions[3] = "space station 2";
7440             menuoptionsactive[3] = false;
7441         }
7442         else
7443         {
7444             menuoptions[3] = "space station 2";
7445             menuoptionsactive[3] = true;
7446         }
7447         if (unlock[13])
7448         {
7449             menuoptions[4] = "the warp zone";
7450             menuoptionsactive[4] = false;
7451         }
7452         else
7453         {
7454             menuoptions[4] = "the warp zone";
7455             menuoptionsactive[4] = true;
7456         }
7457         if (unlock[14])
7458         {
7459             menuoptions[5] = "the final level";
7460             menuoptionsactive[5] = false;
7461         }
7462         else
7463         {
7464             menuoptions[5] = "the final level";
7465             menuoptionsactive[5] = true;
7466         }
7467 
7468         menuoptions[6] = "return to unlock menu";
7469         menuoptionsactive[6] = true;
7470         nummenuoptions = 7;
7471         menuxoff = -80;
7472         menuyoff = 0;
7473     }
7474     else if (t == "timetrials")
7475     {
7476         if (!unlock[9])
7477         {
7478             menuoptions[0] = "???";
7479             menuoptionsactive[0] = false;
7480         }
7481         else
7482         {
7483             menuoptions[0] = "space station 1";
7484             menuoptionsactive[0] = true;
7485         }
7486         if (!unlock[10])
7487         {
7488             menuoptions[1] = "???";
7489             menuoptionsactive[1] = false;
7490         }
7491         else
7492         {
7493             menuoptions[1] = "the laboratory";
7494             menuoptionsactive[1] = true;
7495         }
7496         if (!unlock[11])
7497         {
7498             menuoptions[2] = "???";
7499             menuoptionsactive[2] = false;
7500         }
7501         else
7502         {
7503             menuoptions[2] = "the tower";
7504             menuoptionsactive[2] = true;
7505         }
7506         if (!unlock[12])
7507         {
7508             menuoptions[3] = "???";
7509             menuoptionsactive[3] = false;
7510         }
7511         else
7512         {
7513             menuoptions[3] = "space station 2";
7514             menuoptionsactive[3] = true;
7515         }
7516         if (!unlock[13])
7517         {
7518             menuoptions[4] = "???";
7519             menuoptionsactive[4] = false;
7520         }
7521         else
7522         {
7523             menuoptions[4] = "the warp zone";
7524             menuoptionsactive[4] = true;
7525         }
7526         if (!unlock[14])
7527         {
7528             menuoptions[5] = "???";
7529             menuoptionsactive[5] = false;
7530         }
7531         else
7532         {
7533             menuoptions[5] = "the final level";
7534             menuoptionsactive[5] = true;
7535         }
7536 
7537         menuoptions[6] = "return to play menu";
7538         menuoptionsactive[6] = true;
7539         nummenuoptions = 7;
7540         menuxoff = -80;
7541         menuyoff = 0;
7542     }
7543     else if (t == "nodeathmodecomplete")
7544     {
7545         nummenuoptions = 0;
7546         menucountdown = 90;
7547         menudest = "nodeathmodecomplete2";
7548     }
7549     else if (t == "nodeathmodecomplete2")
7550     {
7551         menuoptions[0] = "return to play menu";
7552         menuoptionsactive[0] = true;
7553         nummenuoptions = 1;
7554         menuxoff = -25;
7555         menuyoff = 70;
7556     }
7557     else if (t == "timetrialcomplete")
7558     {
7559         nummenuoptions = 0;
7560         menucountdown = 90;
7561         menudest="timetrialcomplete2";
7562     }
7563     else if (t == "timetrialcomplete2")
7564     {
7565         nummenuoptions = 0;
7566         menucountdown = 60;
7567         menudest="timetrialcomplete3";
7568     }
7569     else if (t == "timetrialcomplete3")
7570     {
7571         menuoptions[0] = "return to play menu";
7572         menuoptionsactive[0] = true;
7573         menuoptions[1] = "try again";
7574         menuoptionsactive[1] = true;
7575         nummenuoptions = 2;
7576         menuxoff = -25;
7577         menuyoff = 70;
7578     }
7579     else if (t == "gamecompletecontinue")
7580     {
7581         menuoptions[0] = "return to play menu";
7582         menuoptionsactive[0] = true;
7583         nummenuoptions = 1;
7584         menuxoff = -25;
7585         menuyoff = 70;
7586     }
7587 }
7588 
deletequick()7589 void Game::deletequick()
7590 {
7591     if( remove( "qsave.vvv" ) != 0 )
7592         printf("Error deleting file\n");
7593 
7594     quicksummary = "";
7595     quickcookieexists = false;
7596 }
7597 
deletetele()7598 void Game::deletetele()
7599 {
7600     if( remove( "tsave.vvv" ) != 0 )
7601         printf("Error deleting file\n");
7602 
7603     telesummary = "";
7604     telecookieexists = false;
7605 }
7606 
swnpenalty()7607 void Game::swnpenalty()
7608 {
7609     //set the SWN clock back to the closest 5 second interval
7610     if (swntimer <= 150)
7611     {
7612         swntimer += 8;
7613         if (swntimer > 150) swntimer = 150;
7614     }
7615     else if (swntimer <= 300)
7616     {
7617         swntimer += 8;
7618         if (swntimer > 300) swntimer = 300;
7619     }
7620     else if (swntimer <= 450)
7621     {
7622         swntimer += 8;
7623         if (swntimer > 450) swntimer = 450;
7624     }
7625     else if (swntimer <= 600)
7626     {
7627         swntimer += 8;
7628         if (swntimer > 600) swntimer = 600;
7629     }
7630     else if (swntimer <= 750)
7631     {
7632         swntimer += 8;
7633         if (swntimer > 750) swntimer = 750;
7634     }
7635     else if (swntimer <= 900)
7636     {
7637         swntimer += 8;
7638         if (swntimer > 900) swntimer = 900;
7639     }
7640     else if (swntimer <= 1050)
7641     {
7642         swntimer += 8;
7643         if (swntimer > 1050) swntimer = 1050;
7644     }
7645     else if (swntimer <= 1200)
7646     {
7647         swntimer += 8;
7648         if (swntimer > 1200) swntimer = 1200;
7649     }
7650     else if (swntimer <= 1350)
7651     {
7652         swntimer += 8;
7653         if (swntimer > 1350) swntimer = 1350;
7654     }
7655     else if (swntimer <= 1500)
7656     {
7657         swntimer += 8;
7658         if (swntimer > 1500) swntimer = 1500;
7659     }
7660     else if (swntimer <= 1650)
7661     {
7662         swntimer += 8;
7663         if (swntimer > 1650) swntimer = 1650;
7664     }
7665     else if (swntimer <= 1800)
7666     {
7667         swntimer += 8;
7668         if (swntimer > 1800) swntimer = 1800;
7669     }
7670     else if (swntimer <= 2100)
7671     {
7672         swntimer += 8;
7673         if (swntimer > 2100) swntimer = 2100;
7674     }
7675     else if (swntimer <= 2400)
7676     {
7677         swntimer += 8;
7678         if (swntimer > 2400) swntimer = 2400;
7679     }
7680 }
7681 
crewrescued()7682 int Game::crewrescued()
7683 {
7684     int temp = 0;
7685     if (crewstats[0])
7686         temp++;
7687     if (crewstats[1])
7688         temp++;
7689     if (crewstats[2])
7690         temp++;
7691     if (crewstats[3])
7692         temp++;
7693     if (crewstats[4])
7694         temp++;
7695     if (crewstats[5])
7696         temp++;
7697     return temp;
7698 }
7699 
resetgameclock()7700 void Game::resetgameclock()
7701 {
7702     frames = 0;
7703     seconds = 0;
7704     minutes = 0;
7705     hours = 0;
7706     timerStartTime = SDL_GetTicks();
7707 }
7708