From e1674d502e9d5aa4b0360e9640da88a284084b5a Mon Sep 17 00:00:00 2001 From: bones_was_here Date: Mon, 3 Oct 2022 16:36:01 +1000 Subject: [PATCH] Fix bug where ReadyRestart could cause teamed items to all spawn together For weapons this was subtle: ghost item(s) would appear as well as the item selected to spawn. For powerups they would all spawn at once, and/or previously scheduled spawns were not cancelled. Fixing this requires leaving the first of the teamed items marked so Item_FindTeam() will do its job again at ReadyRestart. This requires changing the abused effect field to a bitmask other than EF_NODRAW so that DP will draw the ghost for the marked item. Some minor cleanups to Item_FindTeam() are included. --- qcsrc/server/items/items.qc | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/qcsrc/server/items/items.qc b/qcsrc/server/items/items.qc index ea325eeeb..5f89f7eea 100644 --- a/qcsrc/server/items/items.qc +++ b/qcsrc/server/items/items.qc @@ -748,12 +748,9 @@ void Item_Reset(entity this) void Item_FindTeam(entity this) { - entity e; - - if(!(this.effects & EF_NODRAW)) + if(!(this.effects & EF_NOGUNBOB)) // marker for item team search return; - // marker for item team search LOG_TRACE("Initializing item team ", ftos(this.team)); RandomSelection_Init(); IL_EACH(g_items, it.team == this.team, @@ -762,7 +759,7 @@ void Item_FindTeam(entity this) RandomSelection_AddEnt(it, it.cnt, 0); }); - e = RandomSelection_chosen_ent; + entity e = RandomSelection_chosen_ent; if (!e) return; @@ -772,13 +769,17 @@ void Item_FindTeam(entity this) { if(it != e) { - // make it non-spawned - Item_Show(it, -1); - it.state = 1; // state 1 = initially hidden item, apparently + Item_Show(it, -1); // make it non-spawned + if (it.waypointsprite_attached) + WaypointSprite_Kill(it.waypointsprite_attached); + it.nextthink = 0; // disable any scheduled powerup spawn } else Item_Reset(it); - it.effects &= ~EF_NODRAW; + + // leave 'this' marked so Item_FindTeam() works when called again via this.reset + if(it != this) + it.effects &= ~EF_NOGUNBOB; } }); } @@ -1017,7 +1018,7 @@ void _StartItem(entity this, entity def, float defaultrespawntime, float default if(this.angles != '0 0 0') this.SendFlags |= ISF_ANGLES; - this.reset = Item_Reset; + this.reset = this.team ? Item_FindTeam : Item_Reset; // it's a level item if(this.spawnflags & 1) this.noalign = 1; @@ -1127,7 +1128,7 @@ void _StartItem(entity this, entity def, float defaultrespawntime, float default if(!this.cnt) this.cnt = 1; // item probability weight - this.effects |= EF_NODRAW; // marker for item team search + this.effects |= EF_NOGUNBOB; // marker for item team search InitializeEntity(this, Item_FindTeam, INITPRIO_FINDTARGET); } else -- 2.39.2