summary refs log tree commit diff
path: root/src/GameTick.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/GameTick.cpp')
-rw-r--r--src/GameTick.cpp290
1 files changed, 95 insertions, 195 deletions
diff --git a/src/GameTick.cpp b/src/GameTick.cpp
index 9a79086..3b9cf5a 100644
--- a/src/GameTick.cpp
+++ b/src/GameTick.cpp
@@ -1570,14 +1570,14 @@ void Game::Tick()
 				person[i].skeleton.free=1;
 				person[i].longdead=1;
 
-				for(int j=0;j<person[i].skeleton.num_joints;j++){
-					person[i].skeleton.joints[j].position+=person[i].skeleton.joints[j].offset;
-					person[i].skeleton.joints[j].position=DoRotation(person[i].skeleton.joints[j].position,0,person[i].playerrotation,0);
-					person[i].skeleton.joints[j].position+=person[i].playercoords;
-					person[i].skeleton.joints[j].realoldposition=person[i].skeleton.joints[j].position;
-					person[i].skeleton.joints[j].velocity=DoRotation(person[i].skeleton.joints[j].velocity,0,person[i].playerrotation,0);
-					person[i].skeleton.joints[j].velocity+=person[i].velocity;
-					person[i].skeleton.joints[j].velocity+=person[i].facing*4;
+				for (auto& joint : person[i].skeleton.joints) {
+					joint.position += joint.offset;
+					joint.position = DoRotation(joint.position, 0, person[i].playerrotation, 0);
+					joint.position += person[i].playercoords;
+					joint.realoldposition = joint.position;
+					joint.velocity = DoRotation(joint.velocity, 0, person[i].playerrotation, 0);
+					joint.velocity += person[i].velocity;
+					joint.velocity += person[i].facing * 4;
 				}
 			}
 		 }
@@ -1598,11 +1598,10 @@ void Game::Tick()
 			person[i].oldaverageloc=person[i].averageloc;
 			person[i].averageloc=0;
 
-			for(int j=0;j<person[i].skeleton.num_joints;j++){
-				person[i].averageloc+=person[i].skeleton.joints[j].position;
-			}
+			for (auto& joint : person[i].skeleton.joints)
+				person[i].averageloc += joint.position;
 
-			person[i].averageloc/=person[i].skeleton.num_joints;
+			person[i].averageloc /= max_joints;
 			person[i].playercoords=person[i].averageloc;
 			if(person[i].longdead<multiplier/2&&person[i].longdead>0)person[i].DrawSkeleton(i);
 			if(findDistancefast(person[i].averageloc,person[i].oldaverageloc)<.2*multiplier)person[i].longdead-=multiplier/2;
@@ -1623,9 +1622,9 @@ void Game::Tick()
 
 			//Find playercoords
 			person[i].playercoords=person[i].averageloc;
-			for(int j=0;j<person[i].skeleton.num_joints;j++){
-				if(person[i].skeleton.joints[j].position.y>person[i].playercoords.y)person[i].playercoords.y=person[i].skeleton.joints[j].position.y;
-			}
+			for (auto& joint : person[i].skeleton.joints)
+				if (joint.position.y > person[i].playercoords.y)
+					person[i].playercoords.y = joint.position.y;
 
 			//Find orientation
 			XYZ firsttop=person[i].skeleton.joints[person[i].skeleton.jointlabels[neck]].position-person[i].skeleton.joints[person[i].skeleton.jointlabels[groin]].position;
@@ -1637,7 +1636,7 @@ void Game::Tick()
 			person[i].playervelocity=0;
 			if(person[i].targetanimation==getupfrontanim)person[i].playerrotation+=180;
 
-			for(int j=0;j<person[i].skeleton.num_joints;j++){
+			for (int j = 0; j < max_joints; ++j) {
 				person[i].tempanimation.position[j][0]=person[i].skeleton.joints[j].position-person[i].playercoords;
 				person[i].tempanimation.position[j][0]=DoRotation(person[i].tempanimation.position[j][0],0,-person[i].playerrotation,0);
 			}
@@ -1680,14 +1679,15 @@ void Game::Tick()
 				person[person[0].killtarget].skeleton.free=1;
 				person[person[0].killtarget].longdead=1;
 
-				for(int j=0;j<person[person[0].killtarget].skeleton.num_joints;j++){
-					person[person[0].killtarget].skeleton.joints[j].position=DoRotation(person[person[0].killtarget].skeleton.joints[j].position,0,person[person[0].killtarget].playerrotation,0);
-					person[person[0].killtarget].skeleton.joints[j].position+=person[person[0].killtarget].playercoords;
-					person[person[0].killtarget].skeleton.joints[j].realoldposition=person[person[0].killtarget].skeleton.joints[j].position;
-					person[person[0].killtarget].skeleton.joints[j].velocity=person[person[0].killtarget].velocity;
-					person[person[0].killtarget].skeleton.joints[j].velocity.x+=abs(Random()%10)-5;
-					person[person[0].killtarget].skeleton.joints[j].velocity.y+=abs(Random()%10)-5;
-					person[person[0].killtarget].skeleton.joints[j].velocity.z+=abs(Random()%10)-5;
+				for (auto& joint : person[person[0].killtarget].skeleton.joints) {
+					joint.position = DoRotation(joint.position,
+						0, person[person[0].killtarget].playerrotation, 0);
+					joint.position += person[person[0].killtarget].playercoords;
+					joint.realoldposition = joint.position;
+					joint.velocity = person[person[0].killtarget].velocity;
+					joint.velocity.x += abs(Random() % 10) - 5;
+					joint.velocity.y += abs(Random() % 10) - 5;
+					joint.velocity.z += abs(Random() % 10) - 5;
 				}
 
 				if(person[0].whichgun!=knife){
@@ -1727,15 +1727,15 @@ void Game::Tick()
 				person[person[0].killtarget].skeleton.free=1;
 				person[person[0].killtarget].longdead=1;
 
-				for(int j=0;j<person[person[0].killtarget].skeleton.num_joints;j++){
-					person[person[0].killtarget].skeleton.joints[j].position=DoRotation(person[person[0].killtarget].skeleton.joints[j].position,0,person[person[0].killtarget].playerrotation,0);
-					person[person[0].killtarget].skeleton.joints[j].position+=person[person[0].killtarget].playercoords;
-					person[person[0].killtarget].skeleton.joints[j].realoldposition=person[person[0].killtarget].skeleton.joints[j].position;
-					person[person[0].killtarget].skeleton.joints[j].velocity=person[person[0].killtarget].velocity;
+				for (auto& joint : person[person[0].killtarget].skeleton.joints) {
+					joint.position = DoRotation(joint.position, 0, person[person[0].killtarget].playerrotation, 0);
+					joint.position += person[person[0].killtarget].playercoords;
+					joint.realoldposition = joint.position;
+					joint.velocity = person[person[0].killtarget].velocity;
 
-					person[person[0].killtarget].skeleton.joints[j].velocity.x+=abs(Random()%10)-5;
-					person[person[0].killtarget].skeleton.joints[j].velocity.y+=abs(Random()%10)-5;
-					person[person[0].killtarget].skeleton.joints[j].velocity.z+=abs(Random()%10)-5;
+					joint.velocity.x += abs(Random() % 10) - 5;
+					joint.velocity.y += abs(Random() % 10) - 5;
+					joint.velocity.z += abs(Random() % 10) - 5;
 				}
 
 				if(person[0].whichgun!=knife){
@@ -2211,46 +2211,24 @@ void Game::Tick()
 
 							totalarea=0;
 
-							for(int j=0;j<person[whichhit].skeleton.num_joints;j++){
-
-								person[whichhit].skeleton.joints[j].position=DoRotation(person[whichhit].skeleton.joints[j].position,0,person[whichhit].playerrotation,0);
-
-								person[whichhit].skeleton.joints[j].position+=person[whichhit].playercoords;
-
-								person[whichhit].skeleton.joints[j].realoldposition=person[whichhit].skeleton.joints[j].position;
-
-								person[whichhit].skeleton.joints[j].velocity=person[whichhit].velocity;
-
-								person[whichhit].skeleton.joints[j].velocity.x+=(float)(abs(Random()%20)-10)/2;
-
-								person[whichhit].skeleton.joints[j].velocity.y+=(float)(abs(Random()%20)-10)/2;
-
-								person[whichhit].skeleton.joints[j].velocity.z+=(float)(abs(Random()%20)-10)/2;
-
-							}
-
-						}
-
-						for(int j=0;j<person[whichhit].skeleton.num_joints;j++){
-
-							if(findDistancefast(person[whichhit].skeleton.joints[j].position,hitstruct.hitlocation)<200){
-
-								totalarea+=(200/findDistancefast(person[whichhit].skeleton.joints[j].position,hitstruct.hitlocation));
-
+							for (auto& joint : person[whichhit].skeleton.joints) {
+								joint.position = DoRotation(joint.position, 0, person[whichhit].playerrotation, 0);
+								joint.position += person[whichhit].playercoords;
+								joint.realoldposition = joint.position;
+								joint.velocity = person[whichhit].velocity;
+								joint.velocity.x += (abs(Random()%20) - 10) / 2.0f;
+								joint.velocity.y += (abs(Random()%20) - 10) / 2.0f;
+								joint.velocity.z += (abs(Random()%20) - 10) / 2.0f;
 							}
-
 						}
 
-						for(int j=0;j<person[whichhit].skeleton.num_joints;j++){
-
-							if(findDistancefast(person[whichhit].skeleton.joints[j].position,hitstruct.hitlocation)<200){
-
-								person[whichhit].skeleton.joints[j].velocity+=aim*((200/findDistancefast(person[whichhit].skeleton.joints[j].position,hitstruct.hitlocation))/totalarea*200);
-
+						for (auto& joint : person[whichhit].skeleton.joints) {
+							auto distance = findDistancefast(joint.position, hitstruct.hitlocation);
+							if (distance < 200) {
+								totalarea += 200 / distance;
+								joint.velocity += aim * 200 / distance / totalarea * 200;
 							}
-
 						}
-
 					}
 
 					if(person[whichhit].health>0){
@@ -2281,43 +2259,23 @@ void Game::Tick()
 
 						person[whichhit].skeleton.offset=1;
 
-						for(int j=0;j<person[whichhit].skeleton.num_joints;j++){
-
-							if(findDistancefast(DoRotation(person[whichhit].skeleton.joints[j].position,0,person[whichhit].playerrotation,0)+person[whichhit].playercoords,hitstruct.hitlocation)<200){
-
-								totalarea+=(200/findDistancefast(DoRotation(person[whichhit].skeleton.joints[j].position,0,person[whichhit].playerrotation,0)+person[whichhit].playercoords,hitstruct.hitlocation));
-
+						for (auto& joint : person[whichhit].skeleton.joints) {
+							auto distance = findDistancefast(DoRotation(joint.position, 0, person[whichhit].playerrotation, 0) + person[whichhit].playercoords, hitstruct.hitlocation);
+							if(distance < 200) {
+								totalarea += 200 / distance;
+								joint.offset += DoRotation(aim * 200 / distance / totalarea * 10,
+									0, -person[whichhit].playerrotation, 0);
 							}
-
-						}
-
-						float offsetlength;
-
-						for(int j=0;j<person[whichhit].skeleton.num_joints;j++){
-
-							if(findDistancefast(DoRotation(person[whichhit].skeleton.joints[j].position,0,person[whichhit].playerrotation,0)+person[whichhit].playercoords,hitstruct.hitlocation)<200){
-
-								person[whichhit].skeleton.joints[j].offset+=DoRotation(aim*((200/findDistancefast(DoRotation(person[whichhit].skeleton.joints[j].position,0,person[whichhit].playerrotation,0)+person[whichhit].playercoords,hitstruct.hitlocation))/totalarea*10),0,-person[whichhit].playerrotation,0);
-
-							}
-
-							offsetlength=findLengthfast(person[whichhit].skeleton.joints[j].offset);
-
-							if(offsetlength>36){
-
-								Normalise(&person[whichhit].skeleton.joints[j].offset);
-
-								person[whichhit].skeleton.joints[j].offset*=6;
-
+							if (findLengthfast(joint.offset) > 36) {
+								Normalise(&joint.offset);
+								joint.offset *= 6;
 							}
-
 						}
-
 					}
 
 					if(hitstruct.joint1->modelnum==headmodel&&person[whichhit].health<=0){
 
-						for(int j=0;j<person[whichhit].skeleton.num_joints;j++){
+						for (int j = 0; j < max_joints; ++j) {
 
 							if(&person[whichhit].skeleton.joints[j]==hitstruct.joint1||&person[whichhit].skeleton.joints[j]==hitstruct.joint2){
 
@@ -2900,18 +2858,16 @@ void Game::Tick()
 
 									person[j].longdead=1;
 
-									for (int k = 0; k < person[j].skeleton.num_joints; ++k) {
-										person[j].skeleton.joints[k].realoldposition
-											= person[j].skeleton.joints[k].position
-											= DoRotation(person[j].skeleton.joints[k].position,
+									for (auto& joint : person[j].skeleton.joints) {
+										joint.realoldposition = joint.position
+											= DoRotation(joint.position,
 												0, person[j].playerrotation, 0)
 											+ person[j].playercoords;
 
-										person[j].skeleton.joints[k].velocity = person[j].velocity;
-										person[j].skeleton.joints[k].velocity.x += abs(Random()%10)-5;
-										person[j].skeleton.joints[k].velocity.y += abs(Random()%10)-5;
-										person[j].skeleton.joints[k].velocity.z += abs(Random()%10)-5;
-
+										joint.velocity = person[j].velocity;
+										joint.velocity.x += abs(Random()%10)-5;
+										joint.velocity.y += abs(Random()%10)-5;
+										joint.velocity.z += abs(Random()%10)-5;
 									}
 
 									hitstruct.joint1->velocity += sprites.velocity[i];
@@ -2930,52 +2886,24 @@ void Game::Tick()
 
 									person[j].skeleton.offset=1;
 
-									for(int k=0;k<person[j].skeleton.num_joints;k++){
-
-										if(findDistancefast(DoRotation(person[j].skeleton.joints[k].position,0,person[j].playerrotation,0)+person[j].playercoords,hitstruct.hitlocation)<200){
-
-											totalarea+=(200/findDistancefast(DoRotation(person[j].skeleton.joints[k].position,0,person[j].playerrotation,0)+person[j].playercoords,hitstruct.hitlocation));
-
-										}
-
-									}
-
-									float offsetlength;
-
-									for(int k=0;k<person[j].skeleton.num_joints;k++){
-
-										if(findDistancefast(DoRotation(person[j].skeleton.joints[k].position,0,person[j].playerrotation,0)+person[j].playercoords,hitstruct.hitlocation)<200){
-
-											person[j].skeleton.joints[k].offset+=DoRotation(sprites.velocity[i]*.1*((200/findDistancefast(DoRotation(person[j].skeleton.joints[k].position,0,person[j].playerrotation,0)+person[j].playercoords,hitstruct.hitlocation))/totalarea*10),0,-person[j].playerrotation,0);
-
+									for (auto& joint : person[j].skeleton.joints) {
+										auto distance = findDistancefast(DoRotation(joint.position, 0, person[j].playerrotation, 0) + person[j].playercoords, hitstruct.hitlocation);
+										if (distance < 200) {
+											totalarea += 200 / distance;
+											joint.offset += DoRotation(sprites.velocity[i] * 0.1 * 200 / distance / totalarea * 10, 0, -person[j].playerrotation, 0);
 										}
-
-										offsetlength=findLengthfast(person[j].skeleton.joints[k].offset);
-
-										if(offsetlength>9){
-
-											Normalise(&person[j].skeleton.joints[k].offset);
-
-											person[j].skeleton.joints[k].offset*=3;
-
+										if (findLengthfast(joint.offset) > 9) {
+											Normalise(&joint.offset);
+											joint.offset *= 3;
 										}
-
 									}
-
 								}}
-
 								sprites.velocity[i]*=-.3;
-
 							}
-
 						}
-
 					}
-
 				}
-
 				sprites.oldlocation[i]=sprites.location[i];
-
 			}
 
 			//Explode
@@ -3084,72 +3012,44 @@ void Game::Tick()
 						person[k].bjoint1 = &person[k].skeleton.joints[person[k].skeleton.jointlabels[head]];
 						person[k].bjoint2 = &person[k].skeleton.joints[person[k].skeleton.jointlabels[neck]];
 
-						for(int j=0;j<person[k].skeleton.num_joints;j++){
-
-							person[k].skeleton.joints[j].position=DoRotation(person[k].skeleton.joints[j].position,0,person[k].playerrotation,0);
-
-							person[k].skeleton.joints[j].position+=person[k].playercoords;
-
-							person[k].skeleton.joints[j].realoldposition=person[k].skeleton.joints[j].position;
-
-							person[k].skeleton.joints[j].velocity=DoRotation(person[k].skeleton.joints[j].velocity,0,person[k].playerrotation,0);
-
-							person[k].skeleton.joints[j].velocity+=person[k].velocity;
-
-							person[k].skeleton.joints[j].velocity.x+=abs(Random()%20)-10;
-
-							person[k].skeleton.joints[j].velocity.y+=abs(Random()%20)-10;
-
-							person[k].skeleton.joints[j].velocity.z+=abs(Random()%20)-10;
-
+						for (auto& joint : person[k].skeleton.joints) {
+							joint.position = DoRotation(joint.position, 0, person[k].playerrotation, 0);
+							joint.position += person[k].playercoords;
+							joint.realoldposition = joint.position;
+							joint.velocity = DoRotation(joint.velocity, 0, person[k].playerrotation, 0);
+							joint.velocity += person[k].velocity;
+							joint.velocity.x += abs(Random() % 20) - 10;
+							joint.velocity.y += abs(Random() % 20) - 10;
+							joint.velocity.z += abs(Random() % 20) - 10;
 						}}
 
-						for(int j=0;j<person[k].skeleton.num_joints;j++){
-
-							relation=person[k].skeleton.joints[j].position-sprites.location[i];
-
-							Normalise(&relation);
-
-							if(findDistance(person[k].skeleton.joints[j].position,sprites.location[i])>1)person[k].skeleton.joints[j].velocity+=relation/findDistance(person[k].skeleton.joints[j].position,sprites.location[i])*300;
-
-							else person[k].skeleton.joints[j].velocity+=relation*300;
-
-						}
-
 						person[k].longdead=1;
-
-						for(int j=0;j<person[k].skeleton.num_joints;j++){
-
-							//Sever stuff
-
-							if(findLengthfast(person[k].skeleton.joints[j].velocity)>1500&&person[k].skeleton.joints[j].existing==1&&abs(Random()%3)!=1){
-
-								sprites.MakeSprite(bloodspritedown, .8, 1, .2, .2,person[k].skeleton.joints[j].position, person[k].skeleton.joints[j].velocity/3, 9);
-
-								person[k].skeleton.DeleteJoint(j);
-
+						for (auto& joint : person[k].skeleton.joints) {
+							relation = joint.position - sprites.location[i];
+							Normalise(&relation);
+							auto distance = findDistance(joint.position, sprites.location[i]);
+							if (distance > 1)
+								joint.velocity += relation / distance * 300;
+							else
+								joint.velocity += relation * 300;
+
+							// Sever stuff
+							if (findLengthfast(joint.velocity) > 1500
+							    && joint.existing && abs(Random() % 3) != 1) {
+								sprites.MakeSprite(bloodspritedown, 0.8, 1, 0.2, 0.2, joint.position, joint.velocity / 3, 9);
+								person[k].skeleton.DeleteJoint(&joint
+									- person[k].skeleton.joints);
 								person[k].skeleton.broken=2;
-
 								person[k].health=-10000;
-
-								person[k].skeleton.joints[j].existing=0;
-
+								joint.existing = false;
 							}
-
 						}
-
 						}
-
 						}
-
 					}
-
 				}
-
 			}
-
 		}
-
 	}
 
 	//camera shake