From 695a573f7bf796ab9d1f936ae0b161a5a4f057d2 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 4 Dec 2013 01:14:34 +1100 Subject: [PATCH] Use a spawnflag to check if the monster has re-spawned --- qcsrc/common/monsters/monster/mage.qc | 2 +- qcsrc/common/monsters/spawn.qc | 12 ++++++++- qcsrc/common/monsters/sv_monsters.qc | 30 ++++++++++++++-------- qcsrc/common/monsters/sv_monsters.qh | 3 +-- qcsrc/server/mutators/gamemode_invasion.qc | 6 ++--- 5 files changed, 35 insertions(+), 18 deletions(-) diff --git a/qcsrc/common/monsters/monster/mage.qc b/qcsrc/common/monsters/monster/mage.qc index 83924ab7d..6822363c5 100644 --- a/qcsrc/common/monsters/monster/mage.qc +++ b/qcsrc/common/monsters/monster/mage.qc @@ -147,7 +147,7 @@ void mage_spike_think() self.wait = bound((autocvar_g_monster_mage_attack_spike_smart_trace_min), vlen(self.origin - trace_endpos), self.wait = (autocvar_g_monster_mage_attack_spike_smart_trace_max)); // Calc how important it is that we turn and add this to the desierd (enemy) dir. - desireddir = normalize(((trace_plane_normal * (1 - trace_fraction)) + (desireddir * trace_fraction)) * 0.5); + desireddir = normalize(((trace_plane_normal * (1 - trace_fraction)) + (desireddir * trace_fraction)) * 0.5); } newdir = normalize(olddir + desireddir * turnrate); // take the average of the 2 directions; not the best method but simple & easy diff --git a/qcsrc/common/monsters/spawn.qc b/qcsrc/common/monsters/spawn.qc index 3fe8567ae..924a728a0 100644 --- a/qcsrc/common/monsters/spawn.qc +++ b/qcsrc/common/monsters/spawn.qc @@ -4,6 +4,7 @@ entity spawnmonster (string monster, float monster_id, entity spawnedby, entity initialize_field_db(); entity e = spawn(); + float i; e.spawnflags = MONSTERFLAG_SPAWNED; @@ -12,9 +13,18 @@ entity spawnmonster (string monster, float monster_id, entity spawnedby, entity setorigin(e, orig); + if(monster == "random") + { + RandomSelection_Init(); + for(i = MON_FIRST; i <= MON_LAST; ++i) + RandomSelection_Add(world, 0, (get_monsterinfo(i)).netname, 1, 1); + + monster = RandomSelection_chosen_string; + } + if(monster != "") { - float i, found = 0; + float found = 0; entity mon; for(i = MON_FIRST; i <= MON_LAST; ++i) { diff --git a/qcsrc/common/monsters/sv_monsters.qc b/qcsrc/common/monsters/sv_monsters.qc index 8176dee3d..28a78ceb8 100644 --- a/qcsrc/common/monsters/sv_monsters.qc +++ b/qcsrc/common/monsters/sv_monsters.qc @@ -361,7 +361,7 @@ void Monster_Fade () { if(Monster_CanRespawn(self)) { - self.monster_respawned = TRUE; + self.spawnflags |= MONSTERFLAG_RESPAWNED; self.think = self.monster_spawnfunc; self.nextthink = time + self.respawntime; self.ltime = 0; @@ -379,7 +379,16 @@ void Monster_Fade () setmodel(self, "null"); } else + { + // number of monsters spawned with mobspawn command + totalspawned -= 1; + + if(IS_CLIENT(self.realowner)) + if(!(self.spawnflags & MONSTERFLAG_RESPAWNED)) + self.realowner.monstercount -= 1; + SUB_SetFade(self, time + 3, 1); + } } float Monster_CanJump (vector vel) @@ -798,7 +807,7 @@ void monsters_corpse_damage (entity inflictor, entity attacker, float damage, fl Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker); if(IS_CLIENT(self.realowner)) - if(!self.monster_respawned) + if(!(self.spawnflags & MONSTERFLAG_RESPAWNED)) self.realowner.monstercount -= 1; self.think = SUB_Remove; @@ -822,21 +831,20 @@ void monster_die(entity attacker, float gibbed) MonsterSound(monstersound_death, 0, FALSE, CH_VOICE); - if(!(self.spawnflags & MONSTERFLAG_SPAWNED) && !self.monster_respawned) + if(!(self.spawnflags & MONSTERFLAG_SPAWNED) && !(self.spawnflags & MONSTERFLAG_RESPAWNED)) monsters_killed += 1; if(IS_PLAYER(attacker)) - if( autocvar_g_monsters_score_spawned || - ( !(self.spawnflags & MONSTERFLAG_SPAWNED) && !self.monster_respawned) ) + if(autocvar_g_monsters_score_spawned || !((self.spawnflags & MONSTERFLAG_SPAWNED) || (self.spawnflags & MONSTERFLAG_RESPAWNED))) PlayerScore_Add(attacker, SP_SCORE, +autocvar_g_monsters_score_kill); - if(!Monster_CanRespawn(self) || gibbed) + if(!Monster_CanRespawn(self) && gibbed) { // number of monsters spawned with mobspawn command totalspawned -= 1; if(IS_CLIENT(self.realowner)) - if(!self.monster_respawned) + if(!(self.spawnflags & MONSTERFLAG_RESPAWNED)) self.realowner.monstercount -= 1; } @@ -973,7 +981,7 @@ float monster_spawn() { MON_ACTION(self.monsterid, MR_SETUP); - if(!self.monster_respawned) + if(!(self.spawnflags & MONSTERFLAG_RESPAWNED)) { Monster_CheckMinibossFlag(); self.health *= Monster_SkillModifier(); @@ -985,7 +993,7 @@ float monster_spawn() if(IS_PLAYER(self.monster_owner)) self.effects |= EF_DIMLIGHT; - if(!self.monster_respawned) + if(!(self.spawnflags & MONSTERFLAG_RESPAWNED)) if(!self.skin) self.skin = rint(random() * 4); @@ -1032,7 +1040,7 @@ float monster_initialize(float mon_id, float nodrop) self.team = 0; if(!(self.spawnflags & MONSTERFLAG_SPAWNED)) // naturally spawned monster - if(!self.monster_respawned) + if(!(self.spawnflags & MONSTERFLAG_RESPAWNED)) monsters_total += 1; setmodel(self, mon.model); @@ -1115,7 +1123,7 @@ float monster_initialize(float mon_id, float nodrop) if(!monster_spawn()) return FALSE; - if(!self.monster_respawned) + if(!(self.spawnflags & MONSTERFLAG_RESPAWNED)) monster_setupcolors(); CSQCMODEL_AUTOINIT(); diff --git a/qcsrc/common/monsters/sv_monsters.qh b/qcsrc/common/monsters/sv_monsters.qh index a35d88805..653312072 100644 --- a/qcsrc/common/monsters/sv_monsters.qh +++ b/qcsrc/common/monsters/sv_monsters.qh @@ -59,8 +59,6 @@ ALLMONSTERSOUNDS float GetMonsterSoundSampleField_notFound; -.float monster_respawned; // used to make sure we're not recounting respawned monster stats - const float MONSTERSKILL_NOTEASY = 256; // monster will not spawn on skill <= 1 const float MONSTERSKILL_NOTMEDIUM = 512; // monster will not spawn on skill 2 const float MONSTERSKILL_NOTHARD = 1024; // monster will not spawn on skill >= 3 @@ -72,6 +70,7 @@ const float MONSTERFLAG_FLY_VERTICAL = 8; // fly/swim vertically const float MONSTERFLAG_INFRONT = 32; // only check for enemies infront of us const float MONSTERFLAG_MINIBOSS = 64; // monster spawns as mini-boss (also has a chance of naturally becoming one) const float MONSTERFLAG_SPAWNED = 16384; // flag for spawned monsters +const float MONSTERFLAG_RESPAWNED = 32768; // flag for re-spawned monsters .void() monster_spawnfunc; diff --git a/qcsrc/server/mutators/gamemode_invasion.qc b/qcsrc/server/mutators/gamemode_invasion.qc index f7442c1ca..2147e6a81 100644 --- a/qcsrc/server/mutators/gamemode_invasion.qc +++ b/qcsrc/server/mutators/gamemode_invasion.qc @@ -18,7 +18,7 @@ float invasion_PickMonster(float supermonster_count) for(i = MON_FIRST; i <= MON_LAST; ++i) { mon = get_monsterinfo(i); - if((mon.spawnflags & MONSTER_TYPE_FLY) || (mon.spawnflags & MONSTER_TYPE_SWIM) || (mon.spawnflags & MON_FLAG_SUPERMONSTER && supermonster_count >= 1)) + if((mon.spawnflags & MONSTER_TYPE_FLY) || (mon.spawnflags & MONSTER_TYPE_SWIM) || ((mon.spawnflags & MON_FLAG_SUPERMONSTER) && supermonster_count >= 1)) continue; // flying/swimming monsters not yet supported RandomSelection_Add(world, i, "", 1, 1); @@ -183,7 +183,7 @@ void Invasion_RoundStart() MUTATOR_HOOKFUNCTION(invasion_MonsterDies) { - if(!self.monster_respawned) + if(!(self.spawnflags & MONSTERFLAG_RESPAWNED)) { numkilled += 1; maxcurrent -= 1; @@ -206,7 +206,7 @@ MUTATOR_HOOKFUNCTION(invasion_MonsterSpawn) if(roundcnt < maxrounds && self.spawnflags & MONSTERFLAG_MINIBOSS) self.spawnflags &= ~MONSTERFLAG_MINIBOSS; - if(!self.monster_respawned) + if(!(self.spawnflags & MONSTERFLAG_RESPAWNED)) { numspawned += 1; maxcurrent += 1; -- 2.39.2