]> git.jsancho.org Git - lugaru.git/blobdiff - Source/Skeleton.cpp
convert Game class to namespace
[lugaru.git] / Source / Skeleton.cpp
index 8b7c18a33f5182ff04beca5c9be9b77d95e198c0..b338724bf0a529062597b42eb61771eb7eb17f28 100644 (file)
@@ -1,16 +1,36 @@
+/*
+Copyright (C) 2003, 2010 - Wolfire Games
+
+This file is part of Lugaru.
+
+Lugaru is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+*/
+
 /**> HEADER FILES <**/
+#include "Game.h"
 #include "Skeleton.h"
+#include "openal_wrapper.h"
+#include "Animation.h"
 
 extern float multiplier;
 extern float gravity;
 extern Skeleton testskeleton;
 extern Terrain terrain;
-extern FSOUND_SAMPLE   *samp[100];
-extern int channels[100];
 extern Objects objects;
-extern Sprites sprites;
 extern int environment;
-extern float terraindetail;
 extern float camerashake;
 extern bool freeze;
 extern int detail;
@@ -18,23 +38,20 @@ extern XYZ envsound[30];
 extern float envsoundvol[30];
 extern int numenvsounds;
 extern float envsoundlife[30];
-extern int bonus;
-extern float bonustime;
 extern int tutoriallevel;
 
 extern int whichjointstartarray[26];
 extern int whichjointendarray[26];
 
-#include "Game.h"
-extern Game * pgame;
 extern bool visibleloading;
-extern "C"     void PlaySoundEx(int channel, FSOUND_SAMPLE *sptr, FSOUND_DSPUNIT *dsp, signed char startpaused);
 
 void dealloc2(void* param){
        free(param);
        param=0;
 }
 
+enum {boneconnect, constraint, muscle};
+
 void Muscle::DoConstraint(bool spinny)
 {
        static XYZ vel;
@@ -175,14 +192,14 @@ float Skeleton::DoConstraints(XYZ *coords,float *scale)
        if(free){
                freetime+=multiplier;
 
-               whichpatchx=coords->x/(terrain.size/subdivision*terrain.scale*terraindetail);
-               whichpatchz=coords->z/(terrain.size/subdivision*terrain.scale*terraindetail);
+               whichpatchx=coords->x/(terrain.size/subdivision*terrain.scale);
+               whichpatchz=coords->z/(terrain.size/subdivision*terrain.scale);
 
                terrainlight=*coords;
                objects.SphereCheckPossible(&terrainlight, 1);
                /*
                for(i=0; i<num_joints; i++){
-               oldpos[i]=joints[i].position;           
+               oldpos[i]=joints[i].position;
                }*/
 
                //Add velocity
@@ -190,9 +207,9 @@ float Skeleton::DoConstraints(XYZ *coords,float *scale)
                        //if(!isnormal(joints[i].velocity.x)||!isnormal(joints[i].velocity.y)||!isnormal(joints[i].velocity.z))joints[i].velocity=0;
                        joints[i].position=joints[i].position+joints[i].velocity*multiplier;
                        groundlevel=.15;
-                       if(joints[i].label==head)groundlevel=.8;        
-                       if(joints[i].label==righthand||joints[i].label==rightwrist||joints[i].label==rightelbow)groundlevel=.2; 
-                       if(joints[i].label==lefthand||joints[i].label==leftwrist||joints[i].label==leftelbow)groundlevel=.2;                    
+                       if(joints[i].label==head)groundlevel=.8;
+                       if(joints[i].label==righthand||joints[i].label==rightwrist||joints[i].label==rightelbow)groundlevel=.2;
+                       if(joints[i].label==lefthand||joints[i].label==leftwrist||joints[i].label==leftelbow)groundlevel=.2;
                        joints[i].position.y-=groundlevel;
                        //if(!joints[i].locked&&!broken)joints[i].velocity+=joints[i].velchange*multiplier*10*(500-longdead)/500;
                        joints[i].oldvelocity=joints[i].velocity;
@@ -230,136 +247,6 @@ float Skeleton::DoConstraints(XYZ *coords,float *scale)
                                        temp=joints[jointlabels[leftknee]].position-(joints[jointlabels[lefthip]].position+joints[jointlabels[leftankle]].position)/2;
                                }
                        }
