aboutsummaryrefslogtreecommitdiff
path: root/src/GameTick.cpp
diff options
context:
space:
mode:
authorNguyễn Gia Phong <mcsinyx@disroot.org>2022-02-23 14:10:24 +0700
committerNguyễn Gia Phong <mcsinyx@disroot.org>2022-02-23 14:10:35 +0700
commit7e33695e843a68d711d2c48a5f18d02e171820d6 (patch)
tree09bd3569470d4b7a9b32cd8d0110e9e16cc94cf5 /src/GameTick.cpp
parentbb66a2a3e6ff47476e48caa1c51a3eb06a1cc0dc (diff)
downloadblackshades-7e33695e843a68d711d2c48a5f18d02e171820d6.tar.gz
Stop spawning enemies in the same block
The regression was introduced by 92367ddf025c ("Simplify NPC spawning").
Diffstat (limited to 'src/GameTick.cpp')
-rw-r--r--src/GameTick.cpp28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/GameTick.cpp b/src/GameTick.cpp
index 47e6af3..1193c3c 100644
--- a/src/GameTick.cpp
+++ b/src/GameTick.cpp
@@ -550,13 +550,18 @@ void spawnNpc(Game* game)
{
// Pick a random unfull block close to the player
int blockspawnx, blockspawny;
- auto& player = game->person[0];
- auto block = player.playercoords / block_spacing;
- for (auto i = 0; i < 10; ++i) {
+ auto block = game->person[0].playercoords / block_spacing;
+ auto npc_type = (game->type == zombie_type) ? zombietype
+ : randUint(game->evilprobability) ? civiliantype : eviltype;
+ auto& vip = game->person[1];
+ for (auto i = 0; i < 42; ++i) {
blockspawnx = block.x + 0.5f + randInt(-1, 1);
blockspawny = block.z + 0.5f + randInt(-1, 1);
- if (game->citypeoplenum[blockspawnx][blockspawny]
- < max_people_block)
+ if ((game->citypeoplenum[blockspawnx][blockspawny]
+ < max_people_block)
+ && (npc_type == civiliantype
+ || blockspawnx != vip.whichblockx
+ || blockspawny != vip.whichblocky))
break;
}
if (game->citypeoplenum[blockspawnx][blockspawny] >= max_people_block
@@ -584,27 +589,28 @@ void spawnNpc(Game* game)
npc.whichblockx = blockspawnx;
npc.whichblocky = blockspawny;
npc.whichcostume = casualcostumes + randUint(numcasual);
- if (game->type == zombie_type) {
- npc.type = zombietype;
+ switch (npc.type = npc_type) {
+ case zombietype:
npc.aiming = false;
npc.existing = true;
npc.pathsize = 1.04;
npc.speedmult = 0.7f + 0.2f * game->difficulty;
npc.targetanimation = zombiewalkanim;
- } else if (randUint(game->evilprobability)) {
- npc.type = civiliantype;
+ break;
+ case civiliantype:
npc.aiming = false;
npc.existing = false;
npc.pathsize = 0.98f + 0.04f * randFloat();
npc.speedmult = 0.8f + 0.4f * randFloat();
npc.targetanimation = walkanim;
- } else {
- npc.type = eviltype;
+ break;
+ case eviltype:
npc.aiming = true;
npc.existing = true;
npc.pathsize = 1.04;
npc.speedmult = 1.0f + 0.3f * game->difficulty;
npc.targetanimation = walkanim;
+ break;
}
npc.pathnum = -1;