Source/GameTick.cpp
author Neal Gompa (ニール・ゴンパ) <ngompa13@gmail.com>
Sun, 16 May 2010 15:41:05 -0500
changeset 275 97b303e79826
parent 272 385e7e158813
permissions -rw-r--r--
Removing plain makefiles -- Deprecated in favor of CMake generated makefiles, which now work on all major platforms
     1 /*
     2 Copyright (C) 2003, 2010 - Wolfire Games
     3 
     4 This file is part of Lugaru.
     5 
     6 Lugaru is free software; you can redistribute it and/or
     7 modify it under the terms of the GNU General Public License
     8 as published by the Free Software Foundation; either version 2
     9 of the License, or (at your option) any later version.
    10 
    11 This program is distributed in the hope that it will be useful,
    12 but WITHOUT ANY WARRANTY; without even the implied warranty of
    13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    14 
    15 See the GNU General Public License for more details.
    16 
    17 You should have received a copy of the GNU General Public License
    18 along with this program; if not, write to the Free Software
    19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    20 */
    21 
    22 #if PLATFORM_UNIX
    23 #include <sys/stat.h>
    24 #include <sys/types.h>
    25 #include <unistd.h>
    26 #else
    27 #include <direct.h>
    28 #endif
    29 
    30 #include <ctime>
    31 #include "Game.h"
    32 #include "openal_wrapper.h"
    33 
    34 using namespace std;
    35 
    36 extern float multiplier;
    37 extern XYZ viewer;
    38 extern int environment;
    39 extern float texscale;
    40 extern Terrain terrain;
    41 extern OPENAL_SAMPLE	*samp[100];
    42 extern int channels[100];
    43 extern Sprites sprites;
    44 extern int kTextureSize;
    45 extern float screenwidth,screenheight;
    46 extern float gravity;
    47 extern int detail;
    48 extern float texdetail;
    49 extern Objects objects;
    50 extern int slomo;
    51 extern float slomodelay;
    52 extern bool floatjump;
    53 extern float volume;
    54 extern Animation animation[animation_count];
    55 extern Light light;
    56 extern float texdetail;
    57 extern GLubyte bloodText[512*512*3];
    58 extern GLubyte wolfbloodText[512*512*3];
    59 extern float terraindetail;
    60 extern float camerashake;
    61 extern float woozy;
    62 extern float blackout;
    63 extern bool cellophane;
    64 extern bool musictoggle;
    65 extern int difficulty;
    66 extern Weapons weapons;
    67 extern Person player[maxplayers];
    68 extern int numplayers;
    69 extern int bloodtoggle;
    70 extern bool invertmouse;
    71 extern float windvar;
    72 extern float precipdelay;
    73 extern XYZ viewerfacing;
    74 extern bool ambientsound;
    75 extern bool mousejump;
    76 extern float viewdistance;
    77 extern bool freeze;
    78 extern bool autoslomo;
    79 extern bool keyboardfrozen;
    80 extern int netdatanew;
    81 extern bool loadingstuff;
    82 extern char mapname[256];
    83 extern XYZ windvector;
    84 extern bool buttons[3];
    85 extern bool debugmode;
    86 static int music1;
    87 extern int mainmenu;
    88 extern int oldmainmenu;
    89 extern bool visibleloading;
    90 extern int loadscreencolor;
    91 extern float flashamount,flashr,flashg,flashb;
    92 extern int flashdelay;
    93 extern XYZ envsound[30];
    94 extern float envsoundvol[30];
    95 extern int numenvsounds;
    96 extern float envsoundlife[30];
    97 extern float usermousesensitivity;
    98 extern bool ismotionblur;
    99 extern bool foliage;
   100 extern bool trilinear;
   101 extern bool damageeffects;
   102 extern bool showpoints;
   103 extern bool texttoggle;
   104 extern bool alwaysblur;
   105 extern float gamespeed;
   106 extern bool decals;
   107 extern bool vblsync;
   108 extern bool immediate;
   109 extern bool velocityblur;
   110 extern int bonus;
   111 extern int oldbonus;
   112 extern float bonusvalue;
   113 extern float bonustotal;
   114 extern float bonustime;
   115 extern float startbonustotal;
   116 extern float tintr,tintg,tintb;
   117 extern float bonusnum[100];
   118 extern bool skyboxtexture;
   119 extern float skyboxr;
   120 extern float skyboxg;
   121 extern float skyboxb;
   122 extern float skyboxlightr;
   123 extern float skyboxlightg;
   124 extern float skyboxlightb;
   125 extern float fadestart;
   126 extern float slomospeed;
   127 extern float slomofreq;
   128 extern int tutoriallevel;
   129 extern float smoketex;
   130 extern float tutorialstagetime;
   131 extern int tutorialstage;
   132 extern float tutorialmaxtime;
   133 extern float tutorialsuccess;
   134 extern bool againbonus;
   135 extern bool reversaltrain;
   136 extern bool canattack;
   137 extern bool cananger;
   138 extern float damagedealt;
   139 extern float damagetaken;
   140 extern int maptype;
   141 extern int editoractive;
   142 extern int editorpathtype;
   143 extern bool oldbuttons[3];
   144 
   145 extern float hostiletime;
   146 
   147 extern bool gamestarted;
   148 
   149 extern int numhotspots;
   150 extern int winhotspot;
   151 extern int windialogue;
   152 extern int killhotspot;
   153 extern XYZ hotspot[40];
   154 extern int hotspottype[40];
   155 extern float hotspotsize[40];
   156 extern char hotspottext[40][256];
   157 extern int currenthotspot;
   158 
   159 extern int kBitsPerPixel;
   160 extern int hostile;
   161 
   162 extern int numaccounts;
   163 extern int accountactive;
   164 extern int accountdifficulty[10];
   165 extern int accountprogress[10];
   166 extern float accountpoints[10];
   167 extern float accounthighscore[10][50];
   168 extern float accountfasttime[10][50];
   169 extern bool accountunlocked[10][60];
   170 extern char accountname[10][256];
   171 
   172 extern bool stillloading;
   173 extern bool winfreeze;
   174 
   175 extern int numfalls;
   176 extern int numflipfail;
   177 extern int numseen;
   178 extern int numstaffattack;
   179 extern int numswordattack;
   180 extern int numknifeattack;
   181 extern int numunarmedattack;
   182 extern int numescaped;
   183 extern int numflipped;
   184 extern int numwallflipped;
   185 extern int numthrowkill;
   186 extern int numafterkill;
   187 extern int numreversals;
   188 extern int numattacks;
   189 extern int maxalarmed;
   190 extern int numresponded;
   191 
   192 extern int numdialogues;
   193 extern int numdialogueboxes[max_dialogues];
   194 extern int dialoguetype[max_dialogues];
   195 extern int dialogueboxlocation[max_dialogues][max_dialoguelength];
   196 extern float dialogueboxcolor[max_dialogues][max_dialoguelength][3];
   197 extern int dialogueboxsound[max_dialogues][max_dialoguelength];
   198 extern char dialoguetext[max_dialogues][max_dialoguelength][128];
   199 extern char dialoguename[max_dialogues][max_dialoguelength][64];
   200 extern XYZ dialoguecamera[max_dialogues][max_dialoguelength];
   201 extern XYZ participantlocation[max_dialogues][10];
   202 extern int participantfocus[max_dialogues][max_dialoguelength];
   203 extern int participantaction[max_dialogues][max_dialoguelength];
   204 extern float participantrotation[max_dialogues][10];
   205 extern XYZ participantfacing[max_dialogues][max_dialoguelength][10];
   206 extern float dialoguecamerarotation[max_dialogues][max_dialoguelength];
   207 extern float dialoguecamerarotation2[max_dialogues][max_dialoguelength];
   208 extern int indialogue;
   209 extern int whichdialogue;
   210 extern int directing;
   211 extern float dialoguetime;
   212 extern int dialoguegonethrough[20];
   213 
   214 extern bool campaign;
   215 
   216 extern float oldgamespeed;
   217 
   218 extern float accountcampaignhighscore[10];
   219 extern float accountcampaignfasttime[10];
   220 extern float accountcampaignscore[10];
   221 extern float accountcampaigntime[10];
   222 
   223 extern int accountcampaignchoicesmade[10];
   224 extern int accountcampaignchoices[10][5000];
   225 
   226 static const char *rabbitskin[] = {
   227 ":Data:Textures:Fur3.jpg",
   228 ":Data:Textures:Fur.jpg",
   229 ":Data:Textures:Fur2.jpg",
   230 ":Data:Textures:Lynx.jpg",
   231 ":Data:Textures:Otter.jpg",
   232 ":Data:Textures:Opal.jpg",
   233 ":Data:Textures:Sable.jpg",
   234 ":Data:Textures:Chocolate.jpg",
   235 ":Data:Textures:BW2.jpg",
   236 ":Data:Textures:WB2.jpg"
   237 };
   238 
   239 static const char *wolfskin[] = {
   240 ":Data:Textures:Wolf.jpg",
   241 ":Data:Textures:Darkwolf.jpg",
   242 ":Data:Textures:Snowwolf.jpg"
   243 };
   244 
   245 #define STATIC_ASSERT(x) extern int s_a_dummy[2 * (!!(x)) - 1];
   246 STATIC_ASSERT (rabbittype == 0 && wolftype == 1)
   247 
   248 static const char **creatureskin[] = {rabbitskin, wolfskin};
   249 
   250 /* Return true if PFX is a prefix of STR (case-insensitive).  */
   251 static bool stripfx(const char *str, const char *pfx)
   252 {
   253   return !strncasecmp(str, pfx, strlen(pfx));
   254 }
   255 
   256 extern OPENAL_STREAM * strm[20];
   257 extern "C"	void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
   258 extern "C" void PlayStreamEx(int chan, OPENAL_STREAM *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
   259 
   260 
   261 static const char *cmd_names[] = {
   262 #define DECLARE_COMMAND(cmd) #cmd " ",
   263 #include "ConsoleCmds.h"
   264 #undef  DECLARE_COMMAND
   265 };
   266 
   267 typedef void (*console_handler)(Game *game, const char *args);
   268 
   269 #define DECLARE_COMMAND(cmd) static void ch_##cmd(Game *game, const char *args);
   270 #include "ConsoleCmds.h"
   271 #undef  DECLARE_COMMAND
   272 
   273 static console_handler cmd_handlers[] = {
   274 #define DECLARE_COMMAND(cmd) ch_##cmd,
   275 #include "ConsoleCmds.h"
   276 #undef  DECLARE_COMMAND
   277 };
   278 
   279 static void ch_quit(Game *game, const char *args)
   280 {
   281   game->tryquit = 1;
   282 }
   283 
   284 static void ch_map(Game *game, const char *args)
   285 {
   286   char buf[64];
   287   snprintf(buf, 63, ":Data:Maps:%s", args);
   288   game->Loadlevel(buf);
   289   game->whichlevel = -2;
   290   campaign = 0;
   291 }
   292 
   293 static void ch_save(Game *game, const char *args)
   294 {
   295   char buf[64];
   296   int i, j, k, l, m, templength;
   297   float headprop, bodyprop, armprop, legprop;
   298   snprintf(buf, 63, ":Data:Maps:%s", args);
   299 
   300 
   301   int mapvers = 12;;
   302 
   303   FILE			*tfile;
   304   tfile=fopen( ConvertFileName(buf), "wb" );
   305   fpackf(tfile, "Bi", mapvers);
   306   fpackf(tfile, "Bi", maptype);
   307   fpackf(tfile, "Bi", hostile);
   308   fpackf(tfile, "Bf Bf", viewdistance, fadestart);
   309   fpackf(tfile, "Bb Bf Bf Bf", skyboxtexture, skyboxr, skyboxg, skyboxb);
   310   fpackf(tfile, "Bf Bf Bf", skyboxlightr, skyboxlightg, skyboxlightb);
   311   fpackf(tfile, "Bf Bf Bf Bf Bf Bi", player[0].coords.x, player[0].coords.y, player[0].coords.z, player[0].rotation, player[0].targetrotation, player[0].num_weapons);
   312   if(player[0].num_weapons>0&&player[0].num_weapons<5)
   313     for(j=0;j<player[0].num_weapons;j++){
   314       fpackf(tfile, "Bi", weapons.type[player[0].weaponids[j]]);
   315     }
   316 
   317   fpackf(tfile, "Bf Bf Bf", player[0].armorhead, player[0].armorhigh, player[0].armorlow);
   318   fpackf(tfile, "Bf Bf Bf", player[0].protectionhead, player[0].protectionhigh, player[0].protectionlow);
   319   fpackf(tfile, "Bf Bf Bf", player[0].metalhead, player[0].metalhigh, player[0].metallow);
   320   fpackf(tfile, "Bf Bf", player[0].power, player[0].speedmult);
   321 
   322   fpackf(tfile, "Bi", player[0].numclothes);
   323 
   324   fpackf(tfile, "Bi Bi", player[0].whichskin, player[0].creature);
   325 
   326   fpackf(tfile, "Bi", numdialogues);
   327   if(numdialogues)
   328     for(k=0;k<numdialogues;k++){
   329       fpackf(tfile, "Bi", numdialogueboxes[k]);
   330       fpackf(tfile, "Bi", dialoguetype[k]);
   331       for(l=0;l<10;l++){
   332 	fpackf(tfile, "Bf Bf Bf", participantlocation[k][l].x, participantlocation[k][l].y, participantlocation[k][l].z);
   333 	fpackf(tfile, "Bf", participantrotation[k][l]);
   334       }
   335       if(numdialogueboxes)
   336 	for(l=0;l<numdialogueboxes[k];l++){
   337 	  fpackf(tfile, "Bi", dialogueboxlocation[k][l]);
   338 	  fpackf(tfile, "Bf", dialogueboxcolor[k][l][0]);
   339 	  fpackf(tfile, "Bf", dialogueboxcolor[k][l][1]);
   340 	  fpackf(tfile, "Bf", dialogueboxcolor[k][l][2]);
   341 	  fpackf(tfile, "Bi", dialogueboxsound[k][l]);
   342 
   343 	  templength=strlen(dialoguetext[k][l]);
   344 	  fpackf(tfile, "Bi",(templength));
   345 	  for(m=0;m<templength;m++){
   346 	    fpackf(tfile, "Bb", dialoguetext[k][l][m]);
   347 	    if(dialoguetext[k][l][m]=='\0')break;
   348 	  }
   349 
   350 	  templength=strlen(dialoguename[k][l]);
   351 	  fpackf(tfile, "Bi",templength);
   352 	  for(m=0;m<templength;m++){
   353 	    fpackf(tfile, "Bb", dialoguename[k][l][m]);
   354 	    if(dialoguename[k][l][m]=='\0')break;
   355 	  }
   356 
   357 	  fpackf(tfile, "Bf Bf Bf", dialoguecamera[k][l].x, dialoguecamera[k][l].y, dialoguecamera[k][l].z);
   358 	  fpackf(tfile, "Bi", participantfocus[k][l]);
   359 	  fpackf(tfile, "Bi", participantaction[k][l]);
   360 
   361 	  for(m=0;m<10;m++)
   362 	    fpackf(tfile, "Bf Bf Bf", participantfacing[k][l][m].x, participantfacing[k][l][m].y, participantfacing[k][l][m].z);
   363 
   364 	  fpackf(tfile, "Bf Bf",dialoguecamerarotation[k][l],dialoguecamerarotation2[k][l]);
   365 	}
   366     }
   367 
   368   if(player[0].numclothes)
   369     for(k=0;k<player[0].numclothes;k++){
   370       templength=strlen(player[0].clothes[k]);
   371       fpackf(tfile, "Bi", templength);
   372       for(l=0;l<templength;l++)
   373 	fpackf(tfile, "Bb", player[0].clothes[k][l]);
   374       fpackf(tfile, "Bf Bf Bf", player[0].clothestintr[k], player[0].clothestintg[k], player[0].clothestintb[k]);
   375     }
   376 
   377   fpackf(tfile, "Bi", environment);
   378 
   379   fpackf(tfile, "Bi", objects.numobjects);
   380 
   381   if(objects.numobjects)
   382     for(k=0;k<objects.numobjects;k++){
   383       fpackf(tfile, "Bi Bf Bf Bf Bf Bf Bf", objects.type[k], objects.rotation[k], objects.rotation2[k], objects.position[k].x, objects.position[k].y, objects.position[k].z, objects.scale[k]);
   384     }
   385 
   386   fpackf(tfile, "Bi", numhotspots);
   387   if(numhotspots)
   388     for(i=0;i<numhotspots;i++){
   389       fpackf(tfile, "Bi Bf Bf Bf Bf", hotspottype[i],hotspotsize[i],hotspot[i].x,hotspot[i].y,hotspot[i].z);
   390       templength=strlen(hotspottext[i]);
   391       fpackf(tfile, "Bi",templength);
   392       for(l=0;l<templength;l++)
   393 	fpackf(tfile, "Bb", hotspottext[i][l]);
   394     }
   395 
   396   fpackf(tfile, "Bi", numplayers);
   397   if(numplayers>1&&numplayers<maxplayers)
   398     for(j=1;j<numplayers;j++){
   399       fpackf(tfile, "Bi Bi Bf Bf Bf Bi Bi Bf Bb Bf", player[j].whichskin, player[j].creature, player[j].coords.x, player[j].coords.y, player[j].coords.z, player[j].num_weapons, player[j].howactive, player[j].scale, player[j].immobile, player[j].rotation);
   400       if(player[j].num_weapons>0&&player[j].num_weapons<5)
   401 	for(k=0;k<player[j].num_weapons;k++){
   402 	  fpackf(tfile, "Bi", weapons.type[player[j].weaponids[k]]);
   403 	}
   404       if(player[j].numwaypoints<30){
   405 	fpackf(tfile, "Bi", player[j].numwaypoints);
   406 	for(k=0;k<player[j].numwaypoints;k++){
   407 	  fpackf(tfile, "Bf", player[j].waypoints[k].x);
   408 	  fpackf(tfile, "Bf", player[j].waypoints[k].y);
   409 	  fpackf(tfile, "Bf", player[j].waypoints[k].z);
   410 	  fpackf(tfile, "Bi", player[j].waypointtype[k]);
   411 	}
   412 	fpackf(tfile, "Bi", player[j].waypoint);
   413       }
   414       else{
   415 	player[j].numwaypoints=0;
   416 	player[j].waypoint=0;
   417 	fpackf(tfile, "Bi Bi Bi", player[j].numwaypoints, player[j].waypoint, player[j].waypoint);
   418       }
   419 
   420       fpackf(tfile, "Bf Bf Bf", player[j].armorhead, player[j].armorhigh, player[j].armorlow);
   421       fpackf(tfile, "Bf Bf Bf", player[j].protectionhead, player[j].protectionhigh, player[j].protectionlow);
   422       fpackf(tfile, "Bf Bf Bf", player[j].metalhead, player[j].metalhigh, player[j].metallow);
   423       fpackf(tfile, "Bf Bf", player[j].power, player[j].speedmult);
   424 
   425       if(player[j].creature==wolftype){
   426 	headprop=player[j].proportionhead.x/1.1;
   427 	bodyprop=player[j].proportionbody.x/1.1;
   428 	armprop=player[j].proportionarms.x/1.1;
   429 	legprop=player[j].proportionlegs.x/1.1;
   430       }
   431 
   432       if(player[j].creature==rabbittype){
   433 	headprop=player[j].proportionhead.x/1.2;
   434 	bodyprop=player[j].proportionbody.x/1.05;
   435 	armprop=player[j].proportionarms.x/1.00;
   436 	legprop=player[j].proportionlegs.x/1.1;
   437       }
   438 
   439       fpackf(tfile, "Bf Bf Bf Bf", headprop, bodyprop, armprop, legprop);
   440 
   441 
   442 
   443       fpackf(tfile, "Bi", player[j].numclothes);
   444       if(player[j].numclothes)
   445 	for(k=0;k<player[j].numclothes;k++){
   446 	  int templength;
   447 	  templength=strlen(player[j].clothes[k]);
   448 	  fpackf(tfile, "Bi", templength);
   449 	  for(l=0;l<templength;l++)
   450 	    fpackf(tfile, "Bb", player[j].clothes[k][l]);
   451 	  fpackf(tfile, "Bf Bf Bf", player[j].clothestintr[k], player[j].clothestintg[k], player[j].clothestintb[k]);
   452 	}
   453     }
   454 
   455   fpackf(tfile, "Bi", game->numpathpoints);
   456   if(game->numpathpoints)
   457     for(j=0;j<game->numpathpoints;j++){
   458       fpackf(tfile, "Bf Bf Bf Bi", game->pathpoint[j].x, game->pathpoint[j].y, game->pathpoint[j].z, game->numpathpointconnect[j]);
   459       for(k=0;k<game->numpathpointconnect[j];k++){
   460 	fpackf(tfile, "Bi", game->pathpointconnect[j][k]);
   461       }
   462     }
   463 
   464   fpackf(tfile, "Bf Bf Bf Bf", game->mapcenter.x, game->mapcenter.y, game->mapcenter.z, game->mapradius);
   465 
   466   fclose(tfile);
   467 }
   468 
   469 static void ch_cellar(Game *game, const char *args)
   470 {
   471   game->LoadTextureSave(":Data:Textures:Furdarko.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
   472 }
   473 
   474 static void ch_tint(Game *game, const char *args)
   475 {
   476   sscanf(args, "%f%f%f", &tintr, &tintg, &tintb);
   477 }
   478 
   479 static void ch_tintr(Game *game, const char *args)
   480 {
   481   tintr = atof(args);
   482 }
   483 
   484 static void ch_tintg(Game *game, const char *args)
   485 {
   486   tintg = atof(args);
   487 }
   488 
   489 static void ch_tintb(Game *game, const char *args)
   490 {
   491   tintb = atof(args);
   492 }
   493 
   494 static void ch_speed(Game *game, const char *args)
   495 {
   496   player[0].speedmult = atof(args);
   497 }
   498 
   499 static void ch_strength(Game *game, const char *args)
   500 {
   501   player[0].power = atof(args);
   502 }
   503 
   504 static void ch_power(Game *game, const char *args)
   505 {
   506   player[0].power = atof(args);
   507 }
   508 
   509 static void ch_size(Game *game, const char *args)
   510 {
   511   player[0].scale = atof(args) * .2;
   512 }
   513 
   514 static int find_closest()
   515 {
   516   int closest = 0;
   517   float closestdist = 1.0/0.0;
   518 
   519   for (int i = 1; i < numplayers; i++) {
   520     float distance;
   521     distance = findDistancefast(&player[i].coords,&player[0].coords);
   522     if (distance < closestdist) {
   523       closestdist = distance;
   524       closest = i;
   525     }
   526   }
   527   return closest;
   528 }
   529 
   530 static void ch_sizenear(Game *game, const char *args)
   531 {
   532   int closest = find_closest();
   533 
   534   if (closest)
   535     player[closest].scale = atof(args) * .2;
   536 }
   537 
   538 static void set_proportion(int pnum, const char *args)
   539 {
   540   float headprop,bodyprop,armprop,legprop;
   541 
   542   sscanf(args, "%f%f%f%f", &headprop, &bodyprop, &armprop, &legprop);
   543 
   544   if(player[pnum].creature==wolftype){
   545     player[pnum].proportionhead=1.1*headprop;
   546     player[pnum].proportionbody=1.1*bodyprop;
   547     player[pnum].proportionarms=1.1*armprop;
   548     player[pnum].proportionlegs=1.1*legprop;
   549   }
   550 
   551   if(player[pnum].creature==rabbittype){
   552     player[pnum].proportionhead=1.2*headprop;
   553     player[pnum].proportionbody=1.05*bodyprop;
   554     player[pnum].proportionarms=1.00*armprop;
   555     player[pnum].proportionlegs=1.1*legprop;
   556     player[pnum].proportionlegs.y=1.05*legprop;
   557   }
   558 }
   559 
   560 static void ch_proportion(Game *game, const char *args)
   561 {
   562   set_proportion(0, args);
   563 }
   564 
   565 static void ch_proportionnear(Game *game, const char *args)
   566 {
   567   int closest = find_closest();
   568   if (closest)
   569     set_proportion(closest, args);
   570 }
   571 
   572 static void set_protection(int pnum, const char *args)
   573 {
   574   float head, high, low;
   575   sscanf(args, "%f%f%f", &head, &high, &low);
   576 
   577   player[pnum].protectionhead = head;
   578   player[pnum].protectionhigh = high;
   579   player[pnum].protectionlow  = low;
   580 }
   581 
   582 static void ch_protection(Game *game, const char *args)
   583 {
   584   set_protection(0, args);
   585 }
   586 
   587 static void ch_protectionnear(Game *game, const char *args)
   588 {
   589   int closest = find_closest();
   590   if (closest)
   591     set_protection(closest, args);
   592 }
   593 
   594 static void set_armor(int pnum, const char *args)
   595 {
   596   float head, high, low;
   597   sscanf(args, "%f%f%f", &head, &high, &low);
   598 
   599   player[pnum].armorhead = head;
   600   player[pnum].armorhigh = high;
   601   player[pnum].armorlow  = low;
   602 }
   603 
   604 static void ch_armor(Game *game, const char *args)
   605 {
   606   set_armor(0, args);
   607 }
   608 
   609 static void ch_armornear(Game *game, const char *args)
   610 {
   611   int closest = find_closest();
   612   if (closest)
   613     set_armor(closest, args);
   614 }
   615 
   616 static void ch_protectionreset(Game *game, const char *args)
   617 {
   618   set_protection(0, "1 1 1");
   619   set_armor(0, "1 1 1");
   620 }
   621 
   622 static void set_metal(int pnum, const char *args)
   623 {
   624   float head, high, low;
   625   sscanf(args, "%f%f%f", &head, &high, &low);
   626 
   627   player[pnum].metalhead = head;
   628   player[pnum].metalhigh = high;
   629   player[pnum].metallow  = low;
   630 }
   631 
   632 static void ch_metal(Game *game, const char *args)
   633 {
   634   set_metal(0, args);
   635 }
   636 
   637 static void set_noclothes(int pnum, Game *game, const char *args)
   638 {
   639   player[pnum].numclothes = 0;
   640   game->LoadTextureSave(creatureskin[player[pnum].creature][player[pnum].whichskin],
   641 			&player[pnum].skeleton.drawmodel.textureptr,1,
   642 			&player[pnum].skeleton.skinText[0],&player[pnum].skeleton.skinsize);
   643 }
   644 
   645 static void ch_noclothes(Game *game, const char *args)
   646 {
   647   set_noclothes(0, game, args);
   648 }
   649 
   650 static void ch_noclothesnear(Game *game, const char *args)
   651 {
   652   int closest = find_closest();
   653   if (closest)
   654     set_noclothes(closest, game, args);
   655 }
   656 
   657 
   658 static void set_clothes(int pnum, Game *game, const char *args)
   659 {
   660   char buf[64];
   661   snprintf(buf, 63, ":Data:Textures:%s.png", args);
   662 
   663   if (!game->AddClothes(buf,0,1,&player[pnum].skeleton.skinText[pnum],&player[pnum].skeleton.skinsize))
   664     return;
   665 
   666   player[pnum].DoMipmaps(5,0,0,player[pnum].skeleton.skinsize,player[pnum].skeleton.skinsize);
   667   strcpy(player[pnum].clothes[player[pnum].numclothes],buf);
   668   player[pnum].clothestintr[player[pnum].numclothes]=tintr;
   669   player[pnum].clothestintg[player[pnum].numclothes]=tintg;
   670   player[pnum].clothestintb[player[pnum].numclothes]=tintb;
   671   player[pnum].numclothes++;
   672 }
   673 
   674 static void ch_clothes(Game *game, const char *args)
   675 {
   676   set_clothes(0, game, args);
   677 }
   678 
   679 static void ch_clothesnear(Game *game, const char *args)
   680 {
   681   int closest = find_closest();
   682   if (closest)
   683     set_clothes(closest, game, args);
   684 }
   685 
   686 static void ch_belt(Game *game, const char *args)
   687 {
   688   player[0].skeleton.clothes = !player[0].skeleton.clothes;
   689 }
   690 
   691 
   692 static void ch_cellophane(Game *game, const char *args)
   693 {
   694   cellophane = !cellophane;
   695   float mul = cellophane ? 0 : 1;
   696 
   697   for (int i = 0; i < numplayers; i++) {
   698     player[i].proportionhead.z = player[i].proportionhead.x * mul;
   699     player[i].proportionbody.z = player[i].proportionbody.x * mul;
   700     player[i].proportionarms.z = player[i].proportionarms.x * mul;
   701     player[i].proportionlegs.z = player[i].proportionlegs.x * mul;
   702   }
   703 }
   704 
   705 static void ch_funnybunny(Game *game, const char *args)
   706 {
   707   player[0].skeleton.id=0;
   708   player[0].skeleton.Load(":Data:Skeleton:Basic Figure",":Data:Skeleton:Basic Figurelow",
   709 			  ":Data:Skeleton:Rabbitbelt",":Data:Models:Body.solid",
   710 			  ":Data:Models:Body2.solid",":Data:Models:Body3.solid",
   711 			  ":Data:Models:Body4.solid",":Data:Models:Body5.solid",
   712 			  ":Data:Models:Body6.solid",":Data:Models:Body7.solid",
   713 			  ":Data:Models:Bodylow.solid",":Data:Models:Belt.solid",1);
   714   game->LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,
   715 			&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
   716   player[0].creature=rabbittype;
   717   player[0].scale=.2;
   718   player[0].headless=0;
   719   player[0].damagetolerance=200;
   720   set_proportion(0, "1 1 1 1");
   721 }
   722 
   723 static void ch_wolfie(Game *game, const char *args)
   724 {
   725   player[0].skeleton.id=0;
   726   player[0].skeleton.Load(":Data:Skeleton:Basic Figure Wolf",":Data:Skeleton:Basic Figure Wolf Low",
   727 			  ":Data:Skeleton:Rabbitbelt",":Data:Models:Wolf.solid",
   728 			  ":Data:Models:Wolf2.solid",":Data:Models:Wolf3.solid",
   729 			  ":Data:Models:Wolf4.solid",":Data:Models:Wolf5.solid",
   730 			  ":Data:Models:Wolf6.solid",":Data:Models:Wolf7.solid",
   731 			  ":Data:Models:Wolflow.solid",":Data:Models:Belt.solid",0);
   732   game->LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
   733 			&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
   734   player[0].creature=wolftype;
   735   player[0].damagetolerance=300;
   736   set_proportion(0, "1 1 1 1");
   737 }
   738 
   739 static void ch_wolf(Game *game, const char *args)
   740 {
   741   game->LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
   742 			&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
   743 }
   744 
   745 static void ch_snowwolf(Game *game, const char *args)
   746 {
   747   game->LoadTextureSave(":Data:Textures:SnowWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
   748 			&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
   749 }
   750 
   751 static void ch_darkwolf(Game *game, const char *args)
   752 {
   753   game->LoadTextureSave(":Data:Textures:DarkWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
   754 			&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
   755 }
   756 
   757 static void ch_white(Game *game, const char *args)
   758 {
   759   game->LoadTextureSave(":Data:Textures:fur.jpg",&player[0].skeleton.drawmodel.textureptr,1,
   760 			&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
   761 }
   762 
   763 static void ch_brown(Game *game, const char *args)
   764 {
   765   game->LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,
   766 			&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
   767 }
   768 
   769 static void ch_black(Game *game, const char *args)
   770 {
   771   game->LoadTextureSave(":Data:Textures:fur2.jpg",&player[0].skeleton.drawmodel.textureptr,1,
   772 			&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
   773 }
   774 
   775 static void ch_sizemin(Game *game, const char *args)
   776 {
   777   int i;
   778   for (i = 1; i < numplayers; i++)
   779     if (player[i].scale < 0.8 * 0.2)
   780       player[i].scale = 0.8 * 0.2;
   781 }
   782 
   783 static void ch_tutorial(Game *game, const char *args)
   784 {
   785   tutoriallevel = atoi(args);
   786 }
   787 
   788 static void ch_hostile(Game *game, const char *args)
   789 {
   790   hostile = atoi(args);
   791 }
   792 
   793 static void ch_indemo(Game *game, const char *args)
   794 {
   795   game->indemo=1;
   796   hotspot[numhotspots]=player[0].coords;
   797   hotspotsize[numhotspots]=0;
   798   hotspottype[numhotspots]=-111;
   799   strcpy(hotspottext[numhotspots],"mapname");
   800   numhotspots++;
   801 }
   802 
   803 static void ch_notindemo(Game *game, const char *args)
   804 {
   805   game->indemo=0;
   806   numhotspots--;
   807 }
   808 
   809 static void ch_type(Game *game, const char *args)
   810 {
   811   int i, n = sizeof(editortypenames) / sizeof(editortypenames[0]);
   812   for (i = 0; i < n; i++)
   813     if (stripfx(args, editortypenames[i]))
   814       {
   815 	editoractive = i;
   816 	break;
   817       }
   818 }
   819 
   820 static void ch_path(Game *game, const char *args)
   821 {
   822   int i, n = sizeof(pathtypenames) / sizeof(pathtypenames[0]);
   823   for (i = 0; i < n; i++)
   824     if (stripfx(args, pathtypenames[i]))
   825       {
   826 	editorpathtype = i;
   827 	break;
   828       }
   829 }
   830 
   831 static void ch_hs(Game *game, const char *args)
   832 {
   833   hotspot[numhotspots]=player[0].coords;
   834 
   835   float size;
   836   int type, shift;
   837   sscanf(args, "%f%d %n", &size, &type, &shift);
   838 
   839   hotspotsize[numhotspots] = size;
   840   hotspottype[numhotspots] = type;
   841 
   842   strcpy(hotspottext[numhotspots], args + shift);
   843   strcat(hotspottext[numhotspots], "\n");
   844 
   845   numhotspots++;
   846 }
   847 
   848 static void ch_dialogue(Game *game, const char *args)
   849 {
   850   int dlg, i, j;
   851   char buf1[32], buf2[64];
   852 
   853   sscanf(args, "%d %31s", &dlg, buf1);
   854   snprintf(buf2, 63, ":Data:Dialogues:%s.txt", buf1);
   855 
   856   dialoguetype[numdialogues] = dlg;
   857 
   858   memset(dialoguetext[numdialogues], 0, sizeof(dialoguetext[numdialogues]));
   859   memset(dialoguename[numdialogues], 0, sizeof(dialoguename[numdialogues]));
   860 
   861   ifstream ipstream(ConvertFileName(buf2));
   862   ipstream.ignore(256,':');
   863   ipstream >> numdialogueboxes[numdialogues];
   864   for(i=0;i<numdialogueboxes[numdialogues];i++){
   865     ipstream.ignore(256,':');
   866     ipstream.ignore(256,':');
   867     ipstream.ignore(256,' ');
   868     ipstream >> dialogueboxlocation[numdialogues][i];
   869     ipstream.ignore(256,':');
   870     ipstream >> dialogueboxcolor[numdialogues][i][0];
   871     ipstream >> dialogueboxcolor[numdialogues][i][1];
   872     ipstream >> dialogueboxcolor[numdialogues][i][2];
   873     ipstream.ignore(256,':');
   874     ipstream.getline(dialoguename[numdialogues][i],64);
   875     ipstream.ignore(256,':');
   876     ipstream.ignore(256,' ');
   877     ipstream.getline(dialoguetext[numdialogues][i],128);
   878     for(j=0;j<128;j++){
   879       if(dialoguetext[numdialogues][i][j]=='\\')dialoguetext[numdialogues][i][j]='\n';
   880     }
   881     ipstream.ignore(256,':');
   882     ipstream >> dialogueboxsound[numdialogues][i];
   883   }
   884 
   885   for(i=0;i<numdialogueboxes[numdialogues];i++){
   886     for(j=0;j<numplayers;j++){
   887       participantfacing[numdialogues][i][j]=player[j].facing;
   888     }
   889   }
   890   ipstream.close();
   891 
   892   directing=1;
   893   indialogue=0;
   894   whichdialogue=numdialogues;
   895 
   896   numdialogues++;
   897 }
   898 
   899 static void ch_fixdialogue(Game *game, const char *args)
   900 {
   901   char buf1[32], buf2[64];
   902   int whichdi, i, j;
   903 
   904   sscanf(args, "%d %31s", &whichdi, buf1);
   905   snprintf(buf2, 63, ":Data:Dialogues:%s.txt", buf1);
   906 
   907   memset(dialoguetext[whichdi], 0, sizeof(dialoguetext[whichdi]));
   908   memset(dialoguename[whichdi], 0, sizeof(dialoguename[whichdi]));
   909 
   910   ifstream ipstream(ConvertFileName(buf2));
   911   ipstream.ignore(256,':');
   912   ipstream >> numdialogueboxes[whichdi];
   913   for(i=0;i<numdialogueboxes[whichdi];i++){
   914     ipstream.ignore(256,':');
   915     ipstream.ignore(256,':');
   916     ipstream.ignore(256,' ');
   917     ipstream >> dialogueboxlocation[whichdi][i];
   918     ipstream.ignore(256,':');
   919     ipstream >> dialogueboxcolor[whichdi][i][0];
   920     ipstream >> dialogueboxcolor[whichdi][i][1];
   921     ipstream >> dialogueboxcolor[whichdi][i][2];
   922     ipstream.ignore(256,':');
   923     ipstream.getline(dialoguename[whichdi][i],64);
   924     ipstream.ignore(256,':');
   925     ipstream.ignore(256,' ');
   926     ipstream.getline(dialoguetext[whichdi][i],128);
   927     for(j=0;j<128;j++){
   928       if(dialoguetext[whichdi][i][j]=='\\')dialoguetext[whichdi][i][j]='\n';
   929     }
   930     ipstream.ignore(256,':');
   931     ipstream >> dialogueboxsound[whichdi][i];
   932   }
   933 
   934   ipstream.close();
   935 }
   936 
   937 static void ch_fixtype(Game *game, const char *args)
   938 {
   939   int dlg;
   940   sscanf(args, "%d", &dlg);
   941   dialoguetype[0] = dlg;
   942 }
   943 
   944 static void ch_fixrotation(Game *game, const char *args)
   945 {
   946   participantrotation[whichdialogue][participantfocus[whichdialogue][indialogue]]=player[participantfocus[whichdialogue][indialogue]].rotation;
   947 }
   948 
   949 static void ch_ddialogue(Game *game, const char *args)
   950 {
   951   if (numdialogues)
   952     numdialogues--;
   953 }
   954 
   955 static void ch_dhs(Game *game, const char *args)
   956 {
   957   if (numhotspots)
   958     numhotspots--;
   959 }
   960 
   961 static void ch_immobile(Game *game, const char *args)
   962 {
   963   player[0].immobile = 1;
   964 }
   965 
   966 static void ch_allimmobile(Game *game, const char *args)
   967 {
   968   for (int i = 1; i < numplayers; i++)
   969     player[i].immobile = 1;
   970 }
   971 
   972 static void ch_mobile(Game *game, const char *args)
   973 {
   974   player[0].immobile = 0;
   975 }
   976 
   977 static void ch_default(Game *game, const char *args)
   978 {
   979   player[0].armorhead=1;
   980   player[0].armorhigh=1;
   981   player[0].armorlow=1;
   982   player[0].protectionhead=1;
   983   player[0].protectionhigh=1;
   984   player[0].protectionlow=1;
   985   player[0].metalhead=1;
   986   player[0].metalhigh=1;
   987   player[0].metallow=1;
   988   player[0].power=1;
   989   player[0].speedmult=1;
   990   player[0].scale=1;
   991 
   992   if(player[0].creature==wolftype){
   993     player[0].proportionhead=1.1;
   994     player[0].proportionbody=1.1;
   995     player[0].proportionarms=1.1;
   996     player[0].proportionlegs=1.1;
   997   }
   998 
   999   if(player[0].creature==rabbittype){
  1000     player[0].proportionhead=1.2;
  1001     player[0].proportionbody=1.05;
  1002     player[0].proportionarms=1.00;
  1003     player[0].proportionlegs=1.1;
  1004     player[0].proportionlegs.y=1.05;
  1005   }
  1006 
  1007   player[0].numclothes=0;
  1008   game->LoadTextureSave(creatureskin[player[0].creature][player[0].whichskin],
  1009 			&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],
  1010 			&player[0].skeleton.skinsize);
  1011 
  1012   editoractive=typeactive;
  1013   player[0].immobile=0;
  1014 }
  1015 
  1016 static void ch_play(Game *game, const char *args)
  1017 {
  1018   int dlg, i;
  1019   sscanf(args, "%d", &dlg);
  1020   whichdialogue = dlg;
  1021 
  1022   if (whichdialogue >= numdialogues)
  1023     return;
  1024 
  1025   for(i=0;i<numdialogueboxes[whichdialogue];i++){
  1026     player[participantfocus[whichdialogue][i]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][i]];
  1027     player[participantfocus[whichdialogue][i]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
  1028     player[participantfocus[whichdialogue][i]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
  1029     player[participantfocus[whichdialogue][i]].velocity=0;
  1030     player[participantfocus[whichdialogue][i]].targetanimation=player[participantfocus[whichdialogue][i]].getIdle();
  1031     player[participantfocus[whichdialogue][i]].targetframe=0;
  1032   }
  1033 
  1034   directing=0;
  1035   indialogue=0;
  1036 
  1037   float gLoc[3];
  1038   float vel[3];
  1039   XYZ temppos;
  1040   temppos=player[participantfocus[whichdialogue][indialogue]].coords;
  1041   temppos=temppos-viewer;
  1042   Normalise(&temppos);
  1043   temppos+=viewer;
  1044 
  1045   gLoc[0]=temppos.x;
  1046   gLoc[1]=temppos.y;
  1047   gLoc[2]=temppos.z;
  1048   vel[0]=0;
  1049   vel[1]=0;
  1050   vel[2]=0;
  1051   int whichsoundplay;
  1052   whichsoundplay=rabbitchitter;
  1053   if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
  1054   if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
  1055   if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
  1056   if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
  1057   if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
  1058   if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
  1059   if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
  1060   if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
  1061   if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
  1062   if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
  1063   if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
  1064   if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
  1065   if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
  1066   if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
  1067   if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
  1068   if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
  1069   if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
  1070   if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
  1071   if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
  1072   PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
  1073   OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
  1074   OPENAL_SetVolume(channels[whichsoundplay], 256);
  1075   OPENAL_SetPaused(channels[whichsoundplay], false);
  1076 }
  1077 
  1078 static void ch_mapkilleveryone(Game *game, const char *args)
  1079 {
  1080   maptype = mapkilleveryone;
  1081 }
  1082 
  1083 static void ch_mapkillmost(Game *game, const char *args)
  1084 {
  1085   maptype = mapkillmost;
  1086 }
  1087 
  1088 static void ch_mapkillsomeone(Game *game, const char *args)
  1089 {
  1090   maptype = mapkillsomeone;
  1091 }
  1092 
  1093 static void ch_mapgosomewhere(Game *game, const char *args)
  1094 {
  1095   maptype = mapgosomewhere;
  1096 }
  1097 
  1098 static void ch_viewdistance(Game *game, const char *args)
  1099 {
  1100   viewdistance = atof(args)*100;
  1101 }
  1102 
  1103 static void ch_fadestart(Game *game, const char *args)
  1104 {
  1105   fadestart = atof(args);
  1106 }
  1107 
  1108 static void ch_slomo(Game *game, const char *args)
  1109 {
  1110   slomospeed = atof(args);
  1111   slomo = !slomo;
  1112   slomodelay = 1000;
  1113 }
  1114 
  1115 static void ch_slofreq(Game *game, const char *args)
  1116 {
  1117   slomofreq = atof(args);
  1118 }
  1119 
  1120 static void ch_skytint(Game *game, const char *args)
  1121 {
  1122   sscanf(args, "%f%f%f", &skyboxr, &skyboxg, &skyboxb);
  1123 
  1124   skyboxlightr=skyboxr;
  1125   skyboxlightg=skyboxg;
  1126   skyboxlightb=skyboxb;
  1127 
  1128   game->SetUpLighting();
  1129 
  1130   terrain.DoShadows();
  1131   objects.DoShadows();
  1132 }
  1133 
  1134 static void ch_skylight(Game *game, const char *args)
  1135 {
  1136   sscanf(args, "%f%f%f", &skyboxlightr, &skyboxlightg, &skyboxlightb);
  1137 
  1138   game->SetUpLighting();
  1139 
  1140   terrain.DoShadows();
  1141   objects.DoShadows();
  1142 }
  1143 
  1144 static void ch_skybox(Game *game, const char *args)
  1145 {
  1146   skyboxtexture = !skyboxtexture;
  1147 
  1148   game->SetUpLighting();
  1149 
  1150   terrain.DoShadows();
  1151   objects.DoShadows();
  1152 }
  1153 
  1154 static void cmd_dispatch(Game *game, const char *cmd)
  1155 {
  1156   int i, n_cmds = sizeof(cmd_names) / sizeof(cmd_names[0]);
  1157 
  1158   for (i = 0; i < n_cmds; i++)
  1159     if (stripfx(cmd, cmd_names[i]))
  1160       {
  1161 	cmd_handlers[i](game, cmd + strlen(cmd_names[i]));
  1162 	break;
  1163       }
  1164   if (i < n_cmds)
  1165     {
  1166       PlaySoundEx(consolesuccesssound, samp[consolesuccesssound], NULL, true);
  1167       OPENAL_SetVolume(channels[consolesuccesssound], 256);
  1168       OPENAL_SetPaused(channels[consolesuccesssound], false);
  1169     }
  1170   else
  1171     {
  1172       PlaySoundEx(consolefailsound, samp[consolefailsound], NULL, true);
  1173       OPENAL_SetVolume(channels[consolefailsound], 256);
  1174       OPENAL_SetPaused(channels[consolefailsound], false);
  1175     }
  1176 }
  1177 
  1178 
  1179 
  1180 /********************> Tick() <*****/
  1181 extern void ScreenShot(const char * fname);
  1182 void Screenshot	(void)
  1183 {
  1184 	char temp[1024];
  1185 	time_t	t = time(NULL);
  1186 	struct	tm *tme = localtime(&t);
  1187 	sprintf(temp, "Screenshots\\Screenshot_%04d_%02d_%02d--%02d_%02d_%02d.png", tme->tm_year + 1900, tme->tm_mon + 1, tme->tm_mday, tme->tm_hour, tme->tm_min, tme->tm_sec);
  1188 
  1189 	#if defined(_WIN32)
  1190 	mkdir("Screenshots");
  1191 	#else
  1192 	mkdir("Screenshots", S_IRWXU);
  1193 	#endif
  1194 
  1195 	ScreenShot(temp/*"Screenshots\\Screenshot.png"*/);
  1196 
  1197 	/*FSSpec				MAC_file;
  1198 	GraphicsExportComponent	QT_exporter;
  1199 	OSErr				MAC_error_code;
  1200 	CGrafPtr			MAC_currentPort;
  1201 	GDHandle			MAC_currentDevice;
  1202 	unsigned char*		MAC_pixels;
  1203 	Rect				MAC_picture_rectangle;
  1204 	GWorldPtr			MAC_offscreen_graphics_port;
  1205 
  1206 	static int numscreenshots=0;
  1207 
  1208 	// Make an FSSpec
  1209 	static char buf[256];
  1210 	if(numscreenshots==0){
  1211 	buf[0]=26;
  1212 	buf[1]=':';
  1213 	buf[2]='S';
  1214 	buf[3]='c';
  1215 	buf[4]='r';
  1216 	buf[5]='e';
  1217 	buf[6]='e';
  1218 	buf[7]='n';
  1219 	buf[8]='s';
  1220 	buf[9]='h';
  1221 	buf[10]='o';
  1222 	buf[11]='t';
  1223 	buf[12]='s';
  1224 	buf[13]=':';
  1225 	buf[14]='S';
  1226 	buf[15]='c';
  1227 	buf[16]='r';
  1228 	buf[17]='e';
  1229 	buf[18]='e';
  1230 	buf[19]='n';
  1231 	buf[20]='s';
  1232 	buf[21]='h';
  1233 	buf[22]='o';
  1234 	buf[23]='t';
  1235 	buf[24]='0';
  1236 	buf[25]='0';
  1237 	buf[26]='0';
  1238 	}
  1239 
  1240 	FInfo *fndrInfo;
  1241 	FSMakeFSSpec(0, 0, (unsigned char*)buf, &MAC_file);
  1242 	while(!FSpGetFInfo (&MAC_file, fndrInfo)){
  1243 	FSMakeFSSpec(0, 0, (unsigned char*)buf, &MAC_file);
  1244 	if(!FSpGetFInfo (&MAC_file, fndrInfo)){
  1245 	numscreenshots++;
  1246 	buf[26]++;
  1247 	if(buf[26]==':'){
  1248 	buf[26]='0';
  1249 	buf[25]++;
  1250 	if(buf[25]==':'){
  1251 	buf[25]='0';
  1252 	buf[24]++;
  1253 	if(buf[24]==':'){
  1254 	buf[24]='9';
  1255 	buf[25]='9';
  1256 	buf[26]='9';
  1257 	}
  1258 	}
  1259 	}
  1260 	}
  1261 	}
  1262 
  1263 
  1264 	// Get the GWorld
  1265 	GWorldPtr			MAC_gWorld = (CGrafPtr) FrontWindow();
  1266 	//assert(MAC_gWorld != NULL);
  1267 
  1268 	// Allocate memory for loading image
  1269 	MAC_pixels = new unsigned char[(int)(screenheight * screenwidth * 4)];
  1270 	if (MAC_pixels == NULL) {
  1271 	//UTIL_Error("Could not create Texture data.");
  1272 	return;
  1273 	}
  1274 
  1275 	// Get GWorld
  1276 	::GetGWorld(&MAC_currentPort, &MAC_currentDevice);
  1277 
  1278 	// Make a picture Rectangle
  1279 	MAC_picture_rectangle.left = 0;
  1280 	MAC_picture_rectangle.right = screenwidth;
  1281 	MAC_picture_rectangle.top = 0;
  1282 	MAC_picture_rectangle.bottom = screenheight;
  1283 
  1284 	// Create new offscreen GWorld
  1285 	MAC_error_code = ::QTNewGWorldFromPtr (&MAC_offscreen_graphics_port, k32ARGBPixelFormat, &MAC_picture_rectangle, NULL, NULL, 0, (char *) MAC_pixels, screenwidth * 4);
  1286 	if (MAC_error_code)	{
  1287 	::SetGWorld(MAC_currentPort, MAC_currentDevice);
  1288 	delete MAC_pixels;
  1289 	//UTIL_Error("Could not create offscreen GWorld. ");
  1290 	return;
  1291 
  1292 	}
  1293 
  1294 	// Copy OpenGL Context to new GWorld
  1295 	glReadBuffer(GL_FRONT);
  1296 	glReadPixels(0,0,screenwidth,screenheight,GL_RGBA,GL_UNSIGNED_BYTE,MAC_pixels);
  1297 
  1298 	// Swizzle texture
  1299 	for (unsigned long byte = 0; byte < screenheight * screenwidth * 4; byte+=4) {
  1300 	unsigned char temp = MAC_pixels[byte+0];
  1301 	MAC_pixels[byte+0] = MAC_pixels[byte+3];
  1302 	MAC_pixels[byte+3] = MAC_pixels[byte+2];
  1303 	MAC_pixels[byte+2] = MAC_pixels[byte+1];
  1304 	MAC_pixels[byte+1] = temp;
  1305 	}
  1306 
  1307 	// Flip the image  :(   This could probably be optimized
  1308 	int vert;
  1309 	int src_index;
  1310 	int dst_index;
  1311 	unsigned char temp;
  1312 	for (int horz = 0; horz < screenwidth; ++horz)
  1313 	for (vert = 0; vert < screenheight / 2; ++vert) {
  1314 	src_index = (screenwidth * vert + horz) * 4;
  1315 	dst_index = (screenwidth * (screenheight - vert - 1) + horz) * 4;
  1316 
  1317 	temp=MAC_pixels[src_index+0];
  1318 	MAC_pixels[src_index+0]=MAC_pixels[dst_index+0];
  1319 	MAC_pixels[dst_index+0]=temp;
  1320 
  1321 	temp=MAC_pixels[src_index+1];
  1322 	MAC_pixels[src_index+1]=MAC_pixels[dst_index+1];
  1323 	MAC_pixels[dst_index+1]=temp;
  1324 
  1325 	temp=MAC_pixels[src_index+2];
  1326 	MAC_pixels[src_index+2]=MAC_pixels[dst_index+2];
  1327 	MAC_pixels[dst_index+2]=temp;
  1328 
  1329 	temp=MAC_pixels[src_index+3];
  1330 	MAC_pixels[src_index+3]=MAC_pixels[dst_index+3];
  1331 	MAC_pixels[dst_index+3]=temp;
  1332 	}
  1333 
  1334 
  1335 
  1336 	// Export the Gworld
  1337 	MAC_error_code =  OpenADefaultComponent(GraphicsExporterComponentType, kQTFileTypeBMP, &QT_exporter);
  1338 	if (MAC_error_code) {
  1339 	//UTIL_Warning("Unable to export screenshot.");
  1340 	::SetGWorld(MAC_currentPort, MAC_currentDevice);
  1341 	::DisposeGWorld(MAC_offscreen_graphics_port);
  1342 	delete MAC_pixels;
  1343 	return;
  1344 	}
  1345 
  1346 	MAC_error_code =  GraphicsExportSetInputGWorld(QT_exporter,MAC_offscreen_graphics_port);
  1347 	if (MAC_error_code) {
  1348 	::CloseComponent(QT_exporter);
  1349 	::SetGWorld(MAC_currentPort, MAC_currentDevice);
  1350 	::DisposeGWorld(MAC_offscreen_graphics_port);
  1351 	delete MAC_pixels;
  1352 	//UTIL_Warning("Unable to export screenshot.");
  1353 	return;
  1354 	}
  1355 
  1356 	MAC_error_code = GraphicsExportSetOutputFile(QT_exporter,&MAC_file);
  1357 	if (MAC_error_code) {
  1358 	::CloseComponent(QT_exporter);
  1359 	::SetGWorld(MAC_currentPort, MAC_currentDevice);
  1360 	::DisposeGWorld(MAC_offscreen_graphics_port);
  1361 	delete MAC_pixels;
  1362 	//UTIL_Warning("Unable to export screenshot.");
  1363 	return;
  1364 	}
  1365 
  1366 	MAC_error_code = GraphicsExportDoExport(QT_exporter,NULL);
  1367 	if (MAC_error_code) {
  1368 	::CloseComponent(QT_exporter);
  1369 	::SetGWorld(MAC_currentPort, MAC_currentDevice);
  1370 	::DisposeGWorld(MAC_offscreen_graphics_port);
  1371 	delete MAC_pixels;
  1372 	//UTIL_Warning("Unable to export screenshot.");
  1373 	return;
  1374 	}
  1375 
  1376 	::CloseComponent(QT_exporter);
  1377 	::SetGWorld(MAC_currentPort, MAC_currentDevice);
  1378 	::DisposeGWorld(MAC_offscreen_graphics_port);
  1379 
  1380 	delete MAC_pixels;*/
  1381 }
  1382 
  1383 
  1384 
  1385 void	Game::SetUpLighting(){
  1386 	if(environment==snowyenvironment){
  1387 		light.color[0]=.65;
  1388 		light.color[1]=.65;
  1389 		light.color[2]=.7;
  1390 		light.ambient[0]=.4;
  1391 		light.ambient[1]=.4;
  1392 		light.ambient[2]=.44;
  1393 	}
  1394 	if(environment==desertenvironment){
  1395 		light.color[0]=.95;
  1396 		light.color[1]=.95;
  1397 		light.color[2]=.95;
  1398 		light.ambient[0]=.4;
  1399 		light.ambient[1]=.35;
  1400 		light.ambient[2]=.3;
  1401 	}
  1402 
  1403 	if(environment==grassyenvironment){
  1404 		light.color[0]=.95;
  1405 		light.color[1]=.95;
  1406 		light.color[2]=1;
  1407 		light.ambient[0]=.4;
  1408 		light.ambient[1]=.4;
  1409 		light.ambient[2]=.44;
  1410 	}
  1411 	if(!skyboxtexture){
  1412 		light.color[0]=1;
  1413 		light.color[1]=1;
  1414 		light.color[2]=1;
  1415 		light.ambient[0]=.4;
  1416 		light.ambient[1]=.4;
  1417 		light.ambient[2]=.4;
  1418 	}
  1419 	float average;
  1420 	average=(skyboxlightr+skyboxlightg+skyboxlightb)/3;
  1421 	light.color[0]*=(skyboxlightr+average)/2;
  1422 	light.color[1]*=(skyboxlightg+average)/2;
  1423 	light.color[2]*=(skyboxlightb+average)/2;
  1424 	light.ambient[0]=light.ambient[0]*(skyboxlightr+average)/2*1;
  1425 	light.ambient[1]=light.ambient[1]*(skyboxlightg+average)/2*1;
  1426 	light.ambient[2]=light.ambient[2]*(skyboxlightb+average)/2*1;
  1427 	/*
  1428 	light.ambient[0]=0;
  1429 	light.ambient[1]=0;
  1430 	light.ambient[2]=0;	*/
  1431 }
  1432 
  1433 int Game::findPathDist(int start,int end){
  1434 	int i,j,k,smallestcount,count,connected;
  1435 	int last,last2,last3,last4;
  1436 	int closest;
  1437 
  1438 	smallestcount=1000;
  1439 	for(i=0;i<50;i++){
  1440 		count=0;
  1441 		last=start;
  1442 		last2=-1;
  1443 		last3=-1;
  1444 		last4=-1;
  1445 		while(last!=end&&count<30){
  1446 			closest=-1;
  1447 			for(j=0;j<numpathpoints;j++){
  1448 				if(j!=last&&j!=last2&&j!=last3&&j!=last4)
  1449 				{
  1450 					connected=0;
  1451 					if(numpathpointconnect[j])
  1452 						for(k=0;k<numpathpointconnect[j];k++){
  1453 							if(pathpointconnect[j][k]==last)connected=1;
  1454 						}
  1455 						if(!connected)
  1456 							if(numpathpointconnect[last])
  1457 								for(k=0;k<numpathpointconnect[last];k++){
  1458 									if(pathpointconnect[last][k]==j)connected=1;
  1459 								}
  1460 								if(connected)
  1461 									if(closest==-1||Random()%2==0){
  1462 										closest=j;
  1463 									}
  1464 				}
  1465 			}
  1466 			last4=last3;
  1467 			last3=last2;
  1468 			last2=last;
  1469 			last=closest;
  1470 			count++;
  1471 		}
  1472 		if(count<smallestcount)smallestcount=count;
  1473 	}
  1474 	return smallestcount;
  1475 }
  1476 
  1477 int Game::checkcollide(XYZ startpoint,XYZ endpoint){
  1478 	static XYZ colpoint,colviewer,coltarget;
  1479 	static float minx,minz,maxx,maxz,miny,maxy;
  1480 	static int i;
  1481 
  1482 	//startpoint.y+=.7;
  1483 	//endpoint.y+=.7;
  1484 	//startpoint.y-=.1;
  1485 	//endpoint.y-=.1;
  1486 
  1487 	minx=startpoint.x;
  1488 	if(minx>endpoint.x)minx=endpoint.x;
  1489 	miny=startpoint.y;
  1490 	if(miny>endpoint.y)miny=endpoint.y;
  1491 	minz=startpoint.z;
  1492 	if(minz>endpoint.z)minz=endpoint.z;
  1493 
  1494 	maxx=startpoint.x;
  1495 	if(maxx<endpoint.x)maxx=endpoint.x;
  1496 	maxy=startpoint.y;
  1497 	if(maxy<endpoint.y)maxy=endpoint.y;
  1498 	maxz=startpoint.z;
  1499 	if(maxz<endpoint.z)maxz=endpoint.z;
  1500 
  1501 	minx-=1;
  1502 	miny-=1;
  1503 	minz-=1;
  1504 	maxx+=1;
  1505 	maxy+=1;
  1506 	maxz+=1;
  1507 
  1508 	for(i=0;i<objects.numobjects;i++){
  1509 		if(objects.position[i].x>minx-objects.model[i].boundingsphereradius&&objects.position[i].x<maxx+objects.model[i].boundingsphereradius&&objects.position[i].y>miny-objects.model[i].boundingsphereradius&&objects.position[i].y<maxy+objects.model[i].boundingsphereradius&&objects.position[i].z>minz-objects.model[i].boundingsphereradius&&objects.position[i].z<maxz+objects.model[i].boundingsphereradius){
  1510 			if(objects.type[i]!=treeleavestype&&objects.type[i]!=bushtype&&objects.type[i]!=firetype){
  1511 				colviewer=startpoint;
  1512 				coltarget=endpoint;
  1513 				if(objects.model[i].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[i],&objects.rotation[i])!=-1)return i;
  1514 			}
  1515 		}
  1516 	}
  1517 
  1518 	//if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
  1519 
  1520 	return -1;
  1521 }
  1522 
  1523 int Game::checkcollide(XYZ startpoint,XYZ endpoint,int what){
  1524 	static XYZ colpoint,colviewer,coltarget;
  1525 	static float minx,minz,maxx,maxz,miny,maxy;
  1526 	static int i;
  1527 
  1528 	//startpoint.y+=.7;
  1529 	//endpoint.y+=.7;
  1530 	//startpoint.y-=.1;
  1531 	//endpoint.y-=.1;
  1532 
  1533 	minx=startpoint.x;
  1534 	if(minx>endpoint.x)minx=endpoint.x;
  1535 	miny=startpoint.y;
  1536 	if(miny>endpoint.y)miny=endpoint.y;
  1537 	minz=startpoint.z;
  1538 	if(minz>endpoint.z)minz=endpoint.z;
  1539 
  1540 	maxx=startpoint.x;
  1541 	if(maxx<endpoint.x)maxx=endpoint.x;
  1542 	maxy=startpoint.y;
  1543 	if(maxy<endpoint.y)maxy=endpoint.y;
  1544 	maxz=startpoint.z;
  1545 	if(maxz<endpoint.z)maxz=endpoint.z;
  1546 
  1547 	minx-=1;
  1548 	miny-=1;
  1549 	minz-=1;
  1550 	maxx+=1;
  1551 	maxy+=1;
  1552 	maxz+=1;
  1553 
  1554 	if(what!=1000){
  1555 		if(objects.position[what].x>minx-objects.model[what].boundingsphereradius&&objects.position[what].x<maxx+objects.model[what].boundingsphereradius&&objects.position[what].y>miny-objects.model[what].boundingsphereradius&&objects.position[what].y<maxy+objects.model[what].boundingsphereradius&&objects.position[what].z>minz-objects.model[what].boundingsphereradius&&objects.position[what].z<maxz+objects.model[what].boundingsphereradius){
  1556 			if(objects.type[what]!=treeleavestype&&objects.type[what]!=bushtype&&objects.type[what]!=firetype){
  1557 				colviewer=startpoint;
  1558 				coltarget=endpoint;
  1559 				if(objects.model[what].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[what],&objects.rotation[what])!=-1)return i;
  1560 			}
  1561 		}
  1562 	}
  1563 
  1564 	if(what==1000)if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
  1565 
  1566 	return -1;
  1567 }
  1568 
  1569 void	Game::Setenvironment(int which)
  1570 {
  1571 	LOGFUNC;
  1572 
  1573 	LOG(" Setting environment...");
  1574 
  1575 	float temptexdetail;
  1576 	environment=which;
  1577 /*
  1578 	OPENAL_SetPaused(channels[music1snow], true);
  1579 	OPENAL_SetPaused(channels[music1grass], true);
  1580 	OPENAL_SetPaused(channels[music1desert], true);
  1581 	OPENAL_SetPaused(channels[wind], true);
  1582 	OPENAL_SetPaused(channels[desertambient], true);
  1583 */
  1584 	OPENAL_SetPaused(channels[stream_music1snow], true);
  1585 	OPENAL_SetPaused(channels[stream_music1grass], true);
  1586 	OPENAL_SetPaused(channels[stream_music1desert], true);
  1587 	OPENAL_SetPaused(channels[stream_wind], true);
  1588 	OPENAL_SetPaused(channels[stream_desertambient], true);
  1589 
  1590 
  1591 	if(environment==snowyenvironment){
  1592 		windvector=0;
  1593 		windvector.z=3;
  1594 		if(ambientsound){
  1595 			//PlaySoundEx( wind, samp[wind], NULL, true);
  1596 			PlayStreamEx(stream_wind, strm[stream_wind], 0, true);
  1597 			OPENAL_SetPaused(channels[stream_wind], false);
  1598 			OPENAL_SetVolume(channels[stream_wind], 256);
  1599 		}
  1600 
  1601 		LoadTexture(":Data:Textures:snowtree.png",&objects.treetextureptr,0,1);
  1602 		LoadTexture(":Data:Textures:bushsnow.png",&objects.bushtextureptr,0,1);
  1603 		LoadTexture(":Data:Textures:bouldersnow.jpg",&objects.rocktextureptr,1,0);
  1604 		LoadTexture(":Data:Textures:snowbox.jpg",&objects.boxtextureptr,1,0);
  1605 
  1606 		OPENAL_Sample_Free(samp[footstepsound]);
  1607 		OPENAL_Sample_Free(samp[footstepsound2]);
  1608 		OPENAL_Sample_Free(samp[footstepsound3]);
  1609 		OPENAL_Sample_Free(samp[footstepsound4]);
  1610 		samp[footstepsound] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepsnow1.ogg"), OPENAL_HW3D, 0, 0);
  1611 		samp[footstepsound2] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepsnow2.ogg"), OPENAL_HW3D, 0, 0);
  1612 		samp[footstepsound3] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepstone1.ogg"), OPENAL_HW3D, 0, 0);
  1613 		samp[footstepsound4] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepstone2.ogg"), OPENAL_HW3D, 0, 0);
  1614 		OPENAL_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);
  1615 		OPENAL_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);
  1616 		OPENAL_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);
  1617 		OPENAL_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);
  1618 
  1619 		LoadTexture(":Data:Textures:snow.jpg",&terraintexture,1,0);
  1620 
  1621 		LoadTexture(":Data:Textures:rock.jpg",&terraintexture2,1,0);
  1622 
  1623 		//LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
  1624 
  1625 
  1626 
  1627 
  1628 		temptexdetail=texdetail;
  1629 		if(texdetail>1)texdetail=4;
  1630 		skybox.load(	":Data:Textures:Skybox(snow):Front.jpg",
  1631 			":Data:Textures:Skybox(snow):Left.jpg",
  1632 			":Data:Textures:Skybox(snow):Back.jpg",
  1633 			":Data:Textures:Skybox(snow):Right.jpg",
  1634 			":Data:Textures:Skybox(snow):Up.jpg",
  1635 			":Data:Textures:Skybox(snow):Down.jpg",
  1636 			":Data:Textures:Skybox(snow):Cloud.jpg",
  1637 			":Data:Textures:Skybox(snow):Reflect.jpg");
  1638 
  1639 
  1640 
  1641 
  1642 		texdetail=temptexdetail;
  1643 	}
  1644 	if(environment==desertenvironment){
  1645 		windvector=0;
  1646 		windvector.z=2;
  1647 		LoadTexture(":Data:Textures:deserttree.png",&objects.treetextureptr,0,1);
  1648 		LoadTexture(":Data:Textures:bushdesert.png",&objects.bushtextureptr,0,1);
  1649 		LoadTexture(":Data:Textures:boulderdesert.jpg",&objects.rocktextureptr,1,0);
  1650 		LoadTexture(":Data:Textures:desertbox.jpg",&objects.boxtextureptr,1,0);
  1651 
  1652 
  1653 		if(ambientsound){
  1654 			//PlaySoundEx( desertambient, samp[desertambient], NULL, true);
  1655 			PlayStreamEx( stream_desertambient, strm[stream_desertambient], NULL, true);
  1656 			OPENAL_SetPaused(channels[stream_desertambient], false);
  1657 			OPENAL_SetVolume(channels[stream_desertambient], 256);
  1658 		}
  1659 
  1660 		OPENAL_Sample_Free(samp[footstepsound]);
  1661 		OPENAL_Sample_Free(samp[footstepsound2]);
  1662 		OPENAL_Sample_Free(samp[footstepsound3]);
  1663 		OPENAL_Sample_Free(samp[footstepsound4]);
  1664 		samp[footstepsound] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepsnow1.ogg"), OPENAL_HW3D, 0, 0);
  1665 		samp[footstepsound2] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepsnow2.ogg"), OPENAL_HW3D, 0, 0);
  1666 		samp[footstepsound3] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepsnow1.ogg"), OPENAL_HW3D, 0, 0);
  1667 		samp[footstepsound4] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepsnow2.ogg"), OPENAL_HW3D, 0, 0);
  1668 		OPENAL_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);
  1669 		OPENAL_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);
  1670 		OPENAL_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);
  1671 		OPENAL_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);
  1672 
  1673 		LoadTexture(":Data:Textures:sand.jpg",&terraintexture,1,0);
  1674 
  1675 		LoadTexture(":Data:Textures:sandslope.jpg",&terraintexture2,1,0);
  1676 
  1677 		//LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
  1678 
  1679 
  1680 
  1681 		temptexdetail=texdetail;
  1682 		if(texdetail>1)texdetail=4;
  1683 		skybox.load(	":Data:Textures:Skybox(sand):Front.jpg",
  1684 			":Data:Textures:Skybox(sand):Left.jpg",
  1685 			":Data:Textures:Skybox(sand):Back.jpg",
  1686 			":Data:Textures:Skybox(sand):Right.jpg",
  1687 			":Data:Textures:Skybox(sand):Up.jpg",
  1688 			":Data:Textures:Skybox(sand):Down.jpg",
  1689 			":Data:Textures:Skybox(sand):Cloud.jpg",
  1690 			":Data:Textures:Skybox(sand):Reflect.jpg");
  1691 
  1692 
  1693 
  1694 
  1695 		texdetail=temptexdetail;
  1696 	}
  1697 	if(environment==grassyenvironment){
  1698 		windvector=0;
  1699 		windvector.z=2;
  1700 		LoadTexture(":Data:Textures:tree.png",&objects.treetextureptr,0,1);
  1701 		LoadTexture(":Data:Textures:bush.png",&objects.bushtextureptr,0,1);
  1702 		LoadTexture(":Data:Textures:boulder.jpg",&objects.rocktextureptr,1,0);
  1703 		LoadTexture(":Data:Textures:grassbox.jpg",&objects.boxtextureptr,1,0);
  1704 
  1705 		if(ambientsound){
  1706 			PlayStreamEx( stream_wind, strm[stream_wind], NULL, true);
  1707 			OPENAL_SetPaused(channels[stream_wind], false);
  1708 			OPENAL_SetVolume(channels[stream_wind], 100);
  1709 		}
  1710 
  1711 		OPENAL_Sample_Free(samp[footstepsound]);
  1712 		OPENAL_Sample_Free(samp[footstepsound2]);
  1713 		OPENAL_Sample_Free(samp[footstepsound3]);
  1714 		OPENAL_Sample_Free(samp[footstepsound4]);
  1715 		samp[footstepsound] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepgrass1.ogg"), OPENAL_HW3D, 0, 0);
  1716 		samp[footstepsound2] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepgrass2.ogg"), OPENAL_HW3D, 0, 0);
  1717 		samp[footstepsound3] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepstone1.ogg"), OPENAL_HW3D, 0, 0);
  1718 		samp[footstepsound4] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepstone2.ogg"), OPENAL_HW3D, 0, 0);
  1719 		OPENAL_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);
  1720 		OPENAL_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);
  1721 		OPENAL_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);
  1722 		OPENAL_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);
  1723 
  1724 		LoadTexture(":Data:Textures:grassdirt.jpg",&terraintexture,1,0);
  1725 
  1726 		LoadTexture(":Data:Textures:mossrock.jpg",&terraintexture2,1,0);
  1727 
  1728 		//LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
  1729 
  1730 
  1731 
  1732 		temptexdetail=texdetail;
  1733 		if(texdetail>1)texdetail=4;
  1734 		skybox.load(	":Data:Textures:Skybox(grass):Front.jpg",
  1735 			":Data:Textures:Skybox(grass):Left.jpg",
  1736 			":Data:Textures:Skybox(grass):Back.jpg",
  1737 			":Data:Textures:Skybox(grass):Right.jpg",
  1738 			":Data:Textures:Skybox(grass):Up.jpg",
  1739 			":Data:Textures:Skybox(grass):Down.jpg",
  1740 			":Data:Textures:Skybox(grass):Cloud.jpg",
  1741 			":Data:Textures:Skybox(grass):Reflect.jpg");
  1742 
  1743 
  1744 
  1745 		texdetail=temptexdetail;
  1746 	}
  1747 	temptexdetail=texdetail;
  1748 	texdetail=1;
  1749 	terrain.load(":Data:Textures:heightmap.png");
  1750 
  1751 	texdetail=temptexdetail;
  1752 }
  1753 
  1754 
  1755 void	Game::Loadlevel(int which){
  1756 	stealthloading=0;
  1757 
  1758 	if(which==0)Loadlevel((char *)":Data:Maps:map1");
  1759 	else if(which==1)Loadlevel((char *)":Data:Maps:map2");
  1760 	else if(which==2)Loadlevel((char *)":Data:Maps:map3");
  1761 	else if(which==3)Loadlevel((char *)":Data:Maps:map4");
  1762 	else if(which==4)Loadlevel((char *)":Data:Maps:map5");
  1763 	else if(which==5)Loadlevel((char *)":Data:Maps:map6");
  1764 	else if(which==6)Loadlevel((char *)":Data:Maps:map7");
  1765 	else if(which==7)Loadlevel((char *)":Data:Maps:map8");
  1766 	else if(which==8)Loadlevel((char *)":Data:Maps:map9");
  1767 	else if(which==9)Loadlevel((char *)":Data:Maps:map10");
  1768 	else if(which==10)Loadlevel((char *)":Data:Maps:map11");
  1769 	else if(which==11)Loadlevel((char *)":Data:Maps:map12");
  1770 	else if(which==12)Loadlevel((char *)":Data:Maps:map13");
  1771 	else if(which==13)Loadlevel((char *)":Data:Maps:map14");
  1772 	else if(which==14)Loadlevel((char *)":Data:Maps:map15");
  1773 	else if(which==15)Loadlevel((char *)":Data:Maps:map16");
  1774 	else if(which==-1){tutoriallevel=-1;Loadlevel((char *)":Data:Maps:tutorial");}
  1775 	else Loadlevel((char *)":Data:Maps:mapsave");
  1776 
  1777 	whichlevel=which;
  1778 }
  1779 
  1780 /*char * Game::MD5_string (unsigned char *string){
  1781 char temp[50];
  1782 char temp2[100];
  1783 
  1784 strcpy(temp2,(const char *)string);
  1785 strcat((char *)temp2,(const char *)"Lugaru");
  1786 sprintf (temp, "%d",strlen((char *)temp2));
  1787 strcat((char *)temp2,temp);
  1788 
  1789 MD5 context;
  1790 unsigned int len = strlen ( (char *)temp2);
  1791 
  1792 context.update   ((unsigned char *)temp2, len);
  1793 context.finalize ();
  1794 
  1795 return context.hex_digest();
  1796 }*/
  1797 
  1798 
  1799 
  1800 void	Game::Loadlevel(char *name){
  1801 	int i,j,k,l,m;
  1802 	static int oldlevel;
  1803 	int templength;
  1804 	float lamefloat;
  1805 	int lameint;
  1806 
  1807 	float headprop,legprop,armprop,bodyprop;
  1808 
  1809 	LOGFUNC;
  1810 
  1811 	LOG(std::string("Loading level...") + name);
  1812 
  1813 	if(!gameon)visibleloading=1;
  1814 
  1815 	if(stealthloading)visibleloading=0;
  1816 
  1817 	if(!stillloading)loadtime=0;
  1818 	gamestarted=1;
  1819 
  1820 	numenvsounds=0;
  1821 	//visibleloading=1;
  1822 	if(tutoriallevel!=-1)tutoriallevel=0;
  1823 	else tutoriallevel=1;
  1824 
  1825 	if(tutoriallevel==1)tutorialstage=0;
  1826 	if(tutorialstage==0){
  1827 		tutorialstagetime=0;
  1828 		tutorialmaxtime=1;
  1829 	}
  1830 	loadingstuff=1;
  1831 	if(!firstload){
  1832 		oldlevel=50;
  1833 	}
  1834 	OPENAL_SetPaused(channels[whooshsound], true);
  1835 	OPENAL_SetPaused(channels[stream_firesound], true);
  1836 
  1837 	// Change the map filename into something that is os specific
  1838 	char *FixedFN = ConvertFileName(name);
  1839 
  1840 	int mapvers;
  1841 	FILE			*tfile;
  1842 	tfile=fopen( FixedFN, "rb" );
  1843 	if(tfile)
  1844 	{
  1845 		OPENAL_SetPaused(channels[stream_firesound], true);
  1846 
  1847 
  1848 		scoreadded=0;
  1849 		windialogue=0;
  1850 
  1851 		hostiletime=0;
  1852 
  1853 		won=0;
  1854 
  1855 		//campaign=0;
  1856 		animation[bounceidleanim].Load((char *)":Data:Animations:Idle",middleheight,neutral);
  1857 
  1858 		numdialogues=0;
  1859 
  1860 		for(i=0;i<20;i++)
  1861 		{
  1862 			dialoguegonethrough[i]=0;
  1863 		}
  1864 
  1865 		indialogue=-1;
  1866 		cameramode=0;
  1867 
  1868 		damagedealt=0;
  1869 		damagetaken=0;
  1870 
  1871 		if(accountactive!=-1)difficulty=accountdifficulty[accountactive];
  1872 
  1873 		if(difficulty!=2)minimap=1;
  1874 		else minimap=0;
  1875 
  1876 		numhotspots=0;
  1877 		currenthotspot=-1;
  1878 		bonustime=1;
  1879 
  1880 		skyboxtexture=1;
  1881 		skyboxr=1;
  1882 		skyboxg=1;
  1883 		skyboxb=1;
  1884 
  1885 		freeze=0;
  1886 		winfreeze=0;
  1887 
  1888 		for(i=0;i<100;i++)
  1889 		{
  1890 			bonusnum[i]=0;
  1891 		}
  1892 
  1893 		numfalls=0;
  1894 		numflipfail=0;
  1895 		numseen=0;
  1896 		numstaffattack=0;
  1897 		numswordattack=0;
  1898 		numknifeattack=0;
  1899 		numunarmedattack=0;
  1900 		numescaped=0;
  1901 		numflipped=0;
  1902 		numwallflipped=0;
  1903 		numthrowkill=0;
  1904 		numafterkill=0;
  1905 		numreversals=0;
  1906 		numattacks=0;
  1907 		maxalarmed=0;
  1908 		numresponded=0;
  1909 
  1910 		bonustotal=startbonustotal;
  1911 		bonus=0;
  1912 		gameon=1;
  1913 		changedelay=0;
  1914 		if(console)
  1915 		{
  1916 			PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
  1917 			OPENAL_SetVolume(channels[consolesuccesssound], 256);
  1918 			OPENAL_SetPaused(channels[consolesuccesssound], false);
  1919 			freeze=0;
  1920 			console=0;
  1921 		}
  1922 
  1923 		if(!stealthloading)
  1924 		{
  1925 			terrain.numdecals=0;
  1926 			sprites.numsprites=0;
  1927 			for(i=0;i<objects.numobjects;i++)
  1928 			{
  1929 				objects.model[i].numdecals=0;
  1930 			}
  1931 
  1932 			j=objects.numobjects;
  1933 			for(i=0;i<j;i++)
  1934 			{
  1935 				objects.DeleteObject(0);
  1936 				if(visibleloading){loadscreencolor=4; LoadingScreen();}
  1937 			}
  1938 
  1939 			for(i=0;i<subdivision;i++)
  1940 			{
  1941 				for(j=0;j<subdivision;j++)
  1942 				{
  1943 					terrain.patchobjectnum[i][j]=0;
  1944 				}
  1945 			}
  1946 			if(visibleloading){loadscreencolor=4; LoadingScreen();}
  1947 		}
  1948 
  1949 		weapons.numweapons=0;
  1950 
  1951 		funpackf(tfile, "Bi", &mapvers);
  1952 		if(mapvers>=15)funpackf(tfile, "Bi", &indemo);
  1953 		else indemo=0;
  1954 		if(mapvers>=5)funpackf(tfile, "Bi", &maptype);
  1955 		else maptype=mapkilleveryone;
  1956 		if(mapvers>=6)funpackf(tfile, "Bi", &hostile);
  1957 		else hostile=1;
  1958 		if(mapvers>=4)funpackf(tfile, "Bf Bf", &viewdistance, &fadestart);
  1959 		else
  1960 		{
  1961 			viewdistance=100;
  1962 			fadestart=.6;
  1963 		}
  1964 		if(mapvers>=2)funpackf(tfile, "Bb Bf Bf Bf", &skyboxtexture, &skyboxr, &skyboxg, &skyboxb);
  1965 		else
  1966 		{
  1967 			skyboxtexture=1;
  1968 			skyboxr=1;
  1969 			skyboxg=1;
  1970 			skyboxb=1;
  1971 		}
  1972 		if(mapvers>=10)funpackf(tfile, "Bf Bf Bf", &skyboxlightr, &skyboxlightg, &skyboxlightb);
  1973 		else
  1974 		{
  1975 			skyboxlightr=skyboxr;
  1976 			skyboxlightg=skyboxg;
  1977 			skyboxlightb=skyboxb;
  1978 		}
  1979 		if(!stealthloading)funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &player[0].coords.x,&player[0].coords.y,&player[0].coords.z,&player[0].rotation,&player[0].targetrotation, &player[0].num_weapons);
  1980 		if(stealthloading)funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &lamefloat,&lamefloat,&lamefloat,&lamefloat,&lamefloat, &player[0].num_weapons);
  1981 		player[0].originalcoords=player[0].coords;
  1982 		if(player[0].num_weapons>0&&player[0].num_weapons<5)
  1983 		{
  1984 			for(j=0;j<player[0].num_weapons;j++)
  1985 			{
  1986 				player[0].weaponids[j]=weapons.numweapons;
  1987 				funpackf(tfile, "Bi", &weapons.type[weapons.numweapons]);
  1988 				weapons.owner[weapons.numweapons]=0;
  1989 				weapons.numweapons++;
  1990 			}
  1991 		}
  1992 
  1993 		if(visibleloading){loadscreencolor=4; LoadingScreen();}
  1994 
  1995 		funpackf(tfile, "Bf Bf Bf", &player[0].armorhead, &player[0].armorhigh, &player[0].armorlow);
  1996 		funpackf(tfile, "Bf Bf Bf", &player[0].protectionhead, &player[0].protectionhigh, &player[0].protectionlow);
  1997 		funpackf(tfile, "Bf Bf Bf", &player[0].metalhead, &player[0].metalhigh, &player[0].metallow);
  1998 		funpackf(tfile, "Bf Bf", &player[0].power, &player[0].speedmult);
  1999 
  2000 		funpackf(tfile, "Bi", &player[0].numclothes);
  2001 
  2002 		if(mapvers>=9)
  2003 		{
  2004 			funpackf(tfile, "Bi Bi", &player[0].whichskin, &player[0].creature);
  2005 		}
  2006 		else
  2007 		{
  2008 			player[0].whichskin=0;
  2009 			player[0].creature=rabbittype;
  2010 		}
  2011 
  2012 		for(i=0;i<max_dialogues;i++)
  2013 		{
  2014 			for(j=0;j<max_dialoguelength;j++)
  2015 			{
  2016 				for(k=0;k<128;k++)
  2017 				{
  2018 					dialoguetext[i][j][k]='\0';
  2019 				}
  2020 				for(k=0;k<64;k++)
  2021 				{
  2022 					dialoguename[i][j][k]='\0';
  2023 				}
  2024 			}
  2025 		}
  2026 
  2027 		player[0].lastattack=-1;
  2028 		player[0].lastattack2=-1;
  2029 		player[0].lastattack3=-1;
  2030 
  2031 		if(mapvers>=8)
  2032 		{
  2033 			funpackf(tfile, "Bi", &numdialogues);
  2034 			if(numdialogues)
  2035 			{
  2036 				for(k=0;k<numdialogues;k++)
  2037 				{
  2038 					funpackf(tfile, "Bi", &numdialogueboxes[k]);
  2039 					funpackf(tfile, "Bi", &dialoguetype[k]);
  2040 					for(l=0;l<10;l++)
  2041 					{
  2042 						funpackf(tfile, "Bf Bf Bf", &participantlocation[k][l].x, &participantlocation[k][l].y, &participantlocation[k][l].z);
  2043 						funpackf(tfile, "Bf", &participantrotation[k][l]);
  2044 					}
  2045 					if(numdialogueboxes)
  2046 					{
  2047 						for(l=0;l<numdialogueboxes[k];l++)
  2048 						{
  2049 							funpackf(tfile, "Bi", &dialogueboxlocation[k][l]);
  2050 							funpackf(tfile, "Bf", &dialogueboxcolor[k][l][0]);
  2051 							funpackf(tfile, "Bf", &dialogueboxcolor[k][l][1]);
  2052 							funpackf(tfile, "Bf", &dialogueboxcolor[k][l][2]);
  2053 							funpackf(tfile, "Bi", &dialogueboxsound[k][l]);
  2054 
  2055 							bool doneread;
  2056 
  2057 							funpackf(tfile, "Bi",&templength);
  2058 							if(templength>128||templength<=0)templength=128;
  2059 							for(m=0;m<templength;m++){
  2060 								funpackf(tfile, "Bb", &dialoguetext[k][l][m]);
  2061 								if(dialoguetext[k][l][m]=='\0')break;
  2062 							}
  2063 
  2064 							funpackf(tfile, "Bi",&templength);
  2065 							if(templength>64||templength<=0)templength=64;
  2066 							for(m=0;m<templength;m++){
  2067 								funpackf(tfile, "Bb", &dialoguename[k][l][m]);
  2068 								if(dialoguename[k][l][m]=='\0'){
  2069 									break;
  2070 								}
  2071 							}
  2072 							funpackf(tfile, "Bf Bf Bf", &dialoguecamera[k][l].x, &dialoguecamera[k][l].y, &dialoguecamera[k][l].z);
  2073 							funpackf(tfile, "Bi", &participantfocus[k][l]);
  2074 							funpackf(tfile, "Bi", &participantaction[k][l]);
  2075 
  2076 							for(m=0;m<10;m++)
  2077 								funpackf(tfile, "Bf Bf Bf", &participantfacing[k][l][m].x, &participantfacing[k][l][m].y, &participantfacing[k][l][m].z);
  2078 
  2079 							funpackf(tfile, "Bf Bf",&dialoguecamerarotation[k][l],&dialoguecamerarotation2[k][l]);
  2080 						}
  2081 					}
  2082 				}
  2083 			}
  2084 		}
  2085 		else numdialogues=0;
  2086 
  2087 		if(player[0].numclothes)
  2088 		{
  2089 			for(k=0;k<player[0].numclothes;k++)
  2090 			{
  2091 				funpackf(tfile, "Bi", &templength);
  2092 				for(l=0;l<templength;l++)
  2093 					funpackf(tfile, "Bb", &player[0].clothes[k][l]);
  2094 				player[0].clothes[k][templength]='\0';
  2095 				funpackf(tfile, "Bf Bf Bf", &player[0].clothestintr[k], &player[0].clothestintg[k], &player[0].clothestintb[k]);
  2096 			}
  2097 		}
  2098 
  2099 		funpackf(tfile, "Bi", &environment);
  2100 
  2101 		funpackf(tfile, "Bi", &objects.numobjects);
  2102 		if(objects.numobjects)
  2103 		{
  2104 			for(i=0;i<objects.numobjects;i++)
  2105 			{
  2106 				funpackf(tfile, "Bi Bf Bf Bf Bf Bf Bf", &objects.type[i],&objects.rotation[i],&objects.rotation2[i], &objects.position[i].x, &objects.position[i].y, &objects.position[i].z,&objects.scale[i]);
  2107 				if(objects.type[i]==treeleavestype)objects.scale[i]=objects.scale[i-1];
  2108 			}
  2109 		}
  2110 
  2111 		if(mapvers>=7)
  2112 		{
  2113 			funpackf(tfile, "Bi", &numhotspots);
  2114 			if(numhotspots)
  2115 			{
  2116 				for(i=0;i<numhotspots;i++)
  2117 				{
  2118 					funpackf(tfile, "Bi Bf Bf Bf Bf", &hotspottype[i],&hotspotsize[i],&hotspot[i].x,&hotspot[i].y,&hotspot[i].z);
  2119 					funpackf(tfile, "Bi", &templength);
  2120 					if(templength)
  2121 						for(l=0;l<templength;l++)
  2122 							funpackf(tfile, "Bb", &hotspottext[i][l]);
  2123 					hotspottext[i][templength]='\0';
  2124 					if(hotspottype[i]==-111)indemo=1;
  2125 				}
  2126 			}
  2127 		}
  2128 		else numhotspots=0;
  2129 
  2130 		if(visibleloading){loadscreencolor=4; LoadingScreen();}
  2131 
  2132 		if(!stealthloading)
  2133 		{
  2134 			objects.center=0;
  2135 			for(i=0;i<objects.numobjects;i++)
  2136 			{
  2137 				objects.center+=objects.position[i];
  2138 			}
  2139 			objects.center/=objects.numobjects;
  2140 
  2141 
  2142 			if(visibleloading){loadscreencolor=4; LoadingScreen();}
  2143 
  2144 			float maxdistance=0;
  2145 			float tempdist;
  2146 			int whichclosest;
  2147 			for(i=0;i<objects.numobjects;i++)
  2148 			{
  2149 				tempdist=findDistancefast(&objects.center,&objects.position[i]);
  2150 				if(tempdist>maxdistance)
  2151 				{
  2152 					whichclosest=i;
  2153 					maxdistance=tempdist;
  2154 				}
  2155 			}
  2156 			objects.radius=fast_sqrt(maxdistance);
  2157 		}
  2158 
  2159 		if(visibleloading){loadscreencolor=4; LoadingScreen();}
  2160 		//mapcenter=objects.center;
  2161 		//mapradius=objects.radius;
  2162 
  2163 		funpackf(tfile, "Bi", &numplayers);
  2164 		int howmanyremoved=0;
  2165 		bool removeanother=0;
  2166 		if(numplayers>1&&numplayers<maxplayers)
  2167 		{
  2168 			for(i=1;i<numplayers;i++)
  2169 			{
  2170 				if(visibleloading){loadscreencolor=4; LoadingScreen();}
  2171 				removeanother=0;
  2172 
  2173 				funpackf(tfile, "Bi Bi Bf Bf Bf Bi",&player[i-howmanyremoved].whichskin,&player[i-howmanyremoved].creature, &player[i-howmanyremoved].coords.x,&player[i-howmanyremoved].coords.y,&player[i-howmanyremoved].coords.z,&player[i-howmanyremoved].num_weapons);
  2174 				if(mapvers>=5)funpackf(tfile, "Bi", &player[i-howmanyremoved].howactive);
  2175 				else player[i-howmanyremoved].howactive=typeactive;
  2176 				if(mapvers>=3)funpackf(tfile, "Bf",&player[i-howmanyremoved].scale);
  2177 				else player[i-howmanyremoved].scale=-1;
  2178 				if(mapvers>=11)funpackf(tfile, "Bb",&player[i-howmanyremoved].immobile);
  2179 				else player[i-howmanyremoved].immobile=0;
  2180 				if(mapvers>=12)funpackf(tfile, "Bf",&player[i-howmanyremoved].rotation);
  2181 				else player[i-howmanyremoved].rotation=0;
  2182 				player[i-howmanyremoved].targetrotation=player[i-howmanyremoved].rotation;
  2183 				if(player[i-howmanyremoved].num_weapons<0||player[i-howmanyremoved].num_weapons>5){
  2184 					removeanother=1;
  2185 					howmanyremoved++;
  2186 				}
  2187 				if(!removeanother)
  2188 				{
  2189 					if(player[i-howmanyremoved].num_weapons>0&&player[i-howmanyremoved].num_weapons<5)
  2190 					{
  2191 						for(j=0;j<player[i-howmanyremoved].num_weapons;j++)
  2192 						{
  2193 							player[i-howmanyremoved].weaponids[j]=weapons.numweapons;
  2194 							funpackf(tfile, "Bi", &weapons.type[player[i-howmanyremoved].weaponids[j]]);
  2195 							weapons.owner[player[i-howmanyremoved].weaponids[j]]=i;
  2196 							weapons.numweapons++;
  2197 						}
  2198 					}
  2199 					funpackf(tfile, "Bi", &player[i-howmanyremoved].numwaypoints);
  2200 					//player[i-howmanyremoved].numwaypoints=10;
  2201 					for(j=0;j<player[i-howmanyremoved].numwaypoints;j++)
  2202 					{
  2203 						funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].x);
  2204 						funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].y);
  2205 						funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].z);
  2206 						if(mapvers>=5)funpackf(tfile, "Bi", &player[i-howmanyremoved].waypointtype[j]);
  2207 						else player[i-howmanyremoved].waypointtype[j] = wpkeepwalking;
  2208 					}
  2209 
  2210 					funpackf(tfile, "Bi", &player[i-howmanyremoved].waypoint);
  2211 					if(player[i-howmanyremoved].waypoint>player[i-howmanyremoved].numwaypoints-1)player[i-howmanyremoved].waypoint=0;
  2212 
  2213 					funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].armorhead, &player[i-howmanyremoved].armorhigh, &player[i-howmanyremoved].armorlow);
  2214 					funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].protectionhead, &player[i-howmanyremoved].protectionhigh, &player[i-howmanyremoved].protectionlow);
  2215 					funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].metalhead, &player[i-howmanyremoved].metalhigh, &player[i-howmanyremoved].metallow);
  2216 					funpackf(tfile, "Bf Bf", &player[i-howmanyremoved].power, &player[i-howmanyremoved].speedmult);
  2217 
  2218 					if(mapvers>=4)funpackf(tfile, "Bf Bf Bf Bf", &headprop, &bodyprop, &armprop, &legprop);
  2219 					else
  2220 					{
  2221 						headprop=1;
  2222 						bodyprop=1;
  2223 						armprop=1;
  2224 						legprop=1;
  2225 					}
  2226 					if(player[i-howmanyremoved].creature==wolftype)
  2227 					{
  2228 						player[i-howmanyremoved].proportionhead=1.1*headprop;
  2229 						player[i-howmanyremoved].proportionbody=1.1*bodyprop;
  2230 						player[i-howmanyremoved].proportionarms=1.1*armprop;
  2231 						player[i-howmanyremoved].proportionlegs=1.1*legprop;
  2232 					}
  2233 
  2234 					if(player[i-howmanyremoved].creature==rabbittype)
  2235 					{
  2236 						player[i-howmanyremoved].proportionhead=1.2*headprop;
  2237 						player[i-howmanyremoved].proportionbody=1.05*bodyprop;
  2238 						player[i-howmanyremoved].proportionarms=1.00*armprop;
  2239 						player[i-howmanyremoved].proportionlegs=1.1*legprop;
  2240 						player[i-howmanyremoved].proportionlegs.y=1.05*legprop;
  2241 					}
  2242 
  2243 					funpackf(tfile, "Bi", &player[i-howmanyremoved].numclothes);
  2244 					if(player[i-howmanyremoved].numclothes)
  2245 					{
  2246 						for(k=0;k<player[i-howmanyremoved].numclothes;k++)
  2247 						{
  2248 							int templength;
  2249 							funpackf(tfile, "Bi", &templength);
  2250 							for(l=0;l<templength;l++)
  2251 								funpackf(tfile, "Bb", &player[i-howmanyremoved].clothes[k][l]);
  2252 							player[i-howmanyremoved].clothes[k][templength]='\0';
  2253 							funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].clothestintr[k], &player[i-howmanyremoved].clothestintg[k], &player[i-howmanyremoved].clothestintb[k]);
  2254 						}
  2255 					}
  2256 				}
  2257 			}
  2258 		}
  2259 		if(visibleloading){loadscreencolor=4; LoadingScreen();}
  2260 
  2261 		numplayers-=howmanyremoved;
  2262 		funpackf(tfile, "Bi", &numpathpoints);
  2263 		if(numpathpoints>30||numpathpoints<0)
  2264 			numpathpoints=0;
  2265 		if(numpathpoints)
  2266 		{
  2267 			for(j=0;j<numpathpoints;j++)
  2268 			{
  2269 				funpackf(tfile, "Bf Bf Bf Bi", &pathpoint[j].x,&pathpoint[j].y,&pathpoint[j].z,&numpathpointconnect[j]);
  2270 				for(k=0;k<numpathpointconnect[j];k++){
  2271 					funpackf(tfile, "Bi", &pathpointconnect[j][k]);
  2272 				}
  2273 			}
  2274 		}
  2275 		if(visibleloading){loadscreencolor=4; LoadingScreen();}
  2276 
  2277 		funpackf(tfile, "Bf Bf Bf Bf", &mapcenter.x,&mapcenter.y,&mapcenter.z,&mapradius);
  2278 
  2279 		SetUpLighting();
  2280 		if(environment!=oldenvironment)Setenvironment(environment);
  2281 		oldenvironment=environment;
  2282 
  2283 		if(!stealthloading)
  2284 		{
  2285 			j=objects.numobjects;
  2286 			objects.numobjects=0;
  2287 			for(i=0;i<j;i++)
  2288 			{
  2289 				//if(objects.type[i]!=spiketype)
  2290 				objects.MakeObject(objects.type[i],objects.position[i],objects.rotation[i],objects.rotation2[i],objects.scale[i]);
  2291 				if(visibleloading){loadscreencolor=4; LoadingScreen();}
  2292 			}
  2293 
  2294 			//if(skyboxtexture){
  2295 			terrain.DoShadows();
  2296 			if(visibleloading){loadscreencolor=4; LoadingScreen();}
  2297 			objects.DoShadows();
  2298 			if(visibleloading){loadscreencolor=4; LoadingScreen();}
  2299 			/*}
  2300 			else terrain.DoLighting();
  2301 			*/
  2302 		}
  2303 
  2304 		fclose(tfile);
  2305 
  2306 		oldlevel=whichlevel;
  2307 
  2308 
  2309 		if(numplayers>maxplayers-1)numplayers=maxplayers-1;
  2310 		for(i=0;i<numplayers;i++)
  2311 		{
  2312 			if(visibleloading){loadscreencolor=4; LoadingScreen();}
  2313 			player[i].burnt=0;
  2314 			player[i].bled=0;
  2315 			player[i].onfire=0;
  2316 			if(i==0||player[i].scale<0)player[i].scale=.2;
  2317 			player[i].skeleton.free=0;
  2318 			player[i].skeleton.id=i;
  2319 			//if(Random()%2==0)player[i].creature=wolftype;
  2320 			//else player[i].creature=rabbittype;
  2321 			if(i==0&&mapvers<9)player[i].creature=rabbittype;
  2322 			if(player[i].creature!=wolftype)player[i].skeleton.Load((char *)":Data:Skeleton:Basic Figure",(char *)":Data:Skeleton:Basic Figurelow",(char *)":Data:Skeleton:Rabbitbelt",(char *)":Data:Models:Body.solid",(char *)":Data:Models:Body2.solid",(char *)":Data:Models:Body3.solid",(char *)":Data:Models:Body4.solid",(char *)":Data:Models:Body5.solid",(char *)":Data:Models:Body6.solid",(char *)":Data:Models:Body7.solid",(char *)":Data:Models:Bodylow.solid",(char *)":Data:Models:Belt.solid",0);
  2323 			else
  2324 			{
  2325 				if(player[i].creature!=wolftype){
  2326 					player[i].skeleton.Load((char *)":Data:Skeleton:Basic Figure",(char *)":Data:Skeleton:Basic Figurelow",(char *)":Data:Skeleton:Rabbitbelt",(char *)":Data:Models:Body.solid",(char *)":Data:Models:Body2.solid",(char *)":Data:Models:Body3.solid",(char *)":Data:Models:Body4.solid",(char *)":Data:Models:Body5.solid",(char *)":Data:Models:Body6.solid",(char *)":Data:Models:Body7.solid",(char *)":Data:Models:Bodylow.solid",(char *)":Data:Models:Belt.solid",1);
  2327 					LoadTexture(":Data:Textures:Belt.png",&player[i].skeleton.drawmodelclothes.textureptr,1,1);
  2328 				}
  2329 				if(player[i].creature==wolftype){
  2330 					player[i].skeleton.Load((char *)":Data:Skeleton:Basic Figure Wolf",(char *)":Data:Skeleton:Basic Figure Wolf Low",(char *)":Data:Skeleton:Rabbitbelt",(char *)":Data:Models:Wolf.solid",(char *)":Data:Models:Wolf2.solid",(char *)":Data:Models:Wolf3.solid",(char *)":Data:Models:Wolf4.solid",(char *)":Data:Models:Wolf5.solid",(char *)":Data:Models:Wolf6.solid",(char *)":Data:Models:Wolf7.solid",(char *)":Data:Models:Wolflow.solid",(char *)":Data:Models:Belt.solid",0);
  2331 				}
  2332 			}
  2333 
  2334 
  2335 			int texsize;
  2336 			texsize=512*512*3/texdetail/texdetail;
  2337 			//if(!player[i].loaded)player[i].skeleton.skinText = new GLubyte[texsize];
  2338 			//player[i].skeleton.skinText.resize(texsize);
  2339 
  2340 			LoadTextureSave(creatureskin[player[i].creature][player[i].whichskin],&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
  2341 
  2342 			if(player[i].numclothes)
  2343 			{
  2344 				for(j=0;j<player[i].numclothes;j++)
  2345 				{
  2346 					tintr=player[i].clothestintr[j];
  2347 					tintg=player[i].clothestintg[j];
  2348 					tintb=player[i].clothestintb[j];
  2349 					AddClothes((char *)player[i].clothes[j],0,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
  2350 				}
  2351 				player[i].DoMipmaps(5,0,0,player[i].skeleton.skinsize,player[i].skeleton.skinsize);
  2352 			}
  2353 
  2354 			player[i].currentanimation=bounceidleanim;
  2355 			player[i].targetanimation=bounceidleanim;
  2356 			player[i].currentframe=0;
  2357 			player[i].targetframe=1;
  2358 			player[i].target=0;
  2359 			player[i].speed=1+(float)(Random()%100)/1000;
  2360 			if(difficulty==0)player[i].speed-=.2;
  2361 			if(difficulty==1)player[i].speed-=.1;
  2362 
  2363 			player[i].velocity=0;
  2364 			player[i].oldcoords=player[i].coords;
  2365 			player[i].realoldcoords=player[i].coords;
  2366 
  2367 			player[i].id=i;
  2368 			player[i].skeleton.id=i;
  2369 			player[i].updatedelay=0;
  2370 			player[i].normalsupdatedelay=0;
  2371 
  2372 			player[i].aitype=passivetype;
  2373 			player[i].aitarget=0;
  2374 			player[i].madskills=0;
  2375 
  2376 			if(i==0)
  2377 			{
  2378 				player[i].proportionhead=1.2;
  2379 				player[i].proportionbody=1.05;
  2380 				player[i].proportionarms=1.00;
  2381 				player[i].proportionlegs=1.1;
  2382 				player[i].proportionlegs.y=1.05;
  2383 			}
  2384 			player[i].headless=0;
  2385 			player[i].currentoffset=0;
  2386 			player[i].targetoffset=0;
  2387 			/*player[i].armorhead=1;
  2388 			player[i].armorhigh=1;
  2389 			player[i].armorlow=1;
  2390 			player[i].protectionhead=1;
  2391 			player[i].protectionhigh=1;
  2392 			player[i].protectionlow=1;
  2393 			player[i].metalhead=1;
  2394 			player[i].metalhigh=1;
  2395 			player[i].metallow=1;
  2396 			player[i].power=1;
  2397 			player[i].speedmult=1;*/
  2398 
  2399 			player[i].damagetolerance=200;
  2400 
  2401 			if(player[i].creature==wolftype)
  2402 			{
  2403 				/*player[i].proportionhead=1.1;
  2404 				player[i].proportionbody=1.1;
  2405 				player[i].proportionarms=1.1;
  2406 				player[i].proportionlegs=1.1;
  2407 				player[i].proportionlegs.y=1.1;*/
  2408 				if(i==0||player[i].scale<0)player[i].scale=.23;
  2409 
  2410 				player[i].damagetolerance=300;
  2411 			}
  2412 
  2413 			if(visibleloading){loadscreencolor=4; LoadingScreen();}
  2414 			if(cellophane)
  2415 			{
  2416 				player[i].proportionhead.z=0;
  2417 				player[i].proportionbody.z=0;
  2418 				player[i].proportionarms.z=0;
  2419 				player[i].proportionlegs.z=0;
  2420 			}
  2421 
  2422 			player[i].tempanimation.Load((char *)":Data:Animations:Tempanim",0,0);
  2423 
  2424 			player[i].headmorphness=0;
  2425 			player[i].targetheadmorphness=1;
  2426 			player[i].headmorphstart=0;
  2427 			player[i].headmorphend=0;
  2428 
  2429 			player[i].pausetime=0;
  2430 
  2431 			player[i].dead=0;
  2432 			player[i].jumppower=5;
  2433 			player[i].damage=0;
  2434 			player[i].permanentdamage=0;
  2435 			player[i].superpermanentdamage=0;
  2436 
  2437 			player[i].forwardkeydown=0;
  2438 			player[i].leftkeydown=0;
  2439 			player[i].backkeydown=0;
  2440 			player[i].rightkeydown=0;
  2441 			player[i].jumpkeydown=0;
  2442 			player[i].crouchkeydown=0;
  2443 			player[i].throwkeydown=0;
  2444 
  2445 			player[i].collided=-10;
  2446 			player[i].loaded=1;
  2447 			player[i].bloodloss=0;
  2448 			player[i].weaponactive=-1;
  2449 			player[i].weaponstuck=-1;
  2450 			player[i].bleeding=0;
  2451 			player[i].deathbleeding=0;
  2452 			player[i].stunned=0;
  2453 			player[i].hasvictim=0;
  2454 			player[i].wentforweapon=0;
  2455 		}
  2456 
  2457 		player[0].aitype=playercontrolled;
  2458 		player[0].weaponactive=-1;
  2459 
  2460 		if(difficulty==1)
  2461 		{
  2462 			//player[0].speedmult=1/.9;
  2463 			player[0].power=1/.9;
  2464 		}
  2465 
  2466 		if(difficulty==0)
  2467 		{
  2468 			//player[0].speedmult=1/.8;
  2469 			player[0].power=1/.8;
  2470 		}
  2471 
  2472 		//player[0].weaponstuck=1;
  2473 
  2474 		if(difficulty==1)player[0].damagetolerance=250;
  2475 		if(difficulty==0)player[0].damagetolerance=300;
  2476 		if(difficulty==0)player[0].armorhead*=1.5;
  2477 		if(difficulty==0)player[0].armorhigh*=1.5;
  2478 		if(difficulty==0)player[0].armorlow*=1.5;
  2479 		cameraloc=player[0].coords;
  2480 		cameraloc.y+=5;
  2481 		rotation=player[0].rotation;
  2482 
  2483 		hawkcoords=player[0].coords;
  2484 		hawkcoords.y+=30;
  2485 
  2486 		if(visibleloading){loadscreencolor=4; LoadingScreen();}
  2487 		//weapons.numweapons=numplayers;
  2488 		for(i=0;i<weapons.numweapons;i++)
  2489 		{
  2490 			weapons.bloody[i]=0;
  2491 			weapons.blooddrip[i]=0;
  2492 			weapons.blooddripdelay[i]=0;
  2493 			weapons.onfire[i]=0;
  2494 			weapons.flamedelay[i]=0;
  2495 			weapons.damage[i]=0;
  2496 			//weapons.type[i]=sword;
  2497 			if(weapons.type[i]==sword){
  2498 				weapons.mass[i]=1.5;
  2499 				weapons.tipmass[i]=1;
  2500 				weapons.length[i]=.8;
  2501 			}
  2502 			if(weapons.type[i]==staff){
  2503 				weapons.mass[i]=2;
  2504 				weapons.tipmass[i]=1;
  2505 				weapons.length[i]=1.5;
  2506 			}
  2507 			if(weapons.type[i]==knife){
  2508 				weapons.mass[i]=1;
  2509 				weapons.tipmass[i]=1.2;
  2510 				weapons.length[i]=.25;
  2511 			}
  2512 			weapons.position[i]=-1000;
  2513 			weapons.tippoint[i]=-1000;
  2514 		}
  2515 
  2516 /*		for(i=0;i<32;i++){
  2517 			//if(i<16||i>20)
  2518 			OPENAL_StopSound(i);
  2519 		}
  2520 */
  2521 		LOG("Starting background music...");
  2522 
  2523 		OPENAL_StopSound(OPENAL_ALL);
  2524 		if(environment==snowyenvironment)
  2525 		{
  2526 			if(ambientsound)
  2527 			{
  2528 				PlayStreamEx(stream_wind, strm[stream_wind], NULL, true);
  2529 				OPENAL_SetPaused(channels[stream_wind], false);
  2530 				OPENAL_SetVolume(channels[stream_wind], 256);
  2531 			}
  2532 		}
  2533 		else if(environment==desertenvironment)
  2534 		{
  2535 			if(ambientsound)
  2536 			{
  2537 				//PlaySoundEx(desertambient,
  2538 				//	samp[desertambient], NULL, true);
  2539 				PlayStreamEx(stream_desertambient,
  2540 					strm[stream_desertambient], NULL, true);
  2541 				OPENAL_SetPaused(channels[stream_desertambient], false);
  2542 				OPENAL_SetVolume(channels[stream_desertambient], 256);
  2543 			}
  2544 		}
  2545 		else if(environment==grassyenvironment)
  2546 		{
  2547 			if(ambientsound)
  2548 			{
  2549 				//PlaySoundEx(wind, samp[wind], NULL, true);
  2550 				PlayStreamEx(stream_wind, strm[stream_wind], NULL, true);
  2551 				OPENAL_SetPaused(channels[stream_wind], false);
  2552 				OPENAL_SetVolume(channels[stream_wind], 100);
  2553 			}
  2554 		}
  2555 		oldmusicvolume[0]=0;
  2556 		oldmusicvolume[1]=0;
  2557 		oldmusicvolume[2]=0;
  2558 		oldmusicvolume[3]=0;
  2559 
  2560 
  2561 		/*LoadTexture(":Data:Textures:cloud.png",&sprites.cloudtexture,1,1);
  2562 		LoadTexture(":Data:Textures:cloudimpact.png",&sprites.cloudimpacttexture,1,1);
  2563 		LoadTexture(":Data:Textures:bloodparticle.png",&sprites.bloodtexture,1,1);
  2564 		LoadTexture(":Data:Textures:snowflake.png",&sprites.snowflaketexture,1,1);
  2565 		LoadTexture(":Data:Textures:flame.png",&sprites.flametexture,1,1);
  2566 		LoadTexture(":Data:Textures:bloodflame.png",&sprites.bloodflametexture,1,1);
  2567 		LoadTexture(":Data:Textures:smoke.png",&sprites.smoketexture,1,1);
  2568 		LoadTexture(":Data:Textures:shine.png",&sprites.shinetexture,1,0);
  2569 		*/
  2570 
  2571 		if(!firstload)
  2572 		{
  2573 			firstload=1;
  2574 		}
  2575 	}
  2576 	leveltime=0;
  2577 	loadingstuff=0;
  2578 	visibleloading=0;
  2579 }
  2580 
  2581 void	Game::Tick()
  2582 {
  2583 	static int i,k,j,l,m;
  2584 	static XYZ facing,flatfacing,absflatfacing;
  2585 	static XYZ rotatetarget;
  2586 	static bool oldkey;
  2587 	static float oldtargetrotation;
  2588 	static int target, numgood;
  2589 	static XYZ tempcoords1,tempcoords2;
  2590 	static XYZ test;
  2591 	static XYZ test2;
  2592 	static XYZ lowpoint,lowpointtarget,lowpoint2,lowpointtarget2,lowpoint3,lowpointtarget3,lowpoint4,lowpointtarget4,lowpoint5,lowpointtarget5,lowpoint6,lowpointtarget6,lowpoint7,lowpointtarget7,colpoint,colpoint2;
  2593 	static int whichhit;
  2594 	static bool oldjumpkeydown;
  2595 
  2596 	int templength;
  2597 
  2598 	float headprop,bodyprop,armprop,legprop;
  2599 
  2600 	for(i=0;i<15;i++){
  2601 		displaytime[i]+=multiplier;
  2602 	}
  2603 
  2604 	static unsigned char	theKeyMap[16];
  2605 	GetKeys( theKeyMap );
  2606 
  2607 	keyboardfrozen=0;
  2608 
  2609 
  2610 	static bool mainmenutogglekeydown;
  2611 	if(!console){
  2612 		if(mainmenu&&endgame==1)mainmenu=10;
  2613 		if(IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)&&!mainmenutogglekeydown&&(mainmenu==7&&entername)){
  2614 			for(j=0;j<255;j++){
  2615 				displaytext[0][j]=' ';
  2616 			}
  2617 			displaychars[0]=0;
  2618 			displayselected=0;
  2619 			entername=0;
  2620 			mainmenutogglekeydown=1;
  2621 		}
  2622 		if((IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)||(mainmenu==0&&((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY)||(campaign)))&&!oldjumpkeydown&&campaign&&winfreeze))&&!mainmenutogglekeydown&&(!mainmenu||gameon||mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||(mainmenu==7&&!entername)||mainmenu==9||mainmenu==11||mainmenu==13||mainmenu==17||mainmenu==10)){
  2623 			selected=-1;
  2624 			if(mainmenu==1||mainmenu==2||mainmenu==0){
  2625 				if(mainmenu==0&&!winfreeze)mainmenu=2;
  2626 				else if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1)mainmenu=100;
  2627 				else if(mainmenu==0&&winfreeze){
  2628 					/*	if(campaignchoosenext[campaignchoicewhich[whichchoice]]==2)
  2629 					stealthloading=1;
  2630 					else stealthloading=0;
  2631 
  2632 					if(!stealthloading){
  2633 					float gLoc[3]={0,0,0};
  2634 					float vel[3]={0,0,0};
  2635 					OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
  2636 					PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
  2637 					OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  2638 					OPENAL_SetVolume(channels[firestartsound], 256);
  2639 					OPENAL_SetPaused(channels[firestartsound], false);
  2640 					OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
  2641 
  2642 					flashr=1;
  2643 					flashg=0;
  2644 					flashb=0;
  2645 					flashamount=1;
  2646 					flashdelay=1;
  2647 					}
  2648 
  2649 					startbonustotal=0;
  2650 
  2651 					for(i=0;i<campaignnumlevels;i++){
  2652 					levelvisible[i]=0;
  2653 					levelhighlight[i]=0;
  2654 					}
  2655 
  2656 					levelorder[0]=0;
  2657 					levelvisible[0]=1;
  2658 					if(accountcampaignchoicesmade[accountactive])
  2659 					for(i=0;i<accountcampaignchoicesmade[accountactive];i++){
  2660 					levelorder[i+1]=campaignnextlevel[levelorder[i]][accountcampaignchoices[accountactive][i]];
  2661 					levelvisible[levelorder[i+1]]=1;
  2662 					}
  2663 					int whichlevelstart;
  2664 					whichlevelstart=accountcampaignchoicesmade[accountactive]-1;
  2665 					if(whichlevelstart<0){
  2666 					campaignchoicenum=1;
  2667 					campaignchoicewhich[0]=0;
  2668 					}
  2669 					else
  2670 					{
  2671 					campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
  2672 					if(campaignchoicenum)
  2673 					for(i=0;i<campaignchoicenum;i++){
  2674 					campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
  2675 					levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
  2676 					levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
  2677 					}
  2678 					}
  2679 
  2680 					loading=2;
  2681 					loadtime=0;
  2682 					targetlevel=7;
  2683 					if(firstload)TickOnceAfter();
  2684 					if(!firstload)LoadStuff();
  2685 					//else {
  2686 					for(i=0;i<255;i++){
  2687 					mapname[i]='\0';
  2688 					}
  2689 					mapname[0]=':';
  2690 					mapname[1]='D';
  2691 					mapname[2]='a';
  2692 					mapname[3]='t';
  2693 					mapname[4]='a';
  2694 					mapname[5]=':';
  2695 					mapname[6]='M';
  2696 					mapname[7]='a';
  2697 					mapname[8]='p';
  2698 					mapname[9]='s';
  2699 					mapname[10]=':';
  2700 
  2701 					//accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
  2702 					//accountcampaignchoicesmade[accountactive]++;
  2703 
  2704 
  2705 					strcat(mapname,campaignmapname[campaignchoicewhich[0]]);
  2706 					whichchoice=0;
  2707 					visibleloading=1;
  2708 					stillloading=1;
  2709 					Loadlevel(mapname);
  2710 					campaign=1;
  2711 					mainmenu=0;
  2712 					gameon=1;
  2713 					OPENAL_SetPaused(channels[music3], true);
  2714 
  2715 					stealthloading=0;*/
  2716 				}
  2717 				else if(mainmenu==1||mainmenu==2)mainmenu=0;
  2718 				if(mainmenu&&musictoggle){
  2719 					if(mainmenu==1||mainmenu==2||mainmenu==100){
  2720 						OPENAL_SetFrequency(OPENAL_ALL, 0.001);
  2721 						PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
  2722 						OPENAL_SetPaused(channels[stream_music3], false);
  2723 						OPENAL_SetVolume(channels[stream_music3], 256);
  2724 						OPENAL_SetPaused(channels[music1], true);
  2725 					}
  2726 				}
  2727 				if(!mainmenu){
  2728 					OPENAL_SetPaused(channels[stream_music3], true);
  2729 					OPENAL_SetPaused(channels[music1], false);
  2730 				}
  2731 			}
  2732 			if(mainmenu==3){
  2733 				float gLoc[3]={0,0,0};
  2734 				float vel[3]={0,0,0};
  2735 				OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  2736 				PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
  2737 				OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  2738 				OPENAL_SetVolume(channels[fireendsound], 256);
  2739 				OPENAL_SetPaused(channels[fireendsound], false);
  2740 				OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  2741 
  2742 				flashr=1;
  2743 				flashg=0;
  2744 				flashb=0;
  2745 				flashamount=1;
  2746 				flashdelay=1;
  2747 
  2748 				if(newdetail>2)newdetail=detail;
  2749 				if(newdetail<0)newdetail=detail;
  2750 				if(newscreenwidth<0)newscreenwidth=screenwidth;
  2751 				if(newscreenheight<0)newscreenheight=screenheight;
  2752 
  2753 				ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
  2754 				opstream << "Screenwidth:\n";
  2755 				opstream << newscreenwidth;
  2756 				opstream << "\nScreenheight:\n";
  2757 				opstream << newscreenheight;
  2758 				opstream << "\nMouse sensitivity:\n";
  2759 				opstream << usermousesensitivity;
  2760 				opstream << "\nBlur(0,1):\n";
  2761 				opstream << ismotionblur;
  2762 				opstream << "\nOverall Detail(0,1,2) higher=better:\n";
  2763 				opstream << newdetail;
  2764 				opstream << "\nFloating jump:\n";
  2765 				opstream << floatjump;
  2766 				opstream << "\nMouse jump:\n";
  2767 				opstream << mousejump;
  2768 				opstream << "\nAmbient sound:\n";
  2769 				opstream << ambientsound;
  2770 				opstream << "\nBlood (0,1,2):\n";
  2771 				opstream << bloodtoggle;
  2772 				opstream << "\nAuto slomo:\n";
  2773 				opstream << autoslomo;
  2774 				opstream << "\nFoliage:\n";
  2775 				opstream << foliage;
  2776 				opstream << "\nMusic:\n";
  2777 				opstream << musictoggle;
  2778 				opstream << "\nTrilinear:\n";
  2779 				opstream << trilinear;
  2780 				opstream << "\nDecals(shadows,blood puddles,etc):\n";
  2781 				opstream << decals;
  2782 				opstream << "\nInvert mouse:\n";
  2783 				opstream << invertmouse;
  2784 				opstream << "\nGamespeed:\n";
  2785 				if(oldgamespeed==0)oldgamespeed=1;
  2786 				opstream << oldgamespeed;
  2787 				opstream << "\nDifficulty(0,1,2) higher=harder:\n";
  2788 				opstream << difficulty;
  2789 				opstream << "\nDamage effects(blackout, doublevision):\n";
  2790 				opstream << damageeffects;
  2791 				opstream << "\nText:\n";
  2792 				opstream << texttoggle;
  2793 				opstream << "\nDebug:\n";
  2794 				opstream << debugmode;
  2795 				opstream << "\nVBL Sync:\n";
  2796 				opstream << vblsync;
  2797 				opstream << "\nShow Points:\n";
  2798 				opstream << showpoints;
  2799 				opstream << "\nAlways Blur:\n";
  2800 				opstream << alwaysblur;
  2801 				opstream << "\nImmediate mode (turn on on G5):\n";
  2802 				opstream << immediate;
  2803 				opstream << "\nVelocity blur:\n";
  2804 				opstream << velocityblur;
  2805 			    opstream << "\nVolume:\n";
  2806 		        opstream << volume;
  2807 				opstream << "\nForward key:\n";
  2808 				opstream << KeyToChar(forwardkey);
  2809 				opstream << "\nBack key:\n";
  2810 				opstream << KeyToChar(backkey);
  2811 				opstream << "\nLeft key:\n";
  2812 				opstream << KeyToChar(leftkey);
  2813 				opstream << "\nRight key:\n";
  2814 				opstream << KeyToChar(rightkey);
  2815 				opstream << "\nJump key:\n";
  2816 				opstream << KeyToChar(jumpkey);
  2817 				opstream << "\nCrouch key:\n";
  2818 				opstream << KeyToChar(crouchkey);
  2819 				opstream << "\nDraw key:\n";
  2820 				opstream << KeyToChar(drawkey);
  2821 				opstream << "\nThrow key:\n";
  2822 				opstream << KeyToChar(throwkey);
  2823 				opstream << "\nAttack key:\n";
  2824 				opstream << KeyToChar(attackkey);
  2825 				opstream << "\nChat key:\n";
  2826 				opstream << KeyToChar(chatkey);
  2827 				opstream.close();
  2828 			}
  2829 			if(mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==9||mainmenu==13||mainmenu==10||mainmenu==11||mainmenu==100){
  2830 				float gLoc[3]={0,0,0};
  2831 				float vel[3]={0,0,0};
  2832 				OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  2833 				PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
  2834 				OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  2835 				OPENAL_SetVolume(channels[fireendsound], 256);
  2836 				OPENAL_SetPaused(channels[fireendsound], false);
  2837 				OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  2838 
  2839 				flashr=1;
  2840 				flashg=0;
  2841 				flashb=0;
  2842 				flashamount=1;
  2843 				flashdelay=1;
  2844 			}
  2845 			if(mainmenu==3&&gameon)mainmenu=2;
  2846 			if(mainmenu==3&&!gameon)mainmenu=1;
  2847 			if(mainmenu==5&&gameon)mainmenu=2;
  2848 			if(mainmenu==5&&!gameon)mainmenu=1;
  2849 			if(mainmenu==4)mainmenu=3;
  2850 			if(mainmenu==6)mainmenu=5;
  2851 			if(mainmenu==7)mainmenu=1;
  2852 			if(mainmenu==9)mainmenu=5;
  2853 			if(mainmenu==11)mainmenu=5;
  2854 			if(mainmenu==13)mainmenu=12;
  2855 			if(mainmenu==10)mainmenu=5;
  2856 			if(mainmenu==100){
  2857 				mainmenu=5;
  2858 				gameon=0;
  2859 				winfreeze=0;
  2860 			}
  2861 			mainmenutogglekeydown=1;
  2862 		}
  2863 		if(!IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)){
  2864 			mainmenutogglekeydown=0;
  2865 		}
  2866 	}
  2867 
  2868 	/*static bool minimaptogglekeydown;
  2869 	if(IsKeyDown(theKeyMap, MAC_TAB_KEY)&&!minimaptogglekeydown){
  2870 	minimap=1-minimap;
  2871 	minimaptogglekeydown=1;
  2872 	}
  2873 	if(!IsKeyDown(theKeyMap, MAC_TAB_KEY)){
  2874 	minimaptogglekeydown=0;
  2875 	}
  2876 	*/
  2877 
  2878 	static bool minimaptogglekeydown;
  2879 	if(IsKeyDown(theKeyMap, MAC_TAB_KEY)&&!minimaptogglekeydown&&tutoriallevel){
  2880 		if(tutorialstage!=51)
  2881 			tutorialstagetime=tutorialmaxtime;
  2882 		PlaySoundEx( consolefailsound, samp[consolefailsound], NULL, true);
  2883 		OPENAL_SetVolume(channels[consolefailsound], 128);
  2884 		OPENAL_SetPaused(channels[consolefailsound], false);
  2885 		minimaptogglekeydown=1;
  2886 	}
  2887 	if(!IsKeyDown(theKeyMap, MAC_TAB_KEY)){
  2888 		minimaptogglekeydown=0;
  2889 	}
  2890 
  2891 	if(mainmenu){
  2892 		//menu buttons
  2893 		if(mainmenu==1||mainmenu==2){
  2894 			if(Button()&&!oldbutton&&selected==1){
  2895 				if(!gameon){
  2896 					float gLoc[3]={0,0,0};
  2897 					float vel[3]={0,0,0};
  2898 					OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
  2899 					PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
  2900 					OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  2901 					OPENAL_SetVolume(channels[firestartsound], 256);
  2902 					OPENAL_SetPaused(channels[firestartsound], false);
  2903 					OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
  2904 
  2905 					flashr=1;
  2906 					flashg=0;
  2907 					flashb=0;
  2908 					flashamount=1;
  2909 					flashdelay=1;
  2910 
  2911 					//new game
  2912 					if(accountactive!=-1)mainmenu=5;
  2913 					else mainmenu=7;
  2914 					/*
  2915 					startbonustotal=0;
  2916 
  2917 					loading=2;
  2918 					loadtime=0;
  2919 					if(firstload)TickOnceAfter();
  2920 					if(!firstload)LoadStuff();
  2921 					else {
  2922 					Loadlevel(0);
  2923 					}
  2924 					mainmenu=0;
  2925 					gameon=1;
  2926 					OPENAL_SetPaused(channels[music3], true);	*/
  2927 				}
  2928 				else
  2929 				{
  2930 					//resume
  2931 					mainmenu=0;
  2932 					OPENAL_SetPaused(channels[stream_music3], true);
  2933 					OPENAL_SetPaused(channels[music1], false);
  2934 				}
  2935 			}
  2936 
  2937 			if(Button()&&!oldbutton&&selected==2){
  2938 				float gLoc[3]={0,0,0};
  2939 				float vel[3]={0,0,0};
  2940 				OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
  2941 				PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
  2942 				OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  2943 				OPENAL_SetVolume(channels[firestartsound], 256);
  2944 				OPENAL_SetPaused(channels[firestartsound], false);
  2945 				OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
  2946 
  2947 				flashr=1;
  2948 				flashg=0;
  2949 				flashb=0;
  2950 				flashamount=1;
  2951 				flashdelay=1;
  2952 
  2953 				//options
  2954 
  2955 				mainmenu=3;
  2956 
  2957 				if(newdetail>2)newdetail=detail;
  2958 				if(newdetail<0)newdetail=detail;
  2959 				if(newscreenwidth>3000)newscreenwidth=screenwidth;
  2960 				if(newscreenwidth<0)newscreenwidth=screenwidth;
  2961 				if(newscreenheight>3000)newscreenheight=screenheight;
  2962 				if(newscreenheight<0)newscreenheight=screenheight;
  2963 			}
  2964 
  2965 			if(Button()&&!oldbutton&&selected==3){
  2966 				float gLoc[3]={0,0,0};
  2967 				float vel[3]={0,0,0};
  2968 				OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  2969 				PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
  2970 				OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  2971 				OPENAL_SetVolume(channels[fireendsound], 256);
  2972 				OPENAL_SetPaused(channels[fireendsound], false);
  2973 				OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  2974 
  2975 				flashr=1;
  2976 				flashg=0;
  2977 				flashb=0;
  2978 				flashamount=1;
  2979 				flashdelay=1;
  2980 
  2981 				if(!gameon){
  2982 					//quit
  2983 					tryquit=1;
  2984 					OPENAL_SetPaused(channels[stream_music3], true);
  2985 				}
  2986 				else{
  2987 					//end game
  2988 					gameon=0;
  2989 					mainmenu=1;
  2990 				}
  2991 			}
  2992 			if(Button())oldbutton=1;
  2993 			else oldbutton=0;
  2994 		}
  2995 
  2996 		if(mainmenu==3){
  2997 			if(Button()&&!oldbutton&&selected!=-1){
  2998 				float gLoc[3]={0,0,0};
  2999 				float vel[3]={0,0,0};
  3000 				OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
  3001 				PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
  3002 				OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  3003 				OPENAL_SetVolume(channels[firestartsound], 256);
  3004 				OPENAL_SetPaused(channels[firestartsound], false);
  3005 				OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
  3006 			}
  3007 			if(Button()&&!oldbutton&&selected==0){
  3008 			
  3009 				extern SDL_Rect **resolutions;
  3010 				bool isCustomResolution = true;
  3011 				bool found = false;
  3012 				for (int i = 0; (!found) && (resolutions[i]); i++)
  3013 				{
  3014 					if ((resolutions[i]->w == screenwidth) && (resolutions[i]->h == screenwidth))
  3015 						isCustomResolution = false;
  3016 
  3017 					if ((resolutions[i]->w == newscreenwidth) && (resolutions[i]->h == newscreenheight))
  3018 					{
  3019 						i++;
  3020 						if (resolutions[i] != NULL)
  3021 						{
  3022 							newscreenwidth = (int) resolutions[i]->w;
  3023 							newscreenheight = (int) resolutions[i]->h;
  3024 						}
  3025 						else if (isCustomResolution)
  3026 						{
  3027 							if ((screenwidth == newscreenwidth) && (screenheight == newscreenheight))
  3028 							{
  3029 								newscreenwidth = (int) resolutions[0]->w;
  3030 								newscreenheight = (int) resolutions[0]->h;
  3031 							}
  3032 							else
  3033 							{
  3034 								newscreenwidth = screenwidth;
  3035 								newscreenheight = screenheight;
  3036 							}
  3037 						}
  3038 						else
  3039 						{
  3040 							newscreenwidth = (int) resolutions[0]->w;
  3041 							newscreenheight = (int) resolutions[0]->h;
  3042 						}
  3043 						found = true;
  3044 					}
  3045 				}
  3046 
  3047 				if (!found)
  3048 				{
  3049 					newscreenwidth = (int) resolutions[0]->w;
  3050 					newscreenheight = (int) resolutions[0]->h;
  3051 				}
  3052 
  3053 				
  3054 			}
  3055 			if(Button()&&!oldbutton&&selected==1){
  3056 				newdetail++;
  3057 				if(newdetail>2)newdetail=0;
  3058 			}
  3059 			if(Button()&&!oldbutton&&selected==2){
  3060 				bloodtoggle++;
  3061 				if(bloodtoggle>2)bloodtoggle=0;
  3062 			}
  3063 			if(Button()&&!oldbutton&&selected==3){
  3064 				difficulty++;
  3065 				if(difficulty>2)difficulty=0;
  3066 			}
  3067 			if(Button()&&!oldbutton&&selected==4){
  3068 				ismotionblur=1-ismotionblur;
  3069 			}
  3070 			if(Button()&&!oldbutton&&selected==5){
  3071 				decals=1-decals;
  3072 			}
  3073 			if(Button()&&!oldbutton&&selected==6){
  3074 				musictoggle=1-musictoggle;
  3075 
  3076 				if(!musictoggle){
  3077 					OPENAL_SetPaused(channels[music1], true);
  3078 					OPENAL_SetPaused(channels[stream_music2], true);
  3079 					OPENAL_SetPaused(channels[stream_music3], true);
  3080 
  3081 					for(i=0;i<4;i++){
  3082 						oldmusicvolume[i]=0;
  3083 						musicvolume[i]=0;
  3084 					}
  3085 				}
  3086 
  3087 				if(musictoggle){
  3088 					PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
  3089 					OPENAL_SetPaused(channels[stream_music3], false);
  3090 					OPENAL_SetVolume(channels[stream_music3], 256);
  3091 				}
  3092 			}
  3093 			if(Button()&&!oldbutton&&selected==9){
  3094 				invertmouse=1-invertmouse;
  3095 			}
  3096 			if(Button()&&!oldbutton&&selected==10){
  3097 				usermousesensitivity+=.2;
  3098 				if(usermousesensitivity>2)usermousesensitivity=.2;
  3099 			}
  3100 			if(Button()&&!oldbutton&&selected==11){
  3101 				volume+=.1f;
  3102 				if(volume>1.0001f)volume=0;
  3103 				OPENAL_SetSFXMasterVolume((int)(volume*255));
  3104 			}
  3105 			if(Button()&&!oldbutton&&selected==7){
  3106 				/*float gLoc[3]={0,0,0};
  3107 				float vel[3]={0,0,0};
  3108 				OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
  3109 				PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
  3110 				OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  3111 				OPENAL_SetVolume(channels[firestartsound], 256);
  3112 				OPENAL_SetPaused(channels[firestartsound], false);
  3113 				OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
  3114 				*/
  3115 				flashr=1;
  3116 				flashg=0;
  3117 				flashb=0;
  3118 				flashamount=1;
  3119 				flashdelay=1;
  3120 
  3121 				//options
  3122 
  3123 				mainmenu=4;
  3124 				keyselect=-1;
  3125 			}
  3126 			if(Button()&&!oldbutton&&selected==8){
  3127 				float gLoc[3]={0,0,0};
  3128 				float vel[3]={0,0,0};
  3129 				OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  3130 				PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
  3131 				OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  3132 				OPENAL_SetVolume(channels[fireendsound], 256);
  3133 				OPENAL_SetPaused(channels[fireendsound], false);
  3134 				OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  3135 
  3136 				flashr=1;
  3137 				flashg=0;
  3138 				flashb=0;
  3139 				flashamount=1;
  3140 				flashdelay=1;
  3141 
  3142 				if(newdetail>2)newdetail=detail;
  3143 				if(newdetail<0)newdetail=detail;
  3144 				if(newscreenwidth<0)newscreenwidth=screenwidth;
  3145 				if(newscreenheight<0)newscreenheight=screenheight;
  3146 
  3147 
  3148 				ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
  3149 				opstream << "Screenwidth:\n";
  3150 				opstream << newscreenwidth;
  3151 				opstream << "\nScreenheight:\n";
  3152 				opstream << newscreenheight;
  3153 				opstream << "\nMouse sensitivity:\n";
  3154 				opstream << usermousesensitivity;
  3155 				opstream << "\nBlur(0,1):\n";
  3156 				opstream << ismotionblur;
  3157 				opstream << "\nOverall Detail(0,1,2) higher=better:\n";
  3158 				opstream << newdetail;
  3159 				opstream << "\nFloating jump:\n";
  3160 				opstream << floatjump;
  3161 				opstream << "\nMouse jump:\n";
  3162 				opstream << mousejump;
  3163 				opstream << "\nAmbient sound:\n";
  3164 				opstream << ambientsound;
  3165 				opstream << "\nBlood (0,1,2):\n";
  3166 				opstream << bloodtoggle;
  3167 				opstream << "\nAuto slomo:\n";
  3168 				opstream << autoslomo;
  3169 				opstream << "\nFoliage:\n";
  3170 				opstream << foliage;
  3171 				opstream << "\nMusic:\n";
  3172 				opstream << musictoggle;
  3173 				opstream << "\nTrilinear:\n";
  3174 				opstream << trilinear;
  3175 				opstream << "\nDecals(shadows,blood puddles,etc):\n";
  3176 				opstream << decals;
  3177 				opstream << "\nInvert mouse:\n";
  3178 				opstream << invertmouse;
  3179 				opstream << "\nGamespeed:\n";
  3180 				if(oldgamespeed==0)oldgamespeed=1;
  3181 				opstream << oldgamespeed;
  3182 				opstream << "\nDifficulty(0,1,2) higher=harder:\n";
  3183 				opstream << difficulty;
  3184 				opstream << "\nDamage effects(blackout, doublevision):\n";
  3185 				opstream << damageeffects;
  3186 				opstream << "\nText:\n";
  3187 				opstream << texttoggle;
  3188 				opstream << "\nDebug:\n";
  3189 				opstream << debugmode;
  3190 				opstream << "\nVBL Sync:\n";
  3191 				opstream << vblsync;
  3192 				opstream << "\nShow Points:\n";
  3193 				opstream << showpoints;
  3194 				opstream << "\nAlways Blur:\n";
  3195 				opstream << alwaysblur;
  3196 				opstream << "\nImmediate mode (turn on on G5):\n";
  3197 				opstream << immediate;
  3198 				opstream << "\nVelocity blur:\n";
  3199 				opstream << velocityblur;
  3200 			    opstream << "\nVolume:\n";
  3201 		        opstream << volume;
  3202 				opstream << "\nForward key:\n";
  3203 				opstream << KeyToChar(forwardkey);
  3204 				opstream << "\nBack key:\n";
  3205 				opstream << KeyToChar(backkey);
  3206 				opstream << "\nLeft key:\n";
  3207 				opstream << KeyToChar(leftkey);
  3208 				opstream << "\nRight key:\n";
  3209 				opstream << KeyToChar(rightkey);
  3210 				opstream << "\nJump key:\n";
  3211 				opstream << KeyToChar(jumpkey);
  3212 				opstream << "\nCrouch key:\n";
  3213 				opstream << KeyToChar(crouchkey);
  3214 				opstream << "\nDraw key:\n";
  3215 				opstream << KeyToChar(drawkey);
  3216 				opstream << "\nThrow key:\n";
  3217 				opstream << KeyToChar(throwkey);
  3218 				opstream << "\nAttack key:\n";
  3219 				opstream << KeyToChar(attackkey);
  3220 				opstream << "\nChat key:\n";
  3221 				opstream << KeyToChar(chatkey);
  3222 				opstream.close();
  3223 
  3224 				if(mainmenu==3&&gameon)mainmenu=2;
  3225 				if(mainmenu==3&&!gameon)mainmenu=1;
  3226 			}
  3227 			if(Button())oldbutton=1;
  3228 			else oldbutton=0;
  3229 		}
  3230 		if(mainmenu==4){
  3231 			if(Button()&&!oldbutton&&selected!=-1&&keyselect==-1){
  3232 				float gLoc[3]={0,0,0};
  3233 				float vel[3]={0,0,0};
  3234 				OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
  3235 				PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
  3236 				OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  3237 				OPENAL_SetVolume(channels[firestartsound], 256);
  3238 				OPENAL_SetPaused(channels[firestartsound], false);
  3239 				OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
  3240 			}
  3241 			if(Button()&&!oldbutton&&selected<9&&keyselect==-1){
  3242 				keyselect=selected;
  3243 				oldbuttons[0]=1;
  3244 				oldbuttons[1]=1;
  3245 				oldbuttons[2]=1;
  3246 			}
  3247 			if(keyselect!=-1){
  3248 				for(i=0;i<3;i++)
  3249 					if(!buttons[i]&&!oldbutton&&!Button())oldbuttons[i]=0;
  3250 				for(i=0;i<140;i++){
  3251 					if((IsKeyDown(theKeyMap, i)||(buttons[0]&&!oldbuttons[0]&&!oldbutton)||(buttons[1]&&!oldbuttons[1]&&!oldbutton))&&keyselect!=-1){
  3252 						if(i!=MAC_ESCAPE_KEY&&(strcmp(KeyToChar(i),"unknown")||(buttons[0]&&!oldbuttons[0]&&!oldbutton)||(buttons[1]&&!oldbuttons[1]&&!oldbutton))){
  3253 							float gLoc[3]={0,0,0};
  3254 							float vel[3]={0,0,0};
  3255 							OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  3256 							PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
  3257 							OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  3258 							OPENAL_SetVolume(channels[fireendsound], 256);
  3259 							OPENAL_SetPaused(channels[fireendsound], false);
  3260 							OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  3261 
  3262 							int keynum;
  3263 							keynum=i;
  3264 							if(buttons[0]&&!oldbuttons[0])keynum=MAC_MOUSEBUTTON1;
  3265 							if(buttons[1]&&!oldbuttons[1])keynum=MAC_MOUSEBUTTON2;
  3266 
  3267 
  3268 
  3269 							if(keyselect==0)forwardkey=keynum;
  3270 							if(keyselect==1)backkey=keynum;
  3271 							if(keyselect==2)leftkey=keynum;
  3272 							if(keyselect==3)rightkey=keynum;
  3273 							if(keyselect==4)crouchkey=keynum;
  3274 							if(keyselect==5)jumpkey=keynum;
  3275 							if(keyselect==6)drawkey=keynum;
  3276 							if(keyselect==7)throwkey=keynum;
  3277 							if(keyselect==8)attackkey=keynum;
  3278 							keyselect=-1;
  3279 						}
  3280 					}
  3281 				}}
  3282 			if(Button()&&!oldbutton&&selected==9){
  3283 				float gLoc[3]={0,0,0};
  3284 				float vel[3]={0,0,0};
  3285 				OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  3286 				PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
  3287 				OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  3288 				OPENAL_SetVolume(channels[fireendsound], 256);
  3289 				OPENAL_SetPaused(channels[fireendsound], false);
  3290 				OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  3291 
  3292 				flashr=1;
  3293 				flashg=0;
  3294 				flashb=0;
  3295 				flashamount=1;
  3296 				flashdelay=1;
  3297 
  3298 				mainmenu=3;
  3299 
  3300 				if(newdetail>2)newdetail=detail;
  3301 				if(newdetail<0)newdetail=detail;
  3302 				if(newscreenwidth>3000)newscreenwidth=screenwidth;
  3303 				if(newscreenwidth<0)newscreenwidth=screenwidth;
  3304 				if(newscreenheight>3000)newscreenheight=screenheight;
  3305 				if(newscreenheight<0)newscreenheight=screenheight;
  3306 			}
  3307 		}
  3308 
  3309 		if(mainmenu==5){
  3310 
  3311 			if(endgame==2){
  3312 				accountcampaignchoicesmade[accountactive]=0;
  3313 				accountcampaignscore[accountactive]=0;
  3314 				accountcampaigntime[accountactive]=0;
  3315 				endgame=0;
  3316 			}
  3317 
  3318 			if(Button()&&!oldbutton&&selected==1){
  3319 				float gLoc[3]={0,0,0};
  3320 				float vel[3]={0,0,0};
  3321 				OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
  3322 				PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
  3323 				OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  3324 				OPENAL_SetVolume(channels[firestartsound], 256);
  3325 				OPENAL_SetPaused(channels[firestartsound], false);
  3326 				OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
  3327 
  3328 				flashr=1;
  3329 				flashg=0;
  3330 				flashb=0;
  3331 				flashamount=1;
  3332 				flashdelay=1;
  3333 
  3334 				startbonustotal=0;
  3335 
  3336 				loading=2;
  3337 				loadtime=0;
  3338 				targetlevel=-1;
  3339 				if(firstload)TickOnceAfter();
  3340 				if(!firstload)LoadStuff();
  3341 				else {
  3342 					Loadlevel(-1);
  3343 				}
  3344 
  3345 				mainmenu=0;
  3346 				gameon=1;
  3347 				OPENAL_SetPaused(channels[stream_music3], true);
  3348 			}
  3349 			if(Button()&&!oldbutton&&selected-7>=accountcampaignchoicesmade[accountactive]){//selected>=7&&(selected-7<=campaignnumchoices)){
  3350 				float gLoc[3]={0,0,0};
  3351 				float vel[3]={0,0,0};
  3352 				OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
  3353 				PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
  3354 				OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  3355 				OPENAL_SetVolume(channels[firestartsound], 256);
  3356 				OPENAL_SetPaused(channels[firestartsound], false);
  3357 				OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
  3358 
  3359 				flashr=1;
  3360 				flashg=0;
  3361 				flashb=0;
  3362 				flashamount=1;
  3363 				flashdelay=1;
  3364 
  3365 				startbonustotal=0;
  3366 
  3367 				loading=2;
  3368 				loadtime=0;
  3369 				targetlevel=7;
  3370 				if(firstload)TickOnceAfter();
  3371 				if(!firstload)LoadStuff();
  3372 				//else {
  3373 				for(i=0;i<255;i++){
  3374 					mapname[i]='\0';
  3375 				}
  3376 				mapname[0]=':';
  3377 				mapname[1]='D';
  3378 				mapname[2]='a';
  3379 				mapname[3]='t';
  3380 				mapname[4]='a';
  3381 				mapname[5]=':';
  3382 				mapname[6]='M';
  3383 				mapname[7]='a';
  3384 				mapname[8]='p';
  3385 				mapname[9]='s';
  3386 				mapname[10]=':';
  3387 				strcat(mapname,campaignmapname[campaignchoicewhich[selected-7-accountcampaignchoicesmade[accountactive]]]);
  3388 				whichchoice=selected-7-accountcampaignchoicesmade[accountactive];
  3389 				visibleloading=1;
  3390 				stillloading=1;
  3391 				Loadlevel(mapname);
  3392 				//Loadlevel(campaignmapname[levelorder[selected-7]]);
  3393 				//}
  3394 				campaign=1;
  3395 				mainmenu=0;
  3396 				gameon=1;
  3397 				OPENAL_SetPaused(channels[stream_music3], true);
  3398 			}
  3399 			if(Button()&&!oldbutton&&selected==4){
  3400 				float gLoc[3]={0,0,0};
  3401 				float vel[3]={0,0,0};
  3402 				OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  3403 				PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
  3404 				OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  3405 				OPENAL_SetVolume(channels[fireendsound], 256);
  3406 				OPENAL_SetPaused(channels[fireendsound], false);
  3407 				OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  3408 
  3409 				flashr=1;
  3410 				flashg=0;
  3411 				flashb=0;
  3412 				flashamount=1;
  3413 				flashdelay=1;
  3414 
  3415 				if(mainmenu==5&&gameon)mainmenu=2;
  3416 				if(mainmenu==5&&!gameon)mainmenu=1;
  3417 			}
  3418 			if(Button()&&!oldbutton&&selected==5){
  3419 				float gLoc[3]={0,0,0};
  3420 				float vel[3]={0,0,0};
  3421 				OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  3422 				PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
  3423 				OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  3424 				OPENAL_SetVolume(channels[fireendsound], 256);
  3425 				OPENAL_SetPaused(channels[fireendsound], false);
  3426 				OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  3427 
  3428 				flashr=1;
  3429 				flashg=0;
  3430 				flashb=0;
  3431 				flashamount=1;
  3432 				flashdelay=1;
  3433 
  3434 				mainmenu=7;
  3435 			}
  3436 			if(Button()&&!oldbutton&&selected==3){
  3437 				float gLoc[3]={0,0,0};
  3438 				float vel[3]={0,0,0};
  3439 				OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
  3440 				PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
  3441 				OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  3442 				OPENAL_SetVolume(channels[firestartsound], 256);
  3443 				OPENAL_SetPaused(channels[firestartsound], false);
  3444 				OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
  3445 
  3446 				flashr=1;
  3447 				flashg=0;
  3448 				flashb=0;
  3449 				flashamount=1;
  3450 				flashdelay=1;
  3451 
  3452 				mainmenu=6;
  3453 			}
  3454 			if(Button()&&!oldbutton&&selected==2){
  3455 				float gLoc[3]={0,0,0};
  3456 				float vel[3]={0,0,0};
  3457 				OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
  3458 				PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
  3459 				OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  3460 				OPENAL_SetVolume(channels[firestartsound], 256);
  3461 				OPENAL_SetPaused(channels[firestartsound], false);
  3462 				OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
  3463 
  3464 				flashr=1;
  3465 				flashg=0;
  3466 				flashb=0;
  3467 				flashamount=1;
  3468 				flashdelay=1;
  3469 
  3470 				mainmenu=9;
  3471 			}
  3472 			if(Button())oldbutton=1;
  3473 			else oldbutton=0;
  3474 		}
  3475 		if(mainmenu==9){
  3476 			if(Button()&&!oldbutton&&selected<numchallengelevels&&selected>=0&&selected<=accountprogress[accountactive]){
  3477 				float gLoc[3]={0,0,0};
  3478 				float vel[3]={0,0,0};
  3479 				OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
  3480 				PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
  3481 				OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  3482 				OPENAL_SetVolume(channels[firestartsound], 256);
  3483 				OPENAL_SetPaused(channels[firestartsound], false);
  3484 				OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
  3485 
  3486 				flashr=1;
  3487 				flashg=0;
  3488 				flashb=0;
  3489 				flashamount=1;
  3490 				flashdelay=1;
  3491 
  3492 				startbonustotal=0;
  3493 
  3494 				loading=2;
  3495 				loadtime=0;
  3496 				targetlevel=selected;
  3497 				if(firstload)TickOnceAfter();
  3498 				if(!firstload)LoadStuff();
  3499 				else {
  3500 					Loadlevel(selected);
  3501 				}
  3502 				campaign=0;
  3503 
  3504 				mainmenu=0;
  3505 				gameon=1;
  3506 				OPENAL_SetPaused(channels[stream_music3], true);
  3507 			}
  3508 			if(Button()&&!oldbutton&&selected==numchallengelevels){
  3509 				float gLoc[3]={0,0,0};
  3510 				float vel[3]={0,0,0};
  3511 				OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  3512 				PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
  3513 				OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  3514 				OPENAL_SetVolume(channels[fireendsound], 256);
  3515 				OPENAL_SetPaused(channels[fireendsound], false);
  3516 				OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  3517 
  3518 				flashr=1;
  3519 				flashg=0;
  3520 				flashb=0;
  3521 				flashamount=1;
  3522 				flashdelay=1;
  3523 
  3524 				mainmenu=5;
  3525 			}
  3526 			if(Button())oldbutton=1;
  3527 			else oldbutton=0;
  3528 		}
  3529 		if(mainmenu==11){
  3530 			if(Button()&&!oldbutton&&selected<numchallengelevels&&selected>=0&&selected<=accountprogress[accountactive]){
  3531 				float gLoc[3]={0,0,0};
  3532 				float vel[3]={0,0,0};
  3533 				OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
  3534 				PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
  3535 				OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  3536 				OPENAL_SetVolume(channels[firestartsound], 256);
  3537 				OPENAL_SetPaused(channels[firestartsound], false);
  3538 				OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
  3539 
  3540 				flashr=1;
  3541 				flashg=0;
  3542 				flashb=0;
  3543 				flashamount=1;
  3544 				flashdelay=1;
  3545 
  3546 				startbonustotal=0;
  3547 
  3548 				loading=2;
  3549 				loadtime=0;
  3550 				targetlevel=selected;
  3551 				if(firstload)TickOnceAfter();
  3552 				if(!firstload)LoadStuff();
  3553 				else {
  3554 					Loadlevel(selected);
  3555 				}
  3556 				campaign=0;
  3557 
  3558 				mainmenu=0;
  3559 				gameon=1;
  3560 				OPENAL_SetPaused(channels[stream_music3], true);
  3561 			}
  3562 			if(Button()&&!oldbutton&&selected==numchallengelevels){
  3563 				float gLoc[3]={0,0,0};
  3564 				float vel[3]={0,0,0};
  3565 				OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  3566 				PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
  3567 				OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  3568 				OPENAL_SetVolume(channels[fireendsound], 256);
  3569 				OPENAL_SetPaused(channels[fireendsound], false);
  3570 				OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  3571 
  3572 				flashr=1;
  3573 				flashg=0;
  3574 				flashb=0;
  3575 				flashamount=1;
  3576 				flashdelay=1;
  3577 
  3578 				mainmenu=5;
  3579 			}
  3580 			if(Button())oldbutton=1;
  3581 			else oldbutton=0;
  3582 		}
  3583 		if(mainmenu==10){
  3584 			endgame=2;
  3585 			if(Button()&&!oldbutton&&selected==3){
  3586 				float gLoc[3]={0,0,0};
  3587 				float vel[3]={0,0,0};
  3588 				OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  3589 				PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
  3590 				OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  3591 				OPENAL_SetVolume(channels[fireendsound], 256);
  3592 				OPENAL_SetPaused(channels[fireendsound], false);
  3593 				OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  3594 
  3595 				flashr=1;
  3596 				flashg=0;
  3597 				flashb=0;
  3598 				flashamount=1;
  3599 				flashdelay=1;
  3600 
  3601 				mainmenu=5;
  3602 			}
  3603 			if(Button())oldbutton=1;
  3604 			else oldbutton=0;
  3605 		}
  3606 
  3607 		if(mainmenu==6){
  3608 			if(Button()&&!oldbutton&&selected!=-1){
  3609 				float gLoc[3]={0,0,0};
  3610 				float vel[3]={0,0,0};
  3611 				OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
  3612 				PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
  3613 				OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  3614 				OPENAL_SetVolume(channels[firestartsound], 256);
  3615 				OPENAL_SetPaused(channels[firestartsound], false);
  3616 				OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
  3617 			}
  3618 			if(Button()&&!oldbutton&&selected==1){
  3619 				float gLoc[3]={0,0,0};
  3620 				float vel[3]={0,0,0};
  3621 				OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  3622 				PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
  3623 				OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  3624 				OPENAL_SetVolume(channels[fireendsound], 256);
  3625 				OPENAL_SetPaused(channels[fireendsound], false);
  3626 				OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  3627 
  3628 				flashr=1;
  3629 				flashg=0;
  3630 				flashb=0;
  3631 				flashamount=1;
  3632 				flashdelay=1;
  3633 
  3634 				for(i=accountactive;i<numaccounts-1;i++){
  3635 					accountdifficulty[i]=accountdifficulty[i+1];
  3636 					accountcampaignchoicesmade[i]=accountcampaignchoicesmade[i+1];
  3637 					for(j=0;j<accountcampaignchoicesmade[i+1];j++){
  3638 						accountcampaignchoices[i][j]=accountcampaignchoices[i+1][j];
  3639 					}
  3640 					accountpoints[i]=accountpoints[i+1];
  3641 					for(j=0;j<50;j++){
  3642 						accounthighscore[i][j]=accounthighscore[i+1][j];
  3643 						accountfasttime[i][j]=accountfasttime[i+1][j];
  3644 					}
  3645 					for(j=0;j<60;j++){
  3646 						accountunlocked[i][j]=accountunlocked[i+1][j];
  3647 					}
  3648 					for(j=0;j<256;j++){
  3649 						accountname[i][j]=accountname[i+1][j];
  3650 					}
  3651 					accountcampaignhighscore[i]=accountcampaignhighscore[i+1];
  3652 					accountprogress[i]=accountprogress[i+1];
  3653 					accountcampaignfasttime[i]=accountcampaignfasttime[i+1];
  3654 					accountcampaignscore[i]=accountcampaignscore[i+1];
  3655 					accountcampaigntime[i]=accountcampaigntime[i+1];
  3656 				}
  3657 
  3658 				numaccounts--;
  3659 				accountactive=-1;
  3660 
  3661 
  3662 				mainmenu=7;
  3663 			}
  3664 			if(Button()&&!oldbutton&&selected==2){
  3665 				float gLoc[3]={0,0,0};
  3666 				float vel[3]={0,0,0};
  3667 				OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  3668 				PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
  3669 				OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  3670 				OPENAL_SetVolume(channels[fireendsound], 256);
  3671 				OPENAL_SetPaused(channels[fireendsound], false);
  3672 				OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  3673 
  3674 				flashr=1;
  3675 				flashg=0;
  3676 				flashb=0;
  3677 				flashamount=1;
  3678 				flashdelay=1;
  3679 
  3680 				mainmenu=5;
  3681 			}
  3682 			if(Button())oldbutton=1;
  3683 			else oldbutton=0;
  3684 		}
  3685 		if(mainmenu==7){
  3686 			if(Button()&&!oldbutton&&selected!=-1){
  3687 				float gLoc[3]={0,0,0};
  3688 				float vel[3]={0,0,0};
  3689 				OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
  3690 				PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
  3691 				OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  3692 				OPENAL_SetVolume(channels[firestartsound], 256);
  3693 				OPENAL_SetPaused(channels[firestartsound], false);
  3694 				OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
  3695 			}
  3696 			if(Button()&&!oldbutton&&selected==0&&numaccounts<8){
  3697 				entername=1;
  3698 			}
  3699 			if(Button()&&!oldbutton&&selected>0&&selected<numaccounts+1){
  3700 				accountactive=selected-1;
  3701 				mainmenu=5;
  3702 				flashr=1;
  3703 				flashg=0;
  3704 				flashb=0;
  3705 				flashamount=1;
  3706 				flashdelay=1;
  3707 			}
  3708 			if(Button()&&!oldbutton&&selected==numaccounts+1){
  3709 				float gLoc[3]={0,0,0};
  3710 				float vel[3]={0,0,0};
  3711 				OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  3712 				PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
  3713 				OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  3714 				OPENAL_SetVolume(channels[fireendsound], 256);
  3715 				OPENAL_SetPaused(channels[fireendsound], false);
  3716 				OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  3717 
  3718 				flashr=1;
  3719 				flashg=0;
  3720 				flashb=0;
  3721 				flashamount=1;
  3722 				flashdelay=1;
  3723 
  3724 				mainmenu=1;
  3725 
  3726 				for(j=0;j<255;j++){
  3727 					displaytext[0][j]=' ';
  3728 				}
  3729 				displaychars[0]=0;
  3730 				displayselected=0;
  3731 				entername=0;
  3732 			}
  3733 			if(Button())oldbutton=1;
  3734 			else oldbutton=0;
  3735 		}
  3736 		if(mainmenu==8){
  3737 			if(Button()&&!oldbutton&&selected!=-1){
  3738 				float gLoc[3]={0,0,0};
  3739 				float vel[3]={0,0,0};
  3740 				OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
  3741 				PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
  3742 				OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  3743 				OPENAL_SetVolume(channels[firestartsound], 256);
  3744 				OPENAL_SetPaused(channels[firestartsound], false);
  3745 				OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
  3746 
  3747 				if(selected==0)accountdifficulty[accountactive]=0;
  3748 				if(selected==1)accountdifficulty[accountactive]=1;
  3749 				if(selected==2)accountdifficulty[accountactive]=2;
  3750 
  3751 				mainmenu=5;
  3752 
  3753 				flashr=1;
  3754 				flashg=0;
  3755 				flashb=0;
  3756 				flashamount=1;
  3757 				flashdelay=1;
  3758 
  3759 			}
  3760 			if(Button())oldbutton=1;
  3761 			else oldbutton=0;
  3762 		}
  3763 
  3764 
  3765 		if(Button())oldbutton=1;
  3766 		else oldbutton=0;
  3767 
  3768 		if(IsKeyDown(theKeyMap, MAC_Q_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)){
  3769 			tryquit=1;
  3770 			if(mainmenu==3){
  3771 				if(newdetail>2)newdetail=detail;
  3772 				if(newdetail<0)newdetail=detail;
  3773 				if(newscreenwidth<0)newscreenwidth=screenwidth;
  3774 				if(newscreenheight<0)newscreenheight=screenheight;
  3775 
  3776 				ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
  3777 				opstream << "Screenwidth:\n";
  3778 				opstream << newscreenwidth;
  3779 				opstream << "\nScreenheight:\n";
  3780 				opstream << newscreenheight;
  3781 				opstream << "\nMouse sensitivity:\n";
  3782 				opstream << usermousesensitivity;
  3783 				opstream << "\nBlur(0,1):\n";
  3784 				opstream << ismotionblur;
  3785 				opstream << "\nOverall Detail(0,1,2) higher=better:\n";
  3786 				opstream << newdetail;
  3787 				opstream << "\nFloating jump:\n";
  3788 				opstream << floatjump;
  3789 				opstream << "\nMouse jump:\n";
  3790 				opstream << mousejump;
  3791 				opstream << "\nAmbient sound:\n";
  3792 				opstream << ambientsound;
  3793 				opstream << "\nBlood (0,1,2):\n";
  3794 				opstream << bloodtoggle;
  3795 				opstream << "\nAuto slomo:\n";
  3796 				opstream << autoslomo;
  3797 				opstream << "\nFoliage:\n";
  3798 				opstream << foliage;
  3799 				opstream << "\nMusic:\n";
  3800 				opstream << musictoggle;
  3801 				opstream << "\nTrilinear:\n";
  3802 				opstream << trilinear;
  3803 				opstream << "\nDecals(shadows,blood puddles,etc):\n";
  3804 				opstream << decals;
  3805 				opstream << "\nInvert mouse:\n";
  3806 				opstream << invertmouse;
  3807 				opstream << "\nGamespeed:\n";
  3808 				if(oldgamespeed==0)oldgamespeed=1;
  3809 				opstream << oldgamespeed;
  3810 				opstream << "\nDifficulty(0,1,2) higher=harder:\n";
  3811 				opstream << difficulty;
  3812 				opstream << "\nDamage effects(blackout, doublevision):\n";
  3813 				opstream << damageeffects;
  3814 				opstream << "\nText:\n";
  3815 				opstream << texttoggle;
  3816 				opstream << "\nDebug:\n";
  3817 				opstream << debugmode;
  3818 				opstream << "\nVBL Sync:\n";
  3819 				opstream << vblsync;
  3820 				opstream << "\nShow Points:\n";
  3821 				opstream << showpoints;
  3822 				opstream << "\nAlways Blur:\n";
  3823 				opstream << alwaysblur;
  3824 				opstream << "\nImmediate mode (turn on on G5):\n";
  3825 				opstream << immediate;
  3826 				opstream << "\nVelocity blur:\n";
  3827 				opstream << velocityblur;
  3828 			    opstream << "\nVolume:\n";
  3829 		        opstream << volume;
  3830 				opstream << "\nForward key:\n";
  3831 				opstream << KeyToChar(forwardkey);
  3832 				opstream << "\nBack key:\n";
  3833 				opstream << KeyToChar(backkey);
  3834 				opstream << "\nLeft key:\n";
  3835 				opstream << KeyToChar(leftkey);
  3836 				opstream << "\nRight key:\n";
  3837 				opstream << KeyToChar(rightkey);
  3838 				opstream << "\nJump key:\n";
  3839 				opstream << KeyToChar(jumpkey);
  3840 				opstream << "\nCrouch key:\n";
  3841 				opstream << KeyToChar(crouchkey);
  3842 				opstream << "\nDraw key:\n";
  3843 				opstream << KeyToChar(drawkey);
  3844 				opstream << "\nThrow key:\n";
  3845 				opstream << KeyToChar(throwkey);
  3846 				opstream << "\nAttack key:\n";
  3847 				opstream << KeyToChar(attackkey);
  3848 				opstream << "\nChat key:\n";
  3849 				opstream << KeyToChar(chatkey);
  3850 				opstream.close();
  3851 			}
  3852 		}
  3853 
  3854 		if(mainmenu==1||mainmenu==2){
  3855 			if(loaddistrib>4)transition+=multiplier/8;
  3856 			if(transition>1){
  3857 				transition=0;
  3858 				anim++;
  3859 				if(anim>4)anim=0;
  3860 				loaddistrib=0;
  3861 			}
  3862 		}
  3863 		OPENAL_SetFrequency(channels[stream_music3], 22050);
  3864 
  3865 		if(entername){
  3866 			for(i=0;i<140;i++){
  3867 				if(IsKeyDown(theKeyMap, i)){
  3868 					togglekeydelay[i]+=multiplier;
  3869 					if(togglekeydelay[i]>.4){
  3870 						togglekey[i]=0;
  3871 						togglekeydelay[i]=.36;
  3872 					}
  3873 					if(!togglekey[i]){
  3874 						if(KeyToSingleChar(i)!='\0'&&displaychars[0]<60){
  3875 							for(j=255;j>=displayselected+1;j--){
  3876 								displaytext[0][j]=displaytext[0][j-1];
  3877 							}
  3878 							displaytext[0][displayselected]=KeyToSingleChar(i);
  3879 							if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))displaytext[0][displayselected]=Shift(displaytext[0][displayselected]);
  3880 							displayselected++;
  3881 							displaychars[0]++;
  3882 						}
  3883 						if(i==MAC_DELETE_KEY&&displayselected!=0){
  3884 							for(j=displayselected-1;j<255;j++){
  3885 								displaytext[0][j]=displaytext[0][j+1];
  3886 							}
  3887 							displaytext[0][255]=' ';
  3888 							displayselected--;
  3889 							displaychars[0]--;
  3890 						}
  3891 						if(i==MAC_ARROW_LEFT_KEY&&displayselected!=0){
  3892 							displayselected--;
  3893 						}
  3894 						if(i==MAC_ARROW_RIGHT_KEY&&displayselected<displaychars[0]){
  3895 							displayselected++;
  3896 						}
  3897 						if(i==MAC_RETURN_KEY&&entername){
  3898 							if(displaychars[0]){
  3899 								numaccounts++;
  3900 								strcpy(accountname[numaccounts-1],displaytext[0]);
  3901 								accountactive=numaccounts-1;
  3902 								accountdifficulty[accountactive]=1;
  3903 								accountprogress[accountactive]=0;
  3904 								accountpoints[accountactive]=0;
  3905 								accountcampaigntime[accountactive]=0;
  3906 								accountcampaignscore[accountactive]=0;
  3907 								accountcampaignfasttime[accountactive]=0;
  3908 								accountcampaignhighscore[accountactive]=0;
  3909 								for(j=0;j<50;j++){
  3910 									accounthighscore[accountactive][j]=0;
  3911 									accountfasttime[accountactive][j]=0;
  3912 								}
  3913 								for(j=0;j<60;j++){
  3914 									accountunlocked[accountactive][j]=0;
  3915 								}
  3916 								accountcampaignchoicesmade[accountactive]=0;
  3917 
  3918 								for(j=0;j<255;j++){
  3919 									displaytext[0][j]=' ';
  3920 								}
  3921 								displaychars[0]=0;
  3922 								displayselected=0;
  3923 								entername=0;
  3924 
  3925 								mainmenu=8;
  3926 
  3927 								flashr=1;
  3928 								flashg=0;
  3929 								flashb=0;
  3930 								flashamount=1;
  3931 								flashdelay=1;
  3932 
  3933 								float gLoc[3]={0,0,0};
  3934 								float vel[3]={0,0,0};
  3935 								OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
  3936 								PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
  3937 								OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  3938 								OPENAL_SetVolume(channels[firestartsound], 256);
  3939 								OPENAL_SetPaused(channels[firestartsound], false);
  3940 								OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
  3941 
  3942 								for(j=0;j<255;j++){
  3943 									displaytext[0][j]=' ';
  3944 								}
  3945 								displaychars[0]=0;
  3946 
  3947 
  3948 								displayselected=0;
  3949 							}}
  3950 
  3951 						if(i==MAC_RETURN_KEY&&mainmenu==13){
  3952 							if(displaychars[0]){
  3953 								sprintf (registrationname, "%s", displaytext[0]);
  3954 								if(displaychars[0]<254)registrationname[displaychars[0]]='\0';
  3955 
  3956 								mainmenu=5;
  3957                         
  3958 								flashr=1;
  3959 								flashg=0;
  3960 								flashb=0;
  3961 								flashamount=1;
  3962 								flashdelay=1;
  3963 
  3964 								float gLoc[3]={0,0,0};
  3965 								float vel[3]={0,0,0};
  3966 								OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
  3967 								PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
  3968 								OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  3969 								OPENAL_SetVolume(channels[firestartsound], 256);
  3970 								OPENAL_SetPaused(channels[firestartsound], false);
  3971 								OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
  3972 
  3973 								for(j=0;j<255;j++){
  3974 									displaytext[0][j]=' ';
  3975 								}
  3976 								displaychars[0]=0;
  3977                         
  3978 								displayselected=0;
  3979 							}}
  3980 					}
  3981 					togglekey[i]=1;
  3982 				}
  3983 				else {
  3984 					togglekey[i]=0;
  3985 					togglekeydelay[i]=0;
  3986 				}
  3987 			}
  3988 
  3989 			displayblinkdelay-=multiplier;
  3990 			if(displayblinkdelay<=0){
  3991 				displayblinkdelay=.3;
  3992 				displayblink=1-displayblink;
  3993 			}
  3994 		}
  3995 	}
  3996 
  3997 	if(!mainmenu){
  3998 		if(hostile==1)hostiletime+=multiplier;
  3999 		else hostiletime=0;
  4000 		if(!winfreeze)leveltime+=multiplier;
  4001 		if(IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)){
  4002 			chatting=0;
  4003 			console=0;
  4004 			freeze=0;
  4005 			displaychars[0]=0;
  4006 		}
  4007 
  4008 		if(IsKeyDown(theKeyMap, chatkey)&&!chattogglekeydown&&!console&&!chatting&&debugmode){
  4009 			chatting=1;
  4010 			chattogglekeydown=1;
  4011 			togglekey[chatkey]=1;
  4012 			togglekeydelay[chatkey]=-20;
  4013 		}
  4014 
  4015 		if(!IsKeyDown(theKeyMap, chatkey)){
  4016 			chattogglekeydown=0;
  4017 		}
  4018 
  4019 		if(chatting){
  4020 			for(i=0;i<140;i++){
  4021 				if(IsKeyDown(theKeyMap, i)){
  4022 					togglekeydelay[i]+=multiplier;
  4023 					if(togglekeydelay[i]>.4){
  4024 						togglekey[i]=0;
  4025 						togglekeydelay[i]=.36;
  4026 					}
  4027 					if(!togglekey[i]){
  4028 						if(KeyToSingleChar(i)!='\0'&&displaychars[0]<60){
  4029 							for(j=255;j>=displayselected+1;j--){
  4030 								displaytext[0][j]=displaytext[0][j-1];
  4031 							}
  4032 							displaytext[0][displayselected]=KeyToSingleChar(i);
  4033 							if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))displaytext[0][displayselected]=Shift(displaytext[0][displayselected]);
  4034 							displayselected++;
  4035 							displaychars[0]++;
  4036 						}
  4037 						if(i==MAC_DELETE_KEY&&displayselected!=0){
  4038 							for(j=displayselected-1;j<255;j++){
  4039 								displaytext[0][j]=displaytext[0][j+1];
  4040 							}
  4041 							displaytext[0][255]=' ';
  4042 							displayselected--;
  4043 							displaychars[0]--;
  4044 						}
  4045 						if(i==MAC_ARROW_LEFT_KEY&&displayselected!=0){
  4046 							displayselected--;
  4047 						}
  4048 						if(i==MAC_ARROW_RIGHT_KEY&&displayselected<displaychars[0]){
  4049 							displayselected++;
  4050 						}
  4051 						if(i==MAC_RETURN_KEY){
  4052 							if(displaychars[0]){
  4053 								/*for(j=0;j<displaychars[0];j++){
  4054 								talkname[j]=displaytext[0][j];
  4055 								}
  4056 								talkname[displaychars[0]]='\0';
  4057 								sprintf (chatname, "%s: %s",playerName,talkname);
  4058 								//NetworkSendInformation(chatname);
  4059 								*/
  4060 								for(j=0;j<255;j++){
  4061 									displaytext[0][j]=' ';
  4062 								}
  4063 								displaychars[0]=0;
  4064 								displayselected=0;
  4065 								chatting=0;
  4066 							}
  4067 						}
  4068 					}
  4069 					togglekey[i]=1;
  4070 				}
  4071 				else {
  4072 					togglekey[i]=0;
  4073 					togglekeydelay[i]=0;
  4074 				}
  4075 			}
  4076 
  4077 			displayblinkdelay-=multiplier;
  4078 			if(displayblinkdelay<=0){
  4079 				displayblinkdelay=.3;
  4080 				displayblink=1-displayblink;
  4081 			}
  4082 		}
  4083 
  4084 		if(chatting)keyboardfrozen=1;
  4085 
  4086 		if(IsKeyDown(theKeyMap, MAC_V_KEY)&&!freezetogglekeydown&&debugmode){
  4087 			freeze=1-freeze;
  4088 			if(freeze){
  4089 				OPENAL_SetFrequency(OPENAL_ALL, 0.001);
  4090 			}
  4091 			freezetogglekeydown=1;
  4092 		}
  4093 
  4094 		if(!IsKeyDown(theKeyMap, MAC_V_KEY)&&!IsKeyDown(theKeyMap, MAC_F1_KEY)){
  4095 			freezetogglekeydown=0;
  4096 		}
  4097 
  4098 		if(IsKeyDown(theKeyMap, MAC_TILDE_KEY)&&!consoletogglekeydown&&debugmode){
  4099 			console=1-console;
  4100 			if(!console)freeze=0;
  4101 			if(console){
  4102 				OPENAL_SetFrequency(OPENAL_ALL, 0.001);
  4103 			}
  4104 			consoletogglekeydown=1;
  4105 		}
  4106 
  4107 		if(!IsKeyDown(theKeyMap, MAC_TILDE_KEY)){
  4108 			consoletogglekeydown=0;
  4109 		}
  4110 
  4111 		if(console)freeze=1;
  4112 
  4113 		if(console&&!IsKeyDown(theKeyMap,MAC_COMMAND_KEY)){
  4114 			for(i=0;i<140;i++){
  4115 				if(IsKeyDown(theKeyMap, i)){
  4116 					togglekeydelay[i]+=multiplier;
  4117 					if(togglekeydelay[i]>.4){
  4118 						togglekey[i]=0;
  4119 						togglekeydelay[i]=.36;
  4120 					}
  4121 					if(!togglekey[i]){
  4122 						if(KeyToSingleChar(i)!='\0'&&consolechars[0]<255){
  4123 							for(j=255;j>=consoleselected+1;j--){
  4124 								consoletext[0][j]=consoletext[0][j-1];
  4125 							}
  4126 							consoletext[0][consoleselected]=KeyToSingleChar(i);
  4127 							if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))consoletext[0][consoleselected]=Shift(consoletext[0][consoleselected]);
  4128 							consoleselected++;
  4129 							consolechars[0]++;
  4130 						}
  4131 						else if(i==MAC_ENTER_KEY){
  4132 							for(j=255;j>=consoleselected+1;j--){
  4133 								consoletext[0][j]=consoletext[0][j-1];
  4134 							}
  4135 							consoletext[0][consoleselected]='\n';
  4136 							consoleselected++;
  4137 							consolechars[0]++;
  4138 						}
  4139 						if(i==MAC_DELETE_KEY&&consoleselected!=0){
  4140 							for(j=consoleselected-1;j<255;j++){
  4141 								consoletext[0][j]=consoletext[0][j+1];
  4142 							}
  4143 							consoletext[0][255]=' ';
  4144 							consoleselected--;
  4145 							consolechars[0]--;
  4146 						}
  4147 						if(i==MAC_ARROW_UP_KEY){
  4148 							if(archiveselected<14)archiveselected++;
  4149 							for(j=0;j<255;j++){
  4150 								consolechars[0]=consolechars[archiveselected];
  4151 								consoletext[0][j]=consoletext[archiveselected][j];
  4152 								consoleselected=consolechars[0];
  4153 							}
  4154 						}
  4155 						if(i==MAC_ARROW_DOWN_KEY){
  4156 							if(archiveselected>0)archiveselected--;
  4157 							for(j=0;j<255;j++){
  4158 								consolechars[0]=consolechars[archiveselected];
  4159 								consoletext[0][j]=consoletext[archiveselected][j];
  4160 								consoleselected=consolechars[0];
  4161 							}
  4162 						}
  4163 						if(i==MAC_ARROW_LEFT_KEY&&consoleselected!=0){
  4164 							consoleselected--;
  4165 						}
  4166 						if(i==MAC_ARROW_RIGHT_KEY&&consoleselected<consolechars[0]){
  4167 							consoleselected++;
  4168 						}
  4169 						if(i==MAC_RETURN_KEY){
  4170 							archiveselected=0;
  4171 							cmd_dispatch(this, consoletext[0]);
  4172 
  4173 							if(consolechars[0]>0){
  4174 								for(k=14;k>=1;k--){
  4175 									for(j=0;j<255;j++){
  4176 										consoletext[k][j]=consoletext[k-1][j];
  4177 									}
  4178 									consolechars[k]=consolechars[k-1];
  4179 								}
  4180 								for(j=0;j<255;j++){
  4181 									consoletext[0][j]=' ';
  4182 								}
  4183 								consolechars[0]=0;
  4184 								consoleselected=0;
  4185 							}
  4186 						}
  4187 					}
  4188 					togglekey[i]=1;
  4189 				}
  4190 				else {
  4191 					togglekey[i]=0;
  4192 					togglekeydelay[i]=0;
  4193 				}
  4194 			}
  4195 
  4196 			consoleblinkdelay-=multiplier;
  4197 			if(consoleblinkdelay<=0){
  4198 				consoleblinkdelay=.3;
  4199 				consoleblink=1-consoleblink;
  4200 			}
  4201 		}
  4202 
  4203 		if(IsKeyDown(theKeyMap, MAC_Q_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)){
  4204 			tryquit=1;
  4205 			if(mainmenu==3){
  4206 				if(newdetail>2)newdetail=detail;
  4207 				if(newdetail<0)newdetail=detail;
  4208 				if(newscreenwidth<0)newscreenwidth=screenwidth;
  4209 				if(newscreenheight<0)newscreenheight=screenheight;
  4210 
  4211 				ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
  4212 				opstream << "Screenwidth:\n";
  4213 				opstream << newscreenwidth;
  4214 				opstream << "\nScreenheight:\n";
  4215 				opstream << newscreenheight;
  4216 				opstream << "\nMouse sensitivity:\n";
  4217 				opstream << usermousesensitivity;
  4218 				opstream << "\nBlur(0,1):\n";
  4219 				opstream << ismotionblur;
  4220 				opstream << "\nOverall Detail(0,1,2) higher=better:\n";
  4221 				opstream << newdetail;
  4222 				opstream << "\nFloating jump:\n";
  4223 				opstream << floatjump;
  4224 				opstream << "\nMouse jump:\n";
  4225 				opstream << mousejump;
  4226 				opstream << "\nAmbient sound:\n";
  4227 				opstream << ambientsound;
  4228 				opstream << "\nBlood (0,1,2):\n";
  4229 				opstream << bloodtoggle;
  4230 				opstream << "\nAuto slomo:\n";
  4231 				opstream << autoslomo;
  4232 				opstream << "\nFoliage:\n";
  4233 				opstream << foliage;
  4234 				opstream << "\nMusic:\n";
  4235 				opstream << musictoggle;
  4236 				opstream << "\nTrilinear:\n";
  4237 				opstream << trilinear;
  4238 				opstream << "\nDecals(shadows,blood puddles,etc):\n";
  4239 				opstream << decals;
  4240 				opstream << "\nInvert mouse:\n";
  4241 				opstream << invertmouse;
  4242 				opstream << "\nGamespeed:\n";
  4243 				if(oldgamespeed==0)oldgamespeed=1;
  4244 				opstream << oldgamespeed;
  4245 				opstream << "\nDifficulty(0,1,2) higher=harder:\n";
  4246 				opstream << difficulty;
  4247 				opstream << "\nDamage effects(blackout, doublevision):\n";
  4248 				opstream << damageeffects;
  4249 				opstream << "\nText:\n";
  4250 				opstream << texttoggle;
  4251 				opstream << "\nDebug:\n";
  4252 				opstream << debugmode;
  4253 				opstream << "\nVBL Sync:\n";
  4254 				opstream << vblsync;
  4255 				opstream << "\nShow Points:\n";
  4256 				opstream << showpoints;
  4257 				opstream << "\nAlways Blur:\n";
  4258 				opstream << alwaysblur;
  4259 				opstream << "\nImmediate mode (turn on on G5):\n";
  4260 				opstream << immediate;
  4261 				opstream << "\nVelocity blur:\n";
  4262 				opstream << velocityblur;
  4263 			    opstream << "\nVolume:\n";
  4264 		        opstream << volume;
  4265 				opstream << "\nForward key:\n";
  4266 				opstream << KeyToChar(forwardkey);
  4267 				opstream << "\nBack key:\n";
  4268 				opstream << KeyToChar(backkey);
  4269 				opstream << "\nLeft key:\n";
  4270 				opstream << KeyToChar(leftkey);
  4271 				opstream << "\nRight key:\n";
  4272 				opstream << KeyToChar(rightkey);
  4273 				opstream << "\nJump key:\n";
  4274 				opstream << KeyToChar(jumpkey);
  4275 				opstream << "\nCrouch key:\n";
  4276 				opstream << KeyToChar(crouchkey);
  4277 				opstream << "\nDraw key:\n";
  4278 				opstream << KeyToChar(drawkey);
  4279 				opstream << "\nThrow key:\n";
  4280 				opstream << KeyToChar(throwkey);
  4281 				opstream << "\nAttack key:\n";
  4282 				opstream << KeyToChar(attackkey);
  4283 				opstream << "\nChat key:\n";
  4284 				opstream << KeyToChar(chatkey);
  4285 				opstream.close();
  4286 			}
  4287 		}
  4288 
  4289 		static int oldwinfreeze;
  4290 		if(winfreeze&&!oldwinfreeze){
  4291 			OPENAL_SetFrequency(OPENAL_ALL, 0.001);
  4292 			PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
  4293 			OPENAL_SetVolume(channels[consolesuccesssound], 256);
  4294 			OPENAL_SetPaused(channels[consolesuccesssound], false);
  4295 		}
  4296 		if(winfreeze==0)oldwinfreeze=winfreeze;
  4297 		else oldwinfreeze++;
  4298 
  4299 		if((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY))&&!oldjumpkeydown&&!campaign){
  4300 			if(winfreeze)winfreeze=0;
  4301 			oldjumpkeydown=1;
  4302 		}
  4303 		if((IsKeyDown(theKeyMap, MAC_ESCAPE_KEY))&&!campaign&&gameon){
  4304 			if(winfreeze){
  4305 				mainmenu=9;
  4306 				gameon=0;
  4307 			}
  4308 		}
  4309 		if((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY))){
  4310 			oldjumpkeydown=1;
  4311 		}
  4312 		if(!IsKeyDown(theKeyMap, jumpkey)&&!IsKeyDown(theKeyMap, MAC_SPACE_KEY))oldjumpkeydown=0;
  4313 
  4314 		if(!freeze&&!winfreeze&&!(mainmenu&&gameon)&&(gameon||!gamestarted)){
  4315 
  4316 			static bool oldbuttondialogue;
  4317 
  4318 			if(indialogue!=-1)talkdelay=1;
  4319 			talkdelay-=multiplier;
  4320 
  4321 			if(talkdelay<=0)
  4322 				if(indialogue==-1&&(animation[player[0].targetanimation].height!=highheight)/*&&!hostile*/)
  4323 					for(i=0;i<numdialogues;i++){
  4324 						int realdialoguetype;
  4325 						bool special;
  4326 						if(dialoguetype[i]>49){
  4327 							realdialoguetype=dialoguetype[i]-50;
  4328 							special=1;
  4329 						}
  4330 						else if(dialoguetype[i]>39){
  4331 							realdialoguetype=dialoguetype[i]-40;
  4332 							special=1;
  4333 						}
  4334 						else if(dialoguetype[i]>29){
  4335 							realdialoguetype=dialoguetype[i]-30;
  4336 							special=1;
  4337 						}
  4338 						else if(dialoguetype[i]>19){
  4339 							realdialoguetype=dialoguetype[i]-20;
  4340 							special=1;
  4341 						}
  4342 						else if(dialoguetype[i]>9){
  4343 							realdialoguetype=dialoguetype[i]-10;
  4344 							special=1;
  4345 						}
  4346 						else {
  4347 							realdialoguetype=dialoguetype[i];
  4348 							special=0;
  4349 						}
  4350 						if((!hostile||(dialoguetype[i]>40&&dialoguetype[i]<50))&&realdialoguetype<numplayers&&realdialoguetype>0&&(dialoguegonethrough[i]==0||!special)&&(special||(IsKeyDown(theKeyMap, attackkey)&&!oldbuttondialogue))){
  4351 							if(findDistancefast(&player[0].coords,&player[realdialoguetype].coords)<6||player[realdialoguetype].howactive>=typedead1||(dialoguetype[i]>40&&dialoguetype[i]<50)){
  4352 								whichdialogue=i;
  4353 								for(j=0;j<numdialogueboxes[whichdialogue];j++){
  4354 									player[participantfocus[whichdialogue][j]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][j]];
  4355 									player[participantfocus[whichdialogue][j]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
  4356 									player[participantfocus[whichdialogue][j]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
  4357 									player[participantfocus[whichdialogue][j]].velocity=0;
  4358 									player[participantfocus[whichdialogue][j]].targetanimation=player[participantfocus[whichdialogue][j]].getIdle();
  4359 									player[participantfocus[whichdialogue][j]].targetframe=0;
  4360 								}
  4361 								directing=0;
  4362 								indialogue=0;
  4363 								dialoguetime=0;
  4364 								dialoguegonethrough[i]++;
  4365 								if(dialogueboxsound[whichdialogue][indialogue]!=0){
  4366 									static float gLoc[3];
  4367 									static float vel[3];
  4368 									XYZ temppos;
  4369 									temppos=player[participantfocus[whichdialogue][indialogue]].coords;
  4370 									temppos=temppos-viewer;
  4371 									Normalise(&temppos);
  4372 									temppos+=viewer;
  4373 
  4374 									gLoc[0]=temppos.x;
  4375 									gLoc[1]=temppos.y;
  4376 									gLoc[2]=temppos.z;vel[0]=0;
  4377 									vel[1]=0;
  4378 									vel[2]=0;
  4379 									int whichsoundplay;
  4380 									if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
  4381 									if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
  4382 									if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
  4383 									if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
  4384 									if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
  4385 									if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
  4386 									if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
  4387 									if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
  4388 									if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
  4389 									if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
  4390 									if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
  4391 									if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
  4392 									if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
  4393 									if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
  4394 									if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
  4395 									if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
  4396 									if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
  4397 									if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
  4398 									if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
  4399 									if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
  4400 									PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
  4401 									OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
  4402 									OPENAL_SetVolume(channels[whichsoundplay], 256);
  4403 									OPENAL_SetPaused(channels[whichsoundplay], false);
  4404 								}
  4405 								if(IsKeyDown(theKeyMap, attackkey))oldbuttondialogue=1;
  4406 							}
  4407 						}
  4408 					}
  4409 
  4410 					windvar+=multiplier;
  4411 					smoketex+=multiplier;
  4412 					tutorialstagetime+=multiplier;
  4413 
  4414 					static float hotspotvisual[40];
  4415 					if(numhotspots){
  4416 						XYZ hotspotsprite;
  4417 						if(editorenabled)
  4418 							for(i=0;i<numhotspots;i++)
  4419 								hotspotvisual[i]-=multiplier/320;
  4420 
  4421 						for(i=0;i<numhotspots;i++){
  4422 							//if(hotspottype[i]<=10)
  4423 							while(hotspotvisual[i]<0){
  4424 								hotspotsprite=0;
  4425 								hotspotsprite.x=float(abs(Random()%100000))/100000*hotspotsize[i];
  4426 								hotspotsprite=DoRotation(hotspotsprite,0,0,Random()%360);
  4427 								hotspotsprite=DoRotation(hotspotsprite,0,Random()%360,0);
  4428 								hotspotsprite+=hotspot[i];
  4429 								sprites.MakeSprite(breathsprite, hotspotsprite, hotspotsprite*0, 1,0.5,0, 7, 0.4);
  4430 								hotspotvisual[i]+=0.1/hotspotsize[i]/hotspotsize[i]/hotspotsize[i];
  4431 							}
  4432 						}
  4433 
  4434 						for(i=0;i<numhotspots;i++){
  4435 							if(hotspottype[i]<=10&&hotspottype[i]>0){
  4436 								hotspot[i]=player[hotspottype[i]].coords;
  4437 							}
  4438 						}
  4439 					}
  4440 
  4441 					//Tutorial
  4442 					if(tutoriallevel&&tutorialstagetime>tutorialmaxtime){
  4443 						tutorialstage++;
  4444 						tutorialsuccess=0;
  4445 						if(tutorialstage<=1){
  4446 							canattack=0;
  4447 							cananger=0;
  4448 							reversaltrain=0;
  4449 						}
  4450 						if(tutorialstage==1){
  4451 							tutorialmaxtime=5;
  4452 						}
  4453 						if(tutorialstage==2){
  4454 							tutorialmaxtime=2;
  4455 						}
  4456 						if(tutorialstage==3){
  4457 							tutorialmaxtime=600;
  4458 						}
  4459 						if(tutorialstage==4){
  4460 							tutorialmaxtime=1000;
  4461 						}
  4462 						if(tutorialstage==5){
  4463 							tutorialmaxtime=600;
  4464 						}
  4465 						if(tutorialstage==6){
  4466 							tutorialmaxtime=600;
  4467 						}
  4468 						if(tutorialstage==7){
  4469 							tutorialmaxtime=600;
  4470 						}
  4471 						if(tutorialstage==8){
  4472 							tutorialmaxtime=600;
  4473 						}
  4474 						if(tutorialstage==9){
  4475 							tutorialmaxtime=600;
  4476 						}
  4477 						if(tutorialstage==10){
  4478 							tutorialmaxtime=2;
  4479 						}
  4480 						if(tutorialstage==11){
  4481 							tutorialmaxtime=1000;
  4482 						}
  4483 						if(tutorialstage==12){
  4484 							tutorialmaxtime=1000;
  4485 						}
  4486 						if(tutorialstage==13){
  4487 							tutorialmaxtime=2;
  4488 						}
  4489 						if(tutorialstage==14){
  4490 							tutorialmaxtime=3;
  4491 
  4492 							XYZ temp,temp2;
  4493 
  4494 							temp.x=1011;
  4495 							temp.y=84;
  4496 							temp.z=491;
  4497 							temp2.x=1025;
  4498 							temp2.y=75;
  4499 							temp2.z=447;
  4500 
  4501 							player[1].coords=(temp+temp2)/2;
  4502 
  4503 							float gLoc[3];
  4504 							float vel[3];
  4505 							gLoc[0]=player[1].coords.x;
  4506 							gLoc[1]=player[1].coords.y;
  4507 							gLoc[2]=player[1].coords.z;
  4508 							vel[0]=0;
  4509 							vel[1]=0;
  4510 							vel[2]=0;
  4511 							PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
  4512 							OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  4513 							OPENAL_SetVolume(channels[fireendsound], 256);
  4514 							OPENAL_SetPaused(channels[fireendsound], false);
  4515 
  4516 							for(i=0;i<player[1].skeleton.num_joints;i++){
  4517 								if(Random()%2==0){
  4518 									if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
  4519 									if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
  4520 									if(!player[1].skeleton.free)temp=DoRotation(DoRotation(DoRotation(player[1].skeleton.joints[i].position,0,0,player[1].tilt),player[1].tilt2,0,0),0,player[1].rotation,0)*player[1].scale+player[1].coords;
  4521 									if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
  4522 									sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
  4523 								}
  4524 							}
  4525 
  4526 						}
  4527 						if(tutorialstage==15){
  4528 							tutorialmaxtime=500;
  4529 						}
  4530 						if(tutorialstage==16){
  4531 							tutorialmaxtime=500;
  4532 						}
  4533 						if(tutorialstage==17){
  4534 							tutorialmaxtime=500;
  4535 						}
  4536 						if(tutorialstage==18){
  4537 							tutorialmaxtime=500;
  4538 						}
  4539 						if(tutorialstage==19){
  4540 							tutorialstage=20;
  4541 							//tutorialmaxtime=500;
  4542 						}
  4543 						if(tutorialstage==20){
  4544 							tutorialmaxtime=500;
  4545 						}
  4546 						if(tutorialstage==21){
  4547 							tutorialmaxtime=500;
  4548 							if(bonus==cannon){
  4549 								bonus=Slicebonus;
  4550 								againbonus=1;
  4551 							}
  4552 							else againbonus=0;
  4553 						}
  4554 						if(tutorialstage==22){
  4555 							tutorialmaxtime=500;
  4556 						}
  4557 						if(tutorialstage==23){
  4558 							tutorialmaxtime=500;
  4559 						}
  4560 						if(tutorialstage==24){
  4561 							tutorialmaxtime=500;
  4562 						}
  4563 						if(tutorialstage==25){
  4564 							tutorialmaxtime=500;
  4565 						}
  4566 						if(tutorialstage==26){
  4567 							tutorialmaxtime=2;
  4568 						}
  4569 						if(tutorialstage==27){
  4570 							tutorialmaxtime=4;
  4571 							reversaltrain=1;
  4572 							cananger=1;
  4573 							player[1].aitype=attacktypecutoff;
  4574 						}
  4575 						if(tutorialstage==28){
  4576 							tutorialmaxtime=400;
  4577 						}
  4578 						if(tutorialstage==29){
  4579 							tutorialmaxtime=400;
  4580 							player[0].escapednum=0;
  4581 						}
  4582 						if(tutorialstage==30){
  4583 							tutorialmaxtime=4;
  4584 							reversaltrain=0;
  4585 							cananger=0;
  4586 							player[1].aitype=passivetype;
  4587 						}
  4588 						if(tutorialstage==31){
  4589 							tutorialmaxtime=13;
  4590 						}
  4591 						if(tutorialstage==32){
  4592 							tutorialmaxtime=8;
  4593 						}
  4594 						if(tutorialstage==33){
  4595 							tutorialmaxtime=400;
  4596 							cananger=1;
  4597 							canattack=1;
  4598 							player[1].aitype=attacktypecutoff;
  4599 						}
  4600 						if(tutorialstage==34){
  4601 							tutorialmaxtime=400;
  4602 						}
  4603 						if(tutorialstage==35){
  4604 							tutorialmaxtime=400;
  4605 						}
  4606 						if(tutorialstage==36){
  4607 							tutorialmaxtime=2;
  4608 							reversaltrain=0;
  4609 							cananger=0;
  4610 							player[1].aitype=passivetype;
  4611 						}
  4612 						if(tutorialstage==37){
  4613 							damagedealt=0;
  4614 							damagetaken=0;
  4615 							tutorialmaxtime=50;
  4616 							cananger=1;
  4617 							canattack=1;
  4618 							player[1].aitype=attacktypecutoff;
  4619 						}
  4620 						if(tutorialstage==38){
  4621 							tutorialmaxtime=4;
  4622 							canattack=0;
  4623 							cananger=0;
  4624 							player[1].aitype=passivetype;
  4625 						}
  4626 						if(tutorialstage==39){
  4627 							XYZ temp,temp2;
  4628 
  4629 							temp.x=1011;
  4630 							temp.y=84;
  4631 							temp.z=491;
  4632 							temp2.x=1025;
  4633 							temp2.y=75;
  4634 							temp2.z=447;
  4635 
  4636 
  4637 							weapons.owner[weapons.numweapons]=-1;
  4638 							weapons.type[weapons.numweapons]=knife;
  4639 							weapons.damage[weapons.numweapons]=0;
  4640 							weapons.mass[weapons.numweapons]=1;
  4641 							weapons.tipmass[weapons.numweapons]=1.2;
  4642 							weapons.length[weapons.numweapons]=.25;
  4643 							weapons.position[weapons.numweapons]=(temp+temp2)/2;
  4644 							weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
  4645 
  4646 							weapons.velocity[weapons.numweapons]=0.1;
  4647 							weapons.tipvelocity[weapons.numweapons]=0.1;
  4648 							weapons.missed[weapons.numweapons]=1;
  4649 							weapons.hitsomething[weapons.numweapons]=0;
  4650 							weapons.freetime[weapons.numweapons]=0;
  4651 							weapons.firstfree[weapons.numweapons]=1;
  4652 							weapons.physics[weapons.numweapons]=1;
  4653 
  4654 							weapons.numweapons++;
  4655 						}
  4656 						if(tutorialstage==40){
  4657 							tutorialmaxtime=300;
  4658 						}
  4659 						if(tutorialstage==41){
  4660 							tutorialmaxtime=300;
  4661 						}
  4662 						if(tutorialstage==42){
  4663 							tutorialmaxtime=8;
  4664 						}
  4665 						if(tutorialstage==43){
  4666 							tutorialmaxtime=300;
  4667 						}
  4668 						if(tutorialstage==44){
  4669 							weapons.owner[0]=1;
  4670 							player[0].weaponactive=-1;
  4671 							player[0].num_weapons=0;
  4672 							player[1].weaponactive=0;
  4673 							player[1].num_weapons=1;
  4674 							player[1].weaponids[0]=0;
  4675 
  4676 							cananger=1;
  4677 							canattack=1;
  4678 							player[1].aitype=attacktypecutoff;
  4679 
  4680 							tutorialmaxtime=300;
  4681 						}
  4682 						if(tutorialstage==45){
  4683 							weapons.owner[0]=1;
  4684 							player[0].weaponactive=-1;
  4685 							player[0].num_weapons=0;
  4686 							player[1].weaponactive=0;
  4687 							player[1].num_weapons=1;
  4688 							player[1].weaponids[0]=0;
  4689 
  4690 							tutorialmaxtime=300;
  4691 						}
  4692 						if(tutorialstage==46){
  4693 							weapons.owner[0]=1;
  4694 							player[0].weaponactive=-1;
  4695 							player[0].num_weapons=0;
  4696 							player[1].weaponactive=0;
  4697 							player[1].num_weapons=1;
  4698 							player[1].weaponids[0]=0;
  4699 
  4700 							weapons.type[0]=sword;
  4701 
  4702 							tutorialmaxtime=300;
  4703 						}
  4704 
  4705 						if(tutorialstage==47){
  4706 							tutorialmaxtime=10;
  4707 
  4708 							XYZ temp,temp2;
  4709 
  4710 							temp.x=1011;
  4711 							temp.y=84;
  4712 							temp.z=491;
  4713 							temp2.x=1025;
  4714 							temp2.y=75;
  4715 							temp2.z=447;
  4716 
  4717 							weapons.owner[weapons.numweapons]=-1;
  4718 							weapons.type[weapons.numweapons]=sword;
  4719 							weapons.damage[weapons.numweapons]=0;
  4720 							weapons.mass[weapons.numweapons]=1;
  4721 							weapons.tipmass[weapons.numweapons]=1.2;
  4722 							weapons.length[weapons.numweapons]=.25;
  4723 							weapons.position[weapons.numweapons]=(temp+temp2)/2;
  4724 							weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
  4725 
  4726 							weapons.velocity[weapons.numweapons]=0.1;
  4727 							weapons.tipvelocity[weapons.numweapons]=0.1;
  4728 							weapons.missed[weapons.numweapons]=1;
  4729 							weapons.hitsomething[weapons.numweapons]=0;
  4730 							weapons.freetime[weapons.numweapons]=0;
  4731 							weapons.firstfree[weapons.numweapons]=1;
  4732 							weapons.physics[weapons.numweapons]=1;
  4733 
  4734 							weapons.owner[0]=1;
  4735 							weapons.owner[1]=0;
  4736 							player[0].weaponactive=0;
  4737 							player[0].num_weapons=1;
  4738 							player[0].weaponids[0]=1;
  4739 							player[1].weaponactive=0;
  4740 							player[1].num_weapons=1;
  4741 							player[1].weaponids[0]=0;
  4742 
  4743 							weapons.numweapons++;
  4744 						}
  4745 						if(tutorialstage==48){
  4746 							canattack=0;
  4747 							cananger=0;
  4748 							player[1].aitype=passivetype;
  4749 
  4750 							tutorialmaxtime=15;
  4751 
  4752 							weapons.owner[0]=1;
  4753 							weapons.owner[1]=0;
  4754 							player[0].weaponactive=0;
  4755 							player[0].num_weapons=1;
  4756 							player[0].weaponids[0]=1;
  4757 							player[1].weaponactive=0;
  4758 							player[1].num_weapons=1;
  4759 							player[1].weaponids[0]=0;
  4760 
  4761 							if(player[0].weaponactive!=-1)weapons.type[player[0].weaponids[player[0].weaponactive]]=staff;
  4762 							else weapons.type[0]=staff;
  4763 
  4764 							weapons.numweapons++;
  4765 						}
  4766 						if(tutorialstage==49){
  4767 							canattack=0;
  4768 							cananger=0;
  4769 							player[1].aitype=passivetype;
  4770 
  4771 							tutorialmaxtime=200;
  4772 
  4773 							weapons.position[1]=1000;
  4774 							weapons.tippoint[1]=1000;
  4775 
  4776 							weapons.numweapons=1;
  4777 							weapons.owner[0]=0;
  4778 							player[1].weaponactive=-1;
  4779 							player[1].num_weapons=0;
  4780 							player[0].weaponactive=0;
  4781 							player[0].num_weapons=1;
  4782 							player[0].weaponids[0]=0;
  4783 
  4784 							weapons.type[0]=knife;
  4785 
  4786 							weapons.numweapons++;
  4787 						}
  4788 						if(tutorialstage==50){
  4789 							tutorialmaxtime=8;
  4790 
  4791 							XYZ temp,temp2;
  4792 							float gLoc[3];
  4793 							float vel[3];
  4794 							gLoc[0]=player[1].coords.x;
  4795 							gLoc[1]=player[1].coords.y;
  4796 							gLoc[2]=player[1].coords.z;
  4797 							vel[0]=0;
  4798 							vel[1]=0;
  4799 							vel[2]=0;
  4800 							PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
  4801 							OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  4802 							OPENAL_SetVolume(channels[fireendsound], 256);
  4803 							OPENAL_SetPaused(channels[fireendsound], false);
  4804 
  4805 							for(i=0;i<player[1].skeleton.num_joints;i++){
  4806 								if(Random()%2==0){
  4807 									if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
  4808 									if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
  4809 									if(!player[1].skeleton.free)temp=DoRotation(DoRotation(DoRotation(player[1].skeleton.joints[i].position,0,0,player[1].tilt),player[1].tilt2,0,0),0,player[1].rotation,0)*player[1].scale+player[1].coords;
  4810 									if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
  4811 									sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
  4812 								}
  4813 							}
  4814 
  4815 							player[1].num_weapons=0;
  4816 							player[1].weaponstuck=-1;
  4817 							player[1].weaponactive=-1;
  4818 
  4819 							weapons.numweapons=0;
  4820 
  4821 							weapons.owner[0]=-1;
  4822 							weapons.velocity[0]=0.1;
  4823 							weapons.tipvelocity[0]=-0.1;
  4824 							weapons.missed[0]=1;
  4825 							weapons.hitsomething[0]=0;
  4826 							weapons.freetime[0]=0;
  4827 							weapons.firstfree[0]=1;
  4828 							weapons.physics[0]=1;
  4829 						}
  4830 						if(tutorialstage==51){
  4831 							tutorialmaxtime=80000;
  4832 						}
  4833 						if(tutorialstage<=51)tutorialstagetime=0;
  4834 					}
  4835 
  4836 					//Tutorial success
  4837 					if(tutoriallevel&&tutorialstagetime<tutorialmaxtime-3){
  4838 						if(tutorialstage==3){
  4839 							if(deltah||deltav)tutorialsuccess+=multiplier;
  4840 						}
  4841 						if(tutorialstage==4){
  4842 							if(player[0].forwardkeydown||player[0].backkeydown||player[0].leftkeydown||player[0].rightkeydown)tutorialsuccess+=multiplier;
  4843 						}
  4844 						if(tutorialstage==5){
  4845 							if(player[0].jumpkeydown)tutorialsuccess=1;
  4846 						}
  4847 						if(tutorialstage==6){
  4848 							if(player[0].isCrouch())tutorialsuccess=1;
  4849 						}
  4850 						if(tutorialstage==7){
  4851 							if(player[0].targetanimation==rollanim)tutorialsuccess=1;
  4852 						}
  4853 						if(tutorialstage==8){
  4854 							if(player[0].targetanimation==sneakanim)tutorialsuccess+=multiplier;
  4855 						}
  4856 						if(tutorialstage==9){
  4857 							if(player[0].targetanimation==rabbitrunninganim||player[0].targetanimation==wolfrunninganim)tutorialsuccess+=multiplier;
  4858 						}
  4859 						if(tutorialstage==11){
  4860 							if(player[0].isWallJump())tutorialsuccess=1;
  4861 						}
  4862 						if(tutorialstage==12){
  4863 							if(player[0].targetanimation==flipanim)tutorialsuccess=1;
  4864 						}
  4865 						if(tutorialstage==15){
  4866 							if(player[0].targetanimation==upunchanim||player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
  4867 						}
  4868 						if(tutorialstage==16){
  4869 							if(player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
  4870 						}
  4871 						if(tutorialstage==17){
  4872 							if(player[0].targetanimation==spinkickanim)tutorialsuccess=1;
  4873 						}
  4874 						if(tutorialstage==18){
  4875 							if(player[0].targetanimation==sweepanim)tutorialsuccess=1;
  4876 						}
  4877 						if(tutorialstage==19){
  4878 							if(player[0].targetanimation==dropkickanim)tutorialsuccess=1;
  4879 						}
  4880 						if(tutorialstage==20){
  4881 							if(player[0].targetanimation==rabbitkickanim)tutorialsuccess=1;
  4882 						}
  4883 						if(tutorialstage==21){
  4884 							if(bonus==cannon)tutorialsuccess=1;
  4885 						}
  4886 						if(tutorialstage==22){
  4887 							if(bonus==spinecrusher)tutorialsuccess=1;
  4888 						}
  4889 						if(tutorialstage==23){
  4890 							if(player[0].targetanimation==walljumprightkickanim||player[0].targetanimation==walljumpleftkickanim)tutorialsuccess=1;
  4891 						}
  4892 						if(tutorialstage==24){
  4893 							if(player[0].targetanimation==rabbittacklinganim)tutorialsuccess=1;
  4894 						}
  4895 						if(tutorialstage==25){
  4896 							if(player[0].targetanimation==backhandspringanim)tutorialsuccess=1;
  4897 						}
  4898 						if(tutorialstage==28){
  4899 							if(animation[player[0].targetanimation].attack==reversed&&player[0].feint)tutorialsuccess=1;
  4900 						}
  4901 						if(tutorialstage==29){
  4902 							if(player[0].escapednum==2){
  4903 								tutorialsuccess=1;
  4904 								reversaltrain=0;
  4905 								cananger=0;
  4906 								player[1].aitype=passivetype;
  4907 							}
  4908 						}
  4909 						if(tutorialstage==33){
  4910 							if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
  4911 						}
  4912 						if(tutorialstage==34){
  4913 							if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
  4914 						}
  4915 						if(tutorialstage==35){
  4916 							if(animation[player[0].targetanimation].attack==reversal){
  4917 								tutorialsuccess=1;
  4918 								reversaltrain=0;
  4919 								cananger=0;
  4920 								player[1].aitype=passivetype;
  4921 							}
  4922 						}
  4923 						if(tutorialstage==40){
  4924 							if(player[0].num_weapons>0)tutorialsuccess=1;
  4925 						}
  4926 						if(tutorialstage==41){
  4927 							if(player[0].weaponactive==-1&&player[0].num_weapons>0)tutorialsuccess=1;
  4928 						}
  4929 						if(tutorialstage==43){
  4930 							if(player[0].targetanimation==knifeslashstartanim)tutorialsuccess=1;
  4931 						}
  4932 						if(tutorialstage==44){
  4933 							if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
  4934 						}
  4935 						if(tutorialstage==45){
  4936 							if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
  4937 						}
  4938 						if(tutorialstage==46){
  4939 							if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
  4940 						}
  4941 						if(tutorialstage==49){
  4942 							if(player[1].weaponstuck!=-1)tutorialsuccess=1;
  4943 						}
  4944 						if(tutorialsuccess>=1)tutorialstagetime=tutorialmaxtime-3;
  4945 
  4946 
  4947 						if(tutorialstagetime==tutorialmaxtime-3){
  4948 							PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
  4949 							OPENAL_SetVolume(channels[consolesuccesssound], 256);
  4950 							OPENAL_SetPaused(channels[consolesuccesssound], false);
  4951 						}
  4952 
  4953 						if(tutorialsuccess>=1){
  4954 							if(tutorialstage==34||tutorialstage==35)
  4955 								tutorialstagetime=tutorialmaxtime-1;
  4956 						}
  4957 					}
  4958 
  4959 					if(tutoriallevel){
  4960 						if(tutorialstage<14||tutorialstage>=50){
  4961 							player[1].coords.y=300;
  4962 							player[1].velocity=0;
  4963 						}
  4964 					}
  4965 
  4966 					if(tutoriallevel!=1){
  4967 						if(bonustime==0&&bonus!=solidhit&&bonus!=spinecrusher&&bonus!=tracheotomy&&bonus!=backstab&&bonusvalue>10){
  4968 							PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
  4969 							OPENAL_SetVolume(channels[consolesuccesssound], 256);
  4970 							OPENAL_SetPaused(channels[consolesuccesssound], false);
  4971 						}
  4972 					}
  4973 					else
  4974 						if(bonustime==0){
  4975 							PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
  4976 							OPENAL_SetVolume(channels[fireendsound], 256);
  4977 							OPENAL_SetPaused(channels[fireendsound], false);
  4978 						}
  4979 						if(bonustime==0){
  4980 							if(bonus!=solidhit&&bonus!=twoxcombo&&bonus!=threexcombo&&bonus!=fourxcombo&&bonus!=megacombo)bonusnum[bonus]++;
  4981 							else bonusnum[bonus]+=0.15;
  4982 							if(tutoriallevel)bonusvalue=0;
  4983 							bonusvalue/=bonusnum[bonus];
  4984 							bonustotal+=bonusvalue;
  4985 						}
  4986 						bonustime+=multiplier;
  4987 
  4988 						if(environment==snowyenvironment){
  4989 							precipdelay-=multiplier;
  4990 							while(precipdelay<0){
  4991 								precipdelay+=.04;
  4992 								if(!detail)precipdelay+=.04;
  4993 								XYZ footvel,footpoint;
  4994 
  4995 								footvel=0;
  4996 								footpoint=viewer+viewerfacing*6;
  4997 								footpoint.y+=((float)abs(Random()%1200))/100-6;
  4998 								footpoint.x+=((float)abs(Random()%1200))/100-6;
  4999 								footpoint.z+=((float)abs(Random()%1200))/100-6;
  5000 								sprites.MakeSprite(snowsprite, footpoint,footvel, 1,1,1, .1, 1);
  5001 							}
  5002 						}
  5003 						for(k=0;k<numplayers;k++){
  5004 							if(player[k].aitype==playercontrolled)player[k].turnspeed=500;
  5005 							if(player[k].aitype!=playercontrolled)player[k].turnspeed=500;
  5006 
  5007 							if((player[k].isRun()&&((player[k].targetrotation!=rabbitrunninganim&&player[k].targetrotation!=wolfrunninganim)||player[k].targetframe==4))||player[k].targetanimation==removeknifeanim||player[k].targetanimation==crouchremoveknifeanim||player[k].targetanimation==flipanim||player[k].targetanimation==fightsidestep||player[k].targetanimation==walkanim){
  5008 								if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
  5009 								else if(player[k].rotation>player[k].targetrotation){
  5010 									player[k].rotation-=multiplier*player[k].turnspeed;
  5011 								}
  5012 								else if(player[k].rotation<player[k].targetrotation){
  5013 									player[k].rotation+=multiplier*player[k].turnspeed;
  5014 								}
  5015 							}
  5016 
  5017 
  5018 							if(player[k].isStop()||player[k].isLanding()||player[k].targetanimation==staggerbackhighanim||(player[k].targetanimation==sneakanim&&player[k].currentanimation==sneakanim)||player[k].targetanimation==staggerbackhardanim||player[k].targetanimation==backhandspringanim||player[k].targetanimation==dodgebackanim||player[k].targetanimation==rollanim||(animation[player[k].targetanimation].attack&&player[k].targetanimation!=rabbitkickanim&&(player[k].targetanimation!=crouchstabanim||player[k].hasvictim)&&(player[k].targetanimation!=swordgroundstabanim||player[k].hasvictim))){
  5019 								player[k].turnspeed*=2;
  5020 								if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
  5021 								else if(player[k].rotation>player[k].targetrotation){
  5022 									player[k].rotation-=multiplier*player[k].turnspeed;
  5023 								}
  5024 								else if(player[k].rotation<player[k].targetrotation){
  5025 									player[k].rotation+=multiplier*player[k].turnspeed;
  5026 								}
  5027 								player[k].turnspeed/=2;
  5028 							}
  5029 
  5030 							if(player[k].targetanimation==sneakanim&&player[k].currentanimation!=sneakanim){
  5031 								player[k].turnspeed*=4;
  5032 								if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
  5033 								else if(player[k].rotation>player[k].targetrotation){
  5034 									player[k].rotation-=multiplier*player[k].turnspeed;
  5035 								}
  5036 								else if(player[k].rotation<player[k].targetrotation){
  5037 									player[k].rotation+=multiplier*player[k].turnspeed;
  5038 								}
  5039 								player[k].turnspeed/=4;
  5040 							}
  5041 
  5042 							/*if(player[k].aitype!=passivetype||(findDistancefast(&player[k].coords,&viewer)<viewdistance*viewdistance))*/	player[k].DoStuff();
  5043 							if(player[k].immobile&&k!=0)player[k].coords=player[k].realoldcoords;
  5044 
  5045 							if(findDistancefast(&player[k].coords,&player[k].realoldcoords)>0){
  5046 								if(!player[k].skeleton.free&&player[k].targetanimation!=climbanim&&player[k].targetanimation!=hanganim){
  5047 									bool tempcollide=0;
  5048 
  5049 									if(player[k].collide<-.3)player[k].collide=-.3;
  5050 									if(player[k].collide>1)player[k].collide=1;
  5051 									player[k].collide-=multiplier*30;
  5052 
  5053 									if(player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z)){
  5054 										player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
  5055 									}
  5056 									if(terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz])
  5057 										for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
  5058 											i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
  5059 											if(objects.type[i]!=rocktype||(((objects.scale[i]>.5&&player[k].aitype==playercontrolled)||objects.position[i].y>player[k].coords.y))){
  5060 												lowpoint=player[k].coords;
  5061 												if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim&&!player[k].isFlip())lowpoint.y+=1.25;
  5062 												else lowpoint.y+=1.3;
  5063 												if(player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z)&&player[k].coords.y>terrain.getHeight(player[k].coords.x,player[k].coords.z)-.1){
  5064 													player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
  5065 												}
  5066 												/*while(player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z))
  5067 												player[k].coords+=terrain.getNormal(player[k].coords.x,player[k].coords.z)/50;
  5068 												*/
  5069 												if(player[k].SphereCheck(&lowpoint, 1.3, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
  5070 													flatfacing=lowpoint-player[k].coords;
  5071 													player[k].coords=lowpoint;
  5072 													player[k].coords.y-=1.3;
  5073 													player[k].collide=1;
  5074 													tempcollide=1;
  5075 													if(player[k].aitype==playercontrolled&&(player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].jumptogglekeydown&&player[k].jumpkeydown){
  5076 														lowpointtarget=lowpoint+DoRotation(player[k].facing,0,-90,0)*1.5;
  5077 														tempcoords1=lowpoint;
  5078 														whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
  5079 														if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
  5080 															player[k].target=0;
  5081 															player[k].targetanimation=walljumpleftanim;
  5082 															player[k].targetframe=0;
  5083 															float gLoc[3];
  5084 															float vel[3];
  5085 															gLoc[0]=player[k].coords.x;
  5086 															gLoc[1]=player[k].coords.y;
  5087 															gLoc[2]=player[k].coords.z;
  5088 															vel[0]=0;
  5089 															vel[1]=0;
  5090 															vel[2]=0;
  5091 															PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
  5092 															OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
  5093 															OPENAL_SetVolume(channels[movewhooshsound], 256);
  5094 															OPENAL_SetPaused(channels[movewhooshsound], false);
  5095 															if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
  5096 
  5097 															lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
  5098 															player[k].rotation=-asin(0-lowpointtarget.x);
  5099 															player[k].rotation*=360/6.28;
  5100 															if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
  5101 															player[k].targetrotation=player[k].rotation;
  5102 															player[k].lowrotation=player[k].rotation;
  5103 															if(k==0)numwallflipped++;
  5104 														}
  5105 														else
  5106 														{
  5107 															lowpoint=tempcoords1;
  5108 															lowpointtarget=lowpoint+DoRotation(player[k].facing,0,90,0)*1.5;
  5109 															whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
  5110 															if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
  5111 																player[k].target=0;
  5112 																player[k].targetanimation=walljumprightanim;
  5113 																player[k].targetframe=0;
  5114 																float gLoc[3];
  5115 																float vel[3];
  5116 																gLoc[0]=player[k].coords.x;
  5117 																gLoc[1]=player[k].coords.y;
  5118 																gLoc[2]=player[k].coords.z;
  5119 																vel[0]=0;
  5120 																vel[1]=0;
  5121 																vel[2]=0;
  5122 																PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
  5123 																OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
  5124 																OPENAL_SetVolume(channels[movewhooshsound], 256);
  5125 																OPENAL_SetPaused(channels[movewhooshsound], false);
  5126 																if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
  5127 
  5128 																lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
  5129 																player[k].rotation=-asin(0-lowpointtarget.x);
  5130 																player[k].rotation*=360/6.28;
  5131 																if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
  5132 																player[k].targetrotation=player[k].rotation;
  5133 																player[k].lowrotation=player[k].rotation;
  5134 																if(k==0)numwallflipped++;
  5135 															}
  5136 															else
  5137 															{
  5138 																lowpoint=tempcoords1;
  5139 																lowpointtarget=lowpoint+player[k].facing*2;
  5140 																whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
  5141 																if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
  5142 																	player[k].target=0;
  5143 																	player[k].targetanimation=walljumpbackanim;
  5144 																	player[k].targetframe=0;
  5145 																	float gLoc[3];
  5146 																	float vel[3];
  5147 																	gLoc[0]=player[k].coords.x;
  5148 																	gLoc[1]=player[k].coords.y;
  5149 																	gLoc[2]=player[k].coords.z;
  5150 																	vel[0]=0;
  5151 																	vel[1]=0;
  5152 																	vel[2]=0;
  5153 																	PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
  5154 																	OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
  5155 																	OPENAL_SetVolume(channels[movewhooshsound], 256);
  5156 																	OPENAL_SetPaused(channels[movewhooshsound], false);
  5157 																	if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
  5158 
  5159 																	lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
  5160 																	player[k].rotation=-asin(0-lowpointtarget.x);
  5161 																	player[k].rotation*=360/6.28;
  5162 																	if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
  5163 																	player[k].targetrotation=player[k].rotation;
  5164 																	player[k].lowrotation=player[k].rotation;
  5165 																	if(k==0)numwallflipped++;
  5166 																}
  5167 																else
  5168 																{
  5169 																	lowpoint=tempcoords1;
  5170 																	lowpointtarget=lowpoint-player[k].facing*2;
  5171 																	whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
  5172 																	if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
  5173 																		player[k].target=0;
  5174 																		player[k].targetanimation=walljumpfrontanim;
  5175 																		player[k].targetframe=0;
  5176 																		float gLoc[3];
  5177 																		float vel[3];
  5178 																		gLoc[0]=player[k].coords.x;
  5179 																		gLoc[1]=player[k].coords.y;
  5180 																		gLoc[2]=player[k].coords.z;
  5181 																		vel[0]=0;
  5182 																		vel[1]=0;
  5183 																		vel[2]=0;
  5184 																		PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
  5185 																		OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
  5186 																		OPENAL_SetVolume(channels[movewhooshsound], 256);
  5187 																		OPENAL_SetPaused(channels[movewhooshsound], false);
  5188 																		if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
  5189 
  5190 																		lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
  5191 																		player[k].rotation=-asin(0-lowpointtarget.x);
  5192 																		player[k].rotation*=360/6.28;
  5193 																		if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
  5194 																		player[k].rotation+=180;
  5195 																		player[k].targetrotation=player[k].rotation;
  5196 																		player[k].lowrotation=player[k].rotation;
  5197 																		if(k==0)numwallflipped++;
  5198 																	}
  5199 																}
  5200 															}
  5201 														}
  5202 													}
  5203 												}
  5204 											}
  5205 											else if(objects.type[i]==rocktype){
  5206 												lowpoint2=player[k].coords;
  5207 												lowpoint=player[k].coords;
  5208 												lowpoint.y+=2;
  5209 												if(objects.model[i].LineCheck(&lowpoint,&lowpoint2,&colpoint,&objects.position[i],&objects.rotation[i])!=-1){
  5210 													player[k].coords=colpoint;
  5211 													player[k].collide=1;
  5212 													tempcollide=1;
  5213 
  5214 													if((player[k].targetanimation==jumpdownanim||player[k].isFlip())){
  5215 														if(player[k].isFlip()&&animation[player[k].targetanimation].label[player[k].targetframe]==7)player[k].RagDoll(0);
  5216 
  5217 														if(player[k].targetanimation==jumpupanim){player[k].jumppower=-4;player[k].targetanimation=player[k].getIdle();}
  5218 														player[k].target=0;
  5219 														player[k].targetframe=0;
  5220 														player[k].onterrain=1;
  5221 
  5222 														if(player[k].id==0){
  5223 															OPENAL_SetPaused(channels[whooshsound], true);
  5224 															OPENAL_SetVolume(channels[whooshsound], 0);
  5225 														}
  5226 
  5227 														if((player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].wasLanding()){
  5228 															if(player[k].isFlip())player[k].jumppower=-4;
  5229 															player[k].targetanimation=player[k].getLanding();
  5230 															float gLoc[3];
  5231 															float vel[3];
  5232 															gLoc[0]=player[k].coords.x;
  5233 															gLoc[1]=player[k].coords.y;
  5234 															gLoc[2]=player[k].coords.z;
  5235 															vel[0]=player[k].velocity.x;
  5236 															vel[1]=player[k].velocity.y;
  5237 															vel[2]=player[k].velocity.z;
  5238 															PlaySoundEx( landsound, samp[landsound], NULL, true);
  5239 															OPENAL_3D_SetAttributes(channels[landsound], gLoc, vel);
  5240 															OPENAL_SetVolume(channels[landsound], 128);
  5241 															OPENAL_SetPaused(channels[landsound], false);
  5242 															if(k==0){
  5243 																envsound[numenvsounds]=player[k].coords;
  5244 																envsoundvol[numenvsounds]=16;
  5245 																envsoundlife[numenvsounds]=.4;
  5246 																numenvsounds++;
  5247 															}
  5248 
  5249 														}
  5250 													}
  5251 												}
  5252 											}
  5253 										}
  5254 										if(tempcollide&&terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz]&&(/*player[k].jumptogglekeydown*/1==1||player[k].aitype!=playercontrolled))
  5255 											for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
  5256 												i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
  5257 												lowpoint=player[k].coords;
  5258 												lowpoint.y+=1.35;
  5259 												if(objects.type[i]!=rocktype)
  5260 													if(player[k].SphereCheck(&lowpoint, 1.33, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
  5261 														if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim&&player[k].onterrain)player[k].avoidcollided=1;
  5262 														player[k].coords=lowpoint;
  5263 														player[k].coords.y-=1.35;
  5264 														player[k].collide=1;
  5265 
  5266 														if((player[k].grabdelay<=0||player[k].aitype!=playercontrolled)&&((/*(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)&&*/player[k].currentanimation!=climbanim&&player[k].currentanimation!=hanganim&&!player[k].isWallJump())||player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim)){
  5267 															lowpoint=player[k].coords;
  5268 															objects.model[i].SphereCheckPossible(&lowpoint, 1.5, &objects.position[i], &objects.rotation[i]);
  5269 															lowpoint=player[k].coords;
  5270 															lowpoint.y+=.05;
  5271 															facing=0;
  5272 															facing.z=-1;
  5273 															facing=DoRotation(facing,0,player[k].targetrotation+180,0);
  5274 															lowpointtarget=lowpoint+facing*1.4;
  5275 															whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
  5276 															if(whichhit!=-1){
  5277 																lowpoint=player[k].coords;
  5278 																lowpoint.y+=.1;
  5279 																lowpointtarget=lowpoint+facing*1.4;
  5280 																lowpoint2=lowpoint;
  5281 																lowpointtarget2=lowpointtarget;
  5282 																lowpoint3=lowpoint;
  5283 																lowpointtarget3=lowpointtarget;
  5284 																lowpoint4=lowpoint;
  5285 																lowpointtarget4=lowpointtarget;
  5286 																lowpoint5=lowpoint;
  5287 																lowpointtarget5=lowpointtarget;
  5288 																lowpoint6=lowpoint;
  5289 																lowpointtarget6=lowpointtarget;
  5290 																lowpoint7=lowpoint;
  5291 																lowpointtarget7=lowpoint;
  5292 																lowpoint2.x+=.1;
  5293 																lowpointtarget2.x+=.1;
  5294 																lowpoint3.z+=.1;
  5295 																lowpointtarget3.z+=.1;
  5296 																lowpoint4.x-=.1;
  5297 																lowpointtarget4.x-=.1;
  5298 																lowpoint5.z-=.1;
  5299 																lowpointtarget5.z-=.1;
  5300 																lowpoint6.y+=45/13;
  5301 																lowpointtarget6.y+=45/13;
  5302 																lowpointtarget6+=facing*.6;
  5303 																lowpointtarget7.y+=90/13;
  5304 																whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
  5305 																if(objects.friction[i]>.5)
  5306 																	if(whichhit!=-1){
  5307 																		//if(k==0){
  5308 																		if(whichhit!=-1)if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim)player[k].collided=1;
  5309 																		if(checkcollide(lowpoint7,lowpointtarget7)==-1)
  5310 																			if(checkcollide(lowpoint6,lowpointtarget6)==-1)
  5311 																				if(objects.model[i].LineCheckPossible(&lowpoint2,&lowpointtarget2,&colpoint,&objects.position[i],&objects.rotation[i])!=-1&&objects.model[i].LineCheckPossible(&lowpoint3,&lowpointtarget3,&colpoint,&objects.position[i],&objects.rotation[i])!=-1&&objects.model[i].LineCheckPossible(&lowpoint4,&lowpointtarget4,&colpoint,&objects.position[i],&objects.rotation[i])!=-1&&objects.model[i].LineCheckPossible(&lowpoint5,&lowpointtarget5,&colpoint,&objects.position[i],&objects.rotation[i])!=-1)
  5312 																					for(j=0;j<45;j++){
  5313 																						lowpoint=player[k].coords;
  5314 																						lowpoint.y+=(float)j/13;
  5315 																						lowpointtarget=lowpoint+facing*1.4;
  5316 																						if(objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint2,&objects.position[i],&objects.rotation[i])==-1){
  5317 																							if(j<=6){
  5318 																								j=100;
  5319 																							}
  5320 																							/*if(j>=25&&(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)){
  5321 																							j=100;
  5322 																							}*/
  5323 																							if(j<=25&&player[k].targetanimation==jumpdownanim){
  5324 																								j=100;
  5325 																							}
  5326 																							if(j!=100&&(/*j>25||(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)||*/player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim)){
  5327 																								lowpoint=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0);
  5328 																								if(1==1/*dotproduct(&player[k].velocity,&lowpoint)>0||player[k].aitype!=playercontrolled||(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim||player[k].targetanimation==jumpupanim)*/){
  5329 																									lowpoint=player[k].coords;
  5330 																									lowpoint.y+=(float)j/13;
  5331 																									lowpointtarget=lowpoint+facing*1.3;
  5332 																									flatfacing=player[k].coords;
  5333 																									player[k].coords=colpoint-DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0)*.01;
  5334 																									player[k].coords.y=lowpointtarget.y-.07;
  5335 																									player[k].currentoffset=(flatfacing-player[k].coords)/player[k].scale;
  5336 
  5337 																									if(j>10||!player[k].isRun()){
  5338 																										if(player[k].targetanimation==jumpdownanim||player[k].targetanimation==jumpupanim){
  5339 																											if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
  5340 																										}
  5341 																										float gLoc[3];
  5342 																										float vel[3];
  5343 																										gLoc[0]=player[k].coords.x;
  5344 																										gLoc[1]=player[k].coords.y;
  5345 																										gLoc[2]=player[k].coords.z;
  5346 																										vel[0]=player[k].velocity.x;
  5347 																										vel[1]=player[k].velocity.y;
  5348 																										vel[2]=player[k].velocity.z;
  5349 																										PlaySoundEx( jumpsound, samp[jumpsound], NULL, true);
  5350 																										OPENAL_3D_SetAttributes(channels[jumpsound], gLoc, vel);
  5351 																										OPENAL_SetVolume(channels[jumpsound], 128);
  5352 																										OPENAL_SetPaused(channels[jumpsound], false);
  5353 
  5354 																										lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
  5355 																										player[k].rotation=-asin(0-lowpointtarget.x);
  5356 																										player[k].rotation*=360/6.28;
  5357 																										if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
  5358 																										player[k].targetrotation=player[k].rotation;
  5359 																										player[k].lowrotation=player[k].rotation;
  5360 
  5361 																										//player[k].velocity=lowpointtarget*.03;
  5362 																										player[k].velocity=0;
  5363 
  5364 																										if(/*(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)||*/player[k].targetanimation==jumpupanim){
  5365 																											//player[k].currentanimation=climbanim;
  5366 																											player[k].targetanimation=climbanim;
  5367 																											player[k].jumppower=0;
  5368 																											player[k].jumpclimb=1;
  5369 																										}
  5370 																										player[k].transspeed=6;
  5371 																										player[k].target=0;
  5372 
  5373 																										//player[k].currentframe=1;
  5374 																										player[k].targetframe=1;
  5375 																										if(j>25){
  5376 																											//player[k].currentframe=0;
  5377 																											player[k].targetframe=0;
  5378 																											//player[k].currentanimation=hanganim;
  5379 																											player[k].targetanimation=hanganim;
  5380 																											player[k].jumppower=0;
  5381 																										}
  5382 																									}
  5383 																									j=100;
  5384 																								}
  5385 																							}
  5386 																						}
  5387 																					}
  5388 																					//}
  5389 																	}
  5390 															}
  5391 														}
  5392 													}
  5393 											}
  5394 											if(player[k].collide<=0){
  5395 												if(!player[k].onterrain&&player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim&&player[k].targetanimation!=climbanim&&player[k].targetanimation!=hanganim&&!player[k].isWallJump()&&!player[k].isFlip()){
  5396 													if(player[k].currentanimation!=climbanim&&player[k].currentanimation!=tempanim&&player[k].targetanimation!=backhandspringanim&&(player[k].targetanimation!=rollanim||player[k].targetframe<2||player[k].targetframe>6)){
  5397 														if(player[k].targetanimation==staggerbackhighanim||player[k].targetanimation==staggerbackhardanim)player[k].RagDoll(0);
  5398 														player[k].targetanimation=jumpdownanim;
  5399 														player[k].targetframe=0;
  5400 														player[k].target=0;
  5401 
  5402 														float gLoc[3];
  5403 														float vel[3];
  5404 														gLoc[0]=player[k].coords.x;
  5405 														gLoc[1]=player[k].coords.y;
  5406 														gLoc[2]=player[k].coords.z;
  5407 														vel[0]=player[k].velocity.x;
  5408 														vel[1]=player[k].velocity.y;
  5409 														vel[2]=player[k].velocity.z;
  5410 														if(k==0){
  5411 															PlaySoundEx( whooshsound, samp[whooshsound], NULL, true);
  5412 															OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
  5413 															OPENAL_SetVolume(channels[whooshsound], 128);
  5414 															OPENAL_SetPaused(channels[whooshsound], false);
  5415 														}
  5416 													}
  5417 													player[k].velocity.y+=gravity;
  5418 												}
  5419 											}
  5420 								}
  5421 							}
  5422 							player[k].realoldcoords=player[k].coords;
  5423 						}
  5424 
  5425 						static XYZ oldviewer;
  5426 
  5427 						if(indialogue==-1){
  5428 							player[0].forwardkeydown=IsKeyDown(theKeyMap, forwardkey);
  5429 							player[0].leftkeydown=IsKeyDown(theKeyMap, leftkey);
  5430 							player[0].backkeydown=IsKeyDown(theKeyMap, backkey);
  5431 							player[0].rightkeydown=IsKeyDown(theKeyMap, rightkey);
  5432 							player[0].jumpkeydown=IsKeyDown(theKeyMap, jumpkey);
  5433 							player[0].crouchkeydown=IsKeyDown(theKeyMap, crouchkey);
  5434 							player[0].drawkeydown=IsKeyDown(theKeyMap, drawkey);
  5435 							player[0].throwkeydown=IsKeyDown(theKeyMap, throwkey);
  5436 						}
  5437 						else
  5438 						{
  5439 							player[0].forwardkeydown=0;
  5440 							player[0].leftkeydown=0;
  5441 							player[0].backkeydown=0;
  5442 							player[0].rightkeydown=0;
  5443 							player[0].jumpkeydown=0;
  5444 							player[0].crouchkeydown=0;
  5445 							player[0].drawkeydown=0;
  5446 							player[0].throwkeydown=0;
  5447 						}
  5448 
  5449 						if(!player[0].jumpkeydown)player[0].jumpclimb=0;
  5450 
  5451 
  5452 						static bool endkeydown;
  5453 						if(indialogue!=-1){
  5454 							cameramode=1;
  5455 							if(directing){
  5456 								facing=0;
  5457 								facing.z=-1;
  5458 
  5459 								facing=DoRotation(facing,-rotation2,0,0);
  5460 								facing=DoRotation(facing,0,0-rotation,0);
  5461 
  5462 								flatfacing=0;
  5463 								flatfacing.z=-1;
  5464 
  5465 								flatfacing=DoRotation(flatfacing,0,-rotation,0);
  5466 
  5467 								if(IsKeyDown(theKeyMap, forwardkey))viewer+=facing*multiplier*4;
  5468 								if(IsKeyDown(theKeyMap, backkey))viewer-=facing*multiplier*4;
  5469 								if(IsKeyDown(theKeyMap, leftkey))viewer+=DoRotation(flatfacing*multiplier,0,90,0)*4;
  5470 								if(IsKeyDown(theKeyMap, rightkey))viewer+=DoRotation(flatfacing*multiplier,0,-90,0)*4;
  5471 								if(IsKeyDown(theKeyMap, jumpkey))viewer.y+=multiplier*4;
  5472 								if(IsKeyDown(theKeyMap, crouchkey))viewer.y-=multiplier*4;
  5473 								if(!endkeydown&&(IsKeyDown(theKeyMap, MAC_1_KEY)||IsKeyDown(theKeyMap, MAC_2_KEY)||IsKeyDown(theKeyMap, MAC_3_KEY)||IsKeyDown(theKeyMap, MAC_4_KEY)||IsKeyDown(theKeyMap, MAC_5_KEY)
  5474 									||IsKeyDown(theKeyMap, MAC_6_KEY)||IsKeyDown(theKeyMap, MAC_7_KEY)||IsKeyDown(theKeyMap, MAC_8_KEY)||IsKeyDown(theKeyMap, MAC_9_KEY)||IsKeyDown(theKeyMap, MAC_0_KEY)
  5475 									||IsKeyDown(theKeyMap, MAC_MINUS_KEY))){
  5476 										int whichend;
  5477 										if(IsKeyDown(theKeyMap, MAC_1_KEY))whichend=1;
  5478 										if(IsKeyDown(theKeyMap, MAC_2_KEY))whichend=2;
  5479 										if(IsKeyDown(theKeyMap, MAC_3_KEY))whichend=3;
  5480 										if(IsKeyDown(theKeyMap, MAC_4_KEY))whichend=4;
  5481 										if(IsKeyDown(theKeyMap, MAC_5_KEY))whichend=5;
  5482 										if(IsKeyDown(theKeyMap, MAC_6_KEY))whichend=6;
  5483 										if(IsKeyDown(theKeyMap, MAC_7_KEY))whichend=7;
  5484 										if(IsKeyDown(theKeyMap, MAC_8_KEY))whichend=8;
  5485 										if(IsKeyDown(theKeyMap, MAC_9_KEY))whichend=9;
  5486 										if(IsKeyDown(theKeyMap, MAC_0_KEY))whichend=0;
  5487 										if(IsKeyDown(theKeyMap, MAC_MINUS_KEY))whichend=-1;
  5488 										if(whichend!=-1){
  5489 											participantfocus[whichdialogue][indialogue]=whichend;
  5490 											participantlocation[whichdialogue][whichend]=player[whichend].coords;
  5491 											participantrotation[whichdialogue][whichend]=player[whichend].rotation;
  5492 										}
  5493 										if(whichend==-1){
  5494 											participantfocus[whichdialogue][indialogue]=-1;
  5495 										}
  5496 										if(player[participantfocus[whichdialogue][indialogue]].dead){
  5497 											indialogue=-1;
  5498 											directing=0;
  5499 											cameramode=0;
  5500 										}
  5501 										dialoguecamera[whichdialogue][indialogue]=viewer;
  5502 										dialoguecamerarotation[whichdialogue][indialogue]=rotation;
  5503 										dialoguecamerarotation2[whichdialogue][indialogue]=rotation2;
  5504 										indialogue++;
  5505 										if(indialogue<numdialogueboxes[whichdialogue]){
  5506 											if(dialogueboxsound[whichdialogue][indialogue]!=0){
  5507 												static float gLoc[3];
  5508 												static float vel[3];
  5509 												XYZ temppos;
  5510 												temppos=player[participantfocus[whichdialogue][indialogue]].coords;
  5511 												temppos=temppos-viewer;
  5512 												Normalise(&temppos);
  5513 												temppos+=viewer;
  5514 
  5515 												gLoc[0]=temppos.x;
  5516 												gLoc[1]=temppos.y;
  5517 												gLoc[2]=temppos.z;vel[0]=0;
  5518 												vel[1]=0;
  5519 												vel[2]=0;
  5520 												int whichsoundplay;
  5521 												if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
  5522 												if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
  5523 												if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
  5524 												if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
  5525 												if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
  5526 												if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
  5527 												if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
  5528 												if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
  5529 												if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
  5530 												if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
  5531 												if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
  5532 												if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
  5533 												if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
  5534 												if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
  5535 												if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
  5536 												if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
  5537 												if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
  5538 												if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
  5539 												if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
  5540 												if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
  5541 												PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
  5542 												OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
  5543 												OPENAL_SetVolume(channels[whichsoundplay], 256);
  5544 												OPENAL_SetPaused(channels[whichsoundplay], false);
  5545 											}
  5546 										}
  5547 
  5548 										for(j=0;j<numplayers;j++){
  5549 											participantfacing[whichdialogue][indialogue][j]=participantfacing[whichdialogue][indialogue-1][j];
  5550 										}
  5551 
  5552 										endkeydown=1;
  5553 									}
  5554 									if((IsKeyDown(theKeyMap, MAC_NUMPAD_1_KEY)||IsKeyDown(theKeyMap, MAC_NUMPAD_2_KEY)||IsKeyDown(theKeyMap, MAC_NUMPAD_3_KEY)||IsKeyDown(theKeyMap, MAC_NUMPAD_4_KEY)||IsKeyDown(theKeyMap, MAC_NUMPAD_5_KEY)
  5555 										||IsKeyDown(theKeyMap, MAC_NUMPAD_6_KEY)||IsKeyDown(theKeyMap, MAC_NUMPAD_7_KEY)||IsKeyDown(theKeyMap, MAC_NUMPAD_8_KEY)||IsKeyDown(theKeyMap, MAC_NUMPAD_9_KEY)||IsKeyDown(theKeyMap, MAC_NUMPAD_0_KEY)
  5556 										)){
  5557 											int whichend;
  5558 											if(IsKeyDown(theKeyMap, MAC_NUMPAD_1_KEY))whichend=1;
  5559 											if(IsKeyDown(theKeyMap, MAC_NUMPAD_2_KEY))whichend=2;
  5560 											if(IsKeyDown(theKeyMap, MAC_NUMPAD_3_KEY))whichend=3;
  5561 											if(IsKeyDown(theKeyMap, MAC_NUMPAD_4_KEY))whichend=4;
  5562 											if(IsKeyDown(theKeyMap, MAC_NUMPAD_5_KEY))whichend=5;
  5563 											if(IsKeyDown(theKeyMap, MAC_NUMPAD_6_KEY))whichend=6;
  5564 											if(IsKeyDown(theKeyMap, MAC_NUMPAD_7_KEY))whichend=7;
  5565 											if(IsKeyDown(theKeyMap, MAC_NUMPAD_8_KEY))whichend=8;
  5566 											if(IsKeyDown(theKeyMap, MAC_NUMPAD_9_KEY))whichend=9;
  5567 											if(IsKeyDown(theKeyMap, MAC_NUMPAD_0_KEY))whichend=0;
  5568 											participantfacing[whichdialogue][indialogue][whichend]=facing;
  5569 										}
  5570 										if(!IsKeyDown(theKeyMap, MAC_1_KEY)&&!IsKeyDown(theKeyMap, MAC_2_KEY)&&!IsKeyDown(theKeyMap, MAC_3_KEY)&&!IsKeyDown(theKeyMap, MAC_4_KEY)&&!IsKeyDown(theKeyMap, MAC_5_KEY)
  5571 											&&!IsKeyDown(theKeyMap, MAC_6_KEY)&&!IsKeyDown(theKeyMap, MAC_7_KEY)&&!IsKeyDown(theKeyMap, MAC_8_KEY)&&!IsKeyDown(theKeyMap, MAC_9_KEY)&&!IsKeyDown(theKeyMap, MAC_0_KEY)
  5572 											&&!IsKeyDown(theKeyMap, MAC_MINUS_KEY)){
  5573 												endkeydown=0;
  5574 											}
  5575 											if(indialogue>=numdialogueboxes[whichdialogue]){
  5576 												indialogue=-1;
  5577 												directing=0;
  5578 												cameramode=0;
  5579 											}
  5580 							}
  5581 							if(!directing){
  5582 								OPENAL_SetPaused(channels[whooshsound], true);
  5583 								viewer=dialoguecamera[whichdialogue][indialogue];
  5584 								if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.1){
  5585 									viewer.y=terrain.getHeight(viewer.x,viewer.z)+.1;
  5586 								}
  5587 								rotation=dialoguecamerarotation[whichdialogue][indialogue];
  5588 								rotation2=dialoguecamerarotation2[whichdialogue][indialogue];
  5589 								if(dialoguetime>0.5)
  5590 									if((!endkeydown&&(IsKeyDown(theKeyMap, MAC_1_KEY)||IsKeyDown(theKeyMap, MAC_2_KEY)||IsKeyDown(theKeyMap, MAC_3_KEY)||IsKeyDown(theKeyMap, MAC_4_KEY)||IsKeyDown(theKeyMap, MAC_5_KEY)
  5591 										||IsKeyDown(theKeyMap, MAC_6_KEY)||IsKeyDown(theKeyMap, MAC_7_KEY)||IsKeyDown(theKeyMap, MAC_8_KEY)||IsKeyDown(theKeyMap, MAC_9_KEY)||IsKeyDown(theKeyMap, MAC_0_KEY)
  5592 										||IsKeyDown(theKeyMap, MAC_MINUS_KEY)))||(IsKeyDown(theKeyMap, attackkey)&&!oldbuttondialogue)){
  5593 											indialogue++;
  5594 											endkeydown=1;
  5595 											if(indialogue<numdialogueboxes[whichdialogue]){
  5596 												if(dialogueboxsound[whichdialogue][indialogue]!=0){
  5597 													static float gLoc[3];
  5598 													static float vel[3];
  5599 													XYZ temppos;
  5600 													temppos=player[participantfocus[whichdialogue][indialogue]].coords;
  5601 													temppos=temppos-viewer;
  5602 													Normalise(&temppos);
  5603 													temppos+=viewer;
  5604 
  5605 													gLoc[0]=temppos.x;
  5606 													gLoc[1]=temppos.y;
  5607 													gLoc[2]=temppos.z;vel[0]=0;
  5608 													vel[1]=0;
  5609 													vel[2]=0;
  5610 													int whichsoundplay;
  5611 													if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
  5612 													if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
  5613 													if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
  5614 													if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
  5615 													if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
  5616 													if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
  5617 													if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
  5618 													if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
  5619 													if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
  5620 													if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
  5621 													if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
  5622 													if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
  5623 													if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
  5624 													if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
  5625 													if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
  5626 													if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
  5627 													if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
  5628 													if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
  5629 													if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
  5630 													if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
  5631 													if(dialogueboxsound[whichdialogue][indialogue]==-6)whichsoundplay=alarmsound;
  5632 													if(dialogueboxsound[whichdialogue][indialogue]!=-5){
  5633 														PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
  5634 														OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
  5635 														OPENAL_SetVolume(channels[whichsoundplay], 256);
  5636 														OPENAL_SetPaused(channels[whichsoundplay], false);
  5637 													}
  5638 													if(dialogueboxsound[whichdialogue][indialogue]==-5){
  5639 														hotspot[numhotspots]=player[0].coords;
  5640 														hotspotsize[numhotspots]=10;
  5641 														hotspottype[numhotspots]=-1;
  5642 
  5643 														numhotspots++;
  5644 													}
  5645 													if(dialogueboxsound[whichdialogue][indialogue]==-6){
  5646 														hostile=1;
  5647 													}
  5648 
  5649 													if(player[participantfocus[whichdialogue][indialogue]].dead){
  5650 														indialogue=-1;
  5651 														directing=0;
  5652 														cameramode=0;
  5653 													}
  5654 												}
  5655 											}
  5656 										}
  5657 										if(!IsKeyDown(theKeyMap, MAC_1_KEY)&&!IsKeyDown(theKeyMap, MAC_2_KEY)&&!IsKeyDown(theKeyMap, MAC_3_KEY)&&!IsKeyDown(theKeyMap, MAC_4_KEY)&&!IsKeyDown(theKeyMap, MAC_5_KEY)
  5658 											&&!IsKeyDown(theKeyMap, MAC_6_KEY)&&!IsKeyDown(theKeyMap, MAC_7_KEY)&&!IsKeyDown(theKeyMap, MAC_8_KEY)&&!IsKeyDown(theKeyMap, MAC_9_KEY)&&!IsKeyDown(theKeyMap, MAC_0_KEY)
  5659 											&&!IsKeyDown(theKeyMap, MAC_MINUS_KEY)){
  5660 												endkeydown=0;
  5661 											}
  5662 											if(indialogue>=numdialogueboxes[whichdialogue]){
  5663 												indialogue=-1;
  5664 												directing=0;
  5665 												cameramode=0;
  5666 												if(dialoguetype[whichdialogue]>19&&dialoguetype[whichdialogue]<30){
  5667 													hostile=1;
  5668 												}
  5669 												if(dialoguetype[whichdialogue]>29&&dialoguetype[whichdialogue]<40){
  5670 													windialogue=1;
  5671 												}
  5672 												if(dialoguetype[whichdialogue]>49&&dialoguetype[whichdialogue]<60){
  5673 													hostile=1;
  5674 													for(i=1;i<numplayers;i++){
  5675 														player[i].aitype = attacktypecutoff;
  5676 													}
  5677 												}
  5678 											}
  5679 							}
  5680 						}
  5681 
  5682 						if(!IsKeyDown(theKeyMap, attackkey))oldbuttondialogue=0;
  5683 						else oldbuttondialogue=1;
  5684 
  5685 						static float keyrefreshdelay=0,bigrefreshdelay=0;
  5686 
  5687 						//Net updates
  5688 
  5689 						/*keyrefreshdelay-=multiplier;
  5690 						bigrefreshdelay-=multiplier;
  5691 
  5692 						if(keyrefreshdelay<=0){
  5693 						static int concat[4];
  5694 
  5695 						concat[0]=player[0].forwardkeydown;
  5696 						concat[0]=concat[0]*2+player[0].forwardstogglekeydown;
  5697 						concat[0]=concat[0]*2+player[0].rightkeydown;
  5698 						concat[0]=concat[0]*2+player[0].leftkeydown;
  5699 						concat[0]=concat[0]*2+player[0].backkeydown;
  5700 						concat[0]=concat[0]*2+player[0].jumpkeydown;
  5701 						concat[0]=concat[0]*2+player[0].jumptogglekeydown;
  5702 						concat[0]=concat[0]*2+player[0].crouchkeydown;
  5703 
  5704 						concat[1]=player[0].crouchtogglekeydown;
  5705 						concat[1]=concat[1]*2+player[0].drawkeydown;
  5706 						concat[1]=concat[1]*2+player[0].drawtogglekeydown;
  5707 						concat[1]=concat[1]*2+player[0].throwkeydown;
  5708 						concat[1]=concat[1]*2+player[0].throwtogglekeydown;
  5709 						concat[1]=concat[1]*2+player[0].attackkeydown;
  5710 
  5711 						//concat[2]=(char)((int)(rotation/2)%180);
  5712 
  5713 						//concat[3]=(char)((int)(rotation2/2)%180);
  5714 
  5715 						chatname[0]=concat[0]-128;
  5716 						chatname[1]=concat[1]-128;
  5717 						//chatname[2]=concat[2]-128;
  5718 						//chatname[3]=concat[3]-128;
  5719 						int temppoint=2;
  5720 						memcpy(chatname+temppoint,&rotation,sizeof(float));
  5721 						temppoint+=sizeof(float);
  5722 						memcpy(chatname+temppoint,&rotation2,sizeof(float));
  5723 						temppoint+=sizeof(float);
  5724 
  5725 						chatname[temppoint]='\0';
  5726 
  5727 						//if(!ishost)NetworkSendPlayerMessage( chatname, kMessageType_Keys );
  5728 						//if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_Keys );
  5729 						//keyrefreshdelay=.01;
  5730 						keyrefreshdelay=.03;
  5731 						}
  5732 
  5733 						if(bigrefreshdelay<=0){
  5734 						for(i=0;i<1;i++){
  5735 						/*int temppoint=0;
  5736 						memcpy(chatname+temppoint,&i,sizeof(int));
  5737 						temppoint+=sizeof(int);
  5738 						memcpy(chatname+temppoint,&player[i].coords.x,sizeof(float));
  5739 						temppoint+=sizeof(float);
  5740 						memcpy(chatname+temppoint,&player[i].coords.y,sizeof(float));
  5741 						temppoint+=sizeof(float);
  5742 						memcpy(chatname+temppoint,&player[i].coords.z,sizeof(float));
  5743 						temppoint+=sizeof(float);
  5744 						memcpy(chatname+temppoint,&player[i].damage,sizeof(float));
  5745 						temppoint+=sizeof(float);
  5746 						memcpy(chatname+temppoint,&player[i].target,sizeof(float));
  5747 						temppoint+=sizeof(float);
  5748 						memcpy(chatname+temppoint,&player[i].targetanimation,sizeof(int));
  5749 						temppoint+=sizeof(int);
  5750 						memcpy(chatname+temppoint,&player[i].currentanimation,sizeof(int));
  5751 						temppoint+=sizeof(int);
  5752 						memcpy(chatname+temppoint,&player[i].velocity.x,sizeof(float));
  5753 						temppoint+=sizeof(float);
  5754 						memcpy(chatname+temppoint,&player[i].velocity.y,sizeof(float));
  5755 						temppoint+=sizeof(float);
  5756 						memcpy(chatname+temppoint,&player[i].velocity.z,sizeof(float));
  5757 						temppoint+=sizeof(float);
  5758 						memcpy(chatname+temppoint,&player[i].targetframe,sizeof(int));
  5759 						temppoint+=sizeof(int);
  5760 						memcpy(chatname+temppoint,&player[i].currentframe,sizeof(int));
  5761 						temppoint+=sizeof(int);
  5762 						memcpy(chatname+temppoint,&player[i].rotation,sizeof(float));
  5763 						temppoint+=sizeof(float);
  5764 						memcpy(chatname+temppoint,&player[i].targetrotation,sizeof(float));
  5765 						temppoint+=sizeof(float);
  5766 						memcpy(chatname+temppoint,&player[i].bloodloss,sizeof(float));
  5767 						temppoint+=sizeof(float);
  5768 						memcpy(chatname+temppoint,&player[i].weaponactive,sizeof(int));
  5769 						temppoint+=sizeof(int);
  5770 						memcpy(chatname+temppoint,&player[i].num_weapons,sizeof(int));
  5771 						temppoint+=sizeof(int);
  5772 						memcpy(chatname+temppoint,&player[i].weaponids[0],sizeof(int));
  5773 						temppoint+=sizeof(int);
  5774 						memcpy(chatname+temppoint,&player[i].weaponids[1],sizeof(int));
  5775 						temppoint+=sizeof(int);
  5776 						memcpy(chatname+temppoint,&player[i].weaponids[2],sizeof(int));
  5777 						temppoint+=sizeof(int);
  5778 						memcpy(chatname+temppoint,&player[i].weaponids[3],sizeof(int));
  5779 						temppoint+=sizeof(int);
  5780 						chatname[temppoint]='\0';
  5781 
  5782 						sprintf (chatname, "%d %f %f %f %f %f %d %d %f %f %f %d %d %f %f %f",i,player[i].coords.x,player[i].coords.y,player[i].coords.z,player[i].damage,player[i].target, player[i].targetanimation, player[i].currentanimation, player[i].velocity.x, player[i].velocity.y, player[i].velocity.z, player[i].targetframe, player[i].currentframe, player[i].rotation, player[i].targetrotation);
  5783 						//if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_PlayerState );
  5784 						//else NetworkSendPlayerMessage( chatname, kMessageType_PlayerState );
  5785 
  5786 						sprintf (chatname, "%d %f %d %d %d %d %d %d %d %d %f",i,player[i].bloodloss, player[i].weaponactive, player[i].num_weapons, player[i].weaponids[0], player[i].weaponids[1], player[i].weaponids[2], player[i].weaponids[3],player[i].dead,player[i].skeleton.free,player[i].permanentdamage);
  5787 
  5788 						//if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_PlayerStateMisc );
  5789 						//else NetworkSendPlayerMessage( chatname, kMessageType_PlayerStateMisc );
  5790 						}
  5791 						//bigrefreshdelay=.02;
  5792 						bigrefreshdelay=.1;
  5793 						}
  5794 						}*/
  5795 
  5796 						if(!player[0].jumpkeydown){
  5797 							player[0].jumptogglekeydown=0;
  5798 						}
  5799 						if(player[0].jumpkeydown&&player[0].targetanimation!=jumpupanim&&player[0].targetanimation!=jumpdownanim&&!player[0].isFlip())player[0].jumptogglekeydown=1;
  5800 
  5801 
  5802 						dialoguetime+=multiplier;
  5803 						skybox.cloudmove+=multiplier;
  5804 						hawkrotation+=multiplier*25;
  5805 						realhawkcoords=0;
  5806 						realhawkcoords.x=25;
  5807 						realhawkcoords=DoRotation(realhawkcoords,0,hawkrotation,0)+hawkcoords;
  5808 						hawkcalldelay-=multiplier/2;
  5809 
  5810 						if(hawkcalldelay<=0)
  5811 						{
  5812 							static float gLoc[3];
  5813 							static float vel[3];
  5814 							gLoc[0]=realhawkcoords.x;
  5815 							gLoc[1]=realhawkcoords.y;
  5816 							gLoc[2]=realhawkcoords.z;
  5817 							vel[0]=0;
  5818 							vel[1]=0;
  5819 							vel[2]=0;
  5820 							PlaySoundEx( hawksound, samp[hawksound], NULL, true);
  5821 							OPENAL_3D_SetAttributes(channels[hawksound], gLoc, vel);
  5822 							OPENAL_SetVolume(channels[hawksound], 128);
  5823 							OPENAL_SetPaused(channels[hawksound], false);
  5824 
  5825 							hawkcalldelay=16+abs(Random()%8);
  5826 						}
  5827 						static float temptexdetail;
  5828 
  5829 
  5830 						if(IsKeyDown(theKeyMap, MAC_H_KEY)&&debugmode){
  5831 							player[0].damagetolerance=200000;
  5832 							player[0].damage=0;
  5833 							player[0].burnt=0;
  5834 							player[0].permanentdamage=0;
  5835 							player[0].superpermanentdamage=0;
  5836 							/*
  5837 							int whichchar;
  5838 							whichchar = abs(Random()%7);
  5839 							registrationname[whichchar]+=1;
  5840 							*/
  5841 						}
  5842 
  5843 						if(IsKeyDown(theKeyMap, MAC_J_KEY)&&!envtogglekeydown&&debugmode){
  5844 							environment++;
  5845 							if(environment>2)environment=0;
  5846 							Setenvironment(environment);
  5847 
  5848 							envtogglekeydown=1;
  5849 						}
  5850 
  5851 
  5852 						if(!IsKeyDown(theKeyMap, MAC_J_KEY)){
  5853 							envtogglekeydown=0;
  5854 						}
  5855 
  5856 						if(IsKeyDown(theKeyMap, MAC_C_KEY)&&!cameratogglekeydown&&debugmode){
  5857 							cameramode=1-cameramode;
  5858 							cameratogglekeydown=1;
  5859 						}
  5860 
  5861 						if(!IsKeyDown(theKeyMap, MAC_C_KEY)){
  5862 							cameratogglekeydown=0;
  5863 						}
  5864 
  5865 						if(IsKeyDown(theKeyMap, MAC_X_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!detailtogglekeydown&&debugmode){
  5866 							if(player[0].num_weapons>0){
  5867 								if(weapons.type[player[0].weaponids[0]]==sword)weapons.type[player[0].weaponids[0]]=staff;
  5868 								else if(weapons.type[player[0].weaponids[0]]==staff)weapons.type[player[0].weaponids[0]]=knife;
  5869 								else weapons.type[player[0].weaponids[0]]=sword;
  5870 								if(weapons.type[player[0].weaponids[0]]==sword){
  5871 									weapons.mass[player[0].weaponids[0]]=1.5;
  5872 									weapons.tipmass[player[0].weaponids[0]]=1;
  5873 									weapons.length[player[0].weaponids[0]]=.8;
  5874 								}
  5875 								if(weapons.type[player[0].weaponids[0]]==staff){
  5876 									weapons.mass[player[0].weaponids[0]]=2;
  5877 									weapons.tipmass[player[0].weaponids[0]]=1;
  5878 									weapons.length[player[0].weaponids[0]]=1.5;
  5879 								}
  5880 
  5881 								if(weapons.type[player[0].weaponids[0]]==knife){
  5882 									weapons.mass[player[0].weaponids[0]]=1;
  5883 									weapons.tipmass[player[0].weaponids[0]]=1.2;
  5884 									weapons.length[player[0].weaponids[0]]=.25;
  5885 								}
  5886 							}
  5887 
  5888 							/*for(i=0;i<objects.numobjects;i++){
  5889 							if(objects.type[i]==treeleavestype){
  5890 							for(j=0;j<objects.numobjects;j++){
  5891 							if(objects.type[j]==treetrunktype)
  5892 							if(findDistancefast(&objects.position[i],&objects.position[j])<.5)
  5893 							objects.scale[i]=objects.scale[j];
  5894 							}
  5895 							}
  5896 							}*/
  5897 							detailtogglekeydown=1;
  5898 						}
  5899 
  5900 						if(IsKeyDown(theKeyMap, MAC_X_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!detailtogglekeydown&&debugmode){
  5901 							int closest=-1;
  5902 							float closestdist=-1;
  5903 							float distance;
  5904 							if(numplayers>1)
  5905 								for(i=1;i<numplayers;i++){
  5906 									distance=findDistancefast(&player[i].coords,&player[0].coords);
  5907 									if(closestdist==-1||distance<closestdist){
  5908 										closestdist=distance;
  5909 										closest=i;
  5910 									}
  5911 								}
  5912 								if(closest!=-1){
  5913 									if(player[closest].num_weapons)
  5914 									{
  5915 										if(weapons.type[player[closest].weaponids[0]]==sword)weapons.type[player[closest].weaponids[0]]=staff;
  5916 										else if(weapons.type[player[closest].weaponids[0]]==staff)weapons.type[player[closest].weaponids[0]]=knife;
  5917 										else weapons.type[player[closest].weaponids[0]]=sword;
  5918 										if(weapons.type[player[closest].weaponids[0]]==sword){
  5919 											weapons.mass[player[closest].weaponids[0]]=1.5;
  5920 											weapons.tipmass[player[closest].weaponids[0]]=1;
  5921 											weapons.length[player[closest].weaponids[0]]=.8;
  5922 										}
  5923 										if(weapons.type[player[0].weaponids[0]]==staff){
  5924 											weapons.mass[player[0].weaponids[0]]=2;
  5925 											weapons.tipmass[player[0].weaponids[0]]=1;
  5926 											weapons.length[player[0].weaponids[0]]=1.5;
  5927 										}
  5928 										if(weapons.type[player[closest].weaponids[0]]==knife){
  5929 											weapons.mass[player[closest].weaponids[0]]=1;
  5930 											weapons.tipmass[player[closest].weaponids[0]]=1.2;
  5931 											weapons.length[player[closest].weaponids[0]]=.25;
  5932 										}
  5933 									}
  5934 									if(!player[closest].num_weapons)
  5935 									{
  5936 										player[closest].weaponids[0]=weapons.numweapons;
  5937 										weapons.owner[weapons.numweapons]=closest;
  5938 										weapons.type[weapons.numweapons]=knife;
  5939 										weapons.damage[weapons.numweapons]=0;
  5940 										weapons.numweapons++;
  5941 										player[closest].num_weapons=1;
  5942 										if(weapons.type[player[closest].weaponids[0]]==sword){
  5943 											weapons.mass[player[closest].weaponids[0]]=1.5;
  5944 											weapons.tipmass[player[closest].weaponids[0]]=1;
  5945 											weapons.length[player[closest].weaponids[0]]=.8;
  5946 										}
  5947 										if(weapons.type[player[closest].weaponids[0]]==knife){
  5948 											weapons.mass[player[closest].weaponids[0]]=1;
  5949 											weapons.tipmass[player[closest].weaponids[0]]=1.2;
  5950 											weapons.length[player[closest].weaponids[0]]=.25;
  5951 										}
  5952 									}
  5953 								}
  5954 								detailtogglekeydown=1;
  5955 						}
  5956 
  5957 						if(IsKeyDown(theKeyMap, MAC_U_KEY)&&debugmode){
  5958 							int closest=-1;
  5959 							float closestdist=-1;
  5960 							float distance;
  5961 							if(numplayers>1)
  5962 								for(i=1;i<numplayers;i++){
  5963 									distance=findDistancefast(&player[i].coords,&player[0].coords);
  5964 									if(closestdist==-1||distance<closestdist){
  5965 										closestdist=distance;
  5966 										closest=i;
  5967 									}
  5968 								}
  5969 
  5970 								player[closest].rotation+=multiplier*50;
  5971 								player[closest].targetrotation=player[closest].rotation;
  5972 						}
  5973 
  5974 
  5975 						if(IsKeyDown(theKeyMap, MAC_O_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
  5976 							int closest=-1;
  5977 							float closestdist=-1;
  5978 							float distance;
  5979 							if(numplayers>1)
  5980 								for(i=1;i<numplayers;i++){
  5981 									distance=findDistancefast(&player[i].coords,&player[0].coords);
  5982 									if(closestdist==-1||distance<closestdist){
  5983 										closestdist=distance;
  5984 										closest=i;
  5985 									}
  5986 								}
  5987 								if(IsKeyDown(theKeyMap, MAC_CONTROL_KEY))closest=0;
  5988 
  5989 								if(closest!=-1){
  5990 									player[closest].whichskin++;
  5991 									if(player[closest].whichskin>9)player[closest].whichskin=0;
  5992 									if(player[closest].whichskin>2&&player[closest].creature==wolftype)player[closest].whichskin=0;
  5993 
  5994 									LoadTextureSave(creatureskin[player[closest].creature][player[closest].whichskin],
  5995 											&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  5996 								}
  5997 
  5998 								if(player[closest].numclothes){
  5999 									for(i=0;i<player[closest].numclothes;i++){
  6000 										tintr=player[closest].clothestintr[i];
  6001 										tintg=player[closest].clothestintg[i];
  6002 										tintb=player[closest].clothestintb[i];
  6003 										AddClothes((char *)player[closest].clothes[i],0,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  6004 									}
  6005 									player[closest].DoMipmaps(5,0,0,player[closest].skeleton.skinsize,player[closest].skeleton.skinsize);
  6006 								}
  6007 
  6008 								detailtogglekeydown=1;
  6009 						}
  6010 
  6011 						if(IsKeyDown(theKeyMap, MAC_O_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
  6012 							int closest=-1;
  6013 							float closestdist=-1;
  6014 							float distance;
  6015 							if(numplayers>1)
  6016 								for(i=1;i<numplayers;i++){
  6017 									distance=findDistancefast(&player[i].coords,&player[0].coords);
  6018 									if(closestdist==-1||distance<closestdist){
  6019 										closestdist=distance;
  6020 										closest=i;
  6021 									}
  6022 								}
  6023 								if(closest!=-1){
  6024 									if(player[closest].creature==wolftype){
  6025 										headprop=player[closest].proportionhead.x/1.1;
  6026 										bodyprop=player[closest].proportionbody.x/1.1;
  6027 										armprop=player[closest].proportionarms.x/1.1;
  6028 										legprop=player[closest].proportionlegs.x/1.1;
  6029 									}
  6030 
  6031 									if(player[closest].creature==rabbittype){
  6032 										headprop=player[closest].proportionhead.x/1.2;
  6033 										bodyprop=player[closest].proportionbody.x/1.05;
  6034 										armprop=player[closest].proportionarms.x/1.00;
  6035 										legprop=player[closest].proportionlegs.x/1.1;
  6036 									}
  6037 
  6038 
  6039 									if(player[closest].creature==rabbittype){
  6040 										player[closest].skeleton.id=closest;
  6041 										player[closest].skeleton.Load((char *)":Data:Skeleton:Basic Figure Wolf",(char *)":Data:Skeleton:Basic Figure Wolf Low",(char *)":Data:Skeleton:Rabbitbelt",(char *)":Data:Models:Wolf.solid",(char *)":Data:Models:Wolf2.solid",(char *)":Data:Models:Wolf3.solid",(char *)":Data:Models:Wolf4.solid",(char *)":Data:Models:Wolf5.solid",(char *)":Data:Models:Wolf6.solid",(char *)":Data:Models:Wolf7.solid",(char *)":Data:Models:Wolflow.solid",(char *)":Data:Models:Belt.solid",0);
  6042 										LoadTextureSave(":Data:Textures:Wolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[closest],&player[closest].skeleton.skinsize);
  6043 										player[closest].whichskin=0;
  6044 										player[closest].creature=wolftype;
  6045 
  6046 										player[closest].proportionhead=1.1;
  6047 										player[closest].proportionbody=1.1;
  6048 										player[closest].proportionarms=1.1;
  6049 										player[closest].proportionlegs=1.1;
  6050 										player[closest].proportionlegs.y=1.1;
  6051 										player[closest].scale=.23*5*player[0].scale;
  6052 
  6053 										player[closest].damagetolerance=300;
  6054 									}
  6055 									else
  6056 									{
  6057 										player[closest].skeleton.id=closest;
  6058 										player[closest].skeleton.Load((char *)":Data:Skeleton:Basic Figure",(char *)":Data:Skeleton:Basic Figurelow",(char *)":Data:Skeleton:Rabbitbelt",(char *)":Data:Models:Body.solid",(char *)":Data:Models:Body2.solid",(char *)":Data:Models:Body3.solid",(char *)":Data:Models:Body4.solid",(char *)":Data:Models:Body5.solid",(char *)":Data:Models:Body6.solid",(char *)":Data:Models:Body7.solid",(char *)":Data:Models:Bodylow.solid",(char *)":Data:Models:Belt.solid",1);
  6059 										LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  6060 										player[closest].whichskin=0;
  6061 										player[closest].creature=rabbittype;
  6062 
  6063 										player[closest].proportionhead=1.2;
  6064 										player[closest].proportionbody=1.05;
  6065 										player[closest].proportionarms=1.00;
  6066 										player[closest].proportionlegs=1.1;
  6067 										player[closest].proportionlegs.y=1.05;
  6068 										player[closest].scale=.2*5*player[0].scale;
  6069 
  6070 										player[closest].damagetolerance=200;
  6071 									}
  6072 
  6073 									if(player[closest].creature==wolftype){
  6074 										player[closest].proportionhead=1.1*headprop;
  6075 										player[closest].proportionbody=1.1*bodyprop;
  6076 										player[closest].proportionarms=1.1*armprop;
  6077 										player[closest].proportionlegs=1.1*legprop;
  6078 									}
  6079 
  6080 									if(player[closest].creature==rabbittype){
  6081 										player[closest].proportionhead=1.2*headprop;
  6082 										player[closest].proportionbody=1.05*bodyprop;
  6083 										player[closest].proportionarms=1.00*armprop;
  6084 										player[closest].proportionlegs=1.1*legprop;
  6085 										player[closest].proportionlegs.y=1.05*legprop;
  6086 									}
  6087 
  6088 								}
  6089 								detailtogglekeydown=1;
  6090 						}
  6091 
  6092 						if(!IsKeyDown(theKeyMap, MAC_X_KEY)){
  6093 							detailtogglekeydown=0;
  6094 						}
  6095 
  6096 						if(IsKeyDown(theKeyMap, MAC_B_KEY)&&!slomotogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
  6097 							slomo=1-slomo;
  6098 							slomodelay=1000;
  6099 							slomotogglekeydown=1;
  6100 						}
  6101 
  6102 
  6103 						if(((IsKeyDown(theKeyMap, MAC_I_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY))/*||buttons[1]*/)&&!explodetogglekeydown&&debugmode){
  6104 							int closest=-1;
  6105 							float closestdist=-1;
  6106 							float distance;
  6107 							XYZ flatfacing2,flatvelocity2;
  6108 							XYZ blah;
  6109 							if(numplayers>1)
  6110 								for(i=1;i<numplayers;i++){
  6111 									distance=findDistancefast(&player[i].coords,&player[0].coords);
  6112 									if(distance<144&&!player[i].headless)
  6113 										if(closestdist==-1||distance<closestdist){
  6114 											closestdist=distance;
  6115 											closest=i;
  6116 											blah = player[i].coords;
  6117 										}
  6118 								}
  6119 
  6120 								if(closest!=-1){
  6121 									XYZ headspurtdirection;
  6122 									int i = player[closest].skeleton.jointlabels[head];
  6123 									for(k=0;k<player[closest].skeleton.num_joints; k++){
  6124 										if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
  6125 										if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
  6126 										if(!player[closest].skeleton.free)flatfacing2=DoRotation(DoRotation(DoRotation(player[closest].skeleton.joints[i].position,0,0,player[closest].tilt),player[closest].tilt2,0,0),0,player[closest].rotation,0)*player[closest].scale+player[closest].coords;
  6127 										if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
  6128 										flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
  6129 										flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
  6130 										flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
  6131 										headspurtdirection=player[closest].skeleton.joints[player[closest].skeleton.jointlabels[head]].position-player[closest].skeleton.joints[player[closest].skeleton.jointlabels[neck]].position;
  6132 										Normalise(&headspurtdirection);
  6133 										sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, .6, 1);
  6134 										flatvelocity2+=headspurtdirection*8;
  6135 										sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2/2, 1,1,1, .16, 1);
  6136 									}
  6137 									sprites.MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
  6138 
  6139 									float gLoc[3];
  6140 									float vel[3];
  6141 									gLoc[0]=blah.x;
  6142 									gLoc[1]=blah.y;
  6143 									gLoc[2]=blah.z;
  6144 									vel[0]=0;
  6145 									vel[1]=0;
  6146 									vel[2]=0;
  6147 									PlaySoundEx( splattersound, samp[splattersound], NULL, true);
  6148 									OPENAL_3D_SetAttributes(channels[splattersound], gLoc, vel);
  6149 									OPENAL_SetVolume(channels[splattersound], 256);
  6150 									OPENAL_SetPaused(channels[splattersound], false);
  6151 
  6152 									PlaySoundEx( breaksound2, samp[breaksound2], NULL, true);
  6153 									OPENAL_3D_SetAttributes(channels[breaksound2], gLoc, vel);
  6154 									OPENAL_SetVolume(channels[breaksound2], 100);
  6155 									OPENAL_SetPaused(channels[breaksound2], false);
  6156 
  6157 									if(player[closest].skeleton.free==2)player[closest].skeleton.free=0;
  6158 									player[closest].RagDoll(0);
  6159 									player[closest].dead=2;
  6160 									player[closest].headless=1;
  6161 									player[closest].DoBloodBig(3,165);
  6162 
  6163 									camerashake+=.3;
  6164 								}
  6165 
  6166 								explodetogglekeydown=1;
  6167 						}
  6168 
  6169 						if(((IsKeyDown(theKeyMap, MAC_I_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY))/*||buttons[2]*/)&&!explodetogglekeydown&&debugmode){
  6170 							int closest=-1;
  6171 							float closestdist=-1;
  6172 							float distance;
  6173 							XYZ flatfacing2,flatvelocity2;
  6174 							XYZ blah;
  6175 							if(numplayers>1)
  6176 								for(i=1;i<numplayers;i++){
  6177 									distance=findDistancefast(&player[i].coords,&player[0].coords);
  6178 									if(distance<144)
  6179 										if(closestdist==-1||distance<closestdist){
  6180 											closestdist=distance;
  6181 											closest=i;
  6182 											blah=player[i].coords;
  6183 										}
  6184 								}
  6185 
  6186 								if(closest!=-1){
  6187 									float gLoc[3];
  6188 									float vel[3];
  6189 									gLoc[0]=blah.x;
  6190 									gLoc[1]=blah.y;
  6191 									gLoc[2]=blah.z;
  6192 									vel[0]=0;
  6193 									vel[1]=0;
  6194 									vel[2]=0;
  6195 
  6196 									PlaySoundEx( splattersound, samp[splattersound], NULL, true);
  6197 									OPENAL_3D_SetAttributes(channels[splattersound], gLoc, vel);
  6198 									OPENAL_SetVolume(channels[splattersound], 256);
  6199 									OPENAL_SetPaused(channels[splattersound], false);
  6200 
  6201 									PlaySoundEx( breaksound2, samp[breaksound2], NULL, true);
  6202 									OPENAL_3D_SetAttributes(channels[breaksound2], gLoc, vel);
  6203 									OPENAL_SetVolume(channels[breaksound2], 600);
  6204 									OPENAL_SetPaused(channels[breaksound2], false);
  6205 
  6206 									for(i=0;i<player[closest].skeleton.num_joints; i++){
  6207 										if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
  6208 										if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
  6209 										if(!player[closest].skeleton.free)flatfacing2=DoRotation(DoRotation(DoRotation(player[closest].skeleton.joints[i].position,0,0,player[closest].tilt),player[closest].tilt2,0,0),0,player[closest].rotation,0)*player[closest].scale+player[closest].coords;
  6210 										if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
  6211 										flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
  6212 										flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
  6213 										flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
  6214 										sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
  6215 										sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .3, 1);
  6216 										sprites.MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
  6217 									}
  6218 
  6219 									for(i=0;i<player[closest].skeleton.num_joints; i++){
  6220 										if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
  6221 										if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
  6222 										if(!player[closest].skeleton.free)flatfacing2=DoRotation(DoRotation(DoRotation(player[closest].skeleton.joints[i].position,0,0,player[closest].tilt),player[closest].tilt2,0,0),0,player[closest].rotation,0)*player[closest].scale+player[closest].coords;
  6223 										if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
  6224 										flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
  6225 										flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
  6226 										flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
  6227 										sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
  6228 										sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
  6229 									}
  6230 
  6231 									for(i=0;i<player[closest].skeleton.num_joints; i++){
  6232 										if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
  6233 										if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
  6234 										if(!player[closest].skeleton.free)flatfacing2=DoRotation(DoRotation(DoRotation(player[closest].skeleton.joints[i].position,0,0,player[closest].tilt),player[closest].tilt2,0,0),0,player[closest].rotation,0)*player[closest].scale+player[closest].coords;
  6235 										if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
  6236 										flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
  6237 										flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
  6238 										flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
  6239 										sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
  6240 										sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
  6241 									}
  6242 
  6243 									for(i=0;i<player[closest].skeleton.num_joints; i++){
  6244 										if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
  6245 										if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
  6246 										if(!player[closest].skeleton.free)flatfacing2=DoRotation(DoRotation(DoRotation(player[closest].skeleton.joints[i].position,0,0,player[closest].tilt),player[closest].tilt2,0,0),0,player[closest].rotation,0)*player[closest].scale+player[closest].coords;
  6247 										if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
  6248 										flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
  6249 										flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
  6250 										flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
  6251 										sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
  6252 										sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
  6253 									}
  6254 
  6255 									XYZ temppos;
  6256 									for(j=0;j<numplayers; j++){
  6257 										if(j!=closest){
  6258 											if(findDistancefast(&player[j].coords,&player[closest].coords)<25){
  6259 												player[j].DoDamage((25-findDistancefast(&player[j].coords,&player[closest].coords))*60);
  6260 												if(player[j].skeleton.free==2)player[j].skeleton.free=1;
  6261 												player[j].skeleton.longdead=0;
  6262 												player[j].RagDoll(0);
  6263 												for(i=0;i<player[j].skeleton.num_joints; i++){
  6264 													temppos=player[j].skeleton.joints[i].position+player[j].coords;
  6265 													if(findDistancefast(&temppos,&player[closest].coords)<25){
  6266 														flatvelocity2=temppos-player[closest].coords;
  6267 														Normalise(&flatvelocity2);
  6268 														player[j].skeleton.joints[i].velocity+=flatvelocity2*((20-findDistancefast(&temppos,&player[closest].coords))*20);
  6269 													}
  6270 												}
  6271 											}
  6272 										}
  6273 									}
  6274 
  6275 									player[closest].DoDamage(10000);
  6276 									player[closest].RagDoll(0);
  6277 									player[closest].dead=2;
  6278 									player[closest].coords=20;
  6279 									player[closest].skeleton.free=2;
  6280 
  6281 									camerashake+=.6;
  6282 
  6283 								}
  6284 
  6285 								explodetogglekeydown=1;
  6286 						}
  6287 
  6288 						if(!IsKeyDown(theKeyMap, MAC_I_KEY)){
  6289 							explodetogglekeydown=0;
  6290 						}
  6291 
  6292 						/*
  6293 						if(IsKeyDown(theKeyMap, MAC_S_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)&&!slomotogglekeydown){
  6294 						FILE			*tfile;
  6295 						//tfile=fopen( ":Data:Maps:mapsave", "wb" );
  6296 						if(whichlevel==0)tfile=fopen( ":Data:Maps:map1", "wb" );
  6297 						else if(whichlevel==1)tfile=fopen( ":Data:Maps:map2", "wb" );
  6298 						else if(whichlevel==2)tfile=fopen( ":Data:Maps:map3", "wb" );
  6299 						else if(whichlevel==3)tfile=fopen( ":Data:Maps:map4", "wb" );
  6300 						else if(whichlevel==4)tfile=fopen( ":Data:Maps:map5", "wb" );
  6301 						else tfile=fopen( ":Data:Maps:mapsave", "wb" );
  6302 
  6303 						fwrite( &player[0].coords, 1, sizeof(XYZ), tfile );
  6304 						fwrite( &player[0].rotation, 1, sizeof(float), tfile );
  6305 						fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
  6306 						fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
  6307 						for(j=0;j<player[0].num_weapons;j++){
  6308 						fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
  6309 						}
  6310 						fwrite( &environment, 1, sizeof(int), tfile );
  6311 
  6312 						fwrite( &objects.numobjects, 1, sizeof(int), tfile );
  6313 						fwrite( &objects.type, 1, sizeof(int)*objects.numobjects, tfile );
  6314 						fwrite( &objects.rotation, 1, sizeof(float)*objects.numobjects, tfile );
  6315 						fwrite( &objects.position, 1, sizeof(XYZ)*objects.numobjects, tfile );
  6316 						fwrite( &objects.scale, 1, sizeof(float)*objects.numobjects, tfile );
  6317 
  6318 						fwrite( &numplayers, 1, sizeof(int), tfile );
  6319 						if(numplayers>1&&numplayers<maxplayers)
  6320 						for(i=1;i<numplayers;i++){
  6321 						fwrite( &player[i].coords, 1, sizeof(XYZ), tfile );
  6322 						fwrite( &player[i].num_weapons, 1, sizeof(int), tfile );
  6323 						for(j=0;j<player[i].num_weapons;j++){
  6324 						fwrite( &weapons.type[player[i].weaponids[j]], 1, sizeof(int), tfile );
  6325 						}
  6326 						if(player[i].numwaypoints<30){
  6327 						fwrite( &player[i].numwaypoints, 1, sizeof(int), tfile );
  6328 						fwrite( &player[i].waypoints, 1, sizeof(XYZ)*player[i].numwaypoints, tfile );
  6329 						fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
  6330 						//fwrite( &player[i].jumppath, 1, sizeof(bool), tfile );
  6331 						}
  6332 						else{
  6333 						player[i].numwaypoints=0;
  6334 						player[i].waypoint=0;
  6335 						fwrite( &player[i].numwaypoints, 1, sizeof(int), tfile );
  6336 						fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
  6337 						fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
  6338 						}
  6339 						}
  6340 
  6341 						fclose(tfile);
  6342 
  6343 						slomotogglekeydown=1;
  6344 						}*/
  6345 
  6346 						if(!IsKeyDown(theKeyMap, MAC_B_KEY)&&!IsKeyDown(theKeyMap, MAC_F_KEY)&&!IsKeyDown(theKeyMap, MAC_K_KEY)&&!IsKeyDown(theKeyMap, MAC_S_KEY)){
  6347 							slomotogglekeydown=0;
  6348 						}
  6349 
  6350 
  6351 						if(IsKeyDown(theKeyMap, MAC_F_KEY)&&!slomotogglekeydown&&debugmode){
  6352 							player[0].onfire=1-player[0].onfire;
  6353 							if(player[0].onfire){
  6354 								player[0].CatchFire();
  6355 							}
  6356 							if(!player[0].onfire){
  6357 								float gLoc[3];
  6358 								float vel[3];
  6359 								gLoc[0]=player[0].coords.x;
  6360 								gLoc[1]=player[0].coords.y;
  6361 								gLoc[2]=player[0].coords.z;
  6362 								vel[0]=0;
  6363 								vel[1]=0;
  6364 								vel[2]=0;
  6365 								PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
  6366 								OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  6367 								OPENAL_SetVolume(channels[fireendsound], 256);
  6368 								OPENAL_SetPaused(channels[fireendsound], false);
  6369 								OPENAL_SetPaused(channels[stream_firesound], true);
  6370 							}
  6371 							slomotogglekeydown=1;
  6372 						}
  6373 						/*
  6374 						if(IsKeyDown(theKeyMap, MAC_L_KEY)){
  6375 						if(player[0].bleeding<=0)
  6376 						player[0].DoBlood(1,255);
  6377 						}*/
  6378 
  6379 
  6380 						if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)){
  6381 							int closest=-1;
  6382 							float closestdist=-1;
  6383 							float distance;
  6384 							if(numplayers>1)
  6385 								for(i=1;i<numplayers;i++){
  6386 									distance=findDistancefast(&player[i].coords,&player[0].coords);
  6387 									if(closestdist==-1||distance<closestdist){
  6388 										closestdist=distance;
  6389 										closest=i;
  6390 									}
  6391 								}
  6392 								if(closestdist>0&&closest>=0){
  6393 									//player[closest]=player[numplayers-1];
  6394 									//player[closest].skeleton=player[numplayers-1].skeleton;
  6395 									numplayers--;
  6396 								}
  6397 								drawmodetogglekeydown=1;
  6398 						}
  6399 
  6400 						if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
  6401 							int closest=-1;
  6402 							float closestdist=-1;
  6403 							float distance;
  6404 							if(max_objects>1)
  6405 								for(i=1;i<max_objects;i++){
  6406 									distance=findDistancefast(&objects.position[i],&player[0].coords);
  6407 									if(closestdist==-1||distance<closestdist){
  6408 										closestdist=distance;
  6409 										closest=i;
  6410 									}
  6411 								}
  6412 								if(closestdist>0&&closest>=0){
  6413 									objects.position[closest].y-=500;
  6414 								}
  6415 								drawmodetogglekeydown=1;
  6416 						}
  6417 
  6418 						if(IsKeyDown(theKeyMap, MAC_M_KEY)&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&editorenabled&&debugmode){
  6419 							//drawmode++;
  6420 							//if(drawmode>2)drawmode=0;
  6421 							if(objects.numobjects<max_objects-1){
  6422 								XYZ boxcoords;
  6423 								boxcoords.x=player[0].coords.x;
  6424 								boxcoords.z=player[0].coords.z;
  6425 								boxcoords.y=player[0].coords.y-3;
  6426 								if(editortype==bushtype)boxcoords.y=player[0].coords.y-.5;
  6427 								if(editortype==firetype)boxcoords.y=player[0].coords.y-.5;
  6428 								//objects.MakeObject(abs(Random()%3),boxcoords,Random()%360);
  6429 								float temprotat,temprotat2;
  6430 								temprotat=editorrotation;
  6431 								temprotat2=editorrotation2;
  6432 								if(temprotat<0||editortype==bushtype)temprotat=Random()%360;
  6433 								if(temprotat2<0)temprotat2=Random()%360;
  6434 
  6435 								objects.MakeObject(editortype,boxcoords,(int)temprotat-((int)temprotat)%30,(int)temprotat2,editorsize);
  6436 								if(editortype==treetrunktype)
  6437 									objects.MakeObject(treeleavestype,boxcoords,Random()%360*(temprotat2<2)+(int)editorrotation-((int)editorrotation)%30,editorrotation2,editorsize);
  6438 							}
  6439 
  6440 							drawmodetogglekeydown=1;
  6441 						}
  6442 
  6443 						if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&editorenabled){
  6444 							if(numplayers<maxplayers-1){
  6445 								player[numplayers].scale=.2*5*player[0].scale;
  6446 								player[numplayers].creature=rabbittype;
  6447 								player[numplayers].howactive=editoractive;
  6448 								player[numplayers].skeleton.id=numplayers;
  6449 								player[numplayers].skeleton.Load((char *)":Data:Skeleton:Basic Figure",(char *)":Data:Skeleton:Basic Figurelow",(char *)":Data:Skeleton:Rabbitbelt",(char *)":Data:Models:Body.solid",(char *)":Data:Models:Body2.solid",(char *)":Data:Models:Body3.solid",(char *)":Data:Models:Body4.solid",(char *)":Data:Models:Body5.solid",(char *)":Data:Models:Body6.solid",(char *)":Data:Models:Body7.solid",(char *)":Data:Models:Bodylow.solid",(char *)":Data:Models:Belt.solid",1);
  6450 
  6451 								//texsize=512*512*3/texdetail/texdetail;
  6452 								//if(!player[numplayers].loaded)player[numplayers].skeleton.skinText = new GLubyte[texsize];
  6453 								//player[numplayers].skeleton.skinText.resize(texsize);
  6454 
  6455 								k=abs(Random()%2)+1;
  6456 								if(k==0){
  6457 									LoadTextureSave(":Data:Textures:Fur3.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
  6458 									player[numplayers].whichskin=0;
  6459 								}
  6460 								else if(k==1){
  6461 									LoadTextureSave(":Data:Textures:Fur.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
  6462 									player[numplayers].whichskin=1;
  6463 								}
  6464 								else {
  6465 									LoadTextureSave(":Data:Textures:Fur2.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
  6466 									player[numplayers].whichskin=2;
  6467 								}
  6468 
  6469 								LoadTexture(":Data:Textures:Belt.png",&player[numplayers].skeleton.