aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNguyễn Gia Phong <mcsinyx@disroot.org>2022-02-19 22:13:36 +0700
committerNguyễn Gia Phong <mcsinyx@disroot.org>2022-02-19 23:49:03 +0700
commit62448e16340803ff8d2f8a73cacb90ccaf84f9e5 (patch)
tree66910d1253291a4b2ccfd37a86de128e42b46d46 /src
parent173a81f104a4fcffea96176fc11240d669033dde (diff)
downloadblackshades-62448e16340803ff8d2f8a73cacb90ccaf84f9e5.tar.gz
Move zombie control to separate function
Diffstat (limited to 'src')
-rw-r--r--src/GameTick.cpp76
1 files changed, 45 insertions, 31 deletions
diff --git a/src/GameTick.cpp b/src/GameTick.cpp
index 04502d5..0f883ad 100644
--- a/src/GameTick.cpp
+++ b/src/GameTick.cpp
@@ -849,6 +849,49 @@ void recoil(Game* game, size_t i)
person.recoil = 0;
}
+void controlZombie(Game* game, size_t i)
+{
+ auto& zombie = game->person[i];
+ if (zombie.type != zombietype)
+ return;
+ auto& vip = game->person[1];
+ if (findDistancefast(zombie.playercoords, vip.playercoords) > 20000
+ || zombie.speedmult < 0.7f) {
+ zombie.killtarget = -1;
+ return;
+ } else if (game->enemystate == 2) {
+ zombie.killtarget = 1;
+ }
+
+ auto& target = game->person[zombie.killtarget];
+ if (zombie.targetanimation != zombieeatanim || target.eaten != i)
+ return;
+ auto& target_joints = target.skeleton.joints;
+ target_joints[head].locked = true;
+ target_joints[rightshoulder].locked = true;
+
+ auto& zombie_joints = zombie.skeleton.joints;
+ target_joints[head].position = zombie.playercoords
+ + DoRotation(zombie_joints[righthand].position,
+ 0.0f, zombie.playerrotation, 0.0f);
+ target_joints[head].velocity = {};
+ target_joints[rightshoulder].position = zombie.playercoords
+ + DoRotation(zombie_joints[lefthand].position,
+ 0.0f, zombie.playerrotation, 0.0f);
+ target_joints[rightshoulder].velocity = {};
+ target.skeleton.DoConstraints();
+
+ size_t x = zombie.whichblockx, y = zombie.whichblocky;
+ auto& collide = game->blocksimplecollide[game->citytype[x][y]];
+ XYZ tmp;
+ auto rotation = game->cityrotation[x][y] * 90.0f;
+ target.skeleton.DoConstraints(&collide, &tmp, rotation);
+
+ target.skeleton.joints[rightshoulder].locked = false;
+ target.skeleton.joints[head].locked = false;
+ target.longdead = 1.0f;
+}
+
void renderLaser(Game* game)
{
auto& player = game->person[0];
@@ -998,36 +1041,7 @@ void Game::Tick()
heal(this, i);
if (!person[i].skeleton.free) {
recoil(this, i);
-
- //Zombie eat
- if(i > 0
- && person[i].targetanimation == zombieeatanim
- && person[person[i].killtarget].eaten == i) {
- person[person[i].killtarget].skeleton.joints[head].locked=1;
- person[person[i].killtarget].skeleton.joints[rightshoulder].locked=1;
-
- for(int k=0;k<2;k++){
- person[person[i].killtarget].skeleton.joints[head].position=DoRotation(person[i].skeleton.joints[righthand].position,0,person[i].playerrotation,0)+person[i].playercoords;
- person[person[i].killtarget].skeleton.joints[head].velocity = {};
- person[person[i].killtarget].skeleton.joints[rightshoulder].position=DoRotation(person[i].skeleton.joints[lefthand].position,0,person[i].playerrotation,0)+person[i].playercoords;
- person[person[i].killtarget].skeleton.joints[rightshoulder].velocity = {};
- person[person[i].killtarget].skeleton.DoConstraints();
- person[person[i].killtarget].skeleton.DoConstraints(&blocksimplecollide[citytype[person[i].whichblockx][person[i].whichblocky]],&move,cityrotation[person[i].whichblockx][person[i].whichblocky]*90);
- }
-
- person[person[i].killtarget].skeleton.joints[head].locked=0;
- person[person[i].killtarget].skeleton.joints[rightshoulder].locked=0;
- person[person[i].killtarget].longdead=1;
- }
-
- if(i>0&&enemystate!=1&&person[i].type==zombietype&&person[i].speedmult>.7){
- if(findDistancefast(person[i].playercoords,person[1].playercoords)<20000)person[i].killtarget=1;
- else person[i].killtarget=-1;
- }
-
- if(i>0&&enemystate!=1&&person[i].type==zombietype&&person[i].speedmult<.7){
- person[i].killtarget=-1;
- }
+ controlZombie(this, i);
bool realcheck = false;
@@ -1323,7 +1337,7 @@ void Game::Tick()
person[i].lastdistancevictim=200000;
person[i].pathnum=-1;
- if (person[i].type != zombietype && person[i].whichgun == nogun) {
+ if (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;