]> git.jsancho.org Git - lugaru.git/blobdiff - Source/GameTick.cpp
major refactor of menu system, part 2
[lugaru.git] / Source / GameTick.cpp
index 181802316c8c6d66aba7c43b2739f463763e68b1..75d13958223f69ed036a538a4f5c7eacceeddbc6 100644 (file)
@@ -35,10 +35,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "Input.h"
 #include "Animation.h"
 #include "Awards.h"
+#include "Menu.h"
 
 #include <algorithm>
 
 using namespace std;
+using namespace Game;
 
 // Added more evilness needed for MSVC
 #ifdef _MSC_VER
@@ -82,6 +84,7 @@ extern XYZ windvector;
 extern bool debugmode;
 static int leveltheme;
 extern int mainmenu;
+extern int oldmainmenu;
 extern bool visibleloading;
 extern XYZ envsound[30];
 extern float envsoundvol[30];
@@ -122,8 +125,6 @@ extern float hostiletime;
 extern bool gamestarted;
 
 extern int numhotspots;
-extern int winhotspot;
-extern int windialogue;
 extern int killhotspot;
 extern XYZ hotspot[40];
 extern int hotspottype[40];
@@ -174,9 +175,9 @@ static const char *cmd_names[] = {
 #undef  DECLARE_COMMAND
 };
 
-typedef void (*console_handler)(Game *game, const char *args);
+typedef void (*console_handler)(const char *args);
 
-#define DECLARE_COMMAND(cmd) static void ch_##cmd(Game *game, const char *args);
+#define DECLARE_COMMAND(cmd) static void ch_##cmd(const char *args);
 #include "ConsoleCmds.h"
 #undef  DECLARE_COMMAND
 
@@ -190,13 +191,6 @@ static console_handler cmd_handlers[] = {
 
 // added utility functions -sf17k =============================================================
 
-//TODO: try to hide these variables completely with a better interface
-inline void setAnimation(int playerid,int animation){
-    player[playerid].targetanimation=animation;
-    player[playerid].targetframe=0;
-    player[playerid].target=0;
-}
-
 //TODO: this is incorrect but I'm afraid to change it and break something,
 //probably causes quirky behavior that I might want to preserve
 inline float roughDirection(XYZ vec){
@@ -219,12 +213,6 @@ inline float pitchTo(XYZ start, XYZ end){
     return pitch(end-start);
 }
 
-//change these to a Person method
-inline Joint& playerJoint(int playerid, int bodypart){
-    return player[playerid].skeleton.joints[player[playerid].skeleton.jointlabels[bodypart]]; }
-inline Joint& playerJoint(Person* pplayer, int bodypart){
-    return pplayer->skeleton.joints[pplayer->skeleton.jointlabels[bodypart]]; }
-
 inline float sq(float n) { return n*n; }
 
 inline float stepTowardf(float from, float to, float by){
@@ -273,19 +261,19 @@ void playdialogueboxsound(){
 
 
 
-static void ch_quit(Game *game, const char *args)
+static void ch_quit(const char *args)
 {
-  game->tryquit = 1;
+  tryquit = 1;
 }
 
-static void ch_map(Game *game, const char *args)
+static void ch_map(const char *args)
 {
-  game->Loadlevel(args);
-  game->whichlevel = -2;
+  Loadlevel(args);
+  whichlevel = -2;
   campaign = 0;
 }
 
-static void ch_save(Game *game, const char *args){
+static void ch_save(const char *args){
     char buf[64];
     snprintf(buf, 63, ":Data:Maps:%s", args);
 
@@ -438,59 +426,59 @@ static void ch_save(Game *game, const char *args){
                 }
         }
 
-    fpackf(tfile, "Bi", game->numpathpoints);
-       for(int j=0;j<game->numpathpoints;j++){
-               fpackf(tfile, "Bf Bf Bf Bi", game->pathpoint[j].x, game->pathpoint[j].y, game->pathpoint[j].z, game->numpathpointconnect[j]);
-               for(int k=0;k<game->numpathpointconnect[j];k++)
-                       fpackf(tfile, "Bi", game->pathpointconnect[j][k]);
+    fpackf(tfile, "Bi", numpathpoints);
+       for(int j=0;j<numpathpoints;j++){
+               fpackf(tfile, "Bf Bf Bf Bi", pathpoint[j].x, pathpoint[j].y, pathpoint[j].z, numpathpointconnect[j]);
+               for(int k=0;k<numpathpointconnect[j];k++)
+                       fpackf(tfile, "Bi", pathpointconnect[j][k]);
        }
 
-    fpackf(tfile, "Bf Bf Bf Bf", game->mapcenter.x, game->mapcenter.y, game->mapcenter.z, game->mapradius);
+    fpackf(tfile, "Bf Bf Bf Bf", mapcenter.x, mapcenter.y, mapcenter.z, mapradius);
 
     fclose(tfile);
 }
 
-static void ch_cellar(Game *game, const char *args)
+static void ch_cellar(const char *args)
 {
-  game->LoadTextureSave(":Data:Textures:Furdarko.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
+  LoadTextureSave(":Data:Textures:Furdarko.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
 }
 
-static void ch_tint(Game *game, const char *args)
+static void ch_tint(const char *args)
 {
   sscanf(args, "%f%f%f", &tintr, &tintg, &tintb);
 }
 
-static void ch_tintr(Game *game, const char *args)
+static void ch_tintr(const char *args)
 {
   tintr = atof(args);
 }
 
-static void ch_tintg(Game *game, const char *args)
+static void ch_tintg(const char *args)
 {
   tintg = atof(args);
 }
 
-static void ch_tintb(Game *game, const char *args)
+static void ch_tintb(const char *args)
 {
   tintb = atof(args);
 }
 
-static void ch_speed(Game *game, const char *args)
+static void ch_speed(const char *args)
 {
   player[0].speedmult = atof(args);
 }
 
-static void ch_strength(Game *game, const char *args)
+static void ch_strength(const char *args)
 {
   player[0].power = atof(args);
 }
 
-static void ch_power(Game *game, const char *args)
+static void ch_power(const char *args)
 {
   player[0].power = atof(args);
 }
 
-static void ch_size(Game *game, const char *args)
+static void ch_size(const char *args)
 {
   player[0].scale = atof(args) * .2;
 }
@@ -511,7 +499,7 @@ static int find_closest()
   return closest;
 }
 
-static void ch_sizenear(Game *game, const char *args)
+static void ch_sizenear(const char *args)
 {
   int closest = find_closest();
 
@@ -539,12 +527,12 @@ static void set_proportion(int pnum, const char *args)
   }
 }
 
-static void ch_proportion(Game *game, const char *args)
+static void ch_proportion(const char *args)
 {
   set_proportion(0, args);
 }
 
-static void ch_proportionnear(Game *game, const char *args)
+static void ch_proportionnear(const char *args)
 {
   int closest = find_closest();
   if (closest)
@@ -561,12 +549,12 @@ static void set_protection(int pnum, const char *args)
   player[pnum].protectionlow  = low;
 }
 
-static void ch_protection(Game *game, const char *args)
+static void ch_protection(const char *args)
 {
   set_protection(0, args);
 }
 
-static void ch_protectionnear(Game *game, const char *args)
+static void ch_protectionnear(const char *args)
 {
   int closest = find_closest();
   if (closest)
@@ -583,19 +571,19 @@ static void set_armor(int pnum, const char *args)
   player[pnum].armorlow  = low;
 }
 
-static void ch_armor(Game *game, const char *args)
+static void ch_armor(const char *args)
 {
   set_armor(0, args);
 }
 
-static void ch_armornear(Game *game, const char *args)
+static void ch_armornear(const char *args)
 {
   int closest = find_closest();
   if (closest)
     set_armor(closest, args);
 }
 
-static void ch_protectionreset(Game *game, const char *args)
+static void ch_protectionreset(const char *args)
 {
   set_protection(0, "1 1 1");
   set_armor(0, "1 1 1");
@@ -611,38 +599,38 @@ static void set_metal(int pnum, const char *args)
   player[pnum].metallow  = low;
 }
 
-static void ch_metal(Game *game, const char *args)
+static void ch_metal(const char *args)
 {
   set_metal(0, args);
 }
 
-static void set_noclothes(int pnum, Game *game, const char *args)
+static void set_noclothes(int pnum, const char *args)
 {
   player[pnum].numclothes = 0;
-  game->LoadTextureSave(creatureskin[player[pnum].creature][player[pnum].whichskin],
+  LoadTextureSave(creatureskin[player[pnum].creature][player[pnum].whichskin],
                        &player[pnum].skeleton.drawmodel.textureptr,1,
                        &player[pnum].skeleton.skinText[0],&player[pnum].skeleton.skinsize);
 }
 
-static void ch_noclothes(Game *game, const char *args)
+static void ch_noclothes(const char *args)
 {
-  set_noclothes(0, game, args);
+  set_noclothes(0, args);
 }
 
-static void ch_noclothesnear(Game *game, const char *args)
+static void ch_noclothesnear(const char *args)
 {
   int closest = find_closest();
   if (closest)
-    set_noclothes(closest, game, args);
+    set_noclothes(closest, args);
 }
 
 
-static void set_clothes(int pnum, Game *game, const char *args)
+static void set_clothes(int pnum, const char *args)
 {
   char buf[64];
   snprintf(buf, 63, ":Data:Textures:%s.png", args);
 
-  if (!game->AddClothes(buf,&player[pnum].skeleton.skinText[pnum]))
+  if (!AddClothes(buf,&player[pnum].skeleton.skinText[pnum]))
     return;
 
   player[pnum].DoMipmaps();
@@ -653,25 +641,25 @@ static void set_clothes(int pnum, Game *game, const char *args)
   player[pnum].numclothes++;
 }
 
-static void ch_clothes(Game *game, const char *args)
+static void ch_clothes(const char *args)
 {
-  set_clothes(0, game, args);
+  set_clothes(0, args);
 }
 
-static void ch_clothesnear(Game *game, const char *args)
+static void ch_clothesnear(const char *args)
 {
   int closest = find_closest();
   if (closest)
-    set_clothes(closest, game, args);
+    set_clothes(closest, args);
 }
 
-static void ch_belt(Game *game, const char *args)
+static void ch_belt(const char *args)
 {
   player[0].skeleton.clothes = !player[0].skeleton.clothes;
 }
 
 
-static void ch_cellophane(Game *game, const char *args)
+static void ch_cellophane(const char *args)
 {
   cellophane = !cellophane;
   float mul = cellophane ? 0 : 1;
@@ -684,7 +672,7 @@ static void ch_cellophane(Game *game, const char *args)
   }
 }
 
-static void ch_funnybunny(Game *game, const char *args)
+static void ch_funnybunny(const char *args)
 {
   player[0].skeleton.id=0;
   player[0].skeleton.Load(":Data:Skeleton:Basic Figure",":Data:Skeleton:Basic Figurelow",
@@ -693,7 +681,7 @@ static void ch_funnybunny(Game *game, const char *args)
                          ":Data:Models:Body4.solid",":Data:Models:Body5.solid",
                          ":Data:Models:Body6.solid",":Data:Models:Body7.solid",
                          ":Data:Models:Bodylow.solid",":Data:Models:Belt.solid",1);
-  game->LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,
+  LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,
                        &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
   player[0].creature=rabbittype;
   player[0].scale=.2;
@@ -702,7 +690,7 @@ static void ch_funnybunny(Game *game, const char *args)
   set_proportion(0, "1 1 1 1");
 }
 
-static void ch_wolfie(Game *game, const char *args)
+static void ch_wolfie(const char *args)
 {
   player[0].skeleton.id=0;
   player[0].skeleton.Load(":Data:Skeleton:Basic Figure Wolf",":Data:Skeleton:Basic Figure Wolf Low",
@@ -711,80 +699,80 @@ static void ch_wolfie(Game *game, const char *args)
                          ":Data:Models:Wolf4.solid",":Data:Models:Wolf5.solid",
                          ":Data:Models:Wolf6.solid",":Data:Models:Wolf7.solid",
                          ":Data:Models:Wolflow.solid",":Data:Models:Belt.solid",0);
-  game->LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
+  LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
                        &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
   player[0].creature=wolftype;
   player[0].damagetolerance=300;
   set_proportion(0, "1 1 1 1");
 }
 
-static void ch_wolfieisgod(Game *game, const char *args)
+static void ch_wolfieisgod(const char *args)
 {
-  ch_wolfie(game, args);
+  ch_wolfie(args);
 }
 
-static void ch_wolf(Game *game, const char *args)
+static void ch_wolf(const char *args)
 {
-  game->LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
+  LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
                        &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
 }
 
-static void ch_snowwolf(Game *game, const char *args)
+static void ch_snowwolf(const char *args)
 {
-  game->LoadTextureSave(":Data:Textures:SnowWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
+  LoadTextureSave(":Data:Textures:SnowWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
                        &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
 }
 
-static void ch_darkwolf(Game *game, const char *args)
+static void ch_darkwolf(const char *args)
 {
-  game->LoadTextureSave(":Data:Textures:DarkWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
+  LoadTextureSave(":Data:Textures:DarkWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
                        &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
 }
 
-static void ch_lizardwolf(Game *game, const char *args)
+static void ch_lizardwolf(const char *args)
 {
-  game->LoadTextureSave(":Data:Textures:Lizardwolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
+  LoadTextureSave(":Data:Textures:Lizardwolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
                        &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
 }
 
-static void ch_white(Game *game, const char *args)
+static void ch_white(const char *args)
 {
-  game->LoadTextureSave(":Data:Textures:fur.jpg",&player[0].skeleton.drawmodel.textureptr,1,
+  LoadTextureSave(":Data:Textures:fur.jpg",&player[0].skeleton.drawmodel.textureptr,1,
                        &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
 }
 
-static void ch_brown(Game *game, const char *args)
+static void ch_brown(const char *args)
 {
-  game->LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,
+  LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,
                        &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
 }
 
-static void ch_black(Game *game, const char *args)
+static void ch_black(const char *args)
 {
-  game->LoadTextureSave(":Data:Textures:fur2.jpg",&player[0].skeleton.drawmodel.textureptr,1,
+  LoadTextureSave(":Data:Textures:fur2.jpg",&player[0].skeleton.drawmodel.textureptr,1,
                        &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
 }
 
-static void ch_sizemin(Game *game, const char *args)
+static void ch_sizemin(const char *args)
 {
   for (int i = 1; i < numplayers; i++)
     if (player[i].scale < 0.8 * 0.2)
       player[i].scale = 0.8 * 0.2;
 }
 
-static void ch_tutorial(Game *game, const char *args)
+static void ch_tutorial(const char *args)
 {
   tutoriallevel = atoi(args);
 }
 
-static void ch_hostile(Game *game, const char *args)
+static void ch_hostile(const char *args)
 {
   hostile = atoi(args);
 }
 
-static void ch_indemo(Game *game, const char *args)
+static void ch_indemo(const char *args)
 {
-  game->indemo=1;
+  indemo=1;
   hotspot[numhotspots]=player[0].coords;
   hotspotsize[numhotspots]=0;
   hotspottype[numhotspots]=-111;
@@ -792,13 +780,13 @@ static void ch_indemo(Game *game, const char *args)
   numhotspots++;
 }
 
-static void ch_notindemo(Game *game, const char *args)
+static void ch_notindemo(const char *args)
 {
-  game->indemo=0;
+  indemo=0;
   numhotspots--;
 }
 
-static void ch_type(Game *game, const char *args)
+static void ch_type(const char *args)
 {
   int n = sizeof(editortypenames) / sizeof(editortypenames[0]);
        for (int i = 0; i < n; i++)
@@ -808,7 +796,7 @@ static void ch_type(Game *game, const char *args)
                }
 }
 
-static void ch_path(Game *game, const char *args)
+static void ch_path(const char *args)
 {
   int n = sizeof(pathtypenames) / sizeof(pathtypenames[0]);
   for (int i = 0; i < n; i++)
@@ -818,7 +806,7 @@ static void ch_path(Game *game, const char *args)
     }
 }
 
-static void ch_hs(Game *game, const char *args)
+static void ch_hs(const char *args)
 {
   hotspot[numhotspots]=player[0].coords;
 
@@ -835,7 +823,7 @@ static void ch_hs(Game *game, const char *args)
   numhotspots++;
 }
 
-static void ch_dialogue(Game *game, const char *args)
+static void ch_dialogue(const char *args)
 {
   int dlg;
   char buf1[32], buf2[64];
@@ -886,7 +874,7 @@ static void ch_dialogue(Game *game, const char *args)
   numdialogues++;
 }
 
-static void ch_fixdialogue(Game *game, const char *args)
+static void ch_fixdialogue(const char *args)
 {
   char buf1[32], buf2[64];
   int whichdi;
@@ -924,47 +912,47 @@ static void ch_fixdialogue(Game *game, const char *args)
   ipstream.close();
 }
 
-static void ch_fixtype(Game *game, const char *args)
+static void ch_fixtype(const char *args)
 {
   int dlg;
   sscanf(args, "%d", &dlg);
   dialoguetype[0] = dlg;
 }
 
-static void ch_fixrotation(Game *game, const char *args)
+static void ch_fixrotation(const char *args)
 {
   participantrotation[whichdialogue][participantfocus[whichdialogue][indialogue]]=player[participantfocus[whichdialogue][indialogue]].rotation;
 }
 
-static void ch_ddialogue(Game *game, const char *args)
+static void ch_ddialogue(const char *args)
 {
   if (numdialogues)
     numdialogues--;
 }
 
-static void ch_dhs(Game *game, const char *args)
+static void ch_dhs(const char *args)
 {
   if (numhotspots)
     numhotspots--;
 }
 
-static void ch_immobile(Game *game, const char *args)
+static void ch_immobile(const char *args)
 {
   player[0].immobile = 1;
 }
 
-static void ch_allimmobile(Game *game, const char *args)
+static void ch_allimmobile(const char *args)
 {
   for (int i = 1; i < numplayers; i++)
     player[i].immobile = 1;
 }
 
-static void ch_mobile(Game *game, const char *args)
+static void ch_mobile(const char *args)
 {
   player[0].immobile = 0;
 }
 
-static void ch_default(Game *game, const char *args)
+static void ch_default(const char *args)
 {
   player[0].armorhead=1;
   player[0].armorhigh=1;
@@ -993,7 +981,7 @@ static void ch_default(Game *game, const char *args)
   }
 
   player[0].numclothes=0;
-  game->LoadTextureSave(creatureskin[player[0].creature][player[0].whichskin],
+  LoadTextureSave(creatureskin[player[0].creature][player[0].whichskin],
                        &player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],
                        &player[0].skeleton.skinsize);
 
@@ -1001,7 +989,7 @@ static void ch_default(Game *game, const char *args)
   player[0].immobile=0;
 }
 
-static void ch_play(Game *game, const char *args)
+static void ch_play(const char *args)
 {
   int dlg;
   sscanf(args, "%d", &dlg);
@@ -1025,49 +1013,49 @@ static void ch_play(Game *game, const char *args)
   playdialogueboxsound();
 }
 
-static void ch_mapkilleveryone(Game *game, const char *args)
+static void ch_mapkilleveryone(const char *args)
 {
   maptype = mapkilleveryone;
 }
 
-static void ch_mapkillmost(Game *game, const char *args)
+static void ch_mapkillmost(const char *args)
 {
   maptype = mapkillmost;
 }
 
-static void ch_mapkillsomeone(Game *game, const char *args)
+static void ch_mapkillsomeone(const char *args)
 {
   maptype = mapkillsomeone;
 }
 
-static void ch_mapgosomewhere(Game *game, const char *args)
+static void ch_mapgosomewhere(const char *args)
 {
   maptype = mapgosomewhere;
 }
 
-static void ch_viewdistance(Game *game, const char *args)
+static void ch_viewdistance(const char *args)
 {
   viewdistance = atof(args)*100;
 }
 
-static void ch_fadestart(Game *game, const char *args)
+static void ch_fadestart(const char *args)
 {
   fadestart = atof(args);
 }
 
-static void ch_slomo(Game *game, const char *args)
+static void ch_slomo(const char *args)
 {
   slomospeed = atof(args);
   slomo = !slomo;
   slomodelay = 1000;
 }
 
-static void ch_slofreq(Game *game, const char *args)
+static void ch_slofreq(const char *args)
 {
   slomofreq = atof(args);
 }
 
-static void ch_skytint(Game *game, const char *args)
+static void ch_skytint(const char *args)
 {
   sscanf(args, "%f%f%f", &skyboxr, &skyboxg, &skyboxb);
 
@@ -1075,33 +1063,33 @@ static void ch_skytint(Game *game, const char *args)
   skyboxlightg=skyboxg;
   skyboxlightb=skyboxb;
 
-  game->SetUpLighting();
+  SetUpLighting();
 
   terrain.DoShadows();
   objects.DoShadows();
 }
 
-static void ch_skylight(Game *game, const char *args)
+static void ch_skylight(const char *args)
 {
   sscanf(args, "%f%f%f", &skyboxlightr, &skyboxlightg, &skyboxlightb);
 
-  game->SetUpLighting();
+  SetUpLighting();
 
   terrain.DoShadows();
   objects.DoShadows();
 }
 
-static void ch_skybox(Game *game, const char *args)
+static void ch_skybox(const char *args)
 {
   skyboxtexture = !skyboxtexture;
 
-  game->SetUpLighting();
+  SetUpLighting();
 
   terrain.DoShadows();
   objects.DoShadows();
 }
 
-static void cmd_dispatch(Game *game, const string cmd)
+static void cmd_dispatch(const string cmd)
 {
   int i, n_cmds = sizeof(cmd_names) / sizeof(cmd_names[0]);
 
@@ -1109,7 +1097,7 @@ static void cmd_dispatch(Game *game, const string cmd)
     if (cmd.substr(0,cmd.find(' '))==string(cmd_names[i]))
       {
                  cout << "|" << cmd.substr(cmd.find(' ')+1) << "|" << endl;
-               cmd_handlers[i](game, cmd.substr(cmd.find(' ')+1).c_str());
+               cmd_handlers[i](cmd.substr(cmd.find(' ')+1).c_str());
                break;
       }
   emit_sound_np(i < n_cmds ? consolesuccesssound : consolefailsound);
@@ -1466,7 +1454,7 @@ void Game::Loadlevel(const char *name) {
        if(tfile) {
                pause_sound(stream_firesound);
                scoreadded=0;
-               windialogue=0;
+               windialogue=false;
                hostiletime=0;
                won=0;
 
@@ -2695,7 +2683,7 @@ void Game::doDebugKeys(){
             if(closest!=-1){
                 XYZ headspurtdirection;
                 //int i = player[closest].skeleton.jointlabels[head];
-                Joint& headjoint=playerJoint(closest,head);
+                Joint& headjoint= player[closest].getJointFor(head);
                 for(int k=0;k<player[closest].skeleton.num_joints; k++){
                     if(!player[closest].skeleton.free)
                         flatvelocity2=player[closest].velocity;
@@ -2708,7 +2696,7 @@ void Game::doDebugKeys(){
                     flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
                     flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
                     flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
-                    headspurtdirection=headjoint.position-playerJoint(closest,neck).position;
+                    headspurtdirection=headjoint.position-player[closest].getJointFor(neck).position;
                     Normalise(&headspurtdirection);
                     Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, .6, 1);
                     flatvelocity2+=headspurtdirection*8;
@@ -3415,7 +3403,7 @@ void Game::doAerialAcrobatics(){
                             XYZ tempcoords1=lowpoint;
                             whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
                             if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
-                                setAnimation(k,walljumpleftanim);
+                                player[k].setAnimation(walljumpleftanim);
                                 emit_sound_at(movewhooshsound, player[k].coords);
                                 if(k==0)
                                     pause_sound(whooshsound);
@@ -3435,7 +3423,7 @@ void Game::doAerialAcrobatics(){
                                 lowpointtarget=lowpoint+DoRotation(player[k].facing,0,90,0)*1.5;
                                 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
                                 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
-                                    setAnimation(k,walljumprightanim);
+                                    player[k].setAnimation(walljumprightanim);
                                     emit_sound_at(movewhooshsound, player[k].coords);
                                     if(k==0)pause_sound(whooshsound);
 
@@ -3452,7 +3440,7 @@ void Game::doAerialAcrobatics(){
                                     lowpointtarget=lowpoint+player[k].facing*2;
                                     whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
                                     if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
-                                        setAnimation(k,walljumpbackanim);
+                                        player[k].setAnimation(walljumpbackanim);
                                         emit_sound_at(movewhooshsound, player[k].coords);
                                         if(k==0)pause_sound(whooshsound);
 
@@ -3469,7 +3457,7 @@ void Game::doAerialAcrobatics(){
                                         lowpointtarget=lowpoint-player[k].facing*2;
                                         whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
                                         if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
-                                            setAnimation(k,walljumpfrontanim);
+                                            player[k].setAnimation(walljumpfrontanim);
                                             emit_sound_at(movewhooshsound, player[k].coords);
                                             if(k==0)pause_sound(whooshsound);
 
@@ -3652,7 +3640,7 @@ void Game::doAerialAcrobatics(){
                                                                         player[k].targetframe=1;
                                                                         //hang ledge (?)
                                                                         if(j>25){
-                                                                            setAnimation(k,hanganim);
+                                                                            player[k].setAnimation(hanganim);
                                                                             player[k].jumppower=0;
                                                                         }
                                                                     }
@@ -3683,7 +3671,7 @@ void Game::doAerialAcrobatics(){
                         //stagger off ledge (?)
                         if(player[k].targetanimation==staggerbackhighanim||player[k].targetanimation==staggerbackhardanim)
                             player[k].RagDoll(0);
-                        setAnimation(k,jumpdownanim);
+                        player[k].setAnimation(jumpdownanim);
 
                         if(!k)
                           emit_sound_at(whooshsound, player[k].coords, 128.);
@@ -3758,14 +3746,14 @@ void Game::doAttacks(){
                                     player[i].targetanimation==staffhitanim||
                                     player[i].targetanimation==staffspinhitanim)
                                 if(findDistancefast(&player[k].coords,&player[i].coords)<6.5&&!player[i].skeleton.free){
-                                    setAnimation(k,dodgebackanim);
+                                    player[k].setAnimation(dodgebackanim);
                                     player[k].targetrotation=roughDirectionTo(player[k].coords,player[i].coords);
                                     player[k].targettilt2=pitchTo(player[k].coords,player[i].coords);
                                 }
                         }
                         if(player[k].targetanimation!=dodgebackanim){
                             if(k==0)numflipped++;
-                            setAnimation(k,backhandspringanim);
+                            player[k].setAnimation(backhandspringanim);
                             player[k].targetrotation=-rotation+180;
                             if(player[k].leftkeydown)
                                 player[k].targetrotation-=45;
@@ -4156,8 +4144,8 @@ void Game::doAttacks(){
                                     if(player[k].targetanimation==crouchstabanim||
                                             player[k].targetanimation==swordgroundstabanim||
                                             player[k].targetanimation==staffgroundsmashanim){
-                                        targetpoint+=(playerJoint(i,abdomen).position+
-                                                 playerJoint(i,neck).position)/2*
+                                        targetpoint+=(player[i].getJointFor(abdomen).position+
+                                                 player[i].getJointFor(neck).position)/2*
                                                 player[i].scale;
                                     }
                                     player[k].targetrotation=roughDirectionTo(player[k].coords,targetpoint);
@@ -4213,7 +4201,7 @@ void Game::doAttacks(){
                                   player[k].rabbitkickenabled)||
                                  player[k].jumpkeydown)){
                             oldattackkey=1;
-                            setAnimation(k,rabbitkickanim);
+                            player[k].setAnimation(rabbitkickanim);
                         }
                     //update counts
                     if(animation[player[k].targetanimation].attack&&k==0){
@@ -4277,9 +4265,9 @@ void Game::doPlayerCollisions(){
                     XYZ tempcoords1=player[i].coords;
                     XYZ tempcoords2=player[k].coords;
                     if(!player[i].skeleton.oldfree)
-                        tempcoords1.y+=playerJoint(i,abdomen).position.y*player[i].scale;
+                        tempcoords1.y+=player[i].getJointFor(abdomen).position.y*player[i].scale;
                     if(!player[k].skeleton.oldfree)
-                        tempcoords2.y+=playerJoint(k,abdomen).position.y*player[k].scale;
+                        tempcoords2.y+=player[k].getJointFor(abdomen).position.y*player[k].scale;
                     collisionradius=1.2*sq((player[i].scale+player[k].scale)*2.5);
                     if(player[0].hasvictim)
                         if(player[0].targetanimation==rabbitkickanim&&(k==0||i==0)&&!player[0].victim->skeleton.free)
@@ -4373,18 +4361,18 @@ void Game::doPlayerCollisions(){
                                         if(player[k].howactive==typeactive||hostile)
                                             if(player[k].isIdle()){
                                                 if(player[k].howactive<typesleeping)
-                                                    setAnimation(k,player[k].getStop());
+                                                    player[k].setAnimation(player[k].getStop());
                                                 else if(player[k].howactive==typesleeping)
-                                                    setAnimation(k,getupfromfrontanim);
+                                                    player[k].setAnimation(getupfromfrontanim);
                                                 if(!editorenabled)
                                                     player[k].howactive=typeactive;
                                             }
                                         if(player[i].howactive==typeactive||hostile)
                                             if(player[i].isIdle()){
                                                 if(player[i].howactive<typesleeping)
-                                                    setAnimation(i,player[k].getStop());
+                                                    player[i].setAnimation(player[k].getStop());
                                                 else
-                                                    setAnimation(i,getupfromfrontanim);
+                                                    player[i].setAnimation(getupfromfrontanim);
                                                 if(!editorenabled)
                                                     player[i].howactive=typeactive;
                                             }
@@ -4600,9 +4588,9 @@ void Game::doAI(int i){
                                     if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
                                         if(player[j].coords.y<player[i].coords.y+5||player[j].onterrain)
                                             if(!player[j].isWallJump()&&-1==checkcollide(
-                                                            DoRotation(playerJoint(i,head).position,0,player[i].rotation,0)
+                                                            DoRotation(player[i].getJointFor(head).position,0,player[i].rotation,0)
                                                                 *player[i].scale+player[i].coords,
-                                                            DoRotation(playerJoint(j,head).position,0,player[j].rotation,0)
+                                                            DoRotation(player[j].getJointFor(head).position,0,player[j].rotation,0)
                                                                 *player[j].scale+player[j].coords)||
                                                     (player[j].targetanimation==hanganim&&
                                                      normaldotproduct(player[j].facing,player[i].coords-player[j].coords)<0)){
@@ -4694,7 +4682,7 @@ void Game::doAI(int i){
 
                 if(player[i].aitype!=passivetype){
                     if(player[i].howactive==typesleeping)
-                        setAnimation(i,getupfromfrontanim);
+                        player[i].setAnimation(getupfromfrontanim);
                     player[i].howactive=typeactive;
                 }
             }
@@ -4743,9 +4731,9 @@ void Game::doAI(int i){
                                 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
                                     if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
                                         if((-1==checkcollide(
-                                                        DoRotation(playerJoint(i,head).position,0,player[i].rotation,0)*
+                                                        DoRotation(player[i].getJointFor(head).position,0,player[i].rotation,0)*
                                                             player[i].scale+player[i].coords,
-                                                        DoRotation(playerJoint(j,head).position,0,player[j].rotation,0)*
+                                                        DoRotation(player[j].getJointFor(head).position,0,player[j].rotation,0)*
                                                             player[j].scale+player[j].coords)&&
                                                     !player[j].isWallJump())||
                                                 (player[j].targetanimation==hanganim&&
@@ -4800,7 +4788,7 @@ void Game::doAI(int i){
                         j=checkcollide(test2,test);
                     if(j==-1){
                         player[i].velocity=0;
-                        setAnimation(i,player[i].getStop());
+                        player[i].setAnimation(player[i].getStop());
                         player[i].targetrotation+=180;
                         player[i].stunned=.5;
                         //player[i].aitype=passivetype;
@@ -4879,9 +4867,9 @@ void Game::doAI(int i){
                     if(findDistancefast(&player[i].coords,&player[0].coords)<400)
                         if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
                             if((checkcollide(
-                                        DoRotation(playerJoint(i,head).position,0,player[i].rotation,0)*
+                                        DoRotation(player[i].getJointFor(head).position,0,player[i].rotation,0)*
                                             player[i].scale+player[i].coords,
-                                        DoRotation(playerJoint(0,head).position,0,player[0].rotation,0)*
+                                        DoRotation(player[0].getJointFor(head).position,0,player[0].rotation,0)*
                                             player[0].scale+player[0].coords)==-1)||
                                     (player[0].targetanimation==hanganim&&normaldotproduct(
                                         player[0].facing,player[i].coords-player[0].coords)<0)){
@@ -4912,25 +4900,25 @@ void Game::doAI(int i){
             player[i].runninghowlong=0;
 
         //get help from buddies
-        if(player[i].aitype==gethelptype){
+        if(player[i].aitype==gethelptype) {
             player[i].runninghowlong+=multiplier;
             player[i].aiupdatedelay-=multiplier;
 
-            if(player[i].aiupdatedelay<0||player[i].ally==0){
+            if(player[i].aiupdatedelay<0||player[i].ally==0) {
                 player[i].aiupdatedelay=.2;
 
                 //find closest ally
                 //TODO: factor out closest search somehow
-                if(!player[i].ally){
+                if(!player[i].ally) {
                     int closest=-1;
                     float closestdist=-1;
-                    for(int k=0;k<numplayers;k++){
+                    for(int k=0;k<numplayers;k++) {
                         if(k!=i&&k!=0&&!player[k].dead&&
                                 player[k].howactive<typedead1&&
                                 !player[k].skeleton.free&&
-                                player[k].aitype==passivetype){
+                                player[k].aitype==passivetype) {
                             float distance=findDistancefast(&player[i].coords,&player[k].coords);
-                            if(closestdist==-1||distance<closestdist){
+                            if(closestdist==-1||distance<closestdist) {
                                 closestdist=distance;
                                 closest=k;
                             }
@@ -4950,8 +4938,8 @@ void Game::doAI(int i){
 
                 XYZ facing=player[i].coords;
                 XYZ flatfacing=player[player[i].ally].coords;
-                facing.y+=playerJoint(i,head).position.y*player[i].scale;
-                flatfacing.y+=playerJoint(player[i].ally,head).position.y*player[player[i].ally].scale;
+                facing.y+=player[i].getJointFor(head).position.y*player[i].scale;
+                flatfacing.y+=player[player[i].ally].getJointFor(head).position.y*player[player[i].ally].scale;
                 if(-1!=checkcollide(facing,flatfacing))
                     player[i].lastseentime-=.1;
 
@@ -5112,14 +5100,14 @@ void Game::doAI(int i){
                         if(weapons[player[0].weaponids[0]].getType()==knife){
                             if(player[i].isIdle()||player[i].isCrouch()||player[i].isRun()||player[i].isFlip()){
                                 if(abs(Random()%2==0))
-                                    setAnimation(i,backhandspringanim);
+                                    player[i].setAnimation(backhandspringanim);
                                 else
-                                    setAnimation(i,rollanim);
+                                    player[i].setAnimation(rollanim);
                                 player[i].targetrotation+=90*(abs(Random()%2)*2-1);
                                 player[i].wentforweapon=0;
                             }
                             if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim)
-                                setAnimation(i,flipanim);
+                                player[i].setAnimation(flipanim);
                         }
                     }
                     player[i].forwardkeydown=0;
@@ -5174,7 +5162,7 @@ void Game::doAI(int i){
                         j=checkcollide(test2,test);
                     if(j==-1) {
                         player[i].velocity=0;
-                        setAnimation(i,player[i].getStop());
+                        player[i].setAnimation(player[i].getStop());
                         player[i].targetrotation+=180;
                         player[i].stunned=.5;
                         player[i].aitype=pathfindtype;
@@ -5334,8 +5322,8 @@ void Game::doAI(int i){
 
                 XYZ facing=player[i].coords;
                 XYZ flatfacing=player[0].coords;
-                facing.y+=playerJoint(i,head).position.y*player[i].scale;
-                flatfacing.y+=playerJoint(0,head).position.y*player[0].scale;
+                facing.y+=player[i].getJointFor(head).position.y*player[i].scale;
+                flatfacing.y+=player[0].getJointFor(head).position.y*player[0].scale;
                 if(player[i].occluded>=2)
                     if(-1!=checkcollide(facing,flatfacing)){
                         if(!player[i].pause)
@@ -5407,6 +5395,64 @@ void Game::doAI(int i){
     }
 }
 
+
+
+void updateSettingsMenu(){
+    char sbuf[256];
+    if((float)newscreenwidth>(float)newscreenheight*1.61||(float)newscreenwidth<(float)newscreenheight*1.59)
+        sprintf (sbuf, "Resolution: %d*%d",(int)newscreenwidth,(int)newscreenheight);
+    else
+        sprintf (sbuf, "Resolution: %d*%d (widescreen)",(int)newscreenwidth,(int)newscreenheight);
+    Menu::setText(0,sbuf);
+    if(newdetail==0) Menu::setText(1,"Detail: Low");
+    if(newdetail==1) Menu::setText(1,"Detail: Medium");
+    if(newdetail==2) Menu::setText(1,"Detail: High");
+    if(bloodtoggle==0) Menu::setText(2,"Blood: Off");
+    if(bloodtoggle==1) Menu::setText(2,"Blood: On, low detail");
+    if(bloodtoggle==2) Menu::setText(2,"Blood: On, high detail (slower)");
+    if(difficulty==0) Menu::setText(3,"Difficulty: Easier");
+    if(difficulty==1) Menu::setText(3,"Difficulty: Difficult");
+    if(difficulty==2) Menu::setText(3,"Difficulty: Insane");
+    Menu::setText(4,ismotionblur?"Blur Effects: Enabled (less compatible)":"Blur Effects: Disabled (more compatible)");
+    Menu::setText(5,decals?"Decals: Enabled (slower)":"Decals: Disabled");
+    Menu::setText(6,musictoggle?"Music: Enabled":"Music: Disabled");
+    Menu::setText(9,invertmouse?"Invert mouse: Yes":"Invert mouse: No");
+    sprintf (sbuf, "Mouse Speed: %d", (int)(usermousesensitivity*5));
+    Menu::setText(10,sbuf);
+    sprintf (sbuf, "Volume: %d%%", (int)(volume*100));
+    Menu::setText(11,sbuf);
+    Menu::setText(13,showdamagebar?"Damage Bar: On":"Damage Bar: Off");
+    if(newdetail==detail&&newscreenheight==(int)screenheight&&newscreenwidth==(int)screenwidth)
+        sprintf (sbuf, "Back");
+    else
+        sprintf (sbuf, "Back (some changes take effect next time Lugaru is opened)");
+    Menu::setText(8,sbuf);
+}
+
+void updateStereoConfigMenu(){
+    char sbuf[256];
+    sprintf(sbuf, "Stereo mode: %s", StereoModeName(newstereomode));
+    Menu::setText(0,sbuf);
+    sprintf(sbuf, "Stereo separation: %.3f", stereoseparation);
+    Menu::setText(1,sbuf);
+    sprintf(sbuf, "Reverse stereo: %s", stereoreverse ? "Yes" : "No");
+    Menu::setText(2,sbuf);
+}
+
+void updateControlsMenu(){
+    Menu::setText(0,(string)"Forwards: "+(keyselect==0?"_":Input::keyToChar(forwardkey)));
+    Menu::setText(1,(string)"Back: "    +(keyselect==1?"_":Input::keyToChar(backkey)));
+    Menu::setText(2,(string)"Left: "    +(keyselect==2?"_":Input::keyToChar(leftkey)));
+    Menu::setText(3,(string)"Right: "   +(keyselect==3?"_":Input::keyToChar(rightkey)));
+    Menu::setText(4,(string)"Crouch: "  +(keyselect==4?"_":Input::keyToChar(crouchkey)));
+    Menu::setText(5,(string)"Jump: "    +(keyselect==5?"_":Input::keyToChar(jumpkey)));
+    Menu::setText(6,(string)"Draw: "    +(keyselect==6?"_":Input::keyToChar(drawkey)));
+    Menu::setText(7,(string)"Throw: "   +(keyselect==7?"_":Input::keyToChar(throwkey)));
+    Menu::setText(8,(string)"Attack: "  +(keyselect==8?"_":Input::keyToChar(attackkey)));
+    if(debugmode)
+        Menu::setText(9,(string)"Console: "+(keyselect==9?"_":Input::keyToChar(consolekey)));
+}
+
 /*
 Values of mainmenu :
 1 Main menu
@@ -5422,10 +5468,155 @@ Values of mainmenu :
 11 Same that 9 ??? => unused
 18 stereo configuration
 */
-    
+
+void Game::LoadMenu(){
+    Menu::clearMenu();
+    switch(mainmenu) {
+        case 1:
+        case 2:
+            Menu::addImage(0,Mainmenuitems[0],150,480-128,256,128);
+            Menu::addButtonImage(1,Mainmenuitems[mainmenu==1?1:5],18,480-152-32,128,32);
+            Menu::addButtonImage(2,Mainmenuitems[2],18,480-228-32,112,32);
+            Menu::addButtonImage(3,Mainmenuitems[mainmenu==1?3:6],18,480-306-32,mainmenu==1?68:132,32);
+        break;
+        case 3:
+            Menu::addButton( 0,"",10+20,440);
+            Menu::addButton( 1,"",10+60,405);
+            Menu::addButton( 2,"",10+70,370);
+            Menu::addButton( 3,"",10+20-1000,335-1000);
+            Menu::addButton( 4,"",10   ,335);
+            Menu::addButton( 5,"",10+60,300);
+            Menu::addButton( 6,"",10+70,265);
+            Menu::addButton( 9,"",10   ,230);
+            Menu::addButton(10,"",20   ,195);
+            Menu::addButton(11,"",10+60,160);
+            Menu::addButton(13,"",30   ,125);
+            Menu::addButton( 7,"-Configure Controls-",10+15, 90);
+            Menu::addButton(12,"-Configure Stereo -",10+15, 55);
+            Menu::addButton(8,"Back",10,10);
+            updateSettingsMenu();
+        break;
+        case 4:
+            Menu::addButton(0,"",10   ,400);
+            Menu::addButton(1,"",10+40,360);
+            Menu::addButton(2,"",10+40,320);
+            Menu::addButton(3,"",10+30,280);
+            Menu::addButton(4,"",10+20,240);
+            Menu::addButton(5,"",10+40,200);
+            Menu::addButton(6,"",10+40,160);
+            Menu::addButton(7,"",10+30,120);
+            Menu::addButton(8,"",10+20,80);
+            if(debugmode)
+                Menu::addButton(9,"",10+10,40);
+            Menu::addButton(debugmode?10:9,"Back",10,10);
+            updateControlsMenu();
+        break;
+        case 5: {
+            LoadCampaign();
+            Menu::addLabel(-1,accountactive->getName(),5,400);
+            Menu::addButton(1,"Tutorial",5,300);
+            Menu::addButton(2,"Challenge",5,240);
+            Menu::addButton(3,"Delete User",400,10);
+            Menu::addButton(4,"Main Menu",5,10);
+            Menu::addButton(5,"Change User",5,180);
+            Menu::addButton(6,"Campaign : "+accountactive->getCurrentCampaign(),200,420);
+
+            //show campaign map
+            //with (2,-5) offset from old code
+            Menu::addImage(-1,Mainmenuitems[7],150+2,60-5,400,400);
+            //show levels
+            int numlevels = accountactive->getCampaignChoicesMade();
+            numlevels += numlevels>0 ? campaignlevels[numlevels-1].nextlevel.size() : 1;
+            for(int i=0;i<numlevels;i++){
+                XYZ midpoint=campaignlevels[i].getCenter();
+                float itemsize=campaignlevels[i].getWidth();
+                const bool active=i>=accountactive->getCampaignChoicesMade();
+                if(!active)
+                    itemsize/=2;
+
+                if(i>=1){
+                    XYZ start=campaignlevels[i-1].getCenter();
+                    Menu::addMapLine(start.x,start.y,midpoint.x-start.x,midpoint.y-start.y,0.5,active?1:0.5,active?1:0.5,0,0);
+                }
+                Menu::addMapMarker(NB_CAMPAIGN_MENU_ITEM+i, Mapcircletexture,
+                        midpoint.x-itemsize/2, midpoint.y-itemsize/2, itemsize, itemsize, active?1:0.5, 0, 0);
+
+                if(active){
+                    Menu::addMapLabel(-2,campaignlevels[i].description,
+                            campaignlevels[i].getStartX()+10,
+                            campaignlevels[i].getStartY()-4);
+                }
+            }
+        } break;
+        case 6:
+            Menu::addLabel(-1,"Are you sure you want to delete this user?",10,400);
+            Menu::addButton(1,"Yes",10,360);
+            Menu::addButton(2,"No",10,320);
+            break;
+        case 7:
+            if(Account::getNbAccounts()<8)
+                Menu::addButton(0,"New User",10,400);
+            else
+                Menu::addLabel(0,"No More Users",10,400);
+            Menu::addLabel(-2,"",20,400);
+            Menu::addButton(Account::getNbAccounts()+1,"Back",10,10);
+            for(int i=0;i<Account::getNbAccounts();i++)
+                Menu::addButton(i+1,Account::get(i)->getName(),10,340-20*(i+1));
+            break;
+        case 8:
+            Menu::addButton(0,"Easier",10,400);
+            Menu::addButton(1,"Difficult",10,360);
+            Menu::addButton(2,"Insane",10,320);
+            break;
+        case 9:
+            for(int i=0;i<numchallengelevels;i++){
+                char temp[255];
+                string name="";
+                sprintf (temp, "Level %d",i+1);
+                for(int j=strlen(temp);j<17;j++)
+                        strcat(temp," ");
+                name+=temp;
+                sprintf (temp, "%d",(int)accountactive->getHighScore(i));
+                for(int j=strlen(temp);j<(32-17);j++)
+                        strcat(temp," ");
+                name+=temp;
+                sprintf (temp, "%d:",(int)(((int)accountactive->getFastTime(i)-(int)(accountactive->getFastTime(i))%60)/60));
+                if((int)(accountactive->getFastTime(i))%60<10)strcat(temp,"0");
+                name+=temp;
+                sprintf (temp, "%d",(int)(accountactive->getFastTime(i))%60);
+                name+=temp;
+
+                Menu::addButton(i,name,10,400-i*25,i>accountactive->getProgress()?0.5:1,0,0);
+            }
+
+            Menu::addButton(-1,"             High Score      Best Time",10,440);
+            Menu::addButton(numchallengelevels,"Back",10,10);
+            break;
+        case 10: {
+            Menu::addLabel(0,"Congratulations!",220,330);
+            Menu::addLabel(1,"You have avenged your family and",140,300);
+            Menu::addLabel(2,"restored peace to the island of Lugaru.",110,270);
+            Menu::addButton(3,"Back",10,10);
+            char sbuf[256];
+            sprintf(sbuf,"Your score:         %d",(int)accountactive->getCampaignScore());
+            Menu::addLabel(4,sbuf,190,200);
+            sprintf(sbuf,"Highest score:      %d",(int)accountactive->getCampaignHighScore());
+            Menu::addLabel(5,sbuf,190,180);
+        } break;
+        case 18:
+            Menu::addButton(0,"",70,400);
+            Menu::addButton(1,"",10,360);
+            Menu::addButton(2,"",40,320);
+            Menu::addButton(3,"Back",10,10);
+            updateStereoConfigMenu();
+        break;
+    }
+}
+
 void Game::MenuTick(){
     //menu buttons
-    
+    selected=Menu::getSelected(mousecoordh*640/screenwidth,480-mousecoordv*480/screenheight);
+
     // some specific case where we do something even if the left mouse button is not pressed.
        if((mainmenu==5) && (endgame==2)) {
                accountactive->endGame();
@@ -5433,9 +5624,15 @@ void Game::MenuTick(){
        }
        if(mainmenu==10)
                endgame=2;
-       if( (mainmenu==18) && Input::isKeyPressed(MOUSEBUTTON2) && (selected==1) )
+       if(mainmenu==18 && Input::isKeyPressed(MOUSEBUTTON2) && selected==1){
                stereoseparation-=0.001;
-               
+        updateStereoConfigMenu();
+    }
+
+    static int oldmainmenu=mainmenu;
+
+    char sbuf[256];
+
     if(Input::MouseClicked() && (selected >= 0)) { // handling of the left mouse clic in menus
                switch(mainmenu) {
                        case 1:
@@ -5535,7 +5732,6 @@ void Game::MenuTick(){
                                                break;
                                        case 6:
                                                musictoggle = !musictoggle;
-
                                                if(musictoggle) {
                                                  emit_stream_np(stream_menutheme);
                                                } else {
@@ -5548,7 +5744,6 @@ void Game::MenuTick(){
                                                                musicvolume[i]=0;
                                                        }
                                                }
-
                                                break;
                                        case 7: // controls
                                                flash();
@@ -5558,8 +5753,7 @@ void Game::MenuTick(){
                                                break;
                                        case 8:
                                                flash();
-                                               
-                                               SaveSettings(*this);
+                                               SaveSettings();
                                                mainmenu=gameon?2:1;
                                                break;
                                        case 9:
@@ -5567,16 +5761,17 @@ void Game::MenuTick(){
                                                break;
                                        case 10:
                                                usermousesensitivity+=.2;
-                                               if(usermousesensitivity>2) usermousesensitivity=.2;
+                                               if(usermousesensitivity>2)
+                            usermousesensitivity=.2;
                                                break;
                                        case 11:
                                                volume+=.1f;
-                                               if(volume>1.0001f) volume=0;
+                                               if(volume>1.0001f)
+                            volume=0;
                                                OPENAL_SetSFXMasterVolume((int)(volume*255));
                                                break;
                                        case 12:
                                                flash();
-                                               
                                                newstereomode = stereomode;
                                                mainmenu=18;
                                                keyselect=-1;
@@ -5585,20 +5780,21 @@ void Game::MenuTick(){
                                                showdamagebar = !showdamagebar;
                                                break;
                                }
+                updateSettingsMenu();
                                break;
                        case 4:
                                if(!waiting) {
                                        fireSound();
-                                       if(selected<nummenuitems-1 && keyselect==-1)
+                                       if(selected<(debugmode?10:9) && keyselect==-1)
                                                keyselect=selected;
                                        if(keyselect!=-1)
                                                setKeySelected();
-                                       if(selected==nummenuitems-1){
+                                       if(selected==(debugmode?10:9)){
                                                flash();
-
                                                mainmenu=3;
                                        }
                                }
+                updateControlsMenu();
                                break;
                        case 5:
                                fireSound();
@@ -5664,7 +5860,7 @@ void Game::MenuTick(){
                                                                c=campaigns.begin();
                                                        accountactive->setCurrentCampaign(*c);
                                                }
-                                               LoadCampaign();
+                                               LoadMenu();
                                                break;
                                }
                                break;
@@ -5689,7 +5885,10 @@ void Game::MenuTick(){
                                        accountactive=Account::get(selected-1);
                                } else if (selected == Account::getNbAccounts()+1) {
                                        flash();
-                                       mainmenu=5;
+                    if(accountactive)
+                        mainmenu=5;
+                    else
+                        mainmenu=1;
                                        for(int j=0;j<255;j++){
                                                displaytext[0][j]=0;
                                        }
@@ -5762,6 +5961,7 @@ void Game::MenuTick(){
                                                InitStereo(stereomode);
                                        }
                                }
+                updateStereoConfigMenu();
                                break;
                }
        }
@@ -5769,13 +5969,13 @@ void Game::MenuTick(){
     if(Input::isKeyDown(SDLK_q) && Input::isKeyDown(SDLK_LMETA)){
         tryquit=1;
         if(mainmenu==3) {
-            SaveSettings(*this);
+            SaveSettings();
         }
     }
 
     OPENAL_SetFrequency(channels[stream_menutheme], 22050);
 
-    if(entername) {
+    if(entername){
         inputText(displaytext[0],&displayselected,&displaychars[0]);
         if(!waiting) { // the input as finished
             if(displaychars[0]){ // with enter
@@ -5803,6 +6003,16 @@ void Game::MenuTick(){
             displayblink=1-displayblink;
         }
     }
+
+    if(entername){
+        Menu::setText(0,displaytext[0],20,400,-1,-1);
+        Menu::setText(-2,displayblink?"_":"",20+displayselected*10,400,-1,-1);
+    }
+
+    if(oldmainmenu!=mainmenu)
+        LoadMenu();
+       oldmainmenu=mainmenu;
+
 }
 
 void Game::Tick(){
@@ -5883,7 +6093,7 @@ void Game::Tick(){
                 emit_stream_np(stream_menutheme);
                 pause_sound(leveltheme);
             }
-                       LoadCampaign();
+                       LoadMenu();
         }
         //escape key pressed
         //TODO: there must be code somewhere else that handles clicking the Back button, merge it with this
@@ -5908,7 +6118,7 @@ void Game::Tick(){
             }
             //finished with settings menu
                        if(mainmenu==3){
-                               SaveSettings(*this);
+                               SaveSettings();
                        }
             //effects
                        if(mainmenu>=3&&mainmenu!=8){
@@ -5986,7 +6196,7 @@ void Game::Tick(){
                                archiveselected=0;
                                if(consolechars[0]>0) {
                     consoletext[0][consolechars[0]]='\0';
-                    cmd_dispatch(this, consoletext[0]);
+                    cmd_dispatch(consoletext[0]);
                                        for(int k=14;k>=1;k--) {
                                                for(int j=0;j<255;j++)
                                                        consoletext[k][j]=consoletext[k-1][j];
@@ -6011,7 +6221,7 @@ void Game::Tick(){
                if(Input::isKeyDown(SDLK_q)&&Input::isKeyDown(SDLK_LMETA)){
                        tryquit=1;
                        if(mainmenu==3) {
-                               SaveSettings(*this);
+                               SaveSettings();
                        }
                }
 
@@ -6378,7 +6588,7 @@ void Game::Tick(){
                             hostile=1;
                         }
                         if(dialoguetype[whichdialogue]>29&&dialoguetype[whichdialogue]<40){
-                            windialogue=1;
+                            windialogue=true;
                         }
                         if(dialoguetype[whichdialogue]>49&&dialoguetype[whichdialogue]<60){
                             hostile=1;
@@ -6643,7 +6853,7 @@ void Game::Tick(){
                                                     player[i].isIdle()||
                                                     player[i].aitype!=playercontrolled){
                                                 player[i].throwtogglekeydown=1;
-                                                setAnimation(i,crouchremoveknifeanim);
+                                                player[i].setAnimation(crouchremoveknifeanim);
                                                 player[i].targetrotation=roughDirectionTo(player[i].coords,weapons[j].position);
                                                 player[i].hasvictim=0;
                                             }
@@ -6676,7 +6886,7 @@ void Game::Tick(){
                                                 player[i].coords.y<weapons[j].position.y){
                                             if(!player[i].isFlip()){
                                                 player[i].throwtogglekeydown=1;
-                                                setAnimation(i,removeknifeanim);
+                                                player[i].setAnimation(removeknifeanim);
                                                 player[i].targetrotation=roughDirectionTo(player[i].coords,weapons[j].position);
                                             }
                                             if(player[i].isFlip()){
@@ -6729,7 +6939,7 @@ void Game::Tick(){
                                                         player[i].throwtogglekeydown=1;
                                                         player[i].victim=&player[j];
                                                         player[i].hasvictim=1;
-                                                        setAnimation(i,crouchremoveknifeanim);
+                                                        player[i].setAnimation(crouchremoveknifeanim);
                                                         player[i].targetrotation=roughDirectionTo(player[i].coords,player[j].coords);
                                                     }
                                                     if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
@@ -6791,10 +7001,10 @@ void Game::Tick(){
 
                                                                 player[i].victim->weaponactive=-1;
 
-                                                                playerJoint(player[i].victim,abdomen).velocity+=relative*6;
-                                                                playerJoint(player[i].victim,neck).velocity+=relative*6;
-                                                                playerJoint(player[i].victim,rightshoulder).velocity+=relative*6;
-                                                                playerJoint(player[i].victim,leftshoulder).velocity+=relative*6;
+                                                                player[i].victim->getJointFor(abdomen).velocity+=relative*6;
+                                                                player[i].victim->getJointFor(neck).velocity+=relative*6;
+                                                                player[i].victim->getJointFor(rightshoulder).velocity+=relative*6;
+                                                                player[i].victim->getJointFor(leftshoulder).velocity+=relative*6;
                                                             }
                                                             weapons[k].owner=i;
                                                             if(player[i].num_weapons>0){
@@ -6824,11 +7034,11 @@ void Game::Tick(){
                                                                 findDistancefast(&player[i].coords,&player[j].coords)<100&&
                                                                 findDistancefast(&player[i].coords,&player[j].coords)>1.5&&
                                                                 !player[j].skeleton.free&&
-                                                                -1==checkcollide(DoRotation(playerJoint(j,head).position,0,player[j].rotation,0)*player[j].scale+player[j].coords,DoRotation(playerJoint(i,head).position,0,player[i].rotation,0)*player[i].scale+player[i].coords)){
+                                                                -1==checkcollide(DoRotation(player[j].getJointFor(head).position,0,player[j].rotation,0)*player[j].scale+player[j].coords,DoRotation(player[i].getJointFor(head).position,0,player[i].rotation,0)*player[i].scale+player[i].coords)){
                                                             if(!player[i].isFlip()){
                                                                 player[i].throwtogglekeydown=1;
                                                                 player[i].victim=&player[j];
-                                                                setAnimation(i,knifethrowanim);
+                                                                player[i].setAnimation(knifethrowanim);
                                                                 player[i].targetrotation=roughDirectionTo(player[i].coords,player[j].coords);
                                                                 player[i].targettilt2=pitchTo(player[i].coords,player[j].coords);
                                                             }
@@ -6838,7 +7048,7 @@ void Game::Tick(){
                                                                     player[i].victim=&player[j];
                                                                     XYZ aim;
                                                                     weapons[player[i].weaponids[0]].owner=-1;
-                                                                    aim=player[i].victim->coords+DoRotation(playerJoint(player[i].victim,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(playerJoint(i,righthand).position,0,player[i].rotation,0)*player[i].scale);
+                                                                    aim=player[i].victim->coords+DoRotation(player[i].victim->getJointFor(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].getJointFor(righthand).position,0,player[i].rotation,0)*player[i].scale);
                                                                     Normalise(&aim);
 
                                                                     aim=DoRotation(aim,(float)abs(Random()%30)-15,(float)abs(Random()%30)-15,0);
@@ -6901,7 +7111,7 @@ void Game::Tick(){
                                     isgood=false;
                             if(isgood&&player[i].creature!=wolftype){
                                 if(player[i].isIdle()&&player[i].num_weapons&&weapons[player[i].weaponids[0]].getType()==knife){
-                                    setAnimation(i,drawrightanim);
+                                    player[i].setAnimation(drawrightanim);
                                     player[i].drawtogglekeydown=1;
                                 }
                                 if((player[i].isIdle()||
@@ -6910,11 +7120,11 @@ void Game::Tick(){
                                              player[i].isRun()))&&
                                         player[i].num_weapons&&
                                         weapons[player[i].weaponids[0]].getType()==sword){
-                                    setAnimation(i,drawleftanim);
+                                    player[i].setAnimation(drawleftanim);
                                     player[i].drawtogglekeydown=1;
                                 }
                                 if(player[i].isCrouch()&&player[i].num_weapons&&weapons[player[i].weaponids[0]].getType()==knife){
-                                    setAnimation(i,crouchdrawrightanim);
+                                    player[i].setAnimation(crouchdrawrightanim);
                                     player[i].drawtogglekeydown=1;
                                 }
                             }
@@ -6931,9 +7141,9 @@ void Game::Tick(){
                                                        player[i].attackkeydown&&
                                                        musictype!=stream_fighttheme) {
                                                                if(weapons[player[i].weaponids[player[i].weaponactive]].getType()==knife)
-                                                                       setAnimation(i,crouchstabanim);
+                                                                       player[i].setAnimation(crouchstabanim);
                                                                if(weapons[player[i].weaponids[player[i].weaponactive]].getType()==sword)
-                                                                       setAnimation(i,swordgroundstabanim);
+                                                                       player[i].setAnimation(swordgroundstabanim);
                                                                player[i].hasvictim=0;
                                                }
                                        }
@@ -7006,7 +7216,7 @@ void Game::Tick(){
                             player[i].lowreversaldelay=.5;
 
                             if(player[i].isIdle()){
-                                setAnimation(i,player[i].getCrouch());
+                                player[i].setAnimation(player[i].getCrouch());
                                 player[i].transspeed=10;
                             }
                             if(player[i].isRun()||
@@ -7015,7 +7225,7 @@ void Game::Tick(){
                                       player[i].rightkeydown||
                                       player[i].forwardkeydown||
                                       player[i].backkeydown))){
-                                setAnimation(i,rollanim);
+                                player[i].setAnimation(rollanim);
                                 player[i].transspeed=20;
                             }
                         }
@@ -7050,12 +7260,12 @@ void Game::Tick(){
                                         player[i].currentanimation=player[i].getCrouch();
                                         player[i].currentframe=0;
                                     }
-                                    setAnimation(i,player[i].getIdle());
+                                    player[i].setAnimation(player[i].getIdle());
                                     player[i].transspeed=10;
                                 }
                             }
                             if(player[i].targetanimation==sneakanim){
-                                setAnimation(i,player[i].getIdle());
+                                player[i].setAnimation(player[i].getIdle());
                                 player[i].transspeed=10;
                             }
                         }
@@ -7071,9 +7281,9 @@ void Game::Tick(){
                                      !player[i].jumpkeydown&&
                                      player[i].crouchkeydown)){
                                 if(player[i].aitype==passivetype)
-                                    setAnimation(i,walkanim);
+                                    player[i].setAnimation(walkanim);
                                 else
-                                    setAnimation(i,player[i].getRun());
+                                    player[i].setAnimation(player[i].getRun());
                             }
                             if(player[i].isCrouch()){
                                 player[i].targetanimation=sneakanim;
@@ -7082,7 +7292,7 @@ void Game::Tick(){
                                 player[i].targetframe=0;
                             }
                             if(player[i].targetanimation==hanganim/*&&(!player[i].forwardstogglekeydown||player[i].aitype!=playercontrolled)*/){
-                                setAnimation(i,climbanim);
+                                player[i].setAnimation(climbanim);
                                 player[i].targetframe=1;
                                 player[i].jumpclimb=1;
                             }
@@ -7103,7 +7313,7 @@ void Game::Tick(){
                                      player[i].targetframe>0&&
                                      !player[i].jumpkeydown&&
                                      player[i].crouchkeydown)){
-                                setAnimation(i,player[i].getRun());
+                                player[i].setAnimation(player[i].getRun());
                             }
                             if(player[i].isCrouch()){
                                 player[i].targetanimation=sneakanim;
@@ -7130,7 +7340,7 @@ void Game::Tick(){
                                      player[i].targetframe>0&&
                                      !player[i].jumpkeydown&&
                                      player[i].crouchkeydown)){
-                                setAnimation(i,player[i].getRun());
+                                player[i].setAnimation(player[i].getRun());
                             }
                             if(player[i].isCrouch()){
                                 player[i].targetanimation=sneakanim;
@@ -7157,7 +7367,7 @@ void Game::Tick(){
                                      player[i].targetframe>0&&
                                      !player[i].jumpkeydown&&
                                      player[i].crouchkeydown)){
-                                setAnimation(i,player[i].getRun());
+                                player[i].setAnimation(player[i].getRun());
                             }
                             if(player[i].isCrouch()){
                                 player[i].targetanimation=sneakanim;
@@ -7193,7 +7403,7 @@ void Game::Tick(){
                                     ((player[i].targetanimation!=rabbitrunninganim&&
                                       player[i].targetanimation!=wolfrunninganim)||i!=0)){
                                 player[i].jumpstart=0;
-                                setAnimation(i,jumpupanim);
+                                player[i].setAnimation(jumpupanim);
                                 player[i].rotation=player[i].targetrotation;
                                 player[i].transspeed=20;
                                 player[i].FootLand(0,1);
@@ -7240,7 +7450,7 @@ void Game::Tick(){
                                     emit_sound_at(jumpsound, player[i].coords, 128.);
                             }
                             if((player[i].isIdle())&&player[i].jumppower>1){
-                                setAnimation(i,player[i].getLanding());
+                                player[i].setAnimation(player[i].getLanding());
                                 player[i].targetframe=2;
                                 player[i].landhard=0;
                                 player[i].jumpstart=1;
@@ -7265,7 +7475,7 @@ void Game::Tick(){
 
                         if(!movekey){
                             if(player[i].isRun()||player[i].targetanimation==walkanim)
-                                setAnimation(i,player[i].getStop());
+                                player[i].setAnimation(player[i].getStop());
                             if(player[i].targetanimation==sneakanim){
                                 player[i].targetanimation=player[i].getCrouch();
                                 if(player[i].currentanimation==sneakanim)
@@ -7278,9 +7488,9 @@ void Game::Tick(){
                                  player[i].aitype==searchtype||
                                  (player[i].aitype==passivetype&&
                                   player[i].numwaypoints<=1)))
-                            setAnimation(i,player[i].getStop());
+                            player[i].setAnimation(player[i].getStop());
                         if(player[i].isRun()&&(player[i].aitype==passivetype))
-                            setAnimation(i,player[i].getStop());
+                            player[i].setAnimation(player[i].getStop());
                     }
                 }
                 if(player[i].targetanimation==rollanim)
@@ -7298,7 +7508,7 @@ void Game::Tick(){
 
                 //stop to turn in right direction
                 if(fabs(player[k].rotation-player[k].targetrotation)>90&&(player[k].isRun()||player[k].targetanimation==walkanim))
-                    setAnimation(k,player[k].getStop());
+                    player[k].setAnimation(player[k].getStop());
 
                 if(player[k].targetanimation==backhandspringanim||player[k].targetanimation==dodgebackanim)
                     player[k].targettilt=0;
@@ -7609,11 +7819,11 @@ void Game::TickOnceAfter(){
             killhotspot=0;
 
 
-               winhotspot=0;
+               winhotspot=false;
                for(int i=0;i<numhotspots;i++)
                        if(hotspottype[i]==-1)
                                if(findDistancefast(&player[0].coords,&hotspot[i])<hotspotsize[i])
-                                       winhotspot=1;
+                                       winhotspot=true;
 
                int numalarmed=0;
                for(int i=1;i<numplayers;i++)
@@ -7627,18 +7837,21 @@ void Game::TickOnceAfter(){
                                changedelay=1;
                                targetlevel=whichlevel;
                        }
-                       alldead=1;
-                       for(int i=1;i<numplayers;i++)
-                               if(!player[i].dead&&player[i].howactive<typedead1)
-                    alldead=0;
+                       alldead=true;
+                       for(int i=1;i<numplayers;i++) {
+                               if(!player[i].dead&&player[i].howactive<typedead1) {
+                    alldead=false;
+                    break;
+                               }
+                       }
 
 
-                       if(alldead&&!player[0].dead&&maptype==mapkilleveryone){
+                       if(alldead&&!player[0].dead&&maptype==mapkilleveryone) {
                                changedelay=1;
                                targetlevel=whichlevel+1;
                                if(targetlevel>numchallengelevels-1)targetlevel=0;
                        }
-                       if(winhotspot||windialogue){
+                       if(winhotspot||windialogue) {
                                changedelay=0.1;
                                targetlevel=whichlevel+1;
                                if(targetlevel>numchallengelevels-1)targetlevel=0;
@@ -7668,8 +7881,8 @@ void Game::TickOnceAfter(){
                        if(leveltime<1){
                                loading=0;
                                changedelay=.1;
-                               alldead=0;
-                               winhotspot=0;
+                               alldead=false;
+                               winhotspot=false;
                                killhotspot=0;
                        }