summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/Person.cpp290
1 files changed, 161 insertions, 129 deletions
diff --git a/src/Person.cpp b/src/Person.cpp
index b431b02..c8340d8 100644
--- a/src/Person.cpp
+++ b/src/Person.cpp
@@ -210,64 +210,78 @@ HitStruct 	Person::BulletCollideWithPlayer(int who, XYZ start, XYZ end){
 
 extern float camerashake;
 extern int cycle;
-void 	Person::DoAnimations(int who){
-	if(target>1&&!skeleton.free){
-		//Footstep sounds
-		if(who==0&&slomo==0&&(targetanimation==joganim||targetanimation==walkanim)&&(targetframe==0||targetframe==8)&&visions==0&&(onground||abs(velocity.y)<1)){
-			float gLoc[3];
-			gLoc[0]=playercoords.x/soundscalefactor;
-			gLoc[1]=playercoords.y/soundscalefactor;
-			gLoc[2]=playercoords.z/soundscalefactor;
-			int whichsound = footstepsound+abs(Random())%5;
+void Person::DoAnimations(int who)
+{
+	if (target > 1 && !skeleton.free) {
+		// Footstep sounds
+		if (!slomo && !visions && (onground || abs(velocity.y) < 1)
+		    && (targetanimation == joganim
+			|| targetanimation == walkanim)
+		    && (targetframe == 0 || targetframe == 8)) {
+			auto soundsrc = (playercoords - camera.position)
+				/ soundscalefactor;
+			ALfloat gLoc[] {soundsrc.x, soundsrc.y, soundsrc.z};
+			int whichsound = footstepsound + abs(Random()) % 5;
 			alSourcefv(gSourceID[whichsound], AL_POSITION, gLoc);
 			alSourcePlay(gSourceID[whichsound]);
 		}
-		if(targetanimation==zombieeatanim&&(targetframe==3)){
-			float gLoc[3];
-			XYZ soundpoint=(DoRotation(skeleton.joints[skeleton.jointlabels[head]].position,0,playerrotation,0)+playercoords);
-			gLoc[0]=soundpoint.x/soundscalefactor;
-			gLoc[1]=soundpoint.y/soundscalefactor;
-			gLoc[2]=soundpoint.z/soundscalefactor;
+
+		if (targetanimation == zombieeatanim && targetframe == 3) {
+			auto& joints = skeleton.joints;
+			auto& jointlabels = skeleton.jointlabels;
+			auto head_joint = joints[jointlabels[head]];
+			auto soundsrc = (DoRotation(head_joint.position,
+				0, playerrotation, 0) + playercoords
+				- camera.position) / soundscalefactor;
+			ALfloat gLoc[] {soundsrc.x, soundsrc.y, soundsrc.z};
 			alSourcefv(gSourceID[bodyhitsound], AL_POSITION, gLoc);
 			alSourcePlay(gSourceID[bodyhitsound]);
-			bleeding=1;
-			bleeddelay=1;
-			bjoint1=&skeleton.joints[skeleton.jointlabels[head]];
-			bjoint2=&skeleton.joints[skeleton.jointlabels[neck]];
+			bleeding = 1;
+			bleeddelay = 1;
+			bjoint1 = &head_joint;
+			bjoint2 = joints + jointlabels[neck];
 		}
-		targetframe=currentframe;
-		currentanimation=targetanimation;
-		if(!backwardsanim){targetframe++;
-		if(targetframe>animation[currentanimation].numframes-1)targetframe=0;}
-		if(backwardsanim){targetframe--;
-		if(targetframe<0)targetframe=animation[currentanimation].numframes-1;}
-		target=0;
-		if((currentanimation==getupfrontanim||currentanimation==getupbackanim)&&targetframe==0){
-			targetanimation=idleanim;
-		}
-		if(targetanimation==diveanim&&currentanimation==diveanim&&targetframe==0){
-			targetanimation=getupfrontanim;
-			float gLoc[3];
-			XYZ soundpoint=(DoRotation(skeleton.joints[skeleton.jointlabels[head]].position,0,playerrotation,0)+playercoords);
-			gLoc[0]=soundpoint.x/soundscalefactor;
-			gLoc[1]=soundpoint.y/soundscalefactor;
-			gLoc[2]=soundpoint.z/soundscalefactor;
+
+		currentanimation = targetanimation;
+		targetframe = currentframe + (backwardsanim ? -1 : 1);
+		if (targetframe >= animation[currentanimation].numframes)
+			targetframe = 0;
+		else if (targetframe < 0)
+			targetframe = animation[currentanimation].numframes - 1;
+		target = 0;
+
+		if ((currentanimation == getupfrontanim
+		     || currentanimation == getupbackanim) && targetframe == 0)
+			targetanimation = idleanim;
+
+		if (targetanimation == diveanim
+		    && currentanimation == diveanim && targetframe == 0) {
+			targetanimation = getupfrontanim;
+			auto& joints = skeleton.joints;
+			auto& jointlabels = skeleton.jointlabels;
+			auto head_joint = joints[jointlabels[head]];
+			auto soundsrc = (DoRotation(head_joint.position,
+				0, playerrotation, 0) + playercoords
+				- camera.position) / soundscalefactor;
+			ALfloat gLoc[] {soundsrc.x, soundsrc.y, soundsrc.z};
 			alSourcefv(gSourceID[bodywhacksound], AL_POSITION, gLoc);
 			alSourcePlay(gSourceID[bodywhacksound]);
 		}
-		if(currentanimation==throwanim&&targetframe==0){
-			targetanimation=idleanim;
-		}
-		if(currentanimation==thrownanim&&targetframe==0){
-			skeleton.offset=0;
-			skeleton.free=1;
-			longdead=1;
-			for(int j=0;j<skeleton.num_joints;j++){
-				skeleton.joints[j].position+=skeleton.joints[j].offset;
-				skeleton.joints[j].position=DoRotation(skeleton.joints[j].position,0,playerrotation,0);
-				skeleton.joints[j].position+=playercoords;
-				skeleton.joints[j].realoldposition=skeleton.joints[j].position;
-				skeleton.joints[j].velocity=DoRotation(skeleton.joints[j].velocity,0,playerrotation,0);
+
+		if (currentanimation == throwanim && targetframe == 0)
+			targetanimation = idleanim;
+		if (currentanimation == thrownanim && targetframe == 0) {
+			skeleton.offset = 0;
+			skeleton.free = 1;
+			longdead = 1;
+			for (auto& joint : skeleton.joints) {
+				joint.position = playercoords
+					+ DoRotation(joint.position
+						+ joint.offset,
+						0, playerrotation, 0);
+				joint.realoldposition = joint.position;
+				joint.velocity = DoRotation(joint.velocity,
+					0, playerrotation, 0);
 			}
 		}
 	}
@@ -496,11 +510,10 @@ void 	Person::DoAnimations(int who){
 					sprites.MakeSprite(grenadesprite, 1, 1, 1, 1, DoRotation(skeleton.joints[skeleton.jointlabels[righthand]].position,0,playerrotation,0)+playercoords, DoRotation(facing,0,playerrotation,0)*30+velocity, 1);
 					sprites.MakeSprite(spoonsprite, 1, 1, 1, 1, DoRotation(skeleton.joints[skeleton.jointlabels[righthand]].position,0,playerrotation,0)+playercoords, DoRotation(facing,0,playerrotation,0)*10+velocity, 1);
 					sprites.MakeSprite(pinsprite, 1, 1, 1, 1, DoRotation(skeleton.joints[skeleton.jointlabels[lefthand]].position,0,playerrotation,0)+playercoords, facing*.1+velocity, 1);
-					XYZ soundsource=DoRotation(skeleton.joints[skeleton.jointlabels[righthand]].position,0,playerrotation,0)+playercoords;
-					float gLoc[3];
-					gLoc[0]=soundsource.x/soundscalefactor;
-					gLoc[1]=soundsource.y/soundscalefactor;
-					gLoc[2]=soundsource.z/soundscalefactor;
+
+					XYZ soundsrc = (DoRotation(skeleton.joints[skeleton.jointlabels[righthand]].position, 0, playerrotation, 0)
+						+ playercoords - camera.position) / soundscalefactor;
+					ALfloat gLoc[] {soundsrc.x, soundsrc.y, soundsrc.z};
 					alSourcefv(gSourceID[grenadethrowsound], AL_POSITION, gLoc);
 					alSourcePlay(gSourceID[grenadethrowsound]);
 				}
@@ -526,99 +539,118 @@ void 	Person::DoAnimations(int who){
 
 		skeleton.DoConstraints();
 
-		//Reload
-		if(whichgun!=nogun&&whichgun!=knife){
-			if(reloading>0){
-				aiming=0;
-				reloading-=multiplier;
+		// Reload
+		if (whichgun != nogun && whichgun != knife) {
+			if (reloading > 0) {
+				aiming = 0;
+				reloading -= multiplier;
 			}
-			if(ammo<0&&reloads[whichgun]>0&&reloading<=0){
-				if(whichgun!=grenade){
-					float gLoc[3];
-					ALint tempint;
-					gLoc[0]=playercoords.x/soundscalefactor;
-					gLoc[1]=playercoords.y/soundscalefactor;
-					gLoc[2]=playercoords.z/soundscalefactor;
-					alGetSourcei(gSourceID[reloadsound], AL_SOURCE_STATE, &tempint);
-
-					if (tempint != AL_PLAYING){
-						alSourcefv(gSourceID[reloadsound], AL_POSITION, gLoc);
-						alSourcePlay(gSourceID[reloadsound]);
-					}
+			if(ammo < 0 && reloads[whichgun] > 0 && reloading <= 0) {
+				ALint tempint;
+				alGetSourcei(gSourceID[reloadsound], AL_SOURCE_STATE, &tempint);
+				if (whichgun != grenade && tempint != AL_PLAYING) {
+					auto soundsrc = (playercoords - camera.position) / soundscalefactor;
+					ALfloat gLoc[] {soundsrc.x, soundsrc.y, soundsrc.z};
+					alSourcefv(gSourceID[reloadsound], AL_POSITION, gLoc);
+					alSourcePlay(gSourceID[reloadsound]);
+				}
+				reloading = 3;
+				aiming = 0;
+				switch (whichgun) {
+				case sniperrifle:
+					ammo = 5;
+					break;
+				case shotgun:
+					ammo = 6;
+					break;
+				case assaultrifle:
+					ammo = 25;
+					break;
+				case handgun1:
+					ammo = 12;
+					break;
+				case handgun2:
+					ammo = 16;
+					break;
+				case grenade:
+					ammo = 1;
+					reloading = 1;
+					break;
 				}
-				reloading=3;
-				aiming=0;
-				if(whichgun==sniperrifle)ammo=5;
-				if(whichgun==assaultrifle)ammo=25;
-				if(whichgun==handgun1)ammo=12;
-				if(whichgun==handgun2)ammo=16;
-				if(whichgun==grenade){ammo=1; reloading=1;}
-				if(whichgun==shotgun)ammo=6;
 				reloads[whichgun]--;
 			}
-			if(reloads[whichgun]==0&&whichgun==grenade&&ammo<=0){
-				whichgun=nogun;
-			}
-			if(reloading<0){
-				reloading=0;
-				aiming=1;
+			if (reloads[whichgun] == 0 && whichgun == grenade && ammo <= 0)
+				whichgun = nogun;
+			if (reloading < 0) {
+				reloading = 0;
+				aiming = 1;
 			}
 		}
 	}
 }
 
-void 	Person::DoAnimationslite(int who){
-	if(target>1&&!skeleton.free){
-		//Footstep sounds
-		if(who==0&&(targetanimation==joganim||targetanimation==walkanim)&&(targetframe==0||targetframe==8)&&visions==0&&(onground||abs(velocity.y)<1)){
-			float gLoc[3];
-			gLoc[0]=playercoords.x/soundscalefactor;
-			gLoc[1]=playercoords.y/soundscalefactor;
-			gLoc[2]=playercoords.z/soundscalefactor;
-			int whichsound = footstepsound+abs(Random())%5;
+void Person::DoAnimationslite(int who)
+{
+	if (skeleton.free)
+		return;
+	if (target > 1) {
+		// Footstep sounds
+		if (!visions && (onground || abs(velocity.y) < 1)
+		    && (targetanimation == joganim
+		        || targetanimation == walkanim)
+		    && (targetframe == 0 || targetframe == 8)) {
+			auto soundsrc = (playercoords - camera.position)
+				/ soundscalefactor;
+			ALfloat gLoc[] {soundsrc.x, soundsrc.y, soundsrc.z};
+			int whichsound = footstepsound + abs(Random()) % 5;
 			alSourcefv(gSourceID[whichsound], AL_POSITION, gLoc);
 			alSourcePlay(gSourceID[whichsound]);
 		}
-		if(targetanimation==zombieeatanim&&(targetframe==3)){
-			float gLoc[3];
-			XYZ soundpoint=(DoRotation(skeleton.joints[skeleton.jointlabels[head]].position,0,playerrotation,0)+playercoords);
-			gLoc[0]=soundpoint.x/soundscalefactor;
-			gLoc[1]=soundpoint.y/soundscalefactor;
-			gLoc[2]=soundpoint.z/soundscalefactor;
+
+		if (targetanimation == zombieeatanim && targetframe == 3) {
+			auto& joints = skeleton.joints;
+			auto& jointlabels = skeleton.jointlabels;
+			auto head_joint = joints[jointlabels[head]];
+			auto soundsrc = (DoRotation(head_joint.position,
+				0, playerrotation, 0) + playercoords
+				- camera.position) / soundscalefactor;
+			ALfloat gLoc[] {soundsrc.x, soundsrc.y, soundsrc.z};
 			alSourcefv(gSourceID[bodyhitsound], AL_POSITION, gLoc);
 			alSourcePlay(gSourceID[bodyhitsound]);
-			bleeding=1;
-			bleeddelay=1;
-			bjoint1=&skeleton.joints[skeleton.jointlabels[head]];
-			bjoint2=&skeleton.joints[skeleton.jointlabels[neck]];
-		}
-		targetframe=currentframe;
-		currentanimation=targetanimation;
-		if(!backwardsanim){targetframe++;
-		if(targetframe>animation[currentanimation].numframes-1)targetframe=0;}
-		if(backwardsanim){targetframe--;
-		if(targetframe<0)targetframe=animation[currentanimation].numframes-1;}
-		target=0;
-		if((currentanimation==getupfrontanim||currentanimation==getupbackanim)&&targetframe==0){
-			targetanimation=idleanim;
+			bleeding = 1;
+			bleeddelay = 1;
+			bjoint1 = &head_joint;
+			bjoint2 = joints + jointlabels[neck];
 		}
-	}
 
-	if(!skeleton.free){
-		if(currentanimation!=lyinganim){
-			if(animation[targetanimation].speed[currentframe]>animation[currentanimation].speed[currentframe])
-				target+=multiplier*animation[targetanimation].speed[currentframe]*speed;
-			if(animation[targetanimation].speed[currentframe]<=animation[currentanimation].speed[currentframe])
-				target+=multiplier*animation[currentanimation].speed[currentframe]*speed;
-		}
-		if(currentanimation==lyinganim){
-			target+=multiplier*animation[targetanimation].speed[targetframe]*speed;
-		}
-		if(((currentanimation==crouchanim)&&(targetanimation!=crouchanim))||((currentanimation!=crouchanim)&&(targetanimation==crouchanim)))target+=multiplier*animation[crouchanim].speed[0]*2;
-		if(currentanimation==idleanim&&targetanimation==idleanim)target-=multiplier*animation[idleanim].speed[0]/2;
+		currentanimation = targetanimation;
+		targetframe = currentframe + (backwardsanim ? -1 : 1);
+		if (targetframe >= animation[currentanimation].numframes)
+			targetframe = 0;
+		else if (targetframe < 0)
+			targetframe = animation[currentanimation].numframes - 1;
 
-		if(target>1)currentframe=targetframe;
+		target = 0;
+
+		if ((currentanimation == getupfrontanim
+		     || currentanimation == getupbackanim) && targetframe == 0)
+			targetanimation = idleanim;
 	}
+
+	if (currentanimation == lyinganim)
+		target += speed * multiplier
+			* animation[targetanimation].speed[targetframe];
+	else
+		target += speed * multiplier
+			* max(animation[currentanimation].speed[currentframe],
+				animation[targetanimation].speed[currentframe]);
+
+	if ((currentanimation == crouchanim) ^ (targetanimation == crouchanim))
+		target += *animation[crouchanim].speed * multiplier * 2;
+	if (currentanimation == idleanim && targetanimation == idleanim)
+		target -= *animation[idleanim].speed * multiplier / 2;
+	if (target > 1)
+		currentframe = targetframe;
 }
 
 void 	Person::DoStuff(int who){