-                       /*
-                       if(terrain.patchobjectnum[whichpatchx][whichpatchz])
-                       for(m=0;m<terrain.patchobjectnum[whichpatchx][whichpatchz];m++){
-                       k=terrain.patchobjects[whichpatchx][whichpatchz][m];
-                       if(k<objects.numobjects&&k>=0)
-                       if(objects.possible[k]){
-                       temp=joints[jointlabels[head]].position*(*scale)+*coords;
-                       if(objects.model[k].SphereCheck(&temp, 0.06, &start, &objects.position[k], &objects.rotation[k])!=-1){
-                       //temp=(joints[jointlabels[head]].position*(*scale)+*coords)-start;
-                       //Normalise(&temp);
-                       //joints[jointlabels[head]].position=((temp*.2+start)-*coords)/(*scale);
-                       joints[jointlabels[head]].position=(temp-*coords)/(*scale);
-                       }
-                       }
-                       }       */
-
-
-                       //Ears check
-                       /*XYZ startheadpos;
-                       startheadpos=joints[jointlabels[head]].position;
-                       XYZ headpos;
-                       headpos=joints[jointlabels[head]].position+(joints[jointlabels[head]].position-joints[jointlabels[neck]].position);
-                       if(terrain.patchobjectnum[whichpatchx][whichpatchz])
-                       for(m=0;m<terrain.patchobjectnum[whichpatchx][whichpatchz];m++){
-                       k=terrain.patchobjects[whichpatchx][whichpatchz][m];
-                       if(k<objects.numobjects&&k>=0)
-                       if(objects.possible[k]){
-                       friction=objects.friction[k];
-                       start=joints[jointlabels[head]].position*(*scale)+*coords;
-                       end=(headpos)*(*scale)+*coords;
-                       whichhit=objects.model[k].LineCheckPossible(&start,&end,&temp,&objects.position[k],&objects.rotation[k]);
-                       if(whichhit!=-1){
-                       if(joints[jointlabels[head]].label==groin&&!joints[jointlabels[head]].locked&&joints[jointlabels[head]].delay<=0){
-                       joints[jointlabels[head]].locked=1;
-                       joints[jointlabels[head]].delay=1;
-                       static float gLoc[3];
-                       static float vel[3];
-                       gLoc[0]=headpos.x*(*scale)+coords->x;
-                       gLoc[1]=headpos.y*(*scale)+coords->y;
-                       gLoc[2]=headpos.z*(*scale)+coords->z;
-                       vel[0]=joints[jointlabels[head]].velocity.x;
-                       vel[1]=joints[jointlabels[head]].velocity.y;
-                       vel[2]=joints[jointlabels[head]].velocity.z;
-                       PlaySoundEx( landsound1, samp[landsound1], NULL, TRUE);
-                       FSOUND_3D_SetAttributes(channels[landsound1], gLoc, vel);
-                       FSOUND_SetVolume(channels[landsound1], 128);
-                       FSOUND_SetPaused(channels[landsound1], FALSE);
-
-                       breaking=1;
-                       }
-
-                       if(joints[jointlabels[head]].label==head&&!joints[jointlabels[head]].locked&&joints[jointlabels[head]].delay<=0){
-                       joints[jointlabels[head]].locked=1;
-                       joints[jointlabels[head]].delay=1;
-                       static float gLoc[3];
-                       static float vel[3];
-                       gLoc[0]=headpos.x*(*scale)+coords->x;
-                       gLoc[1]=headpos.y*(*scale)+coords->y;
-                       gLoc[2]=headpos.z*(*scale)+coords->z;
-                       vel[0]=joints[jointlabels[head]].velocity.x;
-                       vel[1]=joints[jointlabels[head]].velocity.y;
-                       vel[2]=joints[jointlabels[head]].velocity.z;
-                       PlaySoundEx( landsound2, samp[landsound2], NULL, TRUE);
-                       FSOUND_3D_SetAttributes(channels[landsound2], gLoc, vel);
-                       FSOUND_SetVolume(channels[landsound2], 128);
-                       FSOUND_SetPaused(channels[landsound2], FALSE);
-                       }
-
-                       terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
-                       if(terrainnormal.y>.8)freefall=0;
-                       bounceness=terrainnormal*findLength(&joints[jointlabels[head]].velocity)*(abs(normaldotproduct(joints[jointlabels[head]].velocity,terrainnormal)));
-                       if(findLengthfast(&joints[jointlabels[head]].velocity)>findLengthfast(&joints[jointlabels[head]].oldvelocity)){
-                       bounceness=0;
-                       joints[jointlabels[head]].velocity=joints[jointlabels[head]].oldvelocity;
-                       }
-                       if(findLengthfast(&bounceness)>4000&&breaking){
-                       objects.model[k].MakeDecal(breakdecal,DoRotation(temp-objects.position[k],0,-objects.rotation[k],0),.4,.5,Random()%360);
-                       sprites.MakeSprite(cloudsprite, headpos*(*scale)+*coords,joints[jointlabels[head]].velocity*.06, 1,1,1, 4, .2);
-                       breaking=0;
-                       camerashake+=.6;
-
-                       static float gLoc[3];
-                       static float vel[3];
-                       gLoc[0]=headpos.x*(*scale)+coords->x;
-                       gLoc[1]=headpos.y*(*scale)+coords->y;
-                       gLoc[2]=headpos.z*(*scale)+coords->z;
-                       vel[0]=joints[jointlabels[head]].velocity.x;
-                       vel[1]=joints[jointlabels[head]].velocity.y;
-                       vel[2]=joints[jointlabels[head]].velocity.z;
-                       PlaySoundEx( breaksound2, samp[breaksound2], NULL, TRUE);
-                       FSOUND_3D_SetAttributes(channels[breaksound2], gLoc, vel);
-                       FSOUND_SetVolume(channels[breaksound2], 300);
-                       FSOUND_SetPaused(channels[breaksound2], FALSE);
-
-                       envsound[numenvsounds]=*coords;
-                       envsoundvol[numenvsounds]=64;
-                       envsoundlife[numenvsounds]=.4;
-                       numenvsounds++;
-                       }
-                       if(objects.type[k]==treetrunktype){
-                       objects.rotx[k]+=joints[jointlabels[head]].velocity.x*multiplier*.4;
-                       objects.roty[k]+=joints[jointlabels[head]].velocity.z*multiplier*.4;
-                       objects.rotx[k+1]+=joints[jointlabels[head]].velocity.x*multiplier*.4;
-                       objects.roty[k+1]+=joints[jointlabels[head]].velocity.z*multiplier*.4;
-                       }
-                       if(!joints[jointlabels[head]].locked)damage+=findLengthfast(&bounceness)/2500;
-                       ReflectVector(&joints[jointlabels[head]].velocity,&terrainnormal);
-                       frictionness=abs(normaldotproduct(joints[jointlabels[head]].velocity,terrainnormal));//findLength(&bounceness)/findLength(&joints[jointlabels[head]].velocity);
-                       joints[jointlabels[head]].velocity-=bounceness;
-                       if(1-friction*frictionness>0)joints[jointlabels[head]].velocity*=1-friction*frictionness;
-                       else joints[jointlabels[head]].velocity=0;
-                       if(findLengthfast(&bounceness)>2500){
-                       Normalise(&bounceness);
-                       bounceness=bounceness*50;
-                       }
-                       joints[jointlabels[head]].velocity+=bounceness*elasticity;
-
-
-                       if(!joints[jointlabels[head]].locked)
-                       if(findLengthfast(&joints[jointlabels[head]].velocity)<1){
-                       joints[jointlabels[head]].locked=1;
-                       //joints[jointlabels[head]].velocity*=3;
-                       }
-                       if(findLengthfast(&bounceness)>500)sprites.MakeSprite(cloudsprite, headpos*(*scale)+*coords,joints[jointlabels[head]].velocity*.06, 1,1,1, .5, .2);
-                       joints[jointlabels[head]].position=(temp-*coords)/(*scale)+(startheadpos-headpos)+terrainnormal*.005;
-                       if(longdead>100)broken=1;
-                       }
-                       }
-                       }
-                       */
 
                        for(i=0; i<num_joints; i++){
                                //joints[i].delay-=multiplier/1.5;
@@ -395,19 +282,8 @@ float Skeleton::DoConstraints(XYZ *coords,float *scale)
                                                if(joints[i].label==groin&&!joints[i].locked&&joints[i].delay<=0){
                                                        joints[i].locked=1;
                                                        joints[i].delay=1;
-                                                       static float gLoc[3];
-                                                       static float vel[3];
-                                                       gLoc[0]=joints[i].position.x*(*scale)+coords->x;
-                                                       gLoc[1]=joints[i].position.y*(*scale)+coords->y;
-                                                       gLoc[2]=joints[i].position.z*(*scale)+coords->z;
-                                                       vel[0]=joints[i].velocity.x;
-                                                       vel[1]=joints[i].velocity.y;
-                                                       vel[2]=joints[i].velocity.z;
                                                        if(tutoriallevel!=1||id==0){
-                                                               PlaySoundEx( landsound1, samp[landsound1], NULL, TRUE);
-                                                               FSOUND_3D_SetAttributes(channels[landsound1], gLoc, vel);
-                                                               FSOUND_SetVolume(channels[landsound1], 128);
-                                                               FSOUND_SetPaused(channels[landsound1], FALSE);
+                                                               emit_sound_at(landsound1, joints[i].position*(*scale)+*coords, 128.);
                                                        }
                                                        breaking=1;
                                                }
@@ -415,19 +291,8 @@ float Skeleton::DoConstraints(XYZ *coords,float *scale)
                                                if(joints[i].label==head&&!joints[i].locked&&joints[i].delay<=0){
                                                        joints[i].locked=1;
                                                        joints[i].delay=1;
-                                                       static float gLoc[3];
-                                                       static float vel[3];
-                                                       gLoc[0]=joints[i].position.x*(*scale)+coords->x;
-                                                       gLoc[1]=joints[i].position.y*(*scale)+coords->y;
-                                                       gLoc[2]=joints[i].position.z*(*scale)+coords->z;
-                                                       vel[0]=joints[i].velocity.x;
-                                                       vel[1]=joints[i].velocity.y;
-                                                       vel[2]=joints[i].velocity.z;
                                                        if(tutoriallevel!=1||id==0){
-                                                               PlaySoundEx( landsound2, samp[landsound2], NULL, TRUE);
-                                                               FSOUND_3D_SetAttributes(channels[landsound2], gLoc, vel);
-                                                               FSOUND_SetVolume(channels[landsound2], 128);
-                                                               FSOUND_SetPaused(channels[landsound2], FALSE);
+                                                               emit_sound_at(landsound2, joints[i].position*(*scale)+*coords, 128.);
                                                        }
                                                }
 
@@ -444,23 +309,12 @@ float Skeleton::DoConstraints(XYZ *coords,float *scale)
                                                if(tutoriallevel!=1||id==0)
                                                        if(findLengthfast(&bounceness)>8000&&breaking){
                                                                objects.model[k].MakeDecal(breakdecal,DoRotation(temp-objects.position[k],0,-objects.rotation[k],0),.4,.5,Random()%360);
-                                                               sprites.MakeSprite(cloudsprite, joints[i].position*(*scale)+*coords,joints[i].velocity*.06, 1,1,1, 4, .2);
-                                                               //sprites.MakeSprite(cloudsprite, joints[i].position*(*scale)+*coords,joints[i].velocity*.06, 1,1,1, 1, .2);
+                                                               Sprite::MakeSprite(cloudsprite, joints[i].position*(*scale)+*coords,joints[i].velocity*.06, 1,1,1, 4, .2);
+                                                               //Sprite::MakeSprite(cloudsprite, joints[i].position*(*scale)+*coords,joints[i].velocity*.06, 1,1,1, 1, .2);
                                                                breaking=0;
                                                                camerashake+=.6;
 
-                                                               static float gLoc[3];
-                                                               static float vel[3];
-                                                               gLoc[0]=joints[i].position.x*(*scale)+coords->x;
-                                                               gLoc[1]=joints[i].position.y*(*scale)+coords->y;
-                                                               gLoc[2]=joints[i].position.z*(*scale)+coords->z;
-                                                               vel[0]=joints[i].velocity.x;
-                                                               vel[1]=joints[i].velocity.y;
-                                                               vel[2]=joints[i].velocity.z;
-                                                               PlaySoundEx( breaksound2, samp[breaksound2], NULL, TRUE);
-                                                               FSOUND_3D_SetAttributes(channels[breaksound2], gLoc, vel);
-                                                               FSOUND_SetVolume(channels[breaksound2], 300);
-                                                               FSOUND_SetPaused(channels[breaksound2], FALSE);
+                                                               emit_sound_at(breaksound2, joints[i].position*(*scale)+*coords);
 
                                                                envsound[numenvsounds]=*coords;
                                                                envsoundvol[numenvsounds]=64;
@@ -471,7 +325,7 @@ float Skeleton::DoConstraints(XYZ *coords,float *scale)
                                                        if(findLengthfast(&bounceness)>2500){
                                                                Normalise(&bounceness);
                                                                bounceness=bounceness*50;
-                                                       }       
+                                                       }
 
                                                        joints[i].velocity+=bounceness*elasticity;
 
@@ -486,19 +340,19 @@ float Skeleton::DoConstraints(XYZ *coords,float *scale)
 
                                                        if(environment==snowyenvironment&&findLengthfast(&bounceness)>500&&terrain.getOpacity(joints[i].position.x*(*scale)+coords->x,joints[i].position.z*(*scale)+coords->z)<.2){
                                                                terrainlight=terrain.getLighting(joints[i].position.x*(*scale)+coords->x,joints[i].position.z*(*scale)+coords->z);
-                                                               sprites.MakeSprite(cloudsprite, joints[i].position*(*scale)+*coords,joints[i].velocity*.06, terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
+                                                               Sprite::MakeSprite(cloudsprite, joints[i].position*(*scale)+*coords,joints[i].velocity*.06, terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
                                                                if(detail==2)terrain.MakeDecal(bodyprintdecal, joints[i].position*(*scale)+*coords,.4,.4,0);
                                                        }
                                                        else if(environment==desertenvironment&&findLengthfast(&bounceness)>500&&terrain.getOpacity(joints[i].position.x*(*scale)+coords->x,joints[i].position.z*(*scale)+coords->z)<.2){
                                                                terrainlight=terrain.getLighting(joints[i].position.x*(*scale)+coords->x,joints[i].position.z*(*scale)+coords->z);
-                                                               sprites.MakeSprite(cloudsprite, joints[i].position*(*scale)+*coords,joints[i].velocity*.06, terrainlight.x*190/255,terrainlight.y*170/255,terrainlight.z*108/255, .5, .7);
+                                                               Sprite::MakeSprite(cloudsprite, joints[i].position*(*scale)+*coords,joints[i].velocity*.06, terrainlight.x*190/255,terrainlight.y*170/255,terrainlight.z*108/255, .5, .7);
                                                        }
 
                                                        else if(environment==grassyenvironment&&findLengthfast(&bounceness)>500&&terrain.getOpacity(joints[i].position.x*(*scale)+coords->x,joints[i].position.z*(*scale)+coords->z)<.2){
                                                                terrainlight=terrain.getLighting(joints[i].position.x*(*scale)+coords->x,joints[i].position.z*(*scale)+coords->z);
-                                                               sprites.MakeSprite(cloudsprite, joints[i].position*(*scale)+*coords,joints[i].velocity*.06, terrainlight.x*90/255,terrainlight.y*70/255,terrainlight.z*8/255, .5, .5);
+                                                               Sprite::MakeSprite(cloudsprite, joints[i].position*(*scale)+*coords,joints[i].velocity*.06, terrainlight.x*90/255,terrainlight.y*70/255,terrainlight.z*8/255, .5, .5);
                                                        }
-                                                       else if(findLengthfast(&bounceness)>500)sprites.MakeSprite(cloudsprite, joints[i].position*(*scale)+*coords,joints[i].velocity*.06, terrainlight.x,terrainlight.y,terrainlight.z, .5, .2);
+                                                       else if(findLengthfast(&bounceness)>500)Sprite::MakeSprite(cloudsprite, joints[i].position*(*scale)+*coords,joints[i].velocity*.06, terrainlight.x,terrainlight.y,terrainlight.z, .5, .2);
 
 
                                                        joints[i].position.y=(terrain.getHeight(joints[i].position.x*(*scale)+coords->x,joints[i].position.z*(*scale)+coords->z)+groundlevel-coords->y)/(*scale);
@@ -517,19 +371,8 @@ float Skeleton::DoConstraints(XYZ *coords,float *scale)
                                                                                if(joints[i].label==groin&&!joints[i].locked&&joints[i].delay<=0){
                                                                                        joints[i].locked=1;
                                                                                        joints[i].delay=1;
-                                                                                       static float gLoc[3];
-                                                                                       static float vel[3];
-                                                                                       gLoc[0]=joints[i].position.x*(*scale)+coords->x;
-                                                                                       gLoc[1]=joints[i].position.y*(*scale)+coords->y;
-                                                                                       gLoc[2]=joints[i].position.z*(*scale)+coords->z;
-                                                                                       vel[0]=joints[i].velocity.x;
-                                                                                       vel[1]=joints[i].velocity.y;
-                                                                                       vel[2]=joints[i].velocity.z;
                                                                                        if(tutoriallevel!=1||id==0){
-                                                                                               PlaySoundEx( landsound1, samp[landsound1], NULL, TRUE);
-                                                                                               FSOUND_3D_SetAttributes(channels[landsound1], gLoc, vel);
-                                                                                               FSOUND_SetVolume(channels[landsound1], 128);
-                                                                                               FSOUND_SetPaused(channels[landsound1], FALSE);
+                                                                                               emit_sound_at(landsound1, joints[i].position*(*scale)+*coords, 128.);
                                                                                        }
                                                                                        breaking=1;
                                                                                }
@@ -537,19 +380,8 @@ float Skeleton::DoConstraints(XYZ *coords,float *scale)
                                                                                if(joints[i].label==head&&!joints[i].locked&&joints[i].delay<=0){
                                                                                        joints[i].locked=1;
                                                                                        joints[i].delay=1;
-                                                                                       static float gLoc[3];
-                                                                                       static float vel[3];
-                                                                                       gLoc[0]=joints[i].position.x*(*scale)+coords->x;
-                                                                                       gLoc[1]=joints[i].position.y*(*scale)+coords->y;
-                                                                                       gLoc[2]=joints[i].position.z*(*scale)+coords->z;
-                                                                                       vel[0]=joints[i].velocity.x;
-                                                                                       vel[1]=joints[i].velocity.y;
-                                                                                       vel[2]=joints[i].velocity.z;
                                                                                        if(tutoriallevel!=1||id==0){
-                                                                                               PlaySoundEx( landsound2, samp[landsound2], NULL, TRUE);
-                                                                                               FSOUND_3D_SetAttributes(channels[landsound2], gLoc, vel);
-                                                                                               FSOUND_SetVolume(channels[landsound2], 128);
-                                                                                               FSOUND_SetPaused(channels[landsound2], FALSE);
+                                                                                               emit_sound_at(landsound2, joints[i].position*(*scale)+*coords, 128.);
                                                                                        }
                                                                                }
 
@@ -563,22 +395,11 @@ float Skeleton::DoConstraints(XYZ *coords,float *scale)
                                                                                if(tutoriallevel!=1||id==0)
                                                                                        if(findLengthfast(&bounceness)>4000&&breaking){
                                                                                                objects.model[k].MakeDecal(breakdecal,DoRotation(temp-objects.position[k],0,-objects.rotation[k],0),.4,.5,Random()%360);
-                                                                                               sprites.MakeSprite(cloudsprite, joints[i].position*(*scale)+*coords,joints[i].velocity*.06, 1,1,1, 4, .2);
+                                                                                               Sprite::MakeSprite(cloudsprite, joints[i].position*(*scale)+*coords,joints[i].velocity*.06, 1,1,1, 4, .2);
                                                                                                breaking=0;
                                                                                                camerashake+=.6;
 
-                                                                                               static float gLoc[3];
-                                                                                               static float vel[3];
-                                                                                               gLoc[0]=joints[i].position.x*(*scale)+coords->x;
-                                                                                               gLoc[1]=joints[i].position.y*(*scale)+coords->y;
-                                                                                               gLoc[2]=joints[i].position.z*(*scale)+coords->z;
-                                                                                               vel[0]=joints[i].velocity.x;
-                                                                                               vel[1]=joints[i].velocity.y;
-                                                                                               vel[2]=joints[i].velocity.z;
-                                                                                               PlaySoundEx( breaksound2, samp[breaksound2], NULL, TRUE);
-                                                                                               FSOUND_3D_SetAttributes(channels[breaksound2], gLoc, vel);
-                                                                                               FSOUND_SetVolume(channels[breaksound2], 300);
-                                                                                               FSOUND_SetPaused(channels[breaksound2], FALSE);
+                                                                                               emit_sound_at(breaksound2, joints[i].position*(*scale)+*coords);
 
                                                                                                envsound[numenvsounds]=*coords;
                                                                                                envsoundvol[numenvsounds]=64;
@@ -602,8 +423,8 @@ float Skeleton::DoConstraints(XYZ *coords,float *scale)
                                                                                                pos.x+=float(abs(Random()%100)-50)/100*objects.scale[k]*5;
                                                                                                pos.y+=float(abs(Random()%100)-50)/100*objects.scale[k]*15;
                                                                                                pos.z+=float(abs(Random()%100)-50)/100*objects.scale[k]*5;
-                                                                                               sprites.MakeSprite(splintersprite, pos,tempvel*.5, 165/255+float(abs(Random()%100)-50)/400,0,0, .2+float(abs(Random()%100)-50)/1300, 1);
-                                                                                               sprites.special[sprites.numsprites-1]=1;
+                                                                                               Sprite::MakeSprite(splintersprite, pos,tempvel*.5, 165/255+float(abs(Random()%100)-50)/400,0,0, .2+float(abs(Random()%100)-50)/1300, 1);
+                                                                                               Sprite::special[Sprite::numsprites-1]=1;
                                                                                                }*/
                                                                                                objects.rotx[k]+=joints[i].velocity.x*multiplier*.4;
                                                                                                objects.roty[k]+=joints[i].velocity.z*multiplier*.4;
@@ -628,7 +449,7 @@ float Skeleton::DoConstraints(XYZ *coords,float *scale)
                                                                                                        joints[i].locked=1;
                                                                                                        //joints[i].velocity*=3;
                                                                                                }
-                                                                                               if(findLengthfast(&bounceness)>500)sprites.MakeSprite(cloudsprite, joints[i].position*(*scale)+*coords,joints[i].velocity*.06, 1,1,1, .5, .2);
+                                                                                               if(findLengthfast(&bounceness)>500)Sprite::MakeSprite(cloudsprite, joints[i].position*(*scale)+*coords,joints[i].velocity*.06, 1,1,1, .5, .2);
                                                                                                joints[i].position=(temp-*coords)/(*scale)+terrainnormal*.005;
                                                                                                if(longdead>100)broken=1;
                                                                        }
@@ -662,9 +483,9 @@ float Skeleton::DoConstraints(XYZ *coords,float *scale)
 
                        for(i=0; i<num_joints; i++){
                                groundlevel=.15;
-                               if(joints[i].label==head)groundlevel=.8;        
-                               if(joints[i].label==righthand||joints[i].label==rightwrist||joints[i].label==rightelbow)groundlevel=.2; 
-                               if(joints[i].label==lefthand||joints[i].label==leftwrist||joints[i].label==leftelbow)groundlevel=.2;                    
+                               if(joints[i].label==head)groundlevel=.8;
+                               if(joints[i].label==righthand||joints[i].label==rightwrist||joints[i].label==rightelbow)groundlevel=.2;
+                               if(joints[i].label==lefthand||joints[i].label==leftwrist||joints[i].label==leftelbow)groundlevel=.2;
                                joints[i].position.y+=groundlevel;
                                joints[i].mass=1;
                                if(joints[i].label==lefthip||joints[i].label==leftknee||joints[i].label==leftankle||joints[i].label==righthip||joints[i].label==rightknee||joints[i].label==rightankle)joints[i].mass=2;
@@ -779,7 +600,7 @@ void Skeleton::Draw(int  muscleview)
                                glVertex3f(muscles[i].parent1->position.x,muscles[i].parent1->position.y,muscles[i].parent1->position.z);
                                glVertex3f(muscles[i].parent2->position.x,muscles[i].parent2->position.y,muscles[i].parent2->position.z);
                        }
-               }       
+               }
                glEnd();
 
                if(muscleview!=2){
@@ -885,12 +706,13 @@ void Skeleton::SetJoint(float x, float y, float z, int which, int whichjoint)
                        joints[whichjoint].parent=&joints[which];
                        joints[whichjoint].hasparent=1;
                        joints[whichjoint].length=findDistance(&joints[whichjoint].position,&joints[whichjoint].parent->position);
-               }       
+               }
        }
 }
 
 void Skeleton::AddMuscle(int attach1,int attach2,float minlength,float maxlength,int type)
 {
+       const int max_muscles = 100; // FIXME: Probably can be dropped
        if(num_muscles<max_muscles-1&&attach1<num_joints&&attach1>=0&&attach2<num_joints&&attach2>=0&&attach1!=attach2){
                muscles[num_muscles].parent1=&joints[attach1];
                muscles[num_muscles].parent2=&joints[attach2];
@@ -986,25 +808,35 @@ void Skeleton::FindRotationMuscle(int which, int animation)
        if(!isnormal(muscles[which].rotate3))muscles[which].rotate3=0;
 }
 
-void Animation::Load(char *filename, int aheight, int aattack)
+void Animation::Load(const char *filename, int aheight, int aattack)
 {
        static FILE *tfile;
        static int i,j;
        static XYZ startoffset,endoffset;
        static int howmany;
 
+       static const char *anim_prefix = ":Data:Animations:";
+
+
        LOGFUNC;
 
-       LOG(std::string("Loading animation...") + filename);
+       int len = strlen(anim_prefix) + strlen(filename);
+       char *buf = new char[len + 1];
+       snprintf(buf, len + 1, "%s%s", anim_prefix, filename);
+       // Changing the filename into something the OS can understand
+       char *fixedFN = ConvertFileName(buf);
+       delete[] buf;
+
+       LOG(std::string("Loading animation...") + fixedFN);
 
        deallocate();
 
        height=aheight;
        attack=aattack;
 
-       if(visibleloading)pgame->LoadingScreen();
+       if(visibleloading) Game::LoadingScreen();
 
-       tfile=fopen( filename, "rb" );
+       tfile=fopen( fixedFN, "rb" );
        if(tfile){
                funpackf(tfile, "Bi Bi", &numframes, &joints);
                /*
@@ -1062,7 +894,9 @@ void Animation::Load(char *filename, int aheight, int aattack)
                                funpackf(tfile, "Bf", &twist[j][i]);
                        }
                        for(j=0;j<joints;j++){
-                               funpackf(tfile, "Bb", &onground[j][i]);
+                               unsigned char uch;
+                               funpackf(tfile, "Bb", &uch);
+                               onground[j][i] = (uch != 0);
                        }
                        funpackf(tfile, "Bf", &speed[i]);
                }
@@ -1079,7 +913,7 @@ void Animation::Load(char *filename, int aheight, int aattack)
                        funpackf(tfile, "Bf Bf Bf", &weapontarget[i].x,&weapontarget[i].y,&weapontarget[i].z);
                }
 
-               fclose(tfile);  
+               fclose(tfile);
        }
 
        startoffset=0;
@@ -1109,7 +943,12 @@ void Animation::Move(XYZ how)
        }
 }
 
-void Skeleton::Load(char *filename,char *lowfilename,char *clothesfilename, char *modelfilename, char *model2filename, char *model3filename, char *model4filename, char *model5filename, char *model6filename, char *model7filename, char *modellowfilename, char *modelclothesfilename, bool aclothes)
+void Skeleton::Load(const char *filename,       const char *lowfilename, const char *clothesfilename, 
+                    const char *modelfilename,  const char *model2filename, 
+                    const char *model3filename, const char *model4filename, 
+                    const char *model5filename, const char *model6filename, 
+                    const char *model7filename, const char *modellowfilename, 
+                    const char *modelclothesfilename, bool aclothes)
 {
        static GLfloat M[16];
        static int parentID;
@@ -1121,6 +960,7 @@ void Skeleton::Load(char *filename,char *lowfilename,char *clothesfilename, char
 
        LOGFUNC;
 
+
        newload=0;
 
        num_models=7;
@@ -1174,7 +1014,7 @@ void Skeleton::Load(char *filename,char *lowfilename,char *clothesfilename, char
                drawmodelclothes.CalculateNormals(0);
        }
 
-       tfile=fopen( filename, "rb" );
+       tfile=fopen( ConvertFileName(filename), "rb" );
        if(1){
                funpackf(tfile, "Bi", &num_joints);
                //joints.resize(num_joints);
@@ -1227,8 +1067,8 @@ void Skeleton::Load(char *filename,char *lowfilename,char *clothesfilename, char
                        funpackf(tfile, "Bi", &lowforwardjoints[j]);
                }
                for(j=0;j<num_muscles;j++){
-                       for(i=0;i<muscles[j].numvertices;i++){  
-                               for(int k=0;k<num_models;k++){                                          
+                       for(i=0;i<muscles[j].numvertices;i++){
+                               for(int k=0;k<num_models;k++){
                                        if(muscles[j].numvertices&&muscles[j].vertices[i]<model[k].vertexNum)model[k].owner[muscles[j].vertices[i]]=j;
                                }
                        }
@@ -1259,9 +1099,9 @@ void Skeleton::Load(char *filename,char *lowfilename,char *clothesfilename, char
                        model[k].CalculateNormals(0);
                }
        }
-       fclose(tfile);          
+       fclose(tfile);
 
-       tfile=fopen( lowfilename, "rb" );
+       tfile=fopen( ConvertFileName(lowfilename), "rb" );
        if(1){
                lSize=sizeof(num_joints);
                fseek ( tfile, lSize, SEEK_CUR);
@@ -1274,21 +1114,21 @@ void Skeleton::Load(char *filename,char *lowfilename,char *clothesfilename, char
                        fseek ( tfile, lSize, SEEK_CUR);
                        lSize=sizeof(float);
                        fseek ( tfile, lSize, SEEK_CUR);
-                       lSize=sizeof(bool);
+                       lSize=1;//sizeof(bool);
                        fseek ( tfile, lSize, SEEK_CUR);
-                       lSize=sizeof(bool);
+                       lSize=1;//sizeof(bool);
                        fseek ( tfile, lSize, SEEK_CUR);
                        lSize=sizeof(int);
                        fseek ( tfile, lSize, SEEK_CUR);
-                       lSize=sizeof(bool);
+                       lSize=1;//sizeof(bool);
                        fseek ( tfile, lSize, SEEK_CUR);
-                       lSize=sizeof(bool);
+                       lSize=1;//sizeof(bool);
                        fseek ( tfile, lSize, SEEK_CUR);
                        lSize=sizeof(int);
                        fseek ( tfile, lSize, SEEK_CUR);
                        lSize=sizeof(int);
                        fseek ( tfile, lSize, SEEK_CUR);
-                       lSize=sizeof(bool);
+                       lSize=1;//sizeof(bool);
                        fseek ( tfile, lSize, SEEK_CUR);
                        lSize=sizeof(int);
                        fseek ( tfile, lSize, SEEK_CUR);
@@ -1329,7 +1169,7 @@ void Skeleton::Load(char *filename,char *lowfilename,char *clothesfilename, char
 
 
                        }
-                       lSize=sizeof(bool);
+                       lSize=1;//sizeof(bool);
                        fseek ( tfile, lSize, SEEK_CUR);
                        lSize=sizeof(int);
                        fseek ( tfile, lSize, SEEK_CUR);
@@ -1337,7 +1177,7 @@ void Skeleton::Load(char *filename,char *lowfilename,char *clothesfilename, char
                }
                lSize=sizeof(int);
                for(j=0;j<num_muscles;j++){
-                       for(i=0;i<muscles[j].numverticeslow;i++){       
+                       for(i=0;i<muscles[j].numverticeslow;i++){
                                if(muscles[j].numverticeslow&&muscles[j].verticeslow[i]<modellow.vertexNum)modellow.owner[muscles[j].verticeslow[i]]=j;
                        }
                }
@@ -1367,7 +1207,7 @@ void Skeleton::Load(char *filename,char *lowfilename,char *clothesfilename, char
        }
 
        if(clothes){
-               tfile=fopen( clothesfilename, "rb" );
+               tfile=fopen( ConvertFileName(clothesfilename), "rb" );
                lSize=sizeof(num_joints);
                fseek ( tfile, lSize, SEEK_CUR);
                //joints = new Joint[num_joints];
@@ -1379,21 +1219,21 @@ void Skeleton::Load(char *filename,char *lowfilename,char *clothesfilename, char
                        fseek ( tfile, lSize, SEEK_CUR);
                        lSize=sizeof(float);
                        fseek ( tfile, lSize, SEEK_CUR);
-                       lSize=sizeof(bool);
+                       lSize=1;//sizeof(bool);
                        fseek ( tfile, lSize, SEEK_CUR);
-                       lSize=sizeof(bool);
+                       lSize=1;//sizeof(bool);
                        fseek ( tfile, lSize, SEEK_CUR);
                        lSize=sizeof(int);
                        fseek ( tfile, lSize, SEEK_CUR);
-                       lSize=sizeof(bool);
+                       lSize=1;//sizeof(bool);
                        fseek ( tfile, lSize, SEEK_CUR);
-                       lSize=sizeof(bool);
+                       lSize=1;//sizeof(bool);
                        fseek ( tfile, lSize, SEEK_CUR);
                        lSize=sizeof(int);
                        fseek ( tfile, lSize, SEEK_CUR);
                        lSize=sizeof(int);
                        fseek ( tfile, lSize, SEEK_CUR);
-                       lSize=sizeof(bool);
+                       lSize=1;//sizeof(bool);
                        fseek ( tfile, lSize, SEEK_CUR);
                        lSize=sizeof(int);
                        fseek ( tfile, lSize, SEEK_CUR);
@@ -1432,7 +1272,7 @@ void Skeleton::Load(char *filename,char *lowfilename,char *clothesfilename, char
                                        }
                                }
                        }
-                       lSize=sizeof(bool);
+                       lSize=1;//sizeof(bool);
                        fseek ( tfile, lSize, SEEK_CUR);
                        lSize=sizeof(int);
                        fseek ( tfile, lSize, SEEK_CUR);
@@ -1440,7 +1280,7 @@ void Skeleton::Load(char *filename,char *lowfilename,char *clothesfilename, char
                }
                lSize=sizeof(int);
                for(j=0;j<num_muscles;j++){
-                       for(i=0;i<muscles[j].numverticesclothes;i++){   
+                       for(i=0;i<muscles[j].numverticesclothes;i++){
                                if(muscles[j].numverticesclothes&&muscles[j].verticesclothes[i]<modelclothes.vertexNum)modelclothes.owner[muscles[j].verticesclothes[i]]=j;
                        }
                }
@@ -1468,7 +1308,7 @@ void Skeleton::Load(char *filename,char *lowfilename,char *clothesfilename, char
                }
                modelclothes.CalculateNormals(0);
        }
-       fclose(tfile);          
+       fclose(tfile);
 
        for(i=0;i<num_joints;i++){
                for(j=0;j<num_joints;j++){