Advertisement
Guest User

Untitled

a guest
May 24th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 470.34 KB | None | 0 0
  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.  
  33. using namespace std;
  34.  
  35. extern float multiplier;
  36. extern XYZ viewer;
  37. extern int environment;
  38. extern float texscale;
  39. extern Terrain terrain;
  40. extern FSOUND_SAMPLE    *samp[100];
  41. extern int channels[100];
  42. extern Sprites sprites;
  43. extern int kTextureSize;
  44. extern float screenwidth,screenheight;
  45. extern float gravity;
  46. extern int detail;
  47. extern float texdetail;
  48. extern Objects objects;
  49. extern int slomo;
  50. extern float slomodelay;
  51. extern bool floatjump;
  52. extern float volume;
  53. extern Animation animation[animation_count];
  54. extern Light light;
  55. extern float texdetail;
  56. extern GLubyte bloodText[512*512*3];
  57. extern GLubyte wolfbloodText[512*512*3];
  58. extern float terraindetail;
  59. extern float camerashake;
  60. extern float woozy;
  61. extern float blackout;
  62. extern bool cellophane;
  63. extern bool musictoggle;
  64. extern int difficulty;
  65. extern Weapons weapons;
  66. extern Person player[maxplayers];
  67. extern int numplayers;
  68. extern int bloodtoggle;
  69. extern bool invertmouse;
  70. extern float windvar;
  71. extern float precipdelay;
  72. extern XYZ viewerfacing;
  73. extern bool ambientsound;
  74. extern bool mousejump;
  75. extern float viewdistance;
  76. extern bool freeze;
  77. extern bool autoslomo;
  78. extern int newnetmessages;
  79. extern char netmessages[256];
  80. extern bool keyboardfrozen;
  81. extern int netdatanew;
  82. extern bool loadingstuff;
  83. extern char mapname[256];
  84. extern XYZ windvector;
  85. extern bool buttons[3];
  86. extern bool debugmode;
  87. static int music1;
  88. extern int mainmenu;
  89. extern int oldmainmenu;
  90. extern bool visibleloading;
  91. extern int loadscreencolor;
  92. extern float flashamount,flashr,flashg,flashb;
  93. extern int flashdelay;
  94. extern XYZ envsound[30];
  95. extern float envsoundvol[30];
  96. extern int numenvsounds;
  97. extern float envsoundlife[30];
  98. extern float usermousesensitivity;
  99. extern bool ismotionblur;
  100. extern bool foliage;
  101. extern bool trilinear;
  102. extern bool damageeffects;
  103. extern bool showpoints;
  104. extern bool texttoggle;
  105. extern bool alwaysblur;
  106. extern float gamespeed;
  107. extern bool decals;
  108. extern bool vblsync;
  109. extern bool immediate;
  110. extern bool velocityblur;
  111. extern int bonus;
  112. extern int oldbonus;
  113. extern float bonusvalue;
  114. extern float bonustotal;
  115. extern float bonustime;
  116. extern float startbonustotal;
  117. extern float tintr,tintg,tintb;
  118. extern float bonusnum[100];
  119. extern bool skyboxtexture;
  120. extern float skyboxr;
  121. extern float skyboxg;
  122. extern float skyboxb;
  123. extern float skyboxlightr;
  124. extern float skyboxlightg;
  125. extern float skyboxlightb;
  126. extern float fadestart;
  127. extern float slomospeed;
  128. extern float slomofreq;
  129. extern int tutoriallevel;
  130. extern float smoketex;
  131. extern float tutorialstagetime;
  132. extern int tutorialstage;
  133. extern float tutorialmaxtime;
  134. extern float tutorialsuccess;
  135. extern bool againbonus;
  136. extern bool reversaltrain;
  137. extern bool canattack;
  138. extern bool cananger;
  139. extern float damagedealt;
  140. extern float damagetaken;
  141. extern int maptype;
  142. extern int editoractive;
  143. extern int editorpathtype;
  144. extern bool oldbuttons[3];
  145.  
  146. extern float hostiletime;
  147.  
  148. extern bool gamestarted;
  149.  
  150. extern int numhotspots;
  151. extern int winhotspot;
  152. extern int windialogue;
  153. extern int killhotspot;
  154. extern XYZ hotspot[40];
  155. extern int hotspottype[40];
  156. extern float hotspotsize[40];
  157. extern char hotspottext[40][256];
  158. extern int currenthotspot;
  159.  
  160. extern int kBitsPerPixel;
  161. extern int hostile;
  162.  
  163. extern int numaccounts;
  164. extern int accountactive;
  165. extern int accountdifficulty[10];
  166. extern int accountprogress[10];
  167. extern float accountpoints[10];
  168. extern float accounthighscore[10][50];
  169. extern float accountfasttime[10][50];
  170. extern bool accountunlocked[10][60];
  171. extern char accountname[10][256];
  172.  
  173. extern bool stillloading;
  174. extern bool winfreeze;
  175.  
  176. extern int numfalls;
  177. extern int numflipfail;
  178. extern int numseen;
  179. extern int numstaffattack;
  180. extern int numswordattack;
  181. extern int numknifeattack;
  182. extern int numunarmedattack;
  183. extern int numescaped;
  184. extern int numflipped;
  185. extern int numwallflipped;
  186. extern int numthrowkill;
  187. extern int numafterkill;
  188. extern int numreversals;
  189. extern int numattacks;
  190. extern int maxalarmed;
  191. extern int numresponded;
  192.  
  193. extern int numdialogues;
  194. extern int numdialogueboxes[max_dialogues];
  195. extern int dialoguetype[max_dialogues];
  196. extern int dialogueboxlocation[max_dialogues][max_dialoguelength];
  197. extern float dialogueboxcolor[max_dialogues][max_dialoguelength][3];
  198. extern int dialogueboxsound[max_dialogues][max_dialoguelength];
  199. extern char dialoguetext[max_dialogues][max_dialoguelength][128];
  200. extern char dialoguename[max_dialogues][max_dialoguelength][64];
  201. extern XYZ dialoguecamera[max_dialogues][max_dialoguelength];
  202. extern XYZ participantlocation[max_dialogues][10];
  203. extern int participantfocus[max_dialogues][max_dialoguelength];
  204. extern int participantaction[max_dialogues][max_dialoguelength];
  205. extern float participantrotation[max_dialogues][10];
  206. extern XYZ participantfacing[max_dialogues][max_dialoguelength][10];
  207. extern float dialoguecamerarotation[max_dialogues][max_dialoguelength];
  208. extern float dialoguecamerarotation2[max_dialogues][max_dialoguelength];
  209. extern int indialogue;
  210. extern int whichdialogue;
  211. extern int directing;
  212. extern float dialoguetime;
  213. extern int dialoguegonethrough[20];
  214.  
  215. extern bool campaign;
  216.  
  217. extern float oldgamespeed;
  218.  
  219. extern float accountcampaignhighscore[10];
  220. extern float accountcampaignfasttime[10];
  221. extern float accountcampaignscore[10];
  222. extern float accountcampaigntime[10];
  223.  
  224. extern int accountcampaignchoicesmade[10];
  225. extern int accountcampaignchoices[10][5000];
  226. /********************> Tick() <*****/
  227. extern FSOUND_STREAM * strm[20];
  228. extern "C"  void PlaySoundEx(int channel, FSOUND_SAMPLE *sptr, FSOUND_DSPUNIT *dsp, signed char startpaused);
  229. extern "C" void PlayStreamEx(int chan, FSOUND_STREAM *sptr, FSOUND_DSPUNIT *dsp, signed char startpaused);
  230.  
  231. extern void ScreenShot(const char * fname);
  232. void Screenshot (void)
  233. {
  234.     char temp[1024];
  235.     time_t  t = time(NULL);
  236.     struct  tm *tme = localtime(&t);
  237.     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);
  238.  
  239.     mkdir("Screenshots", S_IRWXU);
  240.     ScreenShot(temp/*"Screenshots\\Screenshot.png"*/);
  241.  
  242.     /*FSSpec                MAC_file;
  243.     GraphicsExportComponent     QT_exporter;
  244.     OSErr               MAC_error_code;
  245.     CGrafPtr            MAC_currentPort;
  246.     GDHandle            MAC_currentDevice;
  247.     unsigned char*      MAC_pixels;
  248.     Rect                MAC_picture_rectangle;
  249.     GWorldPtr           MAC_offscreen_graphics_port;
  250.  
  251.     static int numscreenshots=0;
  252.  
  253.     // Make an FSSpec
  254.     static char buf[256];
  255.     if(numscreenshots==0){
  256.     buf[0]=26;
  257.     buf[1]=':';
  258.     buf[2]='S';
  259.     buf[3]='c';
  260.     buf[4]='r';
  261.     buf[5]='e';
  262.     buf[6]='e';
  263.     buf[7]='n';
  264.     buf[8]='s';
  265.     buf[9]='h';
  266.     buf[10]='o';
  267.     buf[11]='t';
  268.     buf[12]='s';
  269.     buf[13]=':';
  270.     buf[14]='S';
  271.     buf[15]='c';
  272.     buf[16]='r';
  273.     buf[17]='e';
  274.     buf[18]='e';
  275.     buf[19]='n';
  276.     buf[20]='s';
  277.     buf[21]='h';
  278.     buf[22]='o';
  279.     buf[23]='t';
  280.     buf[24]='0';
  281.     buf[25]='0';
  282.     buf[26]='0';
  283.     }
  284.  
  285.     FInfo *fndrInfo;
  286.     FSMakeFSSpec(0, 0, (unsigned char*)buf, &MAC_file);
  287.     while(!FSpGetFInfo (&MAC_file, fndrInfo)){
  288.     FSMakeFSSpec(0, 0, (unsigned char*)buf, &MAC_file);
  289.     if(!FSpGetFInfo (&MAC_file, fndrInfo)){
  290.     numscreenshots++;
  291.     buf[26]++;
  292.     if(buf[26]==':'){
  293.     buf[26]='0';
  294.     buf[25]++;
  295.     if(buf[25]==':'){
  296.     buf[25]='0';
  297.     buf[24]++;
  298.     if(buf[24]==':'){
  299.     buf[24]='9';
  300.     buf[25]='9';
  301.     buf[26]='9';
  302.     }
  303.     }
  304.     }
  305.     }
  306.     }
  307.  
  308.  
  309.     // Get the GWorld
  310.     GWorldPtr           MAC_gWorld = (CGrafPtr) FrontWindow();
  311.     //assert(MAC_gWorld != NULL);
  312.  
  313.     // Allocate memory for loading image
  314.     MAC_pixels = new unsigned char[(int)(screenheight * screenwidth * 4)];
  315.     if (MAC_pixels == NULL) {
  316.     //UTIL_Error("Could not create Texture data.");
  317.     return;
  318.     }
  319.  
  320.     // Get GWorld
  321.     ::GetGWorld(&MAC_currentPort, &MAC_currentDevice); 
  322.  
  323.     // Make a picture Rectangle
  324.     MAC_picture_rectangle.left = 0;
  325.     MAC_picture_rectangle.right = screenwidth;
  326.     MAC_picture_rectangle.top = 0;
  327.     MAC_picture_rectangle.bottom = screenheight;   
  328.  
  329.     // Create new offscreen GWorld
  330.     MAC_error_code = ::QTNewGWorldFromPtr (&MAC_offscreen_graphics_port, k32ARGBPixelFormat, &MAC_picture_rectangle, NULL, NULL, 0, (char *) MAC_pixels, screenwidth * 4);
  331.     if (MAC_error_code) {
  332.     ::SetGWorld(MAC_currentPort, MAC_currentDevice);   
  333.     delete MAC_pixels;
  334.     //UTIL_Error("Could not create offscreen GWorld. ");
  335.     return;
  336.  
  337.     }
  338.  
  339.     // Copy OpenGL Context to new GWorld
  340.     glReadBuffer(GL_FRONT);
  341.     glReadPixels(0,0,screenwidth,screenheight,GL_RGBA,GL_UNSIGNED_BYTE,MAC_pixels);
  342.  
  343.     // Swizzle texture
  344.     for (unsigned long byte = 0; byte < screenheight * screenwidth * 4; byte+=4) {
  345.     unsigned char temp = MAC_pixels[byte+0];
  346.     MAC_pixels[byte+0] = MAC_pixels[byte+3];
  347.     MAC_pixels[byte+3] = MAC_pixels[byte+2];
  348.     MAC_pixels[byte+2] = MAC_pixels[byte+1];
  349.     MAC_pixels[byte+1] = temp;
  350.     }
  351.  
  352.     // Flip the image  :(   This could probably be optimized
  353.     int vert;
  354.     int src_index;
  355.     int dst_index;
  356.     unsigned char temp;
  357.     for (int horz = 0; horz < screenwidth; ++horz)
  358.     for (vert = 0; vert < screenheight / 2; ++vert) {      
  359.     src_index = (screenwidth * vert + horz) * 4;
  360.     dst_index = (screenwidth * (screenheight - vert - 1) + horz) * 4;
  361.  
  362.     temp=MAC_pixels[src_index+0];
  363.     MAC_pixels[src_index+0]=MAC_pixels[dst_index+0];
  364.     MAC_pixels[dst_index+0]=temp;
  365.  
  366.     temp=MAC_pixels[src_index+1];
  367.     MAC_pixels[src_index+1]=MAC_pixels[dst_index+1];
  368.     MAC_pixels[dst_index+1]=temp;
  369.  
  370.     temp=MAC_pixels[src_index+2];
  371.     MAC_pixels[src_index+2]=MAC_pixels[dst_index+2];
  372.     MAC_pixels[dst_index+2]=temp;
  373.  
  374.     temp=MAC_pixels[src_index+3];
  375.     MAC_pixels[src_index+3]=MAC_pixels[dst_index+3];
  376.     MAC_pixels[dst_index+3]=temp;
  377.     }
  378.  
  379.  
  380.  
  381.     // Export the Gworld
  382.     MAC_error_code =  OpenADefaultComponent(GraphicsExporterComponentType, kQTFileTypeBMP, &QT_exporter);
  383.     if (MAC_error_code) {
  384.     //UTIL_Warning("Unable to export screenshot.");
  385.     ::SetGWorld(MAC_currentPort, MAC_currentDevice);   
  386.     ::DisposeGWorld(MAC_offscreen_graphics_port);
  387.     delete MAC_pixels;
  388.     return;
  389.     }                                              
  390.  
  391.     MAC_error_code =  GraphicsExportSetInputGWorld(QT_exporter,MAC_offscreen_graphics_port);
  392.     if (MAC_error_code) {
  393.     ::CloseComponent(QT_exporter);
  394.     ::SetGWorld(MAC_currentPort, MAC_currentDevice);
  395.     ::DisposeGWorld(MAC_offscreen_graphics_port);
  396.     delete MAC_pixels;
  397.     //UTIL_Warning("Unable to export screenshot.");
  398.     return;
  399.     }                              
  400.  
  401.     MAC_error_code = GraphicsExportSetOutputFile(QT_exporter,&MAC_file);
  402.     if (MAC_error_code) {
  403.     ::CloseComponent(QT_exporter);
  404.     ::SetGWorld(MAC_currentPort, MAC_currentDevice);   
  405.     ::DisposeGWorld(MAC_offscreen_graphics_port);
  406.     delete MAC_pixels;
  407.     //UTIL_Warning("Unable to export screenshot.");
  408.     return;
  409.     }                          
  410.  
  411.     MAC_error_code = GraphicsExportDoExport(QT_exporter,NULL);
  412.     if (MAC_error_code) {
  413.     ::CloseComponent(QT_exporter);
  414.     ::SetGWorld(MAC_currentPort, MAC_currentDevice);           
  415.     ::DisposeGWorld(MAC_offscreen_graphics_port);
  416.     delete MAC_pixels;
  417.     //UTIL_Warning("Unable to export screenshot.");
  418.     return;
  419.     }                      
  420.  
  421.     ::CloseComponent(QT_exporter);
  422.     ::SetGWorld(MAC_currentPort, MAC_currentDevice);
  423.     ::DisposeGWorld(MAC_offscreen_graphics_port);
  424.  
  425.     delete MAC_pixels;*/
  426. }
  427.  
  428.  
  429.  
  430. void    Game::SetUpLighting(){
  431.     if(environment==snowyenvironment){
  432.         light.color[0]=.65;
  433.         light.color[1]=.65;
  434.         light.color[2]=.7;
  435.         light.ambient[0]=.4;
  436.         light.ambient[1]=.4;
  437.         light.ambient[2]=.44;      
  438.     }
  439.     if(environment==desertenvironment){
  440.         light.color[0]=.95;
  441.         light.color[1]=.95;
  442.         light.color[2]=.95;
  443.         light.ambient[0]=.4;
  444.         light.ambient[1]=.35;
  445.         light.ambient[2]=.3;       
  446.     }
  447.  
  448.     if(environment==grassyenvironment){
  449.         light.color[0]=.95;
  450.         light.color[1]=.95;
  451.         light.color[2]=1;
  452.         light.ambient[0]=.4;
  453.         light.ambient[1]=.4;
  454.         light.ambient[2]=.44;      
  455.     }
  456.     if(!skyboxtexture){
  457.         light.color[0]=1;
  458.         light.color[1]=1;
  459.         light.color[2]=1;
  460.         light.ambient[0]=.4;
  461.         light.ambient[1]=.4;
  462.         light.ambient[2]=.4;   
  463.     }
  464.     float average;
  465.     average=(skyboxlightr+skyboxlightg+skyboxlightb)/3;
  466.     light.color[0]*=(skyboxlightr+average)/2;
  467.     light.color[1]*=(skyboxlightg+average)/2;
  468.     light.color[2]*=(skyboxlightb+average)/2;
  469.     light.ambient[0]=light.ambient[0]*(skyboxlightr+average)/2*1;
  470.     light.ambient[1]=light.ambient[1]*(skyboxlightg+average)/2*1;
  471.     light.ambient[2]=light.ambient[2]*(skyboxlightb+average)/2*1;  
  472.     /*
  473.     light.ambient[0]=0;
  474.     light.ambient[1]=0;
  475.     light.ambient[2]=0; */
  476. }
  477.  
  478. int Game::findPathDist(int start,int end){
  479.     int i,j,k,smallestcount,count,connected;
  480.     int last,last2,last3,last4;
  481.     int closest;
  482.  
  483.     smallestcount=1000;
  484.     for(i=0;i<50;i++){
  485.         count=0;
  486.         last=start;
  487.         last2=-1;
  488.         last3=-1;
  489.         last4=-1;
  490.         while(last!=end&&count<30){
  491.             closest=-1;
  492.             for(j=0;j<numpathpoints;j++){
  493.                 if(j!=last&&j!=last2&&j!=last3&&j!=last4)
  494.                 {
  495.                     connected=0;
  496.                     if(numpathpointconnect[j])
  497.                         for(k=0;k<numpathpointconnect[j];k++){
  498.                             if(pathpointconnect[j][k]==last)connected=1;
  499.                         }
  500.                         if(!connected)
  501.                             if(numpathpointconnect[last])
  502.                                 for(k=0;k<numpathpointconnect[last];k++){
  503.                                     if(pathpointconnect[last][k]==j)connected=1;
  504.                                 }
  505.                                 if(connected)
  506.                                     if(closest==-1||Random()%2==0){
  507.                                         closest=j;
  508.                                     }
  509.                 }
  510.             }
  511.             last4=last3;
  512.             last3=last2;
  513.             last2=last;
  514.             last=closest;
  515.             count++;
  516.         }
  517.         if(count<smallestcount)smallestcount=count;
  518.     }
  519.     return smallestcount;
  520. }
  521.  
  522. int Game::checkcollide(XYZ startpoint,XYZ endpoint){
  523.     static XYZ colpoint,colviewer,coltarget;
  524.     static float minx,minz,maxx,maxz,miny,maxy;
  525.     static int i;
  526.  
  527.     //startpoint.y+=.7;
  528.     //endpoint.y+=.7;
  529.     //startpoint.y-=.1;
  530.     //endpoint.y-=.1;
  531.  
  532.     minx=startpoint.x;
  533.     if(minx>endpoint.x)minx=endpoint.x;
  534.     miny=startpoint.y;
  535.     if(miny>endpoint.y)miny=endpoint.y;
  536.     minz=startpoint.z;
  537.     if(minz>endpoint.z)minz=endpoint.z;
  538.  
  539.     maxx=startpoint.x;
  540.     if(maxx<endpoint.x)maxx=endpoint.x;
  541.     maxy=startpoint.y;
  542.     if(maxy<endpoint.y)maxy=endpoint.y;
  543.     maxz=startpoint.z;
  544.     if(maxz<endpoint.z)maxz=endpoint.z;
  545.  
  546.     minx-=1;
  547.     miny-=1;
  548.     minz-=1;
  549.     maxx+=1;
  550.     maxy+=1;
  551.     maxz+=1;
  552.  
  553.     for(i=0;i<objects.numobjects;i++){
  554.         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){
  555.             if(objects.type[i]!=treeleavestype&&objects.type[i]!=bushtype&&objects.type[i]!=firetype){
  556.                 colviewer=startpoint;
  557.                 coltarget=endpoint;
  558.                 if(objects.model[i].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[i],&objects.rotation[i])!=-1)return i; 
  559.             }
  560.         }
  561.     }
  562.  
  563.     //if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
  564.  
  565.     return -1;
  566. }
  567.  
  568. int Game::checkcollide(XYZ startpoint,XYZ endpoint,int what){
  569.     static XYZ colpoint,colviewer,coltarget;
  570.     static float minx,minz,maxx,maxz,miny,maxy;
  571.     static int i;
  572.  
  573.     //startpoint.y+=.7;
  574.     //endpoint.y+=.7;
  575.     //startpoint.y-=.1;
  576.     //endpoint.y-=.1;
  577.  
  578.     minx=startpoint.x;
  579.     if(minx>endpoint.x)minx=endpoint.x;
  580.     miny=startpoint.y;
  581.     if(miny>endpoint.y)miny=endpoint.y;
  582.     minz=startpoint.z;
  583.     if(minz>endpoint.z)minz=endpoint.z;
  584.  
  585.     maxx=startpoint.x;
  586.     if(maxx<endpoint.x)maxx=endpoint.x;
  587.     maxy=startpoint.y;
  588.     if(maxy<endpoint.y)maxy=endpoint.y;
  589.     maxz=startpoint.z;
  590.     if(maxz<endpoint.z)maxz=endpoint.z;
  591.  
  592.     minx-=1;
  593.     miny-=1;
  594.     minz-=1;
  595.     maxx+=1;
  596.     maxy+=1;
  597.     maxz+=1;
  598.  
  599.     if(what!=1000){
  600.         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){
  601.             if(objects.type[what]!=treeleavestype&&objects.type[what]!=bushtype&&objects.type[what]!=firetype){
  602.                 colviewer=startpoint;
  603.                 coltarget=endpoint;
  604.                 if(objects.model[what].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[what],&objects.rotation[what])!=-1)return i;
  605.             }
  606.         }
  607.     }
  608.  
  609.     if(what==1000)if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
  610.  
  611.     return -1;
  612. }
  613.  
  614. void    Game::Setenvironment(int which)
  615. {
  616.     LOGFUNC;
  617.  
  618.     LOG(" Setting environment...");
  619.  
  620.     float temptexdetail;
  621.     environment=which;
  622. /*
  623.     FSOUND_SetPaused(channels[music1snow], TRUE);
  624.     FSOUND_SetPaused(channels[music1grass], TRUE);
  625.     FSOUND_SetPaused(channels[music1desert], TRUE);
  626.     FSOUND_SetPaused(channels[wind], TRUE);
  627.     FSOUND_SetPaused(channels[desertambient], TRUE);
  628. */
  629.     FSOUND_SetPaused(channels[stream_music1snow], TRUE);
  630.     FSOUND_SetPaused(channels[stream_music1grass], TRUE);
  631.     FSOUND_SetPaused(channels[stream_music1desert], TRUE);
  632.     FSOUND_SetPaused(channels[stream_wind], TRUE);
  633.     FSOUND_SetPaused(channels[stream_desertambient], TRUE);
  634.  
  635.  
  636.     if(environment==snowyenvironment){
  637.         windvector=0;
  638.         windvector.z=3;
  639.         if(ambientsound){
  640.             //PlaySoundEx( wind, samp[wind], NULL, TRUE);
  641.             PlayStreamEx(stream_wind, strm[stream_wind], 0, TRUE);
  642.             FSOUND_SetPaused(channels[stream_wind], FALSE);
  643.             FSOUND_SetVolume(channels[stream_wind], 256);
  644.         }
  645.  
  646.         LoadTexture(":Data:Textures:snowtree.png",&objects.treetextureptr,0,1);
  647.         LoadTexture(":Data:Textures:bushsnow.png",&objects.bushtextureptr,0,1);
  648.         LoadTexture(":Data:Textures:bouldersnow.jpg",&objects.rocktextureptr,1,0);
  649.         LoadTexture(":Data:Textures:snowbox.jpg",&objects.boxtextureptr,1,0);
  650.  
  651.         FSOUND_Sample_Free(samp[footstepsound]);
  652.         FSOUND_Sample_Free(samp[footstepsound2]);
  653.         FSOUND_Sample_Free(samp[footstepsound3]);
  654.         FSOUND_Sample_Free(samp[footstepsound4]);
  655.         samp[footstepsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow1.ogg", FSOUND_HW3D, 0, 0);
  656.         samp[footstepsound2] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow2.ogg", FSOUND_HW3D, 0, 0);
  657.         samp[footstepsound3] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepstone1.ogg", FSOUND_HW3D, 0, 0);
  658.         samp[footstepsound4] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepstone2.ogg", FSOUND_HW3D, 0, 0);
  659.         FSOUND_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);   
  660.         FSOUND_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);  
  661.         FSOUND_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);  
  662.         FSOUND_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);  
  663.  
  664.         LoadTexture(":Data:Textures:snow.jpg",&terraintexture,1,0);
  665.  
  666.         LoadTexture(":Data:Textures:rock.jpg",&terraintexture2,1,0);
  667.  
  668.         //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
  669.  
  670.  
  671.  
  672.  
  673.         temptexdetail=texdetail;
  674.         if(texdetail>1)texdetail=4;
  675.         skybox.load(    ":Data:Textures:Skybox(snow):Front.jpg",
  676.             ":Data:Textures:Skybox(snow):Left.jpg",
  677.             ":Data:Textures:Skybox(snow):Back.jpg",
  678.             ":Data:Textures:Skybox(snow):Right.jpg",
  679.             ":Data:Textures:Skybox(snow):Up.jpg",
  680.             ":Data:Textures:Skybox(snow):Down.jpg",
  681.             ":Data:Textures:Skybox(snow):Cloud.jpg",
  682.             ":Data:Textures:Skybox(snow):Reflect.jpg");
  683.  
  684.  
  685.  
  686.  
  687.         texdetail=temptexdetail;
  688.     }
  689.     if(environment==desertenvironment){
  690.         windvector=0;
  691.         windvector.z=2;
  692.         LoadTexture(":Data:Textures:deserttree.png",&objects.treetextureptr,0,1);
  693.         LoadTexture(":Data:Textures:bushdesert.png",&objects.bushtextureptr,0,1);
  694.         LoadTexture(":Data:Textures:boulderdesert.jpg",&objects.rocktextureptr,1,0);
  695.         LoadTexture(":Data:Textures:desertbox.jpg",&objects.boxtextureptr,1,0);
  696.  
  697.  
  698.         if(ambientsound){
  699.             //PlaySoundEx( desertambient, samp[desertambient], NULL, TRUE);
  700.             PlayStreamEx( stream_desertambient, strm[stream_desertambient], NULL, TRUE);
  701.             FSOUND_SetPaused(channels[stream_desertambient], FALSE);
  702.             FSOUND_SetVolume(channels[stream_desertambient], 256);
  703.         }
  704.  
  705.         FSOUND_Sample_Free(samp[footstepsound]);
  706.         FSOUND_Sample_Free(samp[footstepsound2]);
  707.         FSOUND_Sample_Free(samp[footstepsound3]);
  708.         FSOUND_Sample_Free(samp[footstepsound4]);
  709.         samp[footstepsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow1.ogg", FSOUND_HW3D, 0, 0);
  710.         samp[footstepsound2] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow2.ogg", FSOUND_HW3D, 0, 0);
  711.         samp[footstepsound3] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow1.ogg", FSOUND_HW3D, 0, 0);
  712.         samp[footstepsound4] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow2.ogg", FSOUND_HW3D, 0, 0);
  713.         FSOUND_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);   
  714.         FSOUND_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);  
  715.         FSOUND_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);  
  716.         FSOUND_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);  
  717.  
  718.         LoadTexture(":Data:Textures:sand.jpg",&terraintexture,1,0);
  719.  
  720.         LoadTexture(":Data:Textures:sandslope.jpg",&terraintexture2,1,0);
  721.  
  722.         //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
  723.  
  724.  
  725.  
  726.         temptexdetail=texdetail;
  727.         if(texdetail>1)texdetail=4;
  728.         skybox.load(    ":Data:Textures:Skybox(sand):Front.jpg",
  729.             ":Data:Textures:Skybox(sand):Left.jpg",
  730.             ":Data:Textures:Skybox(sand):Back.jpg",
  731.             ":Data:Textures:Skybox(sand):Right.jpg",
  732.             ":Data:Textures:Skybox(sand):Up.jpg",
  733.             ":Data:Textures:Skybox(sand):Down.jpg",
  734.             ":Data:Textures:Skybox(sand):Cloud.jpg",
  735.             ":Data:Textures:Skybox(sand):Reflect.jpg");
  736.  
  737.  
  738.  
  739.  
  740.         texdetail=temptexdetail;
  741.     }
  742.     if(environment==grassyenvironment){
  743.         windvector=0;
  744.         windvector.z=2;
  745.         LoadTexture(":Data:Textures:tree.png",&objects.treetextureptr,0,1);
  746.         LoadTexture(":Data:Textures:bush.png",&objects.bushtextureptr,0,1);
  747.         LoadTexture(":Data:Textures:boulder.jpg",&objects.rocktextureptr,1,0);
  748.         LoadTexture(":Data:Textures:grassbox.jpg",&objects.boxtextureptr,1,0);
  749.  
  750.         if(ambientsound){
  751.             PlayStreamEx( stream_wind, strm[stream_wind], NULL, TRUE);
  752.             FSOUND_SetPaused(channels[stream_wind], FALSE);
  753.             FSOUND_SetVolume(channels[stream_wind], 100);
  754.         }
  755.  
  756.         FSOUND_Sample_Free(samp[footstepsound]);
  757.         FSOUND_Sample_Free(samp[footstepsound2]);
  758.         FSOUND_Sample_Free(samp[footstepsound3]);
  759.         FSOUND_Sample_Free(samp[footstepsound4]);
  760.         samp[footstepsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepgrass1.ogg", FSOUND_HW3D, 0, 0);
  761.         samp[footstepsound2] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepgrass2.ogg", FSOUND_HW3D, 0, 0);
  762.         samp[footstepsound3] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepstone1.ogg", FSOUND_HW3D, 0, 0);
  763.         samp[footstepsound4] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepstone2.ogg", FSOUND_HW3D, 0, 0);
  764.         FSOUND_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);   
  765.         FSOUND_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);  
  766.         FSOUND_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);  
  767.         FSOUND_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);  
  768.  
  769.         LoadTexture(":Data:Textures:grassdirt.jpg",&terraintexture,1,0);
  770.  
  771.         LoadTexture(":Data:Textures:mossrock.jpg",&terraintexture2,1,0);
  772.  
  773.         //LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
  774.  
  775.  
  776.  
  777.         temptexdetail=texdetail;
  778.         if(texdetail>1)texdetail=4;
  779.         skybox.load(    ":Data:Textures:Skybox(grass):Front.jpg",
  780.             ":Data:Textures:Skybox(grass):Left.jpg",
  781.             ":Data:Textures:Skybox(grass):Back.jpg",
  782.             ":Data:Textures:Skybox(grass):Right.jpg",
  783.             ":Data:Textures:Skybox(grass):Up.jpg",
  784.             ":Data:Textures:Skybox(grass):Down.jpg",
  785.             ":Data:Textures:Skybox(grass):Cloud.jpg",
  786.             ":Data:Textures:Skybox(grass):Reflect.jpg");
  787.  
  788.  
  789.  
  790.         texdetail=temptexdetail;
  791.     }
  792.     temptexdetail=texdetail;
  793.     texdetail=1;
  794.     terrain.load(":Data:Textures:heightmap.png");
  795.  
  796.     texdetail=temptexdetail;
  797. }
  798.  
  799.  
  800. void    Game::Loadlevel(int which){
  801.     stealthloading=0;
  802.  
  803.     if(which==0)Loadlevel((char *)":Data:Maps:map1");
  804.     else if(which==1)Loadlevel((char *)":Data:Maps:map2");
  805.     else if(which==2)Loadlevel((char *)":Data:Maps:map3");
  806.     else if(which==3)Loadlevel((char *)":Data:Maps:map4");
  807.     else if(which==4)Loadlevel((char *)":Data:Maps:map5");
  808.     else if(which==5)Loadlevel((char *)":Data:Maps:map6");
  809.     else if(which==6)Loadlevel((char *)":Data:Maps:map7");
  810.     else if(which==7)Loadlevel((char *)":Data:Maps:map8");
  811.     else if(which==8)Loadlevel((char *)":Data:Maps:map9");
  812.     else if(which==9)Loadlevel((char *)":Data:Maps:map10");
  813.     else if(which==10)Loadlevel((char *)":Data:Maps:map11");
  814.     else if(which==11)Loadlevel((char *)":Data:Maps:map12");
  815.     else if(which==12)Loadlevel((char *)":Data:Maps:map13");
  816.     else if(which==13)Loadlevel((char *)":Data:Maps:map14");
  817.     else if(which==14)Loadlevel((char *)":Data:Maps:map15");
  818.     else if(which==15)Loadlevel((char *)":Data:Maps:map16");
  819.     else if(which==-1){tutoriallevel=-1;Loadlevel((char *)":Data:Maps:tutorial");}
  820.     else Loadlevel((char *)":Data:Maps:mapsave");
  821.  
  822.     whichlevel=which;
  823. }
  824.  
  825. /*char * Game::MD5_string (unsigned char *string){
  826. char temp[50];
  827. char temp2[100];
  828.  
  829. strcpy(temp2,(const char *)string);
  830. strcat((char *)temp2,(const char *)"Lugaru");                  
  831. sprintf (temp, "%d",strlen((char *)temp2));
  832. strcat((char *)temp2,temp);                
  833.  
  834. MD5 context;
  835. unsigned int len = strlen ( (char *)temp2);
  836.  
  837. context.update   ((unsigned char *)temp2, len);
  838. context.finalize ();
  839.  
  840. return context.hex_digest();
  841. }*/
  842.  
  843.  
  844.  
  845. void    Game::Loadlevel(char *name){
  846.     int i,j,k,l,m;
  847.     static int oldlevel;
  848.     int templength;
  849.     float lamefloat;
  850.     int lameint;
  851.  
  852.     float headprop,legprop,armprop,bodyprop;
  853.  
  854.     LOGFUNC;
  855.  
  856.     LOG(std::string("Loading level...") + name);
  857.  
  858.     if(!gameon)visibleloading=1;
  859.  
  860.     if(stealthloading)visibleloading=0;
  861.  
  862.     if(!stillloading)loadtime=0;
  863.     gamestarted=1;
  864.  
  865.     numenvsounds=0;
  866.     //visibleloading=1;
  867.     if(tutoriallevel!=-1)tutoriallevel=0;
  868.     else tutoriallevel=1;
  869.  
  870.     if(tutoriallevel==1)tutorialstage=0;
  871.     if(tutorialstage==0){
  872.         tutorialstagetime=0;
  873.         tutorialmaxtime=1;
  874.     }
  875.     loadingstuff=1;
  876.     if(!firstload){
  877.         oldlevel=50;
  878.     }
  879.     FSOUND_SetPaused(channels[whooshsound], TRUE);
  880.     FSOUND_SetPaused(channels[stream_firesound], TRUE);
  881.  
  882.     int mapvers;
  883.     FILE            *tfile;
  884.     tfile=fopen( name, "rb" );
  885.     if(tfile)
  886.     {
  887.         FSOUND_SetPaused(channels[stream_firesound], TRUE);
  888.  
  889.  
  890.         scoreadded=0;
  891.         windialogue=0;
  892.  
  893.         hostiletime=0;
  894.  
  895.         won=0;
  896.  
  897.         //campaign=0;
  898.         animation[bounceidleanim].Load((char *)":Data:Animations:Idle",middleheight,neutral);
  899.  
  900.         numdialogues=0;
  901.  
  902.         for(i=0;i<20;i++)
  903.         {
  904.             dialoguegonethrough[i]=0;
  905.         }
  906.  
  907.         indialogue=-1;
  908.         cameramode=0;
  909.  
  910.         damagedealt=0;
  911.         damagetaken=0;
  912.  
  913.         if(accountactive!=-1)difficulty=accountdifficulty[accountactive];
  914.  
  915.         if(difficulty!=2)minimap=1;
  916.         else minimap=0;
  917.  
  918.         numhotspots=0;
  919.         currenthotspot=-1;
  920.         bonustime=1;
  921.  
  922.         skyboxtexture=1;
  923.         skyboxr=1;
  924.         skyboxg=1;
  925.         skyboxb=1;
  926.  
  927.         freeze=0;
  928.         winfreeze=0;
  929.  
  930.         for(i=0;i<100;i++)
  931.         {
  932.             bonusnum[i]=0;
  933.         }
  934.  
  935.         numfalls=0;
  936.         numflipfail=0;
  937.         numseen=0;
  938.         numstaffattack=0;
  939.         numswordattack=0;
  940.         numknifeattack=0;
  941.         numunarmedattack=0;
  942.         numescaped=0;
  943.         numflipped=0;
  944.         numwallflipped=0;
  945.         numthrowkill=0;
  946.         numafterkill=0;
  947.         numreversals=0;
  948.         numattacks=0;
  949.         maxalarmed=0;
  950.         numresponded=0;
  951.  
  952.         bonustotal=startbonustotal;
  953.         bonus=0;
  954.         gameon=1;
  955.         changedelay=0;
  956.         if(console)
  957.         {
  958.             PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
  959.             FSOUND_SetVolume(channels[consolesuccesssound], 256);
  960.             FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
  961.             freeze=0;
  962.             console=0;
  963.         }
  964.  
  965.         if(!stealthloading)
  966.         {
  967.             terrain.numdecals=0;
  968.             sprites.numsprites=0;
  969.             for(i=0;i<objects.numobjects;i++)
  970.             {
  971.                 objects.model[i].numdecals=0;
  972.             }
  973.  
  974.             j=objects.numobjects;
  975.             for(i=0;i<j;i++)
  976.             {
  977.                 objects.DeleteObject(0);
  978.                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
  979.             }
  980.  
  981.             for(i=0;i<subdivision;i++)
  982.             {
  983.                 for(j=0;j<subdivision;j++)
  984.                 {
  985.                     terrain.patchobjectnum[i][j]=0;
  986.                 }
  987.             }
  988.             if(visibleloading){loadscreencolor=4; LoadingScreen();}
  989.         }
  990.  
  991.         weapons.numweapons=0;
  992.  
  993.         funpackf(tfile, "Bi", &mapvers);
  994.         if(mapvers>=15)funpackf(tfile, "Bi", &indemo);
  995.         else indemo=0;
  996.         if(mapvers>=5)funpackf(tfile, "Bi", &maptype);
  997.         else maptype=mapkilleveryone;
  998.         if(mapvers>=6)funpackf(tfile, "Bi", &hostile);
  999.         else hostile=1;
  1000.         if(mapvers>=4)funpackf(tfile, "Bf Bf", &viewdistance, &fadestart);
  1001.         else
  1002.         {
  1003.             viewdistance=100;
  1004.             fadestart=.6;
  1005.         }
  1006.         if(mapvers>=2)funpackf(tfile, "Bb Bf Bf Bf", &skyboxtexture, &skyboxr, &skyboxg, &skyboxb);
  1007.         else
  1008.         {
  1009.             skyboxtexture=1;
  1010.             skyboxr=1;
  1011.             skyboxg=1;
  1012.             skyboxb=1;
  1013.         }
  1014.         if(mapvers>=10)funpackf(tfile, "Bf Bf Bf", &skyboxlightr, &skyboxlightg, &skyboxlightb);
  1015.         else
  1016.         {
  1017.             skyboxlightr=skyboxr;
  1018.             skyboxlightg=skyboxg;
  1019.             skyboxlightb=skyboxb;
  1020.         }
  1021.         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);
  1022.         if(stealthloading)funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &lamefloat,&lamefloat,&lamefloat,&lamefloat,&lamefloat, &player[0].num_weapons);
  1023.         player[0].originalcoords=player[0].coords;
  1024.         if(player[0].num_weapons>0&&player[0].num_weapons<5)
  1025.         {
  1026.             for(j=0;j<player[0].num_weapons;j++)
  1027.             {
  1028.                 player[0].weaponids[j]=weapons.numweapons;
  1029.                 funpackf(tfile, "Bi", &weapons.type[weapons.numweapons]);
  1030.                 weapons.owner[weapons.numweapons]=0;
  1031.                 weapons.numweapons++;
  1032.             }
  1033.         }
  1034.  
  1035.         if(visibleloading){loadscreencolor=4; LoadingScreen();}
  1036.  
  1037.         funpackf(tfile, "Bf Bf Bf", &player[0].armorhead, &player[0].armorhigh, &player[0].armorlow);
  1038.         funpackf(tfile, "Bf Bf Bf", &player[0].protectionhead, &player[0].protectionhigh, &player[0].protectionlow);
  1039.         funpackf(tfile, "Bf Bf Bf", &player[0].metalhead, &player[0].metalhigh, &player[0].metallow);
  1040.         funpackf(tfile, "Bf Bf", &player[0].power, &player[0].speedmult);
  1041.  
  1042.         funpackf(tfile, "Bi", &player[0].numclothes);
  1043.  
  1044.         if(mapvers>=9)
  1045.         {
  1046.             funpackf(tfile, "Bi Bi", &player[0].whichskin, &player[0].creature);
  1047.         }
  1048.         else
  1049.         {
  1050.             player[0].whichskin=0;
  1051.             player[0].creature=rabbittype;
  1052.         }
  1053.  
  1054.         for(i=0;i<max_dialogues;i++)
  1055.         {
  1056.             for(j=0;j<max_dialoguelength;j++)
  1057.             {
  1058.                 for(k=0;k<128;k++)
  1059.                 {
  1060.                     dialoguetext[i][j][k]='\0';
  1061.                 }
  1062.                 for(k=0;k<64;k++)
  1063.                 {
  1064.                     dialoguename[i][j][k]='\0';
  1065.                 }
  1066.             }
  1067.         }
  1068.  
  1069.         player[0].lastattack=-1;
  1070.         player[0].lastattack2=-1;
  1071.         player[0].lastattack3=-1;
  1072.  
  1073.         if(mapvers>=8)
  1074.         {
  1075.             funpackf(tfile, "Bi", &numdialogues);
  1076.             if(numdialogues)
  1077.             {
  1078.                 for(k=0;k<numdialogues;k++)
  1079.                 {
  1080.                     funpackf(tfile, "Bi", &numdialogueboxes[k]);
  1081.                     funpackf(tfile, "Bi", &dialoguetype[k]);
  1082.                     for(l=0;l<10;l++)
  1083.                     {
  1084.                         funpackf(tfile, "Bf Bf Bf", &participantlocation[k][l].x, &participantlocation[k][l].y, &participantlocation[k][l].z);
  1085.                         funpackf(tfile, "Bf", &participantrotation[k][l]);
  1086.                     }
  1087.                     if(numdialogueboxes)
  1088.                     {
  1089.                         for(l=0;l<numdialogueboxes[k];l++)
  1090.                         {
  1091.                             funpackf(tfile, "Bi", &dialogueboxlocation[k][l]);
  1092.                             funpackf(tfile, "Bf", &dialogueboxcolor[k][l][0]);
  1093.                             funpackf(tfile, "Bf", &dialogueboxcolor[k][l][1]);
  1094.                             funpackf(tfile, "Bf", &dialogueboxcolor[k][l][2]);
  1095.                             funpackf(tfile, "Bi", &dialogueboxsound[k][l]);
  1096.  
  1097.                             bool doneread;
  1098.  
  1099.                             funpackf(tfile, "Bi",&templength);
  1100.                             if(templength>128||templength<=0)templength=128;
  1101.                             for(m=0;m<templength;m++){
  1102.                                 funpackf(tfile, "Bb", &dialoguetext[k][l][m]);
  1103.                                 if(dialoguetext[k][l][m]=='\0')break;
  1104.                             }
  1105.  
  1106.                             funpackf(tfile, "Bi",&templength);
  1107.                             if(templength>64||templength<=0)templength=64;
  1108.                             for(m=0;m<templength;m++){
  1109.                                 funpackf(tfile, "Bb", &dialoguename[k][l][m]);
  1110.                                 if(dialoguename[k][l][m]=='\0'){
  1111.                                     break; 
  1112.                                 }
  1113.                             }
  1114.                             funpackf(tfile, "Bf Bf Bf", &dialoguecamera[k][l].x, &dialoguecamera[k][l].y, &dialoguecamera[k][l].z);
  1115.                             funpackf(tfile, "Bi", &participantfocus[k][l]);
  1116.                             funpackf(tfile, "Bi", &participantaction[k][l]);
  1117.  
  1118.                             for(m=0;m<10;m++)
  1119.                                 funpackf(tfile, "Bf Bf Bf", &participantfacing[k][l][m].x, &participantfacing[k][l][m].y, &participantfacing[k][l][m].z);
  1120.  
  1121.                             funpackf(tfile, "Bf Bf",&dialoguecamerarotation[k][l],&dialoguecamerarotation2[k][l]);
  1122.                         }
  1123.                     }
  1124.                 }
  1125.             }
  1126.         }
  1127.         else numdialogues=0;
  1128.  
  1129.         if(player[0].numclothes)
  1130.         {
  1131.             for(k=0;k<player[0].numclothes;k++)
  1132.             {
  1133.                 funpackf(tfile, "Bi", &templength);
  1134.                 for(l=0;l<templength;l++)
  1135.                     funpackf(tfile, "Bb", &player[0].clothes[k][l]);
  1136.                 player[0].clothes[k][templength]='\0';
  1137.                 funpackf(tfile, "Bf Bf Bf", &player[0].clothestintr[k], &player[0].clothestintg[k], &player[0].clothestintb[k]);                                   
  1138.             }
  1139.         }
  1140.  
  1141.         funpackf(tfile, "Bi", &environment);
  1142.  
  1143.         funpackf(tfile, "Bi", &objects.numobjects);
  1144.         if(objects.numobjects)
  1145.         {
  1146.             for(i=0;i<objects.numobjects;i++)
  1147.             {
  1148.                 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]);
  1149.                 if(objects.type[i]==treeleavestype)objects.scale[i]=objects.scale[i-1];
  1150.             }
  1151.         }
  1152.  
  1153.         if(mapvers>=7)
  1154.         {
  1155.             funpackf(tfile, "Bi", &numhotspots);
  1156.             if(numhotspots)
  1157.             {
  1158.                 for(i=0;i<numhotspots;i++)
  1159.                 {
  1160.                     funpackf(tfile, "Bi Bf Bf Bf Bf", &hotspottype[i],&hotspotsize[i],&hotspot[i].x,&hotspot[i].y,&hotspot[i].z);
  1161.                     funpackf(tfile, "Bi", &templength);
  1162.                     if(templength)
  1163.                         for(l=0;l<templength;l++)
  1164.                             funpackf(tfile, "Bb", &hotspottext[i][l]);
  1165.                     hotspottext[i][templength]='\0';
  1166.                     if(hotspottype[i]==-111)indemo=1;
  1167.                 }
  1168.             }
  1169.         }
  1170.         else numhotspots=0;
  1171.  
  1172.         if(visibleloading){loadscreencolor=4; LoadingScreen();}
  1173.  
  1174.         if(!stealthloading)
  1175.         {
  1176.             objects.center=0;
  1177.             for(i=0;i<objects.numobjects;i++)
  1178.             {
  1179.                 objects.center+=objects.position[i];   
  1180.             }
  1181.             objects.center/=objects.numobjects;
  1182.  
  1183.  
  1184.             if(visibleloading){loadscreencolor=4; LoadingScreen();}
  1185.  
  1186.             float maxdistance=0;
  1187.             float tempdist;
  1188.             int whichclosest;
  1189.             for(i=0;i<objects.numobjects;i++)
  1190.             {
  1191.                 tempdist=findDistancefast(&objects.center,&objects.position[i]);
  1192.                 if(tempdist>maxdistance)
  1193.                 {
  1194.                     whichclosest=i;
  1195.                     maxdistance=tempdist;
  1196.                 }
  1197.             }
  1198.             objects.radius=fast_sqrt(maxdistance);
  1199.         }              
  1200.  
  1201.         if(visibleloading){loadscreencolor=4; LoadingScreen();}
  1202.         //mapcenter=objects.center;
  1203.         //mapradius=objects.radius;
  1204.  
  1205.         funpackf(tfile, "Bi", &numplayers);
  1206.         int howmanyremoved=0;
  1207.         bool removeanother=0;
  1208.         if(numplayers>1&&numplayers<maxplayers)
  1209.         {
  1210.             for(i=1;i<numplayers;i++)
  1211.             {
  1212.                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
  1213.                 removeanother=0;
  1214.  
  1215.                 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);
  1216.                 if(mapvers>=5)funpackf(tfile, "Bi", &player[i-howmanyremoved].howactive);
  1217.                 else player[i-howmanyremoved].howactive=typeactive;
  1218.                 if(mapvers>=3)funpackf(tfile, "Bf",&player[i-howmanyremoved].scale);
  1219.                 else player[i-howmanyremoved].scale=-1;
  1220.                 if(mapvers>=11)funpackf(tfile, "Bb",&player[i-howmanyremoved].immobile);
  1221.                 else player[i-howmanyremoved].immobile=0;
  1222.                 if(mapvers>=12)funpackf(tfile, "Bf",&player[i-howmanyremoved].rotation);
  1223.                 else player[i-howmanyremoved].rotation=0;
  1224.                 player[i-howmanyremoved].targetrotation=player[i-howmanyremoved].rotation;
  1225.                 if(player[i-howmanyremoved].num_weapons<0||player[i-howmanyremoved].num_weapons>5){
  1226.                     removeanother=1;
  1227.                     howmanyremoved++;
  1228.                 }
  1229.                 if(!removeanother)
  1230.                 {
  1231.                     if(player[i-howmanyremoved].num_weapons>0&&player[i-howmanyremoved].num_weapons<5)
  1232.                     {
  1233.                         for(j=0;j<player[i-howmanyremoved].num_weapons;j++)
  1234.                         {
  1235.                             player[i-howmanyremoved].weaponids[j]=weapons.numweapons;
  1236.                             funpackf(tfile, "Bi", &weapons.type[player[i-howmanyremoved].weaponids[j]]);
  1237.                             weapons.owner[player[i-howmanyremoved].weaponids[j]]=i;
  1238.                             weapons.numweapons++;
  1239.                         }
  1240.                     }
  1241.                     funpackf(tfile, "Bi", &player[i-howmanyremoved].numwaypoints);
  1242.                     //player[i-howmanyremoved].numwaypoints=10;
  1243.                     for(j=0;j<player[i-howmanyremoved].numwaypoints;j++)
  1244.                     {
  1245.                         funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].x);
  1246.                         funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].y);
  1247.                         funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].z);
  1248.                         if(mapvers>=5)funpackf(tfile, "Bi", &player[i-howmanyremoved].waypointtype[j]);
  1249.                         else player[i-howmanyremoved].waypointtype[j] = wpkeepwalking;
  1250.                     }
  1251.  
  1252.                     funpackf(tfile, "Bi", &player[i-howmanyremoved].waypoint);
  1253.                     if(player[i-howmanyremoved].waypoint>player[i-howmanyremoved].numwaypoints-1)player[i-howmanyremoved].waypoint=0;
  1254.  
  1255.                     funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].armorhead, &player[i-howmanyremoved].armorhigh, &player[i-howmanyremoved].armorlow);
  1256.                     funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].protectionhead, &player[i-howmanyremoved].protectionhigh, &player[i-howmanyremoved].protectionlow);
  1257.                     funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].metalhead, &player[i-howmanyremoved].metalhigh, &player[i-howmanyremoved].metallow);
  1258.                     funpackf(tfile, "Bf Bf", &player[i-howmanyremoved].power, &player[i-howmanyremoved].speedmult);
  1259.  
  1260.                     if(mapvers>=4)funpackf(tfile, "Bf Bf Bf Bf", &headprop, &bodyprop, &armprop, &legprop);
  1261.                     else
  1262.                     {
  1263.                         headprop=1;
  1264.                         bodyprop=1;
  1265.                         armprop=1;
  1266.                         legprop=1;
  1267.                     }
  1268.                     if(player[i-howmanyremoved].creature==wolftype)
  1269.                     {
  1270.                         player[i-howmanyremoved].proportionhead=1.1*headprop;
  1271.                         player[i-howmanyremoved].proportionbody=1.1*bodyprop;
  1272.                         player[i-howmanyremoved].proportionarms=1.1*armprop;
  1273.                         player[i-howmanyremoved].proportionlegs=1.1*legprop;
  1274.                     }
  1275.  
  1276.                     if(player[i-howmanyremoved].creature==rabbittype)
  1277.                     {
  1278.                         player[i-howmanyremoved].proportionhead=1.2*headprop;
  1279.                         player[i-howmanyremoved].proportionbody=1.05*bodyprop;
  1280.                         player[i-howmanyremoved].proportionarms=1.00*armprop;
  1281.                         player[i-howmanyremoved].proportionlegs=1.1*legprop;
  1282.                         player[i-howmanyremoved].proportionlegs.y=1.05*legprop;
  1283.                     }
  1284.  
  1285.                     funpackf(tfile, "Bi", &player[i-howmanyremoved].numclothes);
  1286.                     if(player[i-howmanyremoved].numclothes)
  1287.                     {
  1288.                         for(k=0;k<player[i-howmanyremoved].numclothes;k++)
  1289.                         {
  1290.                             int templength;
  1291.                             funpackf(tfile, "Bi", &templength);
  1292.                             for(l=0;l<templength;l++)
  1293.                                 funpackf(tfile, "Bb", &player[i-howmanyremoved].clothes[k][l]);
  1294.                             player[i-howmanyremoved].clothes[k][templength]='\0';
  1295.                             funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].clothestintr[k], &player[i-howmanyremoved].clothestintg[k], &player[i-howmanyremoved].clothestintb[k]);                                  
  1296.                         }
  1297.                     }
  1298.                 }
  1299.             }
  1300.         }
  1301.         if(visibleloading){loadscreencolor=4; LoadingScreen();}
  1302.  
  1303.         numplayers-=howmanyremoved;
  1304.         funpackf(tfile, "Bi", &numpathpoints);
  1305.         if(numpathpoints>30||numpathpoints<0)
  1306.             numpathpoints=0;
  1307.         if(numpathpoints)
  1308.         {
  1309.             for(j=0;j<numpathpoints;j++)
  1310.             {
  1311.                 funpackf(tfile, "Bf Bf Bf Bi", &pathpoint[j].x,&pathpoint[j].y,&pathpoint[j].z,&numpathpointconnect[j]);
  1312.                 for(k=0;k<numpathpointconnect[j];k++){
  1313.                     funpackf(tfile, "Bi", &pathpointconnect[j][k]);
  1314.                 }
  1315.             }
  1316.         }
  1317.         if(visibleloading){loadscreencolor=4; LoadingScreen();}
  1318.  
  1319.         funpackf(tfile, "Bf Bf Bf Bf", &mapcenter.x,&mapcenter.y,&mapcenter.z,&mapradius);
  1320.  
  1321.         SetUpLighting();
  1322.         if(environment!=oldenvironment)Setenvironment(environment);
  1323.         oldenvironment=environment;
  1324.  
  1325.         if(!stealthloading)
  1326.         {
  1327.             j=objects.numobjects;
  1328.             objects.numobjects=0;
  1329.             for(i=0;i<j;i++)
  1330.             {
  1331.                 //if(objects.type[i]!=spiketype)
  1332.                 objects.MakeObject(objects.type[i],objects.position[i],objects.rotation[i],objects.rotation2[i],objects.scale[i]);
  1333.                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
  1334.             }
  1335.  
  1336.             //if(skyboxtexture){
  1337.             terrain.DoShadows();
  1338.             if(visibleloading){loadscreencolor=4; LoadingScreen();}
  1339.             objects.DoShadows();
  1340.             if(visibleloading){loadscreencolor=4; LoadingScreen();}
  1341.             /*}
  1342.             else terrain.DoLighting();
  1343.             */
  1344.         }
  1345.  
  1346.         fclose(tfile);
  1347.  
  1348.         oldlevel=whichlevel;
  1349.  
  1350.  
  1351.         if(numplayers>maxplayers-1)numplayers=maxplayers-1;
  1352.         for(i=0;i<numplayers;i++)
  1353.         {
  1354.             if(visibleloading){loadscreencolor=4; LoadingScreen();}
  1355.             player[i].burnt=0;
  1356.             player[i].bled=0;
  1357.             player[i].onfire=0;
  1358.             if(i==0||player[i].scale<0)player[i].scale=.2;
  1359.             player[i].skeleton.free=0;
  1360.             player[i].skeleton.id=i;
  1361.             //if(Random()%2==0)player[i].creature=wolftype;
  1362.             //else player[i].creature=rabbittype;
  1363.             if(i==0&&mapvers<9)player[i].creature=rabbittype;
  1364.             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);
  1365.             else
  1366.             {
  1367.                 if(player[i].creature!=wolftype){
  1368.                     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);
  1369.                     LoadTexture(":Data:Textures:Belt.png",&player[i].skeleton.drawmodelclothes.textureptr,1,1);
  1370.                 }
  1371.                 if(player[i].creature==wolftype){
  1372.                     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);
  1373.                 }
  1374.             }
  1375.  
  1376.  
  1377.             int texsize;
  1378.             texsize=512*512*3/texdetail/texdetail;
  1379.             //if(!player[i].loaded)player[i].skeleton.skinText = new GLubyte[texsize];
  1380.             //player[i].skeleton.skinText.resize(texsize);
  1381.  
  1382.             if(player[i].creature==rabbittype)
  1383.             {
  1384.                 if(player[i].whichskin==0){
  1385.                     LoadTextureSave(":Data:Textures:Fur3.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
  1386.                 }
  1387.                 else if(player[i].whichskin==1){
  1388.                     LoadTextureSave(":Data:Textures:Fur.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
  1389.                 }
  1390.                 else if(player[i].whichskin==2){
  1391.                     LoadTextureSave(":Data:Textures:Fur2.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
  1392.                 }
  1393.                 else if(player[i].whichskin==3){
  1394.                     LoadTextureSave(":Data:Textures:Lynx.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
  1395.                 }
  1396.                 else if(player[i].whichskin==4){
  1397.                     LoadTextureSave(":Data:Textures:Otter.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
  1398.                 }
  1399.                 else if(player[i].whichskin==5){
  1400.                     LoadTextureSave(":Data:Textures:Opal.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
  1401.                 }
  1402.                 else if(player[i].whichskin==6){
  1403.                     LoadTextureSave(":Data:Textures:Sable.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
  1404.                 }
  1405.                 else if(player[i].whichskin==7){
  1406.                     LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
  1407.                 }
  1408.                 else if(player[i].whichskin==8){
  1409.                     LoadTextureSave(":Data:Textures:BW2.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
  1410.                 }
  1411.                 else if(player[i].whichskin==9){
  1412.                     LoadTextureSave(":Data:Textures:WB2.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
  1413.                 }
  1414.             }
  1415.             if(player[i].creature==wolftype)
  1416.             {
  1417.                 //k=abs(Random()%3);
  1418.                 if(player[i].whichskin==0){
  1419.                     LoadTextureSave(":Data:Textures:Wolf.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
  1420.                 }
  1421.                 else if(player[i].whichskin==1){
  1422.                     LoadTextureSave(":Data:Textures:Darkwolf.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
  1423.                 }
  1424.                 else if(player[i].whichskin==2){
  1425.                     LoadTextureSave(":Data:Textures:Snowwolf.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
  1426.                 }
  1427.             }
  1428.  
  1429.             if(player[i].numclothes)
  1430.             {
  1431.                 for(j=0;j<player[i].numclothes;j++)
  1432.                 {
  1433.                     tintr=player[i].clothestintr[j];
  1434.                     tintg=player[i].clothestintg[j];
  1435.                     tintb=player[i].clothestintb[j];
  1436.                     AddClothes((char *)player[i].clothes[j],0,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
  1437.                 }
  1438.                 player[i].DoMipmaps(5,0,0,player[i].skeleton.skinsize,player[i].skeleton.skinsize);
  1439.             }
  1440.  
  1441.             player[i].currentanimation=bounceidleanim;
  1442.             player[i].targetanimation=bounceidleanim;
  1443.             player[i].currentframe=0;
  1444.             player[i].targetframe=1;
  1445.             player[i].target=0;
  1446.             player[i].speed=1+(float)(Random()%100)/1000;
  1447.             if(difficulty==0)player[i].speed-=.2;
  1448.             if(difficulty==1)player[i].speed-=.1;
  1449.  
  1450.             player[i].velocity=0;
  1451.             player[i].oldcoords=player[i].coords;
  1452.             player[i].realoldcoords=player[i].coords;
  1453.  
  1454.             player[i].id=i;
  1455.             player[i].skeleton.id=i;
  1456.             player[i].updatedelay=0;
  1457.             player[i].normalsupdatedelay=0;
  1458.  
  1459.             player[i].aitype=passivetype;
  1460.             player[i].aitarget=0;
  1461.             player[i].madskills=0;
  1462.  
  1463.             if(i==0)
  1464.             {
  1465.                 player[i].proportionhead=1.2;
  1466.                 player[i].proportionbody=1.05;
  1467.                 player[i].proportionarms=1.00;
  1468.                 player[i].proportionlegs=1.1;
  1469.                 player[i].proportionlegs.y=1.05;
  1470.             }
  1471.             player[i].headless=0;
  1472.             player[i].currentoffset=0;
  1473.             player[i].targetoffset=0;
  1474.             /*player[i].armorhead=1;
  1475.             player[i].armorhigh=1;
  1476.             player[i].armorlow=1;
  1477.             player[i].protectionhead=1;
  1478.             player[i].protectionhigh=1;
  1479.             player[i].protectionlow=1;
  1480.             player[i].metalhead=1;
  1481.             player[i].metalhigh=1;
  1482.             player[i].metallow=1;
  1483.             player[i].power=1;
  1484.             player[i].speedmult=1;*/
  1485.  
  1486.             player[i].damagetolerance=200;
  1487.  
  1488.             if(player[i].creature==wolftype)
  1489.             {
  1490.                 /*player[i].proportionhead=1.1;
  1491.                 player[i].proportionbody=1.1;
  1492.                 player[i].proportionarms=1.1;
  1493.                 player[i].proportionlegs=1.1;
  1494.                 player[i].proportionlegs.y=1.1;*/
  1495.                 if(i==0||player[i].scale<0)player[i].scale=.23;
  1496.  
  1497.                 player[i].damagetolerance=300;
  1498.             }              
  1499.  
  1500.             if(visibleloading){loadscreencolor=4; LoadingScreen();}
  1501.             if(cellophane)
  1502.             {
  1503.                 player[i].proportionhead.z=0;
  1504.                 player[i].proportionbody.z=0;
  1505.                 player[i].proportionarms.z=0;
  1506.                 player[i].proportionlegs.z=0;
  1507.             }
  1508.  
  1509.             player[i].tempanimation.Load((char *)":Data:Animations:Tempanim",0,0);
  1510.  
  1511.             player[i].headmorphness=0;
  1512.             player[i].targetheadmorphness=1;
  1513.             player[i].headmorphstart=0;
  1514.             player[i].headmorphend=0;
  1515.  
  1516.             player[i].pausetime=0;
  1517.  
  1518.             player[i].dead=0;
  1519.             player[i].jumppower=5;
  1520.             player[i].damage=0;
  1521.             player[i].permanentdamage=0;
  1522.             player[i].superpermanentdamage=0;
  1523.  
  1524.             player[i].forwardkeydown=0;
  1525.             player[i].leftkeydown=0;
  1526.             player[i].backkeydown=0;
  1527.             player[i].rightkeydown=0;
  1528.             player[i].jumpkeydown=0;
  1529.             player[i].crouchkeydown=0;
  1530.             player[i].throwkeydown=0;
  1531.  
  1532.             player[i].collided=-10;
  1533.             player[i].loaded=1;
  1534.             player[i].bloodloss=0;
  1535.             player[i].weaponactive=-1;
  1536.             player[i].weaponstuck=-1;
  1537.             player[i].bleeding=0;
  1538.             player[i].deathbleeding=0;
  1539.             player[i].stunned=0;
  1540.             player[i].hasvictim=0;
  1541.             player[i].wentforweapon=0;
  1542.         }
  1543.  
  1544.         player[0].aitype=playercontrolled;
  1545.         player[0].weaponactive=-1;
  1546.  
  1547.         if(difficulty==1)
  1548.         {
  1549.             //player[0].speedmult=1/.9;
  1550.             player[0].power=1/.9;
  1551.         }
  1552.  
  1553.         if(difficulty==0)
  1554.         {
  1555.             //player[0].speedmult=1/.8;
  1556.             player[0].power=1/.8;
  1557.         }
  1558.  
  1559.         //player[0].weaponstuck=1;
  1560.  
  1561.         if(difficulty==1)player[0].damagetolerance=250;
  1562.         if(difficulty==0)player[0].damagetolerance=300;
  1563.         if(difficulty==0)player[0].armorhead*=1.5;
  1564.         if(difficulty==0)player[0].armorhigh*=1.5;
  1565.         if(difficulty==0)player[0].armorlow*=1.5;
  1566.         cameraloc=player[0].coords;
  1567.         cameraloc.y+=5;
  1568.         rotation=player[0].rotation;
  1569.  
  1570.         hawkcoords=player[0].coords;
  1571.         hawkcoords.y+=30;
  1572.  
  1573.         if(visibleloading){loadscreencolor=4; LoadingScreen();}
  1574.         //weapons.numweapons=numplayers;
  1575.         for(i=0;i<weapons.numweapons;i++)
  1576.         {
  1577.             weapons.bloody[i]=0;
  1578.             weapons.blooddrip[i]=0;
  1579.             weapons.blooddripdelay[i]=0;
  1580.             weapons.onfire[i]=0;
  1581.             weapons.flamedelay[i]=0;
  1582.             weapons.damage[i]=0;
  1583.             //weapons.type[i]=sword;
  1584.             if(weapons.type[i]==sword){
  1585.                 weapons.mass[i]=1.5;
  1586.                 weapons.tipmass[i]=1;
  1587.                 weapons.length[i]=.8;
  1588.             }
  1589.             if(weapons.type[i]==staff){
  1590.                 weapons.mass[i]=2;
  1591.                 weapons.tipmass[i]=1;
  1592.                 weapons.length[i]=1.5;
  1593.             }
  1594.             if(weapons.type[i]==knife){
  1595.                 weapons.mass[i]=1;
  1596.                 weapons.tipmass[i]=1.2;
  1597.                 weapons.length[i]=.25;
  1598.             }
  1599.             weapons.position[i]=-1000;
  1600.             weapons.tippoint[i]=-1000;
  1601.         }
  1602.  
  1603. /*      for(i=0;i<32;i++){
  1604.             //if(i<16||i>20)               
  1605.             FSOUND_StopSound(i);
  1606.         }
  1607. */
  1608.         LOG("Starting background music...");
  1609.  
  1610.         FSOUND_StopSound(FSOUND_ALL);
  1611.         if(environment==snowyenvironment)
  1612.         {
  1613.             if(ambientsound)
  1614.             {
  1615.                 PlayStreamEx(stream_wind, strm[stream_wind], NULL, TRUE);
  1616.                 FSOUND_SetPaused(channels[stream_wind], FALSE);
  1617.                 FSOUND_SetVolume(channels[stream_wind], 256);
  1618.             }
  1619.         }
  1620.         else if(environment==desertenvironment)
  1621.         {
  1622.             if(ambientsound)
  1623.             {
  1624.                 //PlaySoundEx(desertambient,
  1625.                 //  samp[desertambient], NULL, TRUE);
  1626.                 PlayStreamEx(stream_desertambient,
  1627.                     strm[stream_desertambient], NULL, TRUE);
  1628.                 FSOUND_SetPaused(channels[stream_desertambient], FALSE);
  1629.                 FSOUND_SetVolume(channels[stream_desertambient], 256);
  1630.             }
  1631.         }
  1632.         else if(environment==grassyenvironment)
  1633.         {
  1634.             if(ambientsound)
  1635.             {
  1636.                 //PlaySoundEx(wind, samp[wind], NULL, TRUE);
  1637.                 PlayStreamEx(stream_wind, strm[stream_wind], NULL, TRUE);
  1638.                 FSOUND_SetPaused(channels[stream_wind], FALSE);
  1639.                 FSOUND_SetVolume(channels[stream_wind], 100);
  1640.             }
  1641.         }
  1642.         oldmusicvolume[0]=0;
  1643.         oldmusicvolume[1]=0;
  1644.         oldmusicvolume[2]=0;
  1645.         oldmusicvolume[3]=0;
  1646.  
  1647.  
  1648.         /*LoadTexture(":Data:Textures:cloud.png",&sprites.cloudtexture,1,1);
  1649.         LoadTexture(":Data:Textures:cloudimpact.png",&sprites.cloudimpacttexture,1,1);
  1650.         LoadTexture(":Data:Textures:bloodparticle.png",&sprites.bloodtexture,1,1);
  1651.         LoadTexture(":Data:Textures:snowflake.png",&sprites.snowflaketexture,1,1);
  1652.         LoadTexture(":Data:Textures:flame.png",&sprites.flametexture,1,1);
  1653.         LoadTexture(":Data:Textures:bloodflame.png",&sprites.bloodflametexture,1,1);
  1654.         LoadTexture(":Data:Textures:smoke.png",&sprites.smoketexture,1,1);
  1655.         LoadTexture(":Data:Textures:shine.png",&sprites.shinetexture,1,0);
  1656.         */
  1657.  
  1658.         if(!firstload)
  1659.         {
  1660.             firstload=1;
  1661.         }
  1662.     }
  1663.     leveltime=0;
  1664.     loadingstuff=0;
  1665.     visibleloading=0;
  1666. }
  1667.  
  1668. void    Game::Tick()
  1669. {
  1670.     static int i,k,j,l,m;
  1671.     static XYZ facing,flatfacing,absflatfacing;
  1672.     static XYZ rotatetarget;
  1673.     static bool oldkey;
  1674.     static float oldtargetrotation;
  1675.     static int target, numgood;
  1676.     static XYZ tempcoords1,tempcoords2;
  1677.     static XYZ test;
  1678.     static XYZ test2;
  1679.     static XYZ lowpoint,lowpointtarget,lowpoint2,lowpointtarget2,lowpoint3,lowpointtarget3,lowpoint4,lowpointtarget4,lowpoint5,lowpointtarget5,lowpoint6,lowpointtarget6,lowpoint7,lowpointtarget7,colpoint,colpoint2;
  1680.     static int whichhit;
  1681.     static bool donesomething;
  1682.     static bool oldjumpkeydown;
  1683.  
  1684.     int templength;
  1685.  
  1686.     float headprop,bodyprop,armprop,legprop;
  1687.  
  1688.     if(newnetmessages){
  1689.         newnetmessages=0;
  1690.         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
  1691.         FSOUND_SetVolume(channels[consolesuccesssound], 256);
  1692.         FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
  1693.  
  1694.         for(k=14;k>=2;k--){
  1695.             for(j=0;j<255;j++){
  1696.                 consoletext[k][j]=consoletext[k-1][j];
  1697.             }
  1698.             consolechars[k]=consolechars[k-1];
  1699.         }
  1700.         for(k=14;k>=2;k--){
  1701.             for(j=0;j<255;j++){
  1702.                 displaytext[k][j]=displaytext[k-1][j];
  1703.             }
  1704.             displaychars[k]=displaychars[k-1];
  1705.             displaytime[k]=displaytime[k-1];
  1706.         }
  1707.         for(j=0;j<255;j++){
  1708.             consoletext[1][j]=' ';
  1709.             displaytext[1][j]=' ';
  1710.         }
  1711.         sprintf (consoletext[1], netmessages);
  1712.         sprintf (displaytext[1], netmessages);
  1713.         consolechars[1]=255;
  1714.         displaychars[1]=255;
  1715.         displaytime[1]=0;
  1716.     }
  1717.  
  1718.     for(i=0;i<15;i++){
  1719.         displaytime[i]+=multiplier;
  1720.     }
  1721.  
  1722.     static unsigned char    theKeyMap[16];
  1723.     GetKeys( theKeyMap );
  1724.  
  1725.     keyboardfrozen=0;
  1726.  
  1727.  
  1728.     static bool mainmenutogglekeydown;
  1729.     if(!console){
  1730.         if(mainmenu&&endgame==1)mainmenu=10;
  1731.         if(IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)&&!mainmenutogglekeydown&&(mainmenu==7&&entername)){
  1732.             for(j=0;j<255;j++){
  1733.                 displaytext[0][j]=' ';
  1734.             }
  1735.             displaychars[0]=0;
  1736.             displayselected=0;
  1737.             entername=0;
  1738.             mainmenutogglekeydown=1;
  1739.         }
  1740.         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==12&&!tryquit)||mainmenu==13||mainmenu==14||mainmenu==15||mainmenu==16||mainmenu==17||mainmenu==10)){
  1741.             selected=-1;
  1742.             if(mainmenu==1||mainmenu==2||mainmenu==0){
  1743.                 if(mainmenu==0&&!winfreeze)mainmenu=2;
  1744.                 else if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1)mainmenu=100;
  1745.                 else if(mainmenu==0&&winfreeze){
  1746.                     /*  if(campaignchoosenext[campaignchoicewhich[whichchoice]]==2)
  1747.                     stealthloading=1;
  1748.                     else stealthloading=0;
  1749.  
  1750.                     if(!stealthloading){
  1751.                     float gLoc[3]={0,0,0};
  1752.                     float vel[3]={0,0,0};
  1753.                     FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);  
  1754.                     PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
  1755.                     FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  1756.                     FSOUND_SetVolume(channels[firestartsound], 256);
  1757.                     FSOUND_SetPaused(channels[firestartsound], FALSE);
  1758.                     FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);  
  1759.  
  1760.                     flashr=1;
  1761.                     flashg=0;
  1762.                     flashb=0;
  1763.                     flashamount=1;
  1764.                     flashdelay=1;
  1765.                     }
  1766.  
  1767.                     startbonustotal=0;
  1768.  
  1769.                     for(i=0;i<campaignnumlevels;i++){
  1770.                     levelvisible[i]=0;
  1771.                     levelhighlight[i]=0;
  1772.                     }
  1773.  
  1774.                     levelorder[0]=0;
  1775.                     levelvisible[0]=1;
  1776.                     if(accountcampaignchoicesmade[accountactive])
  1777.                     for(i=0;i<accountcampaignchoicesmade[accountactive];i++){
  1778.                     levelorder[i+1]=campaignnextlevel[levelorder[i]][accountcampaignchoices[accountactive][i]];
  1779.                     levelvisible[levelorder[i+1]]=1;
  1780.                     }
  1781.                     int whichlevelstart;
  1782.                     whichlevelstart=accountcampaignchoicesmade[accountactive]-1;
  1783.                     if(whichlevelstart<0){
  1784.                     campaignchoicenum=1;
  1785.                     campaignchoicewhich[0]=0;
  1786.                     }
  1787.                     else
  1788.                     {
  1789.                     campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
  1790.                     if(campaignchoicenum)
  1791.                     for(i=0;i<campaignchoicenum;i++){
  1792.                     campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
  1793.                     levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
  1794.                     levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
  1795.                     }
  1796.                     }
  1797.  
  1798.                     loading=2;
  1799.                     loadtime=0;
  1800.                     targetlevel=7;
  1801.                     if(firstload)TickOnceAfter();
  1802.                     if(!firstload)LoadStuff();
  1803.                     //else {
  1804.                     for(i=0;i<255;i++){
  1805.                     mapname[i]='\0';
  1806.                     }
  1807.                     mapname[0]=':';
  1808.                     mapname[1]='D';
  1809.                     mapname[2]='a';
  1810.                     mapname[3]='t';
  1811.                     mapname[4]='a';
  1812.                     mapname[5]=':';
  1813.                     mapname[6]='M';
  1814.                     mapname[7]='a';
  1815.                     mapname[8]='p';
  1816.                     mapname[9]='s';
  1817.                     mapname[10]=':';
  1818.  
  1819.                     //accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
  1820.                     //accountcampaignchoicesmade[accountactive]++;
  1821.  
  1822.  
  1823.                     strcat(mapname,campaignmapname[campaignchoicewhich[0]]);
  1824.                     whichchoice=0;
  1825.                     visibleloading=1;
  1826.                     stillloading=1;
  1827.                     Loadlevel(mapname);
  1828.                     campaign=1;
  1829.                     mainmenu=0;
  1830.                     gameon=1;
  1831.                     FSOUND_SetPaused(channels[music3], TRUE);
  1832.  
  1833.                     stealthloading=0;*/
  1834.                 }
  1835.                 else if(mainmenu==1||mainmenu==2)mainmenu=0;
  1836.                 if(mainmenu&&musictoggle){
  1837.                     if(mainmenu==1||mainmenu==2||mainmenu==100){
  1838.                         FSOUND_SetFrequency(FSOUND_ALL, 0.001);
  1839.                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
  1840.                         FSOUND_SetPaused(channels[stream_music3], FALSE);
  1841.                         FSOUND_SetVolume(channels[stream_music3], 256);
  1842.                         FSOUND_SetPaused(channels[music1], TRUE);
  1843.                     }
  1844.                 }
  1845.                 if(!mainmenu){
  1846.                     FSOUND_SetPaused(channels[stream_music3], TRUE);
  1847.                     FSOUND_SetPaused(channels[music1], FALSE);
  1848.                 }
  1849.             }
  1850.             if(mainmenu==3){
  1851.                 float gLoc[3]={0,0,0};
  1852.                 float vel[3]={0,0,0};
  1853.                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  1854.                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
  1855.                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  1856.                 FSOUND_SetVolume(channels[fireendsound], 256);
  1857.                 FSOUND_SetPaused(channels[fireendsound], FALSE);
  1858.                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  1859.  
  1860.                 flashr=1;
  1861.                 flashg=0;
  1862.                 flashb=0;
  1863.                 flashamount=1;
  1864.                 flashdelay=1;
  1865.  
  1866.                 if(newdetail>2)newdetail=detail;
  1867.                 if(newdetail<0)newdetail=detail;
  1868. #if !USE_SDL  // we'll take anything that works.
  1869.                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
  1870.                 if(newscreenheight>3000)newscreenheight=screenheight;
  1871. #endif
  1872.                 if(newscreenwidth<0)newscreenwidth=screenwidth;
  1873.                 if(newscreenheight<0)newscreenheight=screenheight;
  1874.  
  1875.                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
  1876.                 opstream << "Screenwidth:\n";
  1877.                 opstream << newscreenwidth;
  1878.                 opstream << "\nScreenheight:\n";
  1879.                 opstream << newscreenheight;
  1880.                 opstream << "\nMouse sensitivity:\n";
  1881.                 opstream << usermousesensitivity;
  1882.                 opstream << "\nBlur(0,1):\n";
  1883.                 opstream << ismotionblur;
  1884.                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
  1885.                 opstream << newdetail;
  1886.                 opstream << "\nFloating jump:\n";
  1887.                 opstream << floatjump;
  1888.                 opstream << "\nMouse jump:\n";
  1889.                 opstream << mousejump;
  1890.                 opstream << "\nAmbient sound:\n";
  1891.                 opstream << ambientsound;
  1892.                 opstream << "\nBlood (0,1,2):\n";
  1893.                 opstream << bloodtoggle;
  1894.                 opstream << "\nAuto slomo:\n";
  1895.                 opstream << autoslomo;
  1896.                 opstream << "\nFoliage:\n";
  1897.                 opstream << foliage;
  1898.                 opstream << "\nMusic:\n";
  1899.                 opstream << musictoggle;
  1900.                 opstream << "\nTrilinear:\n";
  1901.                 opstream << trilinear;
  1902.                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
  1903.                 opstream << decals;
  1904.                 opstream << "\nInvert mouse:\n";
  1905.                 opstream << invertmouse;
  1906.                 opstream << "\nGamespeed:\n";
  1907.                 if(oldgamespeed==0)oldgamespeed=1;
  1908.                 opstream << oldgamespeed;
  1909.                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
  1910.                 opstream << difficulty;
  1911.                 opstream << "\nDamage effects(blackout, doublevision):\n";
  1912.                 opstream << damageeffects;
  1913.                 opstream << "\nText:\n";
  1914.                 opstream << texttoggle;
  1915.                 opstream << "\nDebug:\n";
  1916.                 opstream << debugmode;
  1917.                 opstream << "\nVBL Sync:\n";
  1918.                 opstream << vblsync;
  1919.                 opstream << "\nShow Points:\n";
  1920.                 opstream << showpoints;
  1921.                 opstream << "\nAlways Blur:\n";
  1922.                 opstream << alwaysblur;
  1923.                 opstream << "\nImmediate mode (turn on on G5):\n";
  1924.                 opstream << immediate;
  1925.                 opstream << "\nVelocity blur:\n";
  1926.                 opstream << velocityblur;
  1927.                 opstream << "\nVolume:\n";
  1928.                 opstream << volume;
  1929.                 opstream << "\nForward key:\n";
  1930.                 opstream << KeyToChar(forwardkey);
  1931.                 opstream << "\nBack key:\n";
  1932.                 opstream << KeyToChar(backkey);
  1933.                 opstream << "\nLeft key:\n";
  1934.                 opstream << KeyToChar(leftkey);
  1935.                 opstream << "\nRight key:\n";
  1936.                 opstream << KeyToChar(rightkey);
  1937.                 opstream << "\nJump key:\n";
  1938.                 opstream << KeyToChar(jumpkey);
  1939.                 opstream << "\nCrouch key:\n";
  1940.                 opstream << KeyToChar(crouchkey);
  1941.                 opstream << "\nDraw key:\n";
  1942.                 opstream << KeyToChar(drawkey);
  1943.                 opstream << "\nThrow key:\n";
  1944.                 opstream << KeyToChar(throwkey);
  1945.                 opstream << "\nAttack key:\n";
  1946.                 opstream << KeyToChar(attackkey);
  1947.                 opstream << "\nChat key:\n";
  1948.                 opstream << KeyToChar(chatkey);
  1949.                 opstream.close();
  1950.             }  
  1951.             if(mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==9||mainmenu==12||mainmenu==13||mainmenu==14||mainmenu==10||mainmenu==11||mainmenu==100){
  1952.                 float gLoc[3]={0,0,0};
  1953.                 float vel[3]={0,0,0};
  1954.                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  1955.                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
  1956.                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  1957.                 FSOUND_SetVolume(channels[fireendsound], 256);
  1958.                 FSOUND_SetPaused(channels[fireendsound], FALSE);
  1959.                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  1960.  
  1961.                 flashr=1;
  1962.                 flashg=0;
  1963.                 flashb=0;
  1964.                 flashamount=1;
  1965.                 flashdelay=1;
  1966.             }  
  1967.             if(mainmenu==3&&gameon)mainmenu=2;
  1968.             if(mainmenu==3&&!gameon)mainmenu=1;
  1969.             if(mainmenu==5&&gameon)mainmenu=2;
  1970.             if(mainmenu==5&&!gameon)mainmenu=1;
  1971.             if(mainmenu==4)mainmenu=3;
  1972.             if(mainmenu==6)mainmenu=5;
  1973.             if(mainmenu==7)mainmenu=1;
  1974.             if(mainmenu==9)mainmenu=5;
  1975.             if(mainmenu==11)mainmenu=5;
  1976.             if(mainmenu==12)mainmenu=5;
  1977.             if(mainmenu==13)mainmenu=12;
  1978.             if(mainmenu==14)mainmenu=13;
  1979.             if(mainmenu==10)mainmenu=5;
  1980.             if(mainmenu==100){
  1981.                 mainmenu=5;
  1982.                 gameon=0;
  1983.                 winfreeze=0;
  1984.             }
  1985.             mainmenutogglekeydown=1;
  1986.         }
  1987.         if(!IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)){
  1988.             mainmenutogglekeydown=0;
  1989.         }
  1990.     }
  1991.  
  1992.     /*static bool minimaptogglekeydown;
  1993.     if(IsKeyDown(theKeyMap, MAC_TAB_KEY)&&!minimaptogglekeydown){
  1994.     minimap=1-minimap;
  1995.     minimaptogglekeydown=1;
  1996.     }
  1997.     if(!IsKeyDown(theKeyMap, MAC_TAB_KEY)){
  1998.     minimaptogglekeydown=0;
  1999.     }
  2000.     */
  2001.  
  2002.     static bool minimaptogglekeydown;
  2003.     if(IsKeyDown(theKeyMap, MAC_TAB_KEY)&&!minimaptogglekeydown&&tutoriallevel){
  2004.         if(tutorialstage!=51)
  2005.             tutorialstagetime=tutorialmaxtime;
  2006.         PlaySoundEx( consolefailsound, samp[consolefailsound], NULL, TRUE);
  2007.         FSOUND_SetVolume(channels[consolefailsound], 128);
  2008.         FSOUND_SetPaused(channels[consolefailsound], FALSE);
  2009.         minimaptogglekeydown=1;
  2010.     }
  2011.     if(!IsKeyDown(theKeyMap, MAC_TAB_KEY)){
  2012.         minimaptogglekeydown=0;
  2013.     }
  2014.  
  2015.     if(mainmenu){
  2016.         //menu buttons
  2017.         if(mainmenu==1||mainmenu==2){
  2018.             if(Button()&&!oldbutton&&selected==1){
  2019.                 if(!gameon){
  2020.                     float gLoc[3]={0,0,0};
  2021.                     float vel[3]={0,0,0};
  2022.                     FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);  
  2023.                     PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
  2024.                     FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  2025.                     FSOUND_SetVolume(channels[firestartsound], 256);
  2026.                     FSOUND_SetPaused(channels[firestartsound], FALSE);
  2027.                     FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);  
  2028.  
  2029.                     flashr=1;
  2030.                     flashg=0;
  2031.                     flashb=0;
  2032.                     flashamount=1;
  2033.                     flashdelay=1;
  2034.  
  2035.                     //new game
  2036.                     if(accountactive!=-1)mainmenu=5;
  2037.                     else mainmenu=7;
  2038.                     /*
  2039.                     startbonustotal=0;
  2040.  
  2041.                     loading=2;
  2042.                     loadtime=0;
  2043.                     if(firstload)TickOnceAfter();
  2044.                     if(!firstload)LoadStuff();
  2045.                     else {
  2046.                     Loadlevel(0);
  2047.                     }
  2048.                     mainmenu=0;
  2049.                     gameon=1;
  2050.                     FSOUND_SetPaused(channels[music3], TRUE);   */         
  2051.                 }
  2052.                 else
  2053.                 {
  2054.                     //resume
  2055.                     mainmenu=0;
  2056.                     FSOUND_SetPaused(channels[stream_music3], TRUE);
  2057.                     FSOUND_SetPaused(channels[music1], FALSE);
  2058.                 }
  2059.             }
  2060.  
  2061.             if(Button()&&!oldbutton&&selected==2){
  2062.                 float gLoc[3]={0,0,0};
  2063.                 float vel[3]={0,0,0};
  2064.                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);  
  2065.                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
  2066.                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  2067.                 FSOUND_SetVolume(channels[firestartsound], 256);
  2068.                 FSOUND_SetPaused(channels[firestartsound], FALSE);
  2069.                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);  
  2070.  
  2071.                 flashr=1;
  2072.                 flashg=0;
  2073.                 flashb=0;
  2074.                 flashamount=1;
  2075.                 flashdelay=1;
  2076.  
  2077.                 //options
  2078.  
  2079.                 mainmenu=3;        
  2080.  
  2081.                 if(newdetail>2)newdetail=detail;
  2082.                 if(newdetail<0)newdetail=detail;
  2083.                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
  2084.                 if(newscreenwidth<0)newscreenwidth=screenwidth;
  2085.                 if(newscreenheight>3000)newscreenheight=screenheight;
  2086.                 if(newscreenheight<0)newscreenheight=screenheight; 
  2087.             }
  2088.  
  2089.             if(Button()&&!oldbutton&&selected==3){
  2090.                 float gLoc[3]={0,0,0};
  2091.                 float vel[3]={0,0,0};
  2092.                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  2093.                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
  2094.                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  2095.                 FSOUND_SetVolume(channels[fireendsound], 256);
  2096.                 FSOUND_SetPaused(channels[fireendsound], FALSE);
  2097.                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  2098.  
  2099.                 flashr=1;
  2100.                 flashg=0;
  2101.                 flashb=0;
  2102.                 flashamount=1;
  2103.                 flashdelay=1;
  2104.  
  2105.                 if(!gameon){
  2106.                     //quit
  2107.                     tryquit=1;
  2108.                     if(registered)FSOUND_SetPaused(channels[stream_music3], TRUE);
  2109.                 }
  2110.                 else{
  2111.                     //end game
  2112.                     gameon=0;
  2113.                     mainmenu=1;
  2114.                 }
  2115.             }
  2116.             if(Button())oldbutton=1;
  2117.             else oldbutton=0;
  2118.         }
  2119.  
  2120.         if(mainmenu==3){
  2121.             if(Button()&&!oldbutton&&selected!=-1){
  2122.                 float gLoc[3]={0,0,0};
  2123.                 float vel[3]={0,0,0};
  2124.                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);  
  2125.                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
  2126.                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  2127.                 FSOUND_SetVolume(channels[firestartsound], 256);
  2128.                 FSOUND_SetPaused(channels[firestartsound], FALSE);
  2129.                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);  
  2130.             }
  2131.             if(Button()&&!oldbutton&&selected==0){
  2132.                 #if USE_SDL
  2133.                 extern SDL_Rect **resolutions;
  2134.                 bool isCustomResolution = true;
  2135.                 bool found = false;
  2136.                 for (int i = 0; (!found) && (resolutions[i]); i++)
  2137.                 {
  2138.                     if ((resolutions[i]->w == screenwidth) && (resolutions[i]->h == screenwidth))
  2139.                         isCustomResolution = false;
  2140.  
  2141.                     if ((resolutions[i]->w == newscreenwidth) && (resolutions[i]->h == newscreenheight))
  2142.                     {
  2143.                         i++;
  2144.                         if (resolutions[i] != NULL)
  2145.                         {
  2146.                             newscreenwidth = (int) resolutions[i]->w;
  2147.                             newscreenheight = (int) resolutions[i]->h;
  2148.                         }
  2149.                         else if (isCustomResolution)
  2150.                         {
  2151.                             if ((screenwidth == newscreenwidth) && (screenheight == newscreenheight))
  2152.                             {
  2153.                                 newscreenwidth = (int) resolutions[0]->w;
  2154.                                 newscreenheight = (int) resolutions[0]->h;
  2155.                             }
  2156.                             else
  2157.                             {
  2158.                                 newscreenwidth = screenwidth;
  2159.                                 newscreenheight = screenheight;
  2160.                             }
  2161.                         }
  2162.                         else
  2163.                         {
  2164.                             newscreenwidth = (int) resolutions[0]->w;
  2165.                             newscreenheight = (int) resolutions[0]->h;
  2166.                         }
  2167.                         found = true;
  2168.                     }
  2169.                 }
  2170.  
  2171.                 if (!found)
  2172.                 {
  2173.                     newscreenwidth = (int) resolutions[0]->w;
  2174.                     newscreenheight = (int) resolutions[0]->h;
  2175.                 }
  2176.  
  2177.                 #else
  2178.                 int whichres;
  2179.                 whichres=-1;
  2180.                 if(newscreenwidth==640&&newscreenheight==480)whichres=0;
  2181.                 if(newscreenwidth==800&&newscreenheight==600)whichres=1;
  2182.                 if(newscreenwidth==1024&&newscreenheight==768)whichres=2;
  2183.                 if(newscreenwidth==1280&&newscreenheight==1024)whichres=3;
  2184.                 if(newscreenwidth==1600&&newscreenheight==1200)whichres=4;
  2185.                 if(newscreenwidth==840&&newscreenheight==524)whichres=5;
  2186.                 if(newscreenwidth==1024&&newscreenheight==640)whichres=6;
  2187.                 if(newscreenwidth==1344&&newscreenheight==840)whichres=7;
  2188.                 if(newscreenwidth==1920&&newscreenheight==1200)whichres=8;
  2189.  
  2190.                 if(whichres==-1||whichres==8){
  2191.                     newscreenwidth=640;
  2192.                     newscreenheight=480;
  2193.                 }
  2194.                 if(whichres==0){
  2195.                     newscreenwidth=800;
  2196.                     newscreenheight=600;
  2197.                 }
  2198.                 if(whichres==1){
  2199.                     newscreenwidth=1024;
  2200.                     newscreenheight=768;
  2201.                 }
  2202.                 if(whichres==2){
  2203.                     newscreenwidth=1280;
  2204.                     newscreenheight=1024;
  2205.                 }
  2206.                 if(whichres==3){
  2207.                     newscreenwidth=1600;
  2208.                     newscreenheight=1200;
  2209.                 }
  2210.                 if(whichres==4){
  2211.                     newscreenwidth=840;
  2212.                     newscreenheight=524;
  2213.                 }
  2214.                 if(whichres==5){
  2215.                     newscreenwidth=1024;
  2216.                     newscreenheight=640;
  2217.                 }
  2218.                 if(whichres==6){
  2219.                     newscreenwidth=1344;
  2220.                     newscreenheight=840;
  2221.                 }
  2222.                 if(whichres==7){
  2223.                     newscreenwidth=1920;
  2224.                     newscreenheight=1200;
  2225.                 }
  2226.                 #endif
  2227.             }
  2228.             if(Button()&&!oldbutton&&selected==1){
  2229.                 newdetail++;
  2230.                 if(newdetail>2)newdetail=0;
  2231.             }
  2232.             if(Button()&&!oldbutton&&selected==2){
  2233.                 bloodtoggle++;
  2234.                 if(bloodtoggle>2)bloodtoggle=0;
  2235.             }
  2236.             if(Button()&&!oldbutton&&selected==3){
  2237.                 difficulty++;
  2238.                 if(difficulty>2)difficulty=0;
  2239.             }
  2240.             if(Button()&&!oldbutton&&selected==4){
  2241.                 ismotionblur=1-ismotionblur;
  2242.             }
  2243.             if(Button()&&!oldbutton&&selected==5){
  2244.                 decals=1-decals;
  2245.             }
  2246.             if(Button()&&!oldbutton&&selected==6){
  2247.                 musictoggle=1-musictoggle;
  2248.  
  2249.                 if(!musictoggle){
  2250.                     FSOUND_SetPaused(channels[music1], TRUE);
  2251.                     FSOUND_SetPaused(channels[stream_music2], TRUE);
  2252.                     FSOUND_SetPaused(channels[stream_music3], TRUE);
  2253.  
  2254.                     for(i=0;i<4;i++){
  2255.                         oldmusicvolume[i]=0;
  2256.                         musicvolume[i]=0;
  2257.                     }
  2258.                 }
  2259.  
  2260.                 if(musictoggle){
  2261.                     PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
  2262.                     FSOUND_SetPaused(channels[stream_music3], FALSE);
  2263.                     FSOUND_SetVolume(channels[stream_music3], 256);            
  2264.                 }
  2265.             }
  2266.             if(Button()&&!oldbutton&&selected==9){
  2267.                 invertmouse=1-invertmouse;
  2268.             }
  2269.             if(Button()&&!oldbutton&&selected==10){
  2270.                 usermousesensitivity+=.2;
  2271.                 if(usermousesensitivity>2)usermousesensitivity=.2;
  2272.             }
  2273.             if(Button()&&!oldbutton&&selected==11){
  2274.                 volume+=.1f;
  2275.                 if(volume>1.0001f)volume=0;
  2276.                 FSOUND_SetSFXMasterVolume((int)(volume*255));
  2277.             }
  2278.             if(Button()&&!oldbutton&&selected==7){
  2279.                 /*float gLoc[3]={0,0,0};
  2280.                 float vel[3]={0,0,0};
  2281.                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);  
  2282.                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
  2283.                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  2284.                 FSOUND_SetVolume(channels[firestartsound], 256);
  2285.                 FSOUND_SetPaused(channels[firestartsound], FALSE);
  2286.                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);  
  2287.                 */
  2288.                 flashr=1;
  2289.                 flashg=0;
  2290.                 flashb=0;
  2291.                 flashamount=1;
  2292.                 flashdelay=1;
  2293.  
  2294.                 //options
  2295.  
  2296.                 mainmenu=4;    
  2297.                 keyselect=-1;
  2298.             }
  2299.             if(Button()&&!oldbutton&&selected==8){
  2300.                 float gLoc[3]={0,0,0};
  2301.                 float vel[3]={0,0,0};
  2302.                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  2303.                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
  2304.                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  2305.                 FSOUND_SetVolume(channels[fireendsound], 256);
  2306.                 FSOUND_SetPaused(channels[fireendsound], FALSE);
  2307.                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  2308.  
  2309.                 flashr=1;
  2310.                 flashg=0;
  2311.                 flashb=0;
  2312.                 flashamount=1;
  2313.                 flashdelay=1;
  2314.  
  2315.                 if(newdetail>2)newdetail=detail;
  2316.                 if(newdetail<0)newdetail=detail;
  2317. #if !USE_SDL  // we'll take anything that works.
  2318.                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
  2319.                 if(newscreenheight>3000)newscreenheight=screenheight;
  2320. #endif
  2321.                 if(newscreenwidth<0)newscreenwidth=screenwidth;
  2322.                 if(newscreenheight<0)newscreenheight=screenheight;
  2323.  
  2324.  
  2325.                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
  2326.                 opstream << "Screenwidth:\n";
  2327.                 opstream << newscreenwidth;
  2328.                 opstream << "\nScreenheight:\n";
  2329.                 opstream << newscreenheight;
  2330.                 opstream << "\nMouse sensitivity:\n";
  2331.                 opstream << usermousesensitivity;
  2332.                 opstream << "\nBlur(0,1):\n";
  2333.                 opstream << ismotionblur;
  2334.                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
  2335.                 opstream << newdetail;
  2336.                 opstream << "\nFloating jump:\n";
  2337.                 opstream << floatjump;
  2338.                 opstream << "\nMouse jump:\n";
  2339.                 opstream << mousejump;
  2340.                 opstream << "\nAmbient sound:\n";
  2341.                 opstream << ambientsound;
  2342.                 opstream << "\nBlood (0,1,2):\n";
  2343.                 opstream << bloodtoggle;
  2344.                 opstream << "\nAuto slomo:\n";
  2345.                 opstream << autoslomo;
  2346.                 opstream << "\nFoliage:\n";
  2347.                 opstream << foliage;
  2348.                 opstream << "\nMusic:\n";
  2349.                 opstream << musictoggle;
  2350.                 opstream << "\nTrilinear:\n";
  2351.                 opstream << trilinear;
  2352.                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
  2353.                 opstream << decals;
  2354.                 opstream << "\nInvert mouse:\n";
  2355.                 opstream << invertmouse;
  2356.                 opstream << "\nGamespeed:\n";
  2357.                 if(oldgamespeed==0)oldgamespeed=1;
  2358.                 opstream << oldgamespeed;
  2359.                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
  2360.                 opstream << difficulty;
  2361.                 opstream << "\nDamage effects(blackout, doublevision):\n";
  2362.                 opstream << damageeffects;
  2363.                 opstream << "\nText:\n";
  2364.                 opstream << texttoggle;
  2365.                 opstream << "\nDebug:\n";
  2366.                 opstream << debugmode;
  2367.                 opstream << "\nVBL Sync:\n";
  2368.                 opstream << vblsync;
  2369.                 opstream << "\nShow Points:\n";
  2370.                 opstream << showpoints;
  2371.                 opstream << "\nAlways Blur:\n";
  2372.                 opstream << alwaysblur;
  2373.                 opstream << "\nImmediate mode (turn on on G5):\n";
  2374.                 opstream << immediate;
  2375.                 opstream << "\nVelocity blur:\n";
  2376.                 opstream << velocityblur;
  2377.                 opstream << "\nVolume:\n";
  2378.                 opstream << volume;
  2379.                 opstream << "\nForward key:\n";
  2380.                 opstream << KeyToChar(forwardkey);
  2381.                 opstream << "\nBack key:\n";
  2382.                 opstream << KeyToChar(backkey);
  2383.                 opstream << "\nLeft key:\n";
  2384.                 opstream << KeyToChar(leftkey);
  2385.                 opstream << "\nRight key:\n";
  2386.                 opstream << KeyToChar(rightkey);
  2387.                 opstream << "\nJump key:\n";
  2388.                 opstream << KeyToChar(jumpkey);
  2389.                 opstream << "\nCrouch key:\n";
  2390.                 opstream << KeyToChar(crouchkey);
  2391.                 opstream << "\nDraw key:\n";
  2392.                 opstream << KeyToChar(drawkey);
  2393.                 opstream << "\nThrow key:\n";
  2394.                 opstream << KeyToChar(throwkey);
  2395.                 opstream << "\nAttack key:\n";
  2396.                 opstream << KeyToChar(attackkey);
  2397.                 opstream << "\nChat key:\n";
  2398.                 opstream << KeyToChar(chatkey);
  2399.                 opstream.close();
  2400.  
  2401.                 if(mainmenu==3&&gameon)mainmenu=2;
  2402.                 if(mainmenu==3&&!gameon)mainmenu=1;
  2403.             }
  2404.             if(Button())oldbutton=1;
  2405.             else oldbutton=0;
  2406.         }
  2407.         if(mainmenu==4){
  2408.             if(Button()&&!oldbutton&&selected!=-1&&keyselect==-1){
  2409.                 float gLoc[3]={0,0,0};
  2410.                 float vel[3]={0,0,0};
  2411.                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);  
  2412.                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
  2413.                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  2414.                 FSOUND_SetVolume(channels[firestartsound], 256);
  2415.                 FSOUND_SetPaused(channels[firestartsound], FALSE);
  2416.                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);  
  2417.             }
  2418.             if(Button()&&!oldbutton&&selected<9&&keyselect==-1){
  2419.                 keyselect=selected;
  2420.                 oldbuttons[0]=1;
  2421.                 oldbuttons[1]=1;
  2422.                 oldbuttons[2]=1;
  2423.             }
  2424.             if(keyselect!=-1){
  2425.                 for(i=0;i<3;i++)
  2426.                     if(!buttons[i]&&!oldbutton&&!Button())oldbuttons[i]=0;
  2427.                 for(i=0;i<140;i++){
  2428.                     if((IsKeyDown(theKeyMap, i)||(buttons[0]&&!oldbuttons[0]&&!oldbutton)||(buttons[1]&&!oldbuttons[1]&&!oldbutton))&&keyselect!=-1){
  2429.                         if(i!=MAC_ESCAPE_KEY&&(strcmp(KeyToChar(i),"unknown")||(buttons[0]&&!oldbuttons[0]&&!oldbutton)||(buttons[1]&&!oldbuttons[1]&&!oldbutton))){
  2430.                             float gLoc[3]={0,0,0};
  2431.                             float vel[3]={0,0,0};
  2432.                             FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  2433.                             PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
  2434.                             FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  2435.                             FSOUND_SetVolume(channels[fireendsound], 256);
  2436.                             FSOUND_SetPaused(channels[fireendsound], FALSE);
  2437.                             FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  2438.  
  2439.                             int keynum;
  2440.                             keynum=i;
  2441.                             if(buttons[0]&&!oldbuttons[0])keynum=MAC_MOUSEBUTTON1;
  2442.                             if(buttons[1]&&!oldbuttons[1])keynum=MAC_MOUSEBUTTON2;
  2443.  
  2444.  
  2445.  
  2446.                             if(keyselect==0)forwardkey=keynum;
  2447.                             if(keyselect==1)backkey=keynum;
  2448.                             if(keyselect==2)leftkey=keynum;
  2449.                             if(keyselect==3)rightkey=keynum;
  2450.                             if(keyselect==4)crouchkey=keynum;
  2451.                             if(keyselect==5)jumpkey=keynum;
  2452.                             if(keyselect==6)drawkey=keynum;
  2453.                             if(keyselect==7)throwkey=keynum;
  2454.                             if(keyselect==8)attackkey=keynum;
  2455.                             keyselect=-1;
  2456.                         }
  2457.                     }
  2458.                 }}
  2459.             if(Button()&&!oldbutton&&selected==9){
  2460.                 float gLoc[3]={0,0,0};
  2461.                 float vel[3]={0,0,0};
  2462.                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  2463.                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
  2464.                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  2465.                 FSOUND_SetVolume(channels[fireendsound], 256);
  2466.                 FSOUND_SetPaused(channels[fireendsound], FALSE);
  2467.                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  2468.  
  2469.                 flashr=1;
  2470.                 flashg=0;
  2471.                 flashb=0;
  2472.                 flashamount=1;
  2473.                 flashdelay=1;
  2474.  
  2475.                 mainmenu=3;
  2476.  
  2477.                 if(newdetail>2)newdetail=detail;
  2478.                 if(newdetail<0)newdetail=detail;
  2479.                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
  2480.                 if(newscreenwidth<0)newscreenwidth=screenwidth;
  2481.                 if(newscreenheight>3000)newscreenheight=screenheight;
  2482.                 if(newscreenheight<0)newscreenheight=screenheight;
  2483.             }
  2484.         }
  2485.  
  2486.         if(mainmenu==5){
  2487.             if(accountcampaignchoicesmade[accountactive]>8&&!registered){
  2488.                 FSOUND_SetFrequency(FSOUND_ALL, 0.001);    
  2489.                 PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
  2490.                 FSOUND_SetPaused(channels[stream_music3], FALSE);
  2491.                 FSOUND_SetVolume(channels[stream_music3], 256);
  2492.  
  2493.                 gameon=0;
  2494.                 mainmenu=12;
  2495.                 accountcampaignchoicesmade[accountactive]=0;
  2496.                 accountcampaignscore[accountactive]=0;
  2497.                 accountcampaigntime[accountactive]=0;
  2498.  
  2499.                 float gLoc[3]={0,0,0};
  2500.                 float vel[3]={0,0,0};
  2501.                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  2502.                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
  2503.                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  2504.                 FSOUND_SetVolume(channels[fireendsound], 256);
  2505.                 FSOUND_SetPaused(channels[fireendsound], FALSE);
  2506.                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  2507.  
  2508.                 flashr=1;
  2509.                 flashg=0;
  2510.                 flashb=0;
  2511.                 flashamount=1;
  2512.                 flashdelay=1;
  2513.             }
  2514.  
  2515.             if(endgame==2){
  2516.                 accountcampaignchoicesmade[accountactive]=0;
  2517.                 accountcampaignscore[accountactive]=0;
  2518.                 accountcampaigntime[accountactive]=0;
  2519.                 endgame=0;
  2520.             }
  2521.  
  2522.             if(Button()&&!oldbutton&&selected==1){         
  2523.                 float gLoc[3]={0,0,0};
  2524.                 float vel[3]={0,0,0};
  2525.                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);  
  2526.                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
  2527.                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  2528.                 FSOUND_SetVolume(channels[firestartsound], 256);
  2529.                 FSOUND_SetPaused(channels[firestartsound], FALSE);
  2530.                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);  
  2531.  
  2532.                 flashr=1;
  2533.                 flashg=0;
  2534.                 flashb=0;
  2535.                 flashamount=1;
  2536.                 flashdelay=1;
  2537.  
  2538.                 startbonustotal=0;
  2539.  
  2540.                 loading=2;
  2541.                 loadtime=0;
  2542.                 targetlevel=-1;
  2543.                 if(firstload)TickOnceAfter();
  2544.                 if(!firstload)LoadStuff();
  2545.                 else {
  2546.                     Loadlevel(-1);
  2547.                 }
  2548.  
  2549.                 mainmenu=0;
  2550.                 gameon=1;
  2551.                 FSOUND_SetPaused(channels[stream_music3], TRUE);
  2552.             }
  2553.             if(Button()&&!oldbutton&&selected-7>=accountcampaignchoicesmade[accountactive]){//selected>=7&&(selected-7<=campaignnumchoices)){          
  2554.                 float gLoc[3]={0,0,0};
  2555.                 float vel[3]={0,0,0};
  2556.                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);  
  2557.                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
  2558.                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  2559.                 FSOUND_SetVolume(channels[firestartsound], 256);
  2560.                 FSOUND_SetPaused(channels[firestartsound], FALSE);
  2561.                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);  
  2562.  
  2563.                 flashr=1;
  2564.                 flashg=0;
  2565.                 flashb=0;
  2566.                 flashamount=1;
  2567.                 flashdelay=1;
  2568.  
  2569.                 startbonustotal=0;
  2570.  
  2571.                 loading=2;
  2572.                 loadtime=0;
  2573.                 targetlevel=7;
  2574.                 if(firstload)TickOnceAfter();
  2575.                 if(!firstload)LoadStuff();
  2576.                 //else {
  2577.                 for(i=0;i<255;i++){
  2578.                     mapname[i]='\0';
  2579.                 }
  2580.                 mapname[0]=':';
  2581.                 mapname[1]='D';
  2582.                 mapname[2]='a';
  2583.                 mapname[3]='t';
  2584.                 mapname[4]='a';
  2585.                 mapname[5]=':';
  2586.                 mapname[6]='M';
  2587.                 mapname[7]='a';
  2588.                 mapname[8]='p';
  2589.                 mapname[9]='s';
  2590.                 mapname[10]=':';
  2591.                 strcat(mapname,campaignmapname[campaignchoicewhich[selected-7-accountcampaignchoicesmade[accountactive]]]);
  2592.                 whichchoice=selected-7-accountcampaignchoicesmade[accountactive];
  2593.                 visibleloading=1;
  2594.                 stillloading=1;
  2595.                 Loadlevel(mapname);
  2596.                 //Loadlevel(campaignmapname[levelorder[selected-7]]);
  2597.                 //}
  2598.                 campaign=1;
  2599.                 mainmenu=0;
  2600.                 gameon=1;
  2601.                 FSOUND_SetPaused(channels[stream_music3], TRUE);
  2602.             }
  2603.             if(Button()&&!oldbutton&&selected==4){
  2604.                 float gLoc[3]={0,0,0};
  2605.                 float vel[3]={0,0,0};
  2606.                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  2607.                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
  2608.                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  2609.                 FSOUND_SetVolume(channels[fireendsound], 256);
  2610.                 FSOUND_SetPaused(channels[fireendsound], FALSE);
  2611.                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  2612.  
  2613.                 flashr=1;
  2614.                 flashg=0;
  2615.                 flashb=0;
  2616.                 flashamount=1;
  2617.                 flashdelay=1;
  2618.  
  2619.                 if(mainmenu==5&&gameon)mainmenu=2;
  2620.                 if(mainmenu==5&&!gameon)mainmenu=1;
  2621.             }
  2622.             if(Button()&&!oldbutton&&selected==5){
  2623.                 float gLoc[3]={0,0,0};
  2624.                 float vel[3]={0,0,0};
  2625.                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  2626.                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
  2627.                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  2628.                 FSOUND_SetVolume(channels[fireendsound], 256);
  2629.                 FSOUND_SetPaused(channels[fireendsound], FALSE);
  2630.                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  2631.  
  2632.                 flashr=1;
  2633.                 flashg=0;
  2634.                 flashb=0;
  2635.                 flashamount=1;
  2636.                 flashdelay=1;
  2637.  
  2638.                 mainmenu=7;
  2639.             }
  2640.             if(Button()&&!oldbutton&&selected==3){
  2641.                 float gLoc[3]={0,0,0};
  2642.                 float vel[3]={0,0,0};
  2643.                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);  
  2644.                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
  2645.                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  2646.                 FSOUND_SetVolume(channels[firestartsound], 256);
  2647.                 FSOUND_SetPaused(channels[firestartsound], FALSE);
  2648.                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);  
  2649.  
  2650.                 flashr=1;
  2651.                 flashg=0;
  2652.                 flashb=0;
  2653.                 flashamount=1;
  2654.                 flashdelay=1;
  2655.  
  2656.                 mainmenu=6;
  2657.             }
  2658.             if(Button()&&!oldbutton&&selected==2){
  2659.                 float gLoc[3]={0,0,0};
  2660.                 float vel[3]={0,0,0};
  2661.                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);  
  2662.                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
  2663.                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  2664.                 FSOUND_SetVolume(channels[firestartsound], 256);
  2665.                 FSOUND_SetPaused(channels[firestartsound], FALSE);
  2666.                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);  
  2667.  
  2668.                 flashr=1;
  2669.                 flashg=0;
  2670.                 flashb=0;
  2671.                 flashamount=1;
  2672.                 flashdelay=1;
  2673.  
  2674.                 mainmenu=9;
  2675.             }
  2676.             if(Button())oldbutton=1;
  2677.             else oldbutton=0;
  2678.         }
  2679.         if(mainmenu==9){
  2680.             if(Button()&&!oldbutton&&selected<numchallengelevels&&selected>=0&&selected<=accountprogress[accountactive]){          
  2681.                 float gLoc[3]={0,0,0};
  2682.                 float vel[3]={0,0,0};
  2683.                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);  
  2684.                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
  2685.                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  2686.                 FSOUND_SetVolume(channels[firestartsound], 256);
  2687.                 FSOUND_SetPaused(channels[firestartsound], FALSE);
  2688.                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);  
  2689.  
  2690.                 flashr=1;
  2691.                 flashg=0;
  2692.                 flashb=0;
  2693.                 flashamount=1;
  2694.                 flashdelay=1;
  2695.  
  2696.                 startbonustotal=0;
  2697.  
  2698.                 loading=2;
  2699.                 loadtime=0;
  2700.                 targetlevel=selected;
  2701.                 if(firstload)TickOnceAfter();
  2702.                 if(!firstload)LoadStuff();
  2703.                 else {
  2704.                     Loadlevel(selected);
  2705.                 }
  2706.                 campaign=0;
  2707.  
  2708.                 mainmenu=0;
  2709.                 gameon=1;
  2710.                 FSOUND_SetPaused(channels[stream_music3], TRUE);
  2711.             }
  2712.             if(Button()&&!oldbutton&&selected==numchallengelevels){
  2713.                 float gLoc[3]={0,0,0};
  2714.                 float vel[3]={0,0,0};
  2715.                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  2716.                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
  2717.                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  2718.                 FSOUND_SetVolume(channels[fireendsound], 256);
  2719.                 FSOUND_SetPaused(channels[fireendsound], FALSE);
  2720.                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  2721.  
  2722.                 flashr=1;
  2723.                 flashg=0;
  2724.                 flashb=0;
  2725.                 flashamount=1;
  2726.                 flashdelay=1;
  2727.  
  2728.                 mainmenu=5;
  2729.             }
  2730.             if(Button())oldbutton=1;
  2731.             else oldbutton=0;
  2732.         }
  2733.         if(mainmenu==11){
  2734.             if(Button()&&!oldbutton&&selected<numchallengelevels&&selected>=0&&selected<=accountprogress[accountactive]){          
  2735.                 float gLoc[3]={0,0,0};
  2736.                 float vel[3]={0,0,0};
  2737.                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);  
  2738.                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
  2739.                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  2740.                 FSOUND_SetVolume(channels[firestartsound], 256);
  2741.                 FSOUND_SetPaused(channels[firestartsound], FALSE);
  2742.                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);  
  2743.  
  2744.                 flashr=1;
  2745.                 flashg=0;
  2746.                 flashb=0;
  2747.                 flashamount=1;
  2748.                 flashdelay=1;
  2749.  
  2750.                 startbonustotal=0;
  2751.  
  2752.                 loading=2;
  2753.                 loadtime=0;
  2754.                 targetlevel=selected;
  2755.                 if(firstload)TickOnceAfter();
  2756.                 if(!firstload)LoadStuff();
  2757.                 else {
  2758.                     Loadlevel(selected);
  2759.                 }
  2760.                 campaign=0;
  2761.  
  2762.                 mainmenu=0;
  2763.                 gameon=1;
  2764.                 FSOUND_SetPaused(channels[stream_music3], TRUE);
  2765.             }
  2766.             if(Button()&&!oldbutton&&selected==numchallengelevels){
  2767.                 float gLoc[3]={0,0,0};
  2768.                 float vel[3]={0,0,0};
  2769.                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  2770.                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
  2771.                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  2772.                 FSOUND_SetVolume(channels[fireendsound], 256);
  2773.                 FSOUND_SetPaused(channels[fireendsound], FALSE);
  2774.                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  2775.  
  2776.                 flashr=1;
  2777.                 flashg=0;
  2778.                 flashb=0;
  2779.                 flashamount=1;
  2780.                 flashdelay=1;
  2781.  
  2782.                 mainmenu=5;
  2783.             }
  2784.             if(Button())oldbutton=1;
  2785.             else oldbutton=0;
  2786.         }
  2787.         if(mainmenu==10){
  2788.             endgame=2;
  2789.             if(Button()&&!oldbutton&&selected==3){
  2790.                 float gLoc[3]={0,0,0};
  2791.                 float vel[3]={0,0,0};
  2792.                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  2793.                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
  2794.                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  2795.                 FSOUND_SetVolume(channels[fireendsound], 256);
  2796.                 FSOUND_SetPaused(channels[fireendsound], FALSE);
  2797.                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  2798.  
  2799.                 flashr=1;
  2800.                 flashg=0;
  2801.                 flashb=0;
  2802.                 flashamount=1;
  2803.                 flashdelay=1;
  2804.  
  2805.                 mainmenu=5;
  2806.             }
  2807.             if(Button())oldbutton=1;
  2808.             else oldbutton=0;
  2809.         }
  2810.  
  2811.         if(mainmenu==15||mainmenu==16){
  2812.             if(Button()&&!oldbutton&&selected==1){
  2813.                 float gLoc[3]={0,0,0};
  2814.                 float vel[3]={0,0,0};
  2815.                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  2816.                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
  2817.                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  2818.                 FSOUND_SetVolume(channels[fireendsound], 256);
  2819.                 FSOUND_SetPaused(channels[fireendsound], FALSE);
  2820.                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  2821.  
  2822.                 flashr=1;
  2823.                 flashg=0;
  2824.                 flashb=0;
  2825.                 flashamount=1;
  2826.                 flashdelay=1;
  2827.  
  2828.                 if(mainmenu==15)mainmenu=5;
  2829.                 else mainmenu=12;
  2830.             }
  2831.             if(Button())oldbutton=1;
  2832.             else oldbutton=0;
  2833.         }
  2834.  
  2835.         if(mainmenu==12){
  2836.             endgame=2;
  2837.             if(Button()&&!oldbutton&&selected==3){
  2838.                 if(tryquit)quit=1;
  2839.                 float gLoc[3]={0,0,0};
  2840.                 float vel[3]={0,0,0};
  2841.                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  2842.                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
  2843.                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  2844.                 FSOUND_SetVolume(channels[fireendsound], 256);
  2845.                 FSOUND_SetPaused(channels[fireendsound], FALSE);
  2846.                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  2847.  
  2848.                 flashr=1;
  2849.                 flashg=0;
  2850.                 flashb=0;
  2851.                 flashamount=1;
  2852.                 flashdelay=1;
  2853.  
  2854.                 mainmenu=5;
  2855.             }
  2856.  
  2857.             if(Button()&&!oldbutton&&selected==4){
  2858.                 registernow=1;
  2859.                 quit=1;
  2860.                 float gLoc[3]={0,0,0};
  2861.                 float vel[3]={0,0,0};
  2862.                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  2863.                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
  2864.                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  2865.                 FSOUND_SetVolume(channels[fireendsound], 256);
  2866.                 FSOUND_SetPaused(channels[fireendsound], FALSE);
  2867.                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  2868.  
  2869.                 flashr=1;
  2870.                 flashg=0;
  2871.                 flashb=0;
  2872.                 flashamount=1;
  2873.                 flashdelay=1;
  2874.             }
  2875.  
  2876.  
  2877.             if(Button()&&!oldbutton&&selected==5){
  2878.                 tryquit=0;
  2879.                 float gLoc[3]={0,0,0};
  2880.                 float vel[3]={0,0,0};
  2881.                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  2882.                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
  2883.                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  2884.                 FSOUND_SetVolume(channels[fireendsound], 256);
  2885.                 FSOUND_SetPaused(channels[fireendsound], FALSE);
  2886.                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  2887.  
  2888.                 flashr=1;
  2889.                 flashg=0;
  2890.                 flashb=0;
  2891.                 flashamount=1;
  2892.                 flashdelay=1;
  2893.  
  2894.                 mainmenu=13;
  2895.             }
  2896.             if(Button())oldbutton=1;
  2897.             else oldbutton=0;
  2898.         }
  2899.         if(mainmenu==6){
  2900.             if(Button()&&!oldbutton&&selected!=-1){
  2901.                 float gLoc[3]={0,0,0};
  2902.                 float vel[3]={0,0,0};
  2903.                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);  
  2904.                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
  2905.                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  2906.                 FSOUND_SetVolume(channels[firestartsound], 256);
  2907.                 FSOUND_SetPaused(channels[firestartsound], FALSE);
  2908.                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);  
  2909.             }
  2910.             if(Button()&&!oldbutton&&selected==1){
  2911.                 float gLoc[3]={0,0,0};
  2912.                 float vel[3]={0,0,0};
  2913.                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  2914.                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
  2915.                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  2916.                 FSOUND_SetVolume(channels[fireendsound], 256);
  2917.                 FSOUND_SetPaused(channels[fireendsound], FALSE);
  2918.                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  2919.  
  2920.                 flashr=1;
  2921.                 flashg=0;
  2922.                 flashb=0;
  2923.                 flashamount=1;
  2924.                 flashdelay=1;
  2925.  
  2926.                 for(i=accountactive;i<numaccounts-1;i++){
  2927.                     accountdifficulty[i]=accountdifficulty[i+1];
  2928.                     accountcampaignchoicesmade[i]=accountcampaignchoicesmade[i+1];
  2929.                     for(j=0;j<accountcampaignchoicesmade[i+1];j++){
  2930.                         accountcampaignchoices[i][j]=accountcampaignchoices[i+1][j];
  2931.                     }
  2932.                     accountpoints[i]=accountpoints[i+1];
  2933.                     for(j=0;j<50;j++){
  2934.                         accounthighscore[i][j]=accounthighscore[i+1][j];
  2935.                         accountfasttime[i][j]=accountfasttime[i+1][j];
  2936.                     }
  2937.                     for(j=0;j<60;j++){
  2938.                         accountunlocked[i][j]=accountunlocked[i+1][j];
  2939.                     }
  2940.                     for(j=0;j<256;j++){
  2941.                         accountname[i][j]=accountname[i+1][j];
  2942.                     }
  2943.                     accountcampaignhighscore[i]=accountcampaignhighscore[i+1];
  2944.                     accountprogress[i]=accountprogress[i+1];
  2945.                     accountcampaignfasttime[i]=accountcampaignfasttime[i+1];
  2946.                     accountcampaignscore[i]=accountcampaignscore[i+1];
  2947.                     accountcampaigntime[i]=accountcampaigntime[i+1];
  2948.                 }
  2949.  
  2950.                 numaccounts--;
  2951.                 accountactive=-1;
  2952.  
  2953.  
  2954.                 mainmenu=7;
  2955.             }
  2956.             if(Button()&&!oldbutton&&selected==2){
  2957.                 float gLoc[3]={0,0,0};
  2958.                 float vel[3]={0,0,0};
  2959.                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  2960.                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
  2961.                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  2962.                 FSOUND_SetVolume(channels[fireendsound], 256);
  2963.                 FSOUND_SetPaused(channels[fireendsound], FALSE);
  2964.                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  2965.  
  2966.                 flashr=1;
  2967.                 flashg=0;
  2968.                 flashb=0;
  2969.                 flashamount=1;
  2970.                 flashdelay=1;
  2971.  
  2972.                 mainmenu=5;
  2973.             }
  2974.             if(Button())oldbutton=1;
  2975.             else oldbutton=0;
  2976.         }
  2977.         if(mainmenu==7){
  2978.             if(Button()&&!oldbutton&&selected!=-1){
  2979.                 float gLoc[3]={0,0,0};
  2980.                 float vel[3]={0,0,0};
  2981.                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);  
  2982.                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
  2983.                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  2984.                 FSOUND_SetVolume(channels[firestartsound], 256);
  2985.                 FSOUND_SetPaused(channels[firestartsound], FALSE);
  2986.                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);  
  2987.             }
  2988.             if(Button()&&!oldbutton&&selected==0&&numaccounts<8){
  2989.                 entername=1;
  2990.             }
  2991.             if(Button()&&!oldbutton&&selected>0&&selected<numaccounts+1){
  2992.                 accountactive=selected-1;
  2993.                 mainmenu=5;
  2994.                 flashr=1;
  2995.                 flashg=0;
  2996.                 flashb=0;
  2997.                 flashamount=1;
  2998.                 flashdelay=1;
  2999.             }
  3000.             if(Button()&&!oldbutton&&selected==numaccounts+1){
  3001.                 float gLoc[3]={0,0,0};
  3002.                 float vel[3]={0,0,0};
  3003.                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  3004.                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
  3005.                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  3006.                 FSOUND_SetVolume(channels[fireendsound], 256);
  3007.                 FSOUND_SetPaused(channels[fireendsound], FALSE);
  3008.                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  3009.  
  3010.                 flashr=1;
  3011.                 flashg=0;
  3012.                 flashb=0;
  3013.                 flashamount=1;
  3014.                 flashdelay=1;
  3015.  
  3016.                 mainmenu=1;
  3017.  
  3018.                 for(j=0;j<255;j++){
  3019.                     displaytext[0][j]=' ';
  3020.                 }
  3021.                 displaychars[0]=0;
  3022.                 displayselected=0;
  3023.                 entername=0;
  3024.             }
  3025.             if(Button())oldbutton=1;
  3026.             else oldbutton=0;
  3027.         }
  3028.         if(mainmenu==8){
  3029.             if(Button()&&!oldbutton&&selected!=-1){
  3030.                 float gLoc[3]={0,0,0};
  3031.                 float vel[3]={0,0,0};
  3032.                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);  
  3033.                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
  3034.                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  3035.                 FSOUND_SetVolume(channels[firestartsound], 256);
  3036.                 FSOUND_SetPaused(channels[firestartsound], FALSE);
  3037.                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);  
  3038.  
  3039.                 if(selected==0)accountdifficulty[accountactive]=0;
  3040.                 if(selected==1)accountdifficulty[accountactive]=1;
  3041.                 if(selected==2)accountdifficulty[accountactive]=2;
  3042.  
  3043.                 mainmenu=5;
  3044.  
  3045.                 flashr=1;
  3046.                 flashg=0;
  3047.                 flashb=0;
  3048.                 flashamount=1;
  3049.                 flashdelay=1;
  3050.  
  3051.             }
  3052.             if(Button())oldbutton=1;
  3053.             else oldbutton=0;
  3054.         }
  3055.  
  3056.  
  3057.         if(Button())oldbutton=1;
  3058.         else oldbutton=0;
  3059.  
  3060.         if(IsKeyDown(theKeyMap, MAC_Q_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)){
  3061.             tryquit=1;
  3062.             if(mainmenu==3){
  3063.                 if(newdetail>2)newdetail=detail;
  3064.                 if(newdetail<0)newdetail=detail;
  3065. #if !USE_SDL  // we'll take anything that works.
  3066.                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
  3067.                 if(newscreenheight>3000)newscreenheight=screenheight;
  3068. #endif
  3069.                 if(newscreenwidth<0)newscreenwidth=screenwidth;
  3070.                 if(newscreenheight<0)newscreenheight=screenheight;
  3071.  
  3072.                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
  3073.                 opstream << "Screenwidth:\n";
  3074.                 opstream << newscreenwidth;
  3075.                 opstream << "\nScreenheight:\n";
  3076.                 opstream << newscreenheight;
  3077.                 opstream << "\nMouse sensitivity:\n";
  3078.                 opstream << usermousesensitivity;
  3079.                 opstream << "\nBlur(0,1):\n";
  3080.                 opstream << ismotionblur;
  3081.                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
  3082.                 opstream << newdetail;
  3083.                 opstream << "\nFloating jump:\n";
  3084.                 opstream << floatjump;
  3085.                 opstream << "\nMouse jump:\n";
  3086.                 opstream << mousejump;
  3087.                 opstream << "\nAmbient sound:\n";
  3088.                 opstream << ambientsound;
  3089.                 opstream << "\nBlood (0,1,2):\n";
  3090.                 opstream << bloodtoggle;
  3091.                 opstream << "\nAuto slomo:\n";
  3092.                 opstream << autoslomo;
  3093.                 opstream << "\nFoliage:\n";
  3094.                 opstream << foliage;
  3095.                 opstream << "\nMusic:\n";
  3096.                 opstream << musictoggle;
  3097.                 opstream << "\nTrilinear:\n";
  3098.                 opstream << trilinear;
  3099.                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
  3100.                 opstream << decals;
  3101.                 opstream << "\nInvert mouse:\n";
  3102.                 opstream << invertmouse;
  3103.                 opstream << "\nGamespeed:\n";
  3104.                 if(oldgamespeed==0)oldgamespeed=1;
  3105.                 opstream << oldgamespeed;
  3106.                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
  3107.                 opstream << difficulty;
  3108.                 opstream << "\nDamage effects(blackout, doublevision):\n";
  3109.                 opstream << damageeffects;
  3110.                 opstream << "\nText:\n";
  3111.                 opstream << texttoggle;
  3112.                 opstream << "\nDebug:\n";
  3113.                 opstream << debugmode;
  3114.                 opstream << "\nVBL Sync:\n";
  3115.                 opstream << vblsync;
  3116.                 opstream << "\nShow Points:\n";
  3117.                 opstream << showpoints;
  3118.                 opstream << "\nAlways Blur:\n";
  3119.                 opstream << alwaysblur;
  3120.                 opstream << "\nImmediate mode (turn on on G5):\n";
  3121.                 opstream << immediate;
  3122.                 opstream << "\nVelocity blur:\n";
  3123.                 opstream << velocityblur;
  3124.                 opstream << "\nVolume:\n";
  3125.                 opstream << volume;
  3126.                 opstream << "\nForward key:\n";
  3127.                 opstream << KeyToChar(forwardkey);
  3128.                 opstream << "\nBack key:\n";
  3129.                 opstream << KeyToChar(backkey);
  3130.                 opstream << "\nLeft key:\n";
  3131.                 opstream << KeyToChar(leftkey);
  3132.                 opstream << "\nRight key:\n";
  3133.                 opstream << KeyToChar(rightkey);
  3134.                 opstream << "\nJump key:\n";
  3135.                 opstream << KeyToChar(jumpkey);
  3136.                 opstream << "\nCrouch key:\n";
  3137.                 opstream << KeyToChar(crouchkey);
  3138.                 opstream << "\nDraw key:\n";
  3139.                 opstream << KeyToChar(drawkey);
  3140.                 opstream << "\nThrow key:\n";
  3141.                 opstream << KeyToChar(throwkey);
  3142.                 opstream << "\nAttack key:\n";
  3143.                 opstream << KeyToChar(attackkey);
  3144.                 opstream << "\nChat key:\n";
  3145.                 opstream << KeyToChar(chatkey);
  3146.                 opstream.close();
  3147.             }
  3148.         }
  3149.  
  3150.         if(mainmenu==1||mainmenu==2){
  3151.             if(loaddistrib>4)transition+=multiplier/8;
  3152.             if(transition>1){
  3153.                 transition=0;
  3154.                 anim++;
  3155.                 if(anim>4)anim=0;
  3156.                 loaddistrib=0;
  3157.             }
  3158.         }
  3159.         FSOUND_SetFrequency(channels[stream_music3], 22050);       
  3160.  
  3161.         if(entername||mainmenu==13||mainmenu==14){
  3162.             for(i=0;i<140;i++){
  3163.                 if(IsKeyDown(theKeyMap, i)){
  3164.                     togglekeydelay[i]+=multiplier;
  3165.                     if(togglekeydelay[i]>.4){
  3166.                         togglekey[i]=0;
  3167.                         togglekeydelay[i]=.36;
  3168.                     }
  3169.                     if(!togglekey[i]){
  3170.                         if(KeyToSingleChar(i)!='\0'&&displaychars[0]<60){
  3171.                             for(j=255;j>=displayselected+1;j--){
  3172.                                 displaytext[0][j]=displaytext[0][j-1];
  3173.                             }
  3174.                             displaytext[0][displayselected]=KeyToSingleChar(i);
  3175.                             if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))displaytext[0][displayselected]=Shift(displaytext[0][displayselected]);
  3176.                             displayselected++;
  3177.                             displaychars[0]++;
  3178.                         }
  3179.                         if(i==MAC_DELETE_KEY&&displayselected!=0){
  3180.                             for(j=displayselected-1;j<255;j++){
  3181.                                 displaytext[0][j]=displaytext[0][j+1];
  3182.                             }
  3183.                             displaytext[0][255]=' ';
  3184.                             displayselected--;
  3185.                             displaychars[0]--;
  3186.                         }
  3187.                         if(i==MAC_ARROW_LEFT_KEY&&displayselected!=0){
  3188.                             displayselected--;
  3189.                         }
  3190.                         if(i==MAC_ARROW_RIGHT_KEY&&displayselected<displaychars[0]){
  3191.                             displayselected++;
  3192.                         }
  3193.                         if(i==MAC_RETURN_KEY&&entername){
  3194.                             if(displaychars[0]){
  3195.                                 numaccounts++;
  3196.                                 strcpy(accountname[numaccounts-1],displaytext[0]);
  3197.                                 accountactive=numaccounts-1;
  3198.                                 accountdifficulty[accountactive]=1;
  3199.                                 accountprogress[accountactive]=0;
  3200.                                 accountpoints[accountactive]=0;
  3201.                                 accountcampaigntime[accountactive]=0;
  3202.                                 accountcampaignscore[accountactive]=0;
  3203.                                 accountcampaignfasttime[accountactive]=0;
  3204.                                 accountcampaignhighscore[accountactive]=0;
  3205.                                 for(j=0;j<50;j++){
  3206.                                     accounthighscore[accountactive][j]=0;
  3207.                                     accountfasttime[accountactive][j]=0;
  3208.                                 }
  3209.                                 for(j=0;j<60;j++){
  3210.                                     accountunlocked[accountactive][j]=0;
  3211.                                 }
  3212.                                 accountcampaignchoicesmade[accountactive]=0;
  3213.  
  3214.                                 for(j=0;j<255;j++){
  3215.                                     displaytext[0][j]=' ';
  3216.                                 }
  3217.                                 displaychars[0]=0;
  3218.                                 displayselected=0;
  3219.                                 entername=0;
  3220.  
  3221.                                 mainmenu=8;
  3222.  
  3223.                                 flashr=1;
  3224.                                 flashg=0;
  3225.                                 flashb=0;
  3226.                                 flashamount=1;
  3227.                                 flashdelay=1;
  3228.  
  3229.                                 float gLoc[3]={0,0,0};
  3230.                                 float vel[3]={0,0,0};
  3231.                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);  
  3232.                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
  3233.                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  3234.                                 FSOUND_SetVolume(channels[firestartsound], 256);
  3235.                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
  3236.                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);  
  3237.  
  3238.                                 for(j=0;j<255;j++){
  3239.                                     displaytext[0][j]=' ';
  3240.                                 }
  3241.                                 displaychars[0]=0;
  3242.  
  3243.  
  3244.                                 displayselected=0;
  3245.                             }}
  3246.  
  3247.                         if(i==MAC_RETURN_KEY&&mainmenu==14){
  3248.                             if(displaychars[0]){
  3249.                                 char serialstring[256];
  3250.                                 char tempstring[256];
  3251.                                 #if defined(__APPLE__)
  3252.                                 sprintf (tempstring, "%s", registrationname);
  3253.                                 #elif defined(_MSC_VER) || defined(__linux__)
  3254.                                 sprintf (tempstring, "%s-windows", registrationname);
  3255.                                 #else
  3256.                                 #error Please make sure you have the right registration key stuff here!
  3257.                                 #endif
  3258.                                 long num1;
  3259.                                 long num2;
  3260.                                 long num3;
  3261.                                 long num4;
  3262.                                 long long longnum;
  3263.                                 longnum = MD5_string ( tempstring);
  3264.                                 //longnum = 1111111111111111;
  3265.                                 num1 = longnum/100000000;
  3266.                                 num2 = longnum%100000000;
  3267.                                 sprintf (tempstring, "%d-%d-%d-%d\0\0\0\0\0", num1/10000, num1%10000, num2/10000, num2%10000);
  3268.  
  3269.                                 int goodcode=3;
  3270.                                 int numchars=3;
  3271.                                 if(num1/10000>999)numchars+=4;
  3272.                                 else if(num1/10000>99)numchars+=3;
  3273.                                 else if(num1/10000>9)numchars+=2;
  3274.                                 else numchars+=1;
  3275.                                 if(num1%10000>999)numchars+=4;
  3276.                                 else if(num1%10000>99)numchars+=3;
  3277.                                 else if(num1%10000>9)numchars+=2;
  3278.                                 else numchars+=1;
  3279.                                 if(num2/10000>999)numchars+=4;
  3280.                                 else if(num2/10000>99)numchars+=3;
  3281.                                 else if(num2/10000>9)numchars+=2;
  3282.                                 else numchars+=1;
  3283.                                 if(num2%10000>999)numchars+=4;
  3284.                                 else if(num2%10000>99)numchars+=3;
  3285.                                 else if(num2%10000>9)numchars+=2;
  3286.                                 else numchars+=1;
  3287.  
  3288.                                 //numchars=12;
  3289.  
  3290.                                 for(j=0;j<numchars;j++){
  3291.                                     if(displaytext[0][j]!=tempstring[j]&&tempstring[j]!=' '&&tempstring[j]!='\0')goodcode--;
  3292.                                 }
  3293.  
  3294.                                 if(longnum==LONGLONGCONST(5077041556214789))goodcode=-1;
  3295.  
  3296.                                 if(goodcode<0)goodcode=0;
  3297.  
  3298.                                 if(goodcode){
  3299.                                     registered=1;
  3300.                                     mainmenu=15;
  3301.  
  3302.                                     FILE            *tfile;
  3303.                                     tfile=fopen( ":Data:Sounds:flame.ogg", "wb" );
  3304.                                     if (tfile)
  3305.                                     {
  3306.                                         int numchars;
  3307.                                         numchars=strlen(registrationname);
  3308.                                         fpackf(tfile, "Bb", registered);
  3309.                                         fpackf(tfile, "Bi", numchars);
  3310.                                         if(numchars>0)
  3311.                                         {
  3312.                                             for(j=0;j<numchars;j++)
  3313.                                             {
  3314.                                                 fpackf(tfile, "Bb",  registrationname[j]);
  3315.                                             }
  3316.                                         }
  3317.                                         fpackf(tfile, "Bi", num1);
  3318.                                         fpackf(tfile, "Bi", num2);
  3319.                                         fclose(tfile);
  3320.                                     }
  3321.                                 }
  3322.                                 else
  3323.                                 {
  3324.                                     mainmenu=16;
  3325.                                 }
  3326.                                 flashr=1;
  3327.                                 flashg=0;
  3328.                                 flashb=0;
  3329.                                 flashamount=1;
  3330.                                 flashdelay=1;
  3331.  
  3332.                                 float gLoc[3]={0,0,0};
  3333.                                 float vel[3]={0,0,0};
  3334.                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);  
  3335.                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
  3336.                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  3337.                                 FSOUND_SetVolume(channels[firestartsound], 256);
  3338.                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
  3339.                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);  
  3340.  
  3341.                                 for(j=0;j<255;j++){
  3342.                                     displaytext[0][j]=' ';
  3343.                                 }
  3344.                                 displaychars[0]=0;
  3345.                                 displayselected=0;
  3346.                             }}
  3347.  
  3348.                         if(i==MAC_RETURN_KEY&&mainmenu==13){
  3349.                             if(displaychars[0]){
  3350.                                 sprintf (registrationname, "%s", displaytext[0]);
  3351.                                 if(displaychars[0]<254)registrationname[displaychars[0]]='\0';
  3352.  
  3353.                                 mainmenu=14;
  3354.  
  3355.                                 flashr=1;
  3356.                                 flashg=0;
  3357.                                 flashb=0;
  3358.                                 flashamount=1;
  3359.                                 flashdelay=1;
  3360.  
  3361.                                 float gLoc[3]={0,0,0};
  3362.                                 float vel[3]={0,0,0};
  3363.                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);  
  3364.                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
  3365.                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  3366.                                 FSOUND_SetVolume(channels[firestartsound], 256);
  3367.                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
  3368.                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);  
  3369.  
  3370.                                 for(j=0;j<255;j++){
  3371.                                     displaytext[0][j]=' ';
  3372.                                 }
  3373.                                 displaychars[0]=0;
  3374.  
  3375.                                 /*char tempstring[50];
  3376.                                 sprintf (tempstring, registrationname);
  3377.                                 long num1;
  3378.                                 long num2;
  3379.                                 long num3;
  3380.                                 long num4;
  3381.                                 long long longnum;
  3382.                                 longnum = MD5_string ( tempstring);
  3383.                                 num1 = longnum/100000000;
  3384.                                 num2 = longnum%100000000;
  3385.                                 sprintf (displaytext[0], "%d-%d-%d-%d", num1/10000, num1%10000, num2/10000, num2%10000);
  3386.  
  3387.                                 displaychars[0]=strlen(displaytext[0]);
  3388.                                 */
  3389.                                 displayselected=0;
  3390.                             }}
  3391.                     }
  3392.                     togglekey[i]=1;
  3393.                 }
  3394.                 else {
  3395.                     togglekey[i]=0;
  3396.                     togglekeydelay[i]=0;
  3397.                 }
  3398.             }
  3399.  
  3400.             displayblinkdelay-=multiplier;
  3401.             if(displayblinkdelay<=0){
  3402.                 displayblinkdelay=.3;
  3403.                 displayblink=1-displayblink;
  3404.             }
  3405.         }
  3406.     }
  3407.  
  3408.     if(!mainmenu){ 
  3409.         if(hostile==1)hostiletime+=multiplier;
  3410.         else hostiletime=0;
  3411.         if(!winfreeze)leveltime+=multiplier;
  3412.         if(IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)){
  3413.             chatting=0;
  3414.             console=0;
  3415.             freeze=0;
  3416.             displaychars[0]=0;
  3417.         }
  3418.  
  3419.         if(IsKeyDown(theKeyMap, chatkey)&&!chattogglekeydown&&!console&&!chatting&&debugmode){
  3420.             chatting=1;
  3421.             chattogglekeydown=1;
  3422.             togglekey[chatkey]=1;
  3423.             togglekeydelay[chatkey]=-20;
  3424.         }
  3425.  
  3426.         if(!IsKeyDown(theKeyMap, chatkey)){
  3427.             chattogglekeydown=0;
  3428.         }
  3429.  
  3430.         if(chatting){
  3431.             for(i=0;i<140;i++){
  3432.                 if(IsKeyDown(theKeyMap, i)){
  3433.                     togglekeydelay[i]+=multiplier;
  3434.                     if(togglekeydelay[i]>.4){
  3435.                         togglekey[i]=0;
  3436.                         togglekeydelay[i]=.36;
  3437.                     }
  3438.                     if(!togglekey[i]){
  3439.                         if(KeyToSingleChar(i)!='\0'&&displaychars[0]<60){
  3440.                             for(j=255;j>=displayselected+1;j--){
  3441.                                 displaytext[0][j]=displaytext[0][j-1];
  3442.                             }
  3443.                             displaytext[0][displayselected]=KeyToSingleChar(i);
  3444.                             if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))displaytext[0][displayselected]=Shift(displaytext[0][displayselected]);
  3445.                             displayselected++;
  3446.                             displaychars[0]++;
  3447.                         }
  3448.                         if(i==MAC_DELETE_KEY&&displayselected!=0){
  3449.                             for(j=displayselected-1;j<255;j++){
  3450.                                 displaytext[0][j]=displaytext[0][j+1];
  3451.                             }
  3452.                             displaytext[0][255]=' ';
  3453.                             displayselected--;
  3454.                             displaychars[0]--;
  3455.                         }
  3456.                         if(i==MAC_ARROW_LEFT_KEY&&displayselected!=0){
  3457.                             displayselected--;
  3458.                         }
  3459.                         if(i==MAC_ARROW_RIGHT_KEY&&displayselected<displaychars[0]){
  3460.                             displayselected++;
  3461.                         }
  3462.                         if(i==MAC_RETURN_KEY){
  3463.                             if(displaychars[0]){
  3464.                                 /*for(j=0;j<displaychars[0];j++){
  3465.                                 talkname[j]=displaytext[0][j];
  3466.                                 }
  3467.                                 talkname[displaychars[0]]='\0';
  3468.                                 sprintf (chatname, "%s: %s",playerName,talkname);
  3469.                                 //NetworkSendInformation(chatname);
  3470.                                 */
  3471.                                 for(j=0;j<255;j++){
  3472.                                     displaytext[0][j]=' ';
  3473.                                 }
  3474.                                 displaychars[0]=0;
  3475.                                 displayselected=0;
  3476.                                 chatting=0;
  3477.                             }
  3478.                         }
  3479.                     }
  3480.                     togglekey[i]=1;
  3481.                 }
  3482.                 else {
  3483.                     togglekey[i]=0;
  3484.                     togglekeydelay[i]=0;
  3485.                 }
  3486.             }
  3487.  
  3488.             displayblinkdelay-=multiplier;
  3489.             if(displayblinkdelay<=0){
  3490.                 displayblinkdelay=.3;
  3491.                 displayblink=1-displayblink;
  3492.             }
  3493.         }
  3494.  
  3495.         if(chatting)keyboardfrozen=1;
  3496.  
  3497.         if(IsKeyDown(theKeyMap, MAC_V_KEY)&&!freezetogglekeydown&&debugmode){
  3498.             freeze=1-freeze;
  3499.             if(freeze){
  3500.                 FSOUND_SetFrequency(FSOUND_ALL, 0.001);
  3501.             }
  3502.             freezetogglekeydown=1;
  3503.         }
  3504.  
  3505.         if(!IsKeyDown(theKeyMap, MAC_V_KEY)&&!IsKeyDown(theKeyMap, MAC_F1_KEY)){
  3506.             freezetogglekeydown=0;
  3507.         }
  3508.  
  3509.         if(IsKeyDown(theKeyMap, MAC_TILDE_KEY)&&!consoletogglekeydown&&debugmode){
  3510.             console=1-console;
  3511.             if(!console)freeze=0;
  3512.             if(console){
  3513.                 FSOUND_SetFrequency(FSOUND_ALL, 0.001);
  3514.             }
  3515.             consoletogglekeydown=1;
  3516.         }
  3517.  
  3518.         if(!IsKeyDown(theKeyMap, MAC_TILDE_KEY)){
  3519.             consoletogglekeydown=0;
  3520.         }
  3521.  
  3522.         if(console)freeze=1;
  3523.  
  3524.         if(console&&!IsKeyDown(theKeyMap,MAC_COMMAND_KEY)){
  3525.             for(i=0;i<140;i++){
  3526.                 if(IsKeyDown(theKeyMap, i)){
  3527.                     togglekeydelay[i]+=multiplier;
  3528.                     if(togglekeydelay[i]>.4){
  3529.                         togglekey[i]=0;
  3530.                         togglekeydelay[i]=.36;
  3531.                     }
  3532.                     if(!togglekey[i]){
  3533.                         if(KeyToSingleChar(i)!='\0'&&consolechars[0]<255){
  3534.                             for(j=255;j>=consoleselected+1;j--){
  3535.                                 consoletext[0][j]=consoletext[0][j-1];
  3536.                             }
  3537.                             consoletext[0][consoleselected]=KeyToSingleChar(i);
  3538.                             if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))consoletext[0][consoleselected]=Shift(consoletext[0][consoleselected]);
  3539.                             consoleselected++;
  3540.                             consolechars[0]++;
  3541.                         }
  3542.                         else if(i==MAC_ENTER_KEY){
  3543.                             for(j=255;j>=consoleselected+1;j--){
  3544.                                 consoletext[0][j]=consoletext[0][j-1];
  3545.                             }
  3546.                             consoletext[0][consoleselected]='\n';
  3547.                             consoleselected++;
  3548.                             consolechars[0]++;
  3549.                         }
  3550.                         if(i==MAC_DELETE_KEY&&consoleselected!=0){
  3551.                             for(j=consoleselected-1;j<255;j++){
  3552.                                 consoletext[0][j]=consoletext[0][j+1];
  3553.                             }
  3554.                             consoletext[0][255]=' ';
  3555.                             consoleselected--;
  3556.                             consolechars[0]--;
  3557.                         }
  3558.                         if(i==MAC_ARROW_UP_KEY){
  3559.                             if(archiveselected<14)archiveselected++;
  3560.                             for(j=0;j<255;j++){
  3561.                                 consolechars[0]=consolechars[archiveselected];
  3562.                                 consoletext[0][j]=consoletext[archiveselected][j];
  3563.                                 consoleselected=consolechars[0];
  3564.                             }
  3565.                         }
  3566.                         if(i==MAC_ARROW_DOWN_KEY){
  3567.                             if(archiveselected>0)archiveselected--;
  3568.                             for(j=0;j<255;j++){
  3569.                                 consolechars[0]=consolechars[archiveselected];
  3570.                                 consoletext[0][j]=consoletext[archiveselected][j];
  3571.                                 consoleselected=consolechars[0];
  3572.                             }
  3573.                         }
  3574.                         if(i==MAC_ARROW_LEFT_KEY&&consoleselected!=0){
  3575.                             consoleselected--;
  3576.                         }
  3577.                         if(i==MAC_ARROW_RIGHT_KEY&&consoleselected<consolechars[0]){
  3578.                             consoleselected++;
  3579.                         }
  3580.                         if(i==MAC_RETURN_KEY){
  3581.                             archiveselected=0;
  3582.                             donesomething=0;
  3583.                             if(Compare(consoletext[0],"quit ",0,4)||Compare(consoletext[0],"exit ",0,4)){
  3584.                                 PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
  3585.                                 FSOUND_SetVolume(channels[consolesuccesssound], 256);
  3586.                                 FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
  3587.                                 donesomething=1;
  3588.                                 tryquit=1;
  3589.                             }
  3590.                             /*if(Compare(consoletext[0],"send ",0,4)){
  3591.                             for(j=5;j<consolechars[0];j++){
  3592.                             talkname[j-5]=consoletext[0][j];
  3593.                             }
  3594.                             talkname[consolechars[0]-5]='\0';
  3595.                             sprintf (chatname, "%s: %s",playerName,talkname);
  3596.                             //NetworkSendInformation(chatname);
  3597.                             donesomething=1;
  3598.                             }
  3599.                             if(Compare(consoletext[0],"name ",0,4)){
  3600.                             int numchars;
  3601.                             numchars=consolechars[0]-5;
  3602.                             if(numchars>32)numchars=32;
  3603.                             for(j=5;j<numchars+5;j++){
  3604.                             talkname[j-5]=consoletext[0][j];
  3605.                             }
  3606.                             talkname[numchars]='\0';
  3607.                             sprintf (chatname, "Player %s is now known as %s.",playerName,talkname);
  3608.                             //NetworkSendInformation(chatname);
  3609.                             sprintf (playerName, "%s",talkname);
  3610.                             //NetworkSendName(playerName);
  3611.                             donesomething=1;
  3612.                             }*/
  3613.                             if(Compare(consoletext[0],"map ",0,3)){
  3614.                                 mapname[0]=':';
  3615.                                 mapname[1]='D';
  3616.                                 mapname[2]='a';
  3617.                                 mapname[3]='t';
  3618.                                 mapname[4]='a';
  3619.                                 mapname[5]=':';
  3620.                                 mapname[6]='M';
  3621.                                 mapname[7]='a';
  3622.                                 mapname[8]='p';
  3623.                                 mapname[9]='s';
  3624.                                 mapname[10]=':';
  3625.                                 for(j=4;j<consolechars[0];j++){
  3626.                                     mapname[j-4+11]=consoletext[0][j];
  3627.                                 }
  3628.                                 mapname[consolechars[0]-4+11]='\0';
  3629.                                 Loadlevel(mapname);
  3630.                                 whichlevel=-2;
  3631.                                 campaign=0;
  3632.                                 donesomething=1;
  3633.                             }
  3634.                             /*if(Compare(consoletext[0],"connect ",0,7)&&!ishost){
  3635.                             int v;
  3636.                             unsigned char playerNameStr[32];
  3637.                             char theIPAddress[256];
  3638.                             char thePort[32];
  3639.                             NMUInt32 port = 25710;
  3640.  
  3641.                             strcpy(playerName, "Client");
  3642.                             GameC2PStr( playerName, playerNameStr );
  3643.  
  3644.                             for(j=0;j<consolechars[0]-8;j++){
  3645.                             theIPAddress[j]=consoletext[0][j+8];
  3646.                             }
  3647.                             theIPAddress[consolechars[0]-8]='\0';
  3648.  
  3649.                             sprintf( thePort, "%li", port );
  3650.                             v=NetworkStartClient( theIPAddress, thePort, playerNameStr );
  3651.                             if(v)
  3652.                             {
  3653.                             if(consolechars[0]>0){
  3654.                             for(k=14;k>=1;k--){
  3655.                             for(j=0;j<255;j++){
  3656.                             consoletext[k][j]=consoletext[k-1][j];
  3657.                             }
  3658.                             consolechars[k]=consolechars[k-1];
  3659.                             }
  3660.                             for(j=0;j<255;j++){
  3661.                             consoletext[0][j]=' ';
  3662.                             }
  3663.                             if(v!=-4994)sprintf (consoletext[0], "Error #%d!!!",v);
  3664.                             else sprintf (consoletext[0], "Could not open connection");
  3665.  
  3666.                             consolechars[0]=255;
  3667.                             consoleselected=0;
  3668.                             }
  3669.                             }
  3670.                             else
  3671.                             {
  3672.                             donesomething=1;
  3673.                             PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
  3674.                             FSOUND_SetVolume(channels[consolesuccesssound], 256);
  3675.                             FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
  3676.  
  3677.                             if(consolechars[0]>0){
  3678.                             for(k=14;k>=1;k--){
  3679.                             for(j=0;j<255;j++){
  3680.                             consoletext[k][j]=consoletext[k-1][j];
  3681.                             }
  3682.                             consolechars[k]=consolechars[k-1];
  3683.                             }
  3684.                             for(j=0;j<255;j++){
  3685.                             consoletext[0][j]=' ';
  3686.                             }
  3687.                             sprintf (consoletext[0], "Connected to %s",theIPAddress);
  3688.  
  3689.                             consolechars[0]=255;
  3690.                             consoleselected=0;
  3691.                             }
  3692.                             }
  3693.                             }
  3694.  
  3695.                             if(Compare(consoletext[0],"host ",0,4)){
  3696.                             unsigned char gameNameStr[32], playerNameStr[32];
  3697.                             char gameName[32];//, playerName[32];
  3698.                             NMUInt32 port;
  3699.                             int players;
  3700.                             int v;
  3701.  
  3702.                             port = 25710;
  3703.                             players =4;
  3704.  
  3705.                             strcpy(gameName, "Host's game");
  3706.                             strcpy(playerName, "Host");
  3707.                             GameC2PStr( gameName, gameNameStr );
  3708.                             GameC2PStr( playerName, playerNameStr );
  3709.  
  3710.                             v=NetworkStartServer( (NMUInt16)port, players, gameNameStr, playerNameStr );
  3711.                             if(v)
  3712.                             {
  3713.                             if(consolechars[0]>0){
  3714.                             for(k=14;k>=1;k--){
  3715.                             for(j=0;j<255;j++){
  3716.                             consoletext[k][j]=consoletext[k-1][j];
  3717.                             }
  3718.                             consolechars[k]=consolechars[k-1];
  3719.                             }
  3720.                             for(j=0;j<255;j++){
  3721.                             consoletext[0][j]=' ';
  3722.                             }
  3723.                             sprintf (consoletext[0], "Error #%d!!!",v);
  3724.  
  3725.                             consolechars[0]=255;
  3726.                             consoleselected=0;
  3727.                             }
  3728.                             }
  3729.                             else
  3730.                             {
  3731.                             donesomething=1;
  3732.                             PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
  3733.                             FSOUND_SetVolume(channels[consolesuccesssound], 256);
  3734.                             FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
  3735.  
  3736.                             if(consolechars[0]>0){
  3737.                             for(k=14;k>=1;k--){
  3738.                             for(j=0;j<255;j++){
  3739.                             consoletext[k][j]=consoletext[k-1][j];
  3740.                             }
  3741.                             consolechars[k]=consolechars[k-1];
  3742.                             }
  3743.                             for(j=0;j<255;j++){
  3744.                             consoletext[0][j]=' ';
  3745.                             }
  3746.                             sprintf (consoletext[0], "Game hosted");
  3747.  
  3748.                             consolechars[0]=255;
  3749.                             consoleselected=0;
  3750.                             }
  3751.                             }
  3752.                             }
  3753.                             */
  3754.                             if(Compare(consoletext[0],"save ",0,4)){
  3755.                                 mapname[0]=':';
  3756.                                 mapname[1]='D';
  3757.                                 mapname[2]='a';
  3758.                                 mapname[3]='t';
  3759.                                 mapname[4]='a';
  3760.                                 mapname[5]=':';
  3761.                                 mapname[6]='M';
  3762.                                 mapname[7]='a';
  3763.                                 mapname[8]='p';
  3764.                                 mapname[9]='s';
  3765.                                 mapname[10]=':';
  3766.                                 for(j=5;j<consolechars[0];j++){
  3767.                                     mapname[j-5+11]=consoletext[0][j];
  3768.                                 }
  3769.                                 mapname[consolechars[0]-5+11]='\0';
  3770.  
  3771.                                 PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
  3772.                                 FSOUND_SetVolume(channels[consolesuccesssound], 256);
  3773.                                 FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
  3774.  
  3775.                                 int mapvers;
  3776.                                 mapvers=12;
  3777.  
  3778.  
  3779.                                 FILE            *tfile;
  3780.                                 tfile=fopen( mapname, "wb" );
  3781.                                 fpackf(tfile, "Bi", mapvers);
  3782.                                 //fpackf(tfile, "Bi", indemo);
  3783.                                 fpackf(tfile, "Bi", maptype);
  3784.                                 fpackf(tfile, "Bi", hostile);
  3785.                                 fpackf(tfile, "Bf Bf", viewdistance, fadestart);
  3786.                                 fpackf(tfile, "Bb Bf Bf Bf", skyboxtexture, skyboxr, skyboxg, skyboxb);
  3787.                                 fpackf(tfile, "Bf Bf Bf", skyboxlightr, skyboxlightg, skyboxlightb);
  3788.                                 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);
  3789.                                 if(player[0].num_weapons>0&&player[0].num_weapons<5)
  3790.                                     for(j=0;j<player[0].num_weapons;j++){
  3791.                                         fpackf(tfile, "Bi", weapons.type[player[0].weaponids[j]]);
  3792.                                     }
  3793.  
  3794.                                     fpackf(tfile, "Bf Bf Bf", player[0].armorhead, player[0].armorhigh, player[0].armorlow);
  3795.                                     fpackf(tfile, "Bf Bf Bf", player[0].protectionhead, player[0].protectionhigh, player[0].protectionlow);
  3796.                                     fpackf(tfile, "Bf Bf Bf", player[0].metalhead, player[0].metalhigh, player[0].metallow);
  3797.                                     fpackf(tfile, "Bf Bf", player[0].power, player[0].speedmult);
  3798.  
  3799.                                     fpackf(tfile, "Bi", player[0].numclothes);
  3800.  
  3801.                                     fpackf(tfile, "Bi Bi", player[0].whichskin, player[0].creature);
  3802.  
  3803.                                     fpackf(tfile, "Bi", numdialogues);
  3804.                                     if(numdialogues)
  3805.                                         for(k=0;k<numdialogues;k++){
  3806.                                             fpackf(tfile, "Bi", numdialogueboxes[k]);
  3807.                                             fpackf(tfile, "Bi", dialoguetype[k]);
  3808.                                             for(l=0;l<10;l++){
  3809.                                                 fpackf(tfile, "Bf Bf Bf", participantlocation[k][l].x, participantlocation[k][l].y, participantlocation[k][l].z);
  3810.                                                 fpackf(tfile, "Bf", participantrotation[k][l]);
  3811.                                             }
  3812.                                             if(numdialogueboxes)
  3813.                                                 for(l=0;l<numdialogueboxes[k];l++){
  3814.                                                     fpackf(tfile, "Bi", dialogueboxlocation[k][l]);
  3815.                                                     fpackf(tfile, "Bf", dialogueboxcolor[k][l][0]);
  3816.                                                     fpackf(tfile, "Bf", dialogueboxcolor[k][l][1]);
  3817.                                                     fpackf(tfile, "Bf", dialogueboxcolor[k][l][2]);
  3818.                                                     fpackf(tfile, "Bi", dialogueboxsound[k][l]);
  3819.  
  3820.                                                     templength=strlen(dialoguetext[k][l]);
  3821.                                                     fpackf(tfile, "Bi",(templength));
  3822.                                                     for(m=0;m<templength;m++){
  3823.                                                         fpackf(tfile, "Bb", dialoguetext[k][l][m]);
  3824.                                                         if(dialoguetext[k][l][m]=='\0')break;
  3825.                                                     }
  3826.  
  3827.                                                     templength=strlen(dialoguename[k][l]);
  3828.                                                     fpackf(tfile, "Bi",templength);
  3829.                                                     for(m=0;m<templength;m++){
  3830.                                                         fpackf(tfile, "Bb", dialoguename[k][l][m]);
  3831.                                                         if(dialoguename[k][l][m]=='\0')break;  
  3832.                                                     }
  3833.  
  3834.                                                     fpackf(tfile, "Bf Bf Bf", dialoguecamera[k][l].x, dialoguecamera[k][l].y, dialoguecamera[k][l].z);
  3835.                                                     fpackf(tfile, "Bi", participantfocus[k][l]);
  3836.                                                     fpackf(tfile, "Bi", participantaction[k][l]);
  3837.  
  3838.                                                     for(m=0;m<10;m++)
  3839.                                                         fpackf(tfile, "Bf Bf Bf", participantfacing[k][l][m].x, participantfacing[k][l][m].y, participantfacing[k][l][m].z);
  3840.  
  3841.                                                     fpackf(tfile, "Bf Bf",dialoguecamerarotation[k][l],dialoguecamerarotation2[k][l]);
  3842.                                                 }
  3843.                                         }
  3844.  
  3845.                                         if(player[0].numclothes)
  3846.                                             for(k=0;k<player[0].numclothes;k++){
  3847.                                                 templength=strlen(player[0].clothes[k]);
  3848.                                                 fpackf(tfile, "Bi", templength);
  3849.                                                 for(l=0;l<templength;l++)
  3850.                                                     fpackf(tfile, "Bb", player[0].clothes[k][l]);
  3851.                                                 fpackf(tfile, "Bf Bf Bf", player[0].clothestintr[k], player[0].clothestintg[k], player[0].clothestintb[k]);                                                                    
  3852.                                             }
  3853.  
  3854.                                             fpackf(tfile, "Bi", environment);
  3855.  
  3856.                                             fpackf(tfile, "Bi", objects.numobjects);
  3857.  
  3858.                                             if(objects.numobjects)
  3859.                                                 for(k=0;k<objects.numobjects;k++){
  3860.                                                     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]);
  3861.                                                 }
  3862.  
  3863.                                                 fpackf(tfile, "Bi", numhotspots);
  3864.                                                 if(numhotspots)
  3865.                                                     for(i=0;i<numhotspots;i++){
  3866.                                                         fpackf(tfile, "Bi Bf Bf Bf Bf", hotspottype[i],hotspotsize[i],hotspot[i].x,hotspot[i].y,hotspot[i].z);
  3867.                                                         templength=strlen(hotspottext[i]);
  3868.                                                         fpackf(tfile, "Bi",templength);
  3869.                                                         for(l=0;l<templength;l++)
  3870.                                                             fpackf(tfile, "Bb", hotspottext[i][l]);
  3871.                                                     }
  3872.  
  3873.                                                     fpackf(tfile, "Bi", numplayers);
  3874.                                                     if(numplayers>1&&numplayers<maxplayers)
  3875.                                                         for(j=1;j<numplayers;j++){
  3876.                                                             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);
  3877.                                                             if(player[j].num_weapons>0&&player[j].num_weapons<5)
  3878.                                                                 for(k=0;k<player[j].num_weapons;k++){
  3879.                                                                     fpackf(tfile, "Bi", weapons.type[player[j].weaponids[k]]);
  3880.                                                                 }
  3881.                                                                 if(player[j].numwaypoints<30){
  3882.                                                                     fpackf(tfile, "Bi", player[j].numwaypoints);
  3883.                                                                     for(k=0;k<player[j].numwaypoints;k++){
  3884.                                                                         fpackf(tfile, "Bf", player[j].waypoints[k].x);
  3885.                                                                         fpackf(tfile, "Bf", player[j].waypoints[k].y);
  3886.                                                                         fpackf(tfile, "Bf", player[j].waypoints[k].z);
  3887.                                                                         fpackf(tfile, "Bi", player[j].waypointtype[k]);
  3888.                                                                     }
  3889.                                                                     fpackf(tfile, "Bi", player[j].waypoint);
  3890.                                                                 }
  3891.                                                                 else{
  3892.                                                                     player[j].numwaypoints=0;
  3893.                                                                     player[j].waypoint=0;
  3894.                                                                     fpackf(tfile, "Bi Bi Bi", player[j].numwaypoints, player[j].waypoint, player[j].waypoint);
  3895.                                                                 }
  3896.  
  3897.                                                                 fpackf(tfile, "Bf Bf Bf", player[j].armorhead, player[j].armorhigh, player[j].armorlow);
  3898.                                                                 fpackf(tfile, "Bf Bf Bf", player[j].protectionhead, player[j].protectionhigh, player[j].protectionlow);
  3899.                                                                 fpackf(tfile, "Bf Bf Bf", player[j].metalhead, player[j].metalhigh, player[j].metallow);
  3900.                                                                 fpackf(tfile, "Bf Bf", player[j].power, player[j].speedmult);
  3901.  
  3902.                                                                 if(player[j].creature==wolftype){
  3903.                                                                     headprop=player[j].proportionhead.x/1.1;
  3904.                                                                     bodyprop=player[j].proportionbody.x/1.1;
  3905.                                                                     armprop=player[j].proportionarms.x/1.1;
  3906.                                                                     legprop=player[j].proportionlegs.x/1.1;
  3907.                                                                 }
  3908.  
  3909.                                                                 if(player[j].creature==rabbittype){
  3910.                                                                     headprop=player[j].proportionhead.x/1.2;
  3911.                                                                     bodyprop=player[j].proportionbody.x/1.05;
  3912.                                                                     armprop=player[j].proportionarms.x/1.00;
  3913.                                                                     legprop=player[j].proportionlegs.x/1.1;
  3914.                                                                 }
  3915.  
  3916.                                                                 fpackf(tfile, "Bf Bf Bf Bf", headprop, bodyprop, armprop, legprop);
  3917.  
  3918.  
  3919.  
  3920.                                                                 fpackf(tfile, "Bi", player[j].numclothes);
  3921.                                                                 if(player[j].numclothes)
  3922.                                                                     for(k=0;k<player[j].numclothes;k++){
  3923.                                                                         int templength;
  3924.                                                                         templength=strlen(player[j].clothes[k]);
  3925.                                                                         fpackf(tfile, "Bi", templength);
  3926.                                                                         for(l=0;l<templength;l++)
  3927.                                                                             fpackf(tfile, "Bb", player[j].clothes[k][l]);
  3928.                                                                         fpackf(tfile, "Bf Bf Bf", player[j].clothestintr[k], player[j].clothestintg[k], player[j].clothestintb[k]);                                                            
  3929.                                                                     }
  3930.                                                         }
  3931.  
  3932.                                                         fpackf(tfile, "Bi", numpathpoints);
  3933.                                                         if(numpathpoints)
  3934.                                                             for(j=0;j<numpathpoints;j++){
  3935.                                                                 fpackf(tfile, "Bf Bf Bf Bi", pathpoint[j].x, pathpoint[j].y, pathpoint[j].z, numpathpointconnect[j]);
  3936.                                                                 for(k=0;k<numpathpointconnect[j];k++){
  3937.                                                                     fpackf(tfile, "Bi", pathpointconnect[j][k]);
  3938.                                                                 }
  3939.                                                             }
  3940.  
  3941.                                                             fpackf(tfile, "Bf Bf Bf Bf", mapcenter.x, mapcenter.y, mapcenter.z, mapradius);
  3942.  
  3943.  
  3944.                                                             fclose(tfile);
  3945.                                                             donesomething=1;
  3946.  
  3947.                                                             /*
  3948.                                                             FILE            *tfile;
  3949.                                                             tfile=fopen( mapname, "wb" );
  3950.                                                             fwrite( &mapvers, 1, sizeof(int), tfile );
  3951.                                                             fwrite( &player[0].coords.x, 1, sizeof(float), tfile );
  3952.                                                             fwrite( &player[0].coords.y, 1, sizeof(float), tfile );
  3953.                                                             fwrite( &player[0].coords.z, 1, sizeof(float), tfile );
  3954.                                                             fwrite( &player[0].rotation, 1, sizeof(float), tfile );
  3955.                                                             fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
  3956.                                                             fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
  3957.                                                             if(player[0].num_weapons>0&&player[0].num_weapons<5)
  3958.                                                             for(j=0;j<player[0].num_weapons;j++){
  3959.                                                             fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
  3960.                                                             }
  3961.  
  3962.                                                             fwrite( &player[0].armorhead, 1, sizeof(int), tfile );
  3963.                                                             fwrite( &player[0].armorhigh, 1, sizeof(int), tfile );
  3964.                                                             fwrite( &player[0].armorlow, 1, sizeof(int), tfile );
  3965.                                                             fwrite( &player[0].protectionhead, 1, sizeof(int), tfile );
  3966.                                                             fwrite( &player[0].protectionhigh, 1, sizeof(int), tfile );
  3967.                                                             fwrite( &player[0].protectionlow, 1, sizeof(int), tfile );
  3968.                                                             fwrite( &player[0].metalhead, 1, sizeof(int), tfile );
  3969.                                                             fwrite( &player[0].metalhigh, 1, sizeof(int), tfile );
  3970.                                                             fwrite( &player[0].metallow, 1, sizeof(int), tfile );
  3971.                                                             fwrite( &player[0].power, 1, sizeof(int), tfile );
  3972.                                                             fwrite( &player[0].speedmult, 1, sizeof(int), tfile );
  3973.  
  3974.                                                             fwrite( &player[0].numclothes, 1, sizeof(int), tfile );
  3975.                                                             if(player[0].numclothes)
  3976.                                                             for(k=0;k<player[0].numclothes;k++){
  3977.                                                             int templength;
  3978.                                                             templength=strlen(player[0].clothes[k]);
  3979.                                                             fwrite( &templength,1,sizeof(int),tfile);  
  3980.                                                             for(l=0;l<templength;l++)
  3981.                                                             fwrite( &player[0].clothes[k][l],1,sizeof(char),tfile);
  3982.                                                             fwrite( &player[0].clothestintr[k],1,sizeof(float),tfile); 
  3983.                                                             fwrite( &player[0].clothestintg[k],1,sizeof(float),tfile); 
  3984.                                                             fwrite( &player[0].clothestintb[k],1,sizeof(float),tfile);                                     
  3985.                                                             }
  3986.  
  3987.                                                             fwrite( &environment, 1, sizeof(int), tfile );
  3988.  
  3989.                                                             fwrite( &objects.numobjects, 1, sizeof(int), tfile );
  3990.  
  3991.                                                             for(k=0;k<objects.numobjects;k++){
  3992.                                                             fwrite( &objects.type[k], 1, sizeof(int), tfile );
  3993.                                                             fwrite( &objects.rotation[k], 1, sizeof(float), tfile );
  3994.                                                             fwrite( &objects.rotation2[k], 1, sizeof(float), tfile );
  3995.                                                             fwrite( &objects.position[k].x, 1, sizeof(float), tfile );
  3996.                                                             fwrite( &objects.position[k].y, 1, sizeof(float), tfile );
  3997.                                                             fwrite( &objects.position[k].z, 1, sizeof(float), tfile );
  3998.                                                             fwrite( &objects.scale[k], 1, sizeof(float), tfile );
  3999.                                                             }
  4000.  
  4001.                                                             fwrite( &numplayers, 1, sizeof(int), tfile );
  4002.                                                             if(numplayers>1&&numplayers<maxplayers)
  4003.                                                             for(j=1;j<numplayers;j++){
  4004.                                                             fwrite( &player[j].whichskin, 1, sizeof(int), tfile );
  4005.                                                             fwrite( &player[j].creature, 1, sizeof(int), tfile );
  4006.                                                             fwrite( &player[j].coords.x, 1, sizeof(float), tfile );
  4007.                                                             fwrite( &player[j].coords.y, 1, sizeof(float), tfile );
  4008.                                                             fwrite( &player[j].coords.z, 1, sizeof(float), tfile );
  4009.                                                             fwrite( &player[j].num_weapons, 1, sizeof(int), tfile );
  4010.                                                             if(player[j].num_weapons>0&&player[j].num_weapons<5)
  4011.                                                             for(k=0;k<player[j].num_weapons;k++){
  4012.                                                             fwrite( &weapons.type[player[j].weaponids[k]], 1, sizeof(int), tfile );
  4013.                                                             }
  4014.                                                             if(player[j].numwaypoints<30){
  4015.                                                             fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
  4016.                                                             for(k=0;k<player[j].numwaypoints;k++){
  4017.                                                             fwrite( &player[j].waypoints[k].x, 1, sizeof(float), tfile );
  4018.                                                             fwrite( &player[j].waypoints[k].y, 1, sizeof(float), tfile );
  4019.                                                             fwrite( &player[j].waypoints[k].z, 1, sizeof(float), tfile );
  4020.                                                             }
  4021.                                                             fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
  4022.                                                             //fwrite( &player[j].jumppath, 1, sizeof(bool), tfile );
  4023.                                                             }
  4024.                                                             else{
  4025.                                                             player[j].numwaypoints=0;
  4026.                                                             player[j].waypoint=0;
  4027.                                                             fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
  4028.                                                             fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
  4029.                                                             fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
  4030.                                                             }
  4031.                                                             fwrite( &player[j].armorhead, 1, sizeof(int), tfile );
  4032.                                                             fwrite( &player[j].armorhigh, 1, sizeof(int), tfile );
  4033.                                                             fwrite( &player[j].armorlow, 1, sizeof(int), tfile );
  4034.                                                             fwrite( &player[j].protectionhead, 1, sizeof(int), tfile );
  4035.                                                             fwrite( &player[j].protectionhigh, 1, sizeof(int), tfile );
  4036.                                                             fwrite( &player[j].protectionlow, 1, sizeof(int), tfile );
  4037.                                                             fwrite( &player[j].metalhead, 1, sizeof(int), tfile );
  4038.                                                             fwrite( &player[j].metalhigh, 1, sizeof(int), tfile );
  4039.                                                             fwrite( &player[j].metallow, 1, sizeof(int), tfile );
  4040.                                                             fwrite( &player[j].power, 1, sizeof(int), tfile );
  4041.                                                             fwrite( &player[j].speedmult, 1, sizeof(int), tfile );
  4042.  
  4043.                                                             fwrite( &player[j].numclothes, 1, sizeof(int), tfile );
  4044.                                                             if(player[j].numclothes)
  4045.                                                             for(k=0;k<player[j].numclothes;k++){
  4046.                                                             int templength;
  4047.                                                             templength=strlen(player[j].clothes[k]);
  4048.                                                             fwrite( &templength,1,sizeof(int),tfile);  
  4049.                                                             for(l=0;l<templength;l++)
  4050.                                                             fwrite( &player[j].clothes[k][l],1,sizeof(char),tfile);
  4051.                                                             fwrite( &player[j].clothestintr[k],1,sizeof(float),tfile); 
  4052.                                                             fwrite( &player[j].clothestintg[k],1,sizeof(float),tfile); 
  4053.                                                             fwrite( &player[j].clothestintb[k],1,sizeof(float),tfile);                                     
  4054.                                                             }
  4055.                                                             }
  4056.                                                             fwrite( &numpathpoints, 1, sizeof(int), tfile );
  4057.                                                             if(numpathpoints)
  4058.                                                             for(j=0;j<numpathpoints;j++){
  4059.                                                             fwrite( &pathpoint[j].x, 1, sizeof(float), tfile );
  4060.                                                             fwrite( &pathpoint[j].y, 1, sizeof(float), tfile );
  4061.                                                             fwrite( &pathpoint[j].z, 1, sizeof(float), tfile );
  4062.                                                             fwrite( &numpathpointconnect[j], 1, sizeof(int), tfile );
  4063.                                                             for(k=0;k<numpathpointconnect[j];k++){
  4064.                                                             fwrite( &pathpointconnect[j][k], 1, sizeof(int), tfile );
  4065.                                                             }
  4066.                                                             }
  4067.  
  4068.                                                             fwrite( &mapcenter.x, 1, sizeof(float), tfile );
  4069.                                                             fwrite( &mapcenter.y, 1, sizeof(float), tfile );
  4070.                                                             fwrite( &mapcenter.z, 1, sizeof(float), tfile );
  4071.  
  4072.                                                             fwrite( &mapradius, 1, sizeof(float), tfile );
  4073.  
  4074.                                                             fclose(tfile);
  4075.                                                             donesomething=1;*/
  4076.                             }
  4077.                             /*
  4078.                             if(Compare(consoletext[0],"save ",0,4)){
  4079.                             mapname[0]=':';
  4080.                             mapname[1]='D';
  4081.                             mapname[2]='a';
  4082.                             mapname[3]='t';
  4083.                             mapname[4]='a';
  4084.                             mapname[5]=':';
  4085.                             mapname[6]='M';
  4086.                             mapname[7]='a';
  4087.                             mapname[8]='p';
  4088.                             mapname[9]='s';
  4089.                             mapname[10]=':';
  4090.                             for(j=5;j<consolechars[0];j++){
  4091.                             mapname[j-5+11]=consoletext[0][j];
  4092.                             }
  4093.                             mapname[consolechars[0]-5+11]='\0';
  4094.  
  4095.                             PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
  4096.                             FSOUND_SetVolume(channels[consolesuccesssound], 256);
  4097.                             FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
  4098.  
  4099.                             FILE            *tfile;
  4100.                             tfile=fopen( mapname, "wb" );
  4101.                             fwrite( &player[0].coords, 1, sizeof(XYZ), tfile );
  4102.                             fwrite( &player[0].rotation, 1, sizeof(float), tfile );
  4103.                             fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
  4104.                             fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
  4105.                             if(player[0].num_weapons>0&&player[0].num_weapons<5)
  4106.                             for(j=0;j<player[0].num_weapons;j++){
  4107.                             fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
  4108.                             }
  4109.                             fwrite( &environment, 1, sizeof(int), tfile );
  4110.  
  4111.                             fwrite( &objects.numobjects, 1, sizeof(int), tfile );
  4112.                             fwrite( &objects.type, 1, sizeof(int)*objects.numobjects, tfile );
  4113.                             fwrite( &objects.rotation, 1, sizeof(float)*objects.numobjects, tfile );
  4114.                             fwrite( &objects.position, 1, sizeof(XYZ)*objects.numobjects, tfile );
  4115.                             fwrite( &objects.scale, 1, sizeof(float)*objects.numobjects, tfile );
  4116.  
  4117.                             fwrite( &numplayers, 1, sizeof(int), tfile );
  4118.                             if(numplayers>1&&numplayers<maxplayers)
  4119.                             for(j=1;j<numplayers;j++){
  4120.                             fwrite( &player[j].coords, 1, sizeof(XYZ), tfile );
  4121.                             fwrite( &player[j].num_weapons, 1, sizeof(int), tfile );
  4122.                             if(player[j].num_weapons>0&&player[j].num_weapons<5)
  4123.                             for(k=0;k<player[j].num_weapons;k++){
  4124.                             fwrite( &weapons.type[player[j].weaponids[k]], 1, sizeof(int), tfile );
  4125.                             }
  4126.                             if(player[j].numwaypoints<30){
  4127.                             fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
  4128.                             fwrite( &player[j].waypoints, 1, sizeof(XYZ)*player[j].numwaypoints, tfile );
  4129.                             fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
  4130.                             //fwrite( &player[j].jumppath, 1, sizeof(bool), tfile );
  4131.                             }
  4132.                             else{
  4133.                             player[j].numwaypoints=0;
  4134.                             player[j].waypoint=0;
  4135.                             fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
  4136.                             fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
  4137.                             fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
  4138.                             }
  4139.                             }
  4140.                             fwrite( &numpathpoints, 1, sizeof(int), tfile );
  4141.                             if(numpathpoints)
  4142.                             for(j=0;j<numpathpoints;j++){
  4143.                             fwrite( &pathpoint[j], 1, sizeof(XYZ), tfile );
  4144.                             fwrite( &numpathpointconnect[j], 1, sizeof(int), tfile );
  4145.                             for(k=0;k<numpathpointconnect[j];k++){
  4146.                             fwrite( &pathpointconnect[j][k], 1, sizeof(int), tfile );
  4147.                             }
  4148.                             }
  4149.                             fclose(tfile);
  4150.                             donesomething=1;
  4151.                             }*/
  4152.                             if(Compare(consoletext[0],"cellar door ",0,11)||Compare(consoletext[0],"cellardoor ",0,10)){
  4153.                                 LoadTextureSave(":Data:Textures:Furdarko.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
  4154.                                 donesomething=1;
  4155.                             }
  4156.                             /*if(Compare(consoletext[0],"Pants ",0,5)){
  4157.                             AddClothes(":Data:Textures:Pants.png",0,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
  4158.                             player[i].DoMipmaps(5,0,0,player[i].skeleton.skinsize,player[i].skeleton.skinsize);
  4159.                             donesomething=1;
  4160.                             }*/
  4161.  
  4162.                             if(Compare(consoletext[0],"tintr ",0,5)||Compare(consoletext[0],"Tintr ",0,5)){
  4163.                                 for(j=6;j<consolechars[0];j++){
  4164.                                     mapname[j-6]=consoletext[0][j];
  4165.                                 }
  4166.  
  4167.                                 tintr=atof(mapname);
  4168.  
  4169.                                 donesomething=1;
  4170.                             }
  4171.  
  4172.                             if(Compare(consoletext[0],"speed ",0,5)||Compare(consoletext[0],"Speed ",0,5)){
  4173.                                 for(j=6;j<consolechars[0];j++){
  4174.                                     mapname[j-6]=consoletext[0][j];
  4175.                                 }
  4176.  
  4177.                                 player[0].speedmult=atof(mapname);
  4178.  
  4179.                                 donesomething=1;
  4180.                             }
  4181.  
  4182.                             if(Compare(consoletext[0],"strength ",0,8)||Compare(consoletext[0],"Strength ",0,8)){
  4183.                                 for(j=9;j<consolechars[0];j++){
  4184.                                     mapname[j-9]=consoletext[0][j];
  4185.                                 }
  4186.  
  4187.                                 player[0].power=atof(mapname);
  4188.  
  4189.                                 donesomething=1;
  4190.                             }
  4191.  
  4192.                             if(Compare(consoletext[0],"viewdistance ",0,12)||Compare(consoletext[0],"Viewdistance ",0,12)){
  4193.                                 for(j=13;j<consolechars[0];j++){
  4194.                                     mapname[j-13]=consoletext[0][j];
  4195.                                 }
  4196.  
  4197.                                 viewdistance=atof(mapname)*100;
  4198.  
  4199.                                 donesomething=1;
  4200.                             }
  4201.  
  4202.                             if(Compare(consoletext[0],"fadestart ",0,9)||Compare(consoletext[0],"Fadestart ",0,9)){
  4203.                                 for(j=10;j<consolechars[0];j++){
  4204.                                     mapname[j-10]=consoletext[0][j];
  4205.                                 }
  4206.  
  4207.                                 fadestart=atof(mapname);
  4208.  
  4209.                                 donesomething=1;
  4210.                             }
  4211.  
  4212.                             if(Compare(consoletext[0],"power ",0,5)||Compare(consoletext[0],"Power ",0,5)){
  4213.                                 for(j=6;j<consolechars[0];j++){
  4214.                                     mapname[j-6]=consoletext[0][j];
  4215.                                 }
  4216.  
  4217.                                 player[0].power=atof(mapname);
  4218.  
  4219.                                 donesomething=1;
  4220.                             }
  4221.  
  4222.                             if(Compare(consoletext[0],"slomo ",0,5)||Compare(consoletext[0],"Slomo ",0,5)){
  4223.                                 for(j=6;j<consolechars[0];j++){
  4224.                                     mapname[j-6]=consoletext[0][j];
  4225.                                 }
  4226.  
  4227.                                 slomospeed=atof(mapname);
  4228.                                 slomo=1-slomo;
  4229.                                 slomodelay=1000;
  4230.  
  4231.                                 donesomething=1;
  4232.                             }
  4233.  
  4234.                             if(Compare(consoletext[0],"slofreq ",0,7)||Compare(consoletext[0],"Slofreq ",0,7)){
  4235.                                 for(j=8;j<consolechars[0];j++){
  4236.                                     mapname[j-8]=consoletext[0][j];
  4237.                                 }
  4238.  
  4239.                                 slomofreq=atoi(mapname);
  4240.  
  4241.                                 donesomething=1;
  4242.                             }
  4243.  
  4244.                             if(Compare(consoletext[0],"size ",0,4)||Compare(consoletext[0],"Size ",0,4)){
  4245.                                 for(j=5;j<consolechars[0];j++){
  4246.                                     mapname[j-5]=consoletext[0][j];
  4247.                                 }
  4248.  
  4249.                                 player[0].scale=atof(mapname)*.2;
  4250.  
  4251.                                 donesomething=1;
  4252.                             }
  4253.  
  4254.                             if(Compare(consoletext[0],"sizenear ",0,8)||Compare(consoletext[0],"Sizenear ",0,8)){
  4255.                                 int closest=-1;
  4256.                                 float closestdist=-1;
  4257.                                 float distance;
  4258.                                 if(numplayers>1)
  4259.                                     for(i=1;i<numplayers;i++){
  4260.                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
  4261.                                         if(closestdist==-1||distance<closestdist){
  4262.                                             closestdist=distance;
  4263.                                             closest=i;
  4264.                                         }
  4265.                                     }
  4266.  
  4267.                                     for(j=9;j<consolechars[0];j++){
  4268.                                         mapname[j-9]=consoletext[0][j];
  4269.                                     }
  4270.  
  4271.                                     player[closest].scale=atof(mapname)*.2;
  4272.  
  4273.                                     donesomething=1;
  4274.                             }
  4275.  
  4276.                             if(Compare(consoletext[0],"proportionnear ",0,14)||Compare(consoletext[0],"Proportionnear ",0,14)){
  4277.                                 int startpoint;
  4278.                                 int alldone;
  4279.  
  4280.                                 int closest=-1;
  4281.                                 float closestdist=-1;
  4282.                                 float distance;
  4283.                                 if(numplayers>1)
  4284.                                     for(i=1;i<numplayers;i++){
  4285.                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
  4286.                                         if(closestdist==-1||distance<closestdist){
  4287.                                             closestdist=distance;
  4288.                                             closest=i;
  4289.                                         }
  4290.                                     }
  4291.  
  4292.                                     alldone=0;
  4293.                                     startpoint=15;
  4294.                                     j=startpoint;
  4295.                                     while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  4296.                                         mapname[j-startpoint]=consoletext[0][j];
  4297.                                         j++;
  4298.                                         if(consoletext[0][j]=='\0')alldone=1;
  4299.                                     }
  4300.                                     mapname[j-startpoint]='\0';
  4301.  
  4302.                                     headprop=atof(mapname);
  4303.  
  4304.                                     j++;
  4305.                                     startpoint=j;
  4306.                                     while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  4307.                                         mapname[j-startpoint]=consoletext[0][j];
  4308.                                         j++;
  4309.                                         if(consoletext[0][j]=='\0')alldone=1;
  4310.                                     }
  4311.                                     mapname[j-startpoint]='\0';
  4312.  
  4313.                                     bodyprop=atof(mapname);
  4314.  
  4315.                                     j++;
  4316.                                     startpoint=j;
  4317.                                     while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  4318.                                         mapname[j-startpoint]=consoletext[0][j];
  4319.                                         j++;
  4320.                                         if(consoletext[0][j]=='\0')alldone=1;
  4321.                                     }
  4322.                                     mapname[j-startpoint]='\0';
  4323.  
  4324.                                     armprop=atof(mapname);
  4325.  
  4326.                                     j++;
  4327.                                     startpoint=j;
  4328.                                     while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  4329.                                         mapname[j-startpoint]=consoletext[0][j];
  4330.                                         j++;
  4331.                                         if(consoletext[0][j]=='\0')alldone=1;
  4332.                                     }
  4333.                                     mapname[j-startpoint]='\0';
  4334.  
  4335.                                     legprop=atof(mapname);
  4336.  
  4337.                                     if(player[closest].creature==wolftype){
  4338.                                         player[closest].proportionhead=1.1*headprop;
  4339.                                         player[closest].proportionbody=1.1*bodyprop;
  4340.                                         player[closest].proportionarms=1.1*armprop;
  4341.                                         player[closest].proportionlegs=1.1*legprop;
  4342.                                     }
  4343.  
  4344.                                     if(player[closest].creature==rabbittype){
  4345.                                         player[closest].proportionhead=1.2*headprop;
  4346.                                         player[closest].proportionbody=1.05*bodyprop;
  4347.                                         player[closest].proportionarms=1.00*armprop;
  4348.                                         player[closest].proportionlegs=1.1*legprop;
  4349.                                         player[closest].proportionlegs.y=1.05*legprop;
  4350.                                     }
  4351.  
  4352.                                     donesomething=1;
  4353.                             }
  4354.  
  4355.  
  4356.                             if(Compare(consoletext[0],"sizemin ",0,7)||Compare(consoletext[0],"Sizemin ",0,7)){
  4357.                                 for(i=1;i<numplayers;i++){
  4358.                                     if(player[i].scale<0.8*0.2)player[i].scale=0.8*0.2;
  4359.                                 }
  4360.  
  4361.                                 donesomething=1;
  4362.                             }
  4363.  
  4364.                             if(Compare(consoletext[0],"tutorial ",0,8)||Compare(consoletext[0],"Tutorial ",0,8)){
  4365.                                 for(j=9;j<consolechars[0];j++){
  4366.                                     mapname[j-9]=consoletext[0][j];
  4367.                                 }
  4368.  
  4369.                                 tutoriallevel=atoi(mapname);
  4370.  
  4371.                                 donesomething=1;
  4372.                             }
  4373.  
  4374.  
  4375.                             if(Compare(consoletext[0],"tintg ",0,5)||Compare(consoletext[0],"Tintg ",0,5)){
  4376.                                 for(j=6;j<consolechars[0];j++){
  4377.                                     mapname[j-6]=consoletext[0][j];
  4378.                                 }
  4379.  
  4380.                                 tintg=atof(mapname);
  4381.  
  4382.                                 donesomething=1;
  4383.                             }
  4384.  
  4385.                             if(Compare(consoletext[0],"tintb ",0,5)||Compare(consoletext[0],"Tintb ",0,5)){
  4386.                                 for(j=6;j<consolechars[0];j++){
  4387.                                     mapname[j-6]=consoletext[0][j];
  4388.                                 }
  4389.  
  4390.                                 tintb=atof(mapname);
  4391.  
  4392.                                 donesomething=1;
  4393.                             }
  4394.  
  4395.                             if(Compare(consoletext[0],"hostile ",0,7)){
  4396.                                 for(j=8;j<consolechars[0];j++){
  4397.                                     mapname[j-8]=consoletext[0][j];
  4398.                                 }
  4399.  
  4400.                                 hostile=atoi(mapname);
  4401.  
  4402.                                 donesomething=1;
  4403.                             }
  4404.  
  4405.  
  4406.                             if(Compare(consoletext[0],"type active ",0,11)){
  4407.                                 editoractive=typeactive;
  4408.  
  4409.                                 donesomething=1;
  4410.                             }
  4411.  
  4412.                             if(Compare(consoletext[0],"indemo ",0,6)){
  4413.                                 indemo=1;
  4414.                                 hotspot[numhotspots]=player[0].coords;
  4415.                                 hotspotsize[numhotspots]=0;
  4416.                                 hotspottype[numhotspots]=-111;
  4417.                                 mapname[0]='\0';
  4418.                                 strcpy(hotspottext[numhotspots],"mapname");
  4419.                                 numhotspots++;
  4420.  
  4421.                                 donesomething=1;
  4422.                             }
  4423.  
  4424.                             if(Compare(consoletext[0],"notindemo ",0,9)){
  4425.                                 indemo=0;
  4426.                                 numhotspots--;
  4427.  
  4428.                                 donesomething=1;
  4429.                             }
  4430.  
  4431.                             if(Compare(consoletext[0],"type sitting ",0,12)){
  4432.                                 editoractive=typesitting;
  4433.  
  4434.                                 donesomething=1;
  4435.                             }
  4436.  
  4437.                             if(Compare(consoletext[0],"type sitting wall ",0,17)){
  4438.                                 editoractive=typesittingwall;
  4439.  
  4440.                                 donesomething=1;
  4441.                             }
  4442.  
  4443.                             if(Compare(consoletext[0],"type sleeping ",0,13)){
  4444.                                 editoractive=typesleeping;
  4445.  
  4446.                                 donesomething=1;
  4447.                             }
  4448.                             if(Compare(consoletext[0],"type dead1 ",0,10)){
  4449.                                 editoractive=typedead1;
  4450.  
  4451.                                 donesomething=1;
  4452.                             }
  4453.                             if(Compare(consoletext[0],"type dead2 ",0,10)){
  4454.                                 editoractive=typedead2;
  4455.  
  4456.                                 donesomething=1;
  4457.                             }
  4458.                             if(Compare(consoletext[0],"type dead3 ",0,10)){
  4459.                                 editoractive=typedead3;
  4460.                                 donesomething=1;
  4461.                             }
  4462.                             if(Compare(consoletext[0],"type dead4 ",0,10)){
  4463.                                 editoractive=typedead4;
  4464.  
  4465.                                 donesomething=1;
  4466.                             }
  4467.  
  4468.                             if(Compare(consoletext[0],"path keepwalking ",0,16)){
  4469.                                 editorpathtype=wpkeepwalking;
  4470.  
  4471.                                 donesomething=1;
  4472.                             }
  4473.  
  4474.                             if(Compare(consoletext[0],"path pause ",0,10)){
  4475.                                 editorpathtype=wppause;
  4476.  
  4477.                                 donesomething=1;
  4478.                             }
  4479.  
  4480.                             if(Compare(consoletext[0],"mapkilleveryone ",0,15)){
  4481.                                 maptype=mapkilleveryone;
  4482.  
  4483.                                 donesomething=1;
  4484.                             }
  4485.  
  4486.                             if(Compare(consoletext[0],"mapgosomewhere ",0,14)){
  4487.                                 maptype=mapgosomewhere;
  4488.  
  4489.                                 donesomething=1;
  4490.                             }
  4491.  
  4492.                             if(Compare(consoletext[0],"mapkillsomeone ",0,14)){
  4493.                                 maptype=mapkillsomeone;
  4494.  
  4495.                                 donesomething=1;
  4496.  
  4497.                             }
  4498.  
  4499.                             if(Compare(consoletext[0],"mapkillmost ",0,11)){
  4500.                                 maptype=mapkillmost;
  4501.  
  4502.                                 donesomething=1;
  4503.  
  4504.                             }
  4505.  
  4506.                             if(Compare(consoletext[0],"hs ",0,2)){
  4507.                                 int startpoint;
  4508.                                 int alldone;
  4509.  
  4510.                                 hotspot[numhotspots]=player[0].coords;
  4511.  
  4512.                                 alldone=0;
  4513.                                 startpoint=3;
  4514.                                 j=startpoint;
  4515.                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  4516.                                     mapname[j-startpoint]=consoletext[0][j];
  4517.                                     j++;
  4518.                                     if(consoletext[0][j]=='\0')alldone=1;
  4519.                                 }
  4520.                                 mapname[j-startpoint]='\0';
  4521.  
  4522.                                 hotspotsize[numhotspots]=atof(mapname);
  4523.  
  4524.                                 j++;
  4525.                                 startpoint=j;
  4526.                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  4527.                                     mapname[j-startpoint]=consoletext[0][j];
  4528.                                     j++;
  4529.                                     if(consoletext[0][j]=='\0')alldone=1;
  4530.                                 }
  4531.                                 mapname[j-startpoint]='\0';
  4532.  
  4533.                                 hotspottype[numhotspots]=atoi(mapname);
  4534.  
  4535.                                 j++;
  4536.                                 startpoint=j;
  4537.                                 while(consoletext[0][j]!='\0'&&!alldone&&j<255){
  4538.                                     mapname[j-startpoint]=consoletext[0][j];
  4539.                                     j++;
  4540.                                     if(consoletext[0][j]=='\0')alldone=1;
  4541.                                 }
  4542.                                 mapname[j-startpoint]='\n';
  4543.                                 mapname[j-startpoint+1]='\0';
  4544.  
  4545.                                 strcpy(hotspottext[numhotspots],mapname);
  4546.  
  4547.                                 numhotspots++;
  4548.  
  4549.                                 donesomething=1;
  4550.                             }
  4551.  
  4552.                             if(Compare(consoletext[0],"dialogue ",0,8)){
  4553.                                 int startpoint;
  4554.                                 int alldone;
  4555.  
  4556.                                 alldone=0;
  4557.                                 startpoint=9;
  4558.                                 j=startpoint;
  4559.                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  4560.                                     mapname[j-startpoint]=consoletext[0][j];
  4561.                                     j++;
  4562.                                     if(consoletext[0][j]=='\0')alldone=1;
  4563.                                 }
  4564.                                 mapname[j-startpoint]='\0';
  4565.                                 startpoint=j+1;
  4566.  
  4567.                                 dialoguetype[numdialogues]=atoi(mapname);
  4568.  
  4569.                                 mapname[0]=':';
  4570.                                 mapname[1]='D';
  4571.                                 mapname[2]='a';
  4572.                                 mapname[3]='t';
  4573.                                 mapname[4]='a';
  4574.                                 mapname[5]=':';
  4575.                                 mapname[6]='D';
  4576.                                 mapname[7]='i';
  4577.                                 mapname[8]='a';
  4578.                                 mapname[9]='l';
  4579.                                 mapname[10]='o';
  4580.                                 mapname[11]='g';
  4581.                                 mapname[12]='u';
  4582.                                 mapname[13]='e';
  4583.                                 mapname[14]='s';
  4584.                                 mapname[15]=':';
  4585.                                 for(j=startpoint;j<consolechars[0];j++){
  4586.                                     mapname[j-startpoint+16]=consoletext[0][j];
  4587.                                 }
  4588.                                 mapname[consolechars[0]-startpoint+16]='.';
  4589.                                 mapname[consolechars[0]-startpoint+17]='t';
  4590.                                 mapname[consolechars[0]-startpoint+18]='x';
  4591.                                 mapname[consolechars[0]-startpoint+19]='t';
  4592.                                 mapname[consolechars[0]-startpoint+20]='\0';
  4593.  
  4594.                                 for(j=0;j<max_dialoguelength;j++){
  4595.                                     for(k=0;k<128;k++){
  4596.                                         dialoguetext[numdialogues][j][k]='\0';
  4597.                                     }
  4598.                                     for(k=0;k<64;k++){
  4599.                                         dialoguename[numdialogues][j][k]='\0';
  4600.                                     }
  4601.                                 }
  4602.  
  4603.                                 ifstream ipstream(ConvertFileName(mapname));
  4604.                                 ipstream.ignore(256,':');
  4605.                                 ipstream >> numdialogueboxes[numdialogues];
  4606.                                 for(i=0;i<numdialogueboxes[numdialogues];i++){
  4607.                                     ipstream.ignore(256,':');
  4608.                                     ipstream.ignore(256,':');
  4609.                                     ipstream.ignore(256,' ');
  4610.                                     ipstream >> dialogueboxlocation[numdialogues][i];
  4611.                                     ipstream.ignore(256,':');
  4612.                                     ipstream >> dialogueboxcolor[numdialogues][i][0];
  4613.                                     ipstream >> dialogueboxcolor[numdialogues][i][1];
  4614.                                     ipstream >> dialogueboxcolor[numdialogues][i][2];
  4615.                                     ipstream.ignore(256,':');
  4616.                                     ipstream.getline(dialoguename[numdialogues][i],64);
  4617.                                     ipstream.ignore(256,':');
  4618.                                     ipstream.ignore(256,' ');
  4619.                                     ipstream.getline(dialoguetext[numdialogues][i],128);
  4620.                                     for(j=0;j<128;j++){
  4621.                                         if(dialoguetext[numdialogues][i][j]=='\\')dialoguetext[numdialogues][i][j]='\n';
  4622.                                     }
  4623.                                     ipstream.ignore(256,':');
  4624.                                     ipstream >> dialogueboxsound[numdialogues][i];
  4625.                                 }
  4626.  
  4627.                                 for(i=0;i<numdialogueboxes[numdialogues];i++){
  4628.                                     for(j=0;j<numplayers;j++){
  4629.                                         participantfacing[numdialogues][i][j]=player[j].facing;
  4630.                                     }
  4631.                                 }
  4632.                                 ipstream.close();
  4633.  
  4634.                                 directing=1;
  4635.                                 indialogue=0;
  4636.                                 whichdialogue=numdialogues;
  4637.  
  4638.  
  4639.                                 numdialogues++;
  4640.  
  4641.                                 donesomething=1;
  4642.                             }
  4643.  
  4644.                             if(Compare(consoletext[0],"fixdialogue ",0,11)){
  4645.                                 int startpoint;
  4646.                                 int alldone;
  4647.                                 int whichdi;
  4648.  
  4649.                                 alldone=0;
  4650.                                 startpoint=12;
  4651.                                 j=startpoint;
  4652.                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  4653.                                     mapname[j-startpoint]=consoletext[0][j];
  4654.                                     j++;
  4655.                                     if(consoletext[0][j]=='\0')alldone=1;
  4656.                                 }
  4657.                                 mapname[j-startpoint]='\0';
  4658.                                 startpoint=j+1;
  4659.  
  4660.                                 whichdi=atoi(mapname);
  4661.  
  4662.                                 mapname[0]=':';
  4663.                                 mapname[1]='D';
  4664.                                 mapname[2]='a';
  4665.                                 mapname[3]='t';
  4666.                                 mapname[4]='a';
  4667.                                 mapname[5]=':';
  4668.                                 mapname[6]='D';
  4669.                                 mapname[7]='i';
  4670.                                 mapname[8]='a';
  4671.                                 mapname[9]='l';
  4672.                                 mapname[10]='o';
  4673.                                 mapname[11]='g';
  4674.                                 mapname[12]='u';
  4675.                                 mapname[13]='e';
  4676.                                 mapname[14]='s';
  4677.                                 mapname[15]=':';
  4678.                                 for(j=startpoint;j<consolechars[0];j++){
  4679.                                     mapname[j-startpoint+16]=consoletext[0][j];
  4680.                                 }
  4681.                                 mapname[consolechars[0]-startpoint+16]='.';
  4682.                                 mapname[consolechars[0]-startpoint+17]='t';
  4683.                                 mapname[consolechars[0]-startpoint+18]='x';
  4684.                                 mapname[consolechars[0]-startpoint+19]='t';
  4685.                                 mapname[consolechars[0]-startpoint+20]='\0';
  4686.  
  4687.                                 for(j=0;j<max_dialoguelength;j++){
  4688.                                     for(k=0;k<128;k++){
  4689.                                         dialoguetext[whichdi][j][k]='\0';
  4690.                                     }
  4691.                                     for(k=0;k<64;k++){
  4692.                                         dialoguename[whichdi][j][k]='\0';
  4693.                                     }
  4694.                                 }
  4695.  
  4696.                                 ifstream ipstream(ConvertFileName(mapname));
  4697.                                 ipstream.ignore(256,':');
  4698.                                 ipstream >> numdialogueboxes[whichdi];
  4699.                                 for(i=0;i<numdialogueboxes[whichdi];i++){
  4700.                                     ipstream.ignore(256,':');
  4701.                                     ipstream.ignore(256,':');
  4702.                                     ipstream.ignore(256,' ');
  4703.                                     ipstream >> dialogueboxlocation[whichdi][i];
  4704.                                     ipstream.ignore(256,':');
  4705.                                     ipstream >> dialogueboxcolor[whichdi][i][0];
  4706.                                     ipstream >> dialogueboxcolor[whichdi][i][1];
  4707.                                     ipstream >> dialogueboxcolor[whichdi][i][2];
  4708.                                     ipstream.ignore(256,':');
  4709.                                     ipstream.getline(dialoguename[whichdi][i],64);
  4710.                                     ipstream.ignore(256,':');
  4711.                                     ipstream.ignore(256,' ');
  4712.                                     ipstream.getline(dialoguetext[whichdi][i],128);
  4713.                                     for(j=0;j<128;j++){
  4714.                                         if(dialoguetext[whichdi][i][j]=='\\')dialoguetext[whichdi][i][j]='\n';
  4715.                                     }
  4716.                                     ipstream.ignore(256,':');
  4717.                                     ipstream >> dialogueboxsound[whichdi][i];
  4718.                                 }
  4719.  
  4720.                                 ipstream.close();
  4721.  
  4722.                                 donesomething=1;
  4723.                             }
  4724.  
  4725.                             if(Compare(consoletext[0],"fixtype ",0,7)){
  4726.                                 int startpoint;
  4727.                                 int alldone;
  4728.                                 int whichdi;
  4729.  
  4730.                                 alldone=0;
  4731.                                 startpoint=8;
  4732.                                 j=startpoint;
  4733.                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  4734.                                     mapname[j-startpoint]=consoletext[0][j];
  4735.                                     j++;
  4736.                                     if(consoletext[0][j]=='\0')alldone=1;
  4737.                                 }
  4738.                                 mapname[j-startpoint]='\0';
  4739.                                 dialoguetype[0]=atoi(mapname);
  4740.  
  4741.                                 startpoint=j+1;
  4742.  
  4743.                                 donesomething=1;
  4744.                             }
  4745.  
  4746.  
  4747.                             if(Compare(consoletext[0],"fixrotation ",0,11)){
  4748.                                 participantrotation[whichdialogue][participantfocus[whichdialogue][indialogue]]=player[participantfocus[whichdialogue][indialogue]].rotation;
  4749.  
  4750.                                 donesomething=1;
  4751.                             }
  4752.  
  4753.                             if(Compare(consoletext[0],"ddialogue ",0,9)){
  4754.                                 numdialogues--;
  4755.                                 if(numdialogues<0)numdialogues=0;
  4756.  
  4757.                                 donesomething=1;
  4758.                             }
  4759.  
  4760.                             if(Compare(consoletext[0],"immobile ",0,8)){
  4761.                                 player[0].immobile=1;
  4762.                                 donesomething=1;
  4763.                             }
  4764.  
  4765.                             if(Compare(consoletext[0],"mobile ",0,6)){
  4766.                                 player[0].immobile=0;
  4767.                                 donesomething=1;
  4768.                             }
  4769.  
  4770.                             if(Compare(consoletext[0],"play ",0,4)){
  4771.                                 int startpoint;
  4772.                                 int alldone;
  4773.  
  4774.                                 alldone=0;
  4775.                                 startpoint=5;
  4776.                                 j=startpoint;
  4777.                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  4778.                                     mapname[j-startpoint]=consoletext[0][j];
  4779.                                     j++;
  4780.                                     if(consoletext[0][j]=='\0')alldone=1;
  4781.                                 }
  4782.                                 mapname[j-startpoint]='\0';
  4783.                                 startpoint=j+1;
  4784.  
  4785.                                 whichdialogue=atoi(mapname);
  4786.  
  4787.                                 if(numdialogues>whichdialogue){
  4788.                                     for(i=0;i<numdialogueboxes[whichdialogue];i++){
  4789.                                         player[participantfocus[whichdialogue][i]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][i]];
  4790.                                         player[participantfocus[whichdialogue][i]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
  4791.                                         player[participantfocus[whichdialogue][i]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
  4792.                                         player[participantfocus[whichdialogue][i]].velocity=0;
  4793.                                         player[participantfocus[whichdialogue][i]].targetanimation=player[participantfocus[whichdialogue][i]].getIdle();
  4794.                                         player[participantfocus[whichdialogue][i]].targetframe=0;
  4795.                                     }
  4796.  
  4797.                                     directing=0;
  4798.                                     indialogue=0;
  4799.  
  4800.                                     donesomething=1;
  4801.  
  4802.                                     //if(dialogueboxsound[whichdialogue][indialogue]!=0){
  4803.                                     float gLoc[3];
  4804.                                     float vel[3];
  4805.                                     XYZ temppos;
  4806.                                     temppos=player[participantfocus[whichdialogue][indialogue]].coords;
  4807.                                     temppos=temppos-viewer;
  4808.                                     Normalise(&temppos);
  4809.                                     temppos+=viewer;
  4810.  
  4811.                                     gLoc[0]=temppos.x;
  4812.                                     gLoc[1]=temppos.y;
  4813.                                     gLoc[2]=temppos.z;
  4814.                                     vel[0]=0;
  4815.                                     vel[1]=0;
  4816.                                     vel[2]=0;
  4817.                                     int whichsoundplay;
  4818.                                     whichsoundplay=rabbitchitter;
  4819.                                     if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
  4820.                                     if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
  4821.                                     if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
  4822.                                     if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
  4823.                                     if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
  4824.                                     if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
  4825.                                     if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
  4826.                                     if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
  4827.                                     if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
  4828.                                     if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
  4829.                                     if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
  4830.                                     if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
  4831.                                     if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
  4832.                                     if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
  4833.                                     if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
  4834.                                     if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
  4835.                                     if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
  4836.                                     if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
  4837.                                     if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
  4838.                                     PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, TRUE);
  4839.                                     FSOUND_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
  4840.                                     FSOUND_SetVolume(channels[whichsoundplay], 256);
  4841.                                     FSOUND_SetPaused(channels[whichsoundplay], FALSE);
  4842.                                     //}
  4843.                                 }
  4844.                             }
  4845.  
  4846.  
  4847.  
  4848.  
  4849.                             if(Compare(consoletext[0],"dhs ",0,3)){
  4850.                                 numhotspots--;
  4851.                                 if(numhotspots<0)numhotspots=0;
  4852.                                 donesomething=1;
  4853.                             }
  4854.  
  4855.  
  4856.                             if(Compare(consoletext[0],"proportion ",0,10)||Compare(consoletext[0],"Proportion ",0,4)){
  4857.                                 int startpoint;
  4858.                                 int alldone;
  4859.  
  4860.                                 alldone=0;
  4861.                                 startpoint=11;
  4862.                                 j=startpoint;
  4863.                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  4864.                                     mapname[j-startpoint]=consoletext[0][j];
  4865.                                     j++;
  4866.                                     if(consoletext[0][j]=='\0')alldone=1;
  4867.                                 }
  4868.                                 mapname[j-startpoint]='\0';
  4869.  
  4870.                                 headprop=atof(mapname);
  4871.  
  4872.                                 j++;
  4873.                                 startpoint=j;
  4874.                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  4875.                                     mapname[j-startpoint]=consoletext[0][j];
  4876.                                     j++;
  4877.                                     if(consoletext[0][j]=='\0')alldone=1;
  4878.                                 }
  4879.                                 mapname[j-startpoint]='\0';
  4880.  
  4881.                                 bodyprop=atof(mapname);
  4882.  
  4883.                                 j++;
  4884.                                 startpoint=j;
  4885.                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  4886.                                     mapname[j-startpoint]=consoletext[0][j];
  4887.                                     j++;
  4888.                                     if(consoletext[0][j]=='\0')alldone=1;
  4889.                                 }
  4890.                                 mapname[j-startpoint]='\0';
  4891.  
  4892.                                 armprop=atof(mapname);
  4893.  
  4894.                                 j++;
  4895.                                 startpoint=j;
  4896.                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  4897.                                     mapname[j-startpoint]=consoletext[0][j];
  4898.                                     j++;
  4899.                                     if(consoletext[0][j]=='\0')alldone=1;
  4900.                                 }
  4901.                                 mapname[j-startpoint]='\0';
  4902.  
  4903.                                 legprop=atof(mapname);
  4904.  
  4905.                                 if(player[0].creature==wolftype){
  4906.                                     player[0].proportionhead=1.1*headprop;
  4907.                                     player[0].proportionbody=1.1*bodyprop;
  4908.                                     player[0].proportionarms=1.1*armprop;
  4909.                                     player[0].proportionlegs=1.1*legprop;
  4910.                                 }
  4911.  
  4912.                                 if(player[0].creature==rabbittype){
  4913.                                     player[0].proportionhead=1.2*headprop;
  4914.                                     player[0].proportionbody=1.05*bodyprop;
  4915.                                     player[0].proportionarms=1.00*armprop;
  4916.                                     player[0].proportionlegs=1.1*legprop;
  4917.                                     player[0].proportionlegs.y=1.05*legprop;
  4918.                                 }
  4919.  
  4920.                                 donesomething=1;
  4921.                             }
  4922.  
  4923.                             if(Compare(consoletext[0],"allimmobile ",0,11)||Compare(consoletext[0],"Allimmobile ",0,11)){
  4924.                                 for(i=0;i<numplayers;i++){
  4925.                                     if(i>0)player[i].immobile=1;
  4926.                                 }
  4927.                                 donesomething=1;
  4928.                             }
  4929.  
  4930.  
  4931.                             if(Compare(consoletext[0],"default ",0,7)||Compare(consoletext[0],"Default ",0,7)){
  4932.                                 player[0].armorhead=1;
  4933.                                 player[0].armorhigh=1;
  4934.                                 player[0].armorlow=1;
  4935.                                 player[0].protectionhead=1;
  4936.                                 player[0].protectionhigh=1;
  4937.                                 player[0].protectionlow=1;
  4938.                                 player[0].metalhead=1;
  4939.                                 player[0].metalhigh=1;
  4940.                                 player[0].metallow=1;
  4941.                                 player[0].power=1;
  4942.                                 player[0].speedmult=1;
  4943.                                 player[0].scale=1;
  4944.  
  4945.                                 if(player[0].creature==wolftype){
  4946.                                     player[0].proportionhead=1.1;
  4947.                                     player[0].proportionbody=1.1;
  4948.                                     player[0].proportionarms=1.1;
  4949.                                     player[0].proportionlegs=1.1;
  4950.                                 }
  4951.  
  4952.                                 if(player[0].creature==rabbittype){
  4953.                                     player[0].proportionhead=1.2;
  4954.                                     player[0].proportionbody=1.05;
  4955.                                     player[0].proportionarms=1.00;
  4956.                                     player[0].proportionlegs=1.1;
  4957.                                     player[0].proportionlegs.y=1.05;
  4958.                                 }
  4959.  
  4960.                                 player[0].numclothes=0;
  4961.                                 if(player[0].whichskin==0){
  4962.                                     LoadTextureSave(":Data:Textures:Fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
  4963.                                 }
  4964.                                 else if(player[0].whichskin==1){
  4965.                                     LoadTextureSave(":Data:Textures:Fur.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
  4966.                                 }
  4967.                                 else if(player[0].whichskin==2){
  4968.                                     LoadTextureSave(":Data:Textures:Fur2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
  4969.                                 }
  4970.                                 else if(player[0].whichskin==3){
  4971.                                     LoadTextureSave(":Data:Textures:Lynx.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
  4972.                                 }
  4973.                                 else if(player[0].whichskin==4){
  4974.                                     LoadTextureSave(":Data:Textures:Otter.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
  4975.                                 }
  4976.                                 else if(player[0].whichskin==5){
  4977.                                     LoadTextureSave(":Data:Textures:Opal.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
  4978.                                 }
  4979.                                 else if(player[0].whichskin==6){
  4980.                                     LoadTextureSave(":Data:Textures:Sable.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
  4981.                                 }
  4982.                                 else if(player[0].whichskin==7){
  4983.                                     LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
  4984.                                 }
  4985.                                 else if(player[0].whichskin==8){
  4986.                                     LoadTextureSave(":Data:Textures:BW2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
  4987.                                 }
  4988.                                 else if(player[0].whichskin==9){
  4989.                                     LoadTextureSave(":Data:Textures:WB2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
  4990.                                 }
  4991.  
  4992.                                 editoractive=typeactive;
  4993.                                 player[0].immobile=0;
  4994.  
  4995.  
  4996.  
  4997.                                 donesomething=1;
  4998.                             }
  4999.  
  5000.                             if(Compare(consoletext[0],"tint ",0,4)||Compare(consoletext[0],"Tint ",0,4)){
  5001.                                 int startpoint;
  5002.                                 int alldone;
  5003.                                 alldone=0;
  5004.                                 startpoint=5;
  5005.                                 j=startpoint;
  5006.                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  5007.                                     mapname[j-startpoint]=consoletext[0][j];
  5008.                                     j++;
  5009.                                     if(consoletext[0][j]=='\0')alldone=1;
  5010.                                 }
  5011.                                 mapname[j-startpoint]='\0';
  5012.  
  5013.                                 tintr=atof(mapname);
  5014.  
  5015.                                 j++;
  5016.                                 startpoint=j;
  5017.                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  5018.                                     mapname[j-startpoint]=consoletext[0][j];
  5019.                                     j++;
  5020.                                     if(consoletext[0][j]=='\0')alldone=1;
  5021.                                 }
  5022.                                 mapname[j-startpoint]='\0';
  5023.  
  5024.                                 tintg=atof(mapname);
  5025.  
  5026.                                 j++;
  5027.                                 startpoint=j;
  5028.                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  5029.                                     mapname[j-startpoint]=consoletext[0][j];
  5030.                                     j++;
  5031.                                     if(consoletext[0][j]=='\0')alldone=1;
  5032.                                 }
  5033.                                 mapname[j-startpoint]='\0';
  5034.  
  5035.                                 tintb=atof(mapname);
  5036.  
  5037.                                 donesomething=1;
  5038.                             }
  5039.  
  5040.                             if(Compare(consoletext[0],"sky tint ",0,8)||Compare(consoletext[0],"Sky Tint ",0,8)){
  5041.                                 int startpoint;
  5042.                                 int alldone;
  5043.                                 alldone=0;
  5044.                                 startpoint=9;
  5045.                                 j=startpoint;
  5046.                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  5047.                                     mapname[j-startpoint]=consoletext[0][j];
  5048.                                     j++;
  5049.                                     if(consoletext[0][j]=='\0')alldone=1;
  5050.                                 }
  5051.                                 mapname[j-startpoint]='\0';
  5052.  
  5053.                                 skyboxr=atof(mapname);
  5054.  
  5055.                                 j++;
  5056.                                 startpoint=j;
  5057.                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  5058.                                     mapname[j-startpoint]=consoletext[0][j];
  5059.                                     j++;
  5060.                                     if(consoletext[0][j]=='\0')alldone=1;
  5061.                                 }
  5062.                                 mapname[j-startpoint]='\0';
  5063.  
  5064.                                 skyboxg=atof(mapname);
  5065.  
  5066.                                 j++;
  5067.                                 startpoint=j;
  5068.                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  5069.                                     mapname[j-startpoint]=consoletext[0][j];
  5070.                                     j++;
  5071.                                     if(consoletext[0][j]=='\0')alldone=1;
  5072.                                 }
  5073.                                 mapname[j-startpoint]='\0';
  5074.  
  5075.                                 skyboxb=atof(mapname);
  5076.  
  5077.                                 skyboxlightr=skyboxr;
  5078.                                 skyboxlightg=skyboxg;
  5079.                                 skyboxlightb=skyboxb;
  5080.  
  5081.                                 SetUpLighting();
  5082.  
  5083.                                 //if(skyboxtexture){
  5084.                                 terrain.DoShadows();
  5085.                                 objects.DoShadows();
  5086.                                 /*}
  5087.                                 else terrain.DoLighting();
  5088.                                 */
  5089.                                 donesomething=1;
  5090.                             }
  5091.  
  5092.                             if(Compare(consoletext[0],"sky light ",0,9)||Compare(consoletext[0],"Sky Light ",0,9)){
  5093.                                 int startpoint;
  5094.                                 int alldone;
  5095.                                 alldone=0;
  5096.                                 startpoint=10;
  5097.                                 j=startpoint;
  5098.                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  5099.                                     mapname[j-startpoint]=consoletext[0][j];
  5100.                                     j++;
  5101.                                     if(consoletext[0][j]=='\0')alldone=1;
  5102.                                 }
  5103.                                 mapname[j-startpoint]='\0';
  5104.  
  5105.                                 skyboxlightr=atof(mapname);
  5106.  
  5107.                                 j++;
  5108.                                 startpoint=j;
  5109.                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  5110.                                     mapname[j-startpoint]=consoletext[0][j];
  5111.                                     j++;
  5112.                                     if(consoletext[0][j]=='\0')alldone=1;
  5113.                                 }
  5114.                                 mapname[j-startpoint]='\0';
  5115.  
  5116.                                 skyboxlightg=atof(mapname);
  5117.  
  5118.                                 j++;
  5119.                                 startpoint=j;
  5120.                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  5121.                                     mapname[j-startpoint]=consoletext[0][j];
  5122.                                     j++;
  5123.                                     if(consoletext[0][j]=='\0')alldone=1;
  5124.                                 }
  5125.                                 mapname[j-startpoint]='\0';
  5126.  
  5127.                                 skyboxlightb=atof(mapname);
  5128.  
  5129.                                 SetUpLighting();
  5130.  
  5131.                                 //if(skyboxtexture){
  5132.                                 terrain.DoShadows();
  5133.                                 objects.DoShadows();
  5134.                                 /*}
  5135.                                 else terrain.DoLighting();
  5136.                                 */
  5137.                                 donesomething=1;
  5138.                             }
  5139.  
  5140.                             if(Compare(consoletext[0],"skybox ",0,6)||Compare(consoletext[0],"Skybox ",0,6)){
  5141.                                 skyboxtexture=1-skyboxtexture;
  5142.  
  5143.                                 SetUpLighting();
  5144.                                 //if(skyboxtexture){
  5145.                                 terrain.DoShadows();
  5146.                                 objects.DoShadows();
  5147.                                 /*}
  5148.                                 else terrain.DoLighting();
  5149.                                 */
  5150.                                 donesomething=1;
  5151.                             }
  5152.  
  5153.                             if(Compare(consoletext[0],"protection ",0,10)||Compare(consoletext[0],"Protection ",0,10)){
  5154.                                 int startpoint;
  5155.                                 int alldone;
  5156.                                 alldone=0;
  5157.                                 startpoint=11;
  5158.                                 j=startpoint;
  5159.                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  5160.                                     mapname[j-startpoint]=consoletext[0][j];
  5161.                                     j++;
  5162.                                     if(consoletext[0][j]=='\0')alldone=1;
  5163.                                 }
  5164.                                 mapname[j-startpoint]='\0';
  5165.  
  5166.                                 player[0].protectionhead=atof(mapname);
  5167.  
  5168.                                 j++;
  5169.                                 startpoint=j;
  5170.                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  5171.                                     mapname[j-startpoint]=consoletext[0][j];
  5172.                                     j++;
  5173.                                     if(consoletext[0][j]=='\0')alldone=1;
  5174.                                 }
  5175.                                 mapname[j-startpoint]='\0';
  5176.  
  5177.                                 player[0].protectionhigh=atof(mapname);
  5178.  
  5179.                                 j++;
  5180.                                 startpoint=j;
  5181.                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  5182.                                     mapname[j-startpoint]=consoletext[0][j];
  5183.                                     j++;
  5184.                                     if(consoletext[0][j]=='\0')alldone=1;
  5185.                                 }
  5186.                                 mapname[j-startpoint]='\0';
  5187.  
  5188.                                 player[0].protectionlow=atof(mapname);
  5189.  
  5190.                                 donesomething=1;
  5191.                             }
  5192.  
  5193.                             if(Compare(consoletext[0],"armor ",0,5)||Compare(consoletext[0],"Armor ",0,5)){
  5194.                                 int startpoint;
  5195.                                 int alldone;
  5196.                                 alldone=0;
  5197.                                 startpoint=6;
  5198.                                 j=startpoint;
  5199.                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  5200.                                     mapname[j-startpoint]=consoletext[0][j];
  5201.                                     j++;
  5202.                                     if(consoletext[0][j]=='\0')alldone=1;
  5203.                                 }
  5204.                                 mapname[j-startpoint]='\0';
  5205.  
  5206.                                 player[0].armorhead=atof(mapname);
  5207.  
  5208.                                 j++;
  5209.                                 startpoint=j;
  5210.                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  5211.                                     mapname[j-startpoint]=consoletext[0][j];
  5212.                                     j++;
  5213.                                     if(consoletext[0][j]=='\0')alldone=1;
  5214.                                 }
  5215.                                 mapname[j-startpoint]='\0';
  5216.  
  5217.                                 player[0].armorhigh=atof(mapname);
  5218.  
  5219.                                 j++;
  5220.                                 startpoint=j;
  5221.                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  5222.                                     mapname[j-startpoint]=consoletext[0][j];
  5223.                                     j++;
  5224.                                     if(consoletext[0][j]=='\0')alldone=1;
  5225.                                 }
  5226.                                 mapname[j-startpoint]='\0';
  5227.  
  5228.                                 player[0].armorlow=atof(mapname);
  5229.  
  5230.                                 donesomething=1;
  5231.                             }
  5232.  
  5233.                             if(Compare(consoletext[0],"protectionreset ",0,15)||Compare(consoletext[0],"Protectionreset ",0,15)){
  5234.                                 for(i=0;i<numplayers;i++){
  5235.                                     player[i].protectionhead=1.0;
  5236.                                     player[i].protectionhigh=1.0;
  5237.                                     player[i].protectionlow=1.0;
  5238.                                     player[i].armorhead=1.0;
  5239.                                     player[i].armorhigh=1.0;
  5240.                                     player[i].armorlow=1.0;
  5241.                                 }
  5242.  
  5243.                                 donesomething=1;
  5244.                             }
  5245.  
  5246.                             if(Compare(consoletext[0],"protectionnear ",0,14)||Compare(consoletext[0],"Protectionnear ",0,14)){
  5247.                                 int closest=-1;
  5248.                                 float closestdist=-1;
  5249.                                 float distance;
  5250.                                 if(numplayers>1)
  5251.                                     for(i=1;i<numplayers;i++){
  5252.                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
  5253.                                         if(closestdist==-1||distance<closestdist){
  5254.                                             closestdist=distance;
  5255.                                             closest=i;
  5256.                                         }
  5257.                                     }
  5258.  
  5259.                                     int startpoint;
  5260.                                     int alldone;
  5261.                                     alldone=0;
  5262.                                     startpoint=15;
  5263.                                     j=startpoint;
  5264.                                     while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  5265.                                         mapname[j-startpoint]=consoletext[0][j];
  5266.                                         j++;
  5267.                                         if(consoletext[0][j]=='\0')alldone=1;
  5268.                                     }
  5269.                                     mapname[j-startpoint]='\0';
  5270.  
  5271.                                     player[closest].protectionhead=atof(mapname);
  5272.  
  5273.                                     j++;
  5274.                                     startpoint=j;
  5275.                                     while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  5276.                                         mapname[j-startpoint]=consoletext[0][j];
  5277.                                         j++;
  5278.                                         if(consoletext[0][j]=='\0')alldone=1;
  5279.                                     }
  5280.                                     mapname[j-startpoint]='\0';
  5281.  
  5282.                                     player[closest].protectionhigh=atof(mapname);
  5283.  
  5284.                                     j++;
  5285.                                     startpoint=j;
  5286.                                     while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  5287.                                         mapname[j-startpoint]=consoletext[0][j];
  5288.                                         j++;
  5289.                                         if(consoletext[0][j]=='\0')alldone=1;
  5290.                                     }
  5291.                                     mapname[j-startpoint]='\0';
  5292.  
  5293.                                     player[closest].protectionlow=atof(mapname);
  5294.  
  5295.                                     donesomething=1;
  5296.                             }
  5297.  
  5298.                             if(Compare(consoletext[0],"armornear ",0,9)||Compare(consoletext[0],"Armornear ",0,9)){
  5299.                                 int closest=-1;
  5300.                                 float closestdist=-1;
  5301.                                 float distance;
  5302.                                 if(numplayers>1)
  5303.                                     for(i=1;i<numplayers;i++){
  5304.                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
  5305.                                         if(closestdist==-1||distance<closestdist){
  5306.                                             closestdist=distance;
  5307.                                             closest=i;
  5308.                                         }
  5309.                                     }
  5310.                                     int startpoint;
  5311.                                     int alldone;
  5312.                                     alldone=0;
  5313.                                     startpoint=10;
  5314.                                     j=startpoint;
  5315.                                     while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  5316.                                         mapname[j-startpoint]=consoletext[0][j];
  5317.                                         j++;
  5318.                                         if(consoletext[0][j]=='\0')alldone=1;
  5319.                                     }
  5320.                                     mapname[j-startpoint]='\0';
  5321.  
  5322.                                     player[closest].armorhead=atof(mapname);
  5323.  
  5324.                                     j++;
  5325.                                     startpoint=j;
  5326.                                     while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  5327.                                         mapname[j-startpoint]=consoletext[0][j];
  5328.                                         j++;
  5329.                                         if(consoletext[0][j]=='\0')alldone=1;
  5330.                                     }
  5331.                                     mapname[j-startpoint]='\0';
  5332.  
  5333.                                     player[closest].armorhigh=atof(mapname);
  5334.  
  5335.                                     j++;
  5336.                                     startpoint=j;
  5337.                                     while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  5338.                                         mapname[j-startpoint]=consoletext[0][j];
  5339.                                         j++;
  5340.                                         if(consoletext[0][j]=='\0')alldone=1;
  5341.                                     }
  5342.                                     mapname[j-startpoint]='\0';
  5343.  
  5344.                                     player[closest].armorlow=atof(mapname);
  5345.  
  5346.                                     donesomething=1;
  5347.                             }
  5348.  
  5349.  
  5350.                             if(Compare(consoletext[0],"metal ",0,5)||Compare(consoletext[0],"Metal ",0,5)){
  5351.                                 int startpoint;
  5352.                                 int alldone;
  5353.                                 alldone=0;
  5354.                                 startpoint=6;
  5355.                                 j=startpoint;
  5356.                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  5357.                                     mapname[j-startpoint]=consoletext[0][j];
  5358.                                     j++;
  5359.                                     if(consoletext[0][j]=='\0')alldone=1;
  5360.                                 }
  5361.                                 mapname[j-startpoint]='\0';
  5362.  
  5363.                                 player[0].metalhead=atof(mapname);
  5364.  
  5365.                                 j++;
  5366.                                 startpoint=j;
  5367.                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  5368.                                     mapname[j-startpoint]=consoletext[0][j];
  5369.                                     j++;
  5370.                                     if(consoletext[0][j]=='\0')alldone=1;
  5371.                                 }
  5372.                                 mapname[j-startpoint]='\0';
  5373.  
  5374.                                 player[0].metalhigh=atof(mapname);
  5375.  
  5376.                                 j++;
  5377.                                 startpoint=j;
  5378.                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
  5379.                                     mapname[j-startpoint]=consoletext[0][j];
  5380.                                     j++;
  5381.                                     if(consoletext[0][j]=='\0')alldone=1;
  5382.                                 }
  5383.  
  5384.                                 mapname[j-startpoint]='\0';
  5385.  
  5386.                                 player[0].metallow=atof(mapname);
  5387.  
  5388.                                 donesomething=1;
  5389.                             }
  5390.  
  5391.                             if(Compare(consoletext[0],"noclothesnear ",0,13)||Compare(consoletext[0],"Noclothesnear ",0,13)){
  5392.                                 int closest=-1;
  5393.                                 float closestdist=-1;
  5394.                                 float distance;
  5395.                                 if(numplayers>1)
  5396.                                     for(i=1;i<numplayers;i++){
  5397.                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
  5398.                                         if(closestdist==-1||distance<closestdist){
  5399.                                             closestdist=distance;
  5400.                                             closest=i;
  5401.                                         }
  5402.                                     }
  5403.                                     player[closest].numclothes=0;
  5404.                                     if(player[closest].whichskin==0){
  5405.                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  5406.                                     }
  5407.                                     else if(player[closest].whichskin==1){
  5408.                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  5409.                                     }
  5410.                                     else if(player[closest].whichskin==2){
  5411.                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  5412.                                     }
  5413.                                     else if(player[closest].whichskin==3){
  5414.                                         LoadTextureSave(":Data:Textures:Lynx.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  5415.                                     }
  5416.                                     else if(player[closest].whichskin==4){
  5417.                                         LoadTextureSave(":Data:Textures:Otter.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  5418.                                     }
  5419.                                     else if(player[closest].whichskin==5){
  5420.                                         LoadTextureSave(":Data:Textures:Opal.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  5421.                                     }
  5422.                                     else if(player[closest].whichskin==6){
  5423.                                         LoadTextureSave(":Data:Textures:Sable.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  5424.                                     }
  5425.                                     else if(player[closest].whichskin==7){
  5426.                                         LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  5427.                                     }
  5428.                                     else if(player[closest].whichskin==8){
  5429.                                         LoadTextureSave(":Data:Textures:BW2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  5430.                                     }
  5431.                                     else if(player[closest].whichskin==9){
  5432.                                         LoadTextureSave(":Data:Textures:WB2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  5433.                                     }
  5434.  
  5435.                                     donesomething=1;
  5436.                             }
  5437.  
  5438.                             if(Compare(consoletext[0],"noclothes ",0,9)||Compare(consoletext[0],"Noclothes ",0,9)){
  5439.                                 int closest=0;
  5440.  
  5441.                                 player[closest].numclothes=0;
  5442.                                 if(player[closest].whichskin==0){
  5443.                                     LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  5444.                                 }
  5445.                                 else if(player[closest].whichskin==1){
  5446.                                     LoadTextureSave(":Data:Textures:Fur.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  5447.                                 }
  5448.                                 else if(player[closest].whichskin==2){
  5449.                                     LoadTextureSave(":Data:Textures:Fur2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  5450.                                 }
  5451.                                 else if(player[closest].whichskin==3){
  5452.                                     LoadTextureSave(":Data:Textures:Lynx.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  5453.                                 }
  5454.                                 else if(player[closest].whichskin==4){
  5455.                                     LoadTextureSave(":Data:Textures:Otter.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  5456.                                 }
  5457.                                 else if(player[closest].whichskin==5){
  5458.                                     LoadTextureSave(":Data:Textures:Opal.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  5459.                                 }
  5460.                                 else if(player[closest].whichskin==6){
  5461.                                     LoadTextureSave(":Data:Textures:Sable.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  5462.                                 }
  5463.                                 else if(player[closest].whichskin==7){
  5464.                                     LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  5465.                                 }
  5466.                                 else if(player[closest].whichskin==8){
  5467.                                     LoadTextureSave(":Data:Textures:BW2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  5468.                                 }
  5469.                                 else if(player[closest].whichskin==9){
  5470.                                     LoadTextureSave(":Data:Textures:WB2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  5471.                                 }
  5472.  
  5473.                                 donesomething=1;
  5474.                             }
  5475.  
  5476.                             if((Compare(consoletext[0],"Clothes ",0,7)||Compare(consoletext[0],"clothes ",0,7))){
  5477.                                 mapname[0]=':';
  5478.                                 mapname[1]='D';
  5479.                                 mapname[2]='a';
  5480.                                 mapname[3]='t';
  5481.                                 mapname[4]='a';
  5482.                                 mapname[5]=':';
  5483.                                 mapname[6]='T';
  5484.                                 mapname[7]='e';
  5485.                                 mapname[8]='x';
  5486.                                 mapname[9]='t';
  5487.                                 mapname[10]='u';
  5488.                                 mapname[11]='r';
  5489.                                 mapname[12]='e';
  5490.                                 mapname[13]='s';
  5491.                                 mapname[14]=':';
  5492.                                 for(j=8;j<consolechars[0];j++){
  5493.                                     mapname[j-8+15]=consoletext[0][j];
  5494.                                 }
  5495.                                 mapname[consolechars[0]-8+15]='.';
  5496.                                 mapname[consolechars[0]-8+16]='p';
  5497.                                 mapname[consolechars[0]-8+17]='n';
  5498.                                 mapname[consolechars[0]-8+18]='g';
  5499.                                 mapname[consolechars[0]-8+19]='\0';
  5500.  
  5501.                                 //:Data:Textures:Pants.png
  5502.  
  5503.                                 if(AddClothes((char *)mapname,0,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize)){
  5504.                                     player[0].DoMipmaps(5,0,0,player[0].skeleton.skinsize,player[0].skeleton.skinsize);
  5505.                                     strcpy(player[0].clothes[player[0].numclothes],mapname);
  5506.                                     player[0].clothestintr[player[0].numclothes]=tintr;
  5507.                                     player[0].clothestintg[player[0].numclothes]=tintg;
  5508.                                     player[0].clothestintb[player[0].numclothes]=tintb;
  5509.                                     player[0].numclothes++;
  5510.                                 }
  5511.  
  5512.                                 donesomething=1;
  5513.                             }
  5514.  
  5515.                             if(Compare(consoletext[0],"belt ",0,4)||Compare(consoletext[0],"belt ",0,4)){
  5516.                                 player[0].skeleton.clothes = 1-player[0].skeleton.clothes;
  5517.  
  5518.                                 donesomething=1;
  5519.                             }
  5520.  
  5521.                             if(Compare(consoletext[0],"Cellophane ",0,10)||Compare(consoletext[0],"cellophane ",0,10)){
  5522.                                 cellophane=1-cellophane;
  5523.  
  5524.                                 if(cellophane){
  5525.                                     for(i=0;i<numplayers;i++){
  5526.                                         player[i].proportionhead.z=0;
  5527.                                         player[i].proportionbody.z=0;
  5528.                                         player[i].proportionarms.z=0;
  5529.                                         player[i].proportionlegs.z=0;
  5530.                                     }
  5531.                                 }
  5532.  
  5533.                                 if(!cellophane){
  5534.                                     for(i=0;i<numplayers;i++){
  5535.                                         player[i].proportionhead.z=player[i].proportionhead.x;
  5536.                                         player[i].proportionbody.z=player[i].proportionbody.x;
  5537.                                         player[i].proportionarms.z=player[i].proportionarms.x;
  5538.                                         player[i].proportionlegs.z=player[i].proportionlegs.x;
  5539.                                     }
  5540.                                 }
  5541.  
  5542.                                 donesomething=1;
  5543.                             }
  5544.  
  5545.                             if((Compare(consoletext[0],"Clothesnear ",0,11)||Compare(consoletext[0],"clothesnear ",0,11))){
  5546.                                 mapname[0]=':';
  5547.                                 mapname[1]='D';
  5548.                                 mapname[2]='a';
  5549.                                 mapname[3]='t';
  5550.                                 mapname[4]='a';
  5551.                                 mapname[5]=':';
  5552.                                 mapname[6]='T';
  5553.                                 mapname[7]='e';
  5554.                                 mapname[8]='x';
  5555.                                 mapname[9]='t';
  5556.                                 mapname[10]='u';
  5557.                                 mapname[11]='r';
  5558.                                 mapname[12]='e';
  5559.                                 mapname[13]='s';
  5560.                                 mapname[14]=':';
  5561.                                 for(j=12;j<consolechars[0];j++){
  5562.                                     mapname[j-12+15]=consoletext[0][j];
  5563.                                 }
  5564.                                 mapname[consolechars[0]-12+15]='.';
  5565.                                 mapname[consolechars[0]-12+16]='p';
  5566.                                 mapname[consolechars[0]-12+17]='n';
  5567.                                 mapname[consolechars[0]-12+18]='g';
  5568.                                 mapname[consolechars[0]-12+19]='\0';
  5569.  
  5570.                                 //:Data:Textures:Pants.png
  5571.                                 int closest=-1;
  5572.                                 float closestdist=-1;
  5573.                                 float distance;
  5574.                                 if(numplayers>1)
  5575.                                     for(i=1;i<numplayers;i++){
  5576.                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
  5577.                                         if(closestdist==-1||distance<closestdist){
  5578.                                             closestdist=distance;
  5579.                                             closest=i;
  5580.                                         }
  5581.                                     }
  5582.  
  5583.                                     if(AddClothes((char *)mapname,0,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize)){
  5584.                                         player[closest].DoMipmaps(5,0,0,player[closest].skeleton.skinsize,player[closest].skeleton.skinsize);
  5585.                                         strcpy(player[closest].clothes[player[closest].numclothes],mapname);
  5586.                                         player[closest].clothestintr[player[closest].numclothes]=tintr;
  5587.                                         player[closest].clothestintg[player[closest].numclothes]=tintg;
  5588.                                         player[closest].clothestintb[player[closest].numclothes]=tintb;
  5589.                                         player[closest].numclothes++;
  5590.                                     }
  5591.  
  5592.                                     donesomething=1;
  5593.                             }
  5594.  
  5595.                             if(Compare(consoletext[0],"funnybunny ",0,10)||Compare(consoletext[0],"funny bunny ",0,11)){
  5596.                                 player[0].skeleton.id=0;
  5597.                                 player[0].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);
  5598.                                 LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
  5599.                                 player[0].creature=rabbittype;
  5600.                                 player[0].scale=.2;
  5601.  
  5602.                                 player[0].proportionhead=1.2;
  5603.                                 player[0].proportionbody=1.05;
  5604.                                 player[0].proportionarms=1.00;
  5605.                                 player[0].proportionlegs=1.1;
  5606.                                 player[0].proportionlegs.y=1.05;
  5607.                                 player[0].headless=0;
  5608.  
  5609.                                 player[0].damagetolerance=200;
  5610.  
  5611.                                 donesomething=1;
  5612.                             }
  5613.                             if(Compare(consoletext[0],"wolfieisgod ",0,11)||Compare(consoletext[0],"wolfie is god ",0,12)){
  5614.                                 player[0].skeleton.id=0;
  5615.                                 player[0].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);
  5616.                                 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
  5617.                                 player[0].creature=wolftype;
  5618.  
  5619.                                 player[0].proportionhead=1.1;
  5620.                                 player[0].proportionbody=1.1;
  5621.                                 player[0].proportionarms=1.1;
  5622.                                 player[0].proportionlegs=1.1;
  5623.                                 player[0].proportionlegs.y=1.1;
  5624.                                 player[0].scale=.23;
  5625.  
  5626.                                 player[0].damagetolerance=300;
  5627.  
  5628.                                 donesomething=1;
  5629.                             }
  5630.                             /*if(Compare(consoletext[0],"kungfu ",0,6)||Compare(consoletext[0],"kung fu ",0,7)){
  5631.                             LoadTextureSave(":Data:Textures:Kungfu.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
  5632.                             donesomething=1;
  5633.                             }
  5634.                             if(Compare(consoletext[0],"rambo ",0,5)){
  5635.                             LoadTextureSave(":Data:Textures:Leather.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
  5636.                             donesomething=1;
  5637.                             }
  5638.                             if(Compare(consoletext[0],"david ",0,5)){
  5639.                             LoadTextureSave(":Data:Textures:David.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
  5640.                             donesomething=1;
  5641.                             }*/
  5642.                             if(Compare(consoletext[0],"wolf ",0,4)){
  5643.                                 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
  5644.                                 donesomething=1;
  5645.                             }
  5646.                             if(Compare(consoletext[0],"darkwolf ",0,8)){
  5647.                                 LoadTextureSave(":Data:Textures:DarkWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
  5648.                                 donesomething=1;
  5649.                             }
  5650.                             if(Compare(consoletext[0],"snowwolf ",0,8)){
  5651.                                 LoadTextureSave(":Data:Textures:Snowwolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
  5652.                                 donesomething=1;
  5653.                             }/*
  5654.                              if(Compare(consoletext[0],"lizardwolf ",0,10)){
  5655.                              LoadTextureSave(":Data:Textures:Lizardwolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
  5656.                              donesomething=1;
  5657.                              }*/
  5658.                             if(Compare(consoletext[0],"white ",0,5)){
  5659.                                 LoadTextureSave(":Data:Textures:fur.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
  5660.                                 donesomething=1;
  5661.                             }
  5662.                             if(Compare(consoletext[0],"brown ",0,5)){
  5663.                                 LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
  5664.                                 donesomething=1;
  5665.                             }
  5666.                             if(Compare(consoletext[0],"black ",0,5)){
  5667.                                 LoadTextureSave(":Data:Textures:fur2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
  5668.                                 donesomething=1;
  5669.                             }
  5670.                             if(consolechars[0]>0){
  5671.                                 for(k=14;k>=1;k--){
  5672.                                     for(j=0;j<255;j++){
  5673.                                         consoletext[k][j]=consoletext[k-1][j];
  5674.                                     }
  5675.                                     consolechars[k]=consolechars[k-1];
  5676.                                 }
  5677.                                 for(j=0;j<255;j++){
  5678.                                     consoletext[0][j]=' ';
  5679.                                 }
  5680.                                 consolechars[0]=0;
  5681.                                 consoleselected=0;
  5682.  
  5683.                                 if(!donesomething){
  5684.                                     PlaySoundEx( consolefailsound, samp[consolefailsound], NULL, TRUE);
  5685.                                     FSOUND_SetVolume(channels[consolefailsound], 256);
  5686.                                     FSOUND_SetPaused(channels[consolefailsound], FALSE);
  5687.                                 }
  5688.                             }
  5689.                         }
  5690.                     }
  5691.                     togglekey[i]=1;
  5692.                 }
  5693.                 else {
  5694.                     togglekey[i]=0;
  5695.                     togglekeydelay[i]=0;
  5696.                 }
  5697.             }
  5698.  
  5699.             consoleblinkdelay-=multiplier;
  5700.             if(consoleblinkdelay<=0){
  5701.                 consoleblinkdelay=.3;
  5702.                 consoleblink=1-consoleblink;
  5703.             }
  5704.         }
  5705.  
  5706.         if(IsKeyDown(theKeyMap, MAC_Q_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)){
  5707.             tryquit=1;
  5708.             if(mainmenu==3){
  5709.                 if(newdetail>2)newdetail=detail;
  5710.                 if(newdetail<0)newdetail=detail;
  5711. #if !USE_SDL  // we'll take anything that works.
  5712.                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
  5713.                 if(newscreenheight>3000)newscreenheight=screenheight;
  5714. #endif
  5715.                 if(newscreenwidth<0)newscreenwidth=screenwidth;
  5716.                 if(newscreenheight<0)newscreenheight=screenheight;
  5717.  
  5718.                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
  5719.                 opstream << "Screenwidth:\n";
  5720.                 opstream << newscreenwidth;
  5721.                 opstream << "\nScreenheight:\n";
  5722.                 opstream << newscreenheight;
  5723.                 opstream << "\nMouse sensitivity:\n";
  5724.                 opstream << usermousesensitivity;
  5725.                 opstream << "\nBlur(0,1):\n";
  5726.                 opstream << ismotionblur;
  5727.                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
  5728.                 opstream << newdetail;
  5729.                 opstream << "\nFloating jump:\n";
  5730.                 opstream << floatjump;
  5731.                 opstream << "\nMouse jump:\n";
  5732.                 opstream << mousejump;
  5733.                 opstream << "\nAmbient sound:\n";
  5734.                 opstream << ambientsound;
  5735.                 opstream << "\nBlood (0,1,2):\n";
  5736.                 opstream << bloodtoggle;
  5737.                 opstream << "\nAuto slomo:\n";
  5738.                 opstream << autoslomo;
  5739.                 opstream << "\nFoliage:\n";
  5740.                 opstream << foliage;
  5741.                 opstream << "\nMusic:\n";
  5742.                 opstream << musictoggle;
  5743.                 opstream << "\nTrilinear:\n";
  5744.                 opstream << trilinear;
  5745.                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
  5746.                 opstream << decals;
  5747.                 opstream << "\nInvert mouse:\n";
  5748.                 opstream << invertmouse;
  5749.                 opstream << "\nGamespeed:\n";
  5750.                 if(oldgamespeed==0)oldgamespeed=1;
  5751.                 opstream << oldgamespeed;
  5752.                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
  5753.                 opstream << difficulty;
  5754.                 opstream << "\nDamage effects(blackout, doublevision):\n";
  5755.                 opstream << damageeffects;
  5756.                 opstream << "\nText:\n";
  5757.                 opstream << texttoggle;
  5758.                 opstream << "\nDebug:\n";
  5759.                 opstream << debugmode;
  5760.                 opstream << "\nVBL Sync:\n";
  5761.                 opstream << vblsync;
  5762.                 opstream << "\nShow Points:\n";
  5763.                 opstream << showpoints;
  5764.                 opstream << "\nAlways Blur:\n";
  5765.                 opstream << alwaysblur;
  5766.                 opstream << "\nImmediate mode (turn on on G5):\n";
  5767.                 opstream << immediate;
  5768.                 opstream << "\nVelocity blur:\n";
  5769.                 opstream << velocityblur;
  5770.                 opstream << "\nVolume:\n";
  5771.                 opstream << volume;
  5772.                 opstream << "\nForward key:\n";
  5773.                 opstream << KeyToChar(forwardkey);
  5774.                 opstream << "\nBack key:\n";
  5775.                 opstream << KeyToChar(backkey);
  5776.                 opstream << "\nLeft key:\n";
  5777.                 opstream << KeyToChar(leftkey);
  5778.                 opstream << "\nRight key:\n";
  5779.                 opstream << KeyToChar(rightkey);
  5780.                 opstream << "\nJump key:\n";
  5781.                 opstream << KeyToChar(jumpkey);
  5782.                 opstream << "\nCrouch key:\n";
  5783.                 opstream << KeyToChar(crouchkey);
  5784.                 opstream << "\nDraw key:\n";
  5785.                 opstream << KeyToChar(drawkey);
  5786.                 opstream << "\nThrow key:\n";
  5787.                 opstream << KeyToChar(throwkey);
  5788.                 opstream << "\nAttack key:\n";
  5789.                 opstream << KeyToChar(attackkey);
  5790.                 opstream << "\nChat key:\n";
  5791.                 opstream << KeyToChar(chatkey);
  5792.                 opstream.close();
  5793.             }
  5794.         }
  5795.  
  5796.         static int oldwinfreeze;
  5797.         if(winfreeze&&!oldwinfreeze){
  5798.             FSOUND_SetFrequency(FSOUND_ALL, 0.001);
  5799.             PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
  5800.             FSOUND_SetVolume(channels[consolesuccesssound], 256);
  5801.             FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
  5802.         }
  5803.         if(winfreeze==0)oldwinfreeze=winfreeze;
  5804.         else oldwinfreeze++;
  5805.  
  5806.         if((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY))&&!oldjumpkeydown&&!campaign){
  5807.             if(winfreeze)winfreeze=0;
  5808.             oldjumpkeydown=1;
  5809.         }
  5810.         if((IsKeyDown(theKeyMap, MAC_ESCAPE_KEY))&&!campaign&&gameon){
  5811.             if(winfreeze){
  5812.                 mainmenu=9;
  5813.                 gameon=0;
  5814.             }
  5815.         }
  5816.         if((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY))){
  5817.             oldjumpkeydown=1;
  5818.         }
  5819.         if(!IsKeyDown(theKeyMap, jumpkey)&&!IsKeyDown(theKeyMap, MAC_SPACE_KEY))oldjumpkeydown=0;
  5820.  
  5821.         if(!freeze&&!winfreeze&&!(mainmenu&&gameon)&&(gameon||!gamestarted)){
  5822.  
  5823.             static bool oldbuttondialogue;
  5824.  
  5825.             if(indialogue!=-1)talkdelay=1;
  5826.             talkdelay-=multiplier;
  5827.  
  5828.             if(talkdelay<=0)
  5829.                 if(indialogue==-1&&(animation[player[0].targetanimation].height!=highheight)/*&&!hostile*/)
  5830.                     for(i=0;i<numdialogues;i++){
  5831.                         int realdialoguetype;
  5832.                         bool special;
  5833.                         if(dialoguetype[i]>49){
  5834.                             realdialoguetype=dialoguetype[i]-50;
  5835.                             special=1;
  5836.                         }
  5837.                         else if(dialoguetype[i]>39){
  5838.                             realdialoguetype=dialoguetype[i]-40;
  5839.                             special=1;
  5840.                         }
  5841.                         else if(dialoguetype[i]>29){
  5842.                             realdialoguetype=dialoguetype[i]-30;
  5843.                             special=1;
  5844.                         }
  5845.                         else if(dialoguetype[i]>19){
  5846.                             realdialoguetype=dialoguetype[i]-20;
  5847.                             special=1;
  5848.                         }
  5849.                         else if(dialoguetype[i]>9){
  5850.                             realdialoguetype=dialoguetype[i]-10;
  5851.                             special=1;
  5852.                         }
  5853.                         else {
  5854.                             realdialoguetype=dialoguetype[i];
  5855.                             special=0;
  5856.                         }
  5857.                         if((!hostile||(dialoguetype[i]>40&&dialoguetype[i]<50))&&realdialoguetype<numplayers&&realdialoguetype>0&&(dialoguegonethrough[i]==0||!special)&&(special||(IsKeyDown(theKeyMap, attackkey)&&!oldbuttondialogue))){
  5858.                             if(findDistancefast(&player[0].coords,&player[realdialoguetype].coords)<6||player[realdialoguetype].howactive>=typedead1||(dialoguetype[i]>40&&dialoguetype[i]<50)){
  5859.                                 whichdialogue=i;
  5860.                                 for(j=0;j<numdialogueboxes[whichdialogue];j++){
  5861.                                     player[participantfocus[whichdialogue][j]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][j]];
  5862.                                     player[participantfocus[whichdialogue][j]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
  5863.                                     player[participantfocus[whichdialogue][j]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
  5864.                                     player[participantfocus[whichdialogue][j]].velocity=0;
  5865.                                     player[participantfocus[whichdialogue][j]].targetanimation=player[participantfocus[whichdialogue][j]].getIdle();
  5866.                                     player[participantfocus[whichdialogue][j]].targetframe=0;
  5867.                                 }
  5868.                                 directing=0;
  5869.                                 indialogue=0;
  5870.                                 dialoguetime=0;
  5871.                                 dialoguegonethrough[i]++;
  5872.                                 if(dialogueboxsound[whichdialogue][indialogue]!=0){
  5873.                                     static float gLoc[3];
  5874.                                     static float vel[3];
  5875.                                     XYZ temppos;
  5876.                                     temppos=player[participantfocus[whichdialogue][indialogue]].coords;
  5877.                                     temppos=temppos-viewer;
  5878.                                     Normalise(&temppos);
  5879.                                     temppos+=viewer;
  5880.  
  5881.                                     gLoc[0]=temppos.x;
  5882.                                     gLoc[1]=temppos.y;
  5883.                                     gLoc[2]=temppos.z;vel[0]=0;
  5884.                                     vel[1]=0;
  5885.                                     vel[2]=0;
  5886.                                     int whichsoundplay;
  5887.                                     if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
  5888.                                     if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
  5889.                                     if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
  5890.                                     if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
  5891.                                     if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
  5892.                                     if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
  5893.                                     if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
  5894.                                     if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
  5895.                                     if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
  5896.                                     if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
  5897.                                     if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
  5898.                                     if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
  5899.                                     if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
  5900.                                     if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
  5901.                                     if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
  5902.                                     if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
  5903.                                     if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
  5904.                                     if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
  5905.                                     if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
  5906.                                     if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
  5907.                                     PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, TRUE);
  5908.                                     FSOUND_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
  5909.                                     FSOUND_SetVolume(channels[whichsoundplay], 256);
  5910.                                     FSOUND_SetPaused(channels[whichsoundplay], FALSE);
  5911.                                 }
  5912.                                 if(IsKeyDown(theKeyMap, attackkey))oldbuttondialogue=1;
  5913.                             }
  5914.                         }
  5915.                     }
  5916.  
  5917.                     windvar+=multiplier;
  5918.                     smoketex+=multiplier;
  5919.                     tutorialstagetime+=multiplier;
  5920.  
  5921.                     static float hotspotvisual[40];
  5922.                     if(numhotspots){
  5923.                         XYZ hotspotsprite;
  5924.                         if(editorenabled)
  5925.                             for(i=0;i<numhotspots;i++)
  5926.                                 hotspotvisual[i]-=multiplier/320;
  5927.  
  5928.                         for(i=0;i<numhotspots;i++){
  5929.                             //if(hotspottype[i]<=10)
  5930.                             while(hotspotvisual[i]<0){
  5931.                                 hotspotsprite=0;
  5932.                                 hotspotsprite.x=float(abs(Random()%100000))/100000*hotspotsize[i];
  5933.                                 hotspotsprite=DoRotation(hotspotsprite,0,0,Random()%360);
  5934.                                 hotspotsprite=DoRotation(hotspotsprite,0,Random()%360,0);
  5935.                                 hotspotsprite+=hotspot[i];
  5936.                                 sprites.MakeSprite(breathsprite, hotspotsprite, hotspotsprite*0, 1,0.5,0, 7, 0.4);
  5937.                                 hotspotvisual[i]+=0.1/hotspotsize[i]/hotspotsize[i]/hotspotsize[i];
  5938.                             }              
  5939.                         }
  5940.  
  5941.                         for(i=0;i<numhotspots;i++){
  5942.                             if(hotspottype[i]<=10&&hotspottype[i]>0){
  5943.                                 hotspot[i]=player[hotspottype[i]].coords;
  5944.                             }
  5945.                         }
  5946.                     }
  5947.  
  5948.                     //Tutorial
  5949.                     if(tutoriallevel&&tutorialstagetime>tutorialmaxtime){
  5950.                         tutorialstage++;
  5951.                         tutorialsuccess=0;
  5952.                         if(tutorialstage<=1){
  5953.                             canattack=0;
  5954.                             cananger=0;
  5955.                             reversaltrain=0;
  5956.                         }
  5957.                         if(tutorialstage==1){
  5958.                             tutorialmaxtime=5;
  5959.                         }
  5960.                         if(tutorialstage==2){
  5961.                             tutorialmaxtime=2;
  5962.                         }
  5963.                         if(tutorialstage==3){
  5964.                             tutorialmaxtime=600;
  5965.                         }
  5966.                         if(tutorialstage==4){
  5967.                             tutorialmaxtime=1000;
  5968.                         }
  5969.                         if(tutorialstage==5){
  5970.                             tutorialmaxtime=600;
  5971.                         }
  5972.                         if(tutorialstage==6){
  5973.                             tutorialmaxtime=600;
  5974.                         }
  5975.                         if(tutorialstage==7){
  5976.                             tutorialmaxtime=600;
  5977.                         }
  5978.                         if(tutorialstage==8){
  5979.                             tutorialmaxtime=600;
  5980.                         }
  5981.                         if(tutorialstage==9){
  5982.                             tutorialmaxtime=600;
  5983.                         }
  5984.                         if(tutorialstage==10){
  5985.                             tutorialmaxtime=2;
  5986.                         }
  5987.                         if(tutorialstage==11){
  5988.                             tutorialmaxtime=1000;
  5989.                         }
  5990.                         if(tutorialstage==12){
  5991.                             tutorialmaxtime=1000;
  5992.                         }
  5993.                         if(tutorialstage==13){
  5994.                             tutorialmaxtime=2;
  5995.                         }
  5996.                         if(tutorialstage==14){
  5997.                             tutorialmaxtime=3;
  5998.  
  5999.                             XYZ temp,temp2;
  6000.  
  6001.                             temp.x=1011;
  6002.                             temp.y=84;
  6003.                             temp.z=491;
  6004.                             temp2.x=1025;
  6005.                             temp2.y=75;
  6006.                             temp2.z=447;
  6007.  
  6008.                             player[1].coords=(temp+temp2)/2;
  6009.  
  6010.                             float gLoc[3];
  6011.                             float vel[3];
  6012.                             gLoc[0]=player[1].coords.x;
  6013.                             gLoc[1]=player[1].coords.y;
  6014.                             gLoc[2]=player[1].coords.z;
  6015.                             vel[0]=0;
  6016.                             vel[1]=0;
  6017.                             vel[2]=0;
  6018.                             PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
  6019.                             FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  6020.                             FSOUND_SetVolume(channels[fireendsound], 256);
  6021.                             FSOUND_SetPaused(channels[fireendsound], FALSE);
  6022.  
  6023.                             for(i=0;i<player[1].skeleton.num_joints;i++){
  6024.                                 if(Random()%2==0){
  6025.                                     if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
  6026.                                     if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
  6027.                                     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;
  6028.                                     if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
  6029.                                     sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
  6030.                                 }
  6031.                             }
  6032.  
  6033.                         }
  6034.                         if(tutorialstage==15){
  6035.                             tutorialmaxtime=500;
  6036.                         }
  6037.                         if(tutorialstage==16){
  6038.                             tutorialmaxtime=500;
  6039.                         }
  6040.                         if(tutorialstage==17){
  6041.                             tutorialmaxtime=500;
  6042.                         }
  6043.                         if(tutorialstage==18){
  6044.                             tutorialmaxtime=500;
  6045.                         }
  6046.                         if(tutorialstage==19){
  6047.                             tutorialstage=20;
  6048.                             //tutorialmaxtime=500;
  6049.                         }
  6050.                         if(tutorialstage==20){
  6051.                             tutorialmaxtime=500;
  6052.                         }
  6053.                         if(tutorialstage==21){
  6054.                             tutorialmaxtime=500;
  6055.                             if(bonus==cannon){
  6056.                                 bonus=Slicebonus;
  6057.                                 againbonus=1;
  6058.                             }
  6059.                             else againbonus=0;
  6060.                         }
  6061.                         if(tutorialstage==22){
  6062.                             tutorialmaxtime=500;
  6063.                         }
  6064.                         if(tutorialstage==23){
  6065.                             tutorialmaxtime=500;
  6066.                         }
  6067.                         if(tutorialstage==24){
  6068.                             tutorialmaxtime=500;
  6069.                         }
  6070.                         if(tutorialstage==25){
  6071.                             tutorialmaxtime=500;
  6072.                         }
  6073.                         if(tutorialstage==26){
  6074.                             tutorialmaxtime=2;
  6075.                         }
  6076.                         if(tutorialstage==27){
  6077.                             tutorialmaxtime=4;
  6078.                             reversaltrain=1;
  6079.                             cananger=1;
  6080.                             player[1].aitype=attacktypecutoff;
  6081.                         }
  6082.                         if(tutorialstage==28){
  6083.                             tutorialmaxtime=400;
  6084.                         }
  6085.                         if(tutorialstage==29){
  6086.                             tutorialmaxtime=400;
  6087.                             player[0].escapednum=0;
  6088.                         }
  6089.                         if(tutorialstage==30){
  6090.                             tutorialmaxtime=4;
  6091.                             reversaltrain=0;
  6092.                             cananger=0;
  6093.                             player[1].aitype=passivetype;
  6094.                         }
  6095.                         if(tutorialstage==31){
  6096.                             tutorialmaxtime=13;
  6097.                         }
  6098.                         if(tutorialstage==32){
  6099.                             tutorialmaxtime=8;
  6100.                         }
  6101.                         if(tutorialstage==33){
  6102.                             tutorialmaxtime=400;
  6103.                             cananger=1;
  6104.                             canattack=1;
  6105.                             player[1].aitype=attacktypecutoff;
  6106.                         }
  6107.                         if(tutorialstage==34){
  6108.                             tutorialmaxtime=400;
  6109.                         }
  6110.                         if(tutorialstage==35){
  6111.                             tutorialmaxtime=400;
  6112.                         }
  6113.                         if(tutorialstage==36){
  6114.                             tutorialmaxtime=2;
  6115.                             reversaltrain=0;
  6116.                             cananger=0;
  6117.                             player[1].aitype=passivetype;
  6118.                         }
  6119.                         if(tutorialstage==37){
  6120.                             damagedealt=0;
  6121.                             damagetaken=0;
  6122.                             tutorialmaxtime=50;
  6123.                             cananger=1;
  6124.                             canattack=1;
  6125.                             player[1].aitype=attacktypecutoff;
  6126.                         }
  6127.                         if(tutorialstage==38){
  6128.                             tutorialmaxtime=4;
  6129.                             canattack=0;
  6130.                             cananger=0;
  6131.                             player[1].aitype=passivetype;
  6132.                         }
  6133.                         if(tutorialstage==39){
  6134.                             XYZ temp,temp2;
  6135.  
  6136.                             temp.x=1011;
  6137.                             temp.y=84;
  6138.                             temp.z=491;
  6139.                             temp2.x=1025;
  6140.                             temp2.y=75;
  6141.                             temp2.z=447;
  6142.  
  6143.  
  6144.                             weapons.owner[weapons.numweapons]=-1;
  6145.                             weapons.type[weapons.numweapons]=knife;
  6146.                             weapons.damage[weapons.numweapons]=0;
  6147.                             weapons.mass[weapons.numweapons]=1;
  6148.                             weapons.tipmass[weapons.numweapons]=1.2;
  6149.                             weapons.length[weapons.numweapons]=.25;
  6150.                             weapons.position[weapons.numweapons]=(temp+temp2)/2;
  6151.                             weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
  6152.  
  6153.                             weapons.velocity[weapons.numweapons]=0.1;
  6154.                             weapons.tipvelocity[weapons.numweapons]=0.1;
  6155.                             weapons.missed[weapons.numweapons]=1;
  6156.                             weapons.hitsomething[weapons.numweapons]=0;
  6157.                             weapons.freetime[weapons.numweapons]=0;
  6158.                             weapons.firstfree[weapons.numweapons]=1;
  6159.                             weapons.physics[weapons.numweapons]=1;
  6160.  
  6161.                             weapons.numweapons++;
  6162.                         }
  6163.                         if(tutorialstage==40){
  6164.                             tutorialmaxtime=300;
  6165.                         }
  6166.                         if(tutorialstage==41){
  6167.                             tutorialmaxtime=300;
  6168.                         }
  6169.                         if(tutorialstage==42){
  6170.                             tutorialmaxtime=8;
  6171.                         }
  6172.                         if(tutorialstage==43){
  6173.                             tutorialmaxtime=300;
  6174.                         }
  6175.                         if(tutorialstage==44){
  6176.                             weapons.owner[0]=1;
  6177.                             player[0].weaponactive=-1;
  6178.                             player[0].num_weapons=0;
  6179.                             player[1].weaponactive=0;
  6180.                             player[1].num_weapons=1;
  6181.                             player[1].weaponids[0]=0;
  6182.  
  6183.                             cananger=1;
  6184.                             canattack=1;
  6185.                             player[1].aitype=attacktypecutoff;
  6186.  
  6187.                             tutorialmaxtime=300;
  6188.                         }
  6189.                         if(tutorialstage==45){
  6190.                             weapons.owner[0]=1;
  6191.                             player[0].weaponactive=-1;
  6192.                             player[0].num_weapons=0;
  6193.                             player[1].weaponactive=0;
  6194.                             player[1].num_weapons=1;
  6195.                             player[1].weaponids[0]=0;
  6196.  
  6197.                             tutorialmaxtime=300;
  6198.                         }
  6199.                         if(tutorialstage==46){
  6200.                             weapons.owner[0]=1;
  6201.                             player[0].weaponactive=-1;
  6202.                             player[0].num_weapons=0;
  6203.                             player[1].weaponactive=0;
  6204.                             player[1].num_weapons=1;
  6205.                             player[1].weaponids[0]=0;
  6206.  
  6207.                             weapons.type[0]=sword;
  6208.  
  6209.                             tutorialmaxtime=300;
  6210.                         }
  6211.  
  6212.                         if(tutorialstage==47){
  6213.                             tutorialmaxtime=10;
  6214.  
  6215.                             XYZ temp,temp2;
  6216.  
  6217.                             temp.x=1011;
  6218.                             temp.y=84;
  6219.                             temp.z=491;
  6220.                             temp2.x=1025;
  6221.                             temp2.y=75;
  6222.                             temp2.z=447;
  6223.  
  6224.                             weapons.owner[weapons.numweapons]=-1;
  6225.                             weapons.type[weapons.numweapons]=sword;
  6226.                             weapons.damage[weapons.numweapons]=0;
  6227.                             weapons.mass[weapons.numweapons]=1;
  6228.                             weapons.tipmass[weapons.numweapons]=1.2;
  6229.                             weapons.length[weapons.numweapons]=.25;
  6230.                             weapons.position[weapons.numweapons]=(temp+temp2)/2;
  6231.                             weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
  6232.  
  6233.                             weapons.velocity[weapons.numweapons]=0.1;
  6234.                             weapons.tipvelocity[weapons.numweapons]=0.1;
  6235.                             weapons.missed[weapons.numweapons]=1;
  6236.                             weapons.hitsomething[weapons.numweapons]=0;
  6237.                             weapons.freetime[weapons.numweapons]=0;
  6238.                             weapons.firstfree[weapons.numweapons]=1;
  6239.                             weapons.physics[weapons.numweapons]=1;
  6240.  
  6241.                             weapons.owner[0]=1;
  6242.                             weapons.owner[1]=0;
  6243.                             player[0].weaponactive=0;
  6244.                             player[0].num_weapons=1;
  6245.                             player[0].weaponids[0]=1;  
  6246.                             player[1].weaponactive=0;
  6247.                             player[1].num_weapons=1;
  6248.                             player[1].weaponids[0]=0;  
  6249.  
  6250.                             weapons.numweapons++;
  6251.                         }
  6252.                         if(tutorialstage==48){
  6253.                             canattack=0;
  6254.                             cananger=0;
  6255.                             player[1].aitype=passivetype;
  6256.  
  6257.                             tutorialmaxtime=15;
  6258.  
  6259.                             weapons.owner[0]=1;
  6260.                             weapons.owner[1]=0;
  6261.                             player[0].weaponactive=0;
  6262.                             player[0].num_weapons=1;
  6263.                             player[0].weaponids[0]=1;  
  6264.                             player[1].weaponactive=0;
  6265.                             player[1].num_weapons=1;
  6266.                             player[1].weaponids[0]=0;
  6267.  
  6268.                             if(player[0].weaponactive!=-1)weapons.type[player[0].weaponids[player[0].weaponactive]]=staff;
  6269.                             else weapons.type[0]=staff;
  6270.  
  6271.                             weapons.numweapons++;
  6272.                         }
  6273.                         if(tutorialstage==49){
  6274.                             canattack=0;
  6275.                             cananger=0;
  6276.                             player[1].aitype=passivetype;
  6277.  
  6278.                             tutorialmaxtime=200;
  6279.  
  6280.                             weapons.position[1]=1000;
  6281.                             weapons.tippoint[1]=1000;
  6282.  
  6283.                             weapons.numweapons=1;
  6284.                             weapons.owner[0]=0;
  6285.                             player[1].weaponactive=-1;
  6286.                             player[1].num_weapons=0;
  6287.                             player[0].weaponactive=0;
  6288.                             player[0].num_weapons=1;
  6289.                             player[0].weaponids[0]=0;  
  6290.  
  6291.                             weapons.type[0]=knife;
  6292.  
  6293.                             weapons.numweapons++;
  6294.                         }
  6295.                         if(tutorialstage==50){
  6296.                             tutorialmaxtime=8;
  6297.  
  6298.                             XYZ temp,temp2;
  6299.                             float gLoc[3];
  6300.                             float vel[3];
  6301.                             gLoc[0]=player[1].coords.x;
  6302.                             gLoc[1]=player[1].coords.y;
  6303.                             gLoc[2]=player[1].coords.z;
  6304.                             vel[0]=0;
  6305.                             vel[1]=0;
  6306.                             vel[2]=0;
  6307.                             PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
  6308.                             FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  6309.                             FSOUND_SetVolume(channels[fireendsound], 256);
  6310.                             FSOUND_SetPaused(channels[fireendsound], FALSE);
  6311.  
  6312.                             for(i=0;i<player[1].skeleton.num_joints;i++){
  6313.                                 if(Random()%2==0){
  6314.                                     if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
  6315.                                     if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
  6316.                                     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;
  6317.                                     if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
  6318.                                     sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
  6319.                                 }
  6320.                             }
  6321.  
  6322.                             player[1].num_weapons=0;
  6323.                             player[1].weaponstuck=-1;
  6324.                             player[1].weaponactive=-1;
  6325.  
  6326.                             weapons.numweapons=0;
  6327.  
  6328.                             weapons.owner[0]=-1;
  6329.                             weapons.velocity[0]=0.1;
  6330.                             weapons.tipvelocity[0]=-0.1;
  6331.                             weapons.missed[0]=1;
  6332.                             weapons.hitsomething[0]=0;
  6333.                             weapons.freetime[0]=0;
  6334.                             weapons.firstfree[0]=1;
  6335.                             weapons.physics[0]=1;
  6336.                         }
  6337.                         if(tutorialstage==51){
  6338.                             tutorialmaxtime=80000;
  6339.                         }
  6340.                         if(tutorialstage<=51)tutorialstagetime=0;
  6341.                     }
  6342.  
  6343.                     //Tutorial success
  6344.                     if(tutoriallevel&&tutorialstagetime<tutorialmaxtime-3){
  6345.                         if(tutorialstage==3){
  6346.                             if(deltah||deltav)tutorialsuccess+=multiplier;
  6347.                         }
  6348.                         if(tutorialstage==4){
  6349.                             if(player[0].forwardkeydown||player[0].backkeydown||player[0].leftkeydown||player[0].rightkeydown)tutorialsuccess+=multiplier;
  6350.                         }
  6351.                         if(tutorialstage==5){
  6352.                             if(player[0].jumpkeydown)tutorialsuccess=1;
  6353.                         }
  6354.                         if(tutorialstage==6){
  6355.                             if(player[0].isCrouch())tutorialsuccess=1;
  6356.                         }
  6357.                         if(tutorialstage==7){
  6358.                             if(player[0].targetanimation==rollanim)tutorialsuccess=1;
  6359.                         }
  6360.                         if(tutorialstage==8){
  6361.                             if(player[0].targetanimation==sneakanim)tutorialsuccess+=multiplier;
  6362.                         }
  6363.                         if(tutorialstage==9){
  6364.                             if(player[0].targetanimation==rabbitrunninganim||player[0].targetanimation==wolfrunninganim)tutorialsuccess+=multiplier;
  6365.                         }
  6366.                         if(tutorialstage==11){
  6367.                             if(player[0].isWallJump())tutorialsuccess=1;
  6368.                         }
  6369.                         if(tutorialstage==12){
  6370.                             if(player[0].targetanimation==flipanim)tutorialsuccess=1;
  6371.                         }
  6372.                         if(tutorialstage==15){
  6373.                             if(player[0].targetanimation==upunchanim||player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
  6374.                         }
  6375.                         if(tutorialstage==16){
  6376.                             if(player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
  6377.                         }
  6378.                         if(tutorialstage==17){
  6379.                             if(player[0].targetanimation==spinkickanim)tutorialsuccess=1;
  6380.                         }
  6381.                         if(tutorialstage==18){
  6382.                             if(player[0].targetanimation==sweepanim)tutorialsuccess=1;
  6383.                         }
  6384.                         if(tutorialstage==19){
  6385.                             if(player[0].targetanimation==dropkickanim)tutorialsuccess=1;
  6386.                         }
  6387.                         if(tutorialstage==20){
  6388.                             if(player[0].targetanimation==rabbitkickanim)tutorialsuccess=1;
  6389.                         }
  6390.                         if(tutorialstage==21){
  6391.                             if(bonus==cannon)tutorialsuccess=1;
  6392.                         }
  6393.                         if(tutorialstage==22){
  6394.                             if(bonus==spinecrusher)tutorialsuccess=1;
  6395.                         }
  6396.                         if(tutorialstage==23){
  6397.                             if(player[0].targetanimation==walljumprightkickanim||player[0].targetanimation==walljumpleftkickanim)tutorialsuccess=1;
  6398.                         }
  6399.                         if(tutorialstage==24){
  6400.                             if(player[0].targetanimation==rabbittacklinganim)tutorialsuccess=1;
  6401.                         }
  6402.                         if(tutorialstage==25){
  6403.                             if(player[0].targetanimation==backhandspringanim)tutorialsuccess=1;
  6404.                         }
  6405.                         if(tutorialstage==28){
  6406.                             if(animation[player[0].targetanimation].attack==reversed&&player[0].feint)tutorialsuccess=1;
  6407.                         }
  6408.                         if(tutorialstage==29){
  6409.                             if(player[0].escapednum==2){
  6410.                                 tutorialsuccess=1;
  6411.                                 reversaltrain=0;
  6412.                                 cananger=0;
  6413.                                 player[1].aitype=passivetype;
  6414.                             }
  6415.                         }
  6416.                         if(tutorialstage==33){
  6417.                             if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
  6418.                         }
  6419.                         if(tutorialstage==34){
  6420.                             if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
  6421.                         }
  6422.                         if(tutorialstage==35){
  6423.                             if(animation[player[0].targetanimation].attack==reversal){
  6424.                                 tutorialsuccess=1;
  6425.                                 reversaltrain=0;
  6426.                                 cananger=0;
  6427.                                 player[1].aitype=passivetype;
  6428.                             }
  6429.                         }
  6430.                         if(tutorialstage==40){
  6431.                             if(player[0].num_weapons>0)tutorialsuccess=1;
  6432.                         }
  6433.                         if(tutorialstage==41){
  6434.                             if(player[0].weaponactive==-1&&player[0].num_weapons>0)tutorialsuccess=1;
  6435.                         }
  6436.                         if(tutorialstage==43){
  6437.                             if(player[0].targetanimation==knifeslashstartanim)tutorialsuccess=1;
  6438.                         }
  6439.                         if(tutorialstage==44){
  6440.                             if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
  6441.                         }
  6442.                         if(tutorialstage==45){
  6443.                             if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
  6444.                         }
  6445.                         if(tutorialstage==46){
  6446.                             if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
  6447.                         }
  6448.                         if(tutorialstage==49){
  6449.                             if(player[1].weaponstuck!=-1)tutorialsuccess=1;
  6450.                         }
  6451.                         if(tutorialsuccess>=1)tutorialstagetime=tutorialmaxtime-3;
  6452.  
  6453.  
  6454.                         if(tutorialstagetime==tutorialmaxtime-3){
  6455.                             PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
  6456.                             FSOUND_SetVolume(channels[consolesuccesssound], 256);
  6457.                             FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
  6458.                         }
  6459.  
  6460.                         if(tutorialsuccess>=1){
  6461.                             if(tutorialstage==34||tutorialstage==35)
  6462.                                 tutorialstagetime=tutorialmaxtime-1;
  6463.                         }
  6464.                     }
  6465.  
  6466.                     if(tutoriallevel){
  6467.                         if(tutorialstage<14||tutorialstage>=50){
  6468.                             player[1].coords.y=300;
  6469.                             player[1].velocity=0;
  6470.                         }
  6471.                     }
  6472.  
  6473.                     if(tutoriallevel!=1){
  6474.                         if(bonustime==0&&bonus!=solidhit&&bonus!=spinecrusher&&bonus!=tracheotomy&&bonus!=backstab&&bonusvalue>10){
  6475.                             PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
  6476.                             FSOUND_SetVolume(channels[consolesuccesssound], 256);
  6477.                             FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
  6478.                         }
  6479.                     }
  6480.                     else
  6481.                         if(bonustime==0){
  6482.                             PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
  6483.                             FSOUND_SetVolume(channels[fireendsound], 256);
  6484.                             FSOUND_SetPaused(channels[fireendsound], FALSE);
  6485.                         }
  6486.                         if(bonustime==0){
  6487.                             if(bonus!=solidhit&&bonus!=twoxcombo&&bonus!=threexcombo&&bonus!=fourxcombo&&bonus!=megacombo)bonusnum[bonus]++;
  6488.                             else bonusnum[bonus]+=0.15;
  6489.                             if(tutoriallevel)bonusvalue=0;
  6490.                             bonusvalue/=bonusnum[bonus];
  6491.                             bonustotal+=bonusvalue;
  6492.                         }
  6493.                         bonustime+=multiplier;
  6494.  
  6495.                         if(environment==snowyenvironment){
  6496.                             precipdelay-=multiplier;
  6497.                             while(precipdelay<0){
  6498.                                 precipdelay+=.04;
  6499.                                 if(!detail)precipdelay+=.04;
  6500.                                 XYZ footvel,footpoint;
  6501.  
  6502.                                 footvel=0;
  6503.                                 footpoint=viewer+viewerfacing*6;
  6504.                                 footpoint.y+=((float)abs(Random()%1200))/100-6;
  6505.                                 footpoint.x+=((float)abs(Random()%1200))/100-6;
  6506.                                 footpoint.z+=((float)abs(Random()%1200))/100-6;
  6507.                                 sprites.MakeSprite(snowsprite, footpoint,footvel, 1,1,1, .1, 1);
  6508.                             }
  6509.                         }
  6510.                         for(k=0;k<numplayers;k++){
  6511.                             if(player[k].aitype==playercontrolled)player[k].turnspeed=500;
  6512.                             if(player[k].aitype!=playercontrolled)player[k].turnspeed=500;
  6513.  
  6514.                             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){
  6515.                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
  6516.                                 else if(player[k].rotation>player[k].targetrotation){
  6517.                                     player[k].rotation-=multiplier*player[k].turnspeed;
  6518.                                 }
  6519.                                 else if(player[k].rotation<player[k].targetrotation){
  6520.                                     player[k].rotation+=multiplier*player[k].turnspeed;
  6521.                                 }
  6522.                             }
  6523.  
  6524.  
  6525.                             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))){
  6526.                                 player[k].turnspeed*=2;
  6527.                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
  6528.                                 else if(player[k].rotation>player[k].targetrotation){
  6529.                                     player[k].rotation-=multiplier*player[k].turnspeed;
  6530.                                 }
  6531.                                 else if(player[k].rotation<player[k].targetrotation){
  6532.                                     player[k].rotation+=multiplier*player[k].turnspeed;
  6533.                                 }
  6534.                                 player[k].turnspeed/=2;
  6535.                             }
  6536.  
  6537.                             if(player[k].targetanimation==sneakanim&&player[k].currentanimation!=sneakanim){
  6538.                                 player[k].turnspeed*=4;
  6539.                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
  6540.                                 else if(player[k].rotation>player[k].targetrotation){
  6541.                                     player[k].rotation-=multiplier*player[k].turnspeed;
  6542.                                 }
  6543.                                 else if(player[k].rotation<player[k].targetrotation){
  6544.                                     player[k].rotation+=multiplier*player[k].turnspeed;
  6545.                                 }
  6546.                                 player[k].turnspeed/=4;
  6547.                             }
  6548.  
  6549.                             /*if(player[k].aitype!=passivetype||(findDistancefast(&player[k].coords,&viewer)<viewdistance*viewdistance))*/  player[k].DoStuff();
  6550.                             if(player[k].immobile&&k!=0)player[k].coords=player[k].realoldcoords;
  6551.  
  6552.                             if(findDistancefast(&player[k].coords,&player[k].realoldcoords)>0){
  6553.                                 if(!player[k].skeleton.free&&player[k].targetanimation!=climbanim&&player[k].targetanimation!=hanganim){
  6554.                                     bool tempcollide=0;
  6555.  
  6556.                                     if(player[k].collide<-.3)player[k].collide=-.3;
  6557.                                     if(player[k].collide>1)player[k].collide=1;
  6558.                                     player[k].collide-=multiplier*30;
  6559.  
  6560.                                     if(player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z)){
  6561.                                         player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
  6562.                                     }
  6563.                                     if(terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz])
  6564.                                         for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
  6565.                                             i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
  6566.                                             if(objects.type[i]!=rocktype||(((objects.scale[i]>.5&&player[k].aitype==playercontrolled)||objects.position[i].y>player[k].coords.y))){
  6567.                                                 lowpoint=player[k].coords;
  6568.                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim&&!player[k].isFlip())lowpoint.y+=1.25;
  6569.                                                 else lowpoint.y+=1.3;
  6570.                                                 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){
  6571.                                                     player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
  6572.                                                 }
  6573.                                                 /*while(player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z))
  6574.                                                 player[k].coords+=terrain.getNormal(player[k].coords.x,player[k].coords.z)/50;
  6575.                                                 */
  6576.                                                 if(player[k].SphereCheck(&lowpoint, 1.3, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
  6577.                                                     flatfacing=lowpoint-player[k].coords;
  6578.                                                     player[k].coords=lowpoint;
  6579.                                                     player[k].coords.y-=1.3;
  6580.                                                     player[k].collide=1;
  6581.                                                     tempcollide=1;
  6582.                                                     if(player[k].aitype==playercontrolled&&(player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].jumptogglekeydown&&player[k].jumpkeydown){
  6583.                                                         lowpointtarget=lowpoint+DoRotation(player[k].facing,0,-90,0)*1.5;
  6584.                                                         tempcoords1=lowpoint;
  6585.                                                         whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
  6586.                                                         if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
  6587.                                                             player[k].target=0;
  6588.                                                             player[k].targetanimation=walljumpleftanim;
  6589.                                                             player[k].targetframe=0;
  6590.                                                             float gLoc[3];
  6591.                                                             float vel[3];
  6592.                                                             gLoc[0]=player[k].coords.x;
  6593.                                                             gLoc[1]=player[k].coords.y;
  6594.                                                             gLoc[2]=player[k].coords.z;
  6595.                                                             vel[0]=0;
  6596.                                                             vel[1]=0;
  6597.                                                             vel[2]=0;
  6598.                                                             PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, TRUE);
  6599.                                                             FSOUND_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
  6600.                                                             FSOUND_SetVolume(channels[movewhooshsound], 256);
  6601.                                                             FSOUND_SetPaused(channels[movewhooshsound], FALSE);
  6602.                                                             if(k==0)FSOUND_SetPaused(channels[whooshsound], TRUE);
  6603.  
  6604.                                                             lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
  6605.                                                             player[k].rotation=-asin(0-lowpointtarget.x);
  6606.                                                             player[k].rotation*=360/6.28;
  6607.                                                             if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
  6608.                                                             player[k].targetrotation=player[k].rotation;
  6609.                                                             player[k].lowrotation=player[k].rotation;
  6610.                                                             if(k==0)numwallflipped++;
  6611.                                                         }
  6612.                                                         else
  6613.                                                         {
  6614.                                                             lowpoint=tempcoords1;
  6615.                                                             lowpointtarget=lowpoint+DoRotation(player[k].facing,0,90,0)*1.5;
  6616.                                                             whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
  6617.                                                             if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
  6618.                                                                 player[k].target=0;
  6619.                                                                 player[k].targetanimation=walljumprightanim;
  6620.                                                                 player[k].targetframe=0;
  6621.                                                                 float gLoc[3];
  6622.                                                                 float vel[3];
  6623.                                                                 gLoc[0]=player[k].coords.x;
  6624.                                                                 gLoc[1]=player[k].coords.y;
  6625.                                                                 gLoc[2]=player[k].coords.z;
  6626.                                                                 vel[0]=0;
  6627.                                                                 vel[1]=0;
  6628.                                                                 vel[2]=0;
  6629.                                                                 PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, TRUE);
  6630.                                                                 FSOUND_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
  6631.                                                                 FSOUND_SetVolume(channels[movewhooshsound], 256);
  6632.                                                                 FSOUND_SetPaused(channels[movewhooshsound], FALSE);
  6633.                                                                 if(k==0)FSOUND_SetPaused(channels[whooshsound], TRUE);
  6634.  
  6635.                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
  6636.                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
  6637.                                                                 player[k].rotation*=360/6.28;
  6638.                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
  6639.                                                                 player[k].targetrotation=player[k].rotation;
  6640.                                                                 player[k].lowrotation=player[k].rotation;
  6641.                                                                 if(k==0)numwallflipped++;
  6642.                                                             }
  6643.                                                             else
  6644.                                                             {
  6645.                                                                 lowpoint=tempcoords1;
  6646.                                                                 lowpointtarget=lowpoint+player[k].facing*2;
  6647.                                                                 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
  6648.                                                                 if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
  6649.                                                                     player[k].target=0;
  6650.                                                                     player[k].targetanimation=walljumpbackanim;
  6651.                                                                     player[k].targetframe=0;
  6652.                                                                     float gLoc[3];
  6653.                                                                     float vel[3];
  6654.                                                                     gLoc[0]=player[k].coords.x;
  6655.                                                                     gLoc[1]=player[k].coords.y;
  6656.                                                                     gLoc[2]=player[k].coords.z;
  6657.                                                                     vel[0]=0;
  6658.                                                                     vel[1]=0;
  6659.                                                                     vel[2]=0;
  6660.                                                                     PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, TRUE);
  6661.                                                                     FSOUND_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
  6662.                                                                     FSOUND_SetVolume(channels[movewhooshsound], 256);
  6663.                                                                     FSOUND_SetPaused(channels[movewhooshsound], FALSE);
  6664.                                                                     if(k==0)FSOUND_SetPaused(channels[whooshsound], TRUE);
  6665.  
  6666.                                                                     lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
  6667.                                                                     player[k].rotation=-asin(0-lowpointtarget.x);
  6668.                                                                     player[k].rotation*=360/6.28;
  6669.                                                                     if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
  6670.                                                                     player[k].targetrotation=player[k].rotation;
  6671.                                                                     player[k].lowrotation=player[k].rotation;
  6672.                                                                     if(k==0)numwallflipped++;
  6673.                                                                 }
  6674.                                                                 else
  6675.                                                                 {
  6676.                                                                     lowpoint=tempcoords1;
  6677.                                                                     lowpointtarget=lowpoint-player[k].facing*2;
  6678.                                                                     whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
  6679.                                                                     if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
  6680.                                                                         player[k].target=0;
  6681.                                                                         player[k].targetanimation=walljumpfrontanim;
  6682.                                                                         player[k].targetframe=0;
  6683.                                                                         float gLoc[3];
  6684.                                                                         float vel[3];
  6685.                                                                         gLoc[0]=player[k].coords.x;
  6686.                                                                         gLoc[1]=player[k].coords.y;
  6687.                                                                         gLoc[2]=player[k].coords.z;
  6688.                                                                         vel[0]=0;
  6689.                                                                         vel[1]=0;
  6690.                                                                         vel[2]=0;
  6691.                                                                         PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, TRUE);
  6692.                                                                         FSOUND_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
  6693.                                                                         FSOUND_SetVolume(channels[movewhooshsound], 256);
  6694.                                                                         FSOUND_SetPaused(channels[movewhooshsound], FALSE);
  6695.                                                                         if(k==0)FSOUND_SetPaused(channels[whooshsound], TRUE);
  6696.  
  6697.                                                                         lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
  6698.                                                                         player[k].rotation=-asin(0-lowpointtarget.x);
  6699.                                                                         player[k].rotation*=360/6.28;
  6700.                                                                         if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
  6701.                                                                         player[k].rotation+=180;
  6702.                                                                         player[k].targetrotation=player[k].rotation;
  6703.                                                                         player[k].lowrotation=player[k].rotation;
  6704.                                                                         if(k==0)numwallflipped++;
  6705.                                                                     }
  6706.                                                                 }
  6707.                                                             }
  6708.                                                         }
  6709.                                                     }
  6710.                                                 }
  6711.                                             }
  6712.                                             else if(objects.type[i]==rocktype){
  6713.                                                 lowpoint2=player[k].coords;
  6714.                                                 lowpoint=player[k].coords;
  6715.                                                 lowpoint.y+=2;
  6716.                                                 if(objects.model[i].LineCheck(&lowpoint,&lowpoint2,&colpoint,&objects.position[i],&objects.rotation[i])!=-1){
  6717.                                                     player[k].coords=colpoint;
  6718.                                                     player[k].collide=1;
  6719.                                                     tempcollide=1;
  6720.  
  6721.                                                     if((player[k].targetanimation==jumpdownanim||player[k].isFlip())){
  6722.                                                         if(player[k].isFlip()&&animation[player[k].targetanimation].label[player[k].targetframe]==7)player[k].RagDoll(0);
  6723.  
  6724.                                                         if(player[k].targetanimation==jumpupanim){player[k].jumppower=-4;player[k].targetanimation=player[k].getIdle();}
  6725.                                                         player[k].target=0;
  6726.                                                         player[k].targetframe=0;   
  6727.                                                         player[k].onterrain=1;
  6728.  
  6729.                                                         if(player[k].id==0){
  6730.                                                             FSOUND_SetPaused(channels[whooshsound], TRUE);
  6731.                                                             FSOUND_SetVolume(channels[whooshsound], 0);
  6732.                                                         }
  6733.  
  6734.                                                         if((player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].wasLanding()){
  6735.                                                             if(player[k].isFlip())player[k].jumppower=-4;
  6736.                                                             player[k].targetanimation=player[k].getLanding();
  6737.                                                             float gLoc[3];
  6738.                                                             float vel[3];
  6739.                                                             gLoc[0]=player[k].coords.x;
  6740.                                                             gLoc[1]=player[k].coords.y;
  6741.                                                             gLoc[2]=player[k].coords.z;
  6742.                                                             vel[0]=player[k].velocity.x;
  6743.                                                             vel[1]=player[k].velocity.y;
  6744.                                                             vel[2]=player[k].velocity.z;
  6745.                                                             PlaySoundEx( landsound, samp[landsound], NULL, TRUE);
  6746.                                                             FSOUND_3D_SetAttributes(channels[landsound], gLoc, vel);
  6747.                                                             FSOUND_SetVolume(channels[landsound], 128);
  6748.                                                             FSOUND_SetPaused(channels[landsound], FALSE);
  6749.                                                             if(k==0){
  6750.                                                                 envsound[numenvsounds]=player[k].coords;
  6751.                                                                 envsoundvol[numenvsounds]=16;
  6752.                                                                 envsoundlife[numenvsounds]=.4;
  6753.                                                                 numenvsounds++;
  6754.                                                             }
  6755.  
  6756.                                                         }
  6757.                                                     }
  6758.                                                 }              
  6759.                                             }
  6760.                                         }
  6761.                                         if(tempcollide&&terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz]&&(/*player[k].jumptogglekeydown*/1==1||player[k].aitype!=playercontrolled))
  6762.                                             for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
  6763.                                                 i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
  6764.                                                 lowpoint=player[k].coords;
  6765.                                                 lowpoint.y+=1.35;
  6766.                                                 if(objects.type[i]!=rocktype)
  6767.                                                     if(player[k].SphereCheck(&lowpoint, 1.33, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
  6768.                                                         if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim&&player[k].onterrain)player[k].avoidcollided=1;      
  6769.                                                         player[k].coords=lowpoint;
  6770.                                                         player[k].coords.y-=1.35;
  6771.                                                         player[k].collide=1;   
  6772.  
  6773.                                                         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)){
  6774.                                                             lowpoint=player[k].coords;
  6775.                                                             objects.model[i].SphereCheckPossible(&lowpoint, 1.5, &objects.position[i], &objects.rotation[i]);
  6776.                                                             lowpoint=player[k].coords;
  6777.                                                             lowpoint.y+=.05;
  6778.                                                             facing=0;
  6779.                                                             facing.z=-1;
  6780.                                                             facing=DoRotation(facing,0,player[k].targetrotation+180,0);
  6781.                                                             lowpointtarget=lowpoint+facing*1.4;
  6782.                                                             whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
  6783.                                                             if(whichhit!=-1){
  6784.                                                                 lowpoint=player[k].coords;
  6785.                                                                 lowpoint.y+=.1;
  6786.                                                                 lowpointtarget=lowpoint+facing*1.4;
  6787.                                                                 lowpoint2=lowpoint;
  6788.                                                                 lowpointtarget2=lowpointtarget;
  6789.                                                                 lowpoint3=lowpoint;
  6790.                                                                 lowpointtarget3=lowpointtarget;
  6791.                                                                 lowpoint4=lowpoint;
  6792.                                                                 lowpointtarget4=lowpointtarget;
  6793.                                                                 lowpoint5=lowpoint;
  6794.                                                                 lowpointtarget5=lowpointtarget;
  6795.                                                                 lowpoint6=lowpoint;
  6796.                                                                 lowpointtarget6=lowpointtarget;
  6797.                                                                 lowpoint7=lowpoint;
  6798.                                                                 lowpointtarget7=lowpoint;
  6799.                                                                 lowpoint2.x+=.1;
  6800.                                                                 lowpointtarget2.x+=.1;
  6801.                                                                 lowpoint3.z+=.1;
  6802.                                                                 lowpointtarget3.z+=.1;
  6803.                                                                 lowpoint4.x-=.1;
  6804.                                                                 lowpointtarget4.x-=.1;
  6805.                                                                 lowpoint5.z-=.1;
  6806.                                                                 lowpointtarget5.z-=.1;
  6807.                                                                 lowpoint6.y+=45/13;
  6808.                                                                 lowpointtarget6.y+=45/13;
  6809.                                                                 lowpointtarget6+=facing*.6;
  6810.                                                                 lowpointtarget7.y+=90/13;
  6811.                                                                 whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
  6812.                                                                 if(objects.friction[i]>.5)
  6813.                                                                     if(whichhit!=-1){
  6814.                                                                         //if(k==0){
  6815.                                                                         if(whichhit!=-1)if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim)player[k].collided=1;
  6816.                                                                         if(checkcollide(lowpoint7,lowpointtarget7)==-1)
  6817.                                                                             if(checkcollide(lowpoint6,lowpointtarget6)==-1)
  6818.                                                                                 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)
  6819.                                                                                     for(j=0;j<45;j++){
  6820.                                                                                         lowpoint=player[k].coords;
  6821.                                                                                         lowpoint.y+=(float)j/13;
  6822.                                                                                         lowpointtarget=lowpoint+facing*1.4;
  6823.                                                                                         if(objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint2,&objects.position[i],&objects.rotation[i])==-1){
  6824.                                                                                             if(j<=6){
  6825.                                                                                                 j=100;
  6826.                                                                                             }
  6827.                                                                                             /*if(j>=25&&(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)){
  6828.                                                                                             j=100;
  6829.                                                                                             }*/
  6830.                                                                                             if(j<=25&&player[k].targetanimation==jumpdownanim){
  6831.                                                                                                 j=100;
  6832.                                                                                             }
  6833.                                                                                             if(j!=100&&(/*j>25||(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)||*/player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim)){
  6834.                                                                                                 lowpoint=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0);
  6835.                                                                                                 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)*/){
  6836.                                                                                                     lowpoint=player[k].coords;
  6837.                                                                                                     lowpoint.y+=(float)j/13;
  6838.                                                                                                     lowpointtarget=lowpoint+facing*1.3;
  6839.                                                                                                     flatfacing=player[k].coords;
  6840.                                                                                                     player[k].coords=colpoint-DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0)*.01;
  6841.                                                                                                     player[k].coords.y=lowpointtarget.y-.07;
  6842.                                                                                                     player[k].currentoffset=(flatfacing-player[k].coords)/player[k].scale;
  6843.  
  6844.                                                                                                     if(j>10||!player[k].isRun()){                                                  
  6845.                                                                                                         if(player[k].targetanimation==jumpdownanim||player[k].targetanimation==jumpupanim){
  6846.                                                                                                             if(k==0)FSOUND_SetPaused(channels[whooshsound], TRUE);
  6847.                                                                                                         }
  6848.                                                                                                         float gLoc[3];
  6849.                                                                                                         float vel[3];
  6850.                                                                                                         gLoc[0]=player[k].coords.x;
  6851.                                                                                                         gLoc[1]=player[k].coords.y;
  6852.                                                                                                         gLoc[2]=player[k].coords.z;
  6853.                                                                                                         vel[0]=player[k].velocity.x;
  6854.                                                                                                         vel[1]=player[k].velocity.y;
  6855.                                                                                                         vel[2]=player[k].velocity.z;
  6856.                                                                                                         PlaySoundEx( jumpsound, samp[jumpsound], NULL, TRUE);
  6857.                                                                                                         FSOUND_3D_SetAttributes(channels[jumpsound], gLoc, vel);
  6858.                                                                                                         FSOUND_SetVolume(channels[jumpsound], 128);
  6859.                                                                                                         FSOUND_SetPaused(channels[jumpsound], FALSE);
  6860.  
  6861.                                                                                                         lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
  6862.                                                                                                         player[k].rotation=-asin(0-lowpointtarget.x);
  6863.                                                                                                         player[k].rotation*=360/6.28;
  6864.                                                                                                         if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
  6865.                                                                                                         player[k].targetrotation=player[k].rotation;
  6866.                                                                                                         player[k].lowrotation=player[k].rotation;
  6867.  
  6868.                                                                                                         //player[k].velocity=lowpointtarget*.03;
  6869.                                                                                                         player[k].velocity=0;
  6870.  
  6871.                                                                                                         if(/*(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)||*/player[k].targetanimation==jumpupanim){
  6872.                                                                                                             //player[k].currentanimation=climbanim;
  6873.                                                                                                             player[k].targetanimation=climbanim;
  6874.                                                                                                             player[k].jumppower=0;
  6875.                                                                                                             player[k].jumpclimb=1;
  6876.                                                                                                         }
  6877.                                                                                                         player[k].transspeed=6;
  6878.                                                                                                         player[k].target=0;
  6879.  
  6880.                                                                                                         //player[k].currentframe=1;
  6881.                                                                                                         player[k].targetframe=1;
  6882.                                                                                                         if(j>25){
  6883.                                                                                                             //player[k].currentframe=0;
  6884.                                                                                                             player[k].targetframe=0;
  6885.                                                                                                             //player[k].currentanimation=hanganim;
  6886.                                                                                                             player[k].targetanimation=hanganim;
  6887.                                                                                                             player[k].jumppower=0;
  6888.                                                                                                         }  
  6889.                                                                                                     }
  6890.                                                                                                     j=100;
  6891.                                                                                                 }
  6892.                                                                                             }
  6893.                                                                                         }
  6894.                                                                                     }
  6895.                                                                                     //}
  6896.                                                                     }
  6897.                                                             }
  6898.                                                         }
  6899.                                                     }
  6900.                                             }
  6901.                                             if(player[k].collide<=0){
  6902.                                                 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()){
  6903.                                                     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)){
  6904.                                                         if(player[k].targetanimation==staggerbackhighanim||player[k].targetanimation==staggerbackhardanim)player[k].RagDoll(0);
  6905.                                                         player[k].targetanimation=jumpdownanim;
  6906.                                                         player[k].targetframe=0;
  6907.                                                         player[k].target=0;
  6908.  
  6909.                                                         float gLoc[3];
  6910.                                                         float vel[3];
  6911.                                                         gLoc[0]=player[k].coords.x;
  6912.                                                         gLoc[1]=player[k].coords.y;
  6913.                                                         gLoc[2]=player[k].coords.z;
  6914.                                                         vel[0]=player[k].velocity.x;
  6915.                                                         vel[1]=player[k].velocity.y;
  6916.                                                         vel[2]=player[k].velocity.z;
  6917.                                                         if(k==0){
  6918.                                                             PlaySoundEx( whooshsound, samp[whooshsound], NULL, TRUE);
  6919.                                                             FSOUND_3D_SetAttributes(channels[whooshsound], gLoc, vel);
  6920.                                                             FSOUND_SetVolume(channels[whooshsound], 128);
  6921.                                                             FSOUND_SetPaused(channels[whooshsound], FALSE);
  6922.                                                         }
  6923.                                                     }
  6924.                                                     player[k].velocity.y+=gravity;
  6925.                                                 }
  6926.                                             }
  6927.                                 }
  6928.                             }
  6929.                             player[k].realoldcoords=player[k].coords;
  6930.                         }
  6931.  
  6932.                         static XYZ oldviewer;
  6933.  
  6934.                         if(indialogue==-1){
  6935.                             player[0].forwardkeydown=IsKeyDown(theKeyMap, forwardkey);
  6936.                             player[0].leftkeydown=IsKeyDown(theKeyMap, leftkey);
  6937.                             player[0].backkeydown=IsKeyDown(theKeyMap, backkey);
  6938.                             player[0].rightkeydown=IsKeyDown(theKeyMap, rightkey);
  6939.                             player[0].jumpkeydown=IsKeyDown(theKeyMap, jumpkey);
  6940.                             player[0].crouchkeydown=IsKeyDown(theKeyMap, crouchkey);
  6941.                             player[0].drawkeydown=IsKeyDown(theKeyMap, drawkey);
  6942.                             player[0].throwkeydown=IsKeyDown(theKeyMap, throwkey);
  6943.                         }
  6944.                         else
  6945.                         {
  6946.                             player[0].forwardkeydown=0;
  6947.                             player[0].leftkeydown=0;
  6948.                             player[0].backkeydown=0;
  6949.                             player[0].rightkeydown=0;
  6950.                             player[0].jumpkeydown=0;
  6951.                             player[0].crouchkeydown=0;
  6952.                             player[0].drawkeydown=0;
  6953.                             player[0].throwkeydown=0;
  6954.                         }
  6955.  
  6956.                         if(!player[0].jumpkeydown)player[0].jumpclimb=0;
  6957.  
  6958.  
  6959.                         static bool endkeydown;
  6960.                         if(indialogue!=-1){
  6961.                             cameramode=1;
  6962.                             if(directing){ 
  6963.                                 facing=0;
  6964.                                 facing.z=-1;
  6965.  
  6966.                                 facing=DoRotation(facing,-rotation2,0,0);
  6967.                                 facing=DoRotation(facing,0,0-rotation,0);
  6968.  
  6969.                                 flatfacing=0;
  6970.                                 flatfacing.z=-1;
  6971.  
  6972.                                 flatfacing=DoRotation(flatfacing,0,-rotation,0);
  6973.  
  6974.                                 if(IsKeyDown(theKeyMap, forwardkey))viewer+=facing*multiplier*4;
  6975.                                 if(IsKeyDown(theKeyMap, backkey))viewer-=facing*multiplier*4;
  6976.                                 if(IsKeyDown(theKeyMap, leftkey))viewer+=DoRotation(flatfacing*multiplier,0,90,0)*4;
  6977.                                 if(IsKeyDown(theKeyMap, rightkey))viewer+=DoRotation(flatfacing*multiplier,0,-90,0)*4;
  6978.                                 if(IsKeyDown(theKeyMap, jumpkey))viewer.y+=multiplier*4;
  6979.                                 if(IsKeyDown(theKeyMap, crouchkey))viewer.y-=multiplier*4;
  6980.                                 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)
  6981.                                     ||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)
  6982.                                     ||IsKeyDown(theKeyMap, MAC_MINUS_KEY))){
  6983.                                         int whichend;
  6984.                                         if(IsKeyDown(theKeyMap, MAC_1_KEY))whichend=1;
  6985.                                         if(IsKeyDown(theKeyMap, MAC_2_KEY))whichend=2;
  6986.                                         if(IsKeyDown(theKeyMap, MAC_3_KEY))whichend=3;
  6987.                                         if(IsKeyDown(theKeyMap, MAC_4_KEY))whichend=4;
  6988.                                         if(IsKeyDown(theKeyMap, MAC_5_KEY))whichend=5;
  6989.                                         if(IsKeyDown(theKeyMap, MAC_6_KEY))whichend=6;
  6990.                                         if(IsKeyDown(theKeyMap, MAC_7_KEY))whichend=7;
  6991.                                         if(IsKeyDown(theKeyMap, MAC_8_KEY))whichend=8;
  6992.                                         if(IsKeyDown(theKeyMap, MAC_9_KEY))whichend=9;
  6993.                                         if(IsKeyDown(theKeyMap, MAC_0_KEY))whichend=0;
  6994.                                         if(IsKeyDown(theKeyMap, MAC_MINUS_KEY))whichend=-1;
  6995.                                         if(whichend!=-1){
  6996.                                             participantfocus[whichdialogue][indialogue]=whichend;
  6997.                                             participantlocation[whichdialogue][whichend]=player[whichend].coords;
  6998.                                             participantrotation[whichdialogue][whichend]=player[whichend].rotation;
  6999.                                         }
  7000.                                         if(whichend==-1){
  7001.                                             participantfocus[whichdialogue][indialogue]=-1;
  7002.                                         }
  7003.                                         if(player[participantfocus[whichdialogue][indialogue]].dead){
  7004.                                             indialogue=-1;
  7005.                                             directing=0;
  7006.                                             cameramode=0;
  7007.                                         }
  7008.                                         dialoguecamera[whichdialogue][indialogue]=viewer;
  7009.                                         dialoguecamerarotation[whichdialogue][indialogue]=rotation;
  7010.                                         dialoguecamerarotation2[whichdialogue][indialogue]=rotation2;
  7011.                                         indialogue++;
  7012.                                         if(indialogue<numdialogueboxes[whichdialogue]){
  7013.                                             if(dialogueboxsound[whichdialogue][indialogue]!=0){
  7014.                                                 static float gLoc[3];
  7015.                                                 static float vel[3];
  7016.                                                 XYZ temppos;
  7017.                                                 temppos=player[participantfocus[whichdialogue][indialogue]].coords;
  7018.                                                 temppos=temppos-viewer;
  7019.                                                 Normalise(&temppos);
  7020.                                                 temppos+=viewer;
  7021.  
  7022.                                                 gLoc[0]=temppos.x;
  7023.                                                 gLoc[1]=temppos.y;
  7024.                                                 gLoc[2]=temppos.z;vel[0]=0;
  7025.                                                 vel[1]=0;
  7026.                                                 vel[2]=0;
  7027.                                                 int whichsoundplay;
  7028.                                                 if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
  7029.                                                 if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
  7030.                                                 if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
  7031.                                                 if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
  7032.                                                 if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
  7033.                                                 if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
  7034.                                                 if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
  7035.                                                 if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
  7036.                                                 if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
  7037.                                                 if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
  7038.                                                 if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
  7039.                                                 if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
  7040.                                                 if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
  7041.                                                 if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
  7042.                                                 if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
  7043.                                                 if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
  7044.                                                 if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
  7045.                                                 if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
  7046.                                                 if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
  7047.                                                 if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
  7048.                                                 PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, TRUE);
  7049.                                                 FSOUND_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
  7050.                                                 FSOUND_SetVolume(channels[whichsoundplay], 256);
  7051.                                                 FSOUND_SetPaused(channels[whichsoundplay], FALSE);
  7052.                                             }
  7053.                                         }
  7054.  
  7055.                                         for(j=0;j<numplayers;j++){
  7056.                                             participantfacing[whichdialogue][indialogue][j]=participantfacing[whichdialogue][indialogue-1][j];
  7057.                                         }
  7058.  
  7059.                                         endkeydown=1;
  7060.                                     }
  7061.                                     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)
  7062.                                         ||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)
  7063.                                         )){
  7064.                                             int whichend;
  7065.                                             if(IsKeyDown(theKeyMap, MAC_NUMPAD_1_KEY))whichend=1;
  7066.                                             if(IsKeyDown(theKeyMap, MAC_NUMPAD_2_KEY))whichend=2;
  7067.                                             if(IsKeyDown(theKeyMap, MAC_NUMPAD_3_KEY))whichend=3;
  7068.                                             if(IsKeyDown(theKeyMap, MAC_NUMPAD_4_KEY))whichend=4;
  7069.                                             if(IsKeyDown(theKeyMap, MAC_NUMPAD_5_KEY))whichend=5;
  7070.                                             if(IsKeyDown(theKeyMap, MAC_NUMPAD_6_KEY))whichend=6;
  7071.                                             if(IsKeyDown(theKeyMap, MAC_NUMPAD_7_KEY))whichend=7;
  7072.                                             if(IsKeyDown(theKeyMap, MAC_NUMPAD_8_KEY))whichend=8;
  7073.                                             if(IsKeyDown(theKeyMap, MAC_NUMPAD_9_KEY))whichend=9;
  7074.                                             if(IsKeyDown(theKeyMap, MAC_NUMPAD_0_KEY))whichend=0;
  7075.                                             participantfacing[whichdialogue][indialogue][whichend]=facing;
  7076.                                         }
  7077.                                         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)
  7078.                                             &&!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)
  7079.                                             &&!IsKeyDown(theKeyMap, MAC_MINUS_KEY)){
  7080.                                                 endkeydown=0;
  7081.                                             }
  7082.                                             if(indialogue>=numdialogueboxes[whichdialogue]){
  7083.                                                 indialogue=-1;
  7084.                                                 directing=0;
  7085.                                                 cameramode=0;
  7086.                                             }
  7087.                             }
  7088.                             if(!directing){
  7089.                                 FSOUND_SetPaused(channels[whooshsound], TRUE);
  7090.                                 viewer=dialoguecamera[whichdialogue][indialogue];
  7091.                                 if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.1){
  7092.                                     viewer.y=terrain.getHeight(viewer.x,viewer.z)+.1;
  7093.                                 }              
  7094.                                 rotation=dialoguecamerarotation[whichdialogue][indialogue];
  7095.                                 rotation2=dialoguecamerarotation2[whichdialogue][indialogue];
  7096.                                 if(dialoguetime>0.5)
  7097.                                     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)
  7098.                                         ||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)
  7099.                                         ||IsKeyDown(theKeyMap, MAC_MINUS_KEY)))||(IsKeyDown(theKeyMap, attackkey)&&!oldbuttondialogue)){
  7100.                                             indialogue++;
  7101.                                             endkeydown=1;
  7102.                                             if(indialogue<numdialogueboxes[whichdialogue]){
  7103.                                                 if(dialogueboxsound[whichdialogue][indialogue]!=0){
  7104.                                                     static float gLoc[3];
  7105.                                                     static float vel[3];
  7106.                                                     XYZ temppos;
  7107.                                                     temppos=player[participantfocus[whichdialogue][indialogue]].coords;
  7108.                                                     temppos=temppos-viewer;
  7109.                                                     Normalise(&temppos);
  7110.                                                     temppos+=viewer;
  7111.  
  7112.                                                     gLoc[0]=temppos.x;
  7113.                                                     gLoc[1]=temppos.y;
  7114.                                                     gLoc[2]=temppos.z;vel[0]=0;
  7115.                                                     vel[1]=0;
  7116.                                                     vel[2]=0;
  7117.                                                     int whichsoundplay;
  7118.                                                     if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
  7119.                                                     if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
  7120.                                                     if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
  7121.                                                     if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
  7122.                                                     if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
  7123.                                                     if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
  7124.                                                     if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
  7125.                                                     if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
  7126.                                                     if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
  7127.                                                     if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
  7128.                                                     if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
  7129.                                                     if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
  7130.                                                     if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
  7131.                                                     if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
  7132.                                                     if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
  7133.                                                     if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
  7134.                                                     if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
  7135.                                                     if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
  7136.                                                     if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
  7137.                                                     if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
  7138.                                                     if(dialogueboxsound[whichdialogue][indialogue]==-6)whichsoundplay=alarmsound;
  7139.                                                     if(dialogueboxsound[whichdialogue][indialogue]!=-5){
  7140.                                                         PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, TRUE);
  7141.                                                         FSOUND_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
  7142.                                                         FSOUND_SetVolume(channels[whichsoundplay], 256);
  7143.                                                         FSOUND_SetPaused(channels[whichsoundplay], FALSE);
  7144.                                                     }
  7145.                                                     if(dialogueboxsound[whichdialogue][indialogue]==-5){
  7146.                                                         hotspot[numhotspots]=player[0].coords;
  7147.                                                         hotspotsize[numhotspots]=10;
  7148.                                                         hotspottype[numhotspots]=-1;
  7149.  
  7150.                                                         numhotspots++;
  7151.                                                     }
  7152.                                                     if(dialogueboxsound[whichdialogue][indialogue]==-6){
  7153.                                                         hostile=1;
  7154.                                                     }
  7155.  
  7156.                                                     if(player[participantfocus[whichdialogue][indialogue]].dead){
  7157.                                                         indialogue=-1;
  7158.                                                         directing=0;
  7159.                                                         cameramode=0;
  7160.                                                     }
  7161.                                                 }
  7162.                                             }
  7163.                                         }
  7164.                                         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)
  7165.                                             &&!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)
  7166.                                             &&!IsKeyDown(theKeyMap, MAC_MINUS_KEY)){
  7167.                                                 endkeydown=0;
  7168.                                             }
  7169.                                             if(indialogue>=numdialogueboxes[whichdialogue]){
  7170.                                                 indialogue=-1;
  7171.                                                 directing=0;
  7172.                                                 cameramode=0;
  7173.                                                 if(dialoguetype[whichdialogue]>19&&dialoguetype[whichdialogue]<30){
  7174.                                                     hostile=1;
  7175.                                                 }
  7176.                                                 if(dialoguetype[whichdialogue]>29&&dialoguetype[whichdialogue]<40){
  7177.                                                     windialogue=1;
  7178.                                                 }
  7179.                                                 if(dialoguetype[whichdialogue]>49&&dialoguetype[whichdialogue]<60){
  7180.                                                     hostile=1;
  7181.                                                     for(i=1;i<numplayers;i++){
  7182.                                                         player[i].aitype = attacktypecutoff;
  7183.                                                     }
  7184.                                                 }
  7185.                                             }
  7186.                             }
  7187.                         }
  7188.  
  7189.                         if(!IsKeyDown(theKeyMap, attackkey))oldbuttondialogue=0;
  7190.                         else oldbuttondialogue=1;
  7191.  
  7192.                         static float keyrefreshdelay=0,bigrefreshdelay=0;
  7193.  
  7194.                         //Net updates
  7195.  
  7196.                         /*keyrefreshdelay-=multiplier;
  7197.                         bigrefreshdelay-=multiplier;
  7198.  
  7199.                         if(keyrefreshdelay<=0){
  7200.                         static int concat[4];
  7201.  
  7202.                         concat[0]=player[0].forwardkeydown;
  7203.                         concat[0]=concat[0]*2+player[0].forwardstogglekeydown;
  7204.                         concat[0]=concat[0]*2+player[0].rightkeydown;
  7205.                         concat[0]=concat[0]*2+player[0].leftkeydown;
  7206.                         concat[0]=concat[0]*2+player[0].backkeydown;
  7207.                         concat[0]=concat[0]*2+player[0].jumpkeydown;
  7208.                         concat[0]=concat[0]*2+player[0].jumptogglekeydown;
  7209.                         concat[0]=concat[0]*2+player[0].crouchkeydown;
  7210.  
  7211.                         concat[1]=player[0].crouchtogglekeydown;
  7212.                         concat[1]=concat[1]*2+player[0].drawkeydown;
  7213.                         concat[1]=concat[1]*2+player[0].drawtogglekeydown;
  7214.                         concat[1]=concat[1]*2+player[0].throwkeydown;
  7215.                         concat[1]=concat[1]*2+player[0].throwtogglekeydown;
  7216.                         concat[1]=concat[1]*2+player[0].attackkeydown;
  7217.  
  7218.                         //concat[2]=(char)((int)(rotation/2)%180);
  7219.  
  7220.                         //concat[3]=(char)((int)(rotation2/2)%180);
  7221.  
  7222.                         chatname[0]=concat[0]-128;
  7223.                         chatname[1]=concat[1]-128;
  7224.                         //chatname[2]=concat[2]-128;
  7225.                         //chatname[3]=concat[3]-128;
  7226.                         int temppoint=2;
  7227.                         memcpy(chatname+temppoint,&rotation,sizeof(float));
  7228.                         temppoint+=sizeof(float);
  7229.                         memcpy(chatname+temppoint,&rotation2,sizeof(float));
  7230.                         temppoint+=sizeof(float);
  7231.  
  7232.                         chatname[temppoint]='\0';
  7233.  
  7234.                         //if(!ishost)NetworkSendPlayerMessage( chatname, kMessageType_Keys );
  7235.                         //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_Keys );
  7236.                         //keyrefreshdelay=.01;
  7237.                         keyrefreshdelay=.03;
  7238.                         }
  7239.  
  7240.                         if(bigrefreshdelay<=0){
  7241.                         for(i=0;i<1;i++){
  7242.                         /*int temppoint=0;
  7243.                         memcpy(chatname+temppoint,&i,sizeof(int));
  7244.                         temppoint+=sizeof(int);
  7245.                         memcpy(chatname+temppoint,&player[i].coords.x,sizeof(float));
  7246.                         temppoint+=sizeof(float);
  7247.                         memcpy(chatname+temppoint,&player[i].coords.y,sizeof(float));
  7248.                         temppoint+=sizeof(float);
  7249.                         memcpy(chatname+temppoint,&player[i].coords.z,sizeof(float));
  7250.                         temppoint+=sizeof(float);
  7251.                         memcpy(chatname+temppoint,&player[i].damage,sizeof(float));
  7252.                         temppoint+=sizeof(float);
  7253.                         memcpy(chatname+temppoint,&player[i].target,sizeof(float));
  7254.                         temppoint+=sizeof(float);
  7255.                         memcpy(chatname+temppoint,&player[i].targetanimation,sizeof(int));
  7256.                         temppoint+=sizeof(int);
  7257.                         memcpy(chatname+temppoint,&player[i].currentanimation,sizeof(int));
  7258.                         temppoint+=sizeof(int);
  7259.                         memcpy(chatname+temppoint,&player[i].velocity.x,sizeof(float));
  7260.                         temppoint+=sizeof(float);
  7261.                         memcpy(chatname+temppoint,&player[i].velocity.y,sizeof(float));
  7262.                         temppoint+=sizeof(float);
  7263.                         memcpy(chatname+temppoint,&player[i].velocity.z,sizeof(float));
  7264.                         temppoint+=sizeof(float);
  7265.                         memcpy(chatname+temppoint,&player[i].targetframe,sizeof(int));
  7266.                         temppoint+=sizeof(int);
  7267.                         memcpy(chatname+temppoint,&player[i].currentframe,sizeof(int));
  7268.                         temppoint+=sizeof(int);
  7269.                         memcpy(chatname+temppoint,&player[i].rotation,sizeof(float));
  7270.                         temppoint+=sizeof(float);
  7271.                         memcpy(chatname+temppoint,&player[i].targetrotation,sizeof(float));
  7272.                         temppoint+=sizeof(float);
  7273.                         memcpy(chatname+temppoint,&player[i].bloodloss,sizeof(float));
  7274.                         temppoint+=sizeof(float);
  7275.                         memcpy(chatname+temppoint,&player[i].weaponactive,sizeof(int));
  7276.                         temppoint+=sizeof(int);
  7277.                         memcpy(chatname+temppoint,&player[i].num_weapons,sizeof(int));
  7278.                         temppoint+=sizeof(int);
  7279.                         memcpy(chatname+temppoint,&player[i].weaponids[0],sizeof(int));
  7280.                         temppoint+=sizeof(int);
  7281.                         memcpy(chatname+temppoint,&player[i].weaponids[1],sizeof(int));
  7282.                         temppoint+=sizeof(int);
  7283.                         memcpy(chatname+temppoint,&player[i].weaponids[2],sizeof(int));
  7284.                         temppoint+=sizeof(int);
  7285.                         memcpy(chatname+temppoint,&player[i].weaponids[3],sizeof(int));
  7286.                         temppoint+=sizeof(int);
  7287.                         chatname[temppoint]='\0';
  7288.  
  7289.                         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);
  7290.                         //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_PlayerState );
  7291.                         //else NetworkSendPlayerMessage( chatname, kMessageType_PlayerState );
  7292.  
  7293.                         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);
  7294.  
  7295.                         //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_PlayerStateMisc );
  7296.                         //else NetworkSendPlayerMessage( chatname, kMessageType_PlayerStateMisc );
  7297.                         }
  7298.                         //bigrefreshdelay=.02;
  7299.                         bigrefreshdelay=.1;
  7300.                         }
  7301.                         }*/
  7302.  
  7303.                         if(!player[0].jumpkeydown){
  7304.                             player[0].jumptogglekeydown=0;
  7305.                         }
  7306.                         if(player[0].jumpkeydown&&player[0].targetanimation!=jumpupanim&&player[0].targetanimation!=jumpdownanim&&!player[0].isFlip())player[0].jumptogglekeydown=1;
  7307.  
  7308.  
  7309.                         dialoguetime+=multiplier;
  7310.                         skybox.cloudmove+=multiplier;
  7311.                         hawkrotation+=multiplier*25;
  7312.                         realhawkcoords=0;
  7313.                         realhawkcoords.x=25;
  7314.                         realhawkcoords=DoRotation(realhawkcoords,0,hawkrotation,0)+hawkcoords;
  7315.                         hawkcalldelay-=multiplier/2;
  7316.  
  7317.                         if(hawkcalldelay<=0)
  7318.                         {
  7319.                             static float gLoc[3];
  7320.                             static float vel[3];
  7321.                             gLoc[0]=realhawkcoords.x;
  7322.                             gLoc[1]=realhawkcoords.y;
  7323.                             gLoc[2]=realhawkcoords.z;
  7324.                             vel[0]=0;
  7325.                             vel[1]=0;
  7326.                             vel[2]=0;
  7327.                             PlaySoundEx( hawksound, samp[hawksound], NULL, TRUE);
  7328.                             FSOUND_3D_SetAttributes(channels[hawksound], gLoc, vel);
  7329.                             FSOUND_SetVolume(channels[hawksound], 128);
  7330.                             FSOUND_SetPaused(channels[hawksound], FALSE);
  7331.  
  7332.                             hawkcalldelay=16+abs(Random()%8);
  7333.                         }
  7334.                         static float temptexdetail;
  7335.  
  7336.  
  7337.                         if(IsKeyDown(theKeyMap, MAC_H_KEY)&&debugmode){
  7338.                             player[0].damagetolerance=200000;
  7339.                             player[0].damage=0;
  7340.                             player[0].burnt=0;
  7341.                             player[0].permanentdamage=0;
  7342.                             player[0].superpermanentdamage=0;
  7343.                             /*
  7344.                             int whichchar;
  7345.                             whichchar = abs(Random()%7);
  7346.                             registrationname[whichchar]+=1;
  7347.                             */
  7348.                         }
  7349.  
  7350.                         if(IsKeyDown(theKeyMap, MAC_J_KEY)&&!envtogglekeydown&&debugmode){
  7351.                             environment++;
  7352.                             if(environment>2)environment=0;
  7353.                             Setenvironment(environment);
  7354.  
  7355.                             envtogglekeydown=1;
  7356.                         }
  7357.  
  7358.  
  7359.                         if(!IsKeyDown(theKeyMap, MAC_J_KEY)){
  7360.                             envtogglekeydown=0;
  7361.                         }
  7362.  
  7363.                         if(IsKeyDown(theKeyMap, MAC_C_KEY)&&!cameratogglekeydown&&debugmode){
  7364.                             cameramode=1-cameramode;
  7365.                             cameratogglekeydown=1;
  7366.                         }
  7367.  
  7368.                         if(!IsKeyDown(theKeyMap, MAC_C_KEY)){
  7369.                             cameratogglekeydown=0;
  7370.                         }
  7371.  
  7372.                         if(IsKeyDown(theKeyMap, MAC_X_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!detailtogglekeydown&&debugmode){
  7373.                             if(player[0].num_weapons>0){
  7374.                                 if(weapons.type[player[0].weaponids[0]]==sword)weapons.type[player[0].weaponids[0]]=staff;
  7375.                                 else if(weapons.type[player[0].weaponids[0]]==staff)weapons.type[player[0].weaponids[0]]=knife;
  7376.                                 else weapons.type[player[0].weaponids[0]]=sword;
  7377.                                 if(weapons.type[player[0].weaponids[0]]==sword){
  7378.                                     weapons.mass[player[0].weaponids[0]]=1.5;
  7379.                                     weapons.tipmass[player[0].weaponids[0]]=1;
  7380.                                     weapons.length[player[0].weaponids[0]]=.8;
  7381.                                 }
  7382.                                 if(weapons.type[player[0].weaponids[0]]==staff){
  7383.                                     weapons.mass[player[0].weaponids[0]]=2;
  7384.                                     weapons.tipmass[player[0].weaponids[0]]=1;
  7385.                                     weapons.length[player[0].weaponids[0]]=1.5;
  7386.                                 }
  7387.  
  7388.                                 if(weapons.type[player[0].weaponids[0]]==knife){
  7389.                                     weapons.mass[player[0].weaponids[0]]=1;
  7390.                                     weapons.tipmass[player[0].weaponids[0]]=1.2;
  7391.                                     weapons.length[player[0].weaponids[0]]=.25;
  7392.                                 }
  7393.                             }
  7394.  
  7395.                             /*for(i=0;i<objects.numobjects;i++){
  7396.                             if(objects.type[i]==treeleavestype){
  7397.                             for(j=0;j<objects.numobjects;j++){
  7398.                             if(objects.type[j]==treetrunktype)
  7399.                             if(findDistancefast(&objects.position[i],&objects.position[j])<.5)
  7400.                             objects.scale[i]=objects.scale[j]; 
  7401.                             }
  7402.                             }
  7403.                             }*/
  7404.                             detailtogglekeydown=1;
  7405.                         }
  7406.  
  7407.                         if(IsKeyDown(theKeyMap, MAC_X_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!detailtogglekeydown&&debugmode){
  7408.                             int closest=-1;
  7409.                             float closestdist=-1;
  7410.                             float distance;
  7411.                             if(numplayers>1)
  7412.                                 for(i=1;i<numplayers;i++){
  7413.                                     distance=findDistancefast(&player[i].coords,&player[0].coords);
  7414.                                     if(closestdist==-1||distance<closestdist){
  7415.                                         closestdist=distance;
  7416.                                         closest=i;
  7417.                                     }
  7418.                                 }
  7419.                                 if(closest!=-1){
  7420.                                     if(player[closest].num_weapons)
  7421.                                     {
  7422.                                         if(weapons.type[player[closest].weaponids[0]]==sword)weapons.type[player[closest].weaponids[0]]=staff;
  7423.                                         else if(weapons.type[player[closest].weaponids[0]]==staff)weapons.type[player[closest].weaponids[0]]=knife;
  7424.                                         else weapons.type[player[closest].weaponids[0]]=sword;
  7425.                                         if(weapons.type[player[closest].weaponids[0]]==sword){
  7426.                                             weapons.mass[player[closest].weaponids[0]]=1.5;
  7427.                                             weapons.tipmass[player[closest].weaponids[0]]=1;
  7428.                                             weapons.length[player[closest].weaponids[0]]=.8;
  7429.                                         }
  7430.                                         if(weapons.type[player[0].weaponids[0]]==staff){
  7431.                                             weapons.mass[player[0].weaponids[0]]=2;
  7432.                                             weapons.tipmass[player[0].weaponids[0]]=1;
  7433.                                             weapons.length[player[0].weaponids[0]]=1.5;
  7434.                                         }
  7435.                                         if(weapons.type[player[closest].weaponids[0]]==knife){
  7436.                                             weapons.mass[player[closest].weaponids[0]]=1;
  7437.                                             weapons.tipmass[player[closest].weaponids[0]]=1.2;
  7438.                                             weapons.length[player[closest].weaponids[0]]=.25;
  7439.                                         }
  7440.                                     }
  7441.                                     if(!player[closest].num_weapons)
  7442.                                     {
  7443.                                         player[closest].weaponids[0]=weapons.numweapons;
  7444.                                         weapons.owner[weapons.numweapons]=closest;
  7445.                                         weapons.type[weapons.numweapons]=knife;
  7446.                                         weapons.damage[weapons.numweapons]=0;
  7447.                                         weapons.numweapons++;
  7448.                                         player[closest].num_weapons=1;
  7449.                                         if(weapons.type[player[closest].weaponids[0]]==sword){
  7450.                                             weapons.mass[player[closest].weaponids[0]]=1.5;
  7451.                                             weapons.tipmass[player[closest].weaponids[0]]=1;
  7452.                                             weapons.length[player[closest].weaponids[0]]=.8;
  7453.                                         }
  7454.                                         if(weapons.type[player[closest].weaponids[0]]==knife){
  7455.                                             weapons.mass[player[closest].weaponids[0]]=1;
  7456.                                             weapons.tipmass[player[closest].weaponids[0]]=1.2;
  7457.                                             weapons.length[player[closest].weaponids[0]]=.25;
  7458.                                         }
  7459.                                     }
  7460.                                 }
  7461.                                 detailtogglekeydown=1;
  7462.                         }
  7463.  
  7464.                         if(IsKeyDown(theKeyMap, MAC_U_KEY)&&debugmode){
  7465.                             int closest=-1;
  7466.                             float closestdist=-1;
  7467.                             float distance;
  7468.                             if(numplayers>1)
  7469.                                 for(i=1;i<numplayers;i++){
  7470.                                     distance=findDistancefast(&player[i].coords,&player[0].coords);
  7471.                                     if(closestdist==-1||distance<closestdist){
  7472.                                         closestdist=distance;
  7473.                                         closest=i;
  7474.                                     }
  7475.                                 }
  7476.  
  7477.                                 player[closest].rotation+=multiplier*50;
  7478.                                 player[closest].targetrotation=player[closest].rotation;
  7479.                         }
  7480.  
  7481.  
  7482.                         if(IsKeyDown(theKeyMap, MAC_O_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
  7483.                             int closest=-1;
  7484.                             float closestdist=-1;
  7485.                             float distance;
  7486.                             if(numplayers>1)
  7487.                                 for(i=1;i<numplayers;i++){
  7488.                                     distance=findDistancefast(&player[i].coords,&player[0].coords);
  7489.                                     if(closestdist==-1||distance<closestdist){
  7490.                                         closestdist=distance;
  7491.                                         closest=i;
  7492.                                     }
  7493.                                 }
  7494.                                 if(IsKeyDown(theKeyMap, MAC_CONTROL_KEY))closest=0;
  7495.  
  7496.                                 if(closest!=-1){
  7497.                                     player[closest].whichskin++;
  7498.                                     if(player[closest].whichskin>9)player[closest].whichskin=0;
  7499.                                     if(player[closest].whichskin>2&&player[closest].creature==wolftype)player[closest].whichskin=0;
  7500.  
  7501.                                     if(player[closest].creature==rabbittype){
  7502.                                         if(player[closest].whichskin==0){
  7503.                                             LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  7504.                                         }
  7505.                                         else if(player[closest].whichskin==1){
  7506.                                             LoadTextureSave(":Data:Textures:Fur.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  7507.                                         }
  7508.                                         else if(player[closest].whichskin==2){
  7509.                                             LoadTextureSave(":Data:Textures:Fur2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  7510.                                         }
  7511.                                         else if(player[closest].whichskin==3){
  7512.                                             LoadTextureSave(":Data:Textures:Lynx.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  7513.                                         }
  7514.                                         else if(player[closest].whichskin==4){
  7515.                                             LoadTextureSave(":Data:Textures:Otter.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  7516.                                         }
  7517.                                         else if(player[closest].whichskin==5){
  7518.                                             LoadTextureSave(":Data:Textures:Opal.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  7519.                                         }
  7520.                                         else if(player[closest].whichskin==6){
  7521.                                             LoadTextureSave(":Data:Textures:Sable.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  7522.                                         }
  7523.                                         else if(player[closest].whichskin==7){
  7524.                                             LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  7525.                                         }
  7526.                                         else if(player[closest].whichskin==8){
  7527.                                             LoadTextureSave(":Data:Textures:BW2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  7528.                                         }
  7529.                                         else if(player[closest].whichskin==9){
  7530.                                             LoadTextureSave(":Data:Textures:WB2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  7531.                                         }
  7532.                                     }
  7533.                                     if(player[closest].creature==wolftype){
  7534.                                         k=abs(Random()%3);
  7535.                                         if(player[closest].whichskin==0){
  7536.                                             LoadTextureSave(":Data:Textures:Wolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  7537.                                         }
  7538.                                         else if(player[closest].whichskin==1){
  7539.                                             LoadTextureSave(":Data:Textures:Darkwolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  7540.                                         }
  7541.                                         else if(player[closest].whichskin==2){
  7542.                                             LoadTextureSave(":Data:Textures:Snowwolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  7543.                                         }
  7544.                                     }
  7545.                                 }
  7546.  
  7547.                                 if(player[closest].numclothes){
  7548.                                     for(i=0;i<player[closest].numclothes;i++){
  7549.                                         tintr=player[closest].clothestintr[i];
  7550.                                         tintg=player[closest].clothestintg[i];
  7551.                                         tintb=player[closest].clothestintb[i];
  7552.                                         AddClothes((char *)player[closest].clothes[i],0,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  7553.                                     }
  7554.                                     player[closest].DoMipmaps(5,0,0,player[closest].skeleton.skinsize,player[closest].skeleton.skinsize);
  7555.                                 }
  7556.  
  7557.                                 detailtogglekeydown=1;
  7558.                         }
  7559.  
  7560.                         if(IsKeyDown(theKeyMap, MAC_O_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
  7561.                             int closest=-1;
  7562.                             float closestdist=-1;
  7563.                             float distance;
  7564.                             if(numplayers>1)
  7565.                                 for(i=1;i<numplayers;i++){
  7566.                                     distance=findDistancefast(&player[i].coords,&player[0].coords);
  7567.                                     if(closestdist==-1||distance<closestdist){
  7568.                                         closestdist=distance;
  7569.                                         closest=i;
  7570.                                     }
  7571.                                 }
  7572.                                 if(closest!=-1){
  7573.                                     if(player[closest].creature==wolftype){
  7574.                                         headprop=player[closest].proportionhead.x/1.1;
  7575.                                         bodyprop=player[closest].proportionbody.x/1.1;
  7576.                                         armprop=player[closest].proportionarms.x/1.1;
  7577.                                         legprop=player[closest].proportionlegs.x/1.1;
  7578.                                     }
  7579.  
  7580.                                     if(player[closest].creature==rabbittype){
  7581.                                         headprop=player[closest].proportionhead.x/1.2;
  7582.                                         bodyprop=player[closest].proportionbody.x/1.05;
  7583.                                         armprop=player[closest].proportionarms.x/1.00;
  7584.                                         legprop=player[closest].proportionlegs.x/1.1;
  7585.                                     }
  7586.  
  7587.  
  7588.                                     if(player[closest].creature==rabbittype){
  7589.                                         player[closest].skeleton.id=closest;
  7590.                                         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);
  7591.                                         LoadTextureSave(":Data:Textures:Wolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[closest],&player[closest].skeleton.skinsize);
  7592.                                         player[closest].whichskin=0;
  7593.                                         player[closest].creature=wolftype;
  7594.  
  7595.                                         player[closest].proportionhead=1.1;
  7596.                                         player[closest].proportionbody=1.1;
  7597.                                         player[closest].proportionarms=1.1;
  7598.                                         player[closest].proportionlegs=1.1;
  7599.                                         player[closest].proportionlegs.y=1.1;
  7600.                                         player[closest].scale=.23*5*player[0].scale;
  7601.  
  7602.                                         player[closest].damagetolerance=300;
  7603.                                     }
  7604.                                     else
  7605.                                     {
  7606.                                         player[closest].skeleton.id=closest;
  7607.                                         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);
  7608.                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
  7609.                                         player[closest].whichskin=0;
  7610.                                         player[closest].creature=rabbittype;
  7611.  
  7612.                                         player[closest].proportionhead=1.2;
  7613.                                         player[closest].proportionbody=1.05;
  7614.                                         player[closest].proportionarms=1.00;
  7615.                                         player[closest].proportionlegs=1.1;
  7616.                                         player[closest].proportionlegs.y=1.05;
  7617.                                         player[closest].scale=.2*5*player[0].scale;
  7618.  
  7619.                                         player[closest].damagetolerance=200;
  7620.                                     }
  7621.  
  7622.                                     if(player[closest].creature==wolftype){
  7623.                                         player[closest].proportionhead=1.1*headprop;
  7624.                                         player[closest].proportionbody=1.1*bodyprop;
  7625.                                         player[closest].proportionarms=1.1*armprop;
  7626.                                         player[closest].proportionlegs=1.1*legprop;
  7627.                                     }
  7628.  
  7629.                                     if(player[closest].creature==rabbittype){
  7630.                                         player[closest].proportionhead=1.2*headprop;
  7631.                                         player[closest].proportionbody=1.05*bodyprop;
  7632.                                         player[closest].proportionarms=1.00*armprop;
  7633.                                         player[closest].proportionlegs=1.1*legprop;
  7634.                                         player[closest].proportionlegs.y=1.05*legprop;
  7635.                                     }
  7636.  
  7637.                                 }
  7638.                                 detailtogglekeydown=1;
  7639.                         }
  7640.  
  7641.                         if(!IsKeyDown(theKeyMap, MAC_X_KEY)){
  7642.                             detailtogglekeydown=0;
  7643.                         }
  7644.  
  7645.                         if(IsKeyDown(theKeyMap, MAC_B_KEY)&&!slomotogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
  7646.                             slomo=1-slomo;
  7647.                             slomodelay=1000;
  7648.                             slomotogglekeydown=1;
  7649.                         }
  7650.  
  7651.  
  7652.                         if(((IsKeyDown(theKeyMap, MAC_I_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY))/*||buttons[1]*/)&&!explodetogglekeydown&&debugmode){
  7653.                             int closest=-1;
  7654.                             float closestdist=-1;
  7655.                             float distance;
  7656.                             XYZ flatfacing2,flatvelocity2;
  7657.                             XYZ blah;
  7658.                             if(numplayers>1)
  7659.                                 for(i=1;i<numplayers;i++){
  7660.                                     distance=findDistancefast(&player[i].coords,&player[0].coords);
  7661.                                     if(distance<144&&!player[i].headless)
  7662.                                         if(closestdist==-1||distance<closestdist){
  7663.                                             closestdist=distance;
  7664.                                             closest=i;
  7665.                                             blah = player[i].coords;
  7666.                                         }
  7667.                                 }
  7668.  
  7669.                                 if(closest!=-1){       
  7670.                                     XYZ headspurtdirection;
  7671.                                     int i = player[closest].skeleton.jointlabels[head];
  7672.                                     for(k=0;k<player[closest].skeleton.num_joints; k++){
  7673.                                         if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
  7674.                                         if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
  7675.                                         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;
  7676.                                         if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
  7677.                                         flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
  7678.                                         flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
  7679.                                         flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
  7680.                                         headspurtdirection=player[closest].skeleton.joints[player[closest].skeleton.jointlabels[head]].position-player[closest].skeleton.joints[player[closest].skeleton.jointlabels[neck]].position;
  7681.                                         Normalise(&headspurtdirection);
  7682.                                         sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, .6, 1);
  7683.                                         flatvelocity2+=headspurtdirection*8;
  7684.                                         sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2/2, 1,1,1, .16, 1);
  7685.                                     }
  7686.                                     sprites.MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
  7687.  
  7688.                                     float gLoc[3];
  7689.                                     float vel[3];
  7690.                                     gLoc[0]=blah.x;
  7691.                                     gLoc[1]=blah.y;
  7692.                                     gLoc[2]=blah.z;
  7693.                                     vel[0]=0;
  7694.                                     vel[1]=0;
  7695.                                     vel[2]=0;
  7696.                                     PlaySoundEx( splattersound, samp[splattersound], NULL, TRUE);
  7697.                                     FSOUND_3D_SetAttributes(channels[splattersound], gLoc, vel);
  7698.                                     FSOUND_SetVolume(channels[splattersound], 256);
  7699.                                     FSOUND_SetPaused(channels[splattersound], FALSE);
  7700.  
  7701.                                     PlaySoundEx( breaksound2, samp[breaksound2], NULL, TRUE);
  7702.                                     FSOUND_3D_SetAttributes(channels[breaksound2], gLoc, vel);
  7703.                                     FSOUND_SetVolume(channels[breaksound2], 100);
  7704.                                     FSOUND_SetPaused(channels[breaksound2], FALSE);
  7705.  
  7706.                                     if(player[closest].skeleton.free==2)player[closest].skeleton.free=0;
  7707.                                     player[closest].RagDoll(0);
  7708.                                     player[closest].dead=2;
  7709.                                     player[closest].headless=1;
  7710.                                     player[closest].DoBloodBig(3,165);
  7711.  
  7712.                                     camerashake+=.3;
  7713.                                 }
  7714.  
  7715.                                 explodetogglekeydown=1;
  7716.                         }
  7717.  
  7718.                         if(((IsKeyDown(theKeyMap, MAC_I_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY))/*||buttons[2]*/)&&!explodetogglekeydown&&debugmode){
  7719.                             int closest=-1;
  7720.                             float closestdist=-1;
  7721.                             float distance;
  7722.                             XYZ flatfacing2,flatvelocity2;
  7723.                             XYZ blah;
  7724.                             if(numplayers>1)
  7725.                                 for(i=1;i<numplayers;i++){
  7726.                                     distance=findDistancefast(&player[i].coords,&player[0].coords);
  7727.                                     if(distance<144)
  7728.                                         if(closestdist==-1||distance<closestdist){
  7729.                                             closestdist=distance;
  7730.                                             closest=i;
  7731.                                             blah=player[i].coords;
  7732.                                         }
  7733.                                 }
  7734.  
  7735.                                 if(closest!=-1){       
  7736.                                     float gLoc[3];
  7737.                                     float vel[3];
  7738.                                     gLoc[0]=blah.x;
  7739.                                     gLoc[1]=blah.y;
  7740.                                     gLoc[2]=blah.z;
  7741.                                     vel[0]=0;
  7742.                                     vel[1]=0;
  7743.                                     vel[2]=0;
  7744.  
  7745.                                     PlaySoundEx( splattersound, samp[splattersound], NULL, TRUE);
  7746.                                     FSOUND_3D_SetAttributes(channels[splattersound], gLoc, vel);
  7747.                                     FSOUND_SetVolume(channels[splattersound], 256);
  7748.                                     FSOUND_SetPaused(channels[splattersound], FALSE);
  7749.  
  7750.                                     PlaySoundEx( breaksound2, samp[breaksound2], NULL, TRUE);
  7751.                                     FSOUND_3D_SetAttributes(channels[breaksound2], gLoc, vel);
  7752.                                     FSOUND_SetVolume(channels[breaksound2], 600);
  7753.                                     FSOUND_SetPaused(channels[breaksound2], FALSE);
  7754.  
  7755.                                     for(i=0;i<player[closest].skeleton.num_joints; i++){
  7756.                                         if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
  7757.                                         if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
  7758.                                         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;
  7759.                                         if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
  7760.                                         flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
  7761.                                         flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
  7762.                                         flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
  7763.                                         sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
  7764.                                         sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .3, 1);
  7765.                                         sprites.MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
  7766.                                     }
  7767.  
  7768.                                     for(i=0;i<player[closest].skeleton.num_joints; i++){
  7769.                                         if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
  7770.                                         if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
  7771.                                         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;
  7772.                                         if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
  7773.                                         flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
  7774.                                         flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
  7775.                                         flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
  7776.                                         sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
  7777.                                         sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
  7778.                                     }
  7779.  
  7780.                                     for(i=0;i<player[closest].skeleton.num_joints; i++){
  7781.                                         if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
  7782.                                         if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
  7783.                                         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;
  7784.                                         if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
  7785.                                         flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
  7786.                                         flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
  7787.                                         flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
  7788.                                         sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
  7789.                                         sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
  7790.                                     }
  7791.  
  7792.                                     for(i=0;i<player[closest].skeleton.num_joints; i++){
  7793.                                         if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
  7794.                                         if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
  7795.                                         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;
  7796.                                         if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
  7797.                                         flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
  7798.                                         flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
  7799.                                         flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
  7800.                                         sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
  7801.                                         sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
  7802.                                     }
  7803.  
  7804.                                     XYZ temppos;
  7805.                                     for(j=0;j<numplayers; j++){
  7806.                                         if(j!=closest){
  7807.                                             if(findDistancefast(&player[j].coords,&player[closest].coords)<25){
  7808.                                                 player[j].DoDamage((25-findDistancefast(&player[j].coords,&player[closest].coords))*60);
  7809.                                                 if(player[j].skeleton.free==2)player[j].skeleton.free=1;
  7810.                                                 player[j].skeleton.longdead=0;
  7811.                                                 player[j].RagDoll(0);
  7812.                                                 for(i=0;i<player[j].skeleton.num_joints; i++){
  7813.                                                     temppos=player[j].skeleton.joints[i].position+player[j].coords;
  7814.                                                     if(findDistancefast(&temppos,&player[closest].coords)<25){
  7815.                                                         flatvelocity2=temppos-player[closest].coords;
  7816.                                                         Normalise(&flatvelocity2);
  7817.                                                         player[j].skeleton.joints[i].velocity+=flatvelocity2*((20-findDistancefast(&temppos,&player[closest].coords))*20);
  7818.                                                     }
  7819.                                                 }
  7820.                                             }
  7821.                                         }
  7822.                                     }
  7823.  
  7824.                                     player[closest].DoDamage(10000);
  7825.                                     player[closest].RagDoll(0);
  7826.                                     player[closest].dead=2;
  7827.                                     player[closest].coords=20;
  7828.                                     player[closest].skeleton.free=2;
  7829.  
  7830.                                     camerashake+=.6;
  7831.  
  7832.                                 }
  7833.  
  7834.                                 explodetogglekeydown=1;
  7835.                         }
  7836.  
  7837.                         if(!IsKeyDown(theKeyMap, MAC_I_KEY)){
  7838.                             explodetogglekeydown=0;
  7839.                         }
  7840.  
  7841.                         /*
  7842.                         if(IsKeyDown(theKeyMap, MAC_S_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)&&!slomotogglekeydown){
  7843.                         FILE            *tfile;
  7844.                         //tfile=fopen( ":Data:Maps:mapsave", "wb" );
  7845.                         if(whichlevel==0)tfile=fopen( ":Data:Maps:map1", "wb" );
  7846.                         else if(whichlevel==1)tfile=fopen( ":Data:Maps:map2", "wb" );
  7847.                         else if(whichlevel==2)tfile=fopen( ":Data:Maps:map3", "wb" );
  7848.                         else if(whichlevel==3)tfile=fopen( ":Data:Maps:map4", "wb" );
  7849.                         else if(whichlevel==4)tfile=fopen( ":Data:Maps:map5", "wb" );
  7850.                         else tfile=fopen( ":Data:Maps:mapsave", "wb" );
  7851.  
  7852.                         fwrite( &player[0].coords, 1, sizeof(XYZ), tfile );
  7853.                         fwrite( &player[0].rotation, 1, sizeof(float), tfile );
  7854.                         fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
  7855.                         fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
  7856.                         for(j=0;j<player[0].num_weapons;j++){
  7857.                         fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
  7858.                         }
  7859.                         fwrite( &environment, 1, sizeof(int), tfile );
  7860.  
  7861.                         fwrite( &objects.numobjects, 1, sizeof(int), tfile );
  7862.                         fwrite( &objects.type, 1, sizeof(int)*objects.numobjects, tfile );
  7863.                         fwrite( &objects.rotation, 1, sizeof(float)*objects.numobjects, tfile );
  7864.                         fwrite( &objects.position, 1, sizeof(XYZ)*objects.numobjects, tfile );
  7865.                         fwrite( &objects.scale, 1, sizeof(float)*objects.numobjects, tfile );
  7866.  
  7867.                         fwrite( &numplayers, 1, sizeof(int), tfile );
  7868.                         if(numplayers>1&&numplayers<maxplayers)
  7869.                         for(i=1;i<numplayers;i++){
  7870.                         fwrite( &player[i].coords, 1, sizeof(XYZ), tfile );
  7871.                         fwrite( &player[i].num_weapons, 1, sizeof(int), tfile );
  7872.                         for(j=0;j<player[i].num_weapons;j++){
  7873.                         fwrite( &weapons.type[player[i].weaponids[j]], 1, sizeof(int), tfile );
  7874.                         }
  7875.                         if(player[i].numwaypoints<30){
  7876.                         fwrite( &player[i].numwaypoints, 1, sizeof(int), tfile );
  7877.                         fwrite( &player[i].waypoints, 1, sizeof(XYZ)*player[i].numwaypoints, tfile );
  7878.                         fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
  7879.                         //fwrite( &player[i].jumppath, 1, sizeof(bool), tfile );
  7880.                         }
  7881.                         else{
  7882.                         player[i].numwaypoints=0;
  7883.                         player[i].waypoint=0;
  7884.                         fwrite( &player[i].numwaypoints, 1, sizeof(int), tfile );
  7885.                         fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
  7886.                         fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
  7887.                         }
  7888.                         }
  7889.  
  7890.                         fclose(tfile);
  7891.  
  7892.                         slomotogglekeydown=1;
  7893.                         }*/
  7894.  
  7895.                         if(!IsKeyDown(theKeyMap, MAC_B_KEY)&&!IsKeyDown(theKeyMap, MAC_F_KEY)&&!IsKeyDown(theKeyMap, MAC_K_KEY)&&!IsKeyDown(theKeyMap, MAC_S_KEY)){
  7896.                             slomotogglekeydown=0;
  7897.                         }
  7898.  
  7899.  
  7900.                         if(IsKeyDown(theKeyMap, MAC_F_KEY)&&!slomotogglekeydown&&debugmode){
  7901.                             player[0].onfire=1-player[0].onfire;
  7902.                             if(player[0].onfire){
  7903.                                 player[0].CatchFire();
  7904.                             }
  7905.                             if(!player[0].onfire){
  7906.                                 float gLoc[3];
  7907.                                 float vel[3];
  7908.                                 gLoc[0]=player[0].coords.x;
  7909.                                 gLoc[1]=player[0].coords.y;
  7910.                                 gLoc[2]=player[0].coords.z;
  7911.                                 vel[0]=0;
  7912.                                 vel[1]=0;
  7913.                                 vel[2]=0;
  7914.                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
  7915.                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  7916.                                 FSOUND_SetVolume(channels[fireendsound], 256);
  7917.                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
  7918.                                 FSOUND_SetPaused(channels[stream_firesound], TRUE);
  7919.                             }
  7920.                             slomotogglekeydown=1;
  7921.                         }
  7922.                         /*
  7923.                         if(IsKeyDown(theKeyMap, MAC_L_KEY)){
  7924.                         if(player[0].bleeding<=0)
  7925.                         player[0].DoBlood(1,255);
  7926.                         }*/
  7927.  
  7928.  
  7929.                         if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)){
  7930.                             int closest=-1;
  7931.                             float closestdist=-1;
  7932.                             float distance;
  7933.                             if(numplayers>1)
  7934.                                 for(i=1;i<numplayers;i++){
  7935.                                     distance=findDistancefast(&player[i].coords,&player[0].coords);
  7936.                                     if(closestdist==-1||distance<closestdist){
  7937.                                         closestdist=distance;
  7938.                                         closest=i;
  7939.                                     }
  7940.                                 }
  7941.                                 if(closestdist>0&&closest>=0){
  7942.                                     //player[closest]=player[numplayers-1];
  7943.                                     //player[closest].skeleton=player[numplayers-1].skeleton;
  7944.                                     numplayers--;
  7945.                                 }
  7946.                                 drawmodetogglekeydown=1;
  7947.                         }
  7948.  
  7949.                         if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
  7950.                             int closest=-1;
  7951.                             float closestdist=-1;
  7952.                             float distance;
  7953.                             if(max_objects>1)
  7954.                                 for(i=1;i<max_objects;i++){
  7955.                                     distance=findDistancefast(&objects.position[i],&player[0].coords);
  7956.                                     if(closestdist==-1||distance<closestdist){
  7957.                                         closestdist=distance;
  7958.                                         closest=i;
  7959.                                     }
  7960.                                 }
  7961.                                 if(closestdist>0&&closest>=0){
  7962.                                     objects.position[closest].y-=500;
  7963.                                 }
  7964.                                 drawmodetogglekeydown=1;
  7965.                         }
  7966.  
  7967.                         if(IsKeyDown(theKeyMap, MAC_M_KEY)&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&editorenabled&&debugmode){
  7968.                             //drawmode++;
  7969.                             //if(drawmode>2)drawmode=0;
  7970.                             if(objects.numobjects<max_objects-1){          
  7971.                                 XYZ boxcoords;
  7972.                                 boxcoords.x=player[0].coords.x;
  7973.                                 boxcoords.z=player[0].coords.z;
  7974.                                 boxcoords.y=player[0].coords.y-3;
  7975.                                 if(editortype==bushtype)boxcoords.y=player[0].coords.y-.5;
  7976.                                 if(editortype==firetype)boxcoords.y=player[0].coords.y-.5;
  7977.                                 //objects.MakeObject(abs(Random()%3),boxcoords,Random()%360);
  7978.                                 float temprotat,temprotat2;
  7979.                                 temprotat=editorrotation;
  7980.                                 temprotat2=editorrotation2;
  7981.                                 if(temprotat<0||editortype==bushtype)temprotat=Random()%360;
  7982.                                 if(temprotat2<0)temprotat2=Random()%360;
  7983.  
  7984.                                 objects.MakeObject(editortype,boxcoords,(int)temprotat-((int)temprotat)%30,(int)temprotat2,editorsize);
  7985.                                 if(editortype==treetrunktype)
  7986.                                     objects.MakeObject(treeleavestype,boxcoords,Random()%360*(temprotat2<2)+(int)editorrotation-((int)editorrotation)%30,editorrotation2,editorsize);
  7987.                             }
  7988.  
  7989.                             drawmodetogglekeydown=1;
  7990.                         }
  7991.  
  7992.                         if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&editorenabled){
  7993.                             if(numplayers<maxplayers-1){
  7994.                                 player[numplayers].scale=.2*5*player[0].scale;
  7995.                                 player[numplayers].creature=rabbittype;
  7996.                                 player[numplayers].howactive=editoractive;
  7997.                                 player[numplayers].skeleton.id=numplayers;
  7998.                                 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);
  7999.  
  8000.                                 //texsize=512*512*3/texdetail/texdetail;
  8001.                                 //if(!player[numplayers].loaded)player[numplayers].skeleton.skinText = new GLubyte[texsize];
  8002.                                 //player[numplayers].skeleton.skinText.resize(texsize);
  8003.  
  8004.                                 k=abs(Random()%2)+1;
  8005.                                 if(k==0){
  8006.                                     LoadTextureSave(":Data:Textures:Fur3.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
  8007.                                     player[numplayers].whichskin=0;
  8008.                                 }
  8009.                                 else if(k==1){
  8010.                                     LoadTextureSave(":Data:Textures:Fur.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
  8011.                                     player[numplayers].whichskin=1;
  8012.                                 }
  8013.                                 else {
  8014.                                     LoadTextureSave(":Data:Textures:Fur2.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
  8015.                                     player[numplayers].whichskin=2;
  8016.                                 }
  8017.  
  8018.                                 LoadTexture(":Data:Textures:Belt.png",&player[numplayers].skeleton.drawmodelclothes.textureptr,1,1);
  8019.                                 player[numplayers].power=1;
  8020.                                 player[numplayers].speedmult=1;
  8021.                                 player[numplayers].currentanimation=bounceidleanim;
  8022.                                 player[numplayers].targetanimation=bounceidleanim;
  8023.                                 player[numplayers].currentframe=0;
  8024.                                 player[numplayers].targetframe=1;
  8025.                                 player[numplayers].target=0;
  8026.                                 player[numplayers].bled=0;
  8027.                                 player[numplayers].speed=1+(float)(Random()%100)/1000;
  8028.  
  8029.                                 player[numplayers].targetrotation=player[0].targetrotation;
  8030.                                 player[numplayers].rotation=player[0].rotation;
  8031.  
  8032.                                 player[numplayers].velocity=0;
  8033.                                 player[numplayers].coords=player[0].coords;
  8034.                                 player[numplayers].oldcoords=player[numplayers].coords;
  8035.                                 player[numplayers].realoldcoords=player[numplayers].coords;
  8036.  
  8037.                                 player[numplayers].id=numplayers;
  8038.                                 player[numplayers].skeleton.id=numplayers;
  8039.                                 player[numplayers].updatedelay=0;
  8040.                                 player[numplayers].normalsupdatedelay=0;
  8041.  
  8042.                                 player[numplayers].aitype=passivetype;
  8043.                                 player[numplayers].aitarget=0;
  8044.  
  8045.                                 if(player[0].creature==wolftype){
  8046.                                     headprop=player[0].proportionhead.x/1.1;
  8047.                                     bodyprop=player[0].proportionbody.x/1.1;
  8048.                                     armprop=player[0].proportionarms.x/1.1;
  8049.                                     legprop=player[0].proportionlegs.x/1.1;
  8050.                                 }
  8051.  
  8052.                                 if(player[0].creature==rabbittype){
  8053.                                     headprop=player[0].proportionhead.x/1.2;
  8054.                                     bodyprop=player[0].proportionbody.x/1.05;
  8055.                                     armprop=player[0].proportionarms.x/1.00;
  8056.                                     legprop=player[0].proportionlegs.x/1.1;
  8057.                                 }
  8058.  
  8059.                                 if(player[numplayers].creature==wolftype){
  8060.                                     player[numplayers].proportionhead=1.1*headprop;
  8061.                                     player[numplayers].proportionbody=1.1*bodyprop;
  8062.                                     player[numplayers].proportionarms=1.1*armprop;
  8063.                                     player[numplayers].proportionlegs=1.1*legprop;
  8064.                                 }
  8065.  
  8066.                                 if(player[numplayers].creature==rabbittype){
  8067.                                     player[numplayers].proportionhead=1.2*headprop;
  8068.                                     player[numplayers].proportionbody=1.05*bodyprop;
  8069.                                     player[numplayers].proportionarms=1.00*armprop;
  8070.                                     player[numplayers].proportionlegs=1.1*legprop;
  8071.                                     player[numplayers].proportionlegs.y=1.05*legprop;
  8072.                                 }
  8073.  
  8074.                                 player[numplayers].headless=0;
  8075.                                 player[numplayers].onfire=0;
  8076.  
  8077.                                 if(cellophane){
  8078.                                     player[numplayers].proportionhead.z=0;
  8079.                                     player[numplayers].proportionbody.z=0;
  8080.                                     player[numplayers].proportionarms.z=0;
  8081.                                     player[numplayers].proportionlegs.z=0;
  8082.                                 }
  8083.  
  8084.                                 player[numplayers].tempanimation.Load((char *)":Data:Animations:Tempanim",0,0);
  8085.  
  8086.                                 player[numplayers].damagetolerance=200;
  8087.  
  8088.                                 player[numplayers].protectionhead=player[0].protectionhead;
  8089.                                 player[numplayers].protectionhigh=player[0].protectionhigh;
  8090.                                 player[numplayers].protectionlow=player[0].protectionlow;
  8091.                                 player[numplayers].armorhead=player[0].armorhead;
  8092.                                 player[numplayers].armorhigh=player[0].armorhigh;
  8093.                                 player[numplayers].armorlow=player[0].armorlow;
  8094.                                 player[numplayers].metalhead=player[0].metalhead;
  8095.                                 player[numplayers].metalhigh=player[0].metalhigh;
  8096.                                 player[numplayers].metallow=player[0].metallow;
  8097.  
  8098.                                 player[numplayers].immobile=player[0].immobile;
  8099.  
  8100.                                 player[numplayers].numclothes=player[0].numclothes;
  8101.                                 if(player[numplayers].numclothes)
  8102.                                     for(i=0;i<player[numplayers].numclothes;i++){
  8103.                                         strcpy(player[numplayers].clothes[i], player[0].clothes[i]);
  8104.                                         player[numplayers].clothestintr[i]=player[0].clothestintr[i];
  8105.                                         player[numplayers].clothestintg[i]=player[0].clothestintg[i];
  8106.                                         player[numplayers].clothestintb[i]=player[0].clothestintb[i];
  8107.                                         tintr=player[numplayers].clothestintr[i];
  8108.                                         tintg=player[numplayers].clothestintg[i];
  8109.                                         tintb=player[numplayers].clothestintb[i];
  8110.                                         AddClothes((char *)player[numplayers].clothes[i],0,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
  8111.                                     }
  8112.                                     if(player[numplayers].numclothes){
  8113.                                         player[numplayers].DoMipmaps(5,0,0,player[numplayers].skeleton.skinsize,player[numplayers].skeleton.skinsize);
  8114.                                     }
  8115.  
  8116.                                     player[numplayers].power=player[0].power;
  8117.                                     player[numplayers].speedmult=player[0].speedmult;
  8118.  
  8119.                                     player[numplayers].damage=0;
  8120.                                     player[numplayers].permanentdamage=0;
  8121.                                     player[numplayers].superpermanentdamage=0;
  8122.                                     player[numplayers].deathbleeding=0;
  8123.                                     player[numplayers].bleeding=0;
  8124.                                     player[numplayers].numwaypoints=0;
  8125.                                     player[numplayers].waypoint=0;
  8126.                                     player[numplayers].jumppath=0;
  8127.                                     player[numplayers].weaponstuck=-1;
  8128.                                     player[numplayers].weaponactive=-1;
  8129.                                     player[numplayers].num_weapons=0;
  8130.                                     player[numplayers].bloodloss=0;
  8131.                                     player[numplayers].dead=0;
  8132.  
  8133.                                     player[numplayers].loaded=1;
  8134.  
  8135.                                     numplayers++;
  8136.                             }
  8137.                             drawmodetogglekeydown=1;
  8138.                         }
  8139.  
  8140.                         if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&editorenabled){
  8141.                             if(player[numplayers-1].numwaypoints<90){
  8142.                                 player[numplayers-1].waypoints[player[numplayers-1].numwaypoints]=player[0].coords;
  8143.                                 player[numplayers-1].waypointtype[player[numplayers-1].numwaypoints]=editorpathtype;
  8144.                                 player[numplayers-1].numwaypoints++;
  8145.                             }
  8146.                             drawmodetogglekeydown=1;
  8147.                         }
  8148.  
  8149.                         if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&editorenabled){
  8150.                             if(numpathpoints<30){
  8151.                                 bool connected,alreadyconnected;
  8152.                                 connected=0;
  8153.                                 if(numpathpoints>1)
  8154.                                     for(i=0;i<numpathpoints;i++){
  8155.                                         if(findDistancefast(&pathpoint[i],&player[0].coords)<.5&&i!=pathpointselected&&!connected){
  8156.                                             alreadyconnected=0;
  8157.                                             for(j=0;j<numpathpointconnect[pathpointselected];j++){
  8158.                                                 if(pathpointconnect[pathpointselected][j]==i)alreadyconnected=1;
  8159.                                             }
  8160.                                             if(!alreadyconnected){
  8161.                                                 numpathpointconnect[pathpointselected]++;
  8162.                                                 connected=1;
  8163.                                                 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=i;
  8164.                                             }
  8165.                                         }
  8166.                                     }
  8167.                                     if(!connected){
  8168.                                         numpathpoints++;
  8169.                                         pathpoint[numpathpoints-1]=player[0].coords;
  8170.                                         numpathpointconnect[numpathpoints-1]=0;
  8171.                                         if(numpathpoints>1&&pathpointselected!=-1){
  8172.                                             numpathpointconnect[pathpointselected]++;
  8173.                                             pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=numpathpoints-1;
  8174.                                         }
  8175.                                         pathpointselected=numpathpoints-1;
  8176.                                     }
  8177.                             }
  8178.                             drawmodetogglekeydown=1;
  8179.                         }
  8180.  
  8181.                         if(IsKeyDown(theKeyMap, MAC_PERIOD_KEY)&&!drawmodetogglekeydown&&editorenabled){
  8182.                             pathpointselected++;
  8183.                             if(pathpointselected>=numpathpoints)pathpointselected=-1;
  8184.                             drawmodetogglekeydown=1;
  8185.                         }
  8186.                         if(IsKeyDown(theKeyMap, MAC_COMMA_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!drawmodetogglekeydown&&editorenabled){
  8187.                             pathpointselected--;
  8188.                             if(pathpointselected<=-2)pathpointselected=numpathpoints-1;
  8189.                             drawmodetogglekeydown=1;
  8190.                         }
  8191.                         if(IsKeyDown(theKeyMap, MAC_COMMA_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!drawmodetogglekeydown&&editorenabled){
  8192.                             if(pathpointselected!=-1){
  8193.                                 numpathpoints--;
  8194.                                 pathpoint[pathpointselected]=pathpoint[numpathpoints];
  8195.                                 numpathpointconnect[pathpointselected]=numpathpointconnect[numpathpoints];
  8196.                                 for(i=0;i<numpathpointconnect[pathpointselected];i++){
  8197.                                     pathpointconnect[pathpointselected][i]=pathpointconnect[numpathpoints][i];
  8198.                                 }
  8199.                                 for(i=0;i<numpathpoints;i++){
  8200.                                     for(j=0;j<numpathpointconnect[i];j++){
  8201.                                         if(pathpointconnect[i][j]==pathpointselected){
  8202.                                             pathpointconnect[i][j]=pathpointconnect[i][numpathpointconnect[i]-1];
  8203.                                             numpathpointconnect[i]--;
  8204.                                         }
  8205.                                         if(pathpointconnect[i][j]==numpathpoints){
  8206.                                             pathpointconnect[i][j]=pathpointselected;
  8207.                                         }
  8208.                                     }
  8209.                                 }
  8210.                                 pathpointselected=numpathpoints-1;
  8211.                             }
  8212.                             drawmodetogglekeydown=1;
  8213.                         }
  8214.  
  8215.                         if(IsKeyDown(theKeyMap, MAC_M_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
  8216.                             editorenabled=1-editorenabled;
  8217.                             if(editorenabled){
  8218.                                 player[0].damagetolerance=100000;
  8219.                                 player[0].damage=0;
  8220.                                 player[0].superpermanentdamage=0;
  8221.                                 player[0].bloodloss=0;
  8222.                                 player[0].deathbleeding=0;
  8223.                             }
  8224.                             if(!editorenabled){
  8225.                                 player[0].damagetolerance=200;
  8226.                                 player[0].damage=0;
  8227.                                 player[0].permanentdamage=0;
  8228.                                 player[0].superpermanentdamage=0;
  8229.                                 player[0].bloodloss=0;
  8230.                                 player[0].deathbleeding=0;
  8231.                             }
  8232.                             drawmodetogglekeydown=1;
  8233.                         }
  8234.  
  8235.                         if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
  8236.                             editortype--;
  8237.                             if(editortype==treeleavestype||editortype==10)editortype--;
  8238.                             if(editortype<0)editortype=firetype;
  8239.                             drawmodetogglekeydown=1;
  8240.                         }
  8241.  
  8242.                         if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
  8243.                             editortype++;
  8244.                             if(editortype==treeleavestype||editortype==10)editortype++;
  8245.                             if(editortype>firetype)editortype=0;
  8246.                             drawmodetogglekeydown=1;
  8247.                         }
  8248.  
  8249.                         if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
  8250.                             editorrotation-=multiplier*100;
  8251.                             if(editorrotation<-.01)editorrotation=-.01;
  8252.                             drawmodetogglekeydown=1;
  8253.                         }
  8254.  
  8255.                         if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
  8256.                             editorrotation+=multiplier*100;
  8257.                             drawmodetogglekeydown=1;
  8258.                         }
  8259.  
  8260.                         if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
  8261.                             editorsize+=multiplier;
  8262.                             drawmodetogglekeydown=1;
  8263.                         }
  8264.  
  8265.                         if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
  8266.                             editorsize-=multiplier;
  8267.                             if(editorsize<.1)editorsize=.1;
  8268.                             drawmodetogglekeydown=1;
  8269.                         }
  8270.  
  8271.  
  8272.                         if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
  8273.                             mapradius-=multiplier*10;
  8274.                         }
  8275.  
  8276.                         if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
  8277.                             mapradius+=multiplier*10;
  8278.                         }
  8279.                         /*
  8280.                         if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
  8281.                         mapcenter.x+=multiplier*20;
  8282.                         }
  8283.  
  8284.                         if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
  8285.                         mapcenter.x-=multiplier*20;
  8286.                         }
  8287.  
  8288.                         if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
  8289.                         mapcenter.z+=multiplier*20;
  8290.                         }
  8291.  
  8292.                         if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
  8293.                         mapcenter.z-=multiplier*20;
  8294.                         }
  8295.                         */
  8296.                         if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
  8297.                             editorrotation2+=multiplier*100;
  8298.                         }
  8299.  
  8300.                         if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
  8301.                             editorrotation2-=multiplier*100;
  8302.                             if(editorrotation2<-.01)editorrotation2=-.01;
  8303.                         }
  8304.                         if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&objects.numobjects&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)){
  8305.                             int closest=-1;
  8306.                             float closestdist=-1;
  8307.                             float distance;
  8308.                             for(i=0;i<objects.numobjects;i++){
  8309.                                 distance=findDistancefast(&objects.position[i],&player[0].coords);
  8310.                                 if(closestdist==-1||distance<closestdist){
  8311.                                     closestdist=distance;
  8312.                                     closest=i;
  8313.                                 }
  8314.                             }
  8315.                             if(closestdist>0&&closest>=0)objects.DeleteObject(closest);    
  8316.                             drawmodetogglekeydown=1;
  8317.                         }
  8318.  
  8319.  
  8320.                         if(!IsKeyDown(theKeyMap, MAC_M_KEY)&&!IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&!IsKeyDown(theKeyMap, MAC_COMMA_KEY)&&!IsKeyDown(theKeyMap, MAC_PERIOD_KEY)&&!IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&!IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&!IsKeyDown(theKeyMap, MAC_P_KEY)){
  8321.                             drawmodetogglekeydown=0;
  8322.                         }
  8323.  
  8324.                         if(IsKeyDown(theKeyMap, MAC_N_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&!texturesizetogglekeydown&&debugmode){
  8325.                             //if(!player[0].skeleton.free)player[0].damage+=500;
  8326.                             player[0].RagDoll(0);
  8327.                             //player[0].spurt=1;
  8328.                             //player[0].DoDamage(1000);
  8329.  
  8330.                             float gLoc[3];
  8331.                             float vel[3];
  8332.                             gLoc[0]=player[0].coords.x;
  8333.                             gLoc[1]=player[0].coords.y;
  8334.                             gLoc[2]=player[0].coords.z;
  8335.                             vel[0]=player[0].velocity.x;
  8336.                             vel[1]=player[0].velocity.y;
  8337.                             vel[2]=player[0].velocity.z;
  8338.                             PlaySoundEx( whooshsound, samp[whooshsound], NULL, TRUE);
  8339.                             FSOUND_3D_SetAttributes(channels[whooshsound], gLoc, vel);
  8340.                             FSOUND_SetVolume(channels[whooshsound], 128);
  8341.                             FSOUND_SetPaused(channels[whooshsound], FALSE);
  8342.                             //FSOUND_SetPaused(channels[whooshsound], TRUE);
  8343.  
  8344.                             texturesizetogglekeydown=1;
  8345.                         }
  8346.  
  8347.                         if(IsKeyDown(theKeyMap, MAC_N_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&!texturesizetogglekeydown&&debugmode){
  8348.  
  8349.                             int closest=-1;
  8350.                             float closestdist=-1;
  8351.                             float distance;
  8352.                             for(i=0;i<objects.numobjects;i++){
  8353.                                 if(objects.type[i]==treeleavestype){
  8354.                                     objects.scale[i]*=.9;
  8355.                                 }
  8356.                             }
  8357.                             texturesizetogglekeydown=1;
  8358.                         }
  8359.  
  8360.                         static XYZ relative;
  8361.                         static int randattack;
  8362.                         //Attack
  8363.                         static bool playerrealattackkeydown=0;
  8364.  
  8365.                         if(!buttons[0])oldbutton=0;
  8366.                         if(!IsKeyDown(theKeyMap, attackkey))oldattackkey=0;
  8367.                         if(oldattackkey)player[0].attackkeydown=0;
  8368.                         if(oldattackkey)playerrealattackkeydown=0;
  8369.                         if(!oldattackkey)playerrealattackkeydown=IsKeyDown(theKeyMap, attackkey);
  8370.                         if((player[0].parriedrecently<=0||player[0].weaponactive==-1)&&(!oldattackkey||(realthreat&&player[0].lastattack!=swordslashanim&&player[0].lastattack!=knifeslashstartanim&&player[0].lastattack!=staffhitanim&&player[0].lastattack!=staffspinhitanim)))player[0].attackkeydown=IsKeyDown(theKeyMap, attackkey);
  8371.                         if(IsKeyDown(theKeyMap, attackkey)&&!oldattackkey&&!player[0].backkeydown){
  8372.                             for(k=0;k<numplayers;k++){
  8373.                                 if((player[k].targetanimation==swordslashanim||player[k].targetanimation==staffhitanim||player[k].targetanimation==staffspinhitanim)&&player[0].currentanimation!=dodgebackanim&&!player[k].skeleton.free)
  8374.                                     player[k].Reverse();
  8375.                             }
  8376.                         }
  8377.  
  8378.                         if(!hostile||indialogue!=-1)player[0].attackkeydown=0;
  8379.  
  8380.                         for(k=0;k<numplayers;k++){
  8381.                             if(indialogue!=-1)player[k].attackkeydown=0;
  8382.                             if(player[k].targetanimation!=rabbitrunninganim&&player[k].targetanimation!=wolfrunninganim){
  8383.                                 if(player[k].aitype!=playercontrolled)player[k].victim=&player[0];
  8384.                                 if(player[k].attackkeydown&&player[k].jumppower<=1&&player[k].backkeydown&&player[k].targetanimation!=backhandspringanim&&(player[k].isIdle()||player[k].isStop()||player[k].isRun()||player[k].targetanimation==walkanim)){
  8385.                                     player[k].jumppower-=2;
  8386.                                 }
  8387.                                 if(player[k].attackkeydown&&player[k].jumppower>1&&player[k].backkeydown&&player[k].targetanimation!=backhandspringanim&&(player[k].isIdle()||player[k].isStop()||player[k].isRun()||player[k].targetanimation==walkanim)){
  8388.                                     for(i=0;i<numplayers;i++){
  8389.                                         if(i==k)i++;
  8390.                                         if(player[i].targetanimation==swordslashanim||player[i].targetanimation==knifeslashstartanim||player[i].targetanimation==staffhitanim||player[i].targetanimation==staffspinhitanim)
  8391.                                             if(findDistancefast(&player[k].coords,&player[i].coords)<6.5&&!player[i].skeleton.free){
  8392.                                                 player[k].targetanimation=dodgebackanim;
  8393.                                                 player[k].target=0;
  8394.                                                 player[k].targetframe=0;
  8395.                                                 rotatetarget=player[i].coords-player[k].coords;
  8396.                                                 Normalise(&rotatetarget);
  8397.                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
  8398.                                                 player[k].targetrotation*=360/6.28;
  8399.                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
  8400.  
  8401.                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;
  8402.                                             }
  8403.                                     }
  8404.                                     if(player[k].targetanimation!=dodgebackanim){
  8405.                                         if(k==0)numflipped++;
  8406.                                         player[k].targetanimation=backhandspringanim;
  8407.                                         player[k].target=0;
  8408.                                         player[k].targetframe=0;
  8409.                                         player[k].targetrotation=-rotation+180;
  8410.                                         if(player[k].leftkeydown)player[k].targetrotation-=45;
  8411.                                         if(player[k].rightkeydown)player[k].targetrotation+=45;
  8412.                                         player[k].rotation=player[k].targetrotation;
  8413.                                         player[k].jumppower-=2;
  8414.                                     }
  8415.                                 }
  8416.                                 if(player[k].attackkeydown&&!animation[player[k].targetanimation].attack&&!player[k].backkeydown&&(player[k].isIdle()||player[k].isRun()||player[k].targetanimation==walkanim||player[k].targetanimation==sneakanim||player[k].isCrouch())){
  8417.                                     player[k].hasvictim=0;
  8418.                                     if(numplayers>1)
  8419.                                         for(i=0;i<numplayers;i++){
  8420.                                             if(i==k)i++;
  8421.                                             if(!player[k].hasvictim)
  8422.                                                 if((k==0||i==0)&&i!=k&&i<numplayers&&k<numplayers&&animation[player[k].targetanimation].attack!=reversal){ 
  8423.                                                     if(findDistancefast(&player[k].coords,&player[i].coords)<4.5&&!player[i].skeleton.free&&player[i].howactive<typedead1&&player[i].targetanimation!=jumpreversedanim&&player[i].targetanimation!=rabbitkickreversedanim&&player[i].targetanimation!=rabbitkickanim&&player[k].targetanimation!=rabbitkickanim&&player[i].targetanimation!=getupfrombackanim&&(player[i].targetanimation!=staggerbackhighanim&&(player[i].targetanimation!=staggerbackhardanim||animation[staggerbackhardanim].label[player[i].targetframe]==6))&&player[i].targetanimation!=jumpdownanim&&player[i].targetanimation!=jumpupanim&&player[i].targetanimation!=getupfromfrontanim){
  8424.                                                         player[k].victim=&player[i];
  8425.                                                         player[k].hasvictim=1;
  8426.                                                         if(player[k].aitype==playercontrolled){
  8427.                                                             if(findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)&&player[k].crouchkeydown&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=sweepanim;
  8428.                                                             else if(findDistancefast(&player[k].coords,&player[i].coords)<1.5*(player[k].scale*5)*(player[k].scale*5)&&animation[player[i].targetanimation].height!=lowheight&&!player[k].forwardkeydown&&!player[k].leftkeydown&&!player[k].rightkeydown&&!player[k].crouchkeydown&&player[k].weaponactive==-1&&!reversaltrain)player[k].targetanimation=winduppunchanim;
  8429.                                                             else if(findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)&&animation[player[i].targetanimation].height!=lowheight&&!player[k].forwardkeydown&&!player[k].leftkeydown&&!player[k].rightkeydown&&!player[k].crouchkeydown&&player[k].weaponactive==-1)player[k].targetanimation=upunchanim;
  8430.                                                             else if(findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)&&player[k].weaponactive!=-1&&player[i].staggerdelay>0&&weapons.type[player[k].weaponids[player[k].weaponactive]]==knife&&player[i].bloodloss>player[i].damagetolerance/2)player[k].targetanimation=knifefollowanim;
  8431.                                                             else if(findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)&&animation[player[i].targetanimation].height!=lowheight&&!player[k].forwardkeydown&&!player[k].leftkeydown&&!player[k].rightkeydown&&!player[k].crouchkeydown&&player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==knife&&player[k].weaponmissdelay<=0)player[k].targetanimation=knifeslashstartanim;
  8432.                                                             else if(findDistancefast(&player[k].coords,&player[i].coords)<4.5*(player[k].scale*5)*(player[k].scale*5)&&animation[player[i].targetanimation].height!=lowheight&&!player[k].crouchkeydown&&player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==sword&&player[k].weaponmissdelay<=0)player[k].targetanimation=swordslashanim;
  8433.                                                             else if(findDistancefast(&player[k].coords,&player[i].coords)<4.5*(player[k].scale*5)*(player[k].scale*5)&&animation[player[i].targetanimation].height!=lowheight&&!player[k].crouchkeydown&&player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==staff&&player[k].weaponmissdelay<=0&&!player[k].leftkeydown&&!player[k].rightkeydown&&!player[k].forwardkeydown)player[k].targetanimation=staffhitanim;
  8434.                                                             else if(findDistancefast(&player[k].coords,&player[i].coords)<4.5*(player[k].scale*5)*(player[k].scale*5)&&animation[player[i].targetanimation].height!=lowheight&&!player[k].crouchkeydown&&player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==staff&&player[k].weaponmissdelay<=0)player[k].targetanimation=staffspinhitanim;
  8435.                                                             else if(findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=spinkickanim;
  8436.                                                             else if(findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)&&animation[player[i].targetanimation].height==lowheight&&animation[player[k].targetanimation].attack!=normalattack)player[k].targetanimation=lowkickanim;
  8437.                                                         }
  8438.                                                         else {
  8439.                                                             if(findDistancefast(&player[k].coords,&player[i].coords)<4.5*(player[k].scale*5)*(player[k].scale*5)){
  8440.                                                                 if(player[k].weaponactive==-1)randattack=abs(Random()%5);
  8441.                                                                 else randattack=abs(Random()%5);
  8442.                                                                 if(player[k].weaponactive==-1&&findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)){
  8443.                                                                     if(randattack==0&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=sweepanim;
  8444.                                                                     else if(randattack==1&&animation[player[i].targetanimation].height!=lowheight&&player[k].weaponactive==-1)player[k].targetanimation=upunchanim;
  8445.                                                                     else if(randattack==2&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=spinkickanim;
  8446.                                                                     else if(animation[player[i].targetanimation].height==lowheight)player[k].targetanimation=lowkickanim;
  8447.                                                                 }
  8448.                                                                 if(player[k].weaponactive!=-1){
  8449.                                                                     if((tutoriallevel!=1||player[k].weaponactive==-1)&&findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)&&randattack==0&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=sweepanim;
  8450.                                                                     else if(findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)/*&&animation[player[i].targetanimation].height!=lowheight*/&&weapons.type[player[k].weaponids[player[k].weaponactive]]==knife&&player[k].weaponmissdelay<=0)player[k].targetanimation=knifeslashstartanim;
  8451.                                                                     //else if(findDistancefast(&player[k].coords,&player[i].coords)<2.5&&player[k].weaponactive!=-1&&player[i].staggerdelay>0&&weapons.type[player[k].weaponids[player[k].weaponactive]]==knife)player[k].targetanimation=knifefollowanim;
  8452.                                                                     else if(!(player[0].victim==&player[i]&&player[0].hasvictim&&player[0].targetanimation==swordslashanim)&&weapons.type[player[k].weaponids[player[k].weaponactive]]==sword&&player[k].weaponmissdelay<=0)player[k].targetanimation=swordslashanim;
  8453.                                                                     else if(!(player[0].victim==&player[i]&&player[0].hasvictim&&player[0].targetanimation==swordslashanim)&&weapons.type[player[k].weaponids[player[k].weaponactive]]==staff&&player[k].weaponmissdelay<=0&&randattack<3)player[k].targetanimation=staffhitanim;
  8454.                                                                     else if(!(player[0].victim==&player[i]&&player[0].hasvictim&&player[0].targetanimation==swordslashanim)&&weapons.type[player[k].weaponids[player[k].weaponactive]]==staff&&player[k].weaponmissdelay<=0&&randattack>=3)player[k].targetanimation=staffspinhitanim;
  8455.                                                                     else if((tutoriallevel!=1||player[k].weaponactive==-1)&&findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)&&randattack==1&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=spinkickanim;
  8456.                                                                     else if(findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)&&animation[player[i].targetanimation].height==lowheight&&animation[player[k].targetanimation].attack!=normalattack)player[k].targetanimation=lowkickanim;
  8457.                                                                 }
  8458.                                                             }
  8459.                                                         }
  8460.                                                         if(player[k].targetanimation==upunchanim&&player[k].creature==wolftype)player[k].targetanimation=wolfslapanim;
  8461.                                                     }
  8462.                                                     if((tutoriallevel!=1||tutorialstage==22)&&player[i].howactive<typedead1&&findDistancefast(&player[k].coords,&player[i].coords)<1.5*(player[k].scale*5)*(player[k].scale*5)&&!player[i].skeleton.free&&player[i].targetanimation!=getupfrombackanim&&player[i].targetanimation!=getupfromfrontanim&&(((player[i].stunned>0&&player[k].madskills)||(player[i].surprised>0)||player[i].aitype==passivetype)||(player[k].weaponactive!=-1&&player[i].stunned>0))&&normaldotproduct(player[i].facing,player[i].coords-player[k].coords)>0&&(k==0)){
  8463.                                                         if(player[k].weaponactive==-1){
  8464.                                                             player[i].targetanimation=sneakattackedanim;
  8465.                                                             player[i].currentanimation=sneakattackedanim;
  8466.                                                             player[k].currentanimation=sneakattackanim;
  8467.                                                             player[k].targetanimation=sneakattackanim;
  8468.                                                             player[k].oldcoords=player[k].coords;
  8469.                                                             player[k].coords=player[i].coords;
  8470.                                                         }
  8471.                                                         if(player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==knife){
  8472.                                                             player[i].targetanimation=knifesneakattackedanim;
  8473.                                                             player[i].currentanimation=knifesneakattackedanim;
  8474.                                                             player[k].currentanimation=knifesneakattackanim;
  8475.                                                             player[k].targetanimation=knifesneakattackanim;
  8476.                                                             player[i].oldcoords=player[i].coords;
  8477.                                                             player[i].coords=player[k].coords;
  8478.                                                         }
  8479.                                                         if(player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==sword){
  8480.                                                             player[i].targetanimation=swordsneakattackedanim;
  8481.                                                             player[i].currentanimation=swordsneakattackedanim;
  8482.                                                             player[k].currentanimation=swordsneakattackanim;
  8483.                                                             player[k].targetanimation=swordsneakattackanim;
  8484.                                                             player[i].oldcoords=player[i].coords;
  8485.                                                             player[i].coords=player[k].coords;
  8486.                                                         }
  8487.                                                         if(player[k].weaponactive==-1||weapons.type[player[k].weaponids[player[k].weaponactive]]!=staff){
  8488.                                                             player[k].victim=&player[i];
  8489.                                                             player[k].hasvictim=1;
  8490.                                                             player[i].targettilt2=0;
  8491.                                                             player[i].targetframe=1;
  8492.                                                             player[i].currentframe=0;
  8493.                                                             player[i].target=0;
  8494.                                                             player[i].velocity=0;
  8495.                                                             player[k].targettilt2=player[i].targettilt2;
  8496.                                                             player[k].currentframe=player[i].currentframe;
  8497.                                                             player[k].targetframe=player[i].targetframe;
  8498.                                                             player[k].target=player[i].target;
  8499.                                                             player[k].velocity=0;
  8500.                                                             player[k].targetrotation=player[i].rotation;
  8501.                                                             player[k].rotation=player[i].rotation;
  8502.                                                             player[i].targetrotation=player[i].rotation;
  8503.                                                         }
  8504.                                                     }
  8505.                                                     if(animation[player[k].targetanimation].attack==normalattack&&player[k].victim==&player[i]&&(!player[i].skeleton.free)){
  8506.                                                         oldattackkey=1;
  8507.                                                         player[k].targetframe=0;
  8508.                                                         player[k].target=0;
  8509.                                                         //player[k].velocity=0;
  8510.  
  8511.                                                         rotatetarget=player[i].coords-player[k].coords;
  8512.                                                         Normalise(&rotatetarget);
  8513.                                                         player[k].targetrotation=-asin(0-rotatetarget.x);
  8514.                                                         player[k].targetrotation*=360/6.28;
  8515.                                                         if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
  8516.  
  8517.                                                         player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
  8518.  
  8519.                                                         player[k].lastattack3=player[k].lastattack2;
  8520.                                                         player[k].lastattack2=player[k].lastattack;
  8521.                                                         player[k].lastattack=player[k].targetanimation;
  8522.                                                         //player[k].targettilt2=0;
  8523.                                                         //slomo=1;
  8524.                                                         //slomodelay=.2;
  8525.                                                     }
  8526.                                                     if(player[k].targetanimation==knifefollowanim&&player[k].victim==&player[i]){
  8527.                                                         rotatetarget=player[i].coords-player[k].coords;
  8528.                                                         Normalise(&rotatetarget);
  8529.                                                         player[k].targetrotation=-asin(0-rotatetarget.x);
  8530.                                                         player[k].targetrotation*=360/6.28;
  8531.                                                         if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
  8532.                                                         player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
  8533.                                                         oldattackkey=1;
  8534.                                                         player[k].victim=&player[i];
  8535.                                                         player[k].hasvictim=1;
  8536.                                                         player[i].targetanimation=knifefollowedanim;
  8537.                                                         player[i].currentanimation=knifefollowedanim;
  8538.                                                         player[i].targettilt2=0;
  8539.                                                         player[i].targettilt2=player[k].targettilt2;
  8540.                                                         player[i].targetframe=1;
  8541.                                                         player[i].currentframe=0;
  8542.                                                         player[i].target=0;
  8543.                                                         player[i].velocity=0;
  8544.                                                         player[k].currentanimation=knifefollowanim;
  8545.                                                         player[k].targetanimation=knifefollowanim;
  8546.                                                         player[k].targettilt2=player[i].targettilt2;
  8547.                                                         player[k].currentframe=player[i].currentframe;
  8548.                                                         player[k].targetframe=player[i].targetframe;
  8549.                                                         player[k].target=player[i].target;
  8550.                                                         player[k].velocity=0;
  8551.                                                         player[k].oldcoords=player[k].coords;
  8552.                                                         player[i].coords=player[k].coords;
  8553.                                                         player[i].targetrotation=player[k].targetrotation;
  8554.                                                         player[i].rotation=player[k].targetrotation;
  8555.                                                         player[k].rotation=player[k].targetrotation;
  8556.                                                         player[i].rotation=player[k].targetrotation;
  8557.                                                     }
  8558.                                                 }
  8559.                                         }
  8560.                                         bool hasstaff=0;
  8561.                                         if(player[k].weaponactive!=-1){
  8562.                                             if(weapons.type[player[k].weaponids[player[k].weaponactive]]==staff)hasstaff=1;
  8563.                                         }
  8564.                                         if(numplayers>1)
  8565.                                             for(i=0;i<numplayers;i++){
  8566.                                                 if(i==k)i++;
  8567.                                                 if((playerrealattackkeydown||player[i].dead||!hasstaff)&&(k==0||i==0)&&i!=k&&i<numplayers&&k<numplayers&&animation[player[k].targetanimation].attack==neutral&&k==0){  
  8568.                                                     if(!player[i].dead||!realthreat||(player[k].weaponactive==-1&&player[k].crouchkeydown))
  8569.                                                         if(player[i].skeleton.free)
  8570.                                                             if(findDistancefast(&player[k].coords,&player[i].coords)<3.5*(player[k].scale*5)*(player[k].scale*5)&&(player[i].dead||player[i].skeleton.longdead>1000||player[k].isRun()||(hasstaff)||(player[k].weaponactive!=-1&&player[i].skeleton.free&&(player[i].skeleton.longdead>2000||player[i].damage>player[i].damagetolerance/8||player[i].bloodloss>player[i].damagetolerance/2)&&findDistancefast(&player[k].coords,&player[i].coords)<1.5*(player[k].scale*5)*(player[k].scale*5)))){
  8571.                                                                 player[k].victim=&player[i];
  8572.                                                                 player[k].hasvictim=1;
  8573.                                                                 if(player[k].weaponactive!=-1&&tutoriallevel!=1){
  8574.                                                                     if(player[k].crouchkeydown&&player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==knife&&findDistancefast(&player[k].coords,&player[i].coords)<1.5*(player[k].scale*5)*(player[k].scale*5))player[k].targetanimation=crouchstabanim;
  8575.                                                                     if(player[k].crouchkeydown&&findDistancefast(&player[k].coords,&player[i].coords)<1.5*(player[k].scale*5)*(player[k].scale*5)/*&&player[i].dead!=2*/&&weapons.type[player[k].weaponids[player[k].weaponactive]]==sword)player[k].targetanimation=swordgroundstabanim;
  8576.                                                                     if(/*(player[k].crouchkeydown||!player[i].dead)&&*/findDistancefast(&player[k].coords,&player[i].coords)<3.5*(player[k].scale*5)*(player[k].scale*5)/*&&player[i].dead!=2*/&&weapons.type[player[k].weaponids[player[k].weaponactive]]==staff)player[k].targetanimation=staffgroundsmashanim;
  8577.                                                                 }
  8578.                                                                 if(findDistancefast(&player[k].coords,&player[i].coords)<2.5&&player[k].crouchkeydown&&player[k].targetanimation!=crouchstabanim&&(player[k].weaponactive==-1)&&player[i].dead&&player[i].skeleton.free&&player[i].skeleton.longdead>1000){
  8579.                                                                     player[k].targetanimation=killanim;
  8580.                                                                     for(j=0;j<terrain.numdecals;j++){
  8581.                                                                         if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&terrain.decalalivetime[j]<2){
  8582.                                                                             terrain.DeleteDecal(j);
  8583.                                                                         }
  8584.                                                                     }
  8585.                                                                     for(l=0;l<objects.numobjects;l++){
  8586.                                                                         if(objects.model[l].type==decalstype)
  8587.                                                                             for(j=0;j<objects.model[l].numdecals;j++){
  8588.                                                                                 if((objects.model[l].decaltype[j]==blooddecal||objects.model[l].decaltype[j]==blooddecalslow)&&objects.model[l].decalalivetime[j]<2){
  8589.                                                                                     objects.model[l].DeleteDecal(j);
  8590.                                                                                 }
  8591.                                                                             }
  8592.                                                                     }
  8593.                                                                 }
  8594.                                                                 if(!player[i].dead||musictype!=2)
  8595.                                                                     if(findDistancefast(&player[k].coords,&player[i].coords)<3.5&&(player[k].isRun()||(player[k].isIdle()&&player[k].attackkeydown))&&(player[k].staggerdelay<=0&&(player[i].dead||(player[i].skeleton.longdead<300&&player[k].lastattack!=spinkickanim&&player[i].skeleton.free)))&&(!player[i].dead||musictype!=stream_music2)){
  8596.                                                                         player[k].targetanimation=dropkickanim;
  8597.                                                                         for(j=0;j<terrain.numdecals;j++){
  8598.                                                                             if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&terrain.decalalivetime[j]<2){
  8599.                                                                                 terrain.DeleteDecal(j);
  8600.                                                                             }
  8601.                                                                         }
  8602.                                                                         for(l=0;l<objects.numobjects;l++){
  8603.                                                                             if(objects.model[l].type==decalstype)
  8604.                                                                                 for(j=0;j<objects.model[l].numdecals;j++){
  8605.                                                                                     if((objects.model[l].decaltype[j]==blooddecal||objects.model[l].decaltype[j]==blooddecalslow)&&objects.model[l].decalalivetime[j]<2){
  8606.                                                                                         objects.model[l].DeleteDecal(j);
  8607.                                                                                     }
  8608.                                                                                 }
  8609.                                                                         }
  8610.                                                                     }
  8611.                                                             }
  8612.                                                             if(animation[player[k].targetanimation].attack==normalattack&&player[k].victim==&player[i]&&(!player[i].skeleton.free||player[k].targetanimation==killanim||player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim||player[k].targetanimation==staffgroundsmashanim||player[k].targetanimation==dropkickanim)){
  8613.                                                                 oldattackkey=1;
  8614.                                                                 player[k].targetframe=0;
  8615.                                                                 player[k].target=0;
  8616.                                                                 //player[k].velocity=0;
  8617.  
  8618.                                                                 rotatetarget=player[i].coords-player[k].coords;
  8619.                                                                 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim||player[k].targetanimation==staffgroundsmashanim){
  8620.                                                                     rotatetarget=(player[i].coords+(player[i].skeleton.joints[player[i].skeleton.jointlabels[abdomen]].position+player[i].skeleton.joints[player[i].skeleton.jointlabels[neck]].position)/2*player[i].scale)-player[k].coords;
  8621.                                                                 }
  8622.                                                                 Normalise(&rotatetarget);
  8623.                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
  8624.                                                                 player[k].targetrotation*=360/6.28;
  8625.                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
  8626.  
  8627.                                                                 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim){
  8628.                                                                     player[k].targetrotation+=(float)(abs(Random()%100)-50)/4;
  8629.                                                                 }
  8630.  
  8631.                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
  8632.                                                                 if(player[k].targetanimation==staffgroundsmashanim)player[k].targettilt2+=10;
  8633.  
  8634.                                                                 player[k].lastattack3=player[k].lastattack2;
  8635.                                                                 player[k].lastattack2=player[k].lastattack;
  8636.                                                                 player[k].lastattack=player[k].targetanimation;
  8637.  
  8638.                                                                 if(player[k].targetanimation==swordgroundstabanim){
  8639.                                                                     player[k].targetrotation+=30;
  8640.                                                                 }
  8641.                                                                 //player[k].targettilt2=0;
  8642.                                                                 //slomo=1;
  8643.                                                                 //slomodelay=.2;
  8644.                                                             }
  8645.                                                 }
  8646.                                             }
  8647.                                             if(!player[k].hasvictim){
  8648.                                                 for(i=0;i<numplayers;i++){
  8649.                                                     if((player[k].hasvictim==0)&&i!=k&&(i==0||k==0)&&!player[i].skeleton.free){
  8650.                                                         player[k].victim=&player[i];
  8651.                                                         player[k].hasvictim=1;
  8652.                                                     }
  8653.                                                     if(player[k].hasvictim&&!player[i].skeleton.free)
  8654.                                                         if(findDistancefast(&player[k].coords,&player[i].coords)<findDistancefast(&player[k].coords,&player[k].victim->coords)&&i!=k&&(i==0||k==0)){
  8655.                                                             player[k].victim=&player[i];
  8656.                                                         }
  8657.                                                 }
  8658.                                             }
  8659.                                             if(player[k].aitype==playercontrolled)
  8660.                                                 if(player[k].attackkeydown&&(player[k].isRun())&&player[k].wasRun()&&((player[k].hasvictim&&findDistancefast(&player[k].coords,&player[k].victim->coords)<12*(player[k].scale*5)*(player[k].scale*5)&&findDistancefast(&player[k].coords,&player[k].victim->coords)>7*(player[k].scale*5)*(player[k].scale*5)&&!player[k].victim->skeleton.free&&player[k].victim->targetanimation!=getupfrombackanim&&player[k].victim->targetanimation!=getupfromfrontanim&&animation[player[k].victim->targetanimation].height!=lowheight&&player[k].aitype!=playercontrolled&&normaldotproduct(player[k].facing,player[k].victim->coords-player[k].coords)>0&&player[k].rabbitkickenabled)||player[k].jumpkeydown)){
  8661.                                                     oldattackkey=1;
  8662.                                                     player[k].targetanimation=rabbitkickanim;
  8663.                                                     player[k].targetframe=0;
  8664.                                                     player[k].target=0;
  8665.                                                 }
  8666.                                                 if(animation[player[k].targetanimation].attack&&k==0){
  8667.                                                     numattacks++;
  8668.                                                     bool armedstaff=0;
  8669.                                                     if(player[k].weaponactive!=-1){
  8670.                                                         if(weapons.type[player[k].weaponids[player[k].weaponactive]]==staff)armedstaff=1;
  8671.                                                     }
  8672.                                                     bool armedsword=0;
  8673.                                                     if(player[k].weaponactive!=-1){
  8674.                                                         if(weapons.type[player[k].weaponids[player[k].weaponactive]]==sword)armedsword=1;
  8675.                                                     }
  8676.                                                     bool armedknife=0;
  8677.                                                     if(player[k].weaponactive!=-1){
  8678.                                                         if(weapons.type[player[k].weaponids[player[k].weaponactive]]==knife)armedknife=1;
  8679.                                                     }
  8680.                                                     if(armedstaff)numstaffattack++;
  8681.                                                     else if(armedsword)numswordattack++;
  8682.                                                     else if(armedknife)numknifeattack++;
  8683.                                                     else numunarmedattack++;
  8684.                                                 }
  8685.                                 }
  8686.                             }
  8687.                         }
  8688.  
  8689.                         //Collisions
  8690.                         static float collisionradius;
  8691.                         if(numplayers>1)
  8692.                             for(k=0;k<numplayers;k++){
  8693.                                 for(i=k;i<numplayers;i++){
  8694.                                     if(i==k)i++;
  8695.                                     if(i<numplayers)
  8696.                                         if((animation[player[i].targetanimation].attack!=reversed&&animation[player[i].targetanimation].attack!=reversal&&animation[player[k].targetanimation].attack!=reversed&&animation[player[k].targetanimation].attack!=reversal)||(i!=0&&k!=0))
  8697.                                             if((animation[player[i].currentanimation].attack!=reversed&&animation[player[i].currentanimation].attack!=reversal&&animation[player[k].currentanimation].attack!=reversed&&animation[player[k].currentanimation].attack!=reversal)||(i!=0&&k!=0))
  8698.                                                 if(player[i].howactive<=typesleeping&&player[k].howactive<=typesleeping)
  8699.                                                     if(player[i].howactive!=typesittingwall&&player[k].howactive!=typesittingwall)
  8700.                                                         if(i!=k&&player[i].whichpatchx==player[k].whichpatchx&&player[i].whichpatchz==player[k].whichpatchz&&player[k].skeleton.oldfree==player[k].skeleton.free&&player[i].skeleton.oldfree==player[i].skeleton.free&&player[i].targetanimation!=climbanim&&player[i].targetanimation!=hanganim&&player[k].targetanimation!=climbanim&&player[k].targetanimation!=hanganim)
  8701.                                                             if(player[i].coords.y>player[k].coords.y-3)
  8702.                                                                 if(player[i].coords.y<player[k].coords.y+3)
  8703.                                                                     if(player[i].coords.x>player[k].coords.x-3)
  8704.                                                                         if(player[i].coords.x<player[k].coords.x+3)
  8705.                                                                             if(player[i].coords.z>player[k].coords.z-3)
  8706.                                                                                 if(player[i].coords.z<player[k].coords.z+3){
  8707.                                                                                     if(findDistancefast(&player[i].coords,&player[k].coords)<3*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5)){
  8708.                                                                                         if(player[i].onfire||player[k].onfire){
  8709.                                                                                             if(!player[i].onfire)player[i].CatchFire();
  8710.                                                                                             if(!player[k].onfire)player[k].CatchFire();
  8711.                                                                                         }  
  8712.                                                                                     }
  8713.  
  8714.                                                                                     tempcoords1=player[i].coords;
  8715.                                                                                     tempcoords2=player[k].coords;
  8716.                                                                                     if(!player[i].skeleton.oldfree)tempcoords1.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[abdomen]].position.y*player[i].scale;
  8717.                                                                                     if(!player[k].skeleton.oldfree)tempcoords2.y+=player[k].skeleton.joints[player[k].skeleton.jointlabels[abdomen]].position.y*player[k].scale;
  8718.                                                                                     collisionradius=1.2*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5);
  8719.                                                                                     if(player[0].hasvictim)
  8720.                                                                                         if(player[0].targetanimation==rabbitkickanim&&(k==0||i==0)&&!player[0].victim->skeleton.free)collisionradius=3;
  8721.                                                                                     if((!player[i].skeleton.oldfree||!player[k].skeleton.oldfree)&&(findDistancefast(&tempcoords1,&tempcoords2)<collisionradius||findDistancefast(&player[i].coords,&player[k].coords)<collisionradius)){  
  8722.                                                                                         if(k==0)
  8723.                                                                                             if(player[k].targetanimation==jumpdownanim&&!player[k].skeleton.oldfree&&!player[k].skeleton.free&&player[i].skeleton.oldfree&&player[i].skeleton.free&&player[i].dead&&player[k].lastcollide<=0&&abs(player[i].coords.y-player[k].coords.y)<.2&&findDistancefast(&player[k].coords,&player[i].coords)<.7*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5)){
  8724.                                                                                                 player[k].coords.y=player[i].coords.y;
  8725.                                                                                                 player[i].velocity=player[k].velocity;
  8726.                                                                                                 player[i].skeleton.free=0;
  8727.                                                                                                 player[i].rotation=0;
  8728.                                                                                                 player[i].RagDoll(0);
  8729.                                                                                                 player[i].DoDamage(20);
  8730.                                                                                                 if(k==0)camerashake+=.3;
  8731.                                                                                                 player[i].skeleton.longdead=0;
  8732.                                                                                                 player[k].lastcollide=1;   
  8733.                                                                                             }
  8734.                                                                                             if(i==0)
  8735.                                                                                                 if(player[i].targetanimation==jumpdownanim&&!player[i].skeleton.oldfree&&!player[i].skeleton.free&&player[k].skeleton.oldfree&&player[k].skeleton.free&&player[k].dead&&player[i].lastcollide<=0&&abs(player[i].coords.y-player[k].coords.y)<.2&&findDistancefast(&player[k].coords,&player[i].coords)<.7*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5)){
  8736.                                                                                                     player[i].coords.y=player[k].coords.y;
  8737.                                                                                                     player[k].velocity=player[i].velocity;
  8738.                                                                                                     player[k].skeleton.free=0;
  8739.                                                                                                     player[k].rotation=0;
  8740.                                                                                                     player[k].RagDoll(0);
  8741.                                                                                                     player[k].DoDamage(20);
  8742.                                                                                                     if(i==0)camerashake+=.3;
  8743.                                                                                                     player[k].skeleton.longdead=0;
  8744.                                                                                                     player[i].lastcollide=1;   
  8745.                                                                                                 }
  8746.  
  8747.                                                                                                 if((player[i].skeleton.oldfree==1&&findLengthfast(&player[i].velocity)>1)||(player[k].skeleton.oldfree==1&&findLengthfast(&player[k].velocity)>1)||(player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0)){
  8748.                                                                                                     rotatetarget=player[k].velocity-player[i].velocity;
  8749.                                                                                                     if(((player[i].targetanimation!=getupfrombackanim&&player[i].targetanimation!=getupfromfrontanim)||player[i].skeleton.free)&&((player[k].targetanimation!=getupfrombackanim&&player[k].targetanimation!=getupfromfrontanim)||player[k].skeleton.free))
  8750.                                                                                                         if(((((findLengthfast(&rotatetarget)>150&&(i!=0&&k!=0))||(findLengthfast(&rotatetarget)>50&&player[0].rabbitkickragdoll/*currentanimation==rabbitkickanim*/&&(i==0||k==0)))&&normaldotproduct(rotatetarget,player[k].coords-player[i].coords)>0)&&((i==0||k==0)||((player[i].skeleton.oldfree==1&&k!=0&&animation[player[k].currentanimation].attack==neutral)||(player[k].skeleton.oldfree==1&&i!=0&&animation[player[i].currentanimation].attack==neutral)||(player[i].isFlip()&&!player[i].skeleton.oldfree&&(i==0||k==0))||(player[k].isFlip()&&!player[k].skeleton.oldfree&&(i==0||k==0))||(i==0||k==0))))||((player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip())&&(player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim||player[k].isFlip())&&(i==0||k==0)&&(!player[i].skeleton.oldfree&&!player[k].skeleton.oldfree))){
  8751.                                                                                                             //If hit by body
  8752.                                                                                                             if((i!=0||player[i].skeleton.free)&&(k!=0||player[k].skeleton.free)||(animation[player[i].targetanimation].height==highheight&&animation[player[k].targetanimation].height==highheight)){
  8753.                                                                                                                 static float gLoc[3];
  8754.                                                                                                                 static float vel[3];
  8755.                                                                                                                 gLoc[0]=player[i].coords.x;
  8756.                                                                                                                 gLoc[1]=player[i].coords.y;
  8757.                                                                                                                 gLoc[2]=player[i].coords.z;
  8758.                                                                                                                 vel[0]=player[i].velocity.x;
  8759.                                                                                                                 vel[1]=player[i].velocity.y;
  8760.                                                                                                                 vel[2]=player[i].velocity.z;
  8761.                                                                                                                 if(tutoriallevel!=1){
  8762.                                                                                                                     PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, TRUE);
  8763.                                                                                                                     FSOUND_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
  8764.                                                                                                                     FSOUND_SetVolume(channels[heavyimpactsound], 256);
  8765.                                                                                                                     FSOUND_SetPaused(channels[heavyimpactsound], FALSE);
  8766.                                                                                                                 }
  8767.                                                                                                                 //player[i].velocity=player[k].velocity;
  8768.                                                                                                                 //player[k].velocity=player[i].velocity;
  8769.  
  8770.                                                                                                                 player[i].RagDoll(0);
  8771.                                                                                                                 if(player[i].damage>player[i].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[i].dead){
  8772.                                                                                                                     bonus=aimbonus;
  8773.                                                                                                                     bonustime=0;
  8774.                                                                                                                     bonusvalue=150;
  8775.                                                                                                                 }
  8776.                                                                                                                 player[i].DoDamage(findLengthfast(&rotatetarget)/4);
  8777.                                                                                                                 player[k].RagDoll(0);
  8778.                                                                                                                 if(player[k].damage>player[k].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[k].dead){
  8779.                                                                                                                     bonus=aimbonus;
  8780.                                                                                                                     bonustime=0;
  8781.                                                                                                                     bonusvalue=150;
  8782.                                                                                                                 }
  8783.                                                                                                                 player[k].DoDamage(findLengthfast(&rotatetarget)/4);
  8784.  
  8785.                                                                                                                 //if(player[i].skeleton.oldfree){
  8786.                                                                                                                 for(j=0;j<player[i].skeleton.num_joints;j++){
  8787.                                                                                                                     player[i].skeleton.joints[j].velocity=player[i].skeleton.joints[j].velocity/5+player[k].velocity;
  8788.                                                                                                                 }
  8789.                                                                                                                 //}
  8790.                                                                                                                 //if(player[k].skeleton.oldfree){
  8791.                                                                                                                 for(j=0;j<player[k].skeleton.num_joints;j++){
  8792.                                                                                                                     player[k].skeleton.joints[j].velocity=player[k].skeleton.joints[j].velocity/5+player[i].velocity;
  8793.                                                                                                                 }
  8794.                                                                                                                 //}
  8795.  
  8796.                                                                                                             }
  8797.                                                                                                         }
  8798.                                                                                                         if((animation[player[i].targetanimation].attack==neutral||animation[player[i].targetanimation].attack==normalattack)&&(animation[player[k].targetanimation].attack==neutral||animation[player[k].targetanimation].attack==normalattack)){
  8799.                                                                                                             //If bumped
  8800.                                                                                                             if(player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0){
  8801.                                                                                                                 if(findDistancefast(&player[k].coords,&player[i].coords)<.5*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5)){
  8802.                                                                                                                     rotatetarget=player[k].coords-player[i].coords;
  8803.                                                                                                                     Normalise(&rotatetarget);
  8804.                                                                                                                     player[k].coords=(player[k].coords+player[i].coords)/2;
  8805.                                                                                                                     player[i].coords=player[k].coords-rotatetarget*fast_sqrt(.6)/2*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5);
  8806.                                                                                                                     player[k].coords+=rotatetarget*fast_sqrt(.6)/2*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5);
  8807.                                                                                                                     if(player[k].howactive==typeactive||hostile)
  8808.                                                                                                                         if(player[k].isIdle()){
  8809.                                                                                                                             if(player[k].howactive<typesleeping){
  8810.                                                                                                                                 player[k].targetanimation=player[k].getStop();
  8811.                                                                                                                                 player[k].targetframe=0;
  8812.                                                                                                                                 player[k].target=0;
  8813.                                                                                                                             }
  8814.                                                                                                                             else if(player[k].howactive==typesleeping)
  8815.                                                                                                                             {
  8816.                                                                                                                                 player[k].targetanimation=getupfromfrontanim;
  8817.                                                                                                                                 player[k].targetframe=0;
  8818.                                                                                                                                 player[k].target=0;
  8819.                                                                                                                             }
  8820.                                                                                                                             if(!editorenabled)player[k].howactive=typeactive;
  8821.                                                                                                                         }
  8822.                                                                                                                         if(player[i].howactive==typeactive||hostile)
  8823.                                                                                                                             if(player[i].isIdle()){
  8824.                                                                                                                                 if(player[i].howactive<typesleeping){
  8825.                                                                                                                                     player[i].targetanimation=player[i].getStop();
  8826.                                                                                                                                     player[i].targetframe=0;
  8827.                                                                                                                                     player[i].target=0;
  8828.                                                                                                                                 }
  8829.                                                                                                                                 else
  8830.                                                                                                                                 {
  8831.                                                                                                                                     player[i].targetanimation=getupfromfrontanim;
  8832.                                                                                                                                     player[i].targetframe=0;
  8833.                                                                                                                                     player[i].target=0;
  8834.                                                                                                                                 }
  8835.                                                                                                                                 if(!editorenabled)player[i].howactive=typeactive;
  8836.                                                                                                                             }
  8837.                                                                                                                 }
  8838.                                                                                                                 if(hostile){
  8839.                                                                                                                     if(k==0&&i!=0&&player[k].targetanimation==jumpdownanim&&!player[i].isCrouch()&&player[i].targetanimation!=rollanim&&!player[k].skeleton.oldfree&&!player[k].skeleton.free&&player[k].lastcollide<=0&&player[k].velocity.y<-10){
  8840.                                                                                                                         player[i].velocity=player[k].velocity;
  8841.                                                                                                                         player[k].velocity=player[k].velocity*-.5;
  8842.                                                                                                                         //player[i].velocity.y-=10;
  8843.                                                                                                                         player[k].velocity.y=player[i].velocity.y;
  8844.                                                                                                                         player[i].DoDamage(20);
  8845.                                                                                                                         player[i].RagDoll(0);
  8846.                                                                                                                         player[k].lastcollide=1;   
  8847.                                                                                                                         if(k==0){
  8848.                                                                                                                             bonus=AboveBonus;
  8849.                                                                                                                             bonustime=0;
  8850.                                                                                                                             bonusvalue=50;
  8851.                                                                                                                         }
  8852.                                                                                                                     }
  8853.                                                                                                                     if(i==0&&k!=0&&player[i].targetanimation==jumpdownanim&&!player[k].isCrouch()&&player[k].targetanimation!=rollanim&&!player[i].skeleton.oldfree&&!player[i].skeleton.free&&player[i].lastcollide<=0&&player[i].velocity.y<-10){
  8854.                                                                                                                         player[k].velocity=player[i].velocity;
  8855.                                                                                                                         player[i].velocity=player[i].velocity*-.3;
  8856.                                                                                                                         //player[k].velocity.y-=10;
  8857.                                                                                                                         player[i].velocity.y=player[k].velocity.y;
  8858.                                                                                                                         player[k].DoDamage(20);
  8859.                                                                                                                         player[k].RagDoll(0);  
  8860.                                                                                                                         player[i].lastcollide=1;   
  8861.                                                                                                                         if(i==0){
  8862.                                                                                                                             bonus=AboveBonus;
  8863.                                                                                                                             bonustime=0;
  8864.                                                                                                                             bonusvalue=50;
  8865.                                                                                                                         }
  8866.                                                                                                                     }
  8867.                                                                                                                 }
  8868.                                                                                                             }
  8869.                                                                                                         }
  8870.                                                                                                 }
  8871.                                                                                                 player[i].CheckKick();
  8872.                                                                                                 player[k].CheckKick();
  8873.                                                                                     }
  8874.                                                                                 }
  8875.                                 }
  8876.                             }
  8877.  
  8878.                             for(k=0;k<numplayers;k++){
  8879.                                 for(i=k;i<numplayers;i++){
  8880.                                     if(i==k)i++;
  8881.                                     if(i<numplayers&&i!=k&&player[k].skeleton.free==0&&player[i].skeleton.oldfree==0&&(player[i].targetanimation==jumpupanim||player[k].targetanimation==jumpupanim)&&(player[i].aitype==playercontrolled||player[k].aitype==playercontrolled)&&((player[i].aitype==attacktypecutoff&&player[i].stunned<=0)||(player[k].aitype==attacktypecutoff&&player[k].stunned<=0))){
  8882.                                         if(findDistancefast(&player[i].coords,&player[k].coords)<10*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5)&&findDistancefastflat(&player[i].coords,&player[k].coords)<2*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5)){
  8883.                                             if(player[i].targetanimation==jumpupanim&&player[k].targetanimation!=getupfrombackanim&&player[k].targetanimation!=getupfromfrontanim&&animation[player[k].targetanimation].height==middleheight&&normaldotproduct(player[i].velocity,player[k].coords-player[i].coords)<0&&((player[k].aitype==playercontrolled&&player[k].attackkeydown)||player[k].aitype!=playercontrolled)){
  8884.                                                 player[i].victim=&player[k];
  8885.                                                 player[i].targetanimation=jumpreversedanim;
  8886.                                                 player[i].currentanimation=jumpreversedanim;
  8887.                                                 player[k].currentanimation=jumpreversalanim;
  8888.                                                 player[k].targetanimation=jumpreversalanim;
  8889.                                                 player[i].targettilt2=0;
  8890.                                                 player[i].currentframe=0;
  8891.                                                 player[i].targetframe=1;
  8892.                                                 player[k].currentframe=0;
  8893.                                                 player[k].targetframe=1;
  8894.                                                 if(player[i].coords.y<player[k].coords.y+1){
  8895.                                                     player[i].targetanimation=rabbitkickreversedanim;
  8896.                                                     player[i].currentanimation=rabbitkickreversedanim;
  8897.                                                     player[k].currentanimation=rabbitkickreversalanim;
  8898.                                                     player[k].targetanimation=rabbitkickreversalanim;
  8899.                                                     player[k].currentframe=1;
  8900.                                                     player[k].targetframe=2;
  8901.                                                     player[i].currentframe=1;
  8902.                                                     player[i].targetframe=2;
  8903.                                                 }
  8904.                                                 player[k].targettilt2=0;
  8905.                                                 player[i].target=0;
  8906.                                                 player[i].velocity=0;
  8907.                                                 player[k].velocity=0;
  8908.                                                 player[k].oldcoords=player[k].coords;
  8909.                                                 player[i].coords=player[k].coords;
  8910.                                                 player[k].targetrotation=player[i].targetrotation;
  8911.                                                 player[k].rotation=player[i].targetrotation;
  8912.                                                 player[k].victim=&player[i];
  8913.                                                 if(player[k].aitype==attacktypecutoff)player[k].stunned=.5;
  8914.                                             }
  8915.                                             if(player[k].targetanimation==jumpupanim&&player[i].targetanimation!=getupfrombackanim&&player[i].targetanimation!=getupfromfrontanim&&animation[player[i].targetanimation].height==middleheight&&normaldotproduct(player[k].velocity,player[i].coords-player[k].coords)<0&&((player[i].aitype==playercontrolled&&player[i].attackkeydown)||player[i].aitype!=playercontrolled)){
  8916.                                                 player[k].victim=&player[i];
  8917.                                                 player[k].targetanimation=jumpreversedanim;
  8918.                                                 player[k].currentanimation=jumpreversedanim;
  8919.                                                 player[i].currentanimation=jumpreversalanim;
  8920.                                                 player[i].targetanimation=jumpreversalanim;
  8921.                                                 player[k].targettilt2=0;
  8922.                                                 player[i].targettilt2=0;
  8923.                                                 player[k].currentframe=0;
  8924.                                                 player[k].targetframe=1;
  8925.                                                 player[i].currentframe=0;
  8926.                                                 player[i].targetframe=1;
  8927.                                                 if(player[k].coords.y<player[i].coords.y+1){
  8928.                                                     player[k].targetanimation=rabbitkickreversedanim;
  8929.                                                     player[k].currentanimation=rabbitkickreversedanim;
  8930.                                                     player[i].currentanimation=rabbitkickreversalanim;
  8931.                                                     player[i].targetanimation=rabbitkickreversalanim;
  8932.                                                     player[k].currentframe=1;
  8933.                                                     player[k].targetframe=2;
  8934.                                                     player[i].currentframe=1;
  8935.                                                     player[i].targetframe=2;
  8936.                                                 }
  8937.                                                 player[k].target=0;
  8938.                                                 player[k].velocity=0;
  8939.                                                 player[i].velocity=0;
  8940.                                                 player[i].oldcoords=player[i].coords;
  8941.                                                 player[k].coords=player[i].coords;
  8942.                                                 player[i].targetrotation=player[k].targetrotation;
  8943.                                                 player[i].rotation=player[k].targetrotation;
  8944.                                                 player[i].victim=&player[k];
  8945.                                                 if(player[i].aitype==attacktypecutoff)player[i].stunned=.5;
  8946.                                             }
  8947.                                         }
  8948.                                     }
  8949.                                 }
  8950.                             }
  8951.  
  8952.                             for(k=0;k<numplayers;k++)
  8953.                                 if(player[k].immobile&&k!=0)player[k].coords=player[k].realoldcoords;
  8954.  
  8955.  
  8956.                             //pile
  8957.                             /*
  8958.                             XYZ tempdiff;
  8959.                             XYZ tempoldpos;
  8960.                             XYZ temp1,temp2;
  8961.                             bool isgood;
  8962.                             static float checkdelay;
  8963.                             checkdelay-=multiplier;
  8964.                             int m;
  8965.                             static bool checkedcoll[maxplayers][maxplayers];
  8966.                             static bool above[maxplayers];
  8967.  
  8968.                             for(i=0;i<maxplayers;i++){
  8969.                             for(j=0;j<maxplayers;j++){
  8970.                             checkedcoll[i][j]=0;
  8971.                             }
  8972.                             }
  8973.  
  8974.                             if(numplayers>1&&checkdelay<=0){
  8975.                             checkdelay=.015;
  8976.                             for(k=0;k<numplayers;k++){
  8977.                             if(player[k].skeleton.free!=2)above[k]=-1;
  8978.  
  8979.                             for(i=k;i<numplayers;i++){
  8980.                             if(i==k)i++;
  8981.                             if(i<numplayers)
  8982.                             if(!checkedcoll[i][k]){
  8983.                             checkedcoll[i][k]=1;
  8984.                             checkedcoll[k][i]=1;
  8985.                             if(player[i].skeleton.free&&player[k].skeleton.free)
  8986.                             if(player[i].skeleton.free!=2||player[k].skeleton.free!=2)
  8987.                             if(i!=k&&player[i].whichpatchx==player[k].whichpatchx&&player[i].whichpatchz==player[k].whichpatchz)
  8988.                             if(player[i].coords.y>player[k].coords.y-3)
  8989.                             if(player[i].coords.y<player[k].coords.y+3)
  8990.                             if(player[i].coords.x>player[k].coords.x-3)
  8991.                             if(player[i].coords.x<player[k].coords.x+3)
  8992.                             if(player[i].coords.z>player[k].coords.z-3)
  8993.                             if(player[i].coords.z<player[k].coords.z+3)
  8994.                             if(findDistancefast(&player[i].coords,&player[k].coords)<3*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5)){
  8995.                             int stuck,moving;
  8996.                             if((player[i].skeleton.longdead>player[k].skeleton.longdead&&player[k].skeleton.free!=2)||player[i].skeleton.free==2){
  8997.                             stuck=i;
  8998.                             moving=k;
  8999.                             }
  9000.                             else
  9001.                             {
  9002.                             moving=i;
  9003.                             stuck=k;
  9004.                             }
  9005.                             isgood=1;
  9006.  
  9007.                             if(isgood){
  9008.                             above[moving]=stuck;
  9009.                             for(l=0;l<player[moving].skeleton.num_joints;l++){
  9010.                             for(m=0;m<player[stuck].skeleton.num_joints;m++){
  9011.                             while(findDistancefast(player[moving].skeleton.joints[l].position+player[moving].coords,player[stuck].skeleton.joints[m].position+player[stuck].coords)<.25)
  9012.                             {
  9013.                             player[moving].skeleton.joints[l].position.y+=.003;
  9014.                             if(player[moving].skeleton.joints[l].velocity.y<-.05)player[moving].skeleton.joints[l].velocity.y+=.003/.015/2;
  9015.  
  9016.                             }
  9017.                             }
  9018.                             }
  9019.                             }
  9020.                             }
  9021.                             }
  9022.                             }
  9023.                             }
  9024.                             }
  9025.  
  9026.                             */
  9027.  
  9028.                             if(!IsKeyDown(theKeyMap, MAC_N_KEY)){
  9029.                                 texturesizetogglekeydown=0;
  9030.                             }
  9031.  
  9032.                             for(k=0;k<numplayers;k++){
  9033.                                 if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
  9034.                                     if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
  9035.                                         player[k].DoDamage(1000);
  9036.                                     }
  9037.                                 }
  9038.                             }
  9039.  
  9040.                             static bool respawnkeydown;
  9041.                             if(!editorenabled&&(whichlevel!=-2&&(IsKeyDown(theKeyMap, MAC_Z_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)&&debugmode&&!editorenabled)||(IsKeyDown(theKeyMap, jumpkey)&&!respawnkeydown&&!oldattackkey&&player[0].dead))){
  9042.                                 targetlevel=whichlevel;
  9043.                                 loading=1;
  9044.                                 leveltime=5;
  9045.                             }
  9046.                             if(!IsKeyDown(theKeyMap, jumpkey))respawnkeydown=0;
  9047.                             if(IsKeyDown(theKeyMap, jumpkey))respawnkeydown=1;
  9048.  
  9049.  
  9050.  
  9051.  
  9052.                             if(whichlevel!=-2&&IsKeyDown(theKeyMap, MAC_K_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!slomotogglekeydown&&debugmode&&!editorenabled){
  9053.                                 targetlevel++;
  9054.                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
  9055.                                 loading=1;
  9056.                                 leveltime=5;
  9057.                                 slomotogglekeydown=1;
  9058.                             }
  9059.  
  9060.                             /*
  9061.                             if(IsKeyDown(theKeyMap, MAC_Z_KEY)){
  9062.                             //Respawn
  9063.                             FSOUND_SetPaused(channels[whooshsound], TRUE);
  9064.                             changedelay=0;
  9065.                             for(k=0;k<numplayers;k++){
  9066.                             player[k].dead=0;
  9067.                             player[k].damage=0;
  9068.                             player[k].permanentdamage=0;
  9069.                             if(player[k].skeleton.free==2)player[k].skeleton.free=1;
  9070.                             player[k].aitype=passivetype;
  9071.                             }
  9072.                             player[0].aitype=playercontrolled;
  9073.                             }
  9074.                             */
  9075.  
  9076.                             static bool movekey;
  9077.                             static bool connected;
  9078.                             /*player[0].forwardkeydown=IsKeyDown(theKeyMap, MAC_W_KEY);
  9079.                             player[0].leftkeydown=IsKeyDown(theKeyMap, MAC_A_KEY);
  9080.                             player[0].backkeydown=IsKeyDown(theKeyMap, MAC_S_KEY);
  9081.                             player[0].rightkeydown=IsKeyDown(theKeyMap, MAC_D_KEY);
  9082.                             player[0].jumpkeydown=IsKeyDown(theKeyMap, MAC_SPACE_KEY);
  9083.                             player[0].crouchkeydown=IsKeyDown(theKeyMap, MAC_SHIFT_KEY);*/
  9084.  
  9085.                             //if(!player[0].crouchkeydown)player[0].crouchkeydown=IsKeyDown(theKeyMap, MAC_CONTROL_KEY);
  9086.  
  9087.         for(int i=0;i<numplayers;i++){ 
  9088.                                 if(!player[i].skeleton.free){
  9089.                                     oldtargetrotation=player[i].targetrotation;
  9090.                                     if(i==0&&indialogue==-1){
  9091.                                         if(!animation[player[0].targetanimation].attack&&player[0].targetanimation!=staggerbackhighanim&&player[0].targetanimation!=staggerbackhardanim&&player[0].targetanimation!=crouchremoveknifeanim&&player[0].targetanimation!=removeknifeanim&&player[0].targetanimation!=backhandspringanim&&player[0].targetanimation!=dodgebackanim&&player[0].targetanimation!=walljumprightkickanim&&player[0].targetanimation!=walljumpleftkickanim){
  9092.                                             if(!cameramode)player[0].targetrotation=-rotation+180;
  9093.                                             if(cameramode)player[0].targetrotation=0;
  9094.                                         }
  9095.  
  9096.                                         facing=0;
  9097.                                         facing.z=-1;
  9098.  
  9099.                                         flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
  9100.                                         if(cameramode){facing=flatfacing;}
  9101.                                         else{
  9102.                                             facing=DoRotation(facing,-rotation2,0,0);
  9103.                                             facing=DoRotation(facing,0,0-rotation,0);
  9104.                                         }
  9105.  
  9106.                                         player[0].lookrotation=-rotation;
  9107.  
  9108.                                         player[i].targetheadrotation=rotation;
  9109.                                         player[i].targetheadrotation2=rotation2;           
  9110.                                     }
  9111.                                     if(i!=0&&player[i].aitype==playercontrolled&&indialogue==-1){
  9112.                                         if(!animation[player[i].targetanimation].attack&&player[i].targetanimation!=staggerbackhighanim&&player[i].targetanimation!=staggerbackhardanim&&player[i].targetanimation!=crouchremoveknifeanim&&player[i].targetanimation!=removeknifeanim&&player[i].targetanimation!=backhandspringanim&&player[i].targetanimation!=dodgebackanim&&player[i].targetanimation!=walljumprightkickanim&&player[i].targetanimation!=walljumpleftkickanim){
  9113.                                             player[i].targetrotation=-player[i].lookrotation+180;
  9114.                                         }
  9115.  
  9116.                                         facing=0;
  9117.                                         facing.z=-1;
  9118.  
  9119.                                         flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
  9120.  
  9121.                                         facing=DoRotation(facing,-player[i].lookrotation2,0,0);
  9122.                                         facing=DoRotation(facing,0,0-player[i].lookrotation,0);
  9123.  
  9124.                                         player[i].targetheadrotation=player[i].lookrotation;
  9125.                                         player[i].targetheadrotation2=player[i].lookrotation2;         
  9126.                                     }
  9127.                                     if(indialogue!=-1){
  9128.                                         rotatetarget=participantfacing[whichdialogue][indialogue][i];
  9129.                                         Normalise(&rotatetarget);
  9130.                                         player[i].targetheadrotation=-asin(0-rotatetarget.x);
  9131.                                         player[i].targetheadrotation*=360/6.28;
  9132.                                         if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
  9133.  
  9134.                                         player[i].targetheadrotation*=-1;
  9135.                                         player[i].targetheadrotation+=180;
  9136.                                         player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
  9137.                                     }
  9138.  
  9139.                                     bool pause;
  9140.  
  9141.                                     if(leveltime<.5)
  9142.                                         numenvsounds=0;
  9143.  
  9144.                                     player[i].avoidsomething=0;
  9145.  
  9146.                                     for(j=0;j<objects.numobjects;j++){
  9147.                                         if(objects.onfire[j]){
  9148.                                             if(findDistancefast(&objects.position[j],&player[i].coords)<objects.scale[j]*objects.scale[j]*200)
  9149.                                             {
  9150.                                                 if(findDistancefast(&player[i].coords,&objects.position[j])<findDistancefast(&player[i].coords,&player[0].coords)){
  9151.                                                     player[i].collided=0;
  9152.                                                     player[i].avoidcollided=1;
  9153.                                                     if(player[i].avoidsomething==0||findDistancefast(&objects.position[j],&player[i].coords)<findDistancefast(&player[i].coords,&player[i].avoidwhere))
  9154.                                                         player[i].avoidwhere=objects.position[j];
  9155.                                                 }
  9156.                                             }
  9157.                                         }
  9158.                                     }
  9159.  
  9160.                                     //Add avoidwhere to players
  9161.  
  9162.                                     for(j=0;j<numplayers;j++){
  9163.                                         if(player[j].onfire){
  9164.                                             if(findDistancefast(&player[j].coords,&player[i].coords)<0.3*0.3*200)
  9165.                                             {
  9166.                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<findDistancefast(&player[i].coords,&player[0].coords)){
  9167.                                                     player[i].collided=0;
  9168.                                                     player[i].avoidcollided=1;
  9169.                                                     if(player[i].avoidsomething==0||findDistancefast(&player[j].coords,&player[i].coords)<findDistancefast(&player[i].coords,&player[i].avoidwhere))
  9170.                                                         player[i].avoidwhere=objects.position[j];
  9171.                                                 }
  9172.                                             }
  9173.                                         }
  9174.                                     }
  9175.  
  9176.                                     if(player[i].collided>.8)player[i].avoidcollided=0;
  9177.                                     if(player[i].aitype!=playercontrolled&&indialogue==-1){
  9178.                                         player[i].jumpclimb=0;
  9179.                                         //AI
  9180.                                         if(editorenabled)player[i].stunned=1;
  9181.  
  9182.                                         player[i].pause=0;
  9183.                                         //if(findDistancefastflat(&player[i].coords,&player[0].coords)<3/*&&player[0].coords.y>player[i].coords.y+.1*/)player[i].pause=1;
  9184.                                         if(findDistancefastflat(&player[0].coords,&player[i].coords)<30&&player[0].coords.y>player[i].coords.y+2&&!player[0].onterrain)player[i].pause=1;
  9185.  
  9186.                                         /*if(player[i].aitype==passivetype&&player[i].numwaypoints<=1){
  9187.                                         player[i].forwardkeydown=0;
  9188.                                         player[i].leftkeydown=0;
  9189.                                         player[i].backkeydown=0;
  9190.                                         player[i].rightkeydown=0;
  9191.                                         player[i].crouchkeydown=0;
  9192.                                         player[i].attackkeydown=0;
  9193.                                         player[i].jumpkeydown=0;
  9194.                                         player[i].throwkeydown=0;
  9195.                                         }*/
  9196.  
  9197.                                         if(player[i].aitype==pathfindtype){
  9198.                                             if(player[i].finalpathfindpoint==-1){
  9199.                                                 float closestdistance;
  9200.                                                 float tempdist;
  9201.                                                 int closest;
  9202.                                                 XYZ colpoint;
  9203.                                                 closest=-1;
  9204.                                                 closestdistance=-1;
  9205.                                                 for(j=0;j<numpathpoints;j++){
  9206.                                                     if(closest==-1||findDistancefast(&player[i].finalfinaltarget,&pathpoint[j])<closestdistance){
  9207.                                                         closestdistance=findDistancefast(&player[i].finalfinaltarget,&pathpoint[j]);
  9208.                                                         closest=j;
  9209.                                                         player[i].finaltarget=pathpoint[j];
  9210.                                                     }
  9211.                                                 }
  9212.                                                 player[i].finalpathfindpoint=closest;
  9213.                                                 for(j=0;j<numpathpoints;j++){
  9214.                                                     if(numpathpointconnect[j])
  9215.                                                         for(k=0;k<numpathpointconnect[j];k++){
  9216.                                                             DistancePointLine(&player[i].finalfinaltarget, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
  9217.                                                             if(tempdist*tempdist<closestdistance){
  9218.                                                                 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
  9219.                                                                     closestdistance=tempdist*tempdist;
  9220.                                                                     closest=j;
  9221.                                                                     player[i].finaltarget=colpoint;
  9222.                                                                 }
  9223.                                                             }
  9224.                                                         }
  9225.                                                 }
  9226.                                                 player[i].finalpathfindpoint=closest;
  9227.  
  9228.                                             }
  9229.                                             if(player[i].targetpathfindpoint==-1){
  9230.                                                 float closestdistance;
  9231.                                                 float tempdist;
  9232.                                                 int closest;
  9233.                                                 XYZ colpoint;
  9234.                                                 closest=-1;
  9235.                                                 closestdistance=-1;
  9236.                                                 if(player[i].lastpathfindpoint==-1){
  9237.                                                     for(j=0;j<numpathpoints;j++){
  9238.                                                         if(j!=player[i].lastpathfindpoint)
  9239.                                                             if(closest==-1||(findDistancefast(&player[i].coords,&pathpoint[j])<closestdistance/*&&findDistancefast(&player[i].finaltarget,&pathpoint[j])<findDistancefast(&player[i].finaltarget,&player[i].coords)*/)){
  9240.                                                                 closestdistance=findDistancefast(&player[i].coords,&pathpoint[j]);
  9241.                                                                 closest=j;
  9242.                                                             }
  9243.                                                     }
  9244.                                                     player[i].targetpathfindpoint=closest;
  9245.                                                     for(j=0;j<numpathpoints;j++){
  9246.                                                         if(j!=player[i].lastpathfindpoint)
  9247.                                                             if(numpathpointconnect[j])
  9248.                                                                 for(k=0;k<numpathpointconnect[j];k++){
  9249.                                                                     DistancePointLine(&player[i].coords, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
  9250.                                                                     if(tempdist*tempdist<closestdistance){
  9251.                                                                         if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
  9252.                                                                             //if(findDistancefast(&player[i].finaltarget,&colpoint)<findDistancefast(&player[i].finaltarget,&player[i].coords)){
  9253.                                                                             closestdistance=tempdist*tempdist;
  9254.                                                                             closest=j;
  9255.                                                                             //}
  9256.                                                                         }
  9257.                                                                     }
  9258.                                                                 }
  9259.                                                     }
  9260.                                                     player[i].targetpathfindpoint=closest;
  9261.                                                 }
  9262.                                                 else
  9263.                                                 {
  9264.                                                     for(j=0;j<numpathpoints;j++){
  9265.                                                         if(j!=player[i].lastpathfindpoint&&j!=player[i].lastpathfindpoint2&&j!=player[i].lastpathfindpoint3&&j!=player[i].lastpathfindpoint4)
  9266.                                                         {
  9267.                                                             connected=0;
  9268.                                                             if(numpathpointconnect[j])
  9269.                                                                 for(k=0;k<numpathpointconnect[j];k++){
  9270.                                                                     if(pathpointconnect[j][k]==player[i].lastpathfindpoint)connected=1;
  9271.                                                                 }
  9272.                                                                 if(!connected)
  9273.                                                                     if(numpathpointconnect[player[i].lastpathfindpoint])
  9274.                                                                         for(k=0;k<numpathpointconnect[player[i].lastpathfindpoint];k++){
  9275.                                                                             if(pathpointconnect[player[i].lastpathfindpoint][k]==j)connected=1;
  9276.                                                                         }
  9277.                                                                         if(connected){
  9278.                                                                             tempdist=findPathDist(j,player[i].finalpathfindpoint);
  9279.                                                                             if(closest==-1||tempdist<closestdistance){
  9280.                                                                                 closestdistance=tempdist;
  9281.                                                                                 closest=j;
  9282.                                                                             }
  9283.                                                                         }
  9284.                                                         }
  9285.                                                     }
  9286.                                                     player[i].targetpathfindpoint=closest;
  9287.                                                 }
  9288.                                             }
  9289.                                             player[i].losupdatedelay-=multiplier;
  9290.  
  9291.                                             rotatetarget=pathpoint[player[i].targetpathfindpoint]-player[i].coords;
  9292.                                             Normalise(&rotatetarget);
  9293.                                             player[i].targetrotation=-asin(0-rotatetarget.x);
  9294.                                             player[i].targetrotation*=360/6.28;
  9295.                                             if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
  9296.                                             player[i].lookrotation=player[i].targetrotation;
  9297.                                             //player[i].aiupdatedelay=.05;
  9298.  
  9299.                                             if(findDistancefastflat(&player[i].coords,&pathpoint[player[i].targetpathfindpoint])<.6){
  9300.                                                 player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
  9301.                                                 player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
  9302.                                                 player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
  9303.                                                 player[i].lastpathfindpoint=player[i].targetpathfindpoint;
  9304.                                                 if(player[i].lastpathfindpoint2==-1)player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
  9305.                                                 if(player[i].lastpathfindpoint3==-1)player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
  9306.                                                 if(player[i].lastpathfindpoint4==-1)player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
  9307.                                                 player[i].targetpathfindpoint=-1;
  9308.                                             }
  9309.                                             if(findDistancefastflat(&player[i].coords,&player[i].finalfinaltarget)<findDistancefastflat(&player[i].coords,&player[i].finaltarget)||findDistancefastflat(&player[i].coords,&player[i].finaltarget)<.6*(player[i].scale*5)*(player[i].scale*5)||player[i].lastpathfindpoint==player[i].finalpathfindpoint){
  9310.                                                 player[i].aitype=passivetype;
  9311.                                             }
  9312.  
  9313.                                             player[i].forwardkeydown=1;
  9314.                                             player[i].leftkeydown=0;
  9315.                                             player[i].backkeydown=0;
  9316.                                             player[i].rightkeydown=0;
  9317.                                             player[i].crouchkeydown=0;
  9318.                                             player[i].attackkeydown=0;
  9319.                                             player[i].throwkeydown=0;
  9320.  
  9321.                                             if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
  9322.  
  9323.                                             if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
  9324.                                             if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
  9325.  
  9326.                                             if((tutoriallevel!=1||cananger)&&hostile&&!player[0].dead&&findDistancefast(&player[i].coords,&player[0].coords)<400&&player[i].occluded<25){
  9327.                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<12&&animation[player[0].targetanimation].height!=lowheight&&!editorenabled&&(player[0].coords.y<player[i].coords.y+5||player[0].onterrain))
  9328.                                                     player[i].aitype=attacktypecutoff;
  9329.                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&animation[player[0].targetanimation].height==highheight&&!editorenabled)
  9330.                                                     player[i].aitype=attacktypecutoff;
  9331.  
  9332.                                                 if(player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
  9333.                                                     player[i].losupdatedelay=.2;
  9334.                                                     for(j=0;j<numplayers;j++){
  9335.                                                         if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
  9336.                                                             if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
  9337.                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
  9338.                                                                     if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
  9339.                                                                         if(player[j].coords.y<player[i].coords.y+5||player[j].onterrain)
  9340.                                                                             if((-1==checkcollide(DoRotation(player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position,0,player[i].rotation,0)*player[i].scale+player[i].coords,DoRotation(player[j].skeleton.joints[player[j].skeleton.jointlabels[head]].position,0,player[j].rotation,0)*player[j].scale+player[j].coords)&&!player[j].isWallJump())||(player[j].targetanimation==hanganim&&normaldotproduct(player[j].facing,player[i].coords-player[j].coords)<0)){
  9341.                                                                                 player[i].aitype=searchtype;
  9342.                                                                                 player[i].lastchecktime=12;
  9343.                                                                                 player[i].lastseen=player[j].coords;
  9344.                                                                                 player[i].lastseentime=12;
  9345.                                                                             }
  9346.                                                         }
  9347.                                                     }
  9348.                                                 }
  9349.                                             }  
  9350.                                             if(player[i].aitype==attacktypecutoff&&musictype!=2){
  9351.                                                 if(player[i].creature!=wolftype){
  9352.                                                     player[i].stunned=.6;
  9353.                                                     player[i].surprised=.6;
  9354.                                                 }
  9355.                                             }
  9356.                                         }
  9357.  
  9358.                                         if(player[i].aitype!=passivetype&&leveltime>.5){
  9359.                                             player[i].howactive=typeactive;
  9360.                                         }
  9361.  
  9362.                                         if(player[i].aitype==passivetype){
  9363.                                             player[i].aiupdatedelay-=multiplier;
  9364.                                             player[i].losupdatedelay-=multiplier;
  9365.                                             player[i].lastseentime+=multiplier;
  9366.                                             player[i].pausetime-=multiplier;
  9367.                                             if(player[i].lastseentime>1)player[i].lastseentime=1;
  9368.  
  9369.                                             if(player[i].aiupdatedelay<0){
  9370.                                                 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0){
  9371.                                                     rotatetarget=player[i].waypoints[player[i].waypoint]-player[i].coords;
  9372.                                                     Normalise(&rotatetarget);
  9373.                                                     player[i].targetrotation=-asin(0-rotatetarget.x);
  9374.                                                     player[i].targetrotation*=360/6.28;
  9375.                                                     if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
  9376.                                                     player[i].lookrotation=player[i].targetrotation;
  9377.                                                     player[i].aiupdatedelay=.05;
  9378.  
  9379.                                                     if(findDistancefastflat(&player[i].coords,&player[i].waypoints[player[i].waypoint])<1){
  9380.                                                         if(player[i].waypointtype[player[i].waypoint]==wppause)player[i].pausetime=4;
  9381.                                                         player[i].waypoint++;
  9382.                                                         if(player[i].waypoint>player[i].numwaypoints-1)player[i].waypoint=0;
  9383.  
  9384.                                                     }
  9385.                                                 }          
  9386.  
  9387.                                                 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0)player[i].forwardkeydown=1;
  9388.                                                 else player[i].forwardkeydown=0;
  9389.                                                 player[i].leftkeydown=0;
  9390.                                                 player[i].backkeydown=0;
  9391.                                                 player[i].rightkeydown=0;
  9392.                                                 player[i].crouchkeydown=0;
  9393.                                                 player[i].attackkeydown=0;
  9394.                                                 player[i].throwkeydown=0;
  9395.  
  9396.                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
  9397.                                                     if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
  9398.                                                     else{
  9399.                                                         XYZ leftpos,rightpos;
  9400.                                                         float leftdist,rightdist;
  9401.                                                         leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
  9402.                                                         rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
  9403.                                                         leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
  9404.                                                         rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
  9405.                                                         if(leftdist<rightdist)player[i].targetrotation+=90;
  9406.                                                         else player[i].targetrotation-=90;
  9407.                                                     }
  9408.                                                 }
  9409.                                             }          
  9410.                                             if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
  9411.                                             if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
  9412.  
  9413.  
  9414.                                             if(!editorenabled){
  9415.                                                 if(player[i].howactive<typesleeping)
  9416.                                                     if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
  9417.                                                         for(j=0;j<numenvsounds;j++){
  9418.                                                             if(findDistancefast(&player[i].coords,&envsound[j])<2*(envsoundvol[j]+envsoundvol[j]*(player[i].creature==rabbittype)*3)){
  9419.                                                                 player[i].aitype=attacktypecutoff;
  9420.                                                             }
  9421.                                                         }
  9422.  
  9423.                                                         if(player[i].howactive==typesleeping)
  9424.                                                             if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
  9425.                                                                 for(j=0;j<numenvsounds;j++){
  9426.                                                                     if(envsoundvol[j]>14)
  9427.                                                                         if(findDistancefast(&player[i].coords,&envsound[j])<2*((envsoundvol[j]-14)+(envsoundvol[j]-14)*(player[i].creature==rabbittype)*3)){
  9428.                                                                             player[i].aitype=attacktypecutoff;
  9429.                                                                         }
  9430.                                                                 }
  9431.  
  9432.                                                                 if(player[i].aitype!=passivetype){
  9433.                                                                     if(player[i].howactive==typesleeping){
  9434.                                                                         player[i].targetanimation=getupfromfrontanim;
  9435.                                                                         player[i].targetframe=0;
  9436.                                                                         player[i].target=0;
  9437.                                                                     }
  9438.  
  9439.                                                                     player[i].howactive=typeactive;
  9440.                                                                 }
  9441.                                             }          
  9442.  
  9443.                                             if(player[i].howactive<typesleeping&&((tutoriallevel!=1||cananger)&&hostile)&&!player[0].dead&&findDistancefast(&player[i].coords,&player[0].coords)<400&&player[i].occluded<25){
  9444.                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<12&&animation[player[0].targetanimation].height!=lowheight&&!editorenabled)
  9445.                                                     player[i].aitype=attacktypecutoff;
  9446.                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&animation[player[0].targetanimation].height==highheight&&!editorenabled)
  9447.                                                     player[i].aitype=attacktypecutoff;
  9448.  
  9449.                                                 if(player[i].creature==wolftype){
  9450.                                                     XYZ windsmell;
  9451.                                                     float smelldistance;
  9452.                                                     smelldistance=50;
  9453.                                                     for(j=0;j<numplayers;j++){
  9454.                                                         if(j==0||(player[j].dead&&player[j].bloodloss>0)){
  9455.                                                             if(j==0&&player[j].num_weapons>0){
  9456.                                                                 if(weapons.bloody[player[j].weaponids[0]])smelldistance=100;
  9457.                                                                 if(player[j].num_weapons==2)
  9458.                                                                     if(weapons.bloody[player[j].weaponids[1]])smelldistance=100;
  9459.                                                             }
  9460.                                                             if(j!=0){
  9461.                                                                 smelldistance=100;
  9462.                                                             }
  9463.                                                             windsmell=windvector;
  9464.                                                             Normalise(&windsmell);
  9465.                                                             windsmell=windsmell*2+player[j].coords;
  9466.                                                             if(findDistancefast(&player[i].coords,&windsmell)<smelldistance&&!editorenabled)
  9467.                                                                 player[i].aitype=attacktypecutoff;
  9468.                                                         }
  9469.                                                     }
  9470.                                                 }
  9471.  
  9472.                                                 if(player[i].howactive<typesleeping&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
  9473.                                                     player[i].losupdatedelay=.2;
  9474.                                                     for(j=0;j<numplayers;j++){
  9475.                                                         if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
  9476.                                                             if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
  9477.                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
  9478.                                                                     if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
  9479.                                                                         if((-1==checkcollide(DoRotation(player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position,0,player[i].rotation,0)*player[i].scale+player[i].coords,DoRotation(player[j].skeleton.joints[player[j].skeleton.jointlabels[head]].position,0,player[j].rotation,0)*player[j].scale+player[j].coords)&&!player[j].isWallJump())||(player[j].targetanimation==hanganim&&normaldotproduct(player[j].facing,player[i].coords-player[j].coords)<0)){
  9480.                                                                             player[i].lastseentime-=.2;
  9481.                                                                             if(j==0&&animation[player[j].targetanimation].height==lowheight)player[i].lastseentime-=.4;
  9482.                                                                             else player[i].lastseentime-=.6;                               
  9483.                                                                         }
  9484.                                                                         if(player[i].lastseentime<=0){
  9485.                                                                             player[i].aitype=searchtype;
  9486.                                                                             player[i].lastchecktime=12;
  9487.                                                                             player[i].lastseen=player[j].coords;
  9488.                                                                             player[i].lastseentime=12;
  9489.                                                                         }
  9490.                                                         }
  9491.                                                     }
  9492.                                                 }
  9493.                                             }
  9494.                                             if(player[i].aitype==attacktypecutoff&&musictype!=2){
  9495.                                                 if(player[i].creature!=wolftype){
  9496.                                                     player[i].stunned=.6;
  9497.                                                     player[i].surprised=.6;
  9498.                                                 }
  9499.                                                 if(player[i].creature==wolftype){
  9500.                                                     player[i].stunned=.47;
  9501.                                                     player[i].surprised=.47;
  9502.                                                 }
  9503.                                                 numseen++;
  9504.                                             }
  9505.                                         }      
  9506.  
  9507.                                         if(player[i].aitype==searchtype){
  9508.                                             player[i].aiupdatedelay-=multiplier;
  9509.                                             player[i].losupdatedelay-=multiplier;
  9510.                                             if(!player[i].pause)player[i].lastseentime-=multiplier;
  9511.                                             player[i].lastchecktime-=multiplier;
  9512.  
  9513.                                             if(player[i].isRun()&&!player[i].onground){
  9514.                                                 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
  9515.                                                     test2=player[i].coords+player[i].facing;
  9516.                                                     test2.y+=5;
  9517.                                                     test=player[i].coords+player[i].facing;
  9518.                                                     test.y-=10;
  9519.                                                     j=checkcollide(test2,test,player[i].laststanding);
  9520.                                                     if(j==-1)j=checkcollide(test2,test);
  9521.                                                     if(j==-1){
  9522.                                                         player[i].velocity=0;
  9523.                                                         player[i].targetanimation=player[i].getStop();
  9524.                                                         player[i].targetframe=0;
  9525.                                                         player[i].target=0;
  9526.                                                         player[i].targetrotation+=180;
  9527.                                                         player[i].stunned=.5;
  9528.                                                         //player[i].aitype=passivetype;
  9529.                                                         player[i].aitype=pathfindtype;
  9530.                                                         player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
  9531.                                                         player[i].finalpathfindpoint=-1;
  9532.                                                         player[i].targetpathfindpoint=-1;
  9533.                                                         player[i].lastpathfindpoint=-1;
  9534.                                                         player[i].lastpathfindpoint2=-1;
  9535.                                                         player[i].lastpathfindpoint3=-1;
  9536.                                                         player[i].lastpathfindpoint4=-1;
  9537.                                                     }
  9538.                                                     else player[i].laststanding=j;
  9539.                                                 }
  9540.                                             }  
  9541.                                             if(player[i].aiupdatedelay<0){
  9542.                                                 rotatetarget=player[i].lastseen-player[i].coords;
  9543.                                                 Normalise(&rotatetarget);
  9544.                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
  9545.                                                 player[i].targetrotation*=360/6.28;
  9546.                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
  9547.                                                 player[i].lookrotation=player[i].targetrotation;
  9548.                                                 player[i].aiupdatedelay=.05;
  9549.                                                 player[i].forwardkeydown=1;
  9550.  
  9551.                                                 if(findDistancefastflat(&player[i].coords,&player[i].lastseen)<1*(player[i].scale*5)*(player[i].scale*5)||player[i].lastchecktime<0){
  9552.                                                     player[i].forwardkeydown=0;
  9553.                                                     player[i].aiupdatedelay=1;
  9554.                                                     player[i].lastseen.x+=(float(Random()%100)-50)/25;
  9555.                                                     player[i].lastseen.z+=(float(Random()%100)-50)/25;
  9556.                                                     player[i].lastchecktime=3;
  9557.                                                 }
  9558.  
  9559.                                                 player[i].leftkeydown=0;
  9560.                                                 player[i].backkeydown=0;
  9561.                                                 player[i].rightkeydown=0;
  9562.                                                 player[i].crouchkeydown=0;
  9563.                                                 player[i].attackkeydown=0;
  9564.                                                 player[i].throwkeydown=0;
  9565.  
  9566.                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
  9567.                                                     if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
  9568.                                                     else{
  9569.                                                         XYZ leftpos,rightpos;
  9570.                                                         float leftdist,rightdist;
  9571.                                                         leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
  9572.                                                         rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
  9573.                                                         leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
  9574.                                                         rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
  9575.                                                         if(leftdist<rightdist)player[i].targetrotation+=90;
  9576.                                                         else player[i].targetrotation-=90;
  9577.                                                     }
  9578.                                                 }
  9579.                                             }
  9580.                                             if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
  9581.                                             if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
  9582.  
  9583.                                             if(numenvsounds>0&&((tutoriallevel!=1||cananger)&&hostile))
  9584.                                                 for(j=0;j<numenvsounds;j++){
  9585.                                                     if(findDistancefast(&player[i].coords,&envsound[j])<2*(envsoundvol[j]+envsoundvol[j]*(player[i].creature==rabbittype)*3)){
  9586.                                                         player[i].aitype=attacktypecutoff;
  9587.                                                     }
  9588.                                                 }
  9589.  
  9590.                                                 if(!player[0].dead&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2&&((tutoriallevel!=1||cananger)&&hostile)){
  9591.                                                     player[i].losupdatedelay=.2;
  9592.                                                     if(findDistancefast(&player[i].coords,&player[0].coords)<4&&animation[player[i].targetanimation].height!=lowheight)
  9593.                                                     {player[i].aitype=attacktypecutoff;
  9594.                                                     player[i].lastseentime=1;}
  9595.                                                     if(abs(Random()%2)||animation[player[i].targetanimation].height!=lowheight)
  9596.                                                         if(findDistancefast(&player[i].coords,&player[0].coords)<400)
  9597.                                                             if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
  9598.                                                                 if((-1==checkcollide(DoRotation(player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position,0,player[i].rotation,0)*player[i].scale+player[i].coords,DoRotation(player[0].skeleton.joints[player[0].skeleton.jointlabels[head]].position,0,player[0].rotation,0)*player[0].scale+player[0].coords))||(player[j].targetanimation==hanganim&&normaldotproduct(player[j].facing,player[i].coords-player[j].coords)<0)){
  9599.                                                                     player[i].aitype=attacktypecutoff;
  9600.                                                                     player[i].lastseentime=1;
  9601.                                                                 }
  9602.                                                 }
  9603.                                                 if(player[i].lastseentime<0){
  9604.                                                     //player[i].aitype=passivetype;
  9605.                                                     numescaped++;
  9606.                                                     player[i].aitype=pathfindtype;
  9607.                                                     player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
  9608.                                                     player[i].finalpathfindpoint=-1;
  9609.                                                     player[i].targetpathfindpoint=-1;
  9610.                                                     player[i].lastpathfindpoint=-1;
  9611.                                                     player[i].lastpathfindpoint2=-1;
  9612.                                                     player[i].lastpathfindpoint3=-1;
  9613.                                                     player[i].lastpathfindpoint4=-1;
  9614.                                                 }
  9615.                                         }
  9616.  
  9617.                                         if(player[i].aitype!=gethelptype){
  9618.                                             player[i].runninghowlong=0;
  9619.                                         }
  9620.  
  9621.                                         if(player[i].aitype==gethelptype){
  9622.                                             player[i].runninghowlong+=multiplier;
  9623.                                             player[i].aiupdatedelay-=multiplier;
  9624.  
  9625.                                             if(player[i].aiupdatedelay<0||player[i].ally==0){
  9626.                                                 player[i].aiupdatedelay=.2;
  9627.  
  9628.                                                 int closest;
  9629.                                                 float closestdist;
  9630.                                                 closest=-1;
  9631.                                                 closestdist=-1;
  9632.                                                 float distance;
  9633.  
  9634.                                                 if(!player[i].ally){
  9635.                                                     for(j=0;j<numplayers;j++){
  9636.                                                         if(j!=i&&j!=0&&!player[j].dead&&player[j].howactive<typedead1&&!player[j].skeleton.free&&player[j].aitype==passivetype){
  9637.                                                             distance=findDistancefast(&player[i].coords,&player[j].coords);
  9638.                                                             if(closestdist==-1||distance<closestdist){
  9639.                                                                 closestdist=distance;
  9640.                                                                 closest=j;
  9641.                                                             }
  9642.                                                             closest=j;
  9643.                                                         }
  9644.                                                     }
  9645.                                                     if(closest!=-1)player[i].ally=closest;
  9646.                                                     else player[i].ally=0;
  9647.                                                     player[i].lastseen=player[0].coords;
  9648.                                                     player[i].lastseentime=12;
  9649.                                                 }
  9650.  
  9651.  
  9652.                                                 player[i].lastchecktime=12;
  9653.                                                 //player[i].lastseentime-=.5;
  9654.  
  9655.                                                 facing=player[i].coords;
  9656.                                                 flatfacing=player[player[i].ally].coords;
  9657.                                                 facing.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position.y*player[i].scale;
  9658.                                                 flatfacing.y+=player[player[i].ally].skeleton.joints[player[player[i].ally].skeleton.jointlabels[head]].position.y*player[player[i].ally].scale;
  9659.                                                 if(-1!=checkcollide(facing,flatfacing))
  9660.                                                     player[i].lastseentime-=.1;
  9661.  
  9662.                                                 if(player[i].ally<=0||player[player[i].ally].skeleton.free||player[player[i].ally].aitype!=passivetype||player[i].lastseentime<=0){
  9663.                                                     player[i].aitype=searchtype;
  9664.                                                     player[i].lastseentime=12;
  9665.                                                 }
  9666.  
  9667.                                                 if(player[i].ally>0){
  9668.                                                     rotatetarget=player[player[i].ally].coords-player[i].coords;
  9669.                                                     Normalise(&rotatetarget);
  9670.                                                     player[i].targetrotation=-asin(0-rotatetarget.x);
  9671.                                                     player[i].targetrotation*=360/6.28;
  9672.                                                     if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
  9673.                                                     player[i].lookrotation=player[i].targetrotation;
  9674.                                                     player[i].aiupdatedelay=.05;
  9675.                                                     player[i].forwardkeydown=1;                
  9676.  
  9677.                                                     if(findDistancefastflat(&player[i].coords,&player[player[i].ally].coords)<3){
  9678.                                                         player[i].aitype=searchtype;
  9679.                                                         player[i].lastseentime=12;
  9680.                                                         player[player[i].ally].aitype=searchtype;
  9681.                                                         if(player[player[i].ally].lastseentime<player[i].lastseentime){
  9682.                                                             player[player[i].ally].lastseen=player[i].lastseen;
  9683.                                                             player[player[i].ally].lastseentime=player[i].lastseentime;
  9684.                                                             player[player[i].ally].lastchecktime=player[i].lastchecktime;
  9685.                                                         }
  9686.                                                     }
  9687.  
  9688.                                                     if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
  9689.                                                         if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
  9690.                                                         else{
  9691.                                                             XYZ leftpos,rightpos;
  9692.                                                             float leftdist,rightdist;
  9693.                                                             leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
  9694.                                                             rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
  9695.                                                             leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
  9696.                                                             rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
  9697.                                                             if(leftdist<rightdist)player[i].targetrotation+=90;
  9698.                                                             else player[i].targetrotation-=90;
  9699.                                                         }
  9700.                                                     }
  9701.                                                 }
  9702.  
  9703.                                                 player[i].leftkeydown=0;
  9704.                                                 player[i].backkeydown=0;
  9705.                                                 player[i].rightkeydown=0;
  9706.                                                 player[i].crouchkeydown=0;
  9707.                                                 player[i].attackkeydown=0;
  9708.                                             }
  9709.                                             if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
  9710.                                             if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
  9711.                                         }
  9712.  
  9713.                                         if(player[i].aitype==getweapontype){
  9714.                                             player[i].aiupdatedelay-=multiplier;
  9715.                                             player[i].lastchecktime-=multiplier;
  9716.  
  9717.                                             if(player[i].aiupdatedelay<0){
  9718.                                                 player[i].aiupdatedelay=.2;
  9719.  
  9720.                                                 int closest;
  9721.                                                 float closestdist;
  9722.                                                 closest=-1;
  9723.                                                 closestdist=-1;
  9724.                                                 float distance;
  9725.  
  9726.                                                 if(player[i].ally<0){
  9727.                                                     for(j=0;j<weapons.numweapons;j++){
  9728.                                                         if(weapons.owner[j]==-1){
  9729.                                                             distance=findDistancefast(&player[i].coords,&weapons.position[j]);
  9730.                                                             if(closestdist==-1||distance<closestdist){
  9731.                                                                 closestdist=distance;
  9732.                                                                 closest=j;
  9733.                                                             }
  9734.                                                             closest=j;
  9735.                                                         }
  9736.                                                     }
  9737.                                                     if(closest!=-1)player[i].ally=closest;
  9738.                                                     else player[i].ally=-1;
  9739.                                                 }
  9740.  
  9741.                                                 player[i].lastseentime=12;
  9742.  
  9743.                                                 if(!player[0].dead&&((tutoriallevel!=1||cananger)&&hostile))
  9744.                                                     if(player[i].ally<0||player[i].weaponactive!=-1||player[i].lastchecktime<=0){
  9745.                                                         player[i].aitype=attacktypecutoff;
  9746.                                                         player[i].lastseentime=1;
  9747.                                                     }                  
  9748.                                                     if(!player[0].dead)
  9749.                                                         if(player[i].ally>=0){
  9750.                                                             if(weapons.owner[player[i].ally]!=-1||findDistancefast(&player[i].coords,&weapons.position[player[i].ally])>16){
  9751.                                                                 player[i].aitype=attacktypecutoff;
  9752.                                                                 player[i].lastseentime=1;
  9753.                                                             }
  9754.                                                             rotatetarget=weapons.position[player[i].ally]-player[i].coords;
  9755.                                                             Normalise(&rotatetarget);
  9756.                                                             player[i].targetrotation=-asin(0-rotatetarget.x);
  9757.                                                             player[i].targetrotation*=360/6.28;
  9758.                                                             if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
  9759.                                                             player[i].lookrotation=player[i].targetrotation;
  9760.                                                             player[i].aiupdatedelay=.05;
  9761.                                                             player[i].forwardkeydown=1;                
  9762.  
  9763.  
  9764.                                                             if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
  9765.                                                                 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
  9766.                                                                 else{
  9767.                                                                     XYZ leftpos,rightpos;
  9768.                                                                     float leftdist,rightdist;
  9769.                                                                     leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
  9770.                                                                     rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
  9771.                                                                     leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
  9772.                                                                     rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
  9773.                                                                     if(leftdist<rightdist)player[i].targetrotation+=90;
  9774.                                                                     else player[i].targetrotation-=90;
  9775.                                                                 }
  9776.                                                             }
  9777.                                                             /*if(findDistancefast(&player[i].coords,&weapons.position[player[i].ally])<3){
  9778.                                                             if(abs(Random()%6)){
  9779.                                                             player[i].crouchkeydown=1;
  9780.                                                             if(!findDistancefast(&player[i].coords,&weapons.position[player[i].ally])<1){
  9781.                                                             if(player[i].isRun()){
  9782.                                                             player[i].targetframe=0;
  9783.                                                             player[i].target=0;
  9784.                                                             player[i].targetanimation=sneakanim;
  9785.                                                             }
  9786.                                                             }
  9787.                                                             else player[i].forwardkeydown=0;
  9788.                                                             }
  9789.                                                             else player[i].crouchkeydown=0;
  9790.                                                             }
  9791.                                                             else player[i].crouchkeydown=0;*/
  9792.                                                         }
  9793.  
  9794.                                                         player[i].leftkeydown=0;
  9795.                                                         player[i].backkeydown=0;
  9796.                                                         player[i].rightkeydown=0;
  9797.                                                         player[i].attackkeydown=0;
  9798.                                                         player[i].throwkeydown=1;
  9799.                                                         player[i].crouchkeydown=0; 
  9800.                                                         if(player[i].targetanimation!=crouchremoveknifeanim&&player[i].targetanimation!=removeknifeanim)player[i].throwtogglekeydown=0;
  9801.                                                         player[i].drawkeydown=0;
  9802.                                             }
  9803.                                             if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
  9804.                                             if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
  9805.                                         }
  9806.  
  9807.                                         if(player[i].aitype==attacktypecutoff){
  9808.                                             player[i].aiupdatedelay-=multiplier;
  9809.                                             if(player[i].damage<player[i].damagetolerance*2/3)
  9810.                                                 if((player[0].targetanimation==rabbitkickanim||player[0].targetanimation==knifethrowanim||(player[0].isFlip()&&normaldotproduct(player[0].facing,player[0].coords-player[i].coords)<0))&&!player[0].skeleton.free&&(player[i].aiupdatedelay<.1)){
  9811.                                                     player[i].attackkeydown=0;
  9812.                                                     if(player[i].isIdle())player[i].crouchkeydown=1;
  9813.                                                     if(player[0].targetanimation!=rabbitkickanim&&player[0].weaponactive!=-1){
  9814.                                                         if(weapons.type[player[0].weaponids[0]]==knife){
  9815.                                                             if(player[i].isIdle()||player[i].isCrouch()||player[i].isRun()||player[i].isFlip()){
  9816.                                                                 if(abs(Random()%2==0))player[i].targetanimation=backhandspringanim;
  9817.                                                                 else player[i].targetanimation=rollanim;
  9818.                                                                 player[i].target=0;
  9819.                                                                 player[i].targetframe=0;
  9820.                                                                 player[i].targetrotation+=90*(abs(Random()%2)*2-1);
  9821.                                                                 player[i].wentforweapon=0;
  9822.                                                             }
  9823.                                                             if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim){
  9824.                                                                 player[i].targetanimation=flipanim;
  9825.                                                                 player[i].target=0;
  9826.                                                                 player[i].targetframe=0;
  9827.                                                             }
  9828.                                                         }
  9829.                                                     }
  9830.                                                     player[i].forwardkeydown=0;
  9831.                                                     player[i].aiupdatedelay=.02;
  9832.                                                 }
  9833.                                                 if(player[0].isFlip()&&!player[0].skeleton.free&&player[0].targetanimation!=walljumprightkickanim&&player[0].targetanimation!=walljumpleftkickanim){
  9834.                                                     if(findDistancefast(&player[0].coords,&player[i].coords)<25)
  9835.                                                         if((1-player[i].damage/player[i].damagetolerance)>.5)player[i].stunned=1;
  9836.                                                 }
  9837.                                                 if(player[i].wentforweapon<3)
  9838.                                                     for(j=0;j<weapons.numweapons;j++){
  9839.                                                         if(player[i].creature!=wolftype)
  9840.                                                             if(player[i].num_weapons==0&&weapons.owner[j]==-1&&weapons.velocity[i].x==0&&weapons.velocity[i].z==0&&weapons.velocity[i].y==0){
  9841.                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<16){
  9842.                                                                     player[i].wentforweapon++;
  9843.                                                                     player[i].lastchecktime=6;
  9844.                                                                     player[i].aitype=getweapontype;
  9845.                                                                     player[i].ally=-1;
  9846.                                                                 }
  9847.                                                             }
  9848.                                                     }
  9849.                                                     if(player[i].damage<player[i].damagetolerance/2)
  9850.                                                         if(animation[player[i].targetanimation].height!=highheight)
  9851.                                                             if(player[i].damage<player[i].damagetolerance*.5&&((player[0].targetanimation==walljumprightkickanim||player[0].targetanimation==walljumpleftkickanim)&&((player[i].aiupdatedelay<.15&&difficulty==2)||(player[i].aiupdatedelay<.08&&difficulty!=2)))){
  9852.                                                                 player[i].crouchkeydown=1;
  9853.                                                             }
  9854.                                                             if(player[i].isRun()&&!player[i].onground){
  9855.                                                                 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
  9856.                                                                     test2=player[i].coords+player[i].facing;
  9857.                                                                     test2.y+=5;
  9858.                                                                     test=player[i].coords+player[i].facing;
  9859.                                                                     test.y-=10;
  9860.                                                                     j=checkcollide(test2,test,player[i].laststanding);
  9861.                                                                     if(j==-1)j=checkcollide(test2,test);
  9862.                                                                     if(j==-1){
  9863.                                                                         player[i].velocity=0;
  9864.                                                                         player[i].targetanimation=player[i].getStop();
  9865.                                                                         player[i].targetframe=0;
  9866.                                                                         player[i].target=0;
  9867.                                                                         player[i].targetrotation+=180;
  9868.                                                                         player[i].stunned=.5;
  9869.                                                                         //player[i].aitype=passivetype;
  9870.                                                                         player[i].aitype=pathfindtype;
  9871.                                                                         player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
  9872.                                                                         player[i].finalpathfindpoint=-1;
  9873.                                                                         player[i].targetpathfindpoint=-1;
  9874.                                                                         player[i].lastpathfindpoint=-1;
  9875.                                                                         player[i].lastpathfindpoint2=-1;
  9876.                                                                         player[i].lastpathfindpoint3=-1;
  9877.                                                                         player[i].lastpathfindpoint4=-1;
  9878.                                                                     }
  9879.                                                                     else player[i].laststanding=j;
  9880.                                                                 }
  9881.                                                             }
  9882.                                                             if(player[0].coords.y>player[i].coords.y+5&&animation[player[0].targetanimation].height!=highheight&&!player[0].onterrain){
  9883.                                                                 player[i].aitype=pathfindtype;
  9884.                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
  9885.                                                                 player[i].finalpathfindpoint=-1;
  9886.                                                                 player[i].targetpathfindpoint=-1;
  9887.                                                                 player[i].lastpathfindpoint=-1;
  9888.                                                                 player[i].lastpathfindpoint2=-1;
  9889.                                                                 player[i].lastpathfindpoint3=-1;
  9890.                                                                 player[i].lastpathfindpoint4=-1;
  9891.                                                             }  
  9892.                                                             if(player[i].aiupdatedelay<0&&!animation[player[i].targetanimation].attack&&player[i].targetanimation!=staggerbackhighanim&&player[i].targetanimation!=staggerbackhardanim&&player[i].targetanimation!=backhandspringanim&&player[i].targetanimation!=dodgebackanim){
  9893.                                                                 if(player[i].weaponactive==-1&&player[i].num_weapons>0)player[i].drawkeydown=Random()%2;
  9894.                                                                 else player[i].drawkeydown=0;
  9895.                                                                 player[i].rabbitkickenabled=Random()%2;
  9896.                                                                 rotatetarget=player[player[i].aitarget].coords+player[player[i].aitarget].velocity;
  9897.                                                                 if(findDistancefast(&player[player[i].aitarget].coords,&player[i].coords)<findDistancefast(&rotatetarget,&player[i].coords))
  9898.                                                                     rotatetarget=player[player[i].aitarget].coords+player[player[i].aitarget].velocity*findDistance(&player[player[i].aitarget].coords,&player[i].coords)/findLength(&player[i].velocity)-player[i].coords;
  9899.                                                                 else rotatetarget=player[player[i].aitarget].coords-player[i].coords;
  9900.                                                                 Normalise(&rotatetarget);
  9901.                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
  9902.                                                                 player[i].targetrotation*=360/6.28;
  9903.                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
  9904.                                                                 player[i].lookrotation=player[i].targetrotation;
  9905.                                                                 player[i].aiupdatedelay=.2+abs((float)(Random()%100)/1000);
  9906.  
  9907.                                                                 oldkey=player[i].forwardkeydown;
  9908.                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)>5&&(player[0].weaponactive==-1||player[i].weaponactive!=-1))player[i].forwardkeydown=1;
  9909.                                                                 else if((findDistancefast(&player[i].coords,&player[0].coords)>16||findDistancefast(&player[i].coords,&player[0].coords)<9)&&player[0].weaponactive!=-1)player[i].forwardkeydown=1;
  9910.                                                                 else if(Random()%6==0||(player[i].creature==wolftype&&Random()%3==0))player[i].forwardkeydown=1;
  9911.                                                                 else player[i].forwardkeydown=0;
  9912.                                                                 if(player[0].dead){
  9913.                                                                     player[i].forwardkeydown=0;
  9914.                                                                     if(Random()%10==0)player[i].forwardkeydown=1;
  9915.                                                                     if(Random()%100==0){
  9916.                                                                         player[i].aitype=pathfindtype;
  9917.                                                                         player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
  9918.                                                                         player[i].finalpathfindpoint=-1;
  9919.                                                                         player[i].targetpathfindpoint=-1;
  9920.                                                                         player[i].lastpathfindpoint=-1;
  9921.                                                                         player[i].lastpathfindpoint2=-1;
  9922.                                                                         player[i].lastpathfindpoint3=-1;
  9923.                                                                         player[i].lastpathfindpoint4=-1;
  9924.                                                                     }
  9925.                                                                 }
  9926.                                                                 player[i].leftkeydown=0;
  9927.                                                                 player[i].backkeydown=0;
  9928.                                                                 player[i].rightkeydown=0;
  9929.                                                                 player[i].crouchkeydown=0;
  9930.                                                                 player[i].throwkeydown=0;
  9931.  
  9932.                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
  9933.                                                                 /*for(j=0;j<numplayers;j++){
  9934.                                                                 if(player[j].victim->id==i&&(player[j].targetanimation==spinkickanim&&player[j].targetframe<3)){
  9935.                                                                 player[i].crouchkeydown=1;
  9936.                                                                 }
  9937.                                                                 }*/
  9938.                                                                 if(Random()%2==0/*||player[0].weaponactive!=-1*/||player[i].weaponactive!=-1||player[i].creature==wolftype)player[i].attackkeydown=1;
  9939.                                                                 else player[i].attackkeydown=0;
  9940.                                                                 if((player[i].isRun())&&Random()%6&&findDistancefast(&player[i].coords,&player[0].coords)>7)player[i].attackkeydown=0;
  9941.                                                                 //if(player[i].attackkeydown&&findDistancefast(&player[i].coords,&player[0].coords)<3&&player[i].targetanimation!=runanim&&!player[0].skeleton.free)player[i].crouchkeydown=1;
  9942.                                                                 /*if(player[0].targetanimation==rabbitkickanim&&!player[0].skeleton.free){
  9943.                                                                 player[i].attackkeydown=0;
  9944.                                                                 if(player[i].isIdle())player[i].crouchkeydown=1;
  9945.                                                                 player[i].forwardkeydown=0;
  9946.                                                                 player[i].aiupdatedelay=.02;
  9947.                                                                 }*/
  9948.  
  9949.                                                                 if(player[i].aitype!=playercontrolled&&(player[i].isIdle()||player[i].isCrouch()||player[i].isRun())){
  9950.                                                                     target=-2;
  9951.                                                                     for(j=0;j<numplayers;j++){
  9952.                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].hasvictim&&((tutoriallevel==1&&reversaltrain)||(Random()%2==0&&difficulty==2)||(Random()%4==0&&difficulty==1)||(Random()%8==0&&difficulty==0)||(player[j].lastattack2==player[j].targetanimation&&player[j].lastattack3==player[j].targetanimation&&(Random()%2==0||difficulty==2))||((player[i].isIdle()||player[i].isRun())&&player[j].weaponactive!=-1)||(player[j].targetanimation==swordslashanim&&player[i].weaponactive!=-1)||player[j].targetanimation==staffhitanim||player[j].targetanimation==staffspinhitanim)){
  9953.                                                                             if(findDistancefast(&player[j].coords,&player[j].victim->coords)<4&&player[j].victim==&player[i]&&(player[j].targetanimation==sweepanim||player[j].targetanimation==spinkickanim||player[j].targetanimation==staffhitanim||player[j].targetanimation==staffspinhitanim||player[j].targetanimation==winduppunchanim||player[j].targetanimation==upunchanim||player[j].targetanimation==wolfslapanim||player[j].targetanimation==knifeslashstartanim||((player[j].targetanimation==swordslashanim)&&(findDistancefast(&player[j].coords,&player[i].coords)<2||(player[i].weaponactive!=-1))))){
  9954.                                                                                 if(target>=0)target=-1;
  9955.                                                                                 else target=j;
  9956.                                                                             }
  9957.                                                                         }
  9958.                                                                     }
  9959.                                                                     if(target>=0)player[target].Reverse();
  9960.                                                                 }
  9961.  
  9962.                                                                 if(player[i].collided<1)player[i].jumpkeydown=0;
  9963.                                                                 if((player[i].collided>.8&&player[i].jumppower>=5)||(findDistancefast(&player[i].coords,&player[0].coords)>400&&player[i].onterrain&&player[i].creature==rabbittype))player[i].jumpkeydown=1;
  9964.                                                                 if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
  9965.                                                                     player[0].jumpkeydown=0;
  9966.                                                                 if(player[0].targetanimation==jumpdownanim&&findDistancefast(&player[0].coords,&player[i].coords)<40)player[i].crouchkeydown=1;
  9967.                                                                 if(player[i].jumpkeydown)player[i].attackkeydown=0;
  9968.                                                                 //if(animation[player[i].targetanimation].attack==reversed)player[i].crouchkeydown=1;
  9969.  
  9970.                                                                 if(tutoriallevel==1){
  9971.                                                                     if(!canattack)player[i].attackkeydown=0;
  9972.                                                                 }
  9973.  
  9974.  
  9975.                                                                 facing=player[i].coords;
  9976.                                                                 flatfacing=player[0].coords;
  9977.                                                                 facing.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position.y*player[i].scale;
  9978.                                                                 flatfacing.y+=player[0].skeleton.joints[player[0].skeleton.jointlabels[head]].position.y*player[0].scale;
  9979.                                                                 if(player[i].occluded>=2)
  9980.                                                                     if(-1!=checkcollide(facing,flatfacing)){
  9981.                                                                         if(!player[i].pause)player[i].lastseentime-=.2;
  9982.                                                                         if(player[i].lastseentime<=0&&(player[i].creature!=wolftype||player[i].weaponstuck==-1)){
  9983.                                                                             player[i].aitype=searchtype;
  9984.                                                                             player[i].lastchecktime=12;
  9985.                                                                             player[i].lastseen=player[0].coords;
  9986.                                                                             player[i].lastseentime=12;
  9987.                                                                         }
  9988.                                                                     }
  9989.                                                                     else player[i].lastseentime=1;
  9990.                                                             }
  9991.                                         }
  9992.                                         if(animation[player[0].targetanimation].height==highheight&&(player[i].aitype==attacktypecutoff||player[i].aitype==searchtype)){
  9993.                                             if(player[0].coords.y>terrain.getHeight(player[0].coords.x,player[0].coords.z)+10){
  9994.                                                 test=player[0].coords;
  9995.                                                 test.y-=40;
  9996.                                                 if(-1==checkcollide(player[0].coords,test))player[i].stunned=1;
  9997.                                             }
  9998.                                         }
  9999.                                         // NOTE: Ask about logic of this call : NOTE
  10000.                                         if((player[i].aitype==passivetype && !(player[i].numwaypoints>1)) ||
  10001.                                             player[i].stunned>0 ||
  10002.                                             (player[i].pause && (player[i].damage > player[i].superpermanentdamage)))
  10003.                                         {
  10004.                                             if(/*player[i].aitype==attacktypecutoff&&*/player[i].pause)player[i].lastseentime=1;
  10005.                                             player[i].targetrotation=player[i].rotation;
  10006.                                             player[i].forwardkeydown=0;
  10007.                                             player[i].leftkeydown=0;
  10008.                                             player[i].backkeydown=0;
  10009.                                             player[i].rightkeydown=0;
  10010.                                             player[i].jumpkeydown=0;
  10011.                                             player[i].attackkeydown=0;
  10012.                                             player[i].crouchkeydown=0;
  10013.                                             player[i].throwkeydown=0;
  10014.                                         }
  10015.  
  10016.  
  10017.                                         facing=0;
  10018.                                         facing.z=-1;
  10019.  
  10020.                                         flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
  10021.                                         facing=flatfacing;
  10022.  
  10023.                                         if(player[i].aitype==attacktypecutoff){
  10024.                                             rotatetarget=player[0].coords-player[i].coords;
  10025.                                             Normalise(&rotatetarget);
  10026.                                             player[i].targetheadrotation=-asin(0-rotatetarget.x);
  10027.                                             player[i].targetheadrotation*=360/6.28;
  10028.                                             if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
  10029.  
  10030.                                             player[i].targetheadrotation*=-1;
  10031.                                             player[i].targetheadrotation+=180;
  10032.                                             //player[i].targetheadrotation2=0;
  10033.                                             player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
  10034.                                         }
  10035.                                         else if(player[i].howactive>=typesleeping){
  10036.                                             player[i].targetheadrotation=player[i].targetrotation;
  10037.                                             player[i].targetheadrotation2=0;
  10038.                                         }
  10039.                                         else {
  10040.                                             if(player[i].interestdelay<=0){
  10041.                                                 player[i].interestdelay=.7+(float)(abs(Random()%100))/100;
  10042.                                                 player[i].headtarget=player[i].coords;
  10043.                                                 player[i].headtarget.x+=(float)(abs(Random()%200)-100)/100;
  10044.                                                 player[i].headtarget.z+=(float)(abs(Random()%200)-100)/100;
  10045.                                                 player[i].headtarget.y+=(float)(abs(Random()%200)-100)/300;
  10046.                                                 player[i].headtarget+=player[i].facing*1.5;
  10047.                                             }
  10048.                                             rotatetarget=player[i].headtarget-player[i].coords;
  10049.                                             Normalise(&rotatetarget);
  10050.                                             player[i].targetheadrotation=-asin(0-rotatetarget.x);
  10051.                                             player[i].targetheadrotation*=360/6.28;
  10052.                                             if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
  10053.  
  10054.                                             player[i].targetheadrotation*=-1;
  10055.                                             player[i].targetheadrotation+=180;
  10056.                                             player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
  10057.                                         }
  10058.                                         //if(whichlevel==2)player[i].jumpkeydown=0;
  10059.                                     }
  10060.                                     if(animation[player[i].targetanimation].attack==reversed){
  10061.                                         //player[i].targetrotation=player[i].rotation;
  10062.                                         player[i].forwardkeydown=0;
  10063.                                         player[i].leftkeydown=0;
  10064.                                         player[i].backkeydown=0;
  10065.                                         player[i].rightkeydown=0;
  10066.                                         player[i].jumpkeydown=0;
  10067.                                         player[i].attackkeydown=0;
  10068.                                         //player[i].crouchkeydown=0;
  10069.                                         player[i].throwkeydown=0;
  10070.                                     }
  10071.  
  10072.                                     if(indialogue!=-1){
  10073.                                         player[i].forwardkeydown=0;
  10074.                                         player[i].leftkeydown=0;
  10075.                                         player[i].backkeydown=0;
  10076.                                         player[i].rightkeydown=0;
  10077.                                         player[i].jumpkeydown=0;
  10078.                                         player[i].crouchkeydown=0;
  10079.                                         player[i].drawkeydown=0;
  10080.                                         player[i].throwkeydown=0;
  10081.                                     }
  10082.  
  10083.                                     if(player[i].collided<-.3)player[i].collided=-.3;
  10084.                                     if(player[i].collided>1)player[i].collided=1;
  10085.                                     player[i].collided-=multiplier*4;
  10086.                                     player[i].whichdirectiondelay-=multiplier;
  10087.                                     if(player[i].avoidcollided<-.3||player[i].whichdirectiondelay<=0){
  10088.                                         player[i].avoidcollided=-.3;
  10089.                                         player[i].whichdirection=abs(Random()%2);
  10090.                                         player[i].whichdirectiondelay=.4;
  10091.                                     }
  10092.                                     if(player[i].avoidcollided>1)player[i].avoidcollided=1;
  10093.                                     player[i].avoidcollided-=multiplier/4;
  10094.                                     if(!player[i].skeleton.free)player[i].stunned-=multiplier;
  10095.                                     if(!player[i].skeleton.free)player[i].surprised-=multiplier;
  10096.                                     if(player[i].surprised<=0&&player[i].aitype==attacktypecutoff&&i!=0&&!player[i].dead&&!player[i].skeleton.free&&animation[player[i].targetanimation].attack==neutral)numresponded=1;
  10097.  
  10098.                                     if(!player[i].throwkeydown){
  10099.                                         player[i].throwtogglekeydown=0;
  10100.                                     }
  10101.                                     if(player[i].throwkeydown&&!player[i].throwtogglekeydown){
  10102.                                         if(player[i].weaponactive==-1&&player[i].num_weapons<2&&(player[i].isIdle()||player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim||player[i].isFlip()||player[i].isFlip()||player[i].aitype!=playercontrolled)){
  10103.                                             for(j=0;j<weapons.numweapons;j++){
  10104.                                                 if(((weapons.velocity[j].x==0&&weapons.velocity[j].y==0&&weapons.velocity[j].z==0)||player[i].aitype==playercontrolled)&&weapons.owner[j]==-1&&player[i].weaponactive==-1)
  10105.                                                     if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2){
  10106.                                                         if(findDistancefast(&player[i].coords,&weapons.position[j])<2){
  10107.                                                             if(player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isRun()||player[i].isIdle()||player[i].aitype!=playercontrolled){
  10108.                                                                 player[i].throwtogglekeydown=1;
  10109.                                                                 player[i].targetanimation=crouchremoveknifeanim;
  10110.                                                                 player[i].target=0;
  10111.                                                                 player[i].targetframe=0;
  10112.                                                                 rotatetarget=weapons.position[j]-player[i].coords;
  10113.                                                                 Normalise(&rotatetarget);
  10114.                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
  10115.                                                                 player[i].targetrotation*=360/6.28;
  10116.                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
  10117.                                                                 player[i].hasvictim=0;
  10118.                                                             }
  10119.                                                             if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
  10120.                                                                 player[i].throwtogglekeydown=1;
  10121.                                                                 player[i].hasvictim=0;
  10122.  
  10123.                                                                 //for(i=0;i<weapons.numweapons;i++){
  10124.                                                                 if((((weapons.velocity[j].x==0&&weapons.velocity[j].y==0&&weapons.velocity[j].z==0)||player[i].aitype==playercontrolled)&&weapons.owner[j]==-1)||(player[i].victim&&weapons.owner[j]==player[i].victim->id))
  10125.                                                                     if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2&&player[i].weaponactive==-1){
  10126.                                                                         if(findDistancefast(&player[i].coords,&weapons.position[j])<1||player[i].victim){
  10127.                                                                             float gLoc[3];
  10128.                                                                             float vel[3];
  10129.                                                                             gLoc[0]=player[i].coords.x;
  10130.                                                                             gLoc[1]=player[i].coords.y;
  10131.                                                                             gLoc[2]=player[i].coords.z;
  10132.                                                                             vel[0]=player[i].velocity.x;
  10133.                                                                             vel[1]=player[i].velocity.y;
  10134.                                                                             vel[2]=player[i].velocity.z;
  10135.                                                                             if(weapons.type[j]!=staff){
  10136.                                                                                 PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, TRUE);
  10137.                                                                                 FSOUND_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
  10138.                                                                                 FSOUND_SetVolume(channels[knifedrawsound], 128);
  10139.                                                                                 FSOUND_SetPaused(channels[knifedrawsound], FALSE);
  10140.                                                                             }
  10141.  
  10142.                                                                             player[i].weaponactive=0;
  10143.                                                                             weapons.owner[j]=player[i].id;
  10144.                                                                             if(player[i].num_weapons>0){
  10145.                                                                                 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
  10146.                                                                             }
  10147.                                                                             player[i].num_weapons++;
  10148.                                                                             player[i].weaponids[0]=j;
  10149.                                                                         }
  10150.                                                                     }
  10151.                                                                     //}
  10152.                                                             }
  10153.                                                         }
  10154.                                                         else if ((player[i].isIdle()||player[i].isFlip()||player[i].aitype!=playercontrolled)&&findDistancefast(&player[i].coords,&weapons.position[j])<5&&player[i].coords.y<weapons.position[j].y){
  10155.                                                             if(!player[i].isFlip()){
  10156.                                                                 player[i].throwtogglekeydown=1;
  10157.                                                                 player[i].targetanimation=removeknifeanim;
  10158.                                                                 player[i].target=0;
  10159.                                                                 player[i].targetframe=0;
  10160.                                                                 rotatetarget=weapons.position[j]-player[i].coords;
  10161.                                                                 Normalise(&rotatetarget);
  10162.                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
  10163.                                                                 player[i].targetrotation*=360/6.28;
  10164.                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
  10165.                                                             }
  10166.                                                             if(player[i].isFlip()){
  10167.                                                                 player[i].throwtogglekeydown=1;
  10168.                                                                 player[i].hasvictim=0;
  10169.  
  10170.                                                                 for(k=0;k<weapons.numweapons;k++){
  10171.                                                                     if(player[i].weaponactive==-1)
  10172.                                                                         if((((weapons.velocity[k].x==0&&weapons.velocity[k].y==0&&weapons.velocity[k].z==0)||player[i].aitype==playercontrolled)&&weapons.owner[k]==-1)||(player[i].victim&&weapons.owner[k]==player[i].victim->id))
  10173.                                                                             if(findDistancefastflat(&player[i].coords,&weapons.position[k])<3&&player[i].weaponactive==-1){
  10174.                                                                                 float gLoc[3];
  10175.                                                                                 float vel[3];
  10176.                                                                                 gLoc[0]=player[i].coords.x;
  10177.                                                                                 gLoc[1]=player[i].coords.y;
  10178.                                                                                 gLoc[2]=player[i].coords.z;
  10179.                                                                                 vel[0]=player[i].velocity.x;
  10180.                                                                                 vel[1]=player[i].velocity.y;
  10181.                                                                                 vel[2]=player[i].velocity.z;
  10182.                                                                                 if(weapons.type[k]!=staff){
  10183.                                                                                     PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, TRUE);
  10184.                                                                                     FSOUND_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
  10185.                                                                                     FSOUND_SetVolume(channels[knifedrawsound], 128);
  10186.                                                                                     FSOUND_SetPaused(channels[knifedrawsound], FALSE);
  10187.                                                                                 }
  10188.  
  10189.                                                                                 player[i].weaponactive=0;
  10190.                                                                                 weapons.owner[k]=player[i].id;
  10191.                                                                                 if(player[i].num_weapons>0){
  10192.                                                                                     player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
  10193.                                                                                 }
  10194.                                                                                 player[i].num_weapons++;
  10195.                                                                                 player[i].weaponids[0]=k;
  10196.                                                                             }
  10197.                                                                 }
  10198.                                                             }
  10199.                                                         }
  10200.                                                     }
  10201.                                             }
  10202.                                             if(player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isRun()||player[i].isIdle()||player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
  10203.                                                 if(numplayers>1)
  10204.                                                     for(j=0;j<numplayers;j++){
  10205.                                                         if(player[i].weaponactive==-1)
  10206.                                                             if(j!=i)
  10207.                                                                 if(player[j].num_weapons&&player[j].skeleton.free&&findDistancefast(&player[i].coords,&player[j].coords)<2/*&&player[j].dead*/&&(((player[j].skeleton.forward.y<0&&player[j].weaponstuckwhere==0)||(player[j].skeleton.forward.y>0&&player[j].weaponstuckwhere==1))||player[j].weaponstuck==-1||player[j].num_weapons>1)){
  10208.                                                                     if(player[i].targetanimation!=rollanim&&player[i].targetanimation!=backhandspringanim){
  10209.                                                                         player[i].throwtogglekeydown=1;
  10210.                                                                         player[i].victim=&player[j];
  10211.                                                                         player[i].hasvictim=1;
  10212.                                                                         player[i].targetanimation=crouchremoveknifeanim;
  10213.                                                                         player[i].target=0;
  10214.                                                                         player[i].targetframe=0;
  10215.                                                                         rotatetarget=player[j].coords-player[i].coords;
  10216.                                                                         Normalise(&rotatetarget);
  10217.                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
  10218.                                                                         player[i].targetrotation*=360/6.28;
  10219.                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
  10220.                                                                     }
  10221.                                                                     if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
  10222.                                                                         player[i].throwtogglekeydown=1;
  10223.                                                                         player[i].victim=&player[j];
  10224.                                                                         player[i].hasvictim=1;
  10225.                                                                         int k = player[j].weaponids[0];
  10226.                                                                         if(player[i].hasvictim){
  10227.                                                                             float gLoc[3];
  10228.                                                                             float vel[3];
  10229.                                                                             gLoc[0]=player[i].coords.x;
  10230.                                                                             gLoc[1]=player[i].coords.y;
  10231.                                                                             gLoc[2]=player[i].coords.z;
  10232.                                                                             vel[0]=player[i].velocity.x;
  10233.                                                                             vel[1]=player[i].velocity.y;
  10234.                                                                             vel[2]=player[i].velocity.z;
  10235.                                                                             bool fleshstuck;
  10236.                                                                             fleshstuck=0;
  10237.                                                                             if(player[i].victim->weaponstuck!=-1){
  10238.                                                                                 if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
  10239.                                                                                     fleshstuck=1;
  10240.                                                                                 }
  10241.                                                                             }
  10242.                                                                             if(!fleshstuck){
  10243.                                                                                 if(weapons.type[k]!=staff){
  10244.                                                                                     PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, TRUE);
  10245.                                                                                     FSOUND_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
  10246.                                                                                     FSOUND_SetVolume(channels[knifedrawsound], 128);
  10247.                                                                                     FSOUND_SetPaused(channels[knifedrawsound], FALSE);
  10248.                                                                                 }
  10249.                                                                             }
  10250.                                                                             if(fleshstuck){
  10251.                                                                                 PlaySoundEx( fleshstabremovesound, samp[fleshstabremovesound], NULL, TRUE);
  10252.                                                                                 FSOUND_3D_SetAttributes(channels[fleshstabremovesound], gLoc, vel);
  10253.                                                                                 FSOUND_SetVolume(channels[fleshstabremovesound], 128);
  10254.                                                                                 FSOUND_SetPaused(channels[fleshstabremovesound], FALSE);
  10255.                                                                             }
  10256.  
  10257.                                                                             player[i].weaponactive=0;
  10258.                                                                             if(weapons.owner[k]!=-1){
  10259.                                                                                 if(player[i].victim->num_weapons==1)player[i].victim->num_weapons=0;
  10260.                                                                                 else player[i].victim->num_weapons=1;
  10261.  
  10262.                                                                                 player[i].victim->skeleton.longdead=0;
  10263.                                                                                 player[i].victim->skeleton.free=1;
  10264.                                                                                 player[i].victim->skeleton.broken=0;
  10265.  
  10266.                                                                                 for(int l=0;l<player[i].victim->skeleton.num_joints;l++){
  10267.                                                                                     player[i].victim->skeleton.joints[l].velchange=0;
  10268.                                                                                     player[i].victim->skeleton.joints[l].locked=0;
  10269.                                                                                 }
  10270.  
  10271.                                                                                 XYZ relative;
  10272.                                                                                 relative=0;
  10273.                                                                                 relative.y=10;
  10274.                                                                                 Normalise(&relative);
  10275.                                                                                 XYZ footvel,footpoint;
  10276.                                                                                 footvel=0;
  10277.                                                                                 footpoint=weapons.position[k];
  10278.                                                                                 if(player[i].victim->weaponstuck!=-1){
  10279.                                                                                     if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
  10280.                                                                                         if(bloodtoggle)sprites.MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
  10281.                                                                                         weapons.bloody[k]=2;
  10282.                                                                                         weapons.blooddrip[k]=5;
  10283.                                                                                         player[i].victim->weaponstuck=-1;
  10284.                                                                                         player[i].victim->bloodloss+=2000;
  10285.                                                                                         player[i].victim->DoDamage(2000);
  10286.                                                                                     }
  10287.                                                                                 }
  10288.                                                                                 if(player[i].victim->num_weapons>0){
  10289.                                                                                     if(player[i].victim->weaponstuck!=0&&player[i].victim->weaponstuck!=-1)player[i].victim->weaponstuck=0;
  10290.                                                                                     if(player[i].victim->weaponids[0]==k)
  10291.                                                                                         player[i].victim->weaponids[0]=player[i].victim->weaponids[player[i].victim->num_weapons];
  10292.                                                                                 }
  10293.  
  10294.                                                                                 player[i].victim->weaponactive=-1;
  10295.  
  10296.                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[abdomen]].velocity+=relative*6;
  10297.                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[neck]].velocity+=relative*6;
  10298.                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[rightshoulder]].velocity+=relative*6;
  10299.                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[leftshoulder]].velocity+=relative*6;
  10300.                                                                             }
  10301.                                                                             weapons.owner[k]=i;
  10302.                                                                             if(player[i].num_weapons>0){
  10303.                                                                                 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
  10304.                                                                             }
  10305.                                                                             player[i].num_weapons++;
  10306.                                                                             player[i].weaponids[0]=k;
  10307.                                                                         }
  10308.                                                                     }
  10309.                                                                 }
  10310.                                                     }
  10311.                                             }
  10312.                                         }
  10313.                                         if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
  10314.                                             if(weapons.type[player[i].weaponids[0]]==knife){
  10315.                                                 if(player[i].isIdle()||player[i].isRun()||player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isFlip())
  10316.                                                     if(numplayers>1)
  10317.                                                         for(j=0;j<numplayers;j++){
  10318.                                                             if(i!=j)
  10319.                                                                 if(tutoriallevel!=1||tutorialstage==49)
  10320.                                                                     if(hostile)
  10321.                                                                         if(normaldotproduct(player[i].facing,player[i].coords-player[j].coords)<0&&findDistancefast(&player[i].coords,&player[j].coords)<100&&findDistancefast(&player[i].coords,&player[j].coords)>1.5&&!player[j].skeleton.free&&-1==checkcollide(DoRotation(player[j].skeleton.joints[player[j].skeleton.jointlabels[head]].position,0,player[j].rotation,0)*player[j].scale+player[j].coords,DoRotation(player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position,0,player[i].rotation,0)*player[i].scale+player[i].coords)){
  10322.                                                                             if(!player[i].isFlip()){
  10323.                                                                                 player[i].throwtogglekeydown=1;
  10324.                                                                                 player[i].victim=&player[j];
  10325.                                                                                 player[i].targetanimation=knifethrowanim;
  10326.                                                                                 player[i].target=0;
  10327.                                                                                 player[i].targetframe=0;
  10328.                                                                                 rotatetarget=player[j].coords-player[i].coords;
  10329.                                                                                 Normalise(&rotatetarget);
  10330.                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
  10331.                                                                                 player[i].targetrotation*=360/6.28;
  10332.                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
  10333.  
  10334.                                                                                 player[i].targettilt2=-asin(rotatetarget.y)*360/6.28;
  10335.                                                                             }
  10336.                                                                             if(player[i].isFlip()){
  10337.                                                                                 if(player[i].weaponactive!=-1){
  10338.                                                                                     player[i].throwtogglekeydown=1;
  10339.                                                                                     player[i].victim=&player[j];
  10340.                                                                                     XYZ aim;
  10341.                                                                                     weapons.owner[player[i].weaponids[0]]=-1;
  10342.                                                                                     aim=player[i].victim->coords+DoRotation(player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[abdomen]].position,0,player[i].victim->rotation,0)*player[i].victim->scale+player[i].victim->velocity*findDistance(&player[i].victim->coords,&player[i].coords)/50-(player[i].coords+DoRotation(player[i].skeleton.joints[player[i].skeleton.jointlabels[righthand]].position,0,player[i].rotation,0)*player[i].scale);                       
  10343.                                                                                     Normalise(&aim);
  10344.  
  10345.                                                                                     aim=DoRotation(aim,(float)abs(Random()%30)-15,(float)abs(Random()%30)-15,0);
  10346.  
  10347.                                                                                     weapons.velocity[player[i].weaponids[0]]=aim*50;
  10348.                                                                                     weapons.tipvelocity[player[i].weaponids[0]]=aim*50;
  10349.                                                                                     weapons.missed[player[i].weaponids[0]]=0;
  10350.                                                                                     weapons.freetime[player[i].weaponids[0]]=0;
  10351.                                                                                     weapons.firstfree[player[i].weaponids[0]]=1;
  10352.                                                                                     weapons.physics[player[i].weaponids[0]]=0;
  10353.                                                                                     player[i].num_weapons--;
  10354.                                                                                     if(player[i].num_weapons){
  10355.                                                                                         player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
  10356.                                                                                     }
  10357.                                                                                     player[i].weaponactive=-1;
  10358.                                                                                 }      
  10359.                                                                             }
  10360.                                                                         }
  10361.                                                         }
  10362.                                             }
  10363.                                         }
  10364.                                         if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
  10365.                                             if(player[i].isCrouch()||player[i].targetanimation==sneakanim)
  10366.                                             {
  10367.                                                 player[i].throwtogglekeydown=1;
  10368.                                                 weapons.owner[player[i].weaponids[0]]=-1;
  10369.                                                 weapons.velocity[player[i].weaponids[0]]=player[i].velocity*.2;
  10370.                                                 if(weapons.velocity[player[i].weaponids[0]].x==0)weapons.velocity[player[i].weaponids[0]].x=.1;
  10371.                                                 weapons.tipvelocity[player[i].weaponids[0]]=weapons.velocity[player[i].weaponids[0]];
  10372.                                                 weapons.missed[player[i].weaponids[0]]=1;
  10373.                                                 weapons.freetime[player[i].weaponids[0]]=0;
  10374.                                                 weapons.firstfree[player[i].weaponids[0]]=1;
  10375.                                                 weapons.physics[player[i].weaponids[0]]=1;
  10376.                                                 player[i].num_weapons--;
  10377.                                                 if(player[i].num_weapons){
  10378.                                                     player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
  10379.                                                     if(player[i].weaponstuck==player[i].num_weapons)player[i].weaponstuck=0;
  10380.                                                 }
  10381.  
  10382.                                                 player[i].weaponactive=-1;
  10383.                                                 for(j=0;j<numplayers;j++){
  10384.                                                     player[j].wentforweapon=0;
  10385.                                                 }
  10386.                                             }
  10387.                                         }
  10388.  
  10389.                                     }
  10390.  
  10391.                                     if(i==0||!player[0].dead||player[i].weaponactive!=-1)
  10392.                                         if((player[i].drawkeydown&&!player[i].drawtogglekeydown)||(player[i].num_weapons==2&&player[i].weaponactive==-1&&player[i].isIdle())||(player[0].dead&&player[i].weaponactive!=-1&&i!=0)){
  10393.                                             //Setenvironment(1-environment);
  10394.                                             bool isgood;
  10395.                                             isgood=1;
  10396.                                             if(player[i].weaponactive!=-1){
  10397.                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==staff)isgood=0;
  10398.                                             }
  10399.                                             if(/*(player[i].weaponactive==-1||player[i].num_weapons==1)&&*/isgood&&player[i].creature!=wolftype){
  10400.                                                 if(player[i].isIdle()&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==knife){
  10401.                                                     player[i].targetanimation=drawrightanim;
  10402.                                                     player[i].targetframe=0;
  10403.                                                     player[i].target=0;
  10404.                                                     player[i].drawtogglekeydown=1;
  10405.                                                 }
  10406.                                                 if((player[i].isIdle()||(player[i].aitype!=playercontrolled&&player[0].weaponactive!=-1&&player[i].isRun()))&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==sword){
  10407.                                                     player[i].targetanimation=drawleftanim;
  10408.                                                     player[i].targetframe=0;
  10409.                                                     player[i].target=0;
  10410.                                                     player[i].drawtogglekeydown=1;
  10411.                                                 }
  10412.                                                 if(player[i].isCrouch()&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==knife){
  10413.                                                     player[i].targetanimation=crouchdrawrightanim;
  10414.                                                     player[i].targetframe=0;
  10415.                                                     player[i].target=0;
  10416.                                                     player[i].drawtogglekeydown=1;
  10417.                                                 }
  10418.                                             }            
  10419.                                         }
  10420.                                         if(player[i].isCrouch()&&weapons.bloody[player[i].weaponids[player[i].weaponactive]]&&bloodtoggle&&player[i].onterrain&&player[i].num_weapons&&player[i].weaponactive!=-1&&player[i].attackkeydown){
  10421.                                             if(weapons.bloody[player[i].weaponids[player[i].weaponactive]]&&player[i].onterrain&&bloodtoggle&&musictype!=stream_music2){
  10422.                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==knife)player[i].targetanimation=crouchstabanim;
  10423.                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==sword)player[i].targetanimation=swordgroundstabanim;
  10424.                                                 player[i].targetframe=0;
  10425.                                                 player[i].target=0;
  10426.                                                 player[i].hasvictim=0;
  10427.                                                 //player[i].attacktogglekeydown=1;
  10428.                                             }
  10429.                                         }
  10430.  
  10431.                                         if(!player[i].drawkeydown){
  10432.                                             player[i].drawtogglekeydown=0;
  10433.                                         }
  10434.  
  10435.                                         if(i==0){
  10436.                                             absflatfacing=0;
  10437.                                             absflatfacing.z=-1;
  10438.  
  10439.                                             absflatfacing=DoRotation(absflatfacing,0,-rotation,0);
  10440.                                         }
  10441.                                         else absflatfacing=flatfacing;
  10442.  
  10443.                                         if(indialogue!=-1){
  10444.                                             player[i].forwardkeydown=0;
  10445.                                             player[i].leftkeydown=0;
  10446.                                             player[i].backkeydown=0;
  10447.                                             player[i].rightkeydown=0;
  10448.                                             player[i].jumpkeydown=0;
  10449.                                             player[i].crouchkeydown=0;
  10450.                                             player[i].drawkeydown=0;
  10451.                                             player[i].throwkeydown=0;
  10452.                                         }
  10453.                                         movekey=0;
  10454.                                         //Do controls
  10455.                                         if(!animation[player[i].targetanimation].attack&&player[i].targetanimation!=staggerbackhighanim&&player[i].targetanimation!=staggerbackhardanim&&player[i].targetanimation!=backhandspringanim&&player[i].targetanimation!=dodgebackanim){
  10456.                                             if(!player[i].forwardkeydown){
  10457.                                                 player[i].forwardstogglekeydown=0;
  10458.                                             }
  10459.                                             if(player[i].crouchkeydown){
  10460.                                                 //Crouch
  10461.                                                 target=-2;
  10462.                                                 if(i==0){
  10463.                                                     player[i].superruntoggle=1;
  10464.                                                     if(numplayers>1)
  10465.                                                         for(j=0;j<numplayers;j++){
  10466.                                                             if(j!=i&&!player[j].skeleton.free&&player[j].aitype==passivetype){
  10467.                                                                 if(findDistancefast(&player[j].coords,&player[i].coords)<16){
  10468.                                                                     player[i].superruntoggle=0;
  10469.                                                                 }
  10470.                                                             }
  10471.                                                         }
  10472.                                                 }
  10473.  
  10474.                                                 if(numplayers>1)
  10475.                                                     for(j=0;j<numplayers;j++){
  10476.                                                         if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].lowreversaldelay<=0){
  10477.                                                             if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&player[j].victim==&player[i]&&(player[j].targetanimation==sweepanim||player[j].targetanimation==upunchanim||player[j].targetanimation==wolfslapanim||((player[j].targetanimation==swordslashanim||player[j].targetanimation==knifeslashstartanim||player[j].targetanimation==staffhitanim||player[j].targetanimation==staffspinhitanim)&&findDistancefast(&player[j].coords,&player[i].coords)<2))){
  10478.                                                                 if(target>=0)target=-1;
  10479.                                                                 else target=j;
  10480.                                                             }
  10481.                                                         }
  10482.                                                     }
  10483.                                                     if(target>=0)player[target].Reverse();
  10484.                                                     player[i].lowreversaldelay=.5;
  10485.  
  10486.                                                     if(player[i].isIdle()){
  10487.                                                         player[i].targetanimation=player[i].getCrouch();
  10488.                                                         player[i].target=0;
  10489.                                                         player[i].targetframe=0;
  10490.                                                         player[i].transspeed=10;
  10491.                                                     }
  10492.                                                     if(player[i].isRun()||(player[i].isStop()&&(player[i].leftkeydown||player[i].rightkeydown||player[i].forwardkeydown||player[i].backkeydown))){
  10493.                                                         player[i].targetanimation=rollanim;
  10494.                                                         player[i].target=0;
  10495.                                                         player[i].targetframe=0;
  10496.                                                         player[i].transspeed=20;
  10497.                                                     }
  10498.                                             }
  10499.                                             if(!player[i].crouchkeydown){
  10500.                                                 //Uncrouch
  10501.                                                 if(!player[i].isRun()&&player[i].targetanimation!=sneakanim&&i==0)player[i].superruntoggle=0;
  10502.                                                 target=-2;
  10503.                                                 if(player[i].isCrouch()){
  10504.                                                     if(numplayers>1)
  10505.                                                         for(j=0;j<numplayers;j++){
  10506.                                                             if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].highreversaldelay<=0){
  10507.                                                                 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&player[j].victim==&player[i]&&(player[j].targetanimation==spinkickanim)&&player[i].isCrouch()){
  10508.                                                                     if(target>=0)target=-1;
  10509.                                                                     else target=j;
  10510.                                                                 }
  10511.                                                             }
  10512.                                                         }
  10513.                                                         if(target>=0)player[target].Reverse();
  10514.                                                         player[i].highreversaldelay=.5;
  10515.  
  10516.                                                         if(player[i].isCrouch()){                      
  10517.                                                             if(!player[i].wasCrouch()){
  10518.                                                                 player[i].currentanimation=player[i].getCrouch();
  10519.                                                                 player[i].currentframe=0;
  10520.                                                             }
  10521.                                                             player[i].target=0;
  10522.                                                             player[i].targetanimation=player[i].getIdle();
  10523.                                                             player[i].targetframe=0;
  10524.                                                             player[i].transspeed=10;
  10525.                                                         }
  10526.                                                 }
  10527.                                                 if(player[i].targetanimation==sneakanim){
  10528.                                                     player[i].targetanimation=player[i].getIdle();
  10529.                                                     player[i].target=0;
  10530.                                                     player[i].targetframe=0;
  10531.                                                     player[i].transspeed=10;
  10532.                                                 }
  10533.                                             }
  10534.                                             if(player[i].forwardkeydown){
  10535.                                                 if(player[i].isIdle()||(player[i].isStop()&&player[i].targetrotation==player[i].rotation)||(player[i].isLanding()&&player[i].targetframe>0&&!player[i].jumpkeydown)||(player[i].isLandhard()&&player[i].targetframe>0&&!player[i].jumpkeydown&&player[i].crouchkeydown)){
  10536.                                                     if(player[i].aitype==passivetype)player[i].targetanimation=walkanim;
  10537.                                                     else player[i].targetanimation=player[i].getRun();
  10538.                                                     player[i].target=0;
  10539.                                                     player[i].targetframe=0;
  10540.                                                 }
  10541.                                                 if(player[i].isCrouch()){
  10542.                                                     player[i].targetanimation=sneakanim;
  10543.                                                     if(player[i].wasCrouch())player[i].target=0;
  10544.                                                     player[i].targetframe=0;
  10545.                                                 }
  10546.                                                 if(player[i].targetanimation==hanganim/*&&(!player[i].forwardstogglekeydown||player[i].aitype!=playercontrolled)*/){
  10547.                                                     player[i].targetanimation=climbanim;
  10548.                                                     player[i].target=0;
  10549.                                                     player[i].targetframe=1;
  10550.                                                     player[i].jumpclimb=1;
  10551.                                                 }
  10552.                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
  10553.                                                     player[i].velocity+=absflatfacing*5*multiplier;
  10554.                                                 }
  10555.                                                 player[i].forwardstogglekeydown=1;
  10556.                                                 movekey=1;
  10557.                                             }
  10558.                                             if (player[i].rightkeydown){
  10559.                                                 if(player[i].isIdle()||(player[i].isStop()&&player[i].targetrotation==player[i].rotation)||(player[i].isLanding()&&player[i].targetframe>0&&!player[i].jumpkeydown)||(player[i].isLandhard()&&player[i].targetframe>0&&!player[i].jumpkeydown&&player[i].crouchkeydown)){
  10560.                                                     player[i].targetanimation=player[i].getRun();
  10561.                                                     player[i].target=0;
  10562.                                                     player[i].targetframe=0;
  10563.                                                 }
  10564.                                                 if(player[i].isCrouch()){
  10565.                                                     player[i].targetanimation=sneakanim;
  10566.                                                     if(player[i].wasCrouch()) player[i].target=0;
  10567.                                                     player[i].targetframe=0;
  10568.                                                 }
  10569.                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
  10570.                                                     player[i].velocity+=DoRotation(absflatfacing*5*multiplier,0,-90,0);
  10571.                                                 }
  10572.                                                 player[i].targetrotation-=90;
  10573.                                                 if(player[i].forwardkeydown)player[i].targetrotation+=45;
  10574.                                                 if(player[i].backkeydown)player[i].targetrotation-=45;
  10575.                                                 movekey=1;
  10576.                                             }
  10577.                                             if ( player[i].leftkeydown){
  10578.                                                 if(player[i].isIdle()||(player[i].isStop()&&player[i].targetrotation==player[i].rotation)||(player[i].isLanding()&&player[i].targetframe>0&&!player[i].jumpkeydown)||(player[i].isLandhard()&&player[i].targetframe>0&&!player[i].jumpkeydown&&player[i].crouchkeydown)){
  10579.                                                     player[i].targetanimation=player[i].getRun();
  10580.                                                     player[i].target=0;
  10581.                                                     player[i].targetframe=0;
  10582.                                                 }
  10583.                                                 if(player[i].isCrouch()){
  10584.                                                     player[i].targetanimation=sneakanim;
  10585.                                                     if(player[i].wasCrouch())player[i].target=0;
  10586.                                                     player[i].targetframe=0;
  10587.                                                 }
  10588.                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
  10589.                                                     player[i].velocity-=DoRotation(absflatfacing*5*multiplier,0,-90,0);
  10590.                                                 }
  10591.                                                 player[i].targetrotation+=90;
  10592.                                                 if(player[i].forwardkeydown)player[i].targetrotation-=45;
  10593.                                                 if(player[i].backkeydown)player[i].targetrotation+=45;
  10594.                                                 movekey=1;
  10595.                                             }
  10596.                                             if(player[i].backkeydown){
  10597.                                                 if(player[i].isIdle()||(player[i].isStop()&&player[i].targetrotation==player[i].rotation)||(player[i].isLanding()&&player[i].targetframe>0&&!player[i].jumpkeydown)||(player[i].isLandhard()&&player[i].targetframe>0&&!player[i].jumpkeydown&&player[i].crouchkeydown)){
  10598.                                                     player[i].targetanimation=player[i].getRun();
  10599.                                                     player[i].target=0;
  10600.                                                     player[i].targetframe=0;
  10601.                                                 }
  10602.                                                 if(player[i].isCrouch()){
  10603.                                                     player[i].targetanimation=sneakanim;
  10604.                                                     if(player[i].wasCrouch())player[i].target=0;
  10605.                                                     player[i].targetframe=0;
  10606.                                                 }
  10607.                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
  10608.                                                     player[i].velocity-=absflatfacing*5*multiplier;
  10609.                                                 }
  10610.                                                 if(player[i].targetanimation==hanganim){
  10611.                                                     player[i].currentanimation=jumpdownanim;
  10612.                                                     player[i].targetanimation=jumpdownanim;
  10613.                                                     player[i].target=0;
  10614.                                                     player[i].currentframe=0;
  10615.                                                     player[i].targetframe=1;
  10616.                                                     player[i].velocity=0;
  10617.                                                     player[i].velocity.y+=gravity;
  10618.                                                     player[i].coords.y-=1.4;
  10619.                                                     player[i].grabdelay=1;
  10620.                                                 }
  10621.                                                 if ( !player[i].leftkeydown&&!player[i].rightkeydown)
  10622.                                                     player[i].targetrotation+=180;
  10623.                                                 movekey=1;
  10624.                                             }
  10625.                                             if((player[i].jumpkeydown&&!player[i].jumpclimb)||player[i].jumpstart){
  10626.                                                 if((((player[i].isLanding()&&player[i].targetframe>=3)||player[i].isRun()||player[i].targetanimation==walkanim||player[i].isCrouch()||player[i].targetanimation==sneakanim)&&player[i].jumppower>1)&&((player[i].targetanimation!=rabbitrunninganim&&player[i].targetanimation!=wolfrunninganim)||i!=0)){
  10627.                                                     player[i].jumpstart=0;
  10628.                                                     player[i].targetanimation=jumpupanim;
  10629.                                                     player[i].target=0;
  10630.                                                     player[i].targetframe=0;
  10631.                                                     player[i].rotation=player[i].targetrotation;
  10632.                                                     player[i].transspeed=20;
  10633.                                                     player[i].FootLand(0,1);
  10634.                                                     player[i].FootLand(1,1);
  10635.  
  10636.                                                     facing=0;
  10637.                                                     facing.z=-1;
  10638.                                                     flatfacing=DoRotation(facing,0,player[i].targetrotation+180,0);
  10639.  
  10640.                                                     if(movekey)player[i].velocity=flatfacing*player[i].speed*45*player[i].scale;
  10641.                                                     if(!movekey)player[i].velocity=0;
  10642.  
  10643.                                                     //Dodge sweep?
  10644.                                                     target=-2;
  10645.                                                     if(numplayers>1)
  10646.                                                         for(j=0;j<numplayers;j++){
  10647.                                                             if(j!=i&&!player[j].skeleton.free&&player[j].victim){
  10648.                                                                 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&player[j].victim==&player[i]&&(player[j].targetanimation==sweepanim)){
  10649.                                                                     if(target>=0)target=-1;
  10650.                                                                     else target=j;
  10651.                                                                 }
  10652.                                                             }
  10653.                                                         }
  10654.                                                         if(target>=0)player[i].velocity.y=1;
  10655.                                                         else if(player[i].crouchkeydown||player[i].aitype!=playercontrolled){
  10656.                                                             player[i].velocity.y=7;
  10657.                                                             player[i].crouchtogglekeydown=1;
  10658.                                                         }
  10659.                                                         else player[i].velocity.y=5;
  10660.  
  10661.                                                         if(mousejump&&i==0&&debugmode){
  10662.                                                             if(!player[i].isLanding())player[i].tempdeltav=deltav;
  10663.                                                             if(player[i].tempdeltav<0)player[i].velocity.y-=(float)(player[i].tempdeltav)/multiplier/1000;
  10664.                                                         }
  10665.  
  10666.                                                         player[i].coords.y+=.2;
  10667.                                                         player[i].jumppower-=1;
  10668.  
  10669.                                                         static float gLoc[3];
  10670.                                                         static float vel[3];
  10671.                                                         gLoc[0]=player[i].coords.x;
  10672.                                                         gLoc[1]=player[i].coords.y;
  10673.                                                         gLoc[2]=player[i].coords.z;
  10674.                                                         vel[0]=player[i].velocity.x;
  10675.                                                         vel[1]=player[i].velocity.y;
  10676.                                                         vel[2]=player[i].velocity.z;
  10677.  
  10678.                                                         if(i==0){
  10679.                                                             PlaySoundEx( whooshsound, samp[whooshsound], NULL, TRUE);
  10680.                                                             FSOUND_3D_SetAttributes(channels[whooshsound], gLoc, vel);
  10681.                                                             FSOUND_SetVolume(channels[whooshsound], 128);
  10682.                                                             FSOUND_SetPaused(channels[whooshsound], FALSE);
  10683.                                                         }
  10684.  
  10685.                                                         PlaySoundEx( jumpsound, samp[jumpsound], NULL, TRUE);
  10686.                                                         FSOUND_3D_SetAttributes(channels[jumpsound], gLoc, vel);
  10687.                                                         FSOUND_SetVolume(channels[jumpsound], 128);
  10688.                                                         FSOUND_SetPaused(channels[jumpsound], FALSE);
  10689.                                                 }      
  10690.                                                 if((player[i].isIdle())&&player[i].jumppower>1){
  10691.                                                     player[i].targetanimation=player[i].getLanding();
  10692.                                                     player[i].landhard=0;
  10693.                                                     player[i].target=0;
  10694.                                                     player[i].targetframe=2;
  10695.                                                     player[i].jumpstart=1;
  10696.                                                     player[i].tempdeltav=deltav;
  10697.                                                 }      
  10698.                                                 if(player[i].targetanimation==jumpupanim&&(((!floatjump&&!editorenabled)||!debugmode)||player[i].aitype!=playercontrolled)){
  10699.                                                     if(player[i].jumppower>multiplier*6){
  10700.                                                         player[i].velocity.y+=multiplier*6;
  10701.                                                         player[i].jumppower-=multiplier*6;
  10702.                                                     }
  10703.                                                     if(player[i].jumppower<=multiplier*6){
  10704.                                                         player[i].velocity.y+=player[i].jumppower;
  10705.                                                         player[i].jumppower=0;
  10706.                                                     }
  10707.                                                 }
  10708.                                                 if(((floatjump||editorenabled)&&debugmode)&&i==0)player[i].velocity.y+=multiplier*30;      
  10709.                                             }
  10710.  
  10711.                                             if(!movekey){
  10712.                                                 if(player[i].isRun()||player[i].targetanimation==walkanim){
  10713.                                                     player[i].targetanimation=player[i].getStop();
  10714.                                                     player[i].target=0;
  10715.                                                     player[i].targetframe=0;
  10716.                                                 }
  10717.                                                 if(player[i].targetanimation==sneakanim){
  10718.                                                     player[i].targetanimation=player[i].getCrouch();
  10719.                                                     if(player[i].currentanimation==sneakanim)player[i].target=0;
  10720.                                                     player[i].targetframe=0;
  10721.                                                 }
  10722.                                             }
  10723.                                             if(player[i].targetanimation==walkanim&&(player[i].aitype==attacktypecutoff||player[i].aitype==searchtype||(player[i].aitype==passivetype&&player[i].numwaypoints<=1))){
  10724.                                                 player[i].targetanimation=player[i].getStop();
  10725.                                                 player[i].target=0;
  10726.                                                 player[i].targetframe=0;
  10727.                                             }
  10728.                                             if(player[i].isRun()&&(player[i].aitype==passivetype)){
  10729.                                                 player[i].targetanimation=player[i].getStop();
  10730.                                                 player[i].target=0;
  10731.                                                 player[i].targetframe=0;
  10732.                                             }
  10733.                                         }
  10734.                                 }
  10735.                                 if(player[i].targetanimation==rollanim)player[i].targetrotation=oldtargetrotation;
  10736.                             }
  10737.  
  10738.                             //Rotation
  10739.                             for(k=0;k<numplayers;k++){
  10740.                                 if(abs(player[k].rotation-player[k].targetrotation)>180){
  10741.                                     if(player[k].rotation>player[k].targetrotation)player[k].rotation-=360;
  10742.                                     else player[k].rotation+=360;
  10743.                                 }
  10744.  
  10745.                                 if(abs(player[k].rotation-player[k].targetrotation)>90&&(player[k].isRun()||player[k].targetanimation==walkanim)){
  10746.                                     player[k].targetanimation=player[k].getStop();
  10747.                                     player[k].targetframe=0;
  10748.                                     player[k].target=0;
  10749.                                 }
  10750.  
  10751.                                 if(player[k].targetanimation==backhandspringanim||player[k].targetanimation==dodgebackanim){
  10752.                                     player[k].targettilt=0;
  10753.                                 }
  10754.                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=backhandspringanim&&player[k].targetanimation!=jumpdownanim&&!player[k].isFlip()){
  10755.                                     player[k].targettilt=0;
  10756.                                     if(player[k].jumppower<0&&!player[k].jumpkeydown)player[k].jumppower=0;
  10757.                                     player[k].jumppower+=multiplier*7;
  10758.                                     if(player[k].isCrouch())player[k].jumppower+=multiplier*7;
  10759.                                     //*(1-(player[k].damage/player[k].damagetolerance))
  10760.                                     if(player[k].jumppower>5)player[k].jumppower=5;
  10761.                                 }
  10762.  
  10763.                                 if(player[k].isRun()){
  10764.                                     player[k].targettilt=(player[k].rotation-player[k].targetrotation)/4;
  10765.                                 }
  10766.  
  10767.                                 if(abs(player[k].tilt-player[k].targettilt)<multiplier*150)player[k].tilt=player[k].targettilt;
  10768.                                 else if(player[k].tilt>player[k].targettilt){
  10769.                                     player[k].tilt-=multiplier*150;
  10770.                                 }
  10771.                                 else if(player[k].tilt<player[k].targettilt){
  10772.                                     player[k].tilt+=multiplier*150;
  10773.                                 }
  10774.  
  10775.                                 player[k].grabdelay-=multiplier;
  10776.                             }
  10777.  
  10778.                             for(k=0;k<numplayers;k++){
  10779.                                 player[k].DoAnimations();
  10780.                                 player[k].whichpatchx=player[k].coords.x/(terrain.size/subdivision*terrain.scale*terraindetail);
  10781.                                 player[k].whichpatchz=player[k].coords.z/(terrain.size/subdivision*terrain.scale*terraindetail);
  10782.                             }
  10783.  
  10784.                             objects.DoStuff();
  10785.                             /*
  10786.                             player[0].righthandmorphstart=0;
  10787.                             player[0].righthandmorphend=1;
  10788.                             player[0].lefthandmorphstart=0;
  10789.                             player[0].lefthandmorphend=1;
  10790.                             player[0].headmorphstart=0;
  10791.                             player[0].headmorphend=2;*/
  10792.  
  10793.                             /*
  10794.                             if(IsKeyDown( theKeyMap, MAC_P_KEY )){
  10795.                             if(player[0].righthandmorphend!=1)player[0].righthandmorphness=0;
  10796.                             player[0].righthandmorphend=1;
  10797.                             player[0].targetrighthandmorphness=1;
  10798.  
  10799.                             if(player[0].lefthandmorphend!=0)player[0].lefthandmorphness=0;
  10800.                             player[0].lefthandmorphend=0;
  10801.                             player[0].targetlefthandmorphness=1;
  10802.  
  10803.                             if(player[0].headmorphend!=2)player[0].headmorphness=0;
  10804.                             player[0].headmorphend=2;
  10805.                             player[0].targetheadmorphness=1;
  10806.                             }
  10807.                             if(IsKeyDown( theKeyMap, MAC_L_KEY )){
  10808.                             if(player[0].righthandmorphend!=0)player[0].righthandmorphness=0;
  10809.                             player[0].righthandmorphend=0;
  10810.                             player[0].targetrighthandmorphness=1;
  10811.  
  10812.                             if(player[0].lefthandmorphend!=1)player[0].lefthandmorphness=0;
  10813.                             player[0].lefthandmorphend=1;
  10814.                             player[0].targetlefthandmorphness=1;
  10815.  
  10816.                             if(player[0].headmorphend!=0)player[0].headmorphness=0;
  10817.                             player[0].headmorphend=0;
  10818.                             player[0].targetheadmorphness=1;
  10819.                             }
  10820.                             */
  10821.                             if(numenvsounds!=0)
  10822.                                 for(j=numenvsounds-1;j>=0;j--){
  10823.                                     envsoundlife[j]-=multiplier;
  10824.                                     if(envsoundlife[j]<0){
  10825.                                         numenvsounds--;
  10826.                                         envsoundlife[j]=envsoundlife[numenvsounds];
  10827.                                         envsound[j]=envsound[numenvsounds];
  10828.                                     }
  10829.                                 }
  10830.                                 if(!slomo)FSOUND_SetFrequency(FSOUND_ALL, 22050);
  10831.                                 if(slomo)FSOUND_SetFrequency(FSOUND_ALL, slomofreq);
  10832.  
  10833.                                 if(tutoriallevel==1){
  10834.                                     XYZ temp;
  10835.                                     XYZ temp2;
  10836.                                     XYZ temp3;
  10837.                                     XYZ oldtemp;
  10838.                                     XYZ oldtemp2;
  10839.                                     temp.x=1011;
  10840.                                     temp.y=84;
  10841.                                     temp.z=491;
  10842.                                     temp2.x=1025;
  10843.                                     temp2.y=75;
  10844.                                     temp2.z=447;
  10845.                                     temp3.x=1038;
  10846.                                     temp3.y=76;
  10847.                                     temp3.z=453;
  10848.                                     oldtemp=temp;
  10849.                                     oldtemp2=temp2;
  10850.                                     if(tutorialstage>=51)
  10851.                                         if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
  10852.                                             FSOUND_StopSound(FSOUND_ALL);  // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu...
  10853.                                             FSOUND_SetFrequency(FSOUND_ALL, 0.001);
  10854.  
  10855.                                             PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
  10856.                                             FSOUND_SetPaused(channels[stream_music3], FALSE);
  10857.                                             FSOUND_SetVolume(channels[stream_music3], 256);
  10858.  
  10859.                                             gameon=0;
  10860.                                             mainmenu=5;
  10861.  
  10862.                                             float gLoc[3]={0,0,0};
  10863.                                             float vel[3]={0,0,0};
  10864.                                             FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  10865.                                             PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
  10866.                                             FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  10867.                                             FSOUND_SetVolume(channels[fireendsound], 256);
  10868.                                             FSOUND_SetPaused(channels[fireendsound], FALSE);
  10869.                                             FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  10870.  
  10871.                                             flashr=1;
  10872.                                             flashg=0;
  10873.                                             flashb=0;
  10874.                                             flashamount=1;
  10875.                                             flashdelay=1;
  10876.                                         }
  10877.                                         if(tutorialstage<51)
  10878.                                             if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
  10879.                                                 float gLoc[3];
  10880.                                                 float vel[3];
  10881.                                                 gLoc[0]=player[0].coords.x;
  10882.                                                 gLoc[1]=player[0].coords.y;
  10883.                                                 gLoc[2]=player[0].coords.z;
  10884.                                                 vel[0]=0;
  10885.                                                 vel[1]=0;
  10886.                                                 vel[2]=0;
  10887.                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
  10888.                                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  10889.                                                 FSOUND_SetVolume(channels[fireendsound], 256);
  10890.                                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
  10891.  
  10892.                                                 player[0].coords=(oldtemp+oldtemp2)/2;
  10893.  
  10894.                                                 flashr=1;
  10895.                                                 flashg=1;
  10896.                                                 flashb=1;
  10897.                                                 flashamount=1;
  10898.                                                 flashdelay=1;
  10899.                                             }
  10900.                                             if(tutorialstage>=14&&tutorialstage<50)
  10901.                                                 if(findDistancefast(&temp,&player[1].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[1].coords)<4){
  10902.                                                     float gLoc[3];
  10903.                                                     float vel[3];
  10904.                                                     gLoc[0]=player[1].coords.x;
  10905.                                                     gLoc[1]=player[1].coords.y;
  10906.                                                     gLoc[2]=player[1].coords.z;
  10907.                                                     vel[0]=0;
  10908.                                                     vel[1]=0;
  10909.                                                     vel[2]=0;
  10910.                                                     PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
  10911.                                                     FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  10912.                                                     FSOUND_SetVolume(channels[fireendsound], 256);
  10913.                                                     FSOUND_SetPaused(channels[fireendsound], FALSE);
  10914.  
  10915.                                                     for(int i=0;i<player[1].skeleton.num_joints;i++){
  10916.                                                         if(Random()%2==0){
  10917.                                                             if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
  10918.                                                             if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
  10919.                                                             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;
  10920.                                                             if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
  10921.                                                             sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
  10922.                                                         }
  10923.                                                     }
  10924.  
  10925.                                                     player[1].coords=(oldtemp+oldtemp2)/2;
  10926.                                                     for(int i=0;i<player[1].skeleton.num_joints;i++){
  10927.                                                         player[1].skeleton.joints[i].velocity=0;
  10928.                                                         if(Random()%2==0){
  10929.                                                             if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
  10930.                                                             if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
  10931.                                                             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;
  10932.                                                             if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
  10933.                                                             sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
  10934.                                                         }
  10935.                                                     }
  10936.                                                 }
  10937.                                 }
  10938.  
  10939.  
  10940.                                 //3d sound
  10941.                                 static float gLoc[3];
  10942.                                 gLoc[0]=viewer.x;
  10943.                                 gLoc[1]=viewer.y;
  10944.                                 gLoc[2]=viewer.z;
  10945.                                 static float vel[3];
  10946.                                 vel[0]=(viewer.x-oldviewer.x)/multiplier;
  10947.                                 vel[1]=(viewer.y-oldviewer.y)/multiplier;
  10948.                                 vel[2]=(viewer.z-oldviewer.z)/multiplier;
  10949.  
  10950.                                 //Set orientation with forward and up vectors
  10951.                                 static XYZ upvector;
  10952.                                 upvector=0;
  10953.                                 upvector.z=-1;
  10954.  
  10955.                                 upvector=DoRotation(upvector,-rotation2+90,0,0);
  10956.                                 upvector=DoRotation(upvector,0,0-rotation,0);
  10957.  
  10958.                                 facing=0;
  10959.                                 facing.z=-1;
  10960.                                
  10961.                                 facing=DoRotation(facing,-rotation2,0,0);
  10962.                                 facing=DoRotation(facing,0,0-rotation,0);
  10963.        
  10964.        
  10965.                                 static float ori[6];
  10966.                                 ori[0] = -facing.x;
  10967.                                 ori[1] = facing.y;
  10968.                                 ori[2] = -facing.z;
  10969.                                 ori[3] = -upvector.x;
  10970.                                 ori[4] = upvector.y;
  10971.                                 ori[5] = -upvector.z;
  10972.  
  10973.                                 FSOUND_3D_Listener_SetAttributes(&gLoc[0], &vel[0], ori[0], ori[1], ori[2], ori[3], ori[4], ori[5]);
  10974.                                 FSOUND_Update();
  10975.  
  10976.                                 oldviewer=viewer;
  10977.         }
  10978.     }
  10979.  
  10980.     if(IsKeyDown(theKeyMap, MAC_F1_KEY)&&!freezetogglekeydown){
  10981.         Screenshot();
  10982.         freezetogglekeydown=1;
  10983.     }
  10984. }
  10985.  
  10986. void    Game::TickOnce(){
  10987.     //if(!console){
  10988.     if(!mainmenu)
  10989.         if(directing||indialogue==-1){
  10990.             rotation+=deltah*.7;
  10991.             if(!invertmouse)rotation2+=deltav*.7;
  10992.             if(invertmouse)rotation2-=deltav*.7;
  10993.             if(rotation2>90)rotation2=90;
  10994.             if(rotation2<-70)rotation2=-70;
  10995.         }
  10996.         if(mainmenu)rotation+=multiplier*5;
  10997.         if(!mainmenu&&!indemo&&!registered){
  10998.             FSOUND_SetFrequency(FSOUND_ALL, 0.001);    
  10999.             PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
  11000.             FSOUND_SetPaused(channels[stream_music3], FALSE);
  11001.             FSOUND_SetVolume(channels[stream_music3], 256);
  11002.  
  11003.             gameon=0;
  11004.             mainmenu=12;
  11005.  
  11006.             float gLoc[3]={0,0,0};
  11007.             float vel[3]={0,0,0};
  11008.             FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  11009.             PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
  11010.             FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  11011.             FSOUND_SetVolume(channels[fireendsound], 256);
  11012.             FSOUND_SetPaused(channels[fireendsound], FALSE);
  11013.             FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  11014.  
  11015.             flashr=1;
  11016.             flashg=0;
  11017.             flashb=0;
  11018.             flashamount=1;
  11019.             flashdelay=1;
  11020.         }
  11021.  
  11022.         if(tryquit==1&&!registered&&mainmenu!=12){
  11023.             FSOUND_SetFrequency(FSOUND_ALL, 0.001);    
  11024.             PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
  11025.             FSOUND_SetPaused(channels[stream_music3], FALSE);
  11026.             FSOUND_SetVolume(channels[stream_music3], 256);
  11027.  
  11028.             gameon=0;
  11029.             mainmenu=12;
  11030.  
  11031.             float gLoc[3]={0,0,0};
  11032.             float vel[3]={0,0,0};
  11033.             FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  11034.             PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
  11035.             FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  11036.             FSOUND_SetVolume(channels[fireendsound], 256);
  11037.             FSOUND_SetPaused(channels[fireendsound], FALSE);
  11038.             FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  11039.  
  11040.             flashr=1;
  11041.             flashg=0;
  11042.             flashb=0;
  11043.             flashamount=1;
  11044.             flashdelay=1;
  11045.         }
  11046.         //}
  11047. }
  11048.  
  11049. void    Game::TickOnceAfter(){
  11050.     static XYZ colviewer;
  11051.     static XYZ coltarget;
  11052.     static XYZ target;
  11053.     static XYZ col;
  11054.     static float brotate;
  11055.     static XYZ facing;
  11056.     static int i,j;
  11057.     static float changedelay;
  11058.     static bool alldead;
  11059.     static float unseendelay;
  11060.     static float cameraspeed;
  11061.  
  11062.     if(!mainmenu){
  11063.  
  11064.         if(environment==snowyenvironment)music1=stream_music1snow;
  11065.         if(environment==grassyenvironment)music1=stream_music1grass;
  11066.         if(environment==desertenvironment)music1=stream_music1desert;
  11067.  
  11068.         realthreat=0;
  11069.  
  11070.         musictype=music1;
  11071.         for(i=0;i<numplayers;i++){
  11072.             if((player[i].aitype==attacktypecutoff||player[i].aitype==getweapontype||player[i].aitype==gethelptype||player[i].aitype==searchtype)&&!player[i].dead/*&&player[i].surprised<=0*/&&(player[i].targetanimation!=sneakattackedanim&&player[i].targetanimation!=knifesneakattackedanim&&player[i].targetanimation!=swordsneakattackedanim)){
  11073.                 musictype=stream_music2;
  11074.                 realthreat=1;
  11075.             }
  11076.         }
  11077.         if(player[0].dead)musictype=stream_music3;
  11078.  
  11079.  
  11080.         if(musictype==stream_music2){
  11081.             unseendelay=1;
  11082.         }
  11083.  
  11084.         if(oldmusictype==stream_music2&&musictype!=stream_music2){
  11085.             unseendelay-=multiplier;
  11086.             if(unseendelay>0){
  11087.                 musictype=stream_music2;
  11088.             }
  11089.         }
  11090.  
  11091.  
  11092.         if(loading==2){
  11093.             musictype=stream_music3;
  11094.             musicvolume[2]=512;
  11095.             musicvolume[0]=0;
  11096.             musicvolume[1]=0;
  11097.             musicvolume[3]=0;
  11098.         }  
  11099.  
  11100.         if(musictoggle){           
  11101.             if(musictype!=oldmusictype&&musictype==stream_music2){
  11102.                 static float gLoc[3];
  11103.                 static float vel[3];
  11104.                 gLoc[0]=cameraloc.x;
  11105.                 gLoc[1]=cameraloc.y;
  11106.                 gLoc[2]=cameraloc.z;
  11107.                 vel[0]=0;
  11108.                 vel[1]=0;
  11109.                 vel[2]=0;
  11110.                 PlaySoundEx( alarmsound, samp[alarmsound], NULL, TRUE);
  11111.                 FSOUND_SetVolume(channels[alarmsound], 512);
  11112.                 FSOUND_SetPaused(channels[alarmsound], FALSE);
  11113.  
  11114.             }
  11115.         }
  11116.         musicselected=musictype;
  11117.  
  11118.         if(musicselected==music1)musicvolume[0]+=multiplier*450;
  11119.         else musicvolume[0]-=multiplier*450;
  11120.         if(musicselected==stream_music2)musicvolume[1]+=multiplier*450;
  11121.         else musicvolume[1]-=multiplier*450;
  11122.         if(musicselected==stream_music3)musicvolume[2]+=multiplier*450;
  11123.         else musicvolume[2]-=multiplier*450;
  11124.         /*
  11125.         if(musicselected==music1)musicvolume[0]+=multiplier*100;
  11126.         else musicvolume[0]-=multiplier*450;
  11127.         if(musicselected==music2)musicvolume[1]+=multiplier*150;
  11128.         else if(player[0].dead)musicvolume[1]-=multiplier*450;
  11129.         else musicvolume[1]-=multiplier*100;
  11130.         if(musicselected==music3)musicvolume[2]+=multiplier*450;
  11131.         else musicvolume[2]-=multiplier*450;*/
  11132.  
  11133.         for(i=0;i<3;i++){
  11134.             if(musicvolume[i]<0)musicvolume[i]=0;
  11135.             if(musicvolume[i]>512)musicvolume[i]=512;
  11136.         }
  11137.  
  11138.         if(musicvolume[2]>128&&!loading&&!mainmenu)musicvolume[2]=128;
  11139.  
  11140.         if(musictoggle){       
  11141.             if(musicvolume[0]>0&&oldmusicvolume[0]<=0){
  11142.                 PlayStreamEx( music1, strm[music1], NULL, TRUE);
  11143.                 FSOUND_SetPaused(channels[music1], FALSE);
  11144.             }
  11145.             if(musicvolume[1]>0&&oldmusicvolume[1]<=0){
  11146.                 PlayStreamEx( stream_music2, strm[stream_music2], NULL, TRUE);
  11147.                 FSOUND_SetPaused(channels[stream_music2], FALSE);
  11148.             }
  11149.             if(musicvolume[2]>0&&oldmusicvolume[2]<=0){
  11150.                 PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
  11151.                 FSOUND_SetPaused(channels[stream_music3], FALSE);
  11152.             }
  11153.         }
  11154.  
  11155.         if(!musictoggle){      
  11156.             FSOUND_SetPaused(channels[music1], TRUE);
  11157.             FSOUND_SetPaused(channels[stream_music2], TRUE);
  11158.             FSOUND_SetPaused(channels[stream_music3], TRUE);
  11159.  
  11160.             for(i=0;i<4;i++){
  11161.                 oldmusicvolume[i]=0;
  11162.                 musicvolume[i]=0;
  11163.             }
  11164.         }
  11165.  
  11166.         if(musictoggle){       
  11167.             if(musicvolume[0]<=0&&oldmusicvolume[0]>0){
  11168.                 FSOUND_SetPaused(channels[music1], TRUE);
  11169.             }
  11170.             if(musicvolume[1]<=0&&oldmusicvolume[1]>0){
  11171.                 FSOUND_SetPaused(channels[stream_music2], TRUE);
  11172.             }
  11173.             if(musicvolume[2]<=0&&oldmusicvolume[2]>0){
  11174.                 FSOUND_SetPaused(channels[stream_music3], TRUE);
  11175.             }
  11176.  
  11177.             if(musicvolume[0]!=oldmusicvolume[0]){
  11178.                 FSOUND_SetVolume(channels[music1], musicvolume[0]);
  11179.             }
  11180.             if(musicvolume[1]!=oldmusicvolume[1]){
  11181.                 FSOUND_SetVolume(channels[stream_music2], musicvolume[1]);
  11182.             }
  11183.             if(musicvolume[2]!=oldmusicvolume[2]){
  11184.                 FSOUND_SetVolume(channels[stream_music3], musicvolume[2]);
  11185.             }
  11186.  
  11187.             for(i=0;i<3;i++){
  11188.                 oldmusicvolume[i]=musicvolume[i];
  11189.             }
  11190.         }
  11191.  
  11192.         killhotspot=2;
  11193.         if(numhotspots)
  11194.             for(i=0;i<numhotspots;i++){
  11195.                 if(hotspottype[i]>10&&hotspottype[i]<20){
  11196.                     if(player[hotspottype[i]-10].dead==0){
  11197.                         killhotspot=0;
  11198.                     }
  11199.                     else if(killhotspot==2)
  11200.                         killhotspot=1;
  11201.                 }
  11202.             }
  11203.             if(killhotspot==2)killhotspot=0;
  11204.  
  11205.  
  11206.             winhotspot=0;
  11207.             if(numhotspots)
  11208.                 for(i=0;i<numhotspots;i++){
  11209.                     if(hotspottype[i]==-1){
  11210.                         if(findDistancefast(&player[0].coords,&hotspot[i])<hotspotsize[i])
  11211.                             winhotspot=1;
  11212.                     }
  11213.                 }
  11214.  
  11215.                 int numalarmed=0;
  11216.                 if(numplayers>1)
  11217.                     for(i=1;i<numplayers;i++){     
  11218.                         if(!player[i].dead&&player[i].aitype==attacktypecutoff&&player[i].surprised<=0)numalarmed++;
  11219.                     }
  11220.                     if(numalarmed>maxalarmed)maxalarmed=numalarmed;
  11221.  
  11222.                     if(changedelay<=0&&!loading&&!editorenabled&&gameon&&!tutoriallevel&&changedelay!=-999&&!won){     
  11223.                         if(player[0].dead&&changedelay<=0){
  11224.                             changedelay=1;
  11225.                             targetlevel=whichlevel;
  11226.                         }
  11227.                         alldead=1;
  11228.                         if(numplayers>1)
  11229.                             for(i=1;i<numplayers;i++){     
  11230.                                 if(!player[i].dead&&player[i].howactive<typedead1)alldead=0;
  11231.                             }
  11232.  
  11233.  
  11234.                             if(alldead&&!player[0].dead&&maptype==mapkilleveryone){
  11235.                                 changedelay=1;
  11236.                                 targetlevel=whichlevel+1;
  11237.                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
  11238.                             }
  11239.                             if(winhotspot||windialogue){
  11240.                                 changedelay=0.1;
  11241.                                 targetlevel=whichlevel+1;
  11242.                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
  11243.                             }
  11244.  
  11245.  
  11246.                             if(killhotspot){
  11247.                                 changedelay=1;
  11248.                                 targetlevel=whichlevel+1;
  11249.                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
  11250.                             }
  11251.  
  11252.                             if(changedelay>0&&!player[0].dead&&!won){
  11253.                                 //high scores, awards, win
  11254.                                 if(campaign){
  11255.                                     won=1;
  11256.                                     accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
  11257.                                     accountcampaignchoicesmade[accountactive]++;
  11258.                                     accountcampaignscore[accountactive]+=bonustotal;
  11259.                                     scoreadded=1;
  11260.                                     accountcampaigntime[accountactive]+=leveltime;
  11261.                                     if(accountcampaignscore[accountactive]>accountcampaignhighscore[accountactive])accountcampaignhighscore[accountactive]=accountcampaignscore[accountactive];
  11262.  
  11263.                                     //if(accountprogress[accountactive]<whichlevel+1)accountprogress[accountactive]=whichlevel+1;
  11264.                                 }
  11265.                                 else
  11266.                                 {
  11267.                                     won=1;
  11268.                                     if(!debugmode){
  11269.                                         if(bonustotal-startbonustotal>accounthighscore[accountactive][whichlevel])accounthighscore[accountactive][whichlevel]=bonustotal-startbonustotal;
  11270.                                         if(accountfasttime[accountactive][whichlevel]==0||leveltime<accountfasttime[accountactive][whichlevel])accountfasttime[accountactive][whichlevel]=leveltime;       
  11271.                                     }
  11272.                                     if(accountprogress[accountactive]<whichlevel+1)accountprogress[accountactive]=whichlevel+1;
  11273.  
  11274.                                 }
  11275.                             }
  11276.                     }
  11277.  
  11278.                     if(!winfreeze){
  11279.  
  11280.                         if(leveltime<1){
  11281.                             loading=0;
  11282.                             changedelay=.1;
  11283.                             alldead=0;
  11284.                             winhotspot=0;
  11285.                             killhotspot=0;
  11286.                         }
  11287.  
  11288.                         if(!editorenabled&&gameon&&!mainmenu){
  11289.                             if(changedelay!=-999)changedelay-=multiplier/7;
  11290.                             if(player[0].dead)targetlevel=whichlevel;
  11291.                             if(loading==2&&!campaign){
  11292.                                 flashr=1;
  11293.                                 flashg=0;
  11294.                                 flashb=0;
  11295.                                 flashamount=1;
  11296.                                 flashdelay=1;
  11297.                                 loadtime=0;
  11298.  
  11299.                                 float gLoc[3]={0,0,0};
  11300.                                 float vel[3]={0,0,0};
  11301.                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);  
  11302.                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
  11303.                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  11304.                                 FSOUND_SetVolume(channels[firestartsound], 256);
  11305.                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
  11306.                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);  
  11307.  
  11308.                                 if(!player[0].dead&&targetlevel!=whichlevel){
  11309.                                     startbonustotal=bonustotal;
  11310.                                 }
  11311.                                 if(!player[0].dead)Loadlevel(targetlevel);
  11312.                                 if(player[0].dead)Loadlevel(whichlevel);
  11313.  
  11314.                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  11315.                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
  11316.                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  11317.                                 FSOUND_SetVolume(channels[fireendsound], 256);
  11318.                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
  11319.                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  11320.  
  11321.                                 loading=3;
  11322.                             }
  11323.                             if(loading==2&&targetlevel==whichlevel){
  11324.                                 flashr=1;
  11325.                                 flashg=0;
  11326.                                 flashb=0;
  11327.                                 flashamount=1;
  11328.                                 flashdelay=1;
  11329.                                 loadtime=0;
  11330.  
  11331.                                 float gLoc[3]={0,0,0};
  11332.                                 float vel[3]={0,0,0};
  11333.                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);  
  11334.                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
  11335.                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  11336.                                 FSOUND_SetVolume(channels[firestartsound], 256);
  11337.                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
  11338.                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);  
  11339.  
  11340.                                 for(i=0;i<255;i++){
  11341.                                     mapname[i]='\0';
  11342.                                 }
  11343.                                 mapname[0]=':';
  11344.                                 mapname[1]='D';
  11345.                                 mapname[2]='a';
  11346.                                 mapname[3]='t';
  11347.                                 mapname[4]='a';
  11348.                                 mapname[5]=':';
  11349.                                 mapname[6]='M';
  11350.                                 mapname[7]='a';
  11351.                                 mapname[8]='p';
  11352.                                 mapname[9]='s';
  11353.                                 mapname[10]=':';
  11354.                                 strcat(mapname,campaignmapname[levelorder[accountcampaignchoicesmade[accountactive]]]);//[campaignchoicewhich[whichchoice]]);
  11355.                                 Loadlevel(mapname);
  11356.  
  11357.                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  11358.                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
  11359.                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  11360.                                 FSOUND_SetVolume(channels[fireendsound], 256);
  11361.                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
  11362.                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  11363.  
  11364.                                 loading=3;
  11365.                             }
  11366.                             if(changedelay<=-999&&whichlevel!=-2&&!loading&&(player[0].dead||(alldead&&maptype==mapkilleveryone)||(winhotspot)||(killhotspot))&&!winfreeze)loading=1;
  11367.                             if((player[0].dead||(alldead&&maptype==mapkilleveryone)||(winhotspot)||(windialogue)||(killhotspot))&&changedelay<=0){
  11368.                                 if(accountprogress[accountactive]>3&&!registered){
  11369.                                     FSOUND_SetFrequency(FSOUND_ALL, 0.001);    
  11370.                                     PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
  11371.                                     FSOUND_SetPaused(channels[stream_music3], FALSE);
  11372.                                     FSOUND_SetVolume(channels[stream_music3], 256);
  11373.  
  11374.                                     gameon=0;
  11375.                                     mainmenu=12;
  11376.                                     accountprogress[accountactive]=3;
  11377.  
  11378.                                     float gLoc[3]={0,0,0};
  11379.                                     float vel[3]={0,0,0};
  11380.                                     FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
  11381.                                     PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
  11382.                                     FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
  11383.                                     FSOUND_SetVolume(channels[fireendsound], 256);
  11384.                                     FSOUND_SetPaused(channels[fireendsound], FALSE);
  11385.                                     FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
  11386.  
  11387.                                     flashr=1;
  11388.                                     flashg=0;
  11389.                                     flashb=0;
  11390.                                     flashamount=1;
  11391.                                     flashdelay=1;
  11392.                                 }
  11393.                                 else{
  11394.                                     if(whichlevel!=-2&&!loading&&!player[0].dead){
  11395.                                         winfreeze=1;
  11396.                                         changedelay=-999;
  11397.                                     }
  11398.                                     if(player[0].dead)loading=1;
  11399.                                 }
  11400.                             }
  11401.                         }
  11402.  
  11403.                         if(campaign)
  11404.                             if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1){
  11405.                                 if(campaignnumnext[campaignchoicewhich[whichchoice]]==0){
  11406.                                     endgame=1;
  11407.                                 }
  11408.                             }
  11409.                             else if(mainmenu==0&&winfreeze){
  11410.                                 if(campaignchoosenext[campaignchoicewhich[whichchoice]]==2)
  11411.                                     stealthloading=1;
  11412.                                 else stealthloading=0;
  11413.  
  11414.                                 if(!stealthloading){
  11415.                                     float gLoc[3]={0,0,0};
  11416.                                     float vel[3]={0,0,0};
  11417.                                     FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);  
  11418.                                     PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
  11419.                                     FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
  11420.                                     FSOUND_SetVolume(channels[firestartsound], 256);
  11421.                                     FSOUND_SetPaused(channels[firestartsound], FALSE);
  11422.                                     FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);  
  11423.  
  11424.                                     flashr=1;
  11425.                                     flashg=0;
  11426.                                     flashb=0;
  11427.                                     flashamount=1;
  11428.                                     flashdelay=1;
  11429.                                 }
  11430.  
  11431.                                 startbonustotal=0;
  11432.  
  11433.                                 ifstream ipstream(ConvertFileName(":Data:Campaigns:main.txt"));
  11434.                                 //campaignnumlevels=0;
  11435.                                 //accountcampaignchoicesmade[accountactive]=0;
  11436.                                 ipstream.ignore(256,':');
  11437.                                 ipstream >> campaignnumlevels;
  11438.                                 for(i=0;i<campaignnumlevels;i++){
  11439.                                     ipstream.ignore(256,':');
  11440.                                     ipstream.ignore(256,':');
  11441.                                     ipstream.ignore(256,' ');
  11442.                                     ipstream >> campaignmapname[i];
  11443.                                     ipstream.ignore(256,':');
  11444.                                     ipstream >> campaigndescription[i];
  11445.                                     for(j=0;j<256;j++){
  11446.                                         if(campaigndescription[i][j]=='_')campaigndescription[i][j]=' ';
  11447.                                     }
  11448.                                     ipstream.ignore(256,':');
  11449.                                     ipstream >> campaignchoosenext[i];
  11450.                                     ipstream.ignore(256,':');
  11451.                                     ipstream >> campaignnumnext[i];
  11452.                                     if(campaignnumnext[i])
  11453.                                         for(j=0;j<campaignnumnext[i];j++){
  11454.                                             ipstream.ignore(256,':');
  11455.                                             ipstream >> campaignnextlevel[i][j];
  11456.                                             campaignnextlevel[i][j]-=1;
  11457.                                         }
  11458.                                         ipstream.ignore(256,':');
  11459.                                         ipstream >> campaignlocationx[i];
  11460.                                         ipstream.ignore(256,':');
  11461.                                         ipstream >> campaignlocationy[i];
  11462.                                 }
  11463.                                 ipstream.close();
  11464.  
  11465.                                 for(i=0;i<campaignnumlevels;i++){
  11466.                                     levelvisible[i]=0;
  11467.                                     levelhighlight[i]=0;
  11468.                                 }
  11469.  
  11470.  
  11471.                                 for(i=0;i<campaignnumlevels;i++){
  11472.                                     levelvisible[i]=0;
  11473.                                     levelhighlight[i]=0;
  11474.                                 }
  11475.  
  11476.                                 levelorder[0]=0;
  11477.                                 levelvisible[0]=1;
  11478.                                 if(accountcampaignchoicesmade[accountactive])
  11479.                                     for(i=0;i<accountcampaignchoicesmade[accountactive];i++){
  11480.                                         levelorder[i+1]=campaignnextlevel[levelorder[i]][accountcampaignchoices[accountactive][i]];
  11481.                                         levelvisible[levelorder[i+1]]=1;
  11482.                                     }
  11483.                                     int whichlevelstart;
  11484.                                     whichlevelstart=accountcampaignchoicesmade[accountactive]-1;
  11485.                                     if(whichlevelstart<0){
  11486.                                         campaignchoicenum=1;
  11487.                                         campaignchoicewhich[0]=0;
  11488.                                     }
  11489.                                     else
  11490.                                     {
  11491.                                         campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
  11492.                                         if(campaignchoicenum)
  11493.                                             for(i=0;i<campaignchoicenum;i++){
  11494.                                                 campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
  11495.                                                 levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
  11496.                                                 levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
  11497.                                             }
  11498.                                     }
  11499.  
  11500.                                     loading=2;
  11501.                                     loadtime=0;
  11502.                                     targetlevel=7;
  11503.                                     //if(firstload)TickOnceAfter();
  11504.                                     if(!firstload)LoadStuff();
  11505.                                     //else {
  11506.                                     for(i=0;i<255;i++){
  11507.                                         mapname[i]='\0';
  11508.                                     }
  11509.                                     mapname[0]=':';
  11510.                                     mapname[1]='D';
  11511.                                     mapname[2]='a';
  11512.                                     mapname[3]='t';
  11513.                                     mapname[4]='a';
  11514.                                     mapname[5]=':';
  11515.                                     mapname[6]='M';
  11516.                                     mapname[7]='a';
  11517.                                     mapname[8]='p';
  11518.                                     mapname[9]='s';
  11519.                                     mapname[10]=':';
  11520.  
  11521.                                     //accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
  11522.                                     //accountcampaignchoicesmade[accountactive]++;
  11523.  
  11524.  
  11525.                                     strcat(mapname,campaignmapname[campaignchoicewhich[0]]);
  11526.                                     whichchoice=0;
  11527.                                     visibleloading=1;
  11528.                                     stillloading=1;
  11529.                                     Loadlevel(mapname);
  11530.                                     campaign=1;
  11531.                                     mainmenu=0;
  11532.                                     gameon=1;
  11533.                                     FSOUND_SetPaused(channels[stream_music3], TRUE);
  11534.  
  11535.                                     stealthloading=0;
  11536.                             }
  11537.  
  11538.                             if(loading==3)loading=0;
  11539.  
  11540.                     }
  11541.  
  11542.                     oldmusictype=musictype;
  11543.     }
  11544.  
  11545.     facing=0;
  11546.     facing.z=-1;
  11547.  
  11548.     facing=DoRotation(facing,-rotation2,0,0);
  11549.     facing=DoRotation(facing,0,0-rotation,0);
  11550.     viewerfacing=facing;
  11551.  
  11552.     brotate=0;
  11553.     if(!cameramode){
  11554.         if((animation[player[0].targetanimation].attack!=3&&animation[player[0].currentanimation].attack!=3)||player[0].skeleton.free)target=player[0].coords+player[0].currentoffset*(1-player[0].target)*player[0].scale+player[0].targetoffset*player[0].target*player[0].scale-player[0].facing*.05;
  11555.         else target=player[0].oldcoords+player[0].currentoffset*(1-player[0].target)*player[0].scale+player[0].targetoffset*player[0].target*player[0].scale-player[0].facing*.05;
  11556.         target.y+=.1;
  11557.         if(player[0].skeleton.free){
  11558.             for(i=0;i<player[0].skeleton.num_joints;i++){
  11559.                 if(player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y>target.y)            
  11560.                     target.y=player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y;
  11561.             }
  11562.             target.y+=.1;
  11563.         }
  11564.         if(player[0].skeleton.free!=2&&!autocam){
  11565.             cameraspeed=20;
  11566.             if(findLengthfast(&player[0].velocity)>400){
  11567.                 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
  11568.             }
  11569.             if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
  11570.             coltarget=target-cameraloc;
  11571.             if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
  11572.             else {
  11573.                 Normalise(&coltarget);
  11574.                 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
  11575.                 else cameraloc=cameraloc+coltarget*multiplier*8;
  11576.             }
  11577.             if(editorenabled)cameraloc=target;
  11578.             cameradist+=multiplier*5;
  11579.             if(cameradist>2.3)cameradist=2.3;
  11580.             viewer=cameraloc-facing*cameradist;
  11581.             colviewer=viewer;
  11582.             coltarget=cameraloc;
  11583.             objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
  11584.             if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
  11585.                 for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
  11586.                     i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
  11587.                     colviewer=viewer;
  11588.                     coltarget=cameraloc;
  11589.                     if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;
  11590.                 }
  11591.                 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
  11592.                     for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
  11593.                         i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
  11594.                         colviewer=viewer;
  11595.                         if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
  11596.                             viewer=colviewer;
  11597.                         }
  11598.                     }
  11599.                     cameradist=findDistance(&viewer,&target);
  11600.                     if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.6){
  11601.                         viewer.y=terrain.getHeight(viewer.x,viewer.z)+.6;
  11602.                     }
  11603.                     if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
  11604.                         cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
  11605.                     }
  11606.         }
  11607.         if(player[0].skeleton.free!=2&&autocam){
  11608.             cameraspeed=20;
  11609.             if(findLengthfast(&player[0].velocity)>400){
  11610.                 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
  11611.             }
  11612.             if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
  11613.             cameradist+=multiplier*5;
  11614.             if(cameradist>3.3)cameradist=3.3;
  11615.             coltarget=target-cameraloc;
  11616.             if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
  11617.             else if(findLengthfast(&coltarget)>1)
  11618.             {
  11619.                 Normalise(&coltarget);
  11620.                 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
  11621.                 else cameraloc=cameraloc+coltarget*multiplier*8;
  11622.             }
  11623.             if(editorenabled)cameraloc=target;
  11624.             viewer=cameraloc;
  11625.             colviewer=viewer;
  11626.             coltarget=cameraloc;
  11627.             objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
  11628.             if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
  11629.                 for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
  11630.                     i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
  11631.                     colviewer=viewer;
  11632.                     coltarget=cameraloc;
  11633.                     if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;
  11634.                 }
  11635.                 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
  11636.                     for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
  11637.                         i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
  11638.                         colviewer=viewer;
  11639.                         if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
  11640.                             viewer=colviewer;
  11641.                         }
  11642.                     }
  11643.                     cameradist=findDistance(&viewer,&target);
  11644.                     if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.6){
  11645.                         viewer.y=terrain.getHeight(viewer.x,viewer.z)+.6;
  11646.                     }
  11647.                     if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
  11648.                         cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
  11649.                     }
  11650.         }
  11651.         if(camerashake>.8)camerashake=.8;
  11652.         //if(woozy>10)woozy=10;
  11653.         //woozy+=multiplier;
  11654.         woozy+=multiplier;
  11655.         if(player[0].dead)camerashake=0;
  11656.         if(player[0].dead)woozy=0;
  11657.         camerashake-=multiplier*2;
  11658.         blackout-=multiplier*2;
  11659.         //if(player[0].isCrouch())woozy-=multiplier*8;
  11660.         if(camerashake<0)camerashake=0;
  11661.         if(blackout<0)blackout=0;
  11662.         //if(woozy<0)woozy=0;
  11663.         if(camerashake){
  11664.             viewer.x+=(float)(Random()%100)*.0005*camerashake;
  11665.             viewer.y+=(float)(Random()%100)*.0005*camerashake;
  11666.             viewer.z+=(float)(Random()%100)*.0005*camerashake;
  11667.         }
  11668.     }
  11669. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement