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.cpp182
1 files changed, 73 insertions, 109 deletions
diff --git a/src/GameTick.cpp b/src/GameTick.cpp
index f97d3c9..a096f9a 100644
--- a/src/GameTick.cpp
+++ b/src/GameTick.cpp
@@ -216,7 +216,6 @@ void click(Game* game, int button, int action, int mods)
 		if (attacking) {
 			player.attacktarget = 0;
 			player.attackframe = 0;
-			game->whacked = false;
 			return;
 		}
 	}
@@ -636,6 +635,74 @@ void spawnNpc(Game* game)
 		&& (npc.type == zombietype || npc.type == eviltype)) ? 1 : -1;
 }
 
+void attackCloseRange(Game* game, XYZ flatfacing)
+{
+	auto& player = game->person[0];
+	if ((player.attackframe < 0 || player.currentanimation != joganim)
+	    && player.attackframe <= 1 && player.targetanimation != joganim
+	    && player.whichgun != nogun && player.whichgun != knife
+	    && player.aiming)
+		return;
+	if (player.killtarget < 2)
+		return;
+	auto& target = game->person[player.killtarget];
+	player.killtarget = 0;
+	if (target.skeleton.free)
+		return;
+	target.skeleton.free = true;
+	target.longdead = 1.0f;
+	if (target.type == zombietype) {
+		target.health -= 200;
+		target.maxhealth -= 20;
+	} else {
+		target.health -= 100;
+	}
+
+	for (auto& joint : target.skeleton.joints) {
+		joint.position = DoRotation(joint.position,
+			0, target.playerrotation, 0);
+		joint.position += target.playercoords;
+		joint.realoldposition = joint.position;
+		joint.velocity = target.velocity;
+		joint.velocity.x += randInt(-4, 4);
+		joint.velocity.y += randInt(-4, 4);
+		joint.velocity.z += randInt(-4, 4);
+	}
+
+	auto soundpos = player.playercoords + flatfacing
+		- camera.position;
+	if (player.whichgun == knife) {
+		playSound(gSourceID[knifeslashsound],
+			soundpos.x, soundpos.y, soundpos.z);
+		target.bjoint1=&target.skeleton.joints[neck];
+		target.bjoint2=&target.skeleton.joints[neck];
+		target.bleeding=1;
+		target.bleeddelay=1;
+
+		player.bjoint1=&player.skeleton.joints[righthand];
+		player.bjoint2=&player.skeleton.joints[righthand];
+		player.bleeding=1;
+		player.bleeddelay=1;
+
+		auto velocity = DoRotation(flatfacing, 0, 70, 0) * 50
+			+ player.velocity * 2;
+		velocity.y += 30;
+		auto sprite_pos = target.playercoords
+			+ DoRotation(target.skeleton.joints[neck].position,
+				0, target.playerrotation, 0);
+		for (auto i = 2; i < 5; ++i)
+			sprites.MakeSprite(bloodspritedown,
+				0.8f, 1.0f, 0.2f, 0.2f, sprite_pos,
+				velocity * (0.5f - 0.1f * i), i);
+	} else {
+		playSound(gSourceID[headwhacksound],
+			soundpos.x, soundpos.y, soundpos.z);
+		target.skeleton.joints[head].velocity
+			+= DoRotation(flatfacing, 0, 40, 0) * 50
+			+ player.velocity * 2;
+	}
+}
+
 void Game::Tick()
 {
 	if (person[1].health <= 0 || person[0].health <= 0 || killedinnocent)
@@ -1145,7 +1212,7 @@ void Game::Tick()
 									person[i].lastdistancevictim=200000;
 									person[i].pathnum=-1;
 
-									if(person[i].whichgun==nogun){
+									if (person[i].type != zombietype && person[i].whichgun == nogun) {
 										person[i].whichgun=possiblegun[randUint(numpossibleguns)];
 										person[i].reloads[person[i].whichgun]=1;
 										if(person[i].whichgun==knife)person[i].speedmult=.8+.5*difficulty;
@@ -1348,108 +1415,7 @@ void Game::Tick()
 		}
 	}
 
-	XYZ velocity;
-
-	if(person[0].attackframe>1||(person[0].attackframe>=0&&person[0].currentanimation==joganim)){
-
-		if(person[person[0].killtarget].skeleton.free<1&&person[0].killtarget!=0&&(person[0].aiming<1||person[0].whichgun==nogun||person[0].whichgun==knife||person[0].targetanimation==joganim)){
-			auto soundpos = person[0].playercoords + flatfacing
-				- camera.position;
-			if (person[person[0].killtarget].type != zombietype) {
-				if (person[0].whichgun != knife) {
-					playSound(gSourceID[headwhacksound],
-						soundpos.x, soundpos.y, soundpos.z);
-				} else {
-					playSound(gSourceID[knifeslashsound],
-						soundpos.x, soundpos.y, soundpos.z);
-
-					person[person[0].killtarget].bjoint1=&person[person[0].killtarget].skeleton.joints[neck];
-					person[person[0].killtarget].bjoint2=&person[person[0].killtarget].skeleton.joints[neck];
-					person[person[0].killtarget].bleeding=1;
-					person[person[0].killtarget].bleeddelay=1;
-					person[0].bjoint1=&person[0].skeleton.joints[righthand];
-					person[0].bjoint2=&person[0].skeleton.joints[righthand];
-
-					person[0].bleeding=1;
-					person[0].bleeddelay=1;
-
-					velocity=DoRotation(flatfacing,0,70,0)*50+person[0].velocity*2;
-					velocity.y+=30;
-					sprites.MakeSprite(bloodspritedown, .8, 1, .2, .2,DoRotation(person[person[0].killtarget].skeleton.joints[neck].position,0,person[person[0].killtarget].playerrotation,0)+person[person[0].killtarget].playercoords, velocity*.3, 2);
-					sprites.MakeSprite(bloodspritedown, .8, 1, .2, .2,DoRotation(person[person[0].killtarget].skeleton.joints[neck].position,0,person[person[0].killtarget].playerrotation,0)+person[person[0].killtarget].playercoords, velocity*.2, 3);
-					sprites.MakeSprite(bloodspritedown, .8, 1, .2, .2,DoRotation(person[person[0].killtarget].skeleton.joints[neck].position,0,person[person[0].killtarget].playerrotation,0)+person[person[0].killtarget].playercoords, velocity*.1, 4);
-				}
-
-				person[person[0].killtarget].health-=100;
-				person[person[0].killtarget].skeleton.free=1;
-				person[person[0].killtarget].longdead=1;
-
-				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 += randInt(-4, 4);
-					joint.velocity.y += randInt(-4, 4);
-					joint.velocity.z += randInt(-4, 4);
-				}
-
-				if(person[0].whichgun!=knife){
-					person[person[0].killtarget].skeleton.joints[head].velocity+=DoRotation(flatfacing,0,40,0)*50;
-					person[person[0].killtarget].skeleton.joints[head].velocity+=person[0].velocity*2;
-				}
-			} else if (!whacked) {
-				whacked = true;
-				if (person[0].whichgun != knife) {
-					playSound(gSourceID[headwhacksound],
-						soundpos.x, soundpos.y, soundpos.z);
-				} else {
-					playSound(gSourceID[knifeslashsound],
-						soundpos.x, soundpos.y, soundpos.z);
-
-					person[person[0].killtarget].bjoint1=&person[person[0].killtarget].skeleton.joints[neck];
-					person[person[0].killtarget].bjoint2=&person[person[0].killtarget].skeleton.joints[neck];
-
-					person[person[0].killtarget].bleeddelay=1;
-
-					person[0].bjoint1=&person[0].skeleton.joints[righthand];
-					person[0].bjoint2=&person[0].skeleton.joints[righthand];
-
-					person[0].bleeding=1;
-					person[0].bleeddelay=1;
-
-					velocity=DoRotation(flatfacing,0,70,0)*50+person[0].velocity*2;
-					velocity.y+=30;
-
-					sprites.MakeSprite(bloodspritedown, .8, 1, .2, .2,DoRotation(person[person[0].killtarget].skeleton.joints[neck].position,0,person[person[0].killtarget].playerrotation,0)+person[person[0].killtarget].playercoords, velocity*.3, 2);
-					sprites.MakeSprite(bloodspritedown, .8, 1, .2, .2,DoRotation(person[person[0].killtarget].skeleton.joints[neck].position,0,person[person[0].killtarget].playerrotation,0)+person[person[0].killtarget].playercoords, velocity*.2, 3);
-					sprites.MakeSprite(bloodspritedown, .8, 1, .2, .2,DoRotation(person[person[0].killtarget].skeleton.joints[neck].position,0,person[person[0].killtarget].playerrotation,0)+person[person[0].killtarget].playercoords, velocity*.1, 4);
-				}
-
-				person[person[0].killtarget].health-=200;
-				person[person[0].killtarget].maxhealth-=20;
-				person[person[0].killtarget].skeleton.free=1;
-				person[person[0].killtarget].longdead=1;
-
-				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 += randInt(-4, 4);
-					joint.velocity.y += randInt(-4, 4);
-					joint.velocity.z += randInt(-4, 4);
-				}
-
-				if(person[0].whichgun!=knife){
-					person[person[0].killtarget].skeleton.joints[head].velocity+=DoRotation(flatfacing,0,40,0)*50;
-					person[person[0].killtarget].skeleton.joints[head].velocity+=person[0].velocity*2;
-				}
-			}
-		}
-	}
+	attackCloseRange(this, flatfacing);
 
 	//Tackle
 	if (person[0].currentanimation == diveanim && visions == 0) {
@@ -2077,10 +2043,8 @@ void Game::Tick()
 				}
 
 				lastshot[0]=start;
-
 				lastshot[1]=oldend;
-
-				velocity=aim*8;
+				auto velocity = aim * 8;
 
 				if(person[j].whichgun!=sniperrifle&&person[j].whichgun!=shotgun&&p==numshots-1)sprites.MakeSprite(smokesprite, .3, 1, 1, 1, start+aim*1.5, velocity, 3);
 
@@ -2305,7 +2269,7 @@ void Game::Tick()
 	snowdelay-=multiplier;
 	while(snowdelay<0&&environment==snowy_environment){
 		snowdelay+=1/precipitationdensity*2;
-		velocity = {0.0f, -5.0f, 0.0f};
+		XYZ velocity {0.0f, -5.0f, 0.0f};
 		start=camera.position;
 		start.y+=precipitationvert;
 		start.x += randUint(precipitationhorz);
@@ -2315,7 +2279,7 @@ void Game::Tick()
 
 	while(snowdelay<0&&environment==rainy_environment){
 		snowdelay+=1/precipitationdensity/4;
-		velocity = {0.0f, -100.0f, 0.0f};
+		XYZ velocity {0.0f, -100.0f, 0.0f};
 		start=camera.position;
 		start.y+=precipitationvert;
 		start.x += randUint(precipitationhorz) * 0.5f;