From 0e83bfa836d40bdab5d96e17b6dd1b822f459fd7 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 28 Jul 2016 03:00:28 +1000 Subject: [PATCH] Add an intrusive list for monsters --- qcsrc/common/monsters/sv_monsters.qc | 2 + qcsrc/common/weapons/weapon/shockwave.qc | 12 +++--- qcsrc/server/_all.qh | 2 +- qcsrc/server/command/common.qc | 14 ++++--- qcsrc/server/defs.qh | 3 ++ qcsrc/server/g_subs.qc | 12 +++--- qcsrc/server/g_world.qc | 3 +- .../mutators/mutator/gamemode_invasion.qc | 40 +++++++++++-------- qcsrc/server/weapons/tracing.qc | 12 +++--- 9 files changed, 57 insertions(+), 43 deletions(-) diff --git a/qcsrc/common/monsters/sv_monsters.qc b/qcsrc/common/monsters/sv_monsters.qc index ae7dc5157..2855ac429 100644 --- a/qcsrc/common/monsters/sv_monsters.qc +++ b/qcsrc/common/monsters/sv_monsters.qc @@ -1290,6 +1290,8 @@ bool Monster_Spawn(entity this, int mon_id) if(!autocvar_g_monsters) { Monster_Remove(this); return false; } + IL_PUSH(g_monsters, this); + if(Monster_Appear_Check(this, mon_id)) { return true; } // return true so the monster isn't removed if(!this.monster_skill) diff --git a/qcsrc/common/weapons/weapon/shockwave.qc b/qcsrc/common/weapons/weapon/shockwave.qc index 953660594..d464da570 100644 --- a/qcsrc/common/weapons/weapon/shockwave.qc +++ b/qcsrc/common/weapons/weapon/shockwave.qc @@ -407,9 +407,9 @@ void W_Shockwave_Attack(entity actor) if(lag) { FOREACH_CLIENT(IS_PLAYER(it) && it != actor, antilag_takeback(it, CS(it), time - lag)); - FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, { - if (it != actor) - antilag_takeback(it, it, time - lag); + IL_EACH(g_monsters, it != actor, + { + antilag_takeback(it, it, time - lag); }); } @@ -687,9 +687,9 @@ void W_Shockwave_Attack(entity actor) if(lag) { FOREACH_CLIENT(IS_PLAYER(it) && it != actor, antilag_restore(it, CS(it))); - FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, { - if (it != actor) - antilag_restore(it, it); + IL_EACH(g_monsters, it != actor, + { + antilag_restore(it, it); }); } } diff --git a/qcsrc/server/_all.qh b/qcsrc/server/_all.qh index a32f8b583..ed3083a12 100644 --- a/qcsrc/server/_all.qh +++ b/qcsrc/server/_all.qh @@ -43,7 +43,7 @@ const string STR_OBSERVER = "observer"; #define FOREACH_CLIENT(cond, body) FOREACH_CLIENTSLOT(IS_CLIENT(it) && (cond), body) -// NOTE: FOR_EACH_MONSTER deprecated! Use the following instead: FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, { code; }); +// NOTE: FOR_EACH_MONSTER deprecated! Use the following instead: IL_EACH(g_monsters, true, { code; }); #include #include diff --git a/qcsrc/server/command/common.qc b/qcsrc/server/command/common.qc index 3c97737e5..81dc1a60e 100644 --- a/qcsrc/server/command/common.qc +++ b/qcsrc/server/command/common.qc @@ -364,10 +364,10 @@ void CommonCommand_editmob(int request, entity caller, int argc) if (arg_lower == "list") { print_to(caller, monsterlist_reply); return; } - FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, LAMBDA( - if(it.realowner == caller) - ++tmp_moncount; - )); + IL_EACH(g_monsters, it.realowner == caller, + { + ++tmp_moncount; + }); if (!autocvar_g_monsters) { print_to(caller, "Monsters are disabled"); return; } if (autocvar_g_monsters_max <= 0 || autocvar_g_monsters_max_perplayer <= 0) { print_to(caller, "Monster spawning is disabled"); return; } @@ -436,10 +436,12 @@ void CommonCommand_editmob(int request, entity caller, int argc) int tmp_remcount = 0; - FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, LAMBDA( + IL_EACH(g_monsters, true, + { Monster_Remove(it); ++tmp_remcount; - )); + }); + IL_CLEAR(g_monsters); monsters_total = monsters_killed = totalspawned = 0; diff --git a/qcsrc/server/defs.qh b/qcsrc/server/defs.qh index df791a626..30c9bb449 100644 --- a/qcsrc/server/defs.qh +++ b/qcsrc/server/defs.qh @@ -443,3 +443,6 @@ const int MIF_GUIDED_CONFUSABLE = MIF_GUIDED_HEAT | MIF_GUIDED_AI; .bool init_for_player_needed; .void(entity this, entity player) init_for_player; + +IntrusiveList g_monsters; +STATIC_INIT(g_monsters) { g_monsters = IL_NEW(); } diff --git a/qcsrc/server/g_subs.qc b/qcsrc/server/g_subs.qc index f3fb1a322..e4affe265 100644 --- a/qcsrc/server/g_subs.qc +++ b/qcsrc/server/g_subs.qc @@ -51,9 +51,9 @@ void tracebox_antilag_force_wz (entity source, vector v1, vector mi, vector ma, { // take players back into the past FOREACH_CLIENT(IS_PLAYER(it) && it != forent, antilag_takeback(it, CS(it), time - lag)); - FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, { - if(it != forent) - antilag_takeback(it, it, time - lag); + IL_EACH(g_monsters, it != forent, + { + antilag_takeback(it, it, time - lag); }); } @@ -67,9 +67,9 @@ void tracebox_antilag_force_wz (entity source, vector v1, vector mi, vector ma, if (lag) { FOREACH_CLIENT(IS_PLAYER(it) && it != forent, antilag_restore(it, CS(it))); - FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, { - if (it != forent) - antilag_restore(it, it); + IL_EACH(g_monsters, it != forent, + { + antilag_restore(it, it); }); } diff --git a/qcsrc/server/g_world.qc b/qcsrc/server/g_world.qc index 2eff929b8..5102aecdf 100644 --- a/qcsrc/server/g_world.qc +++ b/qcsrc/server/g_world.qc @@ -2051,7 +2051,8 @@ void EndFrame() it.damage_dealt = 0; antilag_record(it, CS(it), altime); }); - FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, { + IL_EACH(g_monsters, true, + { antilag_record(it, it, altime); }); FOREACH_CLIENT(PS(it), { diff --git a/qcsrc/server/mutators/mutator/gamemode_invasion.qc b/qcsrc/server/mutators/mutator/gamemode_invasion.qc index 9d31506e6..ffbd29cdf 100644 --- a/qcsrc/server/mutators/mutator/gamemode_invasion.qc +++ b/qcsrc/server/mutators/mutator/gamemode_invasion.qc @@ -193,7 +193,11 @@ float Invasion_CheckWinner() { if(round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0) { - FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, LAMBDA(Monster_Remove(it))); + IL_EACH(g_monsters, true, + { + Monster_Remove(it); + }); + IL_CLEAR(g_monsters); Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_ROUND_OVER); Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ROUND_OVER); @@ -203,23 +207,21 @@ float Invasion_CheckWinner() float total_alive_monsters = 0, supermonster_count = 0, red_alive = 0, blue_alive = 0, yellow_alive = 0, pink_alive = 0; - FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, LAMBDA( - if(it.health > 0) - { - if((get_monsterinfo(it.monsterid)).spawnflags & MON_FLAG_SUPERMONSTER) - ++supermonster_count; - ++total_alive_monsters; + IL_EACH(g_monsters, it.health > 0, + { + if((get_monsterinfo(it.monsterid)).spawnflags & MON_FLAG_SUPERMONSTER) + ++supermonster_count; + ++total_alive_monsters; - if(teamplay) - switch(it.team) - { - case NUM_TEAM_1: ++red_alive; break; - case NUM_TEAM_2: ++blue_alive; break; - case NUM_TEAM_3: ++yellow_alive; break; - case NUM_TEAM_4: ++pink_alive; break; - } + if(teamplay) + switch(it.team) + { + case NUM_TEAM_1: ++red_alive; break; + case NUM_TEAM_2: ++blue_alive; break; + case NUM_TEAM_3: ++yellow_alive; break; + case NUM_TEAM_4: ++pink_alive; break; } - )); + }); if((total_alive_monsters + inv_numkilled) < inv_maxspawned && inv_maxcurrent < inv_maxspawned) { @@ -272,7 +274,11 @@ float Invasion_CheckWinner() )); } - FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, LAMBDA(Monster_Remove(it))); + IL_EACH(g_monsters, true, + { + Monster_Remove(it); + }); + IL_CLEAR(g_monsters); if(teamplay) { diff --git a/qcsrc/server/weapons/tracing.qc b/qcsrc/server/weapons/tracing.qc index 5c64a0ec6..6e7279618 100644 --- a/qcsrc/server/weapons/tracing.qc +++ b/qcsrc/server/weapons/tracing.qc @@ -377,9 +377,9 @@ void fireBullet(entity this, vector start, vector dir, float spread, float max_s if(lag) { FOREACH_CLIENT(IS_PLAYER(it) && it != this, antilag_takeback(it, CS(it), time - lag)); - FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, { - if (it != this) - antilag_takeback(it, it, time - lag); + IL_EACH(g_monsters, it != this, + { + antilag_takeback(it, it, time - lag); }); } @@ -492,9 +492,9 @@ void fireBullet(entity this, vector start, vector dir, float spread, float max_s if(lag) { FOREACH_CLIENT(IS_PLAYER(it) && it != this, antilag_restore(it, CS(it))); - FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, { - if (it != this) - antilag_restore(it, it); + IL_EACH(g_monsters, it != this, + { + antilag_restore(it, it); }); } -- 2.39.2