From 242754f8119f53924b0beed470dc989e80023dab Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 12 Sep 2026 16:53:14 +0200 Subject: [PATCH 01/35] disable flat precaching in opengl in encoremode this appears to mess up remapping behavior in certain cases (ex. sneaker/spring panels) since i cba looking into properly fixing this, ill just disable this for now --- src/hardware/hw_cache.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 423a75b32..13354bda4 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -624,13 +624,26 @@ static void HWR_PrecacheLevelFlats(void) { // lookup for flats that may´ve been already loaded flatcheck flatpresent; - size_t i, j; + size_t i; +#if 0 + size_t j; +#endif INT32 k; + // this kinda messes up encore remapping behavior at times + // so just disable it for now ig +#ifdef GLENCORE + if (encoremap) + { + return; + } +#endif + flatcheck_init(&flatpresent); flatcheck_reserve(&flatpresent, numlevelflats); // special case for encore +#if 0 #ifdef GLENCORE if (encoremap) { @@ -670,6 +683,7 @@ static void HWR_PrecacheLevelFlats(void) } } else +#endif #endif { // on non encore we have it simple @@ -1315,6 +1329,7 @@ void HWR_SetPalette(RGBA_t *palette) crushed_palette[i].s.blue = (UINT8)(fblue / 31.0f * 255.0f); crushed_palette[i].s.alpha = 255; } + GL_SetScreenPalette(crushed_palette); } else @@ -1392,6 +1407,7 @@ void HWR_SetMapPalette(void) I_Error("HWR_SetMapPalette: A programmer assumed palette lumps are at least 768 bytes long, but apparently this was a wrong assumption!\n"); RGB_data = (UINT8 *)(W_CacheLumpNum(lumpnum, PU_CACHE)); + // we got the RGB palette now, but we need it in RGBA format. for (i = 0; i < 256; i++) { @@ -1400,6 +1416,7 @@ void HWR_SetMapPalette(void) RGBA_converted[i].s.blue = *(RGB_data++); RGBA_converted[i].s.alpha = 255; } + palette = RGBA_converted; } @@ -1407,6 +1424,7 @@ void HWR_SetMapPalette(void) if (memcmp(mapPalette, palette, sizeof(mapPalette))) { memcpy(mapPalette, palette, sizeof(mapPalette)); + // in palette rendering mode, this means that all rgba textures now have wrong colors // and the lookup table is outdated HWR_SetPaletteLookup(mapPalette); From 70f4207e02b4f831de5df65764237aa836225ca6 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 17 Sep 2026 11:40:41 +0200 Subject: [PATCH 02/35] =?UTF-8?q?smol=20fix=20for=20pm=C2=B4s=20in=20DoSay?= =?UTF-8?q?Command?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sending a pm might change the length of the string which we need to reconsider when sending the cmd --- src/hu_stuff.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 8f131b3d2..62665f332 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -472,9 +472,7 @@ static void DoSayCommand(SINT8 target, size_t usedargs, UINT8 flags) strlcat(msg, COM_Argv(ix + usedargs), msgspace); } - const size_t msglength = strlen(msg); - - if (msglength > 4 && strnicmp(msg, "/pm", 3) == 0) // used /pm + if (strlen(msg) > 4 && strnicmp(msg, "/pm", 3) == 0) // used /pm { // what we're gonna do now is check if the node exists // with that logic, characters 4 and 5 are our numbers: @@ -528,7 +526,7 @@ static void DoSayCommand(SINT8 target, size_t usedargs, UINT8 flags) strlcpy(msg, newmsg, HU_MAXMSGLEN + 1); } - SendNetXCmd(XD_SAY, buf, msglength + 1 + msg-buf); + SendNetXCmd(XD_SAY, buf, strlen(msg) + 1 + msg-buf); } /** Send a message to everyone. @@ -779,12 +777,11 @@ static void Got_Saycmd(const UINT8 **p, INT32 playernum) return; } - const size_t msglength = strlen(msg); - //check for invalid characters (0x80 or above) { size_t i; - const size_t j = msglength; + const size_t j = strlen(msg); + for (i = 0; i < j; i++) { if (msg[i] & 0x80) @@ -831,7 +828,7 @@ static void Got_Saycmd(const UINT8 **p, INT32 playernum) } // Handle "/me" actions, but only in messages to everyone. - if (target == 0 && msglength > 4 && strnicmp(msg, "/me ", 4) == 0) + if (target == 0 && strlen(msg) > 4 && strnicmp(msg, "/me ", 4) == 0) { msg += 4; action = true; From 2d79ff9606d9db84e625173eba027c4f3cecec5e Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 17 Sep 2026 11:44:06 +0200 Subject: [PATCH 03/35] few more smoler style cleanups --- src/d_clisrv.c | 5 +- src/d_netcmd.c | 2 +- src/hardware/hw_batching.c | 10 +-- src/hardware/r_opengl/r_opengl.c | 1 + src/k_kart.c | 1 - src/m_menu.c | 118 +++++++++++++++++++++---------- src/p_mobj.c | 3 +- src/p_user.c | 2 +- src/st_stuff.c | 2 +- src/y_inter.c | 2 + src/z_zone.cpp | 6 +- 11 files changed, 98 insertions(+), 54 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 5a87b6da0..5a0930367 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1822,7 +1822,7 @@ static void SV_SendPlayerInfo(INT32 node) // Extra data // Kart has extra skincolors, so we can't use this - //netbuffer->u.playerinfo[i].data = 0; //netbuffer->u.playerinfo[i].data = players[i].skincolor; + //netbuffer->u.playerinfo[i].data = 0; // well why not, we only got like 100 of these? netbuffer->u.playerinfo[i].data = players[i].skincolor; @@ -5174,7 +5174,7 @@ static void PT_ServerInfo(SINT8 node) const tic_t ticthen = (tic_t)LONG(netbuffer->u.serverinfo.time); const tic_t ticdiff = (ticnow - ticthen)*1000/NEWTICRATE; netbuffer->u.serverinfo.time = (tic_t)LONG(ticdiff); - netbuffer->u.serverinfo.servername[MAXSERVERNAME-1] = 0; + netbuffer->u.serverinfo.servername[MAXSERVERNAME-1] = '\0'; netbuffer->u.serverinfo.application [sizeof netbuffer->u.serverinfo.application - 1] = '\0'; memcpy(servername, netbuffer->u.serverinfo.servername, MAXSERVERNAME); @@ -7253,6 +7253,7 @@ static void DedicatedIdleUpdate(INT32 *realtics) { CONS_Printf("DEDICATED: Awakening from idle (Player detected...)\n"); } + dedicatedidle = 0; } } diff --git a/src/d_netcmd.c b/src/d_netcmd.c index f0ebc5fc4..253f353db 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -4381,7 +4381,7 @@ static void Got_RequestAddfilecmd(const UINT8 **cp, INT32 playernum) else snprintf(message, sizeof(message), M_GetText("Unknown error finding wad file (%s)\n"), filename); - CONS_Printf("%s",message); + CONS_Printf("%s", message); for (j = 0; j < MAXPLAYERS; j++) if (adminplayers[j]) diff --git a/src/hardware/hw_batching.c b/src/hardware/hw_batching.c index 9b1699029..b647decc9 100644 --- a/src/hardware/hw_batching.c +++ b/src/hardware/hw_batching.c @@ -35,7 +35,7 @@ static int finalVertexArrayAllocSize = 65536; // not gonna use this for now, just sort by color and change state when it changes // later maybe when using vertex attributes if it's needed -static PolygonArrayEntry* polygonArray = NULL ;// contains the polygon data from DrawPolygon, waiting to be processed +static PolygonArrayEntry* polygonArray = NULL; // contains the polygon data from DrawPolygon, waiting to be processed static PolygonArrayEntry **polygonArraySorted = NULL; // contains sorted pointers to polygonArray static int polygonArraySize = 0; static int polygonArrayAllocSize = 65536; @@ -171,8 +171,8 @@ static int comparePolygons(const void *p1, const void *p2) // special case with signedness to prevent overflowing // FIXME: check for prediction slowdowns! - const int shader1 = poly1->hash & 0x80000000 ? -1 : poly1->shader; - const int shader2 = poly2->hash & 0x80000000 ? -1 : poly2->shader; + const int shader1 = (poly1->hash & 0x80000000) ? -1 : poly1->shader; + const int shader2 = (poly2->hash & 0x80000000) ? -1 : poly2->shader; // skywalls and horizon lines must retain their order for horizon lines to work if (shader1 == -1 && shader2 == -1) @@ -214,8 +214,8 @@ static int comparePolygonsNoShaders(const void *p1, const void *p2) const PolygonArrayEntry *poly1 = *(PolygonArrayEntry *const *)p1; const PolygonArrayEntry *poly2 = *(PolygonArrayEntry *const *)p2; - const GLMipmap_t *texture1 = poly1->hash & 0x80000000 ? NULL : poly1->texture; - const GLMipmap_t *texture2 = poly2->hash & 0x80000000 ? NULL : poly2->texture; + const GLMipmap_t *texture1 = (poly1->hash & 0x80000000) ? NULL : poly1->texture; + const GLMipmap_t *texture2 = (poly2->hash & 0x80000000) ? NULL : poly2->texture; // skywalls and horizon lines must retain their order for horizon lines to work if (!texture1 && !texture2) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 0e846a17e..8fe1dff4b 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1931,6 +1931,7 @@ static void GenerateMipmaps(INT32 w, INT32 h, RGBA_t *tex, INT32 maxLOD, UINT32 { if (samplePoint[p].s.alpha == 0) continue; + sumR += samplePoint[p].s.red; sumG += samplePoint[p].s.green; sumB += samplePoint[p].s.blue; diff --git a/src/k_kart.c b/src/k_kart.c index e8b48e7d8..07fbacfdf 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -4337,7 +4337,6 @@ static void K_DoShrink(player_t *user) } } - void K_DoPogoSpring(mobj_t *mo, fixed_t vertispeed, UINT8 sound) { if (mo->player && mo->player->spectator) diff --git a/src/m_menu.c b/src/m_menu.c index 4a8344b3d..82bc1d584 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -7667,7 +7667,7 @@ static void M_DrawMPMainMenu(void) { char buf[28]; strlcpy(buf, setupm_ip, sizeof(buf)); - V_DrawString(x+8,y+12, V_ALLOWLOWERCASE, buf); + V_DrawString(x+8, y+12, V_ALLOWLOWERCASE, buf); } else M_DrawTextInputScroll(x+8, y+12, &setupm_input_ip, 0, SETUPM_IP_MAXSIZE); @@ -8205,12 +8205,12 @@ static void M_DrawSetupMultiPlayerMenu(void) case SKINMENUTYPE_EXTENDED: for (s = 0; s < SKINGRIDNEWWIDTH*SKINGRIDNEWHEIGHT; s++) { - INT32 x = ((s % SKINGRIDNEWWIDTH) * 18) + ((BASEVIDWIDTH / 2) - (18 * SKINGRIDNEWWIDTH) - 8) + 100 + SKINXSHIFT; //BASEVIDWIDTH / 2 - ((icons + 1) * 24) - 4; - INT32 y = ((s / SKINGRIDNEWWIDTH) * 18) + ((BASEVIDHEIGHT / 2) - (18 * (SKINGRIDNEWWIDTH/2)) + 10); //BASEVIDWIDTH / 2 - ((icons + 1) * 24) - 4; - INT32 calcs = s + (setupm_skinypos * SKINGRIDNEWWIDTH); INT32 skinn; patch_t *face; UINT8 *cmap; + const INT32 x = ((s % SKINGRIDNEWWIDTH) * 18) + ((BASEVIDWIDTH / 2) - (18 * SKINGRIDNEWWIDTH) - 8) + 100 + SKINXSHIFT; //BASEVIDWIDTH / 2 - ((icons + 1) * 24) - 4; + const INT32 y = ((s / SKINGRIDNEWWIDTH) * 18) + ((BASEVIDHEIGHT / 2) - (18 * (SKINGRIDNEWWIDTH/2)) + 10); //BASEVIDWIDTH / 2 - ((icons + 1) * 24) - 4; + const INT32 calcs = s + (setupm_skinypos * SKINGRIDNEWWIDTH); if (calcs < numskins) skinn = skinsorted[calcs]; @@ -8231,10 +8231,10 @@ static void M_DrawSetupMultiPlayerMenu(void) if (itemOn == 1) //has to be on skin select part { patch_t *cursor; - INT32 curx = (((setupm_skinselect % SKINGRIDNEWWIDTH) * 18) + ((BASEVIDWIDTH / 2) - (18 * SKINGRIDNEWWIDTH/2)) + SKINXSHIFT) + 20; - INT32 cury = (((setupm_skinselect / SKINGRIDNEWWIDTH) - setupm_skinypos) * 18) + ((BASEVIDHEIGHT / 2) - (18 * (SKINGRIDNEWWIDTH/2))+ 10); + const INT32 curx = (((setupm_skinselect % SKINGRIDNEWWIDTH) * 18) + ((BASEVIDWIDTH / 2) - (18 * SKINGRIDNEWWIDTH/2)) + SKINXSHIFT) + 20; + const INT32 cury = (((setupm_skinselect / SKINGRIDNEWWIDTH) - setupm_skinypos) * 18) + ((BASEVIDHEIGHT / 2) - (18 * (SKINGRIDNEWWIDTH/2))+ 10); - UINT8 cursorframe = (I_GetTime() / 4) % 7; + const UINT8 cursorframe = (I_GetTime() / 4) % 7; cursor = (patch_t *)W_CachePatchName(va("K_CHILI%d", cursorframe + 1), PU_PATCH); V_DrawFixedPatch((curx << FRACBITS) - (FRACUNIT), (cury << FRACBITS) - (FRACUNIT), FRACUNIT+(FRACUNIT>>3), 0, cursor, NULL); } @@ -8243,9 +8243,9 @@ static void M_DrawSetupMultiPlayerMenu(void) case SKINMENUTYPE_GRID: for (s = 0; s < SKINGRIDWIDTH*SKINGRIDHEIGHT; s++) { - INT32 x = ((s % SKINGRIDWIDTH) * 18) + ((BASEVIDWIDTH / 2) - (18 * SKINGRIDWIDTH) - 8) + 100 + SKINXSHIFT; //BASEVIDWIDTH / 2 - ((icons + 1) * 24) - 4; - INT32 y = ((s / SKINGRIDWIDTH) * 18) + ((BASEVIDHEIGHT / 2) - (18 * (SKINGRIDWIDTH/2))); //BASEVIDWIDTH / 2 - ((icons + 1) * 24) - 4; - INT32 calcs = s + (setupm_skinypos * SKINGRIDWIDTH); + const INT32 x = ((s % SKINGRIDWIDTH) * 18) + ((BASEVIDWIDTH / 2) - (18 * SKINGRIDWIDTH) - 8) + 100 + SKINXSHIFT; //BASEVIDWIDTH / 2 - ((icons + 1) * 24) - 4; + const INT32 y = ((s / SKINGRIDWIDTH) * 18) + ((BASEVIDHEIGHT / 2) - (18 * (SKINGRIDWIDTH/2))); //BASEVIDWIDTH / 2 - ((icons + 1) * 24) - 4; + const INT32 calcs = s + (setupm_skinypos * SKINGRIDWIDTH); INT16 skinn; patch_t *face; UINT8 *cmap; @@ -8269,36 +8269,44 @@ static void M_DrawSetupMultiPlayerMenu(void) if (itemOn == 1) //has to be on skin select part { patch_t *cursor; - INT32 curx = (((setupm_skinselect % SKINGRIDWIDTH) * 18) + ((BASEVIDWIDTH / 2) - (18 * SKINGRIDWIDTH/2)) + SKINXSHIFT) + 20; - INT32 cury = (((setupm_skinselect / SKINGRIDWIDTH) - setupm_skinypos) * 18) + ((BASEVIDHEIGHT / 2) - (18 * (SKINGRIDWIDTH/2))); + const INT32 curx = (((setupm_skinselect % SKINGRIDWIDTH) * 18) + ((BASEVIDWIDTH / 2) - (18 * SKINGRIDWIDTH/2)) + SKINXSHIFT) + 20; + const INT32 cury = (((setupm_skinselect / SKINGRIDWIDTH) - setupm_skinypos) * 18) + ((BASEVIDHEIGHT / 2) - (18 * (SKINGRIDWIDTH/2))); if (setupm_skinselect < numskins) { - UINT8 *cmap = R_GetTranslationColormap(setupm_skinselect, setupm_fakecolor, GTC_MENUCACHE); + const UINT8 *cmap = R_GetTranslationColormap(setupm_skinselect, setupm_fakecolor, GTC_MENUCACHE); cursor = facewantprefix[skinsorted[setupm_skinselect]]; V_DrawFixedPatch(((curx-8) << FRACBITS), ((cury-8) << FRACBITS), FRACUNIT, 0, cursor, cmap); } else { - UINT8 cursorframe = (I_GetTime() / 4) % 7; + const UINT8 cursorframe = (I_GetTime() / 4) % 7; cursor = (patch_t *)W_CachePatchName(va("K_CHILI%d", cursorframe + 1), PU_PATCH); V_DrawFixedPatch((curx << FRACBITS) - (FRACUNIT), (cury << FRACBITS) - (FRACUNIT), FRACUNIT+(FRACUNIT>>3), 0, cursor, NULL); } } { // stat dot - INT32 selectedskin = (itemOn == 1 && setupm_skinselect < numskins ? skinsorted[setupm_skinselect] : setupm_fakeskin); + const INT32 selectedskin = (itemOn == 1 && setupm_skinselect < numskins ? skinsorted[setupm_skinselect] : setupm_fakeskin); + speed = skins[selectedskin].kartspeed; weight = skins[selectedskin].kartweight; - statdot = (patch_t *)W_CachePatchName("K_SDOT1", PU_PATCH); - if (skullAnimCounter < 4) // SRB2Kart: we draw this dot later so that it's not covered if there's multiple skins with the same stats - V_DrawFixedPatch((((statx+46) + (speed*4))<>1), (((staty+71) + (weight*4))<>1, 0, statdot, flashcol); - else - V_DrawFixedPatch((((statx+46) + (speed*4))<>1), (((staty+71) + (weight*4))<>1, 0, statdot, NULL); - statdot = (patch_t *)W_CachePatchName("K_SDOT2", PU_PATCH); // coloured center + const INT32 x = (((statx+46) + (speed*4))<>1); + const INT32 y = (((staty+71) + (weight*4))<>1, 0, statdot, flashcol); + else + V_DrawFixedPatch(x, y, FRACUNIT>>1, 0, statdot, NULL); + if (setupm_fakecolor) - V_DrawFixedPatch((((statx+46) + (speed*4))<>1), (((staty+71) + (weight*4))<>1, 0, statdot, R_GetTranslationColormap(0, setupm_fakecolor, GTC_MENUCACHE)); + { + statdot = (patch_t *)W_CachePatchName("K_SDOT2", PU_PATCH); // coloured center + V_DrawFixedPatch(x, y, FRACUNIT>>1, 0, statdot, R_GetTranslationColormap(0, setupm_fakecolor, GTC_MENUCACHE)); + } } break; case SKINMENUTYPE_2D: @@ -8307,12 +8315,13 @@ static void M_DrawSetupMultiPlayerMenu(void) { for (w = 0; w < MAXSTAT; w++) { - INT32 x = ((s * 18) + ((BASEVIDWIDTH / 2) - (18 * 4)) - 8 + SKINXSHIFT); //BASEVIDWIDTH / 2 - ((icons + 1) * 24) - 4; - INT32 y = ((w * 18) + ((BASEVIDHEIGHT / 2) - (18 * 4)) - 8); //BASEVIDWIDTH / 2 - ((icons + 1) * 24) - 4; INT32 skinn; patch_t *face; UINT8 *cmap; + const INT32 x = ((s * 18) + ((BASEVIDWIDTH / 2) - (18 * 4)) - 8 + SKINXSHIFT); //BASEVIDWIDTH / 2 - ((icons + 1) * 24) - 4; + const INT32 y = ((w * 18) + ((BASEVIDHEIGHT / 2) - (18 * 4)) - 8); //BASEVIDWIDTH / 2 - ((icons + 1) * 24) - 4; + if (!skinstatscount[s][w]) { V_DrawFill(x, y, 16, 16, 239); @@ -8330,20 +8339,20 @@ static void M_DrawSetupMultiPlayerMenu(void) if (itemOn == 1) //has to be on skin select part { patch_t *cursor; - INT32 curx = ((setupm_skinxpos * 18) + ((BASEVIDWIDTH / 2) - (18 * 4)) - 8 + SKINXSHIFT); - INT32 cury = ((setupm_skinypos * 18) + ((BASEVIDHEIGHT / 2) - (18 * 4)) - 8); + const INT32 curx = ((setupm_skinxpos * 18) + ((BASEVIDWIDTH / 2) - (18 * 4)) - 8 + SKINXSHIFT); + const INT32 cury = ((setupm_skinypos * 18) + ((BASEVIDHEIGHT / 2) - (18 * 4)) - 8); if (skinstatscount[setupm_skinxpos][setupm_skinypos]) { - UINT8 *cmap = R_GetTranslationColormap(setupm_skinselect, setupm_fakecolor, GTC_MENUCACHE); - INT32 skinn = skinstats[setupm_skinxpos][setupm_skinypos][(I_GetTime() / TICRATE) % skinstatscount[setupm_skinxpos][setupm_skinypos]]; + const UINT8 *cmap = R_GetTranslationColormap(setupm_skinselect, setupm_fakecolor, GTC_MENUCACHE); + const INT32 skinn = skinstats[setupm_skinxpos][setupm_skinypos][(I_GetTime() / TICRATE) % skinstatscount[setupm_skinxpos][setupm_skinypos]]; cursor = facewantprefix[skinn]; V_DrawFixedPatch(((curx-8) << FRACBITS), ((cury-8) << FRACBITS), FRACUNIT, 0, cursor, cmap); } else { - UINT8 cursorframe = (I_GetTime() / 4) % 7; + const UINT8 cursorframe = (I_GetTime() / 4) % 7; cursor = (patch_t *)W_CachePatchName(va("K_CHILI%d", cursorframe + 1), PU_PATCH); V_DrawFixedPatch((curx << FRACBITS) - (FRACUNIT), (cury << FRACBITS) - (FRACUNIT), FRACUNIT+(FRACUNIT>>3), 0, cursor, NULL); } @@ -8351,18 +8360,26 @@ static void M_DrawSetupMultiPlayerMenu(void) break; #undef SKINXSHIFT default: - speed = skins[setupm_fakeskin].kartspeed; - weight = skins[setupm_fakeskin].kartweight; + { + speed = skins[setupm_fakeskin].kartspeed; + weight = skins[setupm_fakeskin].kartweight; - statdot = (patch_t *)W_CachePatchName("K_SDOT1", PU_PATCH); - if (skullAnimCounter < 4) // SRB2Kart: we draw this dot later so that it's not covered if there's multiple skins with the same stats - V_DrawFixedPatch(((BASEVIDWIDTH - mx - 80) + ((speed-1)*8))<= MAXSKINCOLORS) col -= MAXSKINCOLORS-1; + x += cw; } } @@ -8420,6 +8440,7 @@ static void M_DrawSetupMultiPlayerMenu(void) if (col < 0) col += numskins; + while (k <= icons) { if (!(k++)) @@ -8436,12 +8457,16 @@ static void M_DrawSetupMultiPlayerMenu(void) offx = 8; offy = 8; } + colmap = R_GetTranslationColormap(col, setupm_fakecolor, GTC_MENUCACHE); V_DrawFixedPatch((x+offx)<= numskins) col -= numskins; + x += FixedMul(iconwidth< 0 ? (roundedskins/8) - SKINGRIDHEIGHT-2 : 0); } + S_StartSound(NULL, sfx_menu1); break; } @@ -8758,6 +8793,7 @@ static void M_HandleSetupMultiPlayer(INT32 choice) setupm_skinselect++; else setupm_skinselect = 0; + S_StartSound(NULL, sfx_menu1); } else //player skin @@ -8792,6 +8828,7 @@ static void M_HandleSetupMultiPlayer(INT32 choice) setupm_skinselect = 0; setupm_skinypos = 0; } + S_StartSound(NULL, sfx_menu1); break; } @@ -8814,12 +8851,14 @@ static void M_HandleSetupMultiPlayer(INT32 choice) setupm_skinlockedselect = false; break; } + exitmenu = true; break; case KEY_BACKSPACE: if (cv_skinselectmenu.value) BREAKWHENLOCKED + if (itemOn == 0) { M_TextInputHandle(&setupm_input, choice); @@ -8849,6 +8888,7 @@ static void M_HandleSetupMultiPlayer(INT32 choice) case KEY_DEL: if (cv_skinselectmenu.value) BREAKWHENLOCKED + if (itemOn == 0) { M_TextInputHandle(&setupm_input, choice); diff --git a/src/p_mobj.c b/src/p_mobj.c index dbfe3d596..71e06415d 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -1148,7 +1148,6 @@ static void P_SceneryXYFriction(mobj_t *mo, fixed_t oldx, fixed_t oldy) { // Stolen from P_SpawnFriction mo->friction = FRACUNIT - 0x100; - //mo->movefactor = ((0x10092 - mo->friction)*(0x70))/0x158; } else mo->friction = ORIG_FRICTION; @@ -3282,6 +3281,7 @@ void P_CalcChasePostImg(player_t *player, camera_t *thiscam) postimgtype |= POSTIMG_FLIP; #ifdef HWRENDER + // the rest of those effects wont work in gl splitscreen if (rendermode == render_opengl && splitscreen) { thiscam->postimg = postimgtype; @@ -3507,7 +3507,6 @@ static void P_CheckFloatbobPlatforms(mobj_t *mobj) if (!(rover->flags & FF_FLOATBOB)) continue; - if (mobj->eflags & MFE_VERTICALFLIP) { if (abs(*rover->bottomheight - (mobj->z + mobj->height)) > abs(mobj->momz)) diff --git a/src/p_user.c b/src/p_user.c index 42b206830..51a3ac597 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1017,7 +1017,7 @@ boolean P_IsLocalPlayer(const player_t *player) } // -// P_IsLocalPlayer +// P_IsLocalPlayerNum // // Returns true if playernum is // on the local machine. diff --git a/src/st_stuff.c b/src/st_stuff.c index bc7f9e3e3..4871c49fe 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -568,7 +568,7 @@ static void ST_overlayDrawer(void) { if (!(multiplayer && demo.playback)) { - if(!P_IsLocalPlayer(stplyr)) + if (!P_IsLocalPlayer(stplyr)) { /*char name[MAXPLAYERNAME+1]; // shorten the name if its more than twelve characters. diff --git a/src/y_inter.c b/src/y_inter.c index 9c5fc9c0f..e8224335a 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -256,6 +256,7 @@ static void Y_CalculateMatchData(UINT8 rankingsmode, void (*comparison)(INT32)) } if (demo.recording && !rankingsmode) + { G_WriteStanding( data.pos[data.numplayers], data.name[data.numplayers], @@ -263,6 +264,7 @@ static void Y_CalculateMatchData(UINT8 rankingsmode, void (*comparison)(INT32)) *data.color[data.numplayers], data.val[data.numplayers] ); + } data.numplayers++; } diff --git a/src/z_zone.cpp b/src/z_zone.cpp index 3a78c7079..4ee72ae9c 100644 --- a/src/z_zone.cpp +++ b/src/z_zone.cpp @@ -582,7 +582,8 @@ void Z_ChangeTag(void *ptr, INT32 tag) block = MEMBLOCK(ptr); #ifdef PARANOIA - if (block->id != ZONEID) I_Error("Z_ChangeTag at %s:%d: wrong id", file, line); + if (block->id != ZONEID) + I_Error("Z_ChangeTag at %s:%d: wrong id", file, line); #endif if (tag >= PU_PURGELEVEL && block->user == NULL) @@ -613,7 +614,8 @@ void Z_SetUser(void *ptr, void **newuser) block = MEMBLOCK(ptr); #ifdef PARANOIA - if (block->id != ZONEID) I_Error("Z_SetUser at %s:%d: wrong id", file, line); + if (block->id != ZONEID) + I_Error("Z_SetUser at %s:%d: wrong id", file, line); #endif if (block->tag >= PU_PURGELEVEL && newuser == NULL) From 3c3e8dd9869f7d8a81e534afd13e72cf895f4c0b Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 19 Sep 2026 21:09:20 +0200 Subject: [PATCH 04/35] use Z_TotalUsage for memory debug display --- src/st_stuff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/st_stuff.c b/src/st_stuff.c index 4871c49fe..00b3e6a59 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -410,7 +410,7 @@ static void ST_drawDebugInfo(void) } if (cv_debug & DBG_MEMORY) - V_DrawRightAlignedString(320, height, V_MONOSPACE, va("Heap used: %7sKB", sizeu1(Z_TagsUsage(0, INT32_MAX)>>10))); + V_DrawRightAlignedString(320, height, V_MONOSPACE, va("Heap used: %7sKB", sizeu1(Z_TotalUsage()>>10))); } static void ST_drawLevelTitle(void) From 838d05eef7be53366045522acdd25cf61c62c311 Mon Sep 17 00:00:00 2001 From: NepDisk Date: Thu, 20 Aug 2026 03:19:35 -0400 Subject: [PATCH 05/35] Convert Z_Zone head into a list similar to thinkerlists I was thinking to myself about how 2.1 and before did thinkers and how 2.2 made it into thinker lists and thought "wait isn't memory allocated similar to that?" and well here we are. --- src/z_zone.cpp | 125 ++++++++++++++++++++++++++++--------------------- src/z_zone.h | 53 +++++++++++---------- 2 files changed, 100 insertions(+), 78 deletions(-) diff --git a/src/z_zone.cpp b/src/z_zone.cpp index 4ee72ae9c..e5e3b61ec 100644 --- a/src/z_zone.cpp +++ b/src/z_zone.cpp @@ -75,7 +75,7 @@ typedef struct memblock_s #define MEMBLOCK(x) (memblock_t *)((uintptr_t)(x) - ALIGNPAD - sizeof(memblock_t)) // both the head and tail of the zone memory block list -static memblock_t head; +static memblock_t headlist[NUM_PURGETAGS]; static constexpr size_t kLevelLargePoolBlockSize = sizeof(mobj_t); static constexpr size_t kLevelMedPoolBlockSize = sizeof(precipmobj_t); @@ -107,10 +107,14 @@ static void Command_Memdump_f(void); void Z_Init(void) { size_t total, memfree; + size_t i; - memset(&head, 0x00, sizeof(head)); + memset(&headlist, 0x00, sizeof(headlist)); - head.next = head.prev = &head; + for (i = 0; i < NUM_PURGETAGS; i++) + { + headlist[i].next = headlist[i].prev = &headlist[i]; + } memfree = I_GetFreeMem(&total)>>20; @@ -204,7 +208,7 @@ static void *xm(size_t size) if (p == NULL) { // Oh crumbs: we're out of heap. Try purging the cache and reallocating. - Z_FreeTags(PU_PURGELEVEL, INT32_MAX); + Z_FreeTags(PU_PURGELEVEL, NUM_PURGETAGS-1); p = malloc(padedsize); if (p == NULL) @@ -245,9 +249,9 @@ void *Z_Malloc(size_t size, INT32 tag, void *user) ptr = MEMORY(block); I_Assert((intptr_t)ptr % alignof (max_align_t) == 0); - block->next = head.next; - block->prev = &head; - head.next = block; + block->next = headlist[tag].next; + block->prev = &headlist[tag]; + headlist[tag].next = block; block->next->prev = block; block->tag = tag; @@ -411,6 +415,7 @@ void Z_FreeTags(INT32 lowtag, INT32 hightag) #endif { memblock_t *block, *next; + INT32 i; #ifdef ZDEBUG Z_CheckHeap2(file, line); @@ -427,11 +432,13 @@ void Z_FreeTags(INT32 lowtag, INT32 hightag) g_level_tiny_pool.release(); } - for (block = head.next; block != &head; block = next) + for (i = lowtag; i <= hightag; i++) { - next = block->next; // get link before freeing - if (block->tag >= lowtag && block->tag <= hightag) + for (block = headlist[i].next; block != &headlist[i]; block = next) + { + next = block->next; // get link before freeing Z_Free(MEMORY(block)); + } } } @@ -444,18 +451,20 @@ void Z_FreeTags(INT32 lowtag, INT32 hightag) void Z_IterateTags(INT32 lowtag, INT32 hightag, boolean (*iterfunc)(void *)) { memblock_t *block, *next; + INT32 i; if (!iterfunc) I_Error("Z_IterateTags: no iterator function was given"); - for (block = head.next; block != &head; block = next) + for (i = lowtag; i <= hightag; i++) { - next = block->next; // get link before possibly freeing - - if (block->tag >= lowtag && block->tag <= hightag) + for (block = headlist[i].next; block != &headlist[i]; block = next) { + next = block->next; // get link before possibly freeing + void *mem = MEMORY(block); boolean free = iterfunc(mem); + if (free) Z_Free(mem); } @@ -486,7 +495,7 @@ void Z_CheckMemCleanup(void) if (nextcleanup-- == 0) { nextcleanup = CLEANUPCOUNT; - Z_FreeTags(PU_PURGELEVEL, INT32_MAX); + Z_FreeTags(PU_PURGELEVEL, NUM_PURGETAGS-1); } } @@ -504,6 +513,7 @@ void Z_CheckHeap(INT32 tag) { memblock_t *block; UINT32 blocknumon = 0; + size_t j; void *given; #ifndef ZDEBUG @@ -520,40 +530,43 @@ void Z_CheckHeap(INT32 tag) blocknumon, block->ownerfile, block->ownerline, msg) #endif - for (block = head.next; block != &head; block = block->next) + for (j = 0; j < NUM_PURGETAGS; j++) { - blocknumon++; - given = MEMORY(block); + for (block = headlist[j].next; block != &headlist[j]; block = block->next) + { + blocknumon++; + given = MEMORY(block); #ifdef ZDEBUG2 - CONS_Debug(DBG_MEMORY, "block %u owned by %s:%d\n", - blocknumon, block->ownerfile, block->ownerline); + CONS_Debug(DBG_MEMORY, "block %u owned by %s:%d\n", + blocknumon, block->ownerfile, block->ownerline); #endif #ifdef HAVE_VALGRIND - if (RUNNING_ON_VALGRIND && !VALGRIND_MEMPOOL_EXISTS(block)) - { - HeapError(" should not exist"); - } + if (RUNNING_ON_VALGRIND && !VALGRIND_MEMPOOL_EXISTS(block)) + { + HeapError(" should not exist"); + } #endif - if (block->user != NULL && *(block->user) != given) - { - HeapError(" doesn't have a proper user"); - } + if (block->user != NULL && *(block->user) != given) + { + HeapError(" doesn't have a proper user"); + } - if (block->next->prev != block) - { - HeapError(" lacks proper backlink"); - } + if (block->next->prev != block) + { + HeapError(" lacks proper backlink"); + } - if (block->prev->next != block) - { - HeapError(" lacks proper forward link"); - } + if (block->prev->next != block) + { + HeapError(" lacks proper forward link"); + } #ifdef PARANOIA - if (block->id != ZONEID) - { - HeapError(" has the wrong ID"); - } + if (block->id != ZONEID) + { + HeapError(" has the wrong ID"); + } #endif + } } } @@ -640,18 +653,21 @@ void Z_SetUser(void *ptr, void **newuser) size_t Z_TagsUsage(INT32 lowtag, INT32 hightag) { size_t cnt = 0; - memblock_t *rover; + memblock_t *head; // why was this called rover before????? + INT32 i; - for (rover = head.next; rover != &head; rover = rover->next) + for (i = lowtag; i <= hightag; i++) { - if (rover->tag < lowtag || rover->tag > hightag) - continue; - cnt += rover->size + sizeof(memblock_t); + for (head = headlist[i].next; head != &headlist[i]; head = head->next) + { + cnt += head->size + sizeof *head; + } } return cnt; } + // ----------------------- // Miscellaneous functions // ----------------------- @@ -680,7 +696,7 @@ static void Command_Memfree_f(void) CONS_Printf(M_GetText("Level (pooled) : %7s KB\n"), sizeu1(Z_LevelPoolUsage()>>10)); CONS_Printf(M_GetText("Special thinker : %7s KB\n"), sizeu1(Z_TagUsage(PU_LEVSPEC)>>10)); CONS_Printf(M_GetText("All purgable : %7s KB\n"), - sizeu1(Z_TagsUsage(PU_PURGELEVEL, INT32_MAX)>>10)); + sizeu1(Z_TagsUsage(PU_PURGELEVEL, NUM_PURGETAGS-1)>>10)); #ifdef HWRENDER if (rendermode == render_opengl) @@ -709,21 +725,24 @@ static void Command_Memfree_f(void) static void Command_Memdump_f(void) { memblock_t *block; - INT32 mintag = 0, maxtag = INT32_MAX; + INT32 mintag = 0, maxtag = NUM_PURGETAGS-1; + INT32 check; INT32 i; - if ((i = COM_CheckParm("-min"))) - mintag = atoi(COM_Argv(i + 1)); + if ((check = COM_CheckParm("-min"))) + mintag = atoi(COM_Argv(check + 1)); - if ((i = COM_CheckParm("-max"))) - maxtag = atoi(COM_Argv(i + 1)); + if ((check = COM_CheckParm("-max"))) + maxtag = atoi(COM_Argv(check + 1)); - for (block = head.next; block != &head; block = block->next) - if (block->tag >= mintag && block->tag <= maxtag) + for (i = mintag; i <= maxtag; i++) + { + for (block = headlist[i].next; block != &headlist[i]; block = block->next) { const char *filename = strrchr(block->ownerfile, PATHSEP[0]); CONS_Printf("[%3d] %s (%s) bytes @ %s:%d\n", block->tag, sizeu1(block->size + sizeof(memblock_t)), sizeu2(block->size), filename ? filename + 1 : block->ownerfile, block->ownerline); } + } } #endif diff --git a/src/z_zone.h b/src/z_zone.h index 847e47291..0aade2dd2 100644 --- a/src/z_zone.h +++ b/src/z_zone.h @@ -42,39 +42,42 @@ extern "C" { enum { // Tags < PU_LEVEL are not purged until freed explicitly. - PU_STATIC = 1, // static entire execution time - PU_LUA = 2, // static entire execution time -- used by lua so it doesn't get caught in loops forever - PU_PERFSTATS = 3, // static between changes to ps_samplesize cvar + PU_STATIC = 0, // static entire execution time + PU_LUA, // static entire execution time -- used by lua so it doesn't get caught in loops forever + PU_PERFSTATS, // static between changes to ps_samplesize cvar - PU_SOUND = 11, // static while playing - PU_MUSIC = 12, // static while playing + PU_SOUND, // static while playing + PU_MUSIC, // static while playing - PU_PATCH = 14, // static entire execution time - PU_PATCH_LOWPRIORITY = 15, // lower priority patch, static until level exited - PU_PATCH_ROTATED = 16, // rotated patch, static entire execution time - PU_PATCH_DATA = 17, // patch data, lifetime depends on the patch that owns it - PU_SPRITE = 18, // sprite patch, static until WAD added - PU_HUDGFX = 19, // HUD patch, static until WAD added + PU_PATCH, // static entire execution time + PU_PATCH_LOWPRIORITY, // lower priority patch, static until level exited + PU_PATCH_ROTATED, // rotated patch, static until level exited or WAD added + PU_PATCH_DATA, // patch data, lifetime depends on the patch that owns it + PU_SPRITE, // sprite patch, static until WAD added + PU_HUDGFX, // HUD patch, static until WAD added - PU_HWRPATCHINFO = 21, // Hardware GLPatch_t struct for OpenGL texture cache - PU_HWRPATCHCOLMIPMAP = 22, // Hardware GLMipmap_t struct colormap variation of patch - PU_HWRMODELTEXTURE = 23, // Hardware model texture + PU_HWRPATCHINFO, // Hardware GLPatch_t struct for OpenGL texture cache + PU_HWRPATCHCOLMIPMAP, // Hardware GLMipmap_t struct colormap variation of patch + PU_HWRMODELTEXTURE, // Hardware model texture - PU_HWRCACHE = 48, // static until unlocked - PU_CACHE = 49, // static until unlocked + PU_HWRCACHE, // static until unlocked + PU_CACHE, // static until unlocked // Tags s.t. PU_LEVEL <= tag < PU_PURGELEVEL are purged at level start - PU_LEVEL = 50, // static until level exited - PU_LEVSPEC = 51, // a special thinker in a level - PU_HWRPLANE = 52, // if ZPLANALLOC is enabled in hw_bsp.c, this is used to alloc polygons for OpenGL + PU_LEVEL, // static until level exited + PU_LEVSPEC, // a special thinker in a level + PU_HWRPLANE, // if ZPLANALLOC is enabled in hw_bsp.c, this is used to alloc polygons for OpenGL // Tags >= PU_PURGELEVEL are purgable whenever needed - PU_PURGELEVEL = 100, // Note: this is never actually used as a tag - PU_CACHE_UNLOCKED = 101, // Note: unused - PU_HWRCACHE_UNLOCKED = 102, // 'unlocked' PU_HWRCACHE memory: + PU_PURGELEVEL, // Note: this is never actually used as a tag + PU_CACHE_UNLOCKED, // Note: unused + PU_HWRCACHE_UNLOCKED, // 'unlocked' PU_HWRCACHE memory: // 'second-level' cache for graphics - // stored in hardware format and downloaded as needed - PU_HWRMODELTEXTURE_UNLOCKED = 103, // 'unlocked' PU_HWRMODELTEXTURE memory + + // stored in hardware format and downloaded as needed + PU_HWRMODELTEXTURE_UNLOCKED, // 'unlocked' PU_HWRMODELTEXTURE memory + + NUM_PURGETAGS }; // @@ -157,7 +160,7 @@ void Z_SetUser(void *ptr, void **newuser); // #define Z_TagUsage(tagnum) Z_TagsUsage(tagnum, tagnum) size_t Z_TagsUsage(INT32 lowtag, INT32 hightag); -#define Z_TotalUsage() Z_TagsUsage(0, INT32_MAX) +#define Z_TotalUsage() Z_TagsUsage(0, NUM_PURGETAGS-1) // // Miscellaneous functions From c78c0d16572bff721196eb2c0191fe944f0b5379 Mon Sep 17 00:00:00 2001 From: NepDisk Date: Mon, 24 Aug 2026 02:18:26 -0400 Subject: [PATCH 06/35] Fix memory block not being moved to correct taglist with Z_ChangeTag I didn't even notice this one at first, whoops! Also added proper checking to prevent this from happening again. --- src/z_zone.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/z_zone.cpp b/src/z_zone.cpp index e5e3b61ec..236ec0322 100644 --- a/src/z_zone.cpp +++ b/src/z_zone.cpp @@ -566,6 +566,10 @@ void Z_CheckHeap(INT32 tag) HeapError(" has the wrong ID"); } #endif + if (block->tag != j) + { + HeapError(va(" block is contained in the wrong headlist (got: %d expected: %zu)", block->tag, j)); + } } } } @@ -603,6 +607,14 @@ void Z_ChangeTag(void *ptr, INT32 tag) I_Error("Internal memory management error: " "tried to make block purgable but it has no owner"); + block->prev->next = block->next; + block->next->prev = block->prev; + + block->next = headlist[tag].next; + block->prev = &headlist[tag]; + headlist[tag].next = block; + block->next->prev = block; + block->tag = tag; } From 1dd3e903635405c433a517a4c43e0a1cf9549582 Mon Sep 17 00:00:00 2001 From: NepDisk Date: Mon, 24 Aug 2026 02:34:52 -0400 Subject: [PATCH 07/35] Make memdump show block tags --- src/z_zone.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/z_zone.cpp b/src/z_zone.cpp index 236ec0322..55a98cb42 100644 --- a/src/z_zone.cpp +++ b/src/z_zone.cpp @@ -752,7 +752,7 @@ static void Command_Memdump_f(void) for (block = headlist[i].next; block != &headlist[i]; block = block->next) { const char *filename = strrchr(block->ownerfile, PATHSEP[0]); - CONS_Printf("[%3d] %s (%s) bytes @ %s:%d\n", block->tag, sizeu1(block->size + sizeof(memblock_t)), sizeu2(block->size), filename ? filename + 1 : block->ownerfile, block->ownerline); + CONS_Printf("[%3d] %s (%s) bytes @ %s:%d tag: %d (%d)\n", block->tag, sizeu1(block->size + sizeof(memblock_t)), sizeu2(block->size), filename ? filename + 1 : block->ownerfile, block->ownerline, block->tag, i); } } } From 648d3c439bbf62601f55fb50716752acab496962 Mon Sep 17 00:00:00 2001 From: Indev Date: Mon, 7 Sep 2026 18:03:50 +0300 Subject: [PATCH 08/35] Change lua to not use z_zone allocator --- src/lua_script.c | 25 +++++++++++++++---------- src/lua_script.h | 3 +++ src/z_zone.cpp | 2 +- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/lua_script.c b/src/lua_script.c index 0db0bd1e0..432bb511b 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -62,14 +62,6 @@ static lua_CFunction liblist[] = { NULL }; -// Lua asks for memory using this. -static void *LUA_Alloc(void *ud, void *ptr, size_t osize, size_t nsize) -{ - (void)ud; - (void)osize; - return Z_Realloc(ptr, nsize, PU_LUA, NULL); -} - // Panic function Lua calls when there's an unprotected error. // This function cannot return. Lua would kill the application anyway if it did. FUNCNORETURN static int LUA_Panic(lua_State *L) @@ -197,7 +189,7 @@ void LUA_ClearState(void) CONS_Printf(M_GetText("Pardon me while I initialize the Lua scripting interface...\n")); // allocate state - L = lua_newstate(LUA_Alloc, NULL); + L = luaL_newstate(); lua_atpanic(L, LUA_Panic); // open base libraries @@ -373,7 +365,7 @@ void LUA_DumpFile(const char *filename) static void createMathLibState(void) { - mL = lua_newstate(LUA_Alloc, NULL); + mL = luaL_newstate(); lua_atpanic(mL, LUA_Panic); // open only enum lib @@ -1465,3 +1457,16 @@ int Lua_CreateFieldTable(lua_State *L, const char *const lst[]) return luaL_ref(L, LUA_REGISTRYINDEX); } + +size_t LUA_MemoryUsage(void) +{ + size_t usage = 0; + + if (gL) + usage += lua_gc(gL, LUA_GCCOUNT, 0); + + if (mL) + usage += lua_gc(mL, LUA_GCCOUNT, 0); + + return usage; +} diff --git a/src/lua_script.h b/src/lua_script.h index 35dd5b364..2d1209847 100644 --- a/src/lua_script.h +++ b/src/lua_script.h @@ -82,6 +82,9 @@ int Lua_optoption(lua_State *L, int narg, int def, int list_ref); int Lua_CreateFieldTable(lua_State *L, const char *const lst[]); void LUA_HookNetArchive(lua_CFunction archFunc, savebuffer_t *save); +// Returns lua memory usage in kbytes +size_t LUA_MemoryUsage(void); + // Console wrapper void COM_Lua_f(void); diff --git a/src/z_zone.cpp b/src/z_zone.cpp index 55a98cb42..d3e3f3d5e 100644 --- a/src/z_zone.cpp +++ b/src/z_zone.cpp @@ -694,7 +694,7 @@ static void Command_Memfree_f(void) Z_CheckHeap(-1); CONS_Printf("\x82%s", M_GetText("Memory Info\n")); CONS_Printf(M_GetText("Total heap used : %7s KB\n"), sizeu1(Z_TotalUsage()>>10)); - CONS_Printf(M_GetText("Lua : %7s KB\n"), sizeu1(Z_TagUsage(PU_LUA)>>10)); + CONS_Printf(M_GetText("Lua : %7s KB\n"), sizeu1(LUA_MemoryUsage())); // No longer uses z_zone memory but for consistency keep it here CONS_Printf(M_GetText("Static : %7s KB\n"), sizeu1(Z_TagUsage(PU_STATIC)>>10)); CONS_Printf(M_GetText("Static (sound) : %7s KB\n"), sizeu1(Z_TagUsage(PU_SOUND)>>10)); CONS_Printf(M_GetText("Static (music) : %7s KB\n"), sizeu1(Z_TagUsage(PU_MUSIC)>>10)); From 0e62afd3482dc0a0905cce895fdadcb0348d338c Mon Sep 17 00:00:00 2001 From: Indev Date: Mon, 21 Sep 2026 17:14:43 +0300 Subject: [PATCH 09/35] Count lua memory for total usage in memfree command --- src/z_zone.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/z_zone.cpp b/src/z_zone.cpp index d3e3f3d5e..68d91dd48 100644 --- a/src/z_zone.cpp +++ b/src/z_zone.cpp @@ -693,7 +693,7 @@ static void Command_Memfree_f(void) Z_CheckHeap(-1); CONS_Printf("\x82%s", M_GetText("Memory Info\n")); - CONS_Printf(M_GetText("Total heap used : %7s KB\n"), sizeu1(Z_TotalUsage()>>10)); + CONS_Printf(M_GetText("Total heap used : %7s KB\n"), sizeu1((Z_TotalUsage()>>10) + LUA_MemoryUsage())); CONS_Printf(M_GetText("Lua : %7s KB\n"), sizeu1(LUA_MemoryUsage())); // No longer uses z_zone memory but for consistency keep it here CONS_Printf(M_GetText("Static : %7s KB\n"), sizeu1(Z_TagUsage(PU_STATIC)>>10)); CONS_Printf(M_GetText("Static (sound) : %7s KB\n"), sizeu1(Z_TagUsage(PU_SOUND)>>10)); From 080f586c195b91bb29a3281119471e219b3e6cd1 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 9 Jun 2026 09:30:54 +0200 Subject: [PATCH 10/35] simplify W_CheckNumForNamePwad pretty much what blankart does avoids doing a bunch of string work --- src/w_wad.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/w_wad.c b/src/w_wad.c index 5d0771dc3..6c24d69c2 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -396,6 +396,11 @@ FUNCINLINE static ATTRINLINE UINT32 W_HashLumpName(const char *name) return FNV1a_HashLowercaseString(name); } +FUNCINLINE static ATTRINLINE UINT32 W_HashLumpNameLen(const char *name, size_t len) +{ + return FNV1a_QuickCaseHash(name, len); +} + /** Detect a file type. * \todo Actually detect the wad/pkzip headers and whatnot, instead of just checking the extensions. */ @@ -1095,18 +1100,15 @@ const char *W_CheckNameForNum(lumpnum_t lumpnum) UINT16 W_CheckNumForNamePwad(const char *name, UINT16 wad, UINT16 startlump) { UINT16 i; - static char uname[8 + 1]; UINT32 hash; size_t namelen; if (!TestValidLump(wad, 0)) return INT16_MAX; - memset(uname, 0, sizeof(uname)); - strncpy(uname, name, sizeof(uname)-1); - strupr(uname); - namelen = strlen(uname); - hash = W_HashLumpName(uname); + namelen = strlen(name); + namelen = min(namelen, 8); // :chaosleep: + hash = W_HashLumpNameLen(name, namelen); // // scan forward @@ -1121,7 +1123,7 @@ UINT16 W_CheckNumForNamePwad(const char *name, UINT16 wad, UINT16 startlump) { if (lump_p->namelength == namelen && lump_p->hash.name == hash - && !memcmp(lump_p->name, uname, sizeof(uname) - 1)) + && !strncasecmp(lump_p->name, name, namelen)) return i; } } From 3df604e8b6a0694780a1862d439b180059a7fd44 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 25 Jul 2026 09:28:27 +0200 Subject: [PATCH 11/35] expand sector flags include gravflip, heatwave, noclipcam and invertencore is a bit cleaner may also add the special flags at some point to clean things up a bit more --- src/p_map.c | 6 +++--- src/p_maputl.cpp | 4 ++-- src/p_mobj.c | 8 ++++---- src/p_spec.c | 22 ++++++++++++++++++---- src/p_user.c | 11 ++++++----- src/r_bsp.cpp | 7 +++---- src/r_defs.h | 18 +++++++++++++----- 7 files changed, 49 insertions(+), 27 deletions(-) diff --git a/src/p_map.c b/src/p_map.c index 9c974ce44..49870bf88 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -2026,7 +2026,7 @@ static boolean P_CheckCameraPosition(fixed_t x, fixed_t y, camera_t *thiscam) mapcampointer = thiscam; - if (UNLIKELY(GETSECSPECIAL(newsec->special, 4) == 12)) + if (newsec->flags & SF_NOCLIPCAMERA) { // Camera noclip on entire sector. tmfloorz = tmdropoffz = thiscam->z; tmceilingz = tmdrpoffceilz = thiscam->z + thiscam->height; @@ -2068,7 +2068,7 @@ static boolean P_CheckCameraPosition(fixed_t x, fixed_t y, camera_t *thiscam) fixed_t topheight, bottomheight, midheight; if (!(rover->flags & FF_BLOCKOTHERS) || !(rover->flags & FF_EXISTS) || !(rover->flags & FF_RENDERALL) - || UNLIKELY(GETSECSPECIAL(rover->master->frontsector->special, 4) == 12)) + || rover->master->frontsector->flags & SF_NOCLIPCAMERA) continue; topheight = P_CameraGetFOFTopZ(thiscam, newsec, rover, x, y, NULL); @@ -2144,7 +2144,7 @@ static boolean P_CheckCameraPosition(fixed_t x, fixed_t y, camera_t *thiscam) // We're inside it! Yess... polysec = po->lines[0]->backsector; - if (UNLIKELY(GETSECSPECIAL(polysec->special, 4) == 12)) + if (polysec->flags & SF_NOCLIPCAMERA) { // Camera noclip polyobj. plink = (polymaplink_t *)(plink->link.next); continue; diff --git a/src/p_maputl.cpp b/src/p_maputl.cpp index 122311903..355098535 100644 --- a/src/p_maputl.cpp +++ b/src/p_maputl.cpp @@ -328,7 +328,7 @@ void P_CameraLineOpening(line_t *linedef) { fixed_t topheight, bottomheight, midheight; - if (!(rover->flags & FF_BLOCKOTHERS) || !(rover->flags & FF_RENDERALL) || !(rover->flags & FF_EXISTS) || UNLIKELY(GETSECSPECIAL(rover->master->frontsector->special, 4) == 12)) + if (!(rover->flags & FF_BLOCKOTHERS) || !(rover->flags & FF_RENDERALL) || !(rover->flags & FF_EXISTS) || (rover->master->frontsector->flags & SF_NOCLIPCAMERA)) continue; topheight = P_CameraGetFOFTopZ(mapcampointer, front, rover, tmx, tmy, linedef); @@ -358,7 +358,7 @@ void P_CameraLineOpening(line_t *linedef) { fixed_t topheight, bottomheight, midheight; - if (!(rover->flags & FF_BLOCKOTHERS) || !(rover->flags & FF_RENDERALL) || !(rover->flags & FF_EXISTS) || UNLIKELY(GETSECSPECIAL(rover->master->frontsector->special, 4) == 12)) + if (!(rover->flags & FF_BLOCKOTHERS) || !(rover->flags & FF_RENDERALL) || !(rover->flags & FF_EXISTS) || (rover->master->frontsector->flags & SF_NOCLIPCAMERA)) continue; topheight = P_CameraGetFOFTopZ(mapcampointer, back, rover, tmx, tmy, linedef); diff --git a/src/p_mobj.c b/src/p_mobj.c index 71e06415d..52b64df3c 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -971,7 +971,7 @@ fixed_t P_GetMobjGravity(mobj_t *mo) gravityadd = -P_GetSectorGravity(rover->master->frontsector); - if (rover->master->frontsector->verticalflip && gravityadd > 0) + if ((rover->master->frontsector->flags & SF_GRAVITYFLIP) && gravityadd > 0) mo->eflags |= MFE_VERTICALFLIP; no3dfloorgrav = false; @@ -983,7 +983,7 @@ fixed_t P_GetMobjGravity(mobj_t *mo) { gravityadd = -P_GetSectorGravity(mo->subsector->sector); - if (mo->subsector->sector->verticalflip && gravityadd > 0) + if ((mo->subsector->sector->flags & SF_GRAVITYFLIP) && gravityadd > 0) mo->eflags |= MFE_VERTICALFLIP; } @@ -3193,7 +3193,7 @@ static boolean P_CameraCheckHeat(camera_t *thiscam) // see if we are in water sector = thiscam->subsector->sector; - if (P_FindSpecialLineFromTag(13, sector->tag, -1) != -1) + if (sector->flags & SF_HEATWAVE) return true; if (sector->ffloors) @@ -3212,7 +3212,7 @@ static boolean P_CameraCheckHeat(camera_t *thiscam) if (halfheight <= P_GetFFloorBottomZAt(rover, thiscam->x, thiscam->y)) continue; - if (P_FindSpecialLineFromTag(13, rover->master->frontsector->tag, -1) != -1) + if (rover->master->frontsector->flags & SF_HEATWAVE) return true; } } diff --git a/src/p_spec.c b/src/p_spec.c index 8b526798e..8c35a5d0d 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -3394,7 +3394,7 @@ void P_ProcessSpecialSector(player_t *player, sector_t *sector, sector_t *rovers break; case 12: // SRB2kart: Invert Encore Remap break; - case 15: // no idea but keep it dont want anything to break + case 15: // also Invert Encore Remap.... break; } DoneSection2: @@ -5368,6 +5368,11 @@ void P_SpawnSpecials(INT32 fromnetsave, boolean reloadinggamestate) case 11: // Custom global gravity! gravity = sector->floorheight/1000; break; + + case 12: // SRB2kart: Invert Encore Remap + case 15: // NOTE: vanilla kart checks only for this for some reason! + sector->flags |= SF_INVERTENCORE; + break; } // Process Section 4 @@ -5377,6 +5382,10 @@ void P_SpawnSpecials(INT32 fromnetsave, boolean reloadinggamestate) if (G_RaceGametype()) circuitmap = true; break; + + case 12: // Camera noclip + sector->flags |= SF_NOCLIPCAMERA; + break; } } @@ -5461,11 +5470,11 @@ void P_SpawnSpecials(INT32 fromnetsave, boolean reloadinggamestate) sectors[s].gravity = §ors[sec].floorheight; // This allows it to change in realtime! if (lines[i].flags & ML_NOCLIMB) - sectors[s].verticalflip = true; + sectors[s].flags |= SF_GRAVITYFLIP; else - sectors[s].verticalflip = false; + sectors[s].flags &= ~SF_GRAVITYFLIP; - CheckForReverseGravity = sectors[s].verticalflip; + CheckForReverseGravity = (sectors[s].flags & SF_GRAVITYFLIP); } break; @@ -5558,6 +5567,11 @@ void P_SpawnSpecials(INT32 fromnetsave, boolean reloadinggamestate) sectors[s].cullheight = &lines[i]; // This allows it to change in realtime! break; + case 13: // Heat wave effect + for (s = -1; (s = P_FindSectorFromLineTag(lines + i, s)) >= 0 ;) + sectors[s].flags |= SF_HEATWAVE; + break; + case 50: // Insta-Lower Sector EV_DoFloor(&lines[i], instantLower); break; diff --git a/src/p_user.c b/src/p_user.c index 51a3ac597..ee1d45525 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -3561,7 +3561,7 @@ static boolean P_CheckNoclipCameraPosition(player_t *player, camera_t *thiscam, for (rover = newsubsec->sector->ffloors; rover; rover = rover->next) { fixed_t topheight, bottomheight; - if (!(rover->flags & FF_BLOCKOTHERS) || !(rover->flags & FF_EXISTS) || !(rover->flags & FF_RENDERALL) || UNLIKELY(GETSECSPECIAL(rover->master->frontsector->special, 4) == 12)) + if (!(rover->flags & FF_BLOCKOTHERS) || !(rover->flags & FF_EXISTS) || !(rover->flags & FF_RENDERALL) || (rover->master->frontsector->flags & SF_NOCLIPCAMERA)) continue; topheight = P_CameraGetFOFTopZ(thiscam, newsubsec->sector, rover, midx, midy, NULL); @@ -3626,7 +3626,7 @@ static boolean P_CheckNoclipCameraPosition(player_t *player, camera_t *thiscam, // We're inside it! Yess... polysec = po->lines[0]->backsector; - if (UNLIKELY(GETSECSPECIAL(polysec->special, 4) == 12)) + if (polysec->flags & SF_NOCLIPCAMERA) { // Camera noclip polyobj. plink = (polymaplink_t *)(plink->link.next); continue; @@ -3682,7 +3682,8 @@ static boolean P_CheckNoclipCameraPosition(player_t *player, camera_t *thiscam, for (rover = newsubsec->sector->ffloors; rover; rover = rover->next) { fixed_t topheight, bottomheight; - if (UNLIKELY((rover->flags & FF_BLOCKOTHERS) && (rover->flags & FF_RENDERALL) && (rover->flags & FF_EXISTS) && GETSECSPECIAL(rover->master->frontsector->special, 4) == 12)) + + if ((rover->flags & FF_BLOCKOTHERS) && (rover->flags & FF_RENDERALL) && (rover->flags & FF_EXISTS) && (rover->master->frontsector->flags & SF_NOCLIPCAMERA)) { topheight = P_CameraGetFOFTopZ(thiscam, newsubsec->sector, rover, midx, midy, NULL); bottomheight = P_CameraGetFOFBottomZ(thiscam, newsubsec->sector, rover, midx, midy, NULL); @@ -4262,7 +4263,7 @@ boolean P_SpectatorJoinGame(player_t *player) static boolean P_CameraCheckHeatFirstperson(player_t *player, sector_t *sector, fixed_t pviewheight) { - if (P_FindSpecialLineFromTag(13, sector->tag, -1) != -1) + if (sector->flags & SF_HEATWAVE) return true; if (sector->ffloors) @@ -4280,7 +4281,7 @@ static boolean P_CameraCheckHeatFirstperson(player_t *player, sector_t *sector, if (pviewheight <= P_GetFFloorBottomZAt(rover, player->mo->x, player->mo->y)) continue; - if (P_FindSpecialLineFromTag(13, rover->master->frontsector->tag, -1) != -1) + if (rover->master->frontsector->flags & SF_HEATWAVE) return true; } } diff --git a/src/r_bsp.cpp b/src/r_bsp.cpp index b118e8e84..4f8df6dc9 100644 --- a/src/r_bsp.cpp +++ b/src/r_bsp.cpp @@ -48,8 +48,7 @@ boolean g_walloffscreen = false; boolean R_NoEncore(sector_t *sector, boolean ceiling) { - const INT32 invspecial = GETSECSPECIAL(sector->special, 2); - boolean invertencore = (invspecial == 12 || invspecial == 15); // keeping this incase its used + const boolean invertEncore = (sector->flags & SF_INVERTENCORE); #if 0 // perfect implementation const INT32 sprnspecial = GETSECSPECIAL(sector->special, 3); @@ -59,10 +58,10 @@ boolean R_NoEncore(sector_t *sector, boolean ceiling) #endif && GETSECSPECIAL(sector->special, 4) != 6) // sneaker panel { - return invertencore; + return invertEncore; } - if (invertencore) + if (invertEncore) { return false; } diff --git a/src/r_defs.h b/src/r_defs.h index 680a8a9cc..d6c419c1b 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -307,10 +307,19 @@ typedef struct pslope_s typedef enum { - SF_FLIPSPECIAL_FLOOR = 1, - SF_FLIPSPECIAL_CEILING = 2, - SF_FLIPSPECIAL_BOTH = 3, - SF_TRIGGERSPECIAL_TOUCH = 4, + // flipspecial - planes with effect + SF_FLIPSPECIAL_FLOOR = 1, + SF_FLIPSPECIAL_CEILING = 1<<1, + SF_FLIPSPECIAL_BOTH = (SF_FLIPSPECIAL_FLOOR|SF_FLIPSPECIAL_CEILING), + // triggerspecial - conditions under which plane touch causes effect + SF_TRIGGERSPECIAL_TOUCH = 1<<2, + + SF_GRAVITYFLIP = 1<<3, + SF_HEATWAVE = 1<<4, + SF_NOCLIPCAMERA = 1<<5, + + // invert encore color remap status + SF_INVERTENCORE = 1<<6, } sectorflags_t; // @@ -391,7 +400,6 @@ typedef struct sector_s // This points to the master's floorheight, so it can be changed in realtime! fixed_t *gravity; // per-sector gravity - boolean verticalflip; // If gravity < 0, then allow flipped physics sectorflags_t flags; // Sprite culling feature From d0249921442f0b93ff26a2b8b995102ca28619e0 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 5 Aug 2026 22:55:35 +0200 Subject: [PATCH 12/35] clean up Command_connect --- src/d_clisrv.c | 70 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 25 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 5a0930367..e3671f946 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -3347,6 +3347,7 @@ static void Command_connect(void) return; } + // StarManiaKG: allow us to join servers from anywhere at any time // if (Playing() || demo.title || demo.playback) { if (demo.title || demo.playback) @@ -3365,7 +3366,9 @@ static void Command_connect(void) D_StartTitle(); } else + { M_ClearMenus(true); // close the menus + } // modified game check: no longer handled // we don't request a restart unless the filelist differs @@ -3381,37 +3384,52 @@ static void Command_connect(void) } else { - // used in menu to connect to a server in the list - if (netgame && fasticmp(COM_Argv(1), "node")) + // Get the server node. + if (netgame) { - servernode = (SINT8)atoi(COM_Argv(2)); - } - else if (netgame) - { - CONS_Printf(M_GetText("You cannot connect while in a game. End this game first.\n")); - return; - } - else if (I_NetOpenSocket) - { - I_NetOpenSocket(); - netgame = true; - multiplayer = true; - - if (fasticmp(COM_Argv(1), "any")) - servernode = BROADCASTADDR; - else if (I_NetMakeNodewPort && COM_Argc() >= 3) - servernode = I_NetMakeNodewPort(COM_Argv(1), COM_Argv(2)); - else if (I_NetMakeNodewPort) - servernode = I_NetMakeNode(COM_Argv(1)); + // used in menu to connect to a server in the list + if (fasticmp(COM_Argv(1), "node")) + { + servernode = (SINT8)atoi(COM_Argv(2)); + } else { - CONS_Alert(CONS_ERROR, M_GetText("There is no server identification with this network driver\n")); - D_CloseConnection(); - return; + D_QuitNetGame(); + CL_Reset(); + D_StartTitle(); } } else - CONS_Alert(CONS_ERROR, M_GetText("There is no network driver\n")); + { + // Standard behaviour + if (I_NetOpenSocket) + { + I_NetOpenSocket(); + netgame = true; + multiplayer = true; + + if (fasticmp(COM_Argv(1), "any")) + servernode = BROADCASTADDR; + else if (I_NetMakeNodewPort) + { + if (COM_Argc() >= 3) // address AND port + servernode = I_NetMakeNodewPort(COM_Argv(1), COM_Argv(2)); + else // address only, or address:port + servernode = I_NetMakeNode(COM_Argv(1)); + } + else + { + CONS_Alert(CONS_ERROR, M_GetText("There is no server identification with this network driver\n")); + D_CloseConnection(); + return; + } + } + else + { + CONS_Alert(CONS_ERROR, M_GetText("There is no network driver\n")); + return; + } + } // invalid address if (servernode == -1) @@ -3458,6 +3476,7 @@ static void ResetNode(INT32 node); // void CL_ClearPlayer(INT32 playernum) { + // Handle mobj_t pointers. if (players[playernum].mo) { // Don't leave a NiGHTS ghost! @@ -3466,6 +3485,7 @@ void CL_ClearPlayer(INT32 playernum) P_RemoveMobj(players[playernum].mo); } + // Wipe the struct. memset(&players[playernum], 0, sizeof(player_t)); } From a5b6dad8f3b7456425069426c0db4a578abb634b Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 17 Sep 2026 11:45:51 +0200 Subject: [PATCH 13/35] cleanup p_enemy + more safety add a crapton of checks for removed mobjs copy pasted from srb2 mainly --- src/p_enemy.c | 1043 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 710 insertions(+), 333 deletions(-) diff --git a/src/p_enemy.c b/src/p_enemy.c index 013ae4705..54a1f573a 100644 --- a/src/p_enemy.c +++ b/src/p_enemy.c @@ -261,7 +261,7 @@ boolean P_Move(mobj_t *actor, fixed_t speed) if (!P_TryMove(actor, tryx, tryy, false)) { - if (actor->flags & MF_FLOAT && floatok) + if (!P_MobjWasRemovedCompat(actor) && actor->flags & MF_FLOAT && floatok) { // must adjust height if (actor->z < tmfloorz) @@ -307,7 +307,10 @@ void P_NewChaseDir(mobj_t *actor) dirtype_t d[3]; dirtype_t tdir = DI_NODIR, olddir, turnaround; - I_Assert(!P_MobjWasRemoved(actor->target)); + // only valid mobjs with valid targets may pass this point + if (P_MobjWasRemovedCompat(actor) || + P_MobjWasRemovedCompat(actor->target)) + return; olddir = actor->movedir; @@ -344,7 +347,7 @@ void P_NewChaseDir(mobj_t *actor) dirtype_t newdir = diags[((deltay < 0)<<1) + (deltax > 0)]; actor->movedir = newdir; - if ((newdir != turnaround) && P_TryWalk(actor)) + if ((newdir != turnaround) && (P_TryWalk(actor) || P_MobjWasRemovedCompat(actor))) return; } @@ -365,7 +368,7 @@ void P_NewChaseDir(mobj_t *actor) { actor->movedir = d[1]; - if (P_TryWalk(actor)) + if (P_TryWalk(actor) || P_MobjWasRemovedCompat(actor)) return; // either moved forward or attacked } @@ -373,7 +376,7 @@ void P_NewChaseDir(mobj_t *actor) { actor->movedir = d[2]; - if (P_TryWalk(actor)) + if (P_TryWalk(actor) || P_MobjWasRemovedCompat(actor)) return; } @@ -382,7 +385,7 @@ void P_NewChaseDir(mobj_t *actor) { actor->movedir =olddir; - if (P_TryWalk(actor)) + if (P_TryWalk(actor) || P_MobjWasRemovedCompat(actor)) return; } @@ -395,7 +398,7 @@ void P_NewChaseDir(mobj_t *actor) { actor->movedir = tdir; - if (P_TryWalk(actor)) + if (P_TryWalk(actor) || P_MobjWasRemovedCompat(actor)) return; } } @@ -408,7 +411,7 @@ void P_NewChaseDir(mobj_t *actor) { actor->movedir = tdir; - if (P_TryWalk(actor)) + if (P_TryWalk(actor) || P_MobjWasRemovedCompat(actor)) return; } } @@ -418,7 +421,7 @@ void P_NewChaseDir(mobj_t *actor) { actor->movedir = turnaround; - if (P_TryWalk(actor)) + if (P_TryWalk(actor) || P_MobjWasRemovedCompat(actor)) return; } @@ -485,6 +488,7 @@ boolean P_LookForPlayers(mobj_t *actor, boolean allaround, boolean tracer, fixed if (an > ANGLE_90 && an < ANGLE_270) { dist = P_AproxDistance(player->mo->x - actor->x, player->mo->y - actor->y); + // if real close, react anyway if (dist > FixedMul(MELEERANGE, actor->scale)) continue; // behind back @@ -796,7 +800,6 @@ void A_JetJawRoam(void *thing) { mobj_t *actor = thing; - if (LUA_CallAction(A_JETJAWROAM, actor)) return; @@ -914,6 +917,9 @@ void A_PointyThink(void *thing) P_SetTarget(&actor->target, player->mo); A_FaceTarget(actor); + if (P_MobjWasRemovedCompat(actor)) + return; + if (P_AproxDistance(player->mo->x - actor->x, player->mo->y - actor->y) < P_AproxDistance(player->mo->x + player->mo->momx - actor->x, player->mo->y + player->mo->momy - actor->y)) sign = -1; // Player is moving away else @@ -1031,6 +1037,9 @@ void A_HoodThink(void *thing) A_FaceTarget(actor); // Aiming... aiming... + if (P_MobjWasRemovedCompat(actor)) + return; + if (--actor->reactiontime > 0) return; @@ -1219,7 +1228,8 @@ void A_SharpChase(void *thing) { actor->threshold = actor->info->painchance; P_SetMobjState(actor, actor->info->missilestate); - S_StartSound(actor, actor->info->attacksound); + if (!P_MobjWasRemovedCompat(actor)) + S_StartSound(actor, actor->info->attacksound); } } @@ -1283,6 +1293,9 @@ void A_VultureVtol(void *thing) A_FaceTarget(actor); + if (P_MobjWasRemovedCompat(actor)) + return; + S_StopSound(actor); if (actor->z < actor->target->z+(actor->target->height/4) && actor->z + actor->height < actor->ceilingz) @@ -1484,6 +1497,9 @@ void A_LobShot(void *thing) A_FaceTarget(actor); + if (P_MobjWasRemovedCompat(actor)) + return; + if (actor->eflags & MFE_VERTICALFLIP) { z = actor->z + actor->height - FixedMul(locvar2*FRACUNIT, actor->scale); @@ -1497,6 +1513,9 @@ void A_LobShot(void *thing) shot = P_SpawnMobj(actor->x, actor->y, z, locvar1); + if (P_MobjWasRemovedCompat(shot)) + return; + if (actor->type == MT_BLACKEGGMAN) { shot->destscale = actor->scale/2; @@ -1510,8 +1529,12 @@ void A_LobShot(void *thing) // Keep track of where it's going to land hitspot = P_SpawnMobj(actor->target->x&(64*FRACUNIT-1), actor->target->y&(64*FRACUNIT-1), actor->target->subsector->sector->floorheight, MT_NULL); - hitspot->tics = airtime; - P_SetTarget(&shot->tracer, hitspot); + + if (!P_MobjWasRemovedCompat(hitspot)) + { + hitspot->tics = airtime; + P_SetTarget(&shot->tracer, hitspot); + } P_SetTarget(&shot->target, actor); // where it came from @@ -1559,6 +1582,9 @@ void A_FireShot(void *thing) A_FaceTarget(actor); + if (P_MobjWasRemovedCompat(actor)) + return; + if (actor->eflags & MFE_VERTICALFLIP) z = actor->z + actor->height - FixedMul(48*FRACUNIT + locvar2*FRACUNIT, actor->scale); else @@ -1596,6 +1622,9 @@ void A_SuperFireShot(void *thing) A_FaceTarget(actor); + if (P_MobjWasRemovedCompat(actor)) + return; + if (actor->eflags & MFE_VERTICALFLIP) z = actor->z + actor->height - FixedMul(48*FRACUNIT + locvar2*FRACUNIT, actor->scale); else @@ -1641,6 +1670,9 @@ void A_BossFireShot(void *thing) A_FaceTarget(actor); + if (P_MobjWasRemovedCompat(actor)) + return; + switch (locvar2) { case 0: @@ -1727,6 +1759,9 @@ void A_Boss7FireMissiles(void *thing) A_FaceTarget(actor); + if (P_MobjWasRemovedCompat(actor)) + return; + S_StartSound(NULL, locvar2); // set dummymo's coordinates @@ -1809,14 +1844,20 @@ void A_Boss1Laser(void *thing) if (!(actor->flags2 & MF2_FIRING)) { actor->angle = R_PointToAngle2(x, y, actor->target->x, actor->target->y); + if (mobjinfo[locvar1].seesound) S_StartSound(actor, mobjinfo[locvar1].seesound); + if (!(actor->spawnpoint && actor->spawnpoint->options & MTF_AMBUSH)) { point = P_SpawnMobj(x + P_ReturnThrustX(actor, actor->angle, actor->radius), y + P_ReturnThrustY(actor, actor->angle, actor->radius), actor->z - actor->height / 2, MT_EGGMOBILE_TARGET); - point->fuse = actor->tics+1; - P_SetTarget(&point->target, actor->target); - P_SetTarget(&actor->target, point); + + if (!P_MobjWasRemovedCompat(point)) + { + point->fuse = actor->tics+1; + P_SetTarget(&point->target, actor->target); + P_SetTarget(&actor->target, point); + } } } else if (actor->target && !(actor->spawnpoint && actor->spawnpoint->options & MTF_AMBUSH)) @@ -1828,6 +1869,10 @@ void A_Boss1Laser(void *thing) angle = R_PointToAngle2(z + (mobjinfo[locvar1].height>>1), 0, actor->target->z, R_PointToDist2(x, y, actor->target->x, actor->target->y)); point = P_SpawnMobj(x, y, z, locvar1); + + if (P_MobjWasRemovedCompat(point)) + return; + P_SetTarget(&point->target, actor); point->angle = actor->angle; speed = point->radius*2; @@ -1838,6 +1883,10 @@ void A_Boss1Laser(void *thing) for (i = 0; i < 256; i++) { mobj_t *mo = P_SpawnMobj(point->x, point->y, point->z, point->type); + + if (P_MobjWasRemovedCompat(mo)) + continue; + mo->angle = point->angle; P_UnsetThingPosition(mo); mo->flags = MF_NOBLOCKMAP|MF_NOCLIP|MF_NOCLIPHEIGHT|MF_NOGRAVITY|MF_SCENERY; @@ -1852,10 +1901,14 @@ void A_Boss1Laser(void *thing) if (z - floorz < mobjinfo[MT_EGGMOBILE_FIRE].height>>1) { point = P_SpawnMobj(x, y, floorz+1, MT_EGGMOBILE_FIRE); - P_SetTarget(&point->target, actor); - point->destscale = 3*FRACUNIT; - point->scalespeed = FRACUNIT>>2; - point->fuse = TICRATE; + + if (!P_MobjWasRemovedCompat(point)) + { + P_SetTarget(&point->target, actor); + point->destscale = 3*FRACUNIT; + point->scalespeed = FRACUNIT>>2; + point->fuse = TICRATE; + } } if (actor->tics > 1) @@ -2019,8 +2072,12 @@ void A_SkullAttack(void *thing) actor->flags2 |= MF2_SKULLFLY; if (actor->info->activesound) S_StartSound(actor, actor->info->activesound); + A_FaceTarget(actor); + if (P_MobjWasRemovedCompat(actor)) + return; + if (locvar1 == 1) actor->angle += ANGLE_180; else if (locvar1 == 2) @@ -2069,7 +2126,12 @@ void A_BossZoom(void *thing) actor->flags2 |= MF2_SKULLFLY; if (actor->info->attacksound) S_StartAttackSound(actor, actor->info->attacksound); + A_FaceTarget(actor); + + if (P_MobjWasRemovedCompat(actor)) + return; + an = actor->angle >> ANGLETOFINESHIFT; actor->momx = FixedMul(FixedMul(actor->info->speed*5*FRACUNIT, actor->scale), FINECOSINE(an)); actor->momy = FixedMul(FixedMul(actor->info->speed*5*FRACUNIT, actor->scale), FINESINE(an)); @@ -2078,6 +2140,7 @@ void A_BossZoom(void *thing) if (dist < 1) dist = 1; + actor->momz = (dest->z + (dest->height>>1) - actor->z) / dist; } @@ -2131,6 +2194,10 @@ void A_BossScream(void *thing) z = actor->z + FixedMul((P_RandomByte()<<(FRACBITS-2)) - 8*FRACUNIT, actor->scale); mo = P_SpawnMobj(x, y, z, explodetype); + + if (P_MobjWasRemovedCompat(mo)) + return; + if (actor->eflags & MFE_VERTICALFLIP) mo->flags2 |= MF2_OBJECTFLIP; mo->destscale = actor->scale; @@ -2248,16 +2315,23 @@ void A_1upThinker(void *thing) if (closestplayer == -1 || skins[players[closestplayer].skin].spritedef.numframes <= states[S_PLAY_BOX1].frame) { // Closest player not found (no players in game?? may be empty dedicated server!), or does not have correct sprite. actor->frame = 0; - if (actor->tracer) { + + if (actor->tracer) + { P_RemoveMobj(actor->tracer); P_SetTarget(&actor->target, NULL); } + return; } if (!actor->tracer) { P_SetTarget(&actor->tracer, P_SpawnMobj(actor->x, actor->y, actor->z, MT_OVERLAY)); + + if (P_MobjWasRemovedCompat(actor->tracer)) + return; + P_SetTarget(&actor->tracer->target, actor); P_SetMobjState(actor->tracer, actor->info->seestate); } @@ -2295,38 +2369,48 @@ void A_MonitorPop(void *thing) explode = mobjinfo[actor->info->speed].mass; remains = P_SpawnMobj(actor->x, actor->y, ((actor->eflags & MFE_VERTICALFLIP) ? (actor->z + 3*(actor->height/4) - FixedMul(mobjinfo[explode].height, actor->scale)) : (actor->z + actor->height/4)), explode); - if (actor->eflags & MFE_VERTICALFLIP) + + if (!P_MobjWasRemovedCompat(remains)) { - remains->eflags |= MFE_VERTICALFLIP; - remains->flags2 |= MF2_OBJECTFLIP; + if (actor->eflags & MFE_VERTICALFLIP) + { + remains->eflags |= MFE_VERTICALFLIP; + remains->flags2 |= MF2_OBJECTFLIP; + } + + remains->destscale = actor->destscale; + P_SetScale(remains, actor->scale); } - remains->destscale = actor->destscale; - P_SetScale(remains, actor->scale); remains = P_SpawnMobj(actor->x, actor->y, ((actor->eflags & MFE_VERTICALFLIP) ? (actor->z + actor->height - FixedMul(mobjinfo[actor->info->speed].height, actor->scale)) : actor->z), actor->info->speed); - remains->type = actor->type; // Transfer type information - P_UnsetThingPosition(remains); - if (sector_list) + + if (!P_MobjWasRemovedCompat(remains)) { - P_DelSeclist(sector_list); - sector_list = NULL; + remains->type = actor->type; // Transfer type information + P_UnsetThingPosition(remains); + if (sector_list) + { + P_DelSeclist(sector_list); + sector_list = NULL; + } + + P_SetThingPosition(remains); + remains->destscale = actor->destscale; + P_SetScale(remains, actor->scale); + remains->flags = actor->flags; // Transfer flags + remains->flags2 = actor->flags2; // Transfer flags2 + remains->fuse = actor->fuse; // Transfer respawn timer + remains->threshold = 68; + remains->skin = NULL; + remains->localskin = NULL; + + P_SetTarget(&tmthing, remains); + + if (actor->info->deathsound) + S_StartSound(remains, actor->info->deathsound); } - P_SetThingPosition(remains); - remains->destscale = actor->destscale; - P_SetScale(remains, actor->scale); - remains->flags = actor->flags; // Transfer flags - remains->flags2 = actor->flags2; // Transfer flags2 - remains->fuse = actor->fuse; // Transfer respawn timer - remains->threshold = 68; - remains->skin = NULL; - remains->localskin = NULL; - - P_SetTarget(&tmthing, remains); - - if (actor->info->deathsound) - S_StartSound(remains, actor->info->deathsound); item = actor->info->damage; @@ -2342,25 +2426,32 @@ void A_MonitorPop(void *thing) else newmobj = P_SpawnMobj(actor->x, actor->y, actor->z + FixedMul(13*FRACUNIT, actor->scale), item); - newmobj->destscale = actor->destscale; - P_SetScale(newmobj, actor->scale); - P_SetTarget(&newmobj->target, actor->target); // Transfer target - if (item == MT_1UPICO && newmobj->target->player) + if (!P_MobjWasRemovedCompat(newmobj)) { - if (actor->tracer) // Remove the old lives icon. - P_RemoveMobj(actor->tracer); + newmobj->destscale = actor->destscale; + P_SetScale(newmobj, actor->scale); + P_SetTarget(&newmobj->target, actor->target); // Transfer target + if (item == MT_1UPICO && newmobj->target->player) + { + if (actor->tracer) // Remove the old lives icon. + P_RemoveMobj(actor->tracer); - if (!newmobj->target->skin || ((skin_t *)newmobj->target->skin)->spritedef.numframes <= states[S_PLAY_BOX1].frame) - newmobj->frame -= 2; // No lives icon for this player, use the default. - else - { // Spawn the lives icon. - remains = P_SpawnMobj(newmobj->x, newmobj->y, newmobj->z, MT_OVERLAY); - P_SetTarget(&remains->target, newmobj); - P_SetTarget(&newmobj->tracer, remains); + if (!newmobj->target->skin || ((skin_t *)newmobj->target->skin)->spritedef.numframes <= states[S_PLAY_BOX1].frame) + newmobj->frame -= 2; // No lives icon for this player, use the default. + else + { // Spawn the lives icon. + remains = P_SpawnMobj(newmobj->x, newmobj->y, newmobj->z, MT_OVERLAY); - remains->color = newmobj->target->player->mo->color; - remains->skin = &skins[newmobj->target->player->skin]; - P_SetMobjState(remains, newmobj->info->seestate); + if (!P_MobjWasRemovedCompat(remains)) + { + P_SetTarget(&remains->target, newmobj); + P_SetTarget(&newmobj->tracer, remains); + + remains->color = newmobj->target->player->mo->color; + remains->skin = &skins[newmobj->target->player->skin]; + P_SetMobjState(remains, newmobj->info->seestate); + } + } } } } @@ -2387,6 +2478,108 @@ void A_Explode(void *thing) P_RadiusAttack(actor, actor->target, actor->info->damage); } +static void P_DoBossDefaultDeath(mobj_t *mo) +{ + thinker_t *th; + mobj_t *mo2; + + // Stop exploding and prepare to run. + P_SetMobjState(mo, mo->info->xdeathstate); + if (P_MobjWasRemoved(mo)) + return; + + P_SetTarget(&mo->target, NULL); + + // Flee! Flee! Find a point to escape to! If none, just shoot upward! + // scan the thinkers to find the runaway point + for (th = thinkercap.next; th != &thinkercap; th = th->next) + { + if (th->function != (actionf_p1)P_MobjThinker) + continue; + + mo2 = (mobj_t *)th; + + if (!mo2 || mo2->type != MT_BOSSFLYPOINT) + continue; + + // If this one's closer then the last one, go for it. + if (!mo->target || + P_AproxDistance(P_AproxDistance(mo->x - mo2->x, mo->y - mo2->y), mo->z - mo2->z) < + P_AproxDistance(P_AproxDistance(mo->x - mo->target->x, mo->y - mo->target->y), mo->z - mo->target->z)) + P_SetTarget(&mo->target, mo2); + // Otherwise... Don't! + } + + mo->flags |= MF_NOGRAVITY|MF_NOCLIP; + mo->flags |= MF_NOCLIPHEIGHT; + + if (mo->target) + { + mo->angle = R_PointToAngle2(mo->x, mo->y, mo->target->x, mo->target->y); + mo->flags2 |= MF2_BOSSFLEE; + mo->momz = FixedMul(FixedDiv(mo->target->z - mo->z, P_AproxDistance(mo->x-mo->target->x,mo->y-mo->target->y)), FixedMul(2*FRACUNIT, mo->scale)); + } + else + mo->momz = FixedMul(2*FRACUNIT, mo->scale); +} + +static void P_SpawnBossJunk(mobj_t *mo) +{ + mobj_t *mo2; + + mo2 = P_SpawnMobj(mo->x + P_ReturnThrustX(mo, mo->angle - ANGLE_90, FixedMul(32*FRACUNIT, mo->scale)), + mo->y + P_ReturnThrustY(mo, mo->angle - ANGLE_90, FixedMul(32*FRACUNIT, mo->scale)), + mo->z + mo->height/2 + ((mo->eflags & MFE_VERTICALFLIP)? FixedMul(8*FRACUNIT, mo->scale)-mobjinfo[MT_BOSSTANK1].height : -FixedMul(8*FRACUNIT, mo->scale)), MT_BOSSTANK1); // Right tank + + if (!P_MobjWasRemovedCompat(mo2)) + { + mo2->angle = mo->angle; + mo2->destscale = mo->scale; + P_SetScale(mo2, mo2->destscale); + if (mo->eflags & MFE_VERTICALFLIP) + { + mo2->eflags |= MFE_VERTICALFLIP; + mo2->flags2 |= MF2_OBJECTFLIP; + } + P_InstaThrust(mo2, mo2->angle - ANGLE_90, FixedMul(4*FRACUNIT, mo2->scale)); + P_SetObjectMomZ(mo2, 4*FRACUNIT, false); + } + + mo2 = P_SpawnMobj(mo->x + P_ReturnThrustX(mo, mo->angle + ANGLE_90, FixedMul(32*FRACUNIT, mo->scale)), + mo->y + P_ReturnThrustY(mo, mo->angle + ANGLE_90, FixedMul(32*FRACUNIT, mo->scale)), + mo->z + mo->height/2 + ((mo->eflags & MFE_VERTICALFLIP)? FixedMul(8*FRACUNIT, mo->scale)-mobjinfo[MT_BOSSTANK2].height : -FixedMul(8*FRACUNIT, mo->scale)), MT_BOSSTANK2); // Left tank + + if (!P_MobjWasRemovedCompat(mo2)) + { + mo2->angle = mo->angle; + mo2->destscale = mo->scale; + P_SetScale(mo2, mo2->destscale); + if (mo->eflags & MFE_VERTICALFLIP) + { + mo2->eflags |= MFE_VERTICALFLIP; + mo2->flags2 |= MF2_OBJECTFLIP; + } + P_InstaThrust(mo2, mo2->angle + ANGLE_90, FixedMul(4*FRACUNIT, mo2->scale)); + P_SetObjectMomZ(mo2, 4*FRACUNIT, false); + } + + mo2 = P_SpawnMobj(mo->x, mo->y, + mo->z + ((mo->eflags & MFE_VERTICALFLIP)? mobjinfo[MT_BOSSSPIGOT].height-FixedMul(32*FRACUNIT,mo->scale): mo->height + FixedMul(32*FRACUNIT, mo->scale)), MT_BOSSSPIGOT); + + if (!P_MobjWasRemovedCompat(mo2)) + { + mo2->angle = mo->angle; + mo2->destscale = mo->scale; + P_SetScale(mo2, mo2->destscale); + if (mo->eflags & MFE_VERTICALFLIP) + { + mo2->eflags |= MFE_VERTICALFLIP; + mo2->flags2 |= MF2_OBJECTFLIP; + } + P_SetObjectMomZ(mo2, 4*FRACUNIT, false); + } +} + // Function: A_BossDeath // // Description: Possibly trigger special effects when boss dies. @@ -2473,87 +2666,12 @@ bossjustdie: } else // eggmobiles { - // Stop exploding and prepare to run. - P_SetMobjState(mo, mo->info->xdeathstate); - if (P_MobjWasRemoved(mo)) - return; - - P_SetTarget(&mo->target, NULL); - - // Flee! Flee! Find a point to escape to! If none, just shoot upward! - // scan the thinkers to find the runaway point - for (th = thinkercap.next; th != &thinkercap; th = th->next) - { - if (th->function != (actionf_p1)P_MobjThinker) - continue; - - mo2 = (mobj_t *)th; - - if (mo2->type == MT_BOSSFLYPOINT) - { - // If this one's closer then the last one, go for it. - if (!mo->target || - P_AproxDistance(P_AproxDistance(mo->x - mo2->x, mo->y - mo2->y), mo->z - mo2->z) < - P_AproxDistance(P_AproxDistance(mo->x - mo->target->x, mo->y - mo->target->y), mo->z - mo->target->z)) - P_SetTarget(&mo->target, mo2); - // Otherwise... Don't! - } - } - - mo->flags |= MF_NOGRAVITY|MF_NOCLIP; - mo->flags |= MF_NOCLIPHEIGHT; - - if (mo->target) - { - mo->angle = R_PointToAngle2(mo->x, mo->y, mo->target->x, mo->target->y); - mo->flags2 |= MF2_BOSSFLEE; - mo->momz = FixedMul(FixedDiv(mo->target->z - mo->z, P_AproxDistance(mo->x-mo->target->x,mo->y-mo->target->y)), FixedMul(2*FRACUNIT, mo->scale)); - } - else - mo->momz = FixedMul(2*FRACUNIT, mo->scale); + P_DoBossDefaultDeath(mo); } if (mo->type == MT_EGGMOBILE2) { - mo2 = P_SpawnMobj(mo->x + P_ReturnThrustX(mo, mo->angle - ANGLE_90, FixedMul(32*FRACUNIT, mo->scale)), - mo->y + P_ReturnThrustY(mo, mo->angle - ANGLE_90, FixedMul(32*FRACUNIT, mo->scale)), - mo->z + mo->height/2 + ((mo->eflags & MFE_VERTICALFLIP)? FixedMul(8*FRACUNIT, mo->scale)-mobjinfo[MT_BOSSTANK1].height : -FixedMul(8*FRACUNIT, mo->scale)), MT_BOSSTANK1); // Right tank - mo2->angle = mo->angle; - mo2->destscale = mo->scale; - P_SetScale(mo2, mo2->destscale); - if (mo->eflags & MFE_VERTICALFLIP) - { - mo2->eflags |= MFE_VERTICALFLIP; - mo2->flags2 |= MF2_OBJECTFLIP; - } - P_InstaThrust(mo2, mo2->angle - ANGLE_90, FixedMul(4*FRACUNIT, mo2->scale)); - P_SetObjectMomZ(mo2, 4*FRACUNIT, false); - - mo2 = P_SpawnMobj(mo->x + P_ReturnThrustX(mo, mo->angle + ANGLE_90, FixedMul(32*FRACUNIT, mo->scale)), - mo->y + P_ReturnThrustY(mo, mo->angle + ANGLE_90, FixedMul(32*FRACUNIT, mo->scale)), - mo->z + mo->height/2 + ((mo->eflags & MFE_VERTICALFLIP)? FixedMul(8*FRACUNIT, mo->scale)-mobjinfo[MT_BOSSTANK2].height : -FixedMul(8*FRACUNIT, mo->scale)), MT_BOSSTANK2); // Left tank - mo2->angle = mo->angle; - mo2->destscale = mo->scale; - P_SetScale(mo2, mo2->destscale); - if (mo->eflags & MFE_VERTICALFLIP) - { - mo2->eflags |= MFE_VERTICALFLIP; - mo2->flags2 |= MF2_OBJECTFLIP; - } - P_InstaThrust(mo2, mo2->angle + ANGLE_90, FixedMul(4*FRACUNIT, mo2->scale)); - P_SetObjectMomZ(mo2, 4*FRACUNIT, false); - - mo2 = P_SpawnMobj(mo->x, mo->y, - mo->z + ((mo->eflags & MFE_VERTICALFLIP)? mobjinfo[MT_BOSSSPIGOT].height-FixedMul(32*FRACUNIT,mo->scale): mo->height + FixedMul(32*FRACUNIT, mo->scale)), MT_BOSSSPIGOT); - mo2->angle = mo->angle; - mo2->destscale = mo->scale; - P_SetScale(mo2, mo2->destscale); - if (mo->eflags & MFE_VERTICALFLIP) - { - mo2->eflags |= MFE_VERTICALFLIP; - mo2->flags2 |= MF2_OBJECTFLIP; - } - P_SetObjectMomZ(mo2, 4*FRACUNIT, false); + P_SpawnBossJunk(mo); return; } } @@ -3324,16 +3442,21 @@ void A_AttractChase(void *thing) { mobj_t *newring; newring = P_SpawnMobj(actor->x, actor->y, actor->z, actor->info->reactiontime); - newring->momx = actor->momx; - newring->momy = actor->momy; - newring->momz = actor->momz; + + if (!P_MobjWasRemovedCompat(newring)) + { + newring->momx = actor->momx; + newring->momy = actor->momy; + newring->momz = actor->momz; + } + P_RemoveMobj(actor); return; } P_LookForShield(actor); // Go find 'em, boy! - if (!actor->tracer + if (P_MobjWasRemovedCompat(actor->tracer) || !actor->tracer->player || !actor->tracer->health || !P_CheckSight(actor, actor->tracer)) // You have to be able to SEE it...sorta @@ -3358,7 +3481,8 @@ void A_AttractChase(void *thing) // Let attracted rings move through walls and such. actor->flags |= MF_NOCLIP; - P_Attract(actor, actor->tracer, false); + if (!P_MobjWasRemovedCompat(actor->tracer)) + P_Attract(actor, actor->tracer, false); } // Function: A_DropMine @@ -3408,9 +3532,13 @@ void A_DropMine(void *thing) // Use raisestate instead of MT_MINE mine = P_SpawnMobj(actor->x, actor->y, z, (mobjtype_t)actor->info->raisestate); - if (actor->eflags & MFE_VERTICALFLIP) - mine->eflags |= MFE_VERTICALFLIP; - mine->momz = actor->momz + actor->pmomz; + + if (!P_MobjWasRemovedCompat(mine)) + { + if (actor->eflags & MFE_VERTICALFLIP) + mine->eflags |= MFE_VERTICALFLIP; + mine->momz = actor->momz + actor->pmomz; + } S_StartSound(actor, actor->info->attacksound); } @@ -3440,7 +3568,9 @@ void A_FishJump(void *thing) else jumpval = FixedMul(AngleFixed(actor->angle)/4, actor->scale); - if (!jumpval) jumpval = FixedMul(44*(FRACUNIT/4), actor->scale); + if (!jumpval) + jumpval = FixedMul(44*(FRACUNIT/4), actor->scale); + actor->momz = jumpval; P_SetMobjStateNF(actor, actor->info->seestate); } @@ -3810,7 +3940,7 @@ void A_SetSolidSteam(void *thing) } } - P_SetObjectMomZ (actor, 1, true); + P_SetObjectMomZ(actor, 1, true); } // Function: A_UnsetSolidSteam @@ -3859,6 +3989,10 @@ void A_SignPlayer(void *thing) // spawn an overlay of the player's face. ov = P_SpawnMobj(actor->x, actor->y, actor->z, MT_OVERLAY); + + if (P_MobjWasRemovedCompat(ov)) + return; + P_SetTarget(&ov->target, actor); ov->color = actor->target->player->skincolor; ov->skin = &skins[actor->target->player->skin]; @@ -4044,17 +4178,21 @@ void A_JetbThink(void *thing) && (actor->target->z >= actor->floorz)) { mobj_t *bomb; + if (actor->info->attacksound) S_StartAttackSound(actor, actor->info->attacksound); // use raisestate instead of MT_MINE bomb = P_SpawnMobj(actor->x, actor->y, actor->z - FixedMul((32<scale), (mobjtype_t)actor->info->raisestate); - P_SetTarget(&bomb->target, actor); - bomb->destscale = actor->scale; - P_SetScale(bomb, actor->scale); - actor->reactiontime = TICRATE; // one second - S_StartSound(actor, actor->info->attacksound); + if (!P_MobjWasRemovedCompat(bomb)) + { + P_SetTarget(&bomb->target, actor); + bomb->destscale = actor->scale; + P_SetScale(bomb, actor->scale); + actor->reactiontime = TICRATE; // one second + S_StartSound(actor, actor->info->attacksound); + } } } else if (((actor->z - FixedMul((32<scale)) < thefloor) && !((thefloor + FixedMul((32<scale) + actor->height) > actor->ceilingz)) @@ -4110,6 +4248,10 @@ void A_JetgShoot(void *thing) return; A_FaceTarget(actor); + + if (P_MobjWasRemovedCompat(actor)) + return; + P_SpawnMissile(actor, actor->target, (mobjtype_t)actor->info->raisestate); actor->reactiontime = actor->info->reactiontime*TICRATE*2; @@ -4143,6 +4285,10 @@ void A_ShootBullet(void *thing) return; A_FaceTarget(actor); + + if (P_MobjWasRemovedCompat(actor)) + return; + P_SpawnMissile(actor, actor->target, (mobjtype_t)actor->info->raisestate); if (actor->info->attacksound) @@ -4184,6 +4330,10 @@ void A_MinusDigging(void *thing) actor->flags |= MF_NOCLIPTHING; var1 = 3; A_Chase(actor); + + if (P_MobjWasRemovedCompat(actor)) + return; + actor->flags &= ~MF_NOCLIPTHING; // Play digging sound @@ -4275,6 +4425,10 @@ void A_ChickenCheck(void *thing) && actor->state > &states[actor->info->seestate]) { A_Chase(actor); + + if (P_MobjWasRemovedCompat(actor)) + return; + P_SetMobjState(actor, actor->info->seestate); } @@ -4591,18 +4745,20 @@ void A_RotateSpikeBall(void *thing) P_UnsetThingPosition(actor); { const angle_t fa = actor->angle>>ANGLETOFINESHIFT; + if (!locvar1) { - actor->x = actor->target->x + FixedMul(FINECOSINE(fa),radius); - actor->y = actor->target->y + FixedMul(FINESINE(fa),radius); + actor->x = actor->target->x + FixedMul(FINECOSINE(fa), radius); + actor->y = actor->target->y + FixedMul(FINESINE(fa), radius); actor->z = actor->target->z + actor->target->height/2; } else { - actor->x = actor->tracer->x + FixedMul(FINECOSINE(fa),radius); - actor->y = actor->tracer->y + FixedMul(FINESINE(fa),radius); + actor->x = actor->tracer->x + FixedMul(FINECOSINE(fa), radius); + actor->y = actor->tracer->y + FixedMul(FINESINE(fa), radius); actor->z = actor->tracer->z + actor->tracer->height/2; } + P_SetThingPosition(actor); } } @@ -4753,6 +4909,10 @@ void A_RockSpawn(void *thing) randomoomph = 0; mo = P_SpawnMobj(actor->x, actor->y, actor->z, MT_FALLINGROCK); + + if (P_MobjWasRemovedCompat(mo)) + return; + P_SetMobjState(mo, mobjinfo[type].spawnstate); mo->angle = R_PointToAngle2(line->v2->x, line->v2->y, line->v1->x, line->v1->y); @@ -4798,17 +4958,20 @@ void A_SlingAppear(void *thing) { spawnee = P_SpawnMobj(actor->x, actor->y, actor->z, MT_SMALLMACECHAIN); - P_SetTarget(&spawnee->target, actor); - - spawnee->movecount = 0; - spawnee->threshold = 0; - spawnee->reactiontime = mlength; - - if (firsttime) + if (!P_MobjWasRemovedCompat(spawnee)) { - // This is the outermost link in the chain - spawnee->flags2 |= MF2_AMBUSH; - firsttime = false; + P_SetTarget(&spawnee->target, actor); + + spawnee->movecount = 0; + spawnee->threshold = 0; + spawnee->reactiontime = mlength; + + if (firsttime) + { + // This is the outermost link in the chain + spawnee->flags2 |= MF2_AMBUSH; + firsttime = false; + } } mlength--; @@ -5172,7 +5335,6 @@ void A_OldRingExplode(void *thing) mobj_t *mo; const fixed_t ns = FixedMul(20 * FRACUNIT, actor->scale); INT32 locvar1 = var1; - //INT32 locvar2 = var2; boolean changecolor = (actor->target && actor->target->player); if (LUA_CallAction(A_OLDRINGEXPLODE, actor)) @@ -5183,6 +5345,10 @@ void A_OldRingExplode(void *thing) const angle_t fa = (i*FINEANGLES/16) & FINEMASK; mo = P_SpawnMobj(actor->x, actor->y, actor->z, locvar1); + + if (P_MobjWasRemovedCompat(mo)) + continue; + P_SetTarget(&mo->target, actor->target); // Transfer target so player gets the points mo->momx = FixedMul(FINECOSINE(fa),ns); @@ -5210,32 +5376,38 @@ void A_OldRingExplode(void *thing) mo = P_SpawnMobj(actor->x, actor->y, actor->z, locvar1); - P_SetTarget(&mo->target, actor->target); - mo->momz = ns; - mo->flags2 |= MF2_DEBRIS; - mo->fuse = TICRATE/5; - - if (changecolor) + if (!P_MobjWasRemovedCompat(mo)) { - if (gametype != GT_CTF) - mo->color = actor->target->color; //copy color - else if (actor->target->player->ctfteam == 2) - mo->color = skincolor_bluering; + P_SetTarget(&mo->target, actor->target); + mo->momz = ns; + mo->flags2 |= MF2_DEBRIS; + mo->fuse = TICRATE/5; + + if (changecolor) + { + if (gametype != GT_CTF) + mo->color = actor->target->color; //copy color + else if (actor->target->player->ctfteam == 2) + mo->color = skincolor_bluering; + } } mo = P_SpawnMobj(actor->x, actor->y, actor->z, locvar1); - P_SetTarget(&mo->target, actor->target); - mo->momz = -ns; - mo->flags2 |= MF2_DEBRIS; - mo->fuse = TICRATE/5; - - if (changecolor) + if (!P_MobjWasRemovedCompat(mo)) { - if (gametype != GT_CTF) - mo->color = actor->target->color; //copy color - else if (actor->target->player->ctfteam == 2) - mo->color = skincolor_bluering; + P_SetTarget(&mo->target, actor->target); + mo->momz = -ns; + mo->flags2 |= MF2_DEBRIS; + mo->fuse = TICRATE/5; + + if (changecolor) + { + if (gametype != GT_CTF) + mo->color = actor->target->color; //copy color + else if (actor->target->player->ctfteam == 2) + mo->color = skincolor_bluering; + } } } @@ -5265,7 +5437,7 @@ void A_MixUp(void *thing) return; numplayers = 0; - memset(teleported, 0, sizeof (teleported)); + memset(teleported, 0, sizeof(teleported)); // Count the number of players in the game // and grab their xyz coords @@ -5828,23 +6000,27 @@ void A_Boss2Chase(void *thing) fa = (actor->movedir*FINEANGLES/8) & FINEMASK; goop = P_SpawnMobj(actor->x, actor->y, fz, actor->info->painchance); - goop->momx = FixedMul(FINECOSINE(fa),ns); - goop->momy = FixedMul(FINESINE(fa),ns); - goop->momz = FixedMul(4*FRACUNIT, actor->scale); - goop->fuse = 10*TICRATE; - if (actor->info->attacksound) - S_StartAttackSound(actor, actor->info->attacksound); + if (!P_MobjWasRemovedCompat(goop)) + { + goop->momx = FixedMul(FINECOSINE(fa),ns); + goop->momy = FixedMul(FINESINE(fa),ns); + goop->momz = FixedMul(4*FRACUNIT, actor->scale); + goop->fuse = 10*TICRATE; - if (P_RandomChance(FRACUNIT/2)) - { - goop->momx *= 2; - goop->momy *= 2; - } - else if (P_RandomChance(129*FRACUNIT/256)) - { - goop->momx *= 3; - goop->momy *= 3; + if (actor->info->attacksound) + S_StartAttackSound(actor, actor->info->attacksound); + + if (P_RandomChance(FRACUNIT/2)) + { + goop->momx *= 2; + goop->momy *= 2; + } + else if (P_RandomChance(129*FRACUNIT/256)) + { + goop->momx *= 3; + goop->momy *= 3; + } } actor->flags2 |= MF2_JUSTATTACKED; @@ -5887,12 +6063,17 @@ void A_Boss2Pogo(void *thing) fa = (actor->movedir*FINEANGLES/8) & FINEMASK; goop = P_SpawnMobj(actor->x, actor->y, fz, actor->info->painchance); + + if (P_MobjWasRemovedCompat(goop)) + continue; + goop->momx = FixedMul(FINECOSINE(fa),ns); goop->momy = FixedMul(FINESINE(fa),ns); goop->momz = FixedMul(4*FRACUNIT, actor->scale); goop->fuse = 10*TICRATE; } + actor->reactiontime = 0; // we already shot goop, so don't do it again! if (actor->info->attacksound) S_StartAttackSound(actor, actor->info->attacksound); @@ -5917,7 +6098,9 @@ void A_Boss2TakeDamage(void *thing) return; A_Pain(actor); + actor->reactiontime = 1; // turn around + if (locvar1 == 0) // old A_Invincibilerize behavior actor->movecount = TICRATE; else @@ -5999,6 +6182,10 @@ void A_Boss7Chase(void *thing) && (actor->target->player->pflags & PF_ITEMHANG)) { A_FaceTarget(actor); + + if (P_MobjWasRemovedCompat(actor)) + return; + P_SetMobjState(actor, S_BLACKEGG_SHOOT1); actor->movecount = TICRATE + P_RandomByte()/2; return; @@ -6016,6 +6203,10 @@ void A_Boss7Chase(void *thing) if (actor->z < 1056*FRACUNIT) { A_FaceTarget(actor); + + if (P_MobjWasRemovedCompat(actor)) + return; + P_SetMobjState(actor, actor->info->xdeathstate); actor->movecount = 7*TICRATE + P_RandomByte(); break; @@ -6024,6 +6215,10 @@ void A_Boss7Chase(void *thing) /* FALLTHRU */ case 1: // Chaingun Goop A_FaceTarget(actor); + + if (P_MobjWasRemovedCompat(actor)) + return; + P_SetMobjState(actor, S_BLACKEGG_SHOOT1); if (actor->health > actor->info->damage) @@ -6033,6 +6228,10 @@ void A_Boss7Chase(void *thing) break; case 2: // Homing Missile A_FaceTarget(actor); + + if (P_MobjWasRemovedCompat(actor)) + return; + P_SetMobjState(actor, actor->info->missilestate); S_StartSound(NULL, sfx_beflap); break; @@ -6119,7 +6318,9 @@ void A_Boss2PogoSFX(void *thing) actor->angle = R_PointToAngle2(actor->x, actor->y, actor->target->x, actor->target->y) + (P_RandomChance(FRACUNIT/2) ? -prandom : +prandom); P_InstaThrust(actor, actor->angle, FixedMul(FixedMul(actor->info->speed,(locvar2)), actor->scale)); } - if (actor->info->activesound) S_StartSound(actor, actor->info->activesound); + + if (actor->info->activesound) + S_StartSound(actor, actor->info->activesound); actor->momz = FixedMul(locvar1, actor->scale); // Bounce up in air actor->reactiontime = 1; } @@ -6198,7 +6399,9 @@ void A_Boss2PogoTarget(void *thing) if (actor->info->missilestate) // spawn the pogo stick collision box { mobj_t *pogo = P_SpawnMobj(actor->x, actor->y, actor->z - mobjinfo[actor->info->missilestate].height, (mobjtype_t)actor->info->missilestate); - P_SetTarget(&pogo->target, actor); + + if (!P_MobjWasRemovedCompat(pogo)) + P_SetTarget(&pogo->target, actor); } actor->reactiontime = 1; @@ -6522,7 +6725,14 @@ void A_GuardChase(void *thing) // chase towards player if (--actor->movecount < 0 || !P_Move(actor, (actor->flags2 & MF2_AMBUSH) ? actor->info->speed * 2 : actor->info->speed)) { + if (P_MobjWasRemovedCompat(actor)) + return; + P_NewChaseDir(actor); + + if (P_MobjWasRemovedCompat(actor)) + return; + actor->movecount += 5; // Increase tics before change in direction allowed. } @@ -6666,6 +6876,10 @@ void A_Boss1Spikeballs(void *thing) return; ball = P_SpawnMobj(actor->x, actor->y, actor->z, MT_EGGMOBILE_BALL); + + if (P_MobjWasRemovedCompat(ball)) + return; + P_SetTarget(&ball->target, actor); ball->movedir = FixedAngle(FixedMul(FixedDiv(locvar1<threshold = ball->radius + actor->radius + ball->info->painchance; @@ -6723,9 +6937,15 @@ void A_Boss3Path(void *thing) if (actor->tracer) P_SetTarget(&actor->target, actor->tracer->target); var1 = 0, var2 = 0; + A_FaceTarget(actor); - if (actor && actor->tracer && actor->tracer->state == &states[actor->tracer->info->missilestate]) + + if (P_MobjWasRemovedCompat(actor)) + return; + + if (actor->tracer && actor->tracer->state == &states[actor->tracer->info->missilestate]) P_SetMobjState(actor, actor->info->missilestate); + return; } else if (actor->threshold >= 0) // Traveling mode @@ -6746,6 +6966,10 @@ void A_Boss3Path(void *thing) continue; mo2 = (mobj_t *)th; + + if (!mo2) + continue; + if (mo2->type == MT_BOSS3WAYPOINT && mo2->spawnpoint && mo2->spawnpoint->angle == actor->threshold) { P_SetTarget(&actor->target, mo2); @@ -6864,6 +7088,9 @@ void A_PlaySeeSound(void *thing) if (LUA_CallAction(A_PLAYSEESOUND, actor)) return; + if (P_MobjWasRemovedCompat(actor)) + return; + if (actor->info->seesound) S_StartScreamSound(actor, actor->info->seesound); } @@ -6928,11 +7155,20 @@ void A_SmokeTrailer(void *thing) if (actor->eflags & MFE_VERTICALFLIP) { th = P_SpawnMobj(actor->x-actor->momx, actor->y-actor->momy, actor->z + actor->height - FixedMul(mobjinfo[locvar1].height, actor->scale), locvar1); + + if (P_MobjWasRemovedCompat(th)) + return; + th->flags2 |= MF2_OBJECTFLIP; } else + { th = P_SpawnMobj(actor->x-actor->momx, actor->y-actor->momy, actor->z, locvar1); + if (P_MobjWasRemovedCompat(th)) + return; + } + P_SetObjectMomZ(th, FRACUNIT, false); th->destscale = actor->scale; P_SetScale(th, actor->scale); @@ -6973,6 +7209,9 @@ void A_SpawnObjectAbsolute(void *thing) mo = P_SpawnMobj(x<angle = actor->angle; @@ -7017,6 +7256,9 @@ void A_SpawnObjectRelative(void *thing) actor->y + FixedMul(y<scale), (actor->eflags & MFE_VERTICALFLIP) ? ((actor->z + actor->height - mobjinfo[type].height) - FixedMul(z<scale)) : (actor->z + FixedMul(z<scale)), type); + if (P_MobjWasRemovedCompat(mo)) + return; + // Spawn objects with an angle matching the spawner's, rather than spawning Eastwards - Monster Iestyn mo->angle = actor->angle; @@ -7594,12 +7836,16 @@ void A_BossJetFume(void *thing) jetz = actor->z + FixedMul(38*FRACUNIT, actor->scale); filler = P_SpawnMobj(jetx, jety, jetz, MT_JETFUME1); - P_SetTarget(&filler->target, actor); - filler->destscale = actor->scale; - P_SetScale(filler, filler->destscale); - if (actor->eflags & MFE_VERTICALFLIP) - filler->flags2 |= MF2_OBJECTFLIP; - filler->fuse = 56; + + if (!P_MobjWasRemovedCompat(filler)) + { + P_SetTarget(&filler->target, actor); + filler->destscale = actor->scale; + P_SetScale(filler, filler->destscale); + if (actor->eflags & MFE_VERTICALFLIP) + filler->flags2 |= MF2_OBJECTFLIP; + filler->fuse = 56; + } if (actor->eflags & MFE_VERTICALFLIP) jetz = actor->z + actor->height - FixedMul(12*FRACUNIT + mobjinfo[MT_JETFUME1].height, actor->scale); @@ -7609,22 +7855,30 @@ void A_BossJetFume(void *thing) filler = P_SpawnMobj(jetx + P_ReturnThrustX(actor, actor->angle-ANGLE_90, FixedMul(24*FRACUNIT, actor->scale)), jety + P_ReturnThrustY(actor, actor->angle-ANGLE_90, FixedMul(24*FRACUNIT, actor->scale)), jetz, MT_JETFUME1); - P_SetTarget(&filler->target, actor); - filler->destscale = actor->scale; - P_SetScale(filler, filler->destscale); - if (actor->eflags & MFE_VERTICALFLIP) - filler->flags2 |= MF2_OBJECTFLIP; - filler->fuse = 57; + + if (!P_MobjWasRemovedCompat(filler)) + { + P_SetTarget(&filler->target, actor); + filler->destscale = actor->scale; + P_SetScale(filler, filler->destscale); + if (actor->eflags & MFE_VERTICALFLIP) + filler->flags2 |= MF2_OBJECTFLIP; + filler->fuse = 57; + } filler = P_SpawnMobj(jetx + P_ReturnThrustX(actor, actor->angle+ANGLE_90, FixedMul(24*FRACUNIT, actor->scale)), jety + P_ReturnThrustY(actor, actor->angle+ANGLE_90, FixedMul(24*FRACUNIT, actor->scale)), jetz, MT_JETFUME1); - P_SetTarget(&filler->target, actor); - filler->destscale = actor->scale; - P_SetScale(filler, filler->destscale); - if (actor->eflags & MFE_VERTICALFLIP) - filler->flags2 |= MF2_OBJECTFLIP; - filler->fuse = 58; + + if (!P_MobjWasRemovedCompat(filler)) + { + P_SetTarget(&filler->target, actor); + filler->destscale = actor->scale; + P_SetScale(filler, filler->destscale); + if (actor->eflags & MFE_VERTICALFLIP) + filler->flags2 |= MF2_OBJECTFLIP; + filler->fuse = 58; + } P_SetTarget(&actor->tracer, filler); } @@ -7641,12 +7895,16 @@ void A_BossJetFume(void *thing) jetz = actor->z + FixedMul(17*FRACUNIT, actor->scale); filler = P_SpawnMobj(jetx, jety, jetz, MT_PROPELLER); - P_SetTarget(&filler->target, actor); - filler->destscale = actor->scale; - P_SetScale(filler, filler->destscale); - if (actor->eflags & MFE_VERTICALFLIP) - filler->flags2 |= MF2_OBJECTFLIP; - filler->angle = actor->angle - ANGLE_180; + + if (!P_MobjWasRemovedCompat(filler)) + { + P_SetTarget(&filler->target, actor); + filler->destscale = actor->scale; + P_SetScale(filler, filler->destscale); + if (actor->eflags & MFE_VERTICALFLIP) + filler->flags2 |= MF2_OBJECTFLIP; + filler->angle = actor->angle - ANGLE_180; + } P_SetTarget(&actor->tracer, filler); } @@ -7654,29 +7912,39 @@ void A_BossJetFume(void *thing) case 2: // Metal Sonic jet fumes { filler = P_SpawnMobj(actor->x, actor->y, actor->z, MT_JETFUME1); - P_SetTarget(&filler->target, actor); - filler->fuse = 59; - P_SetTarget(&actor->tracer, filler); - filler->destscale = actor->scale/2; - P_SetScale(filler, filler->destscale); - if (actor->eflags & MFE_VERTICALFLIP) - filler->flags2 |= MF2_OBJECTFLIP; + + if (!P_MobjWasRemovedCompat(filler)) + { + P_SetTarget(&filler->target, actor); + filler->fuse = 59; + P_SetTarget(&actor->tracer, filler); + filler->destscale = actor->scale/2; + P_SetScale(filler, filler->destscale); + if (actor->eflags & MFE_VERTICALFLIP) + filler->flags2 |= MF2_OBJECTFLIP; + } } break; case 3: // Boss 4 jet flame { fixed_t jetz; + if (actor->eflags & MFE_VERTICALFLIP) jetz = actor->z + actor->height + FixedMul(50*FRACUNIT - mobjinfo[MT_JETFLAME].height, actor->scale); else jetz = actor->z - FixedMul(50*FRACUNIT, actor->scale); + filler = P_SpawnMobj(actor->x, actor->y, jetz, MT_JETFLAME); - P_SetTarget(&filler->target, actor); - // Boss 4 already uses its tracer for other things - filler->destscale = actor->scale; - P_SetScale(filler, filler->destscale); - if (actor->eflags & MFE_VERTICALFLIP) - filler->flags2 |= MF2_OBJECTFLIP; + + if (!P_MobjWasRemovedCompat(filler)) + { + P_SetTarget(&filler->target, actor); + // Boss 4 already uses its tracer for other things + filler->destscale = actor->scale; + P_SetScale(filler, filler->destscale); + if (actor->eflags & MFE_VERTICALFLIP) + filler->flags2 |= MF2_OBJECTFLIP; + } } break; } @@ -7906,33 +8174,41 @@ void A_ItemPop(void *thing) explode = mobjinfo[actor->info->damage].mass; remains = P_SpawnMobj(actor->x, actor->y, ((actor->eflags & MFE_VERTICALFLIP) ? (actor->z + 3*(actor->height/4) - FixedMul(mobjinfo[explode].height, actor->scale)) : (actor->z + actor->height/4)), explode); - if (actor->eflags & MFE_VERTICALFLIP) + + if (!P_MobjWasRemovedCompat(remains)) { - remains->eflags |= MFE_VERTICALFLIP; - remains->flags2 |= MF2_OBJECTFLIP; + if (actor->eflags & MFE_VERTICALFLIP) + { + remains->eflags |= MFE_VERTICALFLIP; + remains->flags2 |= MF2_OBJECTFLIP; + } + remains->destscale = actor->destscale; + P_SetScale(remains, actor->scale); } - remains->destscale = actor->destscale; - P_SetScale(remains, actor->scale); remains = P_SpawnMobj(actor->x, actor->y, actor->z, actor->info->damage); - remains->type = actor->type; // Transfer type information - P_UnsetThingPosition(remains); - if (sector_list) - { - P_DelSeclist(sector_list); - sector_list = NULL; - } - P_SetThingPosition(remains); - remains->destscale = actor->destscale; - P_SetScale(remains, actor->scale); - remains->flags = actor->flags; // Transfer flags - remains->flags2 = actor->flags2; // Transfer flags2 - remains->fuse = actor->fuse; // Transfer respawn timer - remains->threshold = (actor->threshold == 69 ? 69 : 68); - remains->skin = NULL; - remains->spawnpoint = actor->spawnpoint; - P_SetTarget(&tmthing, remains); + if (!P_MobjWasRemovedCompat(remains)) + { + remains->type = actor->type; // Transfer type information + P_UnsetThingPosition(remains); + if (sector_list) + { + P_DelSeclist(sector_list); + sector_list = NULL; + } + P_SetThingPosition(remains); + remains->destscale = actor->destscale; + P_SetScale(remains, actor->scale); + remains->flags = actor->flags; // Transfer flags + remains->flags2 = actor->flags2; // Transfer flags2 + remains->fuse = actor->fuse; // Transfer respawn timer + remains->threshold = (actor->threshold == 69 ? 69 : 68); + remains->skin = NULL; + remains->spawnpoint = actor->spawnpoint; + + P_SetTarget(&tmthing, remains); + } if (actor->info->deathsound) S_StartSound(remains, actor->info->deathsound); @@ -7964,12 +8240,16 @@ void A_JawzChase(void *thing) mobj_t *ret; ret = P_SpawnMobj(actor->tracer->x, actor->tracer->y, actor->tracer->z, MT_PLAYERRETICULE); - P_SetTarget(&ret->target, actor->tracer); - ret->old_x = actor->tracer->old_x; - ret->old_y = actor->tracer->old_y; - ret->old_z = actor->tracer->old_z; - ret->frame |= ((leveltime % 10) / 2) + 5; - ret->color = actor->cvmem; + + if (!P_MobjWasRemovedCompat(ret)) + { + P_SetTarget(&ret->target, actor->tracer); + ret->old_x = actor->tracer->old_x; + ret->old_y = actor->tracer->old_y; + ret->old_z = actor->tracer->old_z; + ret->frame |= ((leveltime % 10) / 2) + 5; + ret->color = actor->cvmem; + } P_Thrust(actor, R_PointToAngle2(actor->x, actor->y, actor->tracer->x, actor->tracer->y), (7*actor->movefactor)/64); return; @@ -8002,8 +8282,12 @@ void A_JawzExplode(void *thing) return; truc = P_SpawnMobj(actor->x, actor->y, actor->z, MT_BOOMEXPLODE); - truc->scale = actor->scale*2; - truc->color = SKINCOLOR_KETCHUP; + + if (!P_MobjWasRemovedCompat(truc)) + { + truc->scale = actor->scale*2; + truc->color = SKINCOLOR_KETCHUP; + } while (shrapnel) { @@ -8018,17 +8302,21 @@ void A_JawzExplode(void *thing) rand_x = actor->x + P_RandomRange(-8, 8)*FRACUNIT; truc = P_SpawnMobj(rand_x, rand_y, rand_z, MT_BOOMPARTICLE); - truc->scale = actor->scale*2; - speed = FixedMul(7*FRACUNIT, actor->scale)>>FRACBITS; - truc->momx = P_RandomRange(-speed, speed)*FRACUNIT; - truc->momy = P_RandomRange(-speed, speed)*FRACUNIT; + if (!P_MobjWasRemovedCompat(truc)) + { + truc->scale = actor->scale*2; - speed = FixedMul(5*FRACUNIT, actor->scale)>>FRACBITS; - speed2 = FixedMul(15*FRACUNIT, actor->scale)>>FRACBITS; - truc->momz = P_RandomRange(speed, speed2)*FRACUNIT; - truc->tics = TICRATE*2; - truc->color = SKINCOLOR_KETCHUP; + speed = FixedMul(7*FRACUNIT, actor->scale)>>FRACBITS; + truc->momx = P_RandomRange(-speed, speed)*FRACUNIT; + truc->momy = P_RandomRange(-speed, speed)*FRACUNIT; + + speed = FixedMul(5*FRACUNIT, actor->scale)>>FRACBITS; + speed2 = FixedMul(15*FRACUNIT, actor->scale)>>FRACBITS; + truc->momz = P_RandomRange(speed, speed2)*FRACUNIT; + truc->tics = TICRATE*2; + truc->color = SKINCOLOR_KETCHUP; + } shrapnel--; } @@ -8201,14 +8489,18 @@ void A_SPBChase(void *thing) rand_x = actor->x + (P_RandomRange(-24,24) * actor->scale); mobj_t *fast = P_SpawnMobj(rand_x, rand_y, rand_z, MT_FASTLINE); - fast->angle = R_PointToAngle2(0, 0, actor->momx, actor->momy); - //fast->momx = (3*actor->momx)/4; - //fast->momy = (3*actor->momy)/4; - //fast->momz = (3*actor->momz)/4; - fast->color = SKINCOLOR_RED; - fast->colorized = true; - P_SetTarget(&fast->target, actor); // easier lua access - K_MatchGenericExtraFlags(fast, actor); + + if (!P_MobjWasRemovedCompat(fast)) + { + fast->angle = R_PointToAngle2(0, 0, actor->momx, actor->momy); + //fast->momx = (3*actor->momx)/4; + //fast->momy = (3*actor->momy)/4; + //fast->momz = (3*actor->momz)/4; + fast->color = SKINCOLOR_RED; + fast->colorized = true; + P_SetTarget(&fast->target, actor); // easier lua access + K_MatchGenericExtraFlags(fast, actor); + } } return; @@ -8339,6 +8631,10 @@ void A_BallhogExplode(void *thing) return; mo2 = P_SpawnMobj(actor->x, actor->y, actor->z, MT_BALLHOGBOOM); + + if (P_MobjWasRemovedCompat(mo2)) + return; + P_SetScale(mo2, actor->scale*2); mo2->destscale = mo2->scale; S_StartSound(mo2, actor->info->deathsound); @@ -8424,6 +8720,9 @@ void A_FZBoomSmoke(void *thing) mobj_t *smoke = P_SpawnMobj(rand_x, rand_y, rand_z, MT_THOK); + if (P_MobjWasRemovedCompat(smoke)) + continue; + P_SetMobjState(smoke, S_FZEROSMOKE1); smoke->tics += P_RandomRange(-3, 4); smoke->scale = actor->scale*3; @@ -8447,13 +8746,18 @@ void A_RandomShadowFrame(void *thing) if (!actor->extravalue1) // Hack that spawns thoks that look like random shadows. Otherwise the state would overwrite our frame and that's a pain. { fake = P_SpawnMobj(actor->x, actor->y, actor->z, MT_THOK); - fake->sprite = SPR_ENM1; - fake->frame = P_RandomRange(0, 6); - P_SetScale(fake, FRACUNIT*3/2); - fake->scale = FRACUNIT*3/2; - fake->destscale = FRACUNIT*3/2; - fake->angle = actor->angle; - fake->tics = -1; + + if (!P_MobjWasRemovedCompat(fake)) + { + fake->sprite = SPR_ENM1; + fake->frame = P_RandomRange(0, 6); + P_SetScale(fake, FRACUNIT*3/2); + fake->scale = FRACUNIT*3/2; + fake->destscale = FRACUNIT*3/2; + fake->angle = actor->angle; + fake->tics = -1; + } + actor->flags2 |= MF2_DONTDRAW; actor->extravalue1 = 1; } @@ -8472,11 +8776,16 @@ void A_RandomShadowFrame(void *thing) { P_DamageMobj(actor->target, actor, actor, 1); P_InstaThrust(actor->target, actor->angle, 16<target->x, actor->target->y, actor->target->z, MT_THOK); - P_SetMobjStateNF(fire, S_QUICKBOOM1); - P_SetScale(fire, 4<color = SKINCOLOR_KETCHUP; - S_StartSound(actor->target, sfx_fire2); + + if (!P_MobjWasRemovedCompat(fire)) + { + P_SetMobjStateNF(fire, S_QUICKBOOM1); + P_SetScale(fire, 4<color = SKINCOLOR_KETCHUP; + S_StartSound(actor->target, sfx_fire2); + } } } @@ -8524,12 +8833,21 @@ void A_RoamingShadowThinker(void *thing) // Spawn the WIND: wind = P_SpawnMobj(actor->target->x, actor->target->y, actor->target->z, MT_THOK); // Opaque layer: - P_SetMobjState(wind, S_GARU1); - P_SetScale(wind, FRACUNIT*3/2); + + if (!P_MobjWasRemovedCompat(wind)) + { + P_SetMobjState(wind, S_GARU1); + P_SetScale(wind, FRACUNIT*3/2); + } + wind = P_SpawnMobj(actor->target->x, actor->target->y, actor->target->z, MT_THOK); // Translucent layer: - P_SetMobjState(wind, S_TGARU0); - P_SetScale(wind, FRACUNIT*3/2); - wind->destscale = 30<destscale = 30<angle += ANG1*3; actor->extravalue2--; } + return; } @@ -8607,6 +8926,10 @@ void A_MementosTPParticles(void *thing) rand_x = actor->x + (P_RandomRange(-256, 256)<frame = 0; particle->color = ((i%2) ? (SKINCOLOR_RED) : (SKINCOLOR_BLACK)); particle->destscale = 1; @@ -8678,6 +9001,10 @@ void A_ReaperThinker(void *thing) rand_x = actor->x + (P_RandomRange(-60, 60)<z, MT_THOK); + + if (P_MobjWasRemovedCompat(particle)) + continue; + particle->momz = 20<color = ((i%2 !=0) ? (SKINCOLOR_RED) : (SKINCOLOR_BLACK)); particle->frame = 0; @@ -8693,6 +9020,10 @@ void A_ReaperThinker(void *thing) for (; i < 15; i++) // spawn in a circle formation or w/e. { particle = P_SpawnMobj(actor->x, actor->y, actor->z, MT_THOK); + + if (P_MobjWasRemovedCompat(particle)) + continue; + particle->momz = 20<color = ((i%2 !=0) ? (SKINCOLOR_RED) : (SKINCOLOR_BLACK)); particle->frame = 0; @@ -8755,7 +9086,6 @@ void A_ReaperThinker(void *thing) // The player we should target if it's near us: for (i = 0; i < MAXPLAYERS; i++) { - if (!playeringame[i]) continue; @@ -8841,7 +9171,9 @@ void A_FlameParticle(void *thing) rand_x = actor->x + (P_RandomRange(-rad, rad)<info->painchance); - par->momz = actor->scale<<1; + + if (!P_MobjWasRemovedCompat(par)) + par->momz = actor->scale<<1; } //} @@ -9028,7 +9360,7 @@ void A_KnockBack(void *thing) if (!target) { - if(cv_debug) + if (cv_debug) CONS_Printf("A_KnockBack: No target!\n"); return; } @@ -9130,6 +9462,9 @@ void A_SplitShot(void *thing) A_FaceTarget(actor); + if (P_MobjWasRemovedCompat(actor)) + return; + const angle_t an = (actor->angle + ANGLE_90) >> ANGLETOFINESHIFT; const fixed_t fasin = FINESINE(an); const fixed_t facos = FINECOSINE(an); @@ -9194,8 +9529,13 @@ void A_MultiShot(void *thing) return; if (actor->target) + { A_FaceTarget(actor); + if (P_MobjWasRemovedCompat(actor)) + return; + } + if (loc1lw > 90) ad = FixedMul(90*FRACUNIT, actor->scale); else @@ -10366,6 +10706,9 @@ void A_TrapShot(void *thing) missile = P_SpawnMobj(x, y, z, type); + if (P_MobjWasRemovedCompat(missile)) + return; + if (actor->eflags & MFE_VERTICALFLIP) missile->flags2 |= MF2_OBJECTFLIP; missile->destscale = actor->destscale; @@ -10410,6 +10753,9 @@ void A_VileTarget(void *thing) A_FaceTarget(actor); + if (P_MobjWasRemovedCompat(actor)) + return; + // Determine object to spawn if (locvar1 <= 0 || locvar1 >= NUMMOBJTYPES) fogtype = MT_CYBRAKDEMON_TARGET_RETICULE; @@ -10422,18 +10768,22 @@ void A_VileTarget(void *thing) actor->target->y, actor->target->z + ((actor->target->eflags & MFE_VERTICALFLIP) ? actor->target->height - mobjinfo[fogtype].height : 0), fogtype); - if (actor->target->eflags & MFE_VERTICALFLIP) - { - fog->eflags |= MFE_VERTICALFLIP; - fog->flags2 |= MF2_OBJECTFLIP; - } - fog->destscale = actor->target->scale; - P_SetScale(fog, fog->destscale); - P_SetTarget(&actor->tracer, fog); - P_SetTarget(&fog->target, actor); - P_SetTarget(&fog->tracer, actor->target); - A_VileFire(fog); + if (!P_MobjWasRemovedCompat(fog)) + { + if (actor->target->eflags & MFE_VERTICALFLIP) + { + fog->eflags |= MFE_VERTICALFLIP; + fog->flags2 |= MF2_OBJECTFLIP; + } + fog->destscale = actor->target->scale; + P_SetScale(fog, fog->destscale); + + P_SetTarget(&actor->tracer, fog); + P_SetTarget(&fog->target, actor); + P_SetTarget(&fog->tracer, actor->target); + A_VileFire(fog); + } } else { @@ -10450,19 +10800,22 @@ void A_VileTarget(void *thing) players[i].mo->z + ((players[i].mo->eflags & MFE_VERTICALFLIP) ? players[i].mo->height - mobjinfo[fogtype].height : 0), fogtype); - if (players[i].mo->eflags & MFE_VERTICALFLIP) + if (!P_MobjWasRemovedCompat(fog)) { - fog->eflags |= MFE_VERTICALFLIP; - fog->flags2 |= MF2_OBJECTFLIP; - } - fog->destscale = players[i].mo->scale; - P_SetScale(fog, fog->destscale); + if (players[i].mo->eflags & MFE_VERTICALFLIP) + { + fog->eflags |= MFE_VERTICALFLIP; + fog->flags2 |= MF2_OBJECTFLIP; + } + fog->destscale = players[i].mo->scale; + P_SetScale(fog, fog->destscale); - if (players[i].mo == actor->target) // We only care to track the fog targeting who we REALLY hate right now - P_SetTarget(&actor->tracer, fog); - P_SetTarget(&fog->target, actor); - P_SetTarget(&fog->tracer, players[i].mo); - A_VileFire(fog); + if (players[i].mo == actor->target) // We only care to track the fog targeting who we REALLY hate right now + P_SetTarget(&actor->tracer, fog); + P_SetTarget(&fog->target, actor); + P_SetTarget(&fog->tracer, players[i].mo); + A_VileFire(fog); + } } } } @@ -10496,6 +10849,9 @@ void A_VileAttack(void *thing) A_FaceTarget(actor); + if (P_MobjWasRemovedCompat(actor)) + return; + if (locvar1 <= 0 || locvar1 >= NUMSFX) soundtoplay = sfx_brakrx; else @@ -10817,6 +11173,9 @@ void A_BrakFireShot(void *thing) A_FaceTarget(actor); + if (P_MobjWasRemovedCompat(actor)) + return; + x = actor->x + P_ReturnThrustX(actor, actor->angle, FixedMul(64*FRACUNIT, actor->scale)) + P_ReturnThrustX(actor, actor->angle+ANGLE_270, FixedMul(32*FRACUNIT, actor->scale)); @@ -10934,10 +11293,20 @@ void A_BrakLobShot(void *thing) // Okay, complicated math done. Let's fire our object already, sheesh. A_FaceTarget(actor); + + if (P_MobjWasRemovedCompat(actor)) + return; + if (locvar1 <= 0 || locvar1 >= NUMMOBJTYPES) typeOfShot = MT_CANNONBALL; - else typeOfShot = (mobjtype_t)locvar1; + else + typeOfShot = (mobjtype_t)locvar1; + shot = P_SpawnMobj(actor->x, actor->y, actor->z + FixedMul(locvar2*FRACUNIT, actor->scale), typeOfShot); + + if (P_MobjWasRemovedCompat(shot)) + return; + if (shot->info->seesound) S_StartSound(shot, shot->info->seesound); P_SetTarget(&shot->target, actor); // where it came from @@ -11006,6 +11375,10 @@ void A_NapalmScatter(void *thing) const angle_t fa = (i*FINEANGLES/numToShoot) & FINEMASK; mo = P_SpawnMobj(actor->x, actor->y, actor->z, typeOfShot); + + if (P_MobjWasRemovedCompat(mo)) + continue; + P_SetTarget(&mo->target, actor->target); // Transfer target so Brak doesn't hit himself like an idiot mo->angle = fa << ANGLETOFINESHIFT; @@ -11033,6 +11406,10 @@ void A_SpawnFreshCopy(void *thing) return; newObject = P_SpawnMobj(actor->x, actor->y, actor->z, actor->type); + + if (P_MobjWasRemovedCompat(newObject)) + return; + newObject->angle = actor->angle; P_SetScale(newObject, actor->scale); newObject->destscale = actor->destscale; From 295b35b23a50492d362b785adad190937dec03e0 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 21 Sep 2026 16:38:54 +0200 Subject: [PATCH 14/35] cleanup p_mobj + more safety big cleanups and more mobj checks needs to be rechecked since its quite a lot --- src/p_inter.c | 3 + src/p_mobj.c | 1907 +++++++++++++++++++++++++++---------------------- 2 files changed, 1047 insertions(+), 863 deletions(-) diff --git a/src/p_inter.c b/src/p_inter.c index e6f753b56..0bb273ace 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -107,6 +107,9 @@ void P_DoNightsScore(player_t *player) dummymo = P_SpawnMobj(player->mo->x, player->mo->y, player->mo->z+player->mo->height/2, MT_NIGHTSCORE); + if (P_MobjWasRemovedCompat(dummymo)) + return; + if (player->bot) player = &players[consoleplayer]; diff --git a/src/p_mobj.c b/src/p_mobj.c index 52b64df3c..fbb821e88 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -43,6 +43,10 @@ consvar_t cv_splats = {"splats", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; #endif +#define MAXHUNTEMERALDS 64 +mapthing_t *huntemeralds[MAXHUNTEMERALDS] = {}; +INT32 numhuntemeralds = 0; + actioncache_t actioncachehead = {}; static mobj_t *overlaycap = NULL; @@ -122,6 +126,27 @@ static void P_CycleMobjState(mobj_t *mobj) } } +// +// P_CycleMobjState for players. +// +static void P_CyclePlayerMobjState(mobj_t *mobj) +{ + // state animations + // P_CycleStateAnimation(mobj); // kart does not call this for some reason + + // cycle through states, + // calling action functions at transitions + if (mobj->tics != -1) + { + mobj->tics--; + + // you can cycle through multiple states in a tic + if (!mobj->tics && mobj->state) + if (!P_SetPlayerMobjState(mobj, mobj->state->nextstate)) + return; // freed itself + } +} + #define MAX_RECURSION 20 // @@ -327,6 +352,14 @@ boolean P_WeaponOrPanel(mobjtype_t type) return false; } +// +// P_RingOrCoin +// +static inline boolean P_RingOrCoin(mobjtype_t type) +{ + return (type == MT_RING || type == MT_REDTEAMRING || type == MT_BLUETEAMRING || type == MT_COIN); +} + // // P_ExplodeMissile // @@ -1459,6 +1492,10 @@ void P_XYMovement(mobj_t *mo) else if (mo->flags & MF_BOUNCE) { P_BounceMove(mo); + + if (P_MobjWasRemovedCompat(mo)) + return; + S_StartSound(mo, mo->info->activesound); //{ SRB2kart - Orbinaut, Ballhog @@ -2782,10 +2819,14 @@ static boolean P_SceneryZMovement(mobj_t *mo) { prandom = P_RandomByte(); explodemo = P_SpawnMobj(mo->x, mo->y, mo->z, MT_SMALLBUBBLE); - explodemo->momx += ((prandom & 0x0F) << (FRACBITS-2)) * (i & 2 ? -1 : 1); - explodemo->momy += ((prandom & 0xF0) << (FRACBITS-6)) * (i & 1 ? -1 : 1); - explodemo->destscale = mo->scale; - P_SetScale(explodemo, mo->scale); + + if (!P_MobjWasRemovedCompat(explodemo)) + { + explodemo->momx += ((prandom & 0x0F) << (FRACBITS-2)) * (i & 2 ? -1 : 1); + explodemo->momy += ((prandom & 0xF0) << (FRACBITS-6)) * (i & 1 ? -1 : 1); + explodemo->destscale = mo->scale; + P_SetScale(explodemo, mo->scale); + } } if (mo->threshold != 42) // Don't make pop sound if threshold is 42. @@ -3272,7 +3313,7 @@ void P_CalcChasePostImg(player_t *player, camera_t *thiscam) player_flipcam = cv_flipcam[pnum].value; } - const boolean flipcam = (player_flipcam && player->mo->eflags & MFE_VERTICALFLIP && !nightsplayer(player)); + const boolean flipcam = (player_flipcam && (player->mo->eflags & MFE_VERTICALFLIP) && !nightsplayer(player)); UINT8 postimgtype = 0; if (encoremode) @@ -3612,17 +3653,7 @@ static void P_PlayerMobjThinker(mobj_t *mobj) } animonly: - // cycle through states, - // calling action functions at transitions - if (mobj->tics != -1) - { - mobj->tics--; - - // you can cycle through multiple states in a tic - if (!mobj->tics) - if (!P_SetPlayerMobjState(mobj, mobj->state->nextstate)) - return; // freed itself - } + P_CyclePlayerMobjState(mobj); } static void P_CalculatePrecipFloor(precipmobj_t *mobj) @@ -3783,6 +3814,7 @@ static void P_RingThinker(mobj_t *mobj) boolean P_BossTargetPlayer(mobj_t *actor, boolean closest) { INT32 stop = -1, c = 0; + INT32 i, pcount = 0; player_t *player; fixed_t dist, lastdist = 0; @@ -3791,6 +3823,18 @@ boolean P_BossTargetPlayer(mobj_t *actor, boolean closest) actor->lastlook = P_RandomByte(); actor->lastlook &= PLAYERSMASK; + // No players? Don't bother. + for (i = 0; i < MAXPLAYERS; i++) + { + if (!playeringame[i] || players[i].spectator) + continue; + + pcount++; + } + + if (!pcount) + return false; + for( ; ; actor->lastlook = (actor->lastlook+1) & PLAYERSMASK) { // save the first look so we stop next time. @@ -3823,11 +3867,13 @@ boolean P_BossTargetPlayer(mobj_t *actor, boolean closest) if (closest) { dist = P_AproxDistance(actor->x - player->mo->x, actor->y - player->mo->y); + if (!lastdist || dist < lastdist) { lastdist = dist+1; P_SetTarget(&actor->target, player->mo); } + continue; } @@ -3917,7 +3963,7 @@ static void P_Boss1Thinker(mobj_t *mobj) if (!mobj->target || !(mobj->target->flags & MF_SHOOTABLE)) { if (mobj->target && mobj->target->health - && mobj->target->type == MT_EGGMOBILE_TARGET) // Oh, we're just firing our laser. + && mobj->target->type == MT_EGGMOBILE_TARGET) // Oh, we're just firing our laser. return; // It's okay, then. if (mobj->health <= 0) @@ -5532,9 +5578,9 @@ static void P_MoveHoop(mobj_t *mobj) z = mobj->target->z+mobj->target->height/2; // Make the sprite travel towards the center of the hoop - v[0] = FixedMul(FINECOSINE(fa),fuse); + v[0] = FixedMul(FINECOSINE(fa), fuse); v[1] = 0; - v[2] = FixedMul(FINESINE(fa),fuse); + v[2] = FixedMul(FINESINE(fa), fuse); v[3] = FRACUNIT; res = VectorMatrixMultiply(v, *RotateXMatrix(FixedAngle(mobj->target->movedir*FRACUNIT))); @@ -5792,7 +5838,7 @@ void P_RunOverlays(void) { // run overlays mobj_t *mo, *next = NULL; - fixed_t destx,desty,zoffs; + fixed_t destx, desty, zoffs; for (mo = overlaycap; mo; mo = next) { @@ -5818,6 +5864,7 @@ void P_RunOverlays(void) if (!(mo->state->frame & FF_ANIMATE) && mo->state->var1) viewingangle += ANGLE_180; + destx = mo->target->x + P_ReturnThrustX(mo->target, viewingangle, FixedMul(FRACUNIT/4, mo->scale)); desty = mo->target->y + P_ReturnThrustY(mo->target, viewingangle, FixedMul(FRACUNIT/4, mo->scale)); } @@ -5846,16 +5893,20 @@ void P_RunOverlays(void) mo->y = desty; mo->radius = mo->target->radius; mo->height = mo->target->height; + if (mo->eflags & MFE_VERTICALFLIP) mo->z = (mo->target->z + mo->target->height - mo->height) - zoffs; else mo->z = mo->target->z + zoffs; + if (mo->state->var1) P_SetUnderlayPosition(mo); else P_SetThingPosition(mo); + P_CheckPosition(mo, mo->x, mo->y); } + P_SetTarget(&overlaycap, NULL); } @@ -6144,8 +6195,8 @@ static void P_MobjScaleThink(mobj_t *mobj) fixed_t oldheight = mobj->height; UINT8 correctionType = 0; // Don't correct Z position, just gain height - if (mobj->z > mobj->floorz && mobj->z + mobj->height < mobj->ceilingz - && mobj->type != MT_EGGMOBILE_FIRE) + if (mobj->z > mobj->floorz && mobj->z + mobj->height < mobj->ceilingz && + mobj->type != MT_EGGMOBILE_FIRE) correctionType = 1; // Correct Z position by centering else if (mobj->eflags & MFE_VERTICALFLIP) correctionType = 2; // Correct Z position by moving down @@ -6658,8 +6709,10 @@ static void P_MobjSceneryThink(mobj_t *mobj) case MT_MEDIUMBUBBLE: case MT_EXTRALARGEBUBBLE: // start bubble dissipate P_SceneryCheckWater(mobj); + if (P_MobjWasRemoved(mobj)) // bubble was removed by not being in water return; + if (!(mobj->eflags & MFE_UNDERWATER) || (!(mobj->eflags & MFE_VERTICALFLIP) && mobj->z + mobj->height >= mobj->ceilingz) || (mobj->eflags & MFE_VERTICALFLIP && mobj->z <= mobj->floorz) @@ -6910,6 +6963,9 @@ static boolean P_MobjBossThink(mobj_t *mobj) break; } + if (P_MobjWasRemovedCompat(mobj)) + return false; + if (mobj->flags2 & MF2_BOSSFLEE) P_InstaThrust(mobj, mobj->angle, FixedMul(12*FRACUNIT, mobj->scale)); @@ -7097,6 +7153,13 @@ static boolean P_MobjDeadThink(mobj_t *mobj) static boolean P_MobjRegularThink(mobj_t *mobj) { +#define DOITEMSPRING(mo) \ + sector_t *sec2 = P_ThingOnSpecial3DFloor(mo); \ + if ((sec2 && GETSECSPECIAL(sec2->special, 3) == 1) || \ + (mo->subsector && P_IsObjectOnRealGround(mo, (mo)->subsector->sector) && GETSECSPECIAL(mo->subsector->sector->special, 3) == 1)) { \ + K_DoPogoSpring(mo, 0, 1); \ + } + switch (mobj->type) { case MT_PLAYER: @@ -7143,11 +7206,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj) if (grounded) { - sector_t *sec2 = P_ThingOnSpecial3DFloor(mobj); - if ((sec2 && GETSECSPECIAL(sec2->special, 3) == 1) - || (P_IsObjectOnRealGround(mobj, mobj->subsector->sector) - && GETSECSPECIAL(mobj->subsector->sector->special, 3) == 1)) - K_DoPogoSpring(mobj, 0, 1); + DOITEMSPRING(mobj); } if (mobj->threshold > 0) @@ -7160,7 +7219,6 @@ static boolean P_MobjRegularThink(mobj_t *mobj) } case MT_JAWZ: { - sector_t *sec2; fixed_t topspeed = mobj->movefactor; fixed_t distbarrier = 512*mapobjectscale; fixed_t distaway; @@ -7212,17 +7270,14 @@ static boolean P_MobjRegularThink(mobj_t *mobj) K_DriftDustHandling(mobj); - sec2 = P_ThingOnSpecial3DFloor(mobj); - if ((sec2 && GETSECSPECIAL(sec2->special, 3) == 1) - || (P_IsObjectOnRealGround(mobj, mobj->subsector->sector) - && GETSECSPECIAL(mobj->subsector->sector->special, 3) == 1)) - K_DoPogoSpring(mobj, 0, 1); + DOITEMSPRING(mobj); break; } case MT_JAWZ_DUD: { boolean grounded = P_IsObjectOnGround(mobj); + if (mobj->flags2 & MF2_AMBUSH) { if (grounded && (mobj->flags & MF_NOCLIPTHING)) @@ -7242,11 +7297,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj) if (grounded) { - sector_t *sec2 = P_ThingOnSpecial3DFloor(mobj); - if ((sec2 && GETSECSPECIAL(sec2->special, 3) == 1) - || (P_IsObjectOnRealGround(mobj, mobj->subsector->sector) - && GETSECSPECIAL(mobj->subsector->sector->special, 3) == 1)) - K_DoPogoSpring(mobj, 0, 1); + DOITEMSPRING(mobj); } if (mobj->threshold > 0) @@ -7275,7 +7326,9 @@ static boolean P_MobjRegularThink(mobj_t *mobj) mobj->friction = ORIG_FRICTION/4; if (mobj->momx || mobj->momy) + { P_SpawnGhostMobj(mobj); + } if (grounded && mobj->health > 1) { @@ -7300,20 +7353,31 @@ static boolean P_MobjRegularThink(mobj_t *mobj) indirectitemcooldown = 20*TICRATE; /* FALLTHRU */ case MT_BALLHOG: - P_SpawnGhostMobj(mobj)->fuse = 3; - if (mobj->threshold > 0) - mobj->threshold--; - break; + { + mobj_t *ghost = P_SpawnGhostMobj(mobj); + if (ghost) + ghost->fuse = 3; + + if (mobj->threshold > 0) + mobj->threshold--; + + break; + } case MT_SINK: if (mobj->momx || mobj->momy) + { P_SpawnGhostMobj(mobj); + } + if (P_IsObjectOnGround(mobj)) { S_StartSound(mobj, mobj->info->deathsound); P_SetMobjState(mobj, S_NULL); } + if (mobj->threshold > 0) mobj->threshold--; + break; case MT_SSMINE: if (mobj->target && mobj->target->player) @@ -7322,7 +7386,9 @@ static boolean P_MobjRegularThink(mobj_t *mobj) mobj->color = SKINCOLOR_KETCHUP; if (mobj->momx || mobj->momy) + { P_SpawnGhostMobj(mobj); + } if (P_IsObjectOnGround(mobj) && (mobj->state == &states[S_SSMINE_AIR1] || mobj->state == &states[S_SSMINE_AIR2])) { @@ -7874,7 +7940,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj) { cur->angle += FixedAngle(mobj->info->speed); P_MoveOrigin(cur, mobj->x + FINECOSINE((cur->angle*8)>>ANGLETOFINESHIFT), - mobj->y + FINESINE((cur->angle*8)>>ANGLETOFINESHIFT), mobj->z); + mobj->y + FINESINE((cur->angle*8)>>ANGLETOFINESHIFT), mobj->z); //P_SpawnGhostMobj(cur)->tics = 2; cur = cur->hnext; @@ -8318,6 +8384,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj) case MT_TUMBLEGEM: case MT_TUMBLECOIN: mobj->friction = 95*FRACUNIT/100; + if ((((statenum_t)(mobj->state-states)) == mobj->info->seestate) && abs(mobj->momx) < mobj->scale && abs(mobj->momy) < mobj->scale && P_IsObjectOnGround(mobj)) { @@ -8439,6 +8506,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj) fixed_t shortest = 1024*FRACUNIT; INT32 i; P_SetTarget(&mobj->target, NULL); + for (i = 0; i < MAXPLAYERS; i++) { if (!playeringame[i] || !players[i].mo) @@ -8702,20 +8770,29 @@ static boolean P_MobjRegularThink(mobj_t *mobj) case MT_BLUEBALL: case MT_REDTEAMRING: case MT_BLUETEAMRING: + if (P_MobjWasRemovedCompat(mobj)) + return false; + // No need to check water. Who cares? P_RingThinker(mobj); + if (mobj->flags2 & MF2_NIGHTSPULL) P_NightsItemChase(mobj); else A_AttractChase(mobj); + return false; // Flung items case MT_FLINGRING: case MT_FLINGCOIN: + if (P_MobjWasRemovedCompat(mobj)) + break; + if (mobj->flags2 & MF2_NIGHTSPULL) P_NightsItemChase(mobj); else A_AttractChase(mobj); + break; case MT_NIGHTSWING: if (mobj->flags2 & MF2_NIGHTSPULL) @@ -8760,6 +8837,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj) mobj_t *mo2; z = mobj->subsector->sector->floorheight + FixedMul(64*FRACUNIT, mobj->scale); + for (j = 0; j < 2; j++) { for (i = 0; i < 32; i++) @@ -8777,6 +8855,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj) z -= FixedMul(32*FRACUNIT, mobj->scale); } + P_SetMobjState(mobj, mobj->info->deathstate); mobj->health = 0; mobj->flags2 &= ~MF2_FIRING; @@ -9165,21 +9244,23 @@ void P_MobjThinker(mobj_t *mobj) if (mobj->scale != mobj->destscale) P_MobjScaleThink(mobj); // Slowly scale up/down to reach your destscale. - if (mobj->type == MT_GHOST && mobj->fuse > 0 // Not guaranteed to be MF_SCENERY or not MF_SCENERY! - && (signed)((mobj->frame & FF_TRANSMASK) >> FF_TRANSSHIFT) < (NUMTRANSMAPS-1) - mobj->fuse / 2) - // fade out when nearing the end of fuse... - mobj->frame = (mobj->frame & ~FF_TRANSMASK) | (((NUMTRANSMAPS-1) - mobj->fuse / 2) << FF_TRANSSHIFT); - - // Special thinker for scenery objects - if (mobj->flags & MF_SCENERY && !mobj->player) - { - P_MobjSceneryThink(mobj); - return; - } - - // Check for a Lua thinker first if (!mobj->player) { + if (mobj->type == MT_GHOST && mobj->fuse > 0 // Not guaranteed to be MF_SCENERY or not MF_SCENERY! + && (signed)((mobj->frame & FF_TRANSMASK) >> FF_TRANSSHIFT) < (NUMTRANSMAPS-1) - mobj->fuse / 2) + { + // fade out when nearing the end of fuse... + mobj->frame = (mobj->frame & ~FF_TRANSMASK) | (((NUMTRANSMAPS-1) - mobj->fuse / 2) << FF_TRANSSHIFT); + } + + // Special thinker for scenery objects + if (mobj->flags & MF_SCENERY) + { + P_MobjSceneryThink(mobj); + return; + } + + // Check for a Lua thinker first if (LUA_HookMobj(mobj, MOBJ_HOOK(MobjThinker)) || P_MobjWasRemoved(mobj)) return; } @@ -9224,8 +9305,10 @@ void P_MobjThinker(mobj_t *mobj) { if (leveltime % mobj->health) return; + if (mobj->info->seesound) S_StartSound(mobj, mobj->info->seesound); + return; } @@ -9238,13 +9321,14 @@ void P_MobjThinker(mobj_t *mobj) if (mobj->momx || mobj->momy || (mobj->flags2 & MF2_SKULLFLY)) { P_XYMovement(mobj); + if (P_MobjWasRemoved(mobj)) return; } // always do the gravity bit now, that's simpler // BUT CheckPosition only if wasn't done before. - if (!(mobj->eflags & MFE_ONGROUND) || mobj->momz + if ( !(mobj->eflags & MFE_ONGROUND) || mobj->momz || ((mobj->eflags & MFE_VERTICALFLIP) && mobj->z + mobj->height != mobj->ceilingz) || (!(mobj->eflags & MFE_VERTICALFLIP) && mobj->z != mobj->floorz) || P_IsObjectInGoop(mobj)) @@ -9281,8 +9365,8 @@ void P_MobjThinker(mobj_t *mobj) P_ButteredSlope(mobj); } - if (mobj->flags & (MF_ENEMY|MF_BOSS) && mobj->health - && P_CheckDeathPitCollide(mobj)) // extra pit check in case these didn't have momz + if (mobj->flags & (MF_ENEMY|MF_BOSS) && mobj->health && + P_CheckDeathPitCollide(mobj)) // extra pit check in case these didn't have momz { P_KillMobj(mobj, NULL, NULL); return; @@ -9291,9 +9375,9 @@ void P_MobjThinker(mobj_t *mobj) // Crush enemies! if (mobj->ceilingz - mobj->floorz < mobj->height) { - if (((mobj->flags & (MF_ENEMY|MF_BOSS) && mobj->flags & MF_SHOOTABLE) || mobj->type == MT_EGGSHIELD) - && !(mobj->flags & MF_NOCLIPHEIGHT) - && mobj->health > 0) + if (((mobj->flags & (MF_ENEMY|MF_BOSS) && mobj->flags & MF_SHOOTABLE) || mobj->type == MT_EGGSHIELD) && + !(mobj->flags & MF_NOCLIPHEIGHT) && + mobj->health > 0) { P_KillMobj(mobj, NULL, NULL); return; @@ -9310,12 +9394,7 @@ void P_MobjThinker(mobj_t *mobj) return; if ((mobj->health == 0) && // Fading tile - (mobj->type == MT_BOUNCEPICKUP - || mobj->type == MT_RAILPICKUP - || mobj->type == MT_AUTOPICKUP - || mobj->type == MT_EXPLODEPICKUP - || mobj->type == MT_SCATTERPICKUP - || mobj->type == MT_GRENADEPICKUP)) + (mobj->type >= MT_BOUNCEPICKUP && mobj->type <= MT_GRENADEPICKUP)) { INT32 value = mobj->info->damage/10; value = mobj->fuse/value; @@ -9343,6 +9422,7 @@ boolean P_RailThinker(mobj_t *mobj) if (mobj->momx || mobj->momy) { P_XYMovement(mobj); + if (P_MobjWasRemoved(mobj)) return true; } @@ -10183,39 +10263,51 @@ void P_RemoveMobj(mobj_t *mobj) LUA_HookMobj(mobj, MOBJ_HOOK(MobjRemoved)); mobj->thinker.function = (actionf_p1)P_MobjThinker; // needed for P_UnsetThingPosition, etc. to work. - if (mobj->type == MT_SHADOW) - P_RemoveShadow(mobj); - else if (mobj->type == MT_SPB) - spbplace = -1; - else if (mobj->type == MT_OVERLAY) - P_RemoveOverlay(mobj); - else if (mobj->type == MT_KARMAHITBOX) // Remove linked list objects for certain types + switch (mobj->type) { - mobj_t *cur = mobj->hnext; + case MT_SHADOW: + P_RemoveShadow(mobj); + break; + case MT_OVERLAY: + P_RemoveOverlay(mobj); + break; + case MT_SPB: + spbplace = -1; + break; + case MT_KARMAHITBOX: // Remove linked list objects for certain types + { + mobj_t *cur = mobj->hnext; - while (!P_MobjWasRemoved(cur)) - { - mobj_t *prev = cur; // Kind of a dumb var, but we need to set cur before we remove the mobj - cur = cur->hnext; - P_RemoveMobj(prev); - } - } - // Rings only, please! - else if (mobj->spawnpoint && - !(mobj->flags2 & MF2_DONTRESPAWN) && - (mobj->type == MT_RING - || mobj->type == MT_COIN - || mobj->type == MT_BLUEBALL - || mobj->type == MT_REDTEAMRING - || mobj->type == MT_BLUETEAMRING - || P_WeaponOrPanel(mobj->type))) - { - itemrespawnque[iquehead] = mobj->spawnpoint; - itemrespawntime[iquehead] = leveltime; - iquehead = (iquehead+1)&(ITEMQUESIZE-1); - // lose one off the end? - if (iquehead == iquetail) - iquetail = (iquetail+1)&(ITEMQUESIZE-1); + while (!P_MobjWasRemoved(cur)) + { + mobj_t *prev = cur; // Kind of a dumb var, but we need to set cur before we remove the mobj + cur = cur->hnext; + P_RemoveMobj(prev); + } + } + break; + default: + { + // Rings only, please! + if (mobj->spawnpoint == NULL) + break; + + if (mobj->flags2 & MF2_DONTRESPAWN) + break; + + if (mobj->type == MT_BLUEBALL + || P_RingOrCoin(mobj->type) + || P_WeaponOrPanel(mobj->type)) + { + itemrespawnque[iquehead] = mobj->spawnpoint; + itemrespawntime[iquehead] = leveltime; + iquehead = (iquehead+1)&(ITEMQUESIZE-1); + // lose one off the end? + if (iquehead == iquetail) + iquetail = (iquetail+1)&(ITEMQUESIZE-1); + } + } + break; } mobj->health = 0; // Just because @@ -10312,6 +10404,7 @@ void P_RemoveSavegameMobj(mobj_t *mobj) // stop any playing sound S_StopSound(mobj); + R_RemoveMobjInterpolator(mobj); // just set its reference count to 0 to not trigger the assert in P_UnlinkThinker @@ -10568,6 +10661,59 @@ void CalculateDoomednumToMobjtype(void) } } +static mobjtype_t P_GetMobjtype(UINT16 mthingtype) +{ + mobjtype_t i = g_doomednum_to_mobjtype[mthingtype]; + + if (i <= MT_NULL || i >= NUMMOBJTYPES) + { + i = MT_UNKNOWN; + } + + return i; +} + +static void P_RespawnBattleBoxes(void) +{ + thinker_t *th; + + for (th = thinkercap.next; th != &thinkercap; th = th->next) + { + mobj_t *box; + mobj_t *newmobj; + + if (th->function != (actionf_p1)P_MobjThinker) // not a mobj + continue; + + box = (mobj_t *)th; + + if (box->type != MT_RANDOMITEM || box->threshold != 68 || box->fuse) // only popped items + continue; + + // Respawn from mapthing if you have one! + if (box->spawnpoint) + { + P_SpawnMapThing(box->spawnpoint); + newmobj = box->spawnpoint->mobj; // this is set to the new mobj in P_SpawnMapThing + P_SpawnMobj(box->spawnpoint->mobj->x, box->spawnpoint->mobj->y, box->spawnpoint->mobj->z, MT_EXPLODE); // poof into existance + } + else + { + newmobj = P_SpawnMobj(box->x, box->y, box->z, box->type); + P_SpawnMobj(newmobj->x, newmobj->y, newmobj->z, MT_EXPLODE); // poof into existance + } + + // Transfer flags2 (strongbox, objectflip) + newmobj->flags2 = box->flags2; + P_RemoveMobj(box); // make sure they disappear + numgotboxes--; // you've restored a box, remove it from the count + //continue; -- irrelevant? + } + + if (numgotboxes < 0) + numgotboxes = 0; +} + // // P_RespawnSpecials // @@ -10580,43 +10726,7 @@ void P_RespawnSpecials(void) if (G_BattleGametype() && numgotboxes >= (4*nummapboxes/5)) // Battle Mode respawns all boxes in a different way { - thinker_t *th; - - for (th = thinkercap.next; th != &thinkercap; th = th->next) - { - mobj_t *box; - mobj_t *newmobj; - - if (th->function != (actionf_p1)P_MobjThinker) // not a mobj - continue; - - box = (mobj_t *)th; - - if (box->type != MT_RANDOMITEM || box->threshold != 68 || box->fuse) // only popped items - continue; - - // Respawn from mapthing if you have one! - if (box->spawnpoint) - { - P_SpawnMapThing(box->spawnpoint); - newmobj = box->spawnpoint->mobj; // this is set to the new mobj in P_SpawnMapThing - P_SpawnMobj(box->spawnpoint->mobj->x, box->spawnpoint->mobj->y, box->spawnpoint->mobj->z, MT_EXPLODE); // poof into existance - } - else - { - newmobj = P_SpawnMobj(box->x, box->y, box->z, box->type); - P_SpawnMobj(newmobj->x, newmobj->y, newmobj->z, MT_EXPLODE); // poof into existance - } - - // Transfer flags2 (strongbox, objectflip) - newmobj->flags2 = box->flags2; - P_RemoveMobj(box); // make sure they disappear - numgotboxes--; // you've restored a box, remove it from the count - //continue; -- irrelevant? - } - - if (numgotboxes < 0) - numgotboxes = 0; + P_RespawnBattleBoxes(); } // only respawn items when cv_itemrespawn is on @@ -10646,10 +10756,8 @@ void P_RespawnSpecials(void) y = mthing->y << FRACBITS; ss = R_PointInSubsector(x, y); - // find which type to spawn - i = g_doomednum_to_mobjtype[mthing->type]; - - if (i <= MT_NULL || i >= NUMMOBJTYPES) // prevent creation of objects with this type -- Monster Iestyn 17/12/17 + i = P_GetMobjtype(mthing->type); + if (i == MT_UNKNOWN) { // 3D Mode start Thing is unlikely to be added to the que, // so don't bother checking for that specific type @@ -10671,7 +10779,7 @@ void P_RespawnSpecials(void) z = P_GetSectorCeilingZAt(ss->sector, x, y) - (mthing->options >> ZSHIFT) * FRACUNIT; if (mthing->options & MTF_AMBUSH - && (i == MT_RING || i == MT_REDTEAMRING || i == MT_BLUETEAMRING || i == MT_COIN || P_WeaponOrPanel(i))) + && (P_RingOrCoin(i) || P_WeaponOrPanel(i))) z -= 24*FRACUNIT; z -= mobjinfo[i].height; // Don't forget the height! } @@ -10680,7 +10788,7 @@ void P_RespawnSpecials(void) z = P_GetSectorFloorZAt(ss->sector, x, y) + (mthing->options >> ZSHIFT) * FRACUNIT; if (mthing->options & MTF_AMBUSH - && (i == MT_RING || i == MT_REDTEAMRING || i == MT_BLUETEAMRING || i == MT_COIN || P_WeaponOrPanel(i))) + && (P_RingOrCoin(i) || P_WeaponOrPanel(i))) z += 24*FRACUNIT; } @@ -11066,584 +11174,260 @@ void P_MovePlayerToStarpost(INT32 playernum) P_AfterPlayerSpawn(playernum); } -#define MAXHUNTEMERALDS 64 -mapthing_t *huntemeralds[MAXHUNTEMERALDS] = {}; -INT32 numhuntemeralds = 0; - -// -// P_SpawnMapThing -// The fields of the mapthing should -// already be in host byte order. -// -void P_SpawnMapThing(mapthing_t *mthing) +static boolean P_SetupMace(mapthing_t *mthing, mobj_t *mobj) { - mobjtype_t i = MT_NULL; - mobj_t *mobj; - fixed_t x, y, z; - subsector_t *ss; + fixed_t mlength, mspeed, mxspeed, mzspeed, mstartangle, mmaxspeed; + mobjtype_t chainlink = MT_SMALLMACECHAIN; + mobjtype_t macetype = MT_SMALLMACE; + boolean firsttime; + mobj_t *spawnee; + size_t line; + const size_t mthingi = (size_t)(mthing - mapthings); - if (!mthing->type) - return; // Ignore type-0 things as NOPs - - // Always spawn in objectplace. - // Skip all returning code. - if (objectplacing) + // Why does P_FindSpecialLineFromTag not work here?!? + // Monster Iestyn: tag lists haven't been initialised yet for the map, that's why + for (line = 0; line < numlines; line++) { - // find which type to spawn - i = g_doomednum_to_mobjtype[mthing->type]; - - if (i <= MT_NULL || i >= NUMMOBJTYPES) - { - if (mthing->type == 3328) // 3D Mode start Thing - return; - CONS_Alert(CONS_WARNING, M_GetText("Unknown thing type %d placed at (%d, %d)\n"), mthing->type, mthing->x, mthing->y); - i = MT_UNKNOWN; - } - goto noreturns; - } - - // count deathmatch start positions - switch (mthing->type) - { - case 33: - if (numdmstarts < MAX_DM_STARTS) - { - deathmatchstarts[numdmstarts] = mthing; - mthing->type = 0; - numdmstarts++; - } - return; - case 34: // Red CTF Starts - if (numredctfstarts < MAXPLAYERS) - { - redctfstarts[numredctfstarts] = mthing; - mthing->type = 0; - numredctfstarts++; - } - return; - case 35: // Blue CTF Starts - if (numbluectfstarts < MAXPLAYERS) - { - bluectfstarts[numbluectfstarts] = mthing; - mthing->type = 0; - numbluectfstarts++; - } - return; - case 300: // Ring - case 308: - case 309: // Team Rings - case 600 ... 609: // Placement patterns - case 750: // Slope vertex point (formerly chaos spawn) - case 1705: - case 1706: // Nights Wing - case 1713: // NiGHTS Hoops - case 1800: // Mario Coin - return; // Don't spawn hoops, wings, or rings yet! - default: + if (lines[line].special == 9 && lines[line].tag == mthing->angle) break; } - // check for players specially - if (mthing->type > 0 && mthing->type <= 32) + if (line == numlines) { - if (mthing->type > MAXPLAYERS) // be wary of playerstarts size! playerstarts[MAXPLAYERS] - { - CONS_Alert(CONS_ERROR, "Excess player start detected %d This will crash vanilla clients!\n", mthing->type); - } - else - { - // save spots for respawning in network games - playerstarts[mthing->type-1] = mthing; - } - - return; + CONS_Debug(DBG_GAMELOGIC, "Mace chain (mapthing #%s) needs tagged to a #9 parameter line (trying to find tag %d).\n", sizeu1(mthingi), mthing->angle); + return false; } - - // find which type to spawn - i = g_doomednum_to_mobjtype[mthing->type]; - - if (i <= MT_NULL || i >= NUMMOBJTYPES) - { - if (mthing->type == 3328) // 3D Mode start Thing - return; - - CONS_Alert(CONS_WARNING, M_GetText("Unknown thing type %d placed at (%d, %d)\n"), mthing->type, mthing->x, mthing->y); - - i = MT_UNKNOWN; - } - - if (i >= MT_EMERALD1 && i <= MT_EMERALD7) // Pickupable Emeralds - { - if (gametype != GT_COOP) // Don't place emeralds in non-coop modes - return; - - if (emeralds & mobjinfo[i].speed) // You already have this emerald! - return; - } - - if (!G_BattleGametype() || !cv_specialrings.value) - { - if (P_WeaponOrPanel(i)) - return; // Don't place weapons/panels in non-ringslinger modes - } - - if (i == MT_EMERHUNT) - { - // Emerald Hunt is Coop only. - if (gametype != GT_COOP) - return; - - ss = R_PointInSubsector((mthing->x << FRACBITS), (mthing->y << FRACBITS)); - mthing->z = (INT16)((P_GetSectorFloorZAt(ss->sector, (mthing->x << FRACBITS), (mthing->y << FRACBITS)) >> FRACBITS) + (mthing->options >> ZSHIFT)); - - if (numhuntemeralds < MAXHUNTEMERALDS) - huntemeralds[numhuntemeralds++] = mthing; - return; - } - - if (i == MT_EMERALDSPAWN) - { - if (!cv_powerstones.value || !G_BattleGametype()) - return; - } - - if (!G_RaceGametype()) // No enemies in match or CTF modes - { - if ((mobjinfo[i].flags & MF_ENEMY) || (mobjinfo[i].flags & MF_BOSS)) - return; - } - - // Set powerup boxes to user settings for competition. - if (gametype == GT_COMPETITION && cv_competitionboxes.value && (mobjinfo[i].flags & MF_MONITOR)) // not Normal - { - switch (cv_competitionboxes.value) - { - case 1: // Random - i = MT_QUESTIONBOX; - break; - case 2: // Teleports - i = MT_MIXUPBOX; - break; - case 3: // None - return; // Don't spawn! - default: - break; - } - } - // Set powerup boxes to user settings for other netplay modes - else if (gametype != GT_COOP && cv_matchboxes.value && (mobjinfo[i].flags & MF_MONITOR)) // not Normal - { - switch (cv_matchboxes.value) - { - case 1: // Random - i = MT_QUESTIONBOX; - break; - case 3: // None - return; // Don't spawn! - default: - if (i == MT_QUESTIONBOX) - return; // don't spawn in Non-Random - mthing->options &= ~(MTF_AMBUSH|MTF_OBJECTSPECIAL); // no random respawning! - break; - } - } - - if (gametype != GT_CTF) // CTF specific things - { - switch (i) - { - case MT_BLUETEAMRING: - case MT_REDTEAMRING: - i = MT_RING; - break; - case MT_BLUERINGBOX: - case MT_REDRINGBOX: - i = MT_SUPERRINGBOX; - break; - case MT_BLUEFLAG: - case MT_REDFLAG: - return; // No flags in non-CTF modes! - default: - break; - } - } - else - { - if ((i == MT_BLUEFLAG && blueflag) || (i == MT_REDFLAG && redflag)) - { - CONS_Alert(CONS_ERROR, M_GetText("Only one flag per team allowed in CTF!\n")); - return; - } - } - - if (!G_RaceGametype() && (i == MT_SIGN || i == MT_STARPOST)) - return; // Don't spawn exit signs or starposts in wrong game modes - - if (modeattacking) // Record Attack special stuff - { - // Emerald Tokens -->> Score Tokens - if (i == MT_EMMY) - return; /// \todo - - // 1UPs -->> Score TVs - else if (i == MT_PRUP) // 1UP - { - // Either or, doesn't matter which. - if (mthing->options & (MTF_AMBUSH|MTF_OBJECTSPECIAL)) - i = MT_SCORETVLARGE; // 10,000 - else - i = MT_SCORETVSMALL; // 1,000 - } - } - - if (i == MT_EMMY && (gametype != GT_COOP || tokenbits == 30 || tokenlist & (1 << tokenbits++))) - return; // you already got this token, or there are too many, or the gametype's not right - - // Objectplace landing point - noreturns: - - // spawn it - x = mthing->x << FRACBITS; - y = mthing->y << FRACBITS; - ss = R_PointInSubsector(x, y); - - if (i == MT_NIGHTSBUMPER) - z = P_GetSectorFloorZAt(ss->sector, x, y) + ((mthing->options >> ZSHIFT) << FRACBITS); - else if (i == MT_AXIS || i == MT_AXISTRANSFER || i == MT_AXISTRANSFERLINE) - z = ONFLOORZ; - else if (i == MT_SPECIALSPIKEBALL || P_WeaponOrPanel(i) || i == MT_EMERALDSPAWN || i == MT_EMMY) - { - if (mthing->options & MTF_OBJECTFLIP) - { - z = P_GetSectorCeilingZAt(ss->sector, x, y); - - if (mthing->options & MTF_AMBUSH) // Special flag for rings - z -= 24*FRACUNIT; - if (mthing->options >> ZSHIFT) - z -= (mthing->options >> ZSHIFT)*FRACUNIT; - - z -= mobjinfo[i].height; //Don't forget the height! - } - else - { - z = P_GetSectorFloorZAt(ss->sector, x, y); - - if (mthing->options & MTF_AMBUSH) // Special flag for rings - z += 24*FRACUNIT; - if (mthing->options >> ZSHIFT) - z += (mthing->options >> ZSHIFT)*FRACUNIT; - } - - if (z == ONFLOORZ) - mthing->z = 0; - else - mthing->z = (INT16)(z>>FRACBITS); - } - else - { - fixed_t offset = 0; - boolean flip = (!!(mobjinfo[i].flags & MF_SPAWNCEILING) ^ !!(mthing->options & MTF_OBJECTFLIP)); - - // base positions - if (flip) - z = P_GetSectorCeilingZAt(ss->sector, x, y) - mobjinfo[i].height; - else - z = P_GetSectorFloorZAt(ss->sector, x, y); - - // offsetting - if (mthing->options >> ZSHIFT) - offset = ((mthing->options >> ZSHIFT) << FRACBITS); - else switch (i) - { - case MT_CRAWLACOMMANDER: - case MT_DETON: - case MT_JETTBOMBER: - case MT_JETTGUNNER: - case MT_EGGMOBILE2: - offset = 33*FRACUNIT; - break; - case MT_EGGMOBILE: - offset = 128*FRACUNIT; - break; - case MT_GOLDBUZZ: - case MT_REDBUZZ: - offset = 288*FRACUNIT; - break; - default: - break; - } - - // applying offsets! (if any) - if (flip) - { - if (offset) - z -= offset; - else - z = ONCEILINGZ; - } - else - { - if (offset) - z += offset; - else - z = ONFLOORZ; - } - - if (z == ONFLOORZ) - mthing->z = 0; - else - mthing->z = (INT16)(z>>FRACBITS); - } - - mobj = P_SpawnMobj(x, y, z, i); - - if (P_MobjWasRemoved(mobj)) - { - CONS_Alert(CONS_ERROR, "Failed to spawn map thing #%d at %d, %d. This will crash vanilla clients!\n", mthing->type, x>>FRACBITS, y>>FRACBITS); - return; - } - - mobj->spawnpoint = mthing; - - switch(mobj->type) - { - case MT_SKYBOX: - mobj->angle = 0; - if (mthing->options & MTF_OBJECTSPECIAL) - skyboxmo[1] = mobj; - else - skyboxmo[0] = mobj; - break; - case MT_FAN: - if (mthing->options & MTF_OBJECTSPECIAL) - { - P_UnsetThingPosition(mobj); - if (sector_list) - { - P_DelSeclist(sector_list); - sector_list = NULL; - } - mobj->flags |= MF_NOSECTOR; // this flag basically turns it invisible - P_SetThingPosition(mobj); - } - if (mthing->angle) - mobj->health = mthing->angle; - else - mobj->health = FixedMul(ss->sector->ceilingheight-ss->sector->floorheight, 3*(FRACUNIT/4))>>FRACBITS; - break; - case MT_WATERDRIP: - if (mthing->angle) - mobj->tics = 3*TICRATE + mthing->angle; - else - mobj->tics = 3*TICRATE; - break; - case MT_FLAMEJET: - case MT_VERTICALFLAMEJET: - mobj->threshold = (mthing->angle >> 10) & 7; - mobj->movecount = (mthing->angle >> 13); - - mobj->threshold *= (TICRATE/2); - mobj->movecount *= (TICRATE/2); - - mobj->movedir = mthing->extrainfo; - break; - case MT_MACEPOINT: - case MT_SWINGMACEPOINT: - case MT_HANGMACEPOINT: - case MT_SPINMACEPOINT: - { - fixed_t mlength, mspeed, mxspeed, mzspeed, mstartangle, mmaxspeed; - mobjtype_t chainlink = MT_SMALLMACECHAIN; - mobjtype_t macetype = MT_SMALLMACE; - boolean firsttime; - mobj_t *spawnee; - size_t line; - const size_t mthingi = (size_t)(mthing - mapthings); - - // Why does P_FindSpecialLineFromTag not work here?!? - // Monster Iestyn: tag lists haven't been initialised yet for the map, that's why - for (line = 0; line < numlines; line++) - { - if (lines[line].special == 9 && lines[line].tag == mthing->angle) - break; - } - - if (line == numlines) - { - CONS_Debug(DBG_GAMELOGIC, "Mace chain (mapthing #%s) needs tagged to a #9 parameter line (trying to find tag %d).\n", sizeu1(mthingi), mthing->angle); - return; - } /* No deaf - small mace Deaf - big mace ML_NOCLIMB : Direction not controllable */ - mlength = abs(lines[line].dx >> FRACBITS); - mspeed = abs(lines[line].dy >> FRACBITS); - mxspeed = sides[lines[line].sidenum[0]].textureoffset >> FRACBITS; - mzspeed = sides[lines[line].sidenum[0]].rowoffset >> FRACBITS; - mstartangle = lines[line].frontsector->floorheight >> FRACBITS; - mmaxspeed = lines[line].frontsector->ceilingheight >> FRACBITS; + mlength = abs(lines[line].dx >> FRACBITS); + mspeed = abs(lines[line].dy >> FRACBITS); + mxspeed = sides[lines[line].sidenum[0]].textureoffset >> FRACBITS; + mzspeed = sides[lines[line].sidenum[0]].rowoffset >> FRACBITS; + mstartangle = lines[line].frontsector->floorheight >> FRACBITS; + mmaxspeed = lines[line].frontsector->ceilingheight >> FRACBITS; - mstartangle %= 360; - mxspeed %= 360; - mzspeed %= 360; + mstartangle %= 360; + mxspeed %= 360; + mzspeed %= 360; - CONS_Debug(DBG_GAMELOGIC, "Mace Chain (mapthing #%s):\n" - "Length is %d\n" - "Speed is %d\n" - "Xspeed is %d\n" - "Zspeed is %d\n" - "startangle is %d\n" - "maxspeed is %d\n", - sizeu1(mthingi), mlength, mspeed, mxspeed, mzspeed, mstartangle, mmaxspeed); + CONS_Debug(DBG_GAMELOGIC, "Mace/Chain (mapthing #%s):\n" + "Length is %d\n" + "Speed is %d\n" + "Xspeed is %d\n" + "Zspeed is %d\n" + "startangle is %d\n" + "maxspeed is %d\n", + sizeu1(mthingi), mlength, mspeed, mxspeed, mzspeed, mstartangle, mmaxspeed); - mobj->lastlook = mspeed << 4; - mobj->movecount = mobj->lastlook; - mobj->health = (FixedAngle(mzspeed*FRACUNIT)>>ANGLETOFINESHIFT) + (FixedAngle(mstartangle*FRACUNIT)>>ANGLETOFINESHIFT); - mobj->threshold = (FixedAngle(mxspeed*FRACUNIT)>>ANGLETOFINESHIFT) + (FixedAngle(mstartangle*FRACUNIT)>>ANGLETOFINESHIFT); - mobj->movefactor = mobj->threshold; - mobj->friction = mmaxspeed; + mobj->lastlook = mspeed << 4; + mobj->movecount = mobj->lastlook; + mobj->health = (FixedAngle(mzspeed*FRACUNIT)>>ANGLETOFINESHIFT) + (FixedAngle(mstartangle*FRACUNIT)>>ANGLETOFINESHIFT); + mobj->threshold = (FixedAngle(mxspeed*FRACUNIT)>>ANGLETOFINESHIFT) + (FixedAngle(mstartangle*FRACUNIT)>>ANGLETOFINESHIFT); + mobj->movefactor = mobj->threshold; + mobj->friction = mmaxspeed; - if (lines[line].flags & ML_NOCLIMB) - mobj->flags |= MF_SLIDEME; + if (lines[line].flags & ML_NOCLIMB) + mobj->flags |= MF_SLIDEME; - mobj->reactiontime = 0; + mobj->reactiontime = 0; - if (mthing->options & MTF_AMBUSH) - { - chainlink = MT_BIGMACECHAIN; - macetype = MT_BIGMACE; - } - - if (mthing->options & MTF_OBJECTSPECIAL) - mobj->flags2 |= MF2_BOSSNOTRAP; // shut up maces. - - if (mobj->type == MT_HANGMACEPOINT || mobj->type == MT_SPINMACEPOINT) - firsttime = true; - else - { - firsttime = false; - - spawnee = P_SpawnMobj(mobj->x, mobj->y, mobj->z, macetype); - P_SetTarget(&spawnee->target, mobj); - - if (mobj->type == MT_SWINGMACEPOINT) - spawnee->movecount = FixedAngle(mstartangle*FRACUNIT)>>ANGLETOFINESHIFT; - else - spawnee->movecount = 0; - - spawnee->threshold = FixedAngle(mstartangle*FRACUNIT)>>ANGLETOFINESHIFT; - spawnee->reactiontime = mlength+1; - } - - while (mlength > 0) - { - spawnee = P_SpawnMobj(mobj->x, mobj->y, mobj->z, chainlink); - - P_SetTarget(&spawnee->target, mobj); - - if (mobj->type == MT_HANGMACEPOINT || mobj->type == MT_SWINGMACEPOINT) - spawnee->movecount = FixedAngle(mstartangle*FRACUNIT)>>ANGLETOFINESHIFT; - else - spawnee->movecount = 0; - - spawnee->threshold = FixedAngle(mstartangle*FRACUNIT)>>ANGLETOFINESHIFT; - spawnee->reactiontime = mlength; - - if (firsttime) - { - // This is the outermost link in the chain - spawnee->flags2 |= MF2_AMBUSH; - firsttime = false; - } - - mlength--; - } - break; + if (mthing->options & MTF_AMBUSH) + { + chainlink = MT_BIGMACECHAIN; + macetype = MT_BIGMACE; } - case MT_ROCKSPAWNER: - mobj->threshold = mthing->angle; - mobj->movecount = mthing->extrainfo; - break; - case MT_POPUPTURRET: - if (mthing->angle) - mobj->threshold = mthing->angle; + + if (mthing->options & MTF_OBJECTSPECIAL) + mobj->flags2 |= MF2_BOSSNOTRAP; // shut up maces. + + if (mobj->type == MT_HANGMACEPOINT || mobj->type == MT_SPINMACEPOINT) + firsttime = true; + else + { + firsttime = false; + + spawnee = P_SpawnMobj(mobj->x, mobj->y, mobj->z, macetype); + P_SetTarget(&spawnee->target, mobj); + + if (mobj->type == MT_SWINGMACEPOINT) + spawnee->movecount = FixedAngle(mstartangle*FRACUNIT)>>ANGLETOFINESHIFT; else - mobj->threshold = (TICRATE*2)-1; - break; - case MT_NIGHTSBUMPER: - // Lower 4 bits specify the angle of - // the bumper in 30 degree increments. - mobj->threshold = (mthing->options & 15) % 12; // It loops over, etc - P_SetMobjState(mobj, mobj->info->spawnstate+mobj->threshold); - break; - case MT_EGGCAPSULE: - if (mthing->angle <= 0) - mthing->angle = 20; // prevent 0 health + spawnee->movecount = 0; - mobj->health = mthing->angle; - mobj->threshold = min(mthing->extrainfo, 7); - break; - case MT_TUBEWAYPOINT: - mobj->health = mthing->angle & 255; - mobj->threshold = mthing->angle >> 8; - break; - case MT_NIGHTSDRONE: - if (mthing->angle > 0) - mobj->health = mthing->angle; - break; - case MT_TRAPGOYLE: - case MT_TRAPGOYLEUP: - case MT_TRAPGOYLEDOWN: - case MT_TRAPGOYLELONG: - if (mthing->angle >= 360) - mobj->tics += 7*(mthing->angle / 360) + 1; // starting delay - break; - // SRB2Kart - case MT_BALLOON: - mobj->color = (1 + (mthing->angle % (MAXSKINCOLORS-1))); - break; - case MT_AAZTREE_HELPER: + spawnee->threshold = FixedAngle(mstartangle*FRACUNIT)>>ANGLETOFINESHIFT; + spawnee->reactiontime = mlength+1; + } + + while (mlength > 0) + { + spawnee = P_SpawnMobj(mobj->x, mobj->y, mobj->z, chainlink); + + P_SetTarget(&spawnee->target, mobj); + + if (mobj->type == MT_HANGMACEPOINT || mobj->type == MT_SWINGMACEPOINT) + spawnee->movecount = FixedAngle(mstartangle*FRACUNIT)>>ANGLETOFINESHIFT; + else + spawnee->movecount = 0; + + spawnee->threshold = FixedAngle(mstartangle*FRACUNIT)>>ANGLETOFINESHIFT; + spawnee->reactiontime = mlength; + + if (firsttime) { - fixed_t top = mobj->z; - UINT8 locnumsegs = (mthing->extrainfo)+2; - UINT8 numleaves = max(3, (abs(mthing->angle+1) % 6) + 3); - mobj_t *coconut; - - // Spawn tree segments - for (i = 0; i < locnumsegs; i++) - { - P_SpawnMobj(mobj->x, mobj->y, top, MT_AAZTREE_SEG); - top += FixedMul(mobjinfo[MT_AAZTREE_SEG].height, mobj->scale); - } - - // Big coconut topper - coconut = P_SpawnMobj(mobj->x, mobj->y, top - (8<destscale = (2*mobj->scale))); - - // Spawn all of the papersprite leaves - for (i = 0; i < numleaves; i++) - { - mobj_t *leaf; - - mobj->angle = FixedAngle((i * (360/numleaves))<x + FINECOSINE((mobj->angle>>ANGLETOFINESHIFT) & FINEMASK), - mobj->y + FINESINE((mobj->angle>>ANGLETOFINESHIFT) & FINEMASK), top, MT_AAZTREE_LEAF); - leaf->angle = mobj->angle; - - // Small coconut for each leaf - P_SpawnMobj(mobj->x + (32 * FINECOSINE((mobj->angle>>ANGLETOFINESHIFT) & FINEMASK)), - mobj->y + (32 * FINESINE((mobj->angle>>ANGLETOFINESHIFT) & FINEMASK)), top - (24<flags2 |= MF2_AMBUSH; + firsttime = false; } - default: - break; + + mlength--; + } + + return true; +} + +static boolean P_SetupSpawnedMapThing(mapthing_t *mthing, fixed_t x, fixed_t y, fixed_t z, subsector_t *ss, mobj_t *mobj, mobjtype_t type) +{ + switch (type) + { + case MT_SKYBOX: + mobj->angle = 0; + + if (mthing->options & MTF_OBJECTSPECIAL) + skyboxmo[1] = mobj; + else + skyboxmo[0] = mobj; + + break; + case MT_FAN: + if (mthing->options & MTF_OBJECTSPECIAL) + { + P_UnsetThingPosition(mobj); + if (sector_list) + { + P_DelSeclist(sector_list); + sector_list = NULL; + } + mobj->flags |= MF_NOSECTOR; // this flag basically turns it invisible + P_SetThingPosition(mobj); + } + + if (mthing->angle) + mobj->health = mthing->angle; + else + mobj->health = FixedMul(ss->sector->ceilingheight-ss->sector->floorheight, 3*(FRACUNIT/4))>>FRACBITS; + + break; + case MT_WATERDRIP: + if (mthing->angle) + mobj->tics = 3*TICRATE + mthing->angle; + else + mobj->tics = 3*TICRATE; + break; + case MT_FLAMEJET: + case MT_VERTICALFLAMEJET: + mobj->threshold = (mthing->angle >> 10) & 7; + mobj->movecount = (mthing->angle >> 13); + + mobj->threshold *= (TICRATE/2); + mobj->movecount *= (TICRATE/2); + + mobj->movedir = mthing->extrainfo; + break; + case MT_MACEPOINT: + case MT_SWINGMACEPOINT: + case MT_HANGMACEPOINT: + case MT_SPINMACEPOINT: + if (!P_SetupMace(mthing, mobj)) + return false; + break; + case MT_ROCKSPAWNER: + mobj->threshold = mthing->angle; + mobj->movecount = mthing->extrainfo; + break; + case MT_POPUPTURRET: + if (mthing->angle) + mobj->threshold = mthing->angle; + else + mobj->threshold = (TICRATE*2)-1; + break; + case MT_NIGHTSBUMPER: + // Lower 4 bits specify the angle of + // the bumper in 30 degree increments. + mobj->threshold = (mthing->options & 15) % 12; // It loops over, etc + P_SetMobjState(mobj, mobj->info->spawnstate+mobj->threshold); + break; + case MT_EGGCAPSULE: + if (mthing->angle <= 0) + mthing->angle = 20; // prevent 0 health + + mobj->health = mthing->angle; + mobj->threshold = min(mthing->extrainfo, 7); + break; + case MT_TUBEWAYPOINT: + mobj->health = mthing->angle & 255; + mobj->threshold = mthing->angle >> 8; + break; + case MT_NIGHTSDRONE: + if (mthing->angle > 0) + mobj->health = mthing->angle; + break; + case MT_TRAPGOYLE: + case MT_TRAPGOYLEUP: + case MT_TRAPGOYLEDOWN: + case MT_TRAPGOYLELONG: + if (mthing->angle >= 360) + mobj->tics += 7*(mthing->angle / 360) + 1; // starting delay + break; + // SRB2Kart + case MT_BALLOON: + mobj->color = (1 + (mthing->angle % (MAXSKINCOLORS-1))); + break; + case MT_AAZTREE_HELPER: + { + UINT8 i; + fixed_t top = mobj->z; + UINT8 locnumsegs = (mthing->extrainfo)+2; + UINT8 numleaves = max(3, (abs(mthing->angle+1) % 6) + 3); + mobj_t *coconut; + + // Spawn tree segments + for (i = 0; i < locnumsegs; i++) + { + P_SpawnMobj(mobj->x, mobj->y, top, MT_AAZTREE_SEG); + top += FixedMul(mobjinfo[MT_AAZTREE_SEG].height, mobj->scale); + } + + // Big coconut topper + coconut = P_SpawnMobj(mobj->x, mobj->y, top - (8<destscale = (2*mobj->scale))); + + // Spawn all of the papersprite leaves + for (i = 0; i < numleaves; i++) + { + mobj_t *leaf; + + mobj->angle = FixedAngle((i * (360/numleaves))<x + FINECOSINE((mobj->angle>>ANGLETOFINESHIFT) & FINEMASK), + mobj->y + FINESINE((mobj->angle>>ANGLETOFINESHIFT) & FINEMASK), top, MT_AAZTREE_LEAF); + + leaf->angle = mobj->angle; + + // Small coconut for each leaf + P_SpawnMobj(mobj->x + (32 * FINECOSINE((mobj->angle>>ANGLETOFINESHIFT) & FINEMASK)), + mobj->y + (32 * FINESINE((mobj->angle>>ANGLETOFINESHIFT) & FINEMASK)), top - (24<flags & MF_BOSS) @@ -11652,179 +11436,207 @@ ML_NOCLIMB : Direction not controllable mobj->flags2 |= MF2_BOSSNOTRAP; } - if (i == MT_AXIS || i == MT_AXISTRANSFER || i == MT_AXISTRANSFERLINE) // Axis Points + switch (type) { - // Mare it belongs to - mobj->threshold = min(mthing->extrainfo, 7); - - // # in the mare - mobj->health = mthing->options; - - mobj->flags2 |= MF2_AXIS; - - if (i == MT_AXIS) - { - // Inverted if uppermost bit is set - if (mthing->angle & 16384) - mobj->flags2 |= MF2_AMBUSH; - - if (mthing->angle > 0) - mobj->radius = (mthing->angle & 16383)*FRACUNIT; - } - } - else if (i == MT_EMMY) - { - if (mthing->options & MTF_OBJECTSPECIAL) // Mario Block version - mobj->flags &= ~(MF_NOGRAVITY|MF_NOCLIPHEIGHT); - else - { - fixed_t zheight = mobj->z; - mobj_t *tokenobj; - - if (mthing->options & MTF_OBJECTFLIP) - zheight += mobj->height-FixedMul(mobjinfo[MT_TOKEN].height, mobj->scale); // align with emmy properly! - - tokenobj = P_SpawnMobj(x, y, zheight, MT_TOKEN); - P_SetTarget(&mobj->tracer, tokenobj); - tokenobj->destscale = mobj->scale; - P_SetScale(tokenobj, mobj->scale); - if (mthing->options & MTF_OBJECTFLIP) // flip token to match emmy + case MT_STARPOST: { - tokenobj->eflags |= MFE_VERTICALFLIP; - tokenobj->flags2 |= MF2_OBJECTFLIP; + thinker_t *th; + mobj_t *mo2; + boolean foundanother = false; + mobj->health = (mthing->angle / 360) + 1; + + // See if other starposts exist in this level that have the same value. + for (th = thinkercap.next; th != &thinkercap; th = th->next) + { + if (th->function != (actionf_p1)P_MobjThinker) + continue; + + mo2 = (mobj_t *)th; + + if (mo2 == mobj) + continue; + + if (mo2->type == MT_STARPOST && mo2->health == mobj->health) + { + foundanother = true; + break; + } + } + + if (!foundanother) + numstarposts++; } - } - - // We advanced tokenbits earlier due to the return check. - // Subtract 1 here for the correct value. - mobj->health = 1 << (tokenbits - 1); - } - else if (i == MT_CYBRAKDEMON && mthing->options & MTF_AMBUSH) - { - mobj_t *elecmobj; - elecmobj = P_SpawnMobj(x, y, z, MT_CYBRAKDEMON_ELECTRIC_BARRIER); - P_SetTarget(&elecmobj->target, mobj); - elecmobj->angle = FixedAngle(mthing->angle*FRACUNIT); - elecmobj->destscale = mobj->scale*2; - P_SetScale(elecmobj, elecmobj->destscale); - } - else if (i == MT_STARPOST) - { - thinker_t *th; - mobj_t *mo2; - boolean foundanother = false; - mobj->health = (mthing->angle / 360) + 1; - - // See if other starposts exist in this level that have the same value. - for (th = thinkercap.next; th != &thinkercap; th = th->next) - { - if (th->function != (actionf_p1)P_MobjThinker) - continue; - - mo2 = (mobj_t *)th; - - if (mo2 == mobj) - continue; - - if (mo2->type == MT_STARPOST && mo2->health == mobj->health) + break; + case MT_BOSS3WAYPOINT: // SRB2kart 120217 - Used to store checkpoint num { - foundanother = true; - break; + mobj->health = mthing->angle; + mobj->movecount = mthing->extrainfo; + P_SetTarget(&mobj->tracer, waypointcap); + P_SetTarget(&waypointcap, mobj); } - } + break; + case MT_SPIKE: + { + // Pop up spikes! + if (mthing->options & MTF_OBJECTSPECIAL) + { + mobj->flags &= ~MF_SCENERY; + mobj->fuse = mthing->angle + mobj->info->speed; + } + // Use per-thing collision for spikes if the deaf flag is checked. + if (mthing->options & MTF_AMBUSH) + { + P_UnsetThingPosition(mobj); + mobj->flags &= ~(MF_NOBLOCKMAP|MF_NOGRAVITY|MF_NOCLIPHEIGHT); + mobj->flags |= MF_SOLID; + P_SetThingPosition(mobj); + } + } + break; + case MT_BIGTUMBLEWEED: + case MT_LITTLETUMBLEWEED: + { + if (mthing->options & MTF_AMBUSH) + { + mobj->momz += FixedMul(16*FRACUNIT, mobj->scale); - if (!foundanother) - numstarposts++; - } - else if (i == MT_BOSS3WAYPOINT) // SRB2kart 120217 - Used to store checkpoint num - { - mobj->health = mthing->angle; - mobj->movecount = mthing->extrainfo; - P_SetTarget(&mobj->tracer, waypointcap); - P_SetTarget(&waypointcap, mobj); - } - else if (i == MT_SPIKE) - { - // Pop up spikes! - if (mthing->options & MTF_OBJECTSPECIAL) - { - mobj->flags &= ~MF_SCENERY; - mobj->fuse = mthing->angle + mobj->info->speed; - } - // Use per-thing collision for spikes if the deaf flag is checked. - if (mthing->options & MTF_AMBUSH) - { - P_UnsetThingPosition(mobj); - mobj->flags &= ~(MF_NOBLOCKMAP|MF_NOGRAVITY|MF_NOCLIPHEIGHT); - mobj->flags |= MF_SOLID; - P_SetThingPosition(mobj); - } - } + if (P_RandomChance(FRACUNIT/2)) + mobj->momx += FixedMul(16*FRACUNIT, mobj->scale); + else + mobj->momx -= FixedMul(16*FRACUNIT, mobj->scale); - //count 10 ring boxes into the number of rings equation too. - if (i == MT_SUPERRINGBOX) - nummaprings += 10; + if (P_RandomChance(FRACUNIT/2)) + mobj->momy += FixedMul(16*FRACUNIT, mobj->scale); + else + mobj->momy -= FixedMul(16*FRACUNIT,mobj->scale); + } + } + break; + // Axis Points + case MT_AXIS: + case MT_AXISTRANSFER: + case MT_AXISTRANSFERLINE: + { + // Mare it belongs to + mobj->threshold = min(mthing->extrainfo, 7); - if (i == MT_BIGTUMBLEWEED || i == MT_LITTLETUMBLEWEED) - { - if (mthing->options & MTF_AMBUSH) - { - mobj->momz += FixedMul(16*FRACUNIT, mobj->scale); + // # in the mare + mobj->health = mthing->options; - if (P_RandomChance(FRACUNIT/2)) - mobj->momx += FixedMul(16*FRACUNIT, mobj->scale); - else - mobj->momx -= FixedMul(16*FRACUNIT, mobj->scale); + mobj->flags2 |= MF2_AXIS; - if (P_RandomChance(FRACUNIT/2)) - mobj->momy += FixedMul(16*FRACUNIT, mobj->scale); - else - mobj->momy -= FixedMul(16*FRACUNIT,mobj->scale); - } - } + if (type == MT_AXIS) + { + // Inverted if uppermost bit is set + if (mthing->angle & 16384) + mobj->flags2 |= MF2_AMBUSH; - // CTF flag pointers - if (i == MT_REDFLAG) - { - redflag = mobj; - rflagpoint = mobj->spawnpoint; - } - if (i == MT_BLUEFLAG) - { - blueflag = mobj; - bflagpoint = mobj->spawnpoint; - } + if (mthing->angle > 0) + mobj->radius = (mthing->angle & 16383)*FRACUNIT; + } + } + break; + case MT_EMMY: + { + if (mthing->options & MTF_OBJECTSPECIAL) // Mario Block version + { + mobj->flags &= ~(MF_NOGRAVITY|MF_NOCLIPHEIGHT); + } + else + { + fixed_t zheight = mobj->z; + mobj_t *tokenobj; - // special push/pull stuff - if (i == MT_PUSH || i == MT_PULL) - { - mobj->health = 0; // Default behaviour: pushing uses XY, fading uses XYZ + if (mthing->options & MTF_OBJECTFLIP) + zheight += mobj->height - FixedMul(mobjinfo[MT_TOKEN].height, mobj->scale); // align with emmy properly! - if (mthing->options & MTF_AMBUSH) - mobj->health |= 1; // If ambush is set, push using XYZ - if (mthing->options & MTF_OBJECTSPECIAL) - mobj->health |= 2; // If object special is set, fade using XY - } + tokenobj = P_SpawnMobj(x, y, zheight, MT_TOKEN); + P_SetTarget(&mobj->tracer, tokenobj); + tokenobj->destscale = mobj->scale; + P_SetScale(tokenobj, mobj->scale); - // ignore MTF_ flags and return early - if (i == MT_NIGHTSBUMPER) - { - mobj->angle = FixedAngle(mthing->angle*FRACUNIT); - mthing->mobj = mobj; - return; + if (mthing->options & MTF_OBJECTFLIP) // flip token to match emmy + { + tokenobj->eflags |= MFE_VERTICALFLIP; + tokenobj->flags2 |= MF2_OBJECTFLIP; + } + } + + // We advanced tokenbits earlier due to the return check. + // Subtract 1 here for the correct value. + mobj->health = 1 << (tokenbits - 1); + } + break; + case MT_CYBRAKDEMON: + { + mobj_t *elecmobj; + + if (!(mthing->options & MTF_AMBUSH)) + break; + + elecmobj = P_SpawnMobj(x, y, z, MT_CYBRAKDEMON_ELECTRIC_BARRIER); + P_SetTarget(&elecmobj->target, mobj); + elecmobj->angle = FixedAngle(mthing->angle*FRACUNIT); + elecmobj->destscale = mobj->scale*2; + P_SetScale(elecmobj, elecmobj->destscale); + } + break; + case MT_SUPERRINGBOX: + { + // count 10 ring boxes into the number of rings equation too. + if (type == MT_SUPERRINGBOX) + nummaprings += 10; + } + break; + // CTF flag pointers + case MT_REDFLAG: + { + redflag = mobj; + rflagpoint = mobj->spawnpoint; + } + break; + case MT_BLUEFLAG: + { + blueflag = mobj; + bflagpoint = mobj->spawnpoint; + } + break; + // special push/pull stuff + case MT_PUSH: + case MT_PULL: + { + mobj->health = 0; // Default behaviour: pushing uses XY, fading uses XYZ + + if (mthing->options & MTF_AMBUSH) + mobj->health |= 1; // If ambush is set, push using XYZ + if (mthing->options & MTF_OBJECTSPECIAL) + mobj->health |= 2; // If object special is set, fade using XY + } + break; + case MT_NIGHTSBUMPER: + { + // ignore MTF_ flags and return early + mobj->angle = FixedAngle(mthing->angle*FRACUNIT); + mthing->mobj = mobj; + return false; + } + default: + break; } mobj->angle = FixedAngle(mthing->angle*FRACUNIT); - if ((mthing->options & MTF_AMBUSH) - && (mthing->options & MTF_OBJECTSPECIAL) - && (mobj->flags & MF_PUSHABLE)) + if ((mthing->options & MTF_AMBUSH) && + (mthing->options & MTF_OBJECTSPECIAL) && + (mobj->flags & MF_PUSHABLE)) + { mobj->flags2 |= MF2_CLASSICPUSH; + } else { if (mthing->options & MTF_AMBUSH) { - if (i == MT_YELLOWDIAG || i == MT_REDDIAG) + if (type == MT_YELLOWDIAG || type == MT_REDDIAG) mobj->angle += ANGLE_22h; if (mobj->flags & MF_NIGHTSITEM) @@ -11844,33 +11656,39 @@ ML_NOCLIMB : Direction not controllable if (mobj->flags & MF_MONITOR) { // flag for strong/weak random boxes - if (i == MT_SUPERRINGBOX || i == MT_PRUP || - i == MT_SNEAKERTV || i == MT_INV || - i == MT_WHITETV || i == MT_GREENTV || - i == MT_YELLOWTV || i == MT_BLUETV || - i == MT_BLACKTV || i == MT_PITYTV || - i == MT_RECYCLETV || i == MT_MIXUPBOX) + if (type == MT_SUPERRINGBOX || type == MT_PRUP || + type == MT_SNEAKERTV || type == MT_INV || + type == MT_WHITETV || type == MT_GREENTV || + type == MT_YELLOWTV || type == MT_BLUETV || + type == MT_BLACKTV || type == MT_PITYTV || + type == MT_RECYCLETV || type == MT_MIXUPBOX) + { mobj->flags2 |= MF2_AMBUSH; + } } else if ( - i != MT_AXIS && - i != MT_AXISTRANSFER && - i != MT_AXISTRANSFERLINE && - i != MT_NIGHTSBUMPER && - i != MT_STARPOST) + type != MT_AXIS && + type != MT_AXISTRANSFER && + type != MT_AXISTRANSFERLINE && + type != MT_NIGHTSBUMPER && + type != MT_STARPOST) + { mobj->flags2 |= MF2_AMBUSH; + } } if (mthing->options & MTF_OBJECTSPECIAL) { // flag for strong/weak random boxes - if (i == MT_SUPERRINGBOX || i == MT_PRUP || - i == MT_SNEAKERTV || i == MT_INV || - i == MT_WHITETV || i == MT_GREENTV || - i == MT_YELLOWTV || i == MT_BLUETV || - i == MT_BLACKTV || i == MT_PITYTV || - i == MT_RECYCLETV || i == MT_MIXUPBOX) + if (type == MT_SUPERRINGBOX || type == MT_PRUP || + type == MT_SNEAKERTV || type == MT_INV || + type == MT_WHITETV || type == MT_GREENTV || + type == MT_YELLOWTV || type == MT_BLUETV || + type == MT_BLACKTV || type == MT_PITYTV || + type == MT_RECYCLETV || type == MT_MIXUPBOX) + { mobj->flags2 |= MF2_STRONGBOX; + } // Requires you to be in bonus time to activate if (mobj->flags & MF_NIGHTSITEM) @@ -11892,7 +11710,362 @@ ML_NOCLIMB : Direction not controllable mobj->flags2 |= MF2_OBJECTFLIP; } - mthing->mobj = mobj; + return true; +} + +static boolean P_PrepareMapThing(mapthing_t *mthing, fixed_t *x, fixed_t *y, fixed_t *z, subsector_t **ss, mobjtype_t *type) +{ + // Always spawn in objectplace. + // Skip all returning code. + if (objectplacing) + goto noreturns; + + if (*type >= MT_EMERALD1 && *type <= MT_EMERALD7) // Pickupable Emeralds + { + if (gametype != GT_COOP) // Don't place emeralds in non-coop modes + return false; + + if (emeralds & mobjinfo[*type].speed) // You already have this emerald! + return false; + } + + if (!G_BattleGametype() || !cv_specialrings.value) + { + if (P_WeaponOrPanel(*type)) + return false; // Don't place weapons/panels in non-ringslinger modes + } + + if (*type == MT_EMERHUNT) + { + // Emerald Hunt is Coop only. + if (gametype != GT_COOP) + return false; + + *ss = R_PointInSubsector((mthing->x << FRACBITS), (mthing->y << FRACBITS)); + mthing->z = (INT16)((P_GetSectorFloorZAt((*ss)->sector, (mthing->x << FRACBITS), (mthing->y << FRACBITS)) >> FRACBITS) + (mthing->options >> ZSHIFT)); + + if (numhuntemeralds < MAXHUNTEMERALDS) + huntemeralds[numhuntemeralds++] = mthing; + + return false; + } + + if (*type == MT_EMERALDSPAWN) + { + if (!cv_powerstones.value || !G_BattleGametype()) + return false; + } + + if (!G_RaceGametype()) // No enemies in match or CTF modes + { + if ((mobjinfo[*type].flags & MF_ENEMY) || (mobjinfo[*type].flags & MF_BOSS)) + return false; + } + + // Set powerup boxes to user settings for competition. + if (gametype == GT_COMPETITION && cv_competitionboxes.value && (mobjinfo[*type].flags & MF_MONITOR)) // not Normal + { + switch (cv_competitionboxes.value) + { + case 1: // Random + *type = MT_QUESTIONBOX; + break; + case 2: // Teleports + *type = MT_MIXUPBOX; + break; + case 3: // None + return false; // Don't spawn! + default: + break; + } + } + // Set powerup boxes to user settings for other netplay modes + else if (gametype != GT_COOP && cv_matchboxes.value && (mobjinfo[*type].flags & MF_MONITOR)) // not Normal + { + switch (cv_matchboxes.value) + { + case 1: // Random + *type = MT_QUESTIONBOX; + break; + case 3: // None + return false; // Don't spawn! + default: + if (*type == MT_QUESTIONBOX) + return false; // don't spawn in Non-Random + mthing->options &= ~(MTF_AMBUSH|MTF_OBJECTSPECIAL); // no random respawning! + break; + } + } + + if (gametype != GT_CTF) // CTF specific things + { + switch (*type) + { + case MT_BLUETEAMRING: + case MT_REDTEAMRING: + *type = MT_RING; + break; + case MT_BLUERINGBOX: + case MT_REDRINGBOX: + *type = MT_SUPERRINGBOX; + break; + case MT_BLUEFLAG: + case MT_REDFLAG: + return false; // No flags in non-CTF modes! + default: + break; + } + } + else + { + if ((*type == MT_BLUEFLAG && blueflag) || (*type == MT_REDFLAG && redflag)) + { + CONS_Alert(CONS_ERROR, M_GetText("Only one flag per team allowed in CTF!\n")); + return false; + } + } + + if (!G_RaceGametype() && (*type == MT_SIGN || *type == MT_STARPOST)) + return false; // Don't spawn exit signs or starposts in wrong game modes + + if (modeattacking) // Record Attack special stuff + { + // Emerald Tokens -->> Score Tokens + if (*type == MT_EMMY) + return false; /// \todo + + // 1UPs -->> Score TVs + else if (*type == MT_PRUP) // 1UP + { + // Either or, doesn't matter which. + if (mthing->options & (MTF_AMBUSH|MTF_OBJECTSPECIAL)) + *type = MT_SCORETVLARGE; // 10,000 + else + *type = MT_SCORETVSMALL; // 1,000 + } + } + + if (*type == MT_EMMY && (gametype != GT_COOP || tokenbits == 30 || tokenlist & (1 << tokenbits++))) + return false; // you already got this token, or there are too many, or the gametype's not right + + // Objectplace landing point + noreturns: + + // spawn it + *x = mthing->x << FRACBITS; + *y = mthing->y << FRACBITS; + *ss = R_PointInSubsector(*x, *y); + + if (*type == MT_NIGHTSBUMPER) + { + *z = P_GetSectorFloorZAt((*ss)->sector, *x, *y) + ((mthing->options >> ZSHIFT) << FRACBITS); + } + else if (*type == MT_AXIS || *type == MT_AXISTRANSFER || *type == MT_AXISTRANSFERLINE) + { + *z = ONFLOORZ; + } + else if (*type == MT_SPECIALSPIKEBALL || P_WeaponOrPanel(*type) || *type == MT_EMERALDSPAWN || *type == MT_EMMY) + { + if (mthing->options & MTF_OBJECTFLIP) + { + *z = P_GetSectorCeilingZAt((*ss)->sector, *x, *y); + + if (mthing->options & MTF_AMBUSH) // Special flag for rings + *z -= 24*FRACUNIT; + if (mthing->options >> ZSHIFT) + *z -= (mthing->options >> ZSHIFT)*FRACUNIT; + + *z -= mobjinfo[*type].height; //Don't forget the height! + } + else + { + *z = P_GetSectorFloorZAt((*ss)->sector, *x, *y); + + if (mthing->options & MTF_AMBUSH) // Special flag for rings + *z += 24*FRACUNIT; + if (mthing->options >> ZSHIFT) + *z += (mthing->options >> ZSHIFT)*FRACUNIT; + } + + if (*z == ONFLOORZ) + mthing->z = 0; + else + mthing->z = (INT16)(*z >> FRACBITS); + } + else + { + fixed_t offset = 0; + boolean flip = (!!(mobjinfo[*type].flags & MF_SPAWNCEILING) ^ !!(mthing->options & MTF_OBJECTFLIP)); + + // base positions + if (flip) + *z = P_GetSectorCeilingZAt((*ss)->sector, *x, *y) - mobjinfo[*type].height; + else + *z = P_GetSectorFloorZAt((*ss)->sector, *x, *y); + + // offsetting + if (mthing->options >> ZSHIFT) + { + offset = ((mthing->options >> ZSHIFT) << FRACBITS); + } + else + { + switch (*type) + { + case MT_CRAWLACOMMANDER: + case MT_DETON: + case MT_JETTBOMBER: + case MT_JETTGUNNER: + case MT_EGGMOBILE2: + offset = 33*FRACUNIT; + break; + case MT_EGGMOBILE: + offset = 128*FRACUNIT; + break; + case MT_GOLDBUZZ: + case MT_REDBUZZ: + offset = 288*FRACUNIT; + break; + default: + break; + } + } + + // applying offsets! (if any) + if (flip) + { + if (offset) + *z -= offset; + else + *z = ONCEILINGZ; + } + else + { + if (offset) + *z += offset; + else + *z = ONFLOORZ; + } + + if (*z == ONFLOORZ) + mthing->z = 0; + else + mthing->z = (INT16)(*z >> FRACBITS); + } + + return true; +} + +static boolean P_SpawnNonMobjMapThing(mapthing_t *mthing) +{ + // count deathmatch start positions + switch (mthing->type) + { + case 33: + if (numdmstarts < MAX_DM_STARTS) + { + deathmatchstarts[numdmstarts] = mthing; + mthing->type = 0; + numdmstarts++; + } + return true; + case 34: // Red CTF Starts + if (numredctfstarts < MAXPLAYERS) + { + redctfstarts[numredctfstarts] = mthing; + mthing->type = 0; + numredctfstarts++; + } + return true; + case 35: // Blue CTF Starts + if (numbluectfstarts < MAXPLAYERS) + { + bluectfstarts[numbluectfstarts] = mthing; + mthing->type = 0; + numbluectfstarts++; + } + return true; + case 300: // Ring + case 308: + case 309: // Team Rings + case 600 ... 609: // Placement patterns + case 750: // Slope vertex point (formerly chaos spawn) + case 1705: + case 1706: // Nights Wing + case 1713: // NiGHTS Hoops + case 1800: // Mario Coin + return true; // Don't spawn hoops, wings, or rings yet! + default: + break; + } + + // check for players specially + if (mthing->type > 0 && mthing->type <= 32) + { + if (mthing->type > MAXPLAYERS) // be wary of playerstarts size! playerstarts[MAXPLAYERS] + { + CONS_Alert(CONS_ERROR, "Excess player start detected %d This will crash vanilla clients!\n", mthing->type); + } + else + { + // save spots for respawning in network games + playerstarts[mthing->type-1] = mthing; + } + + return true; + } + + return false; +} + +static boolean P_DoomEdNumIsNOP(UINT16 type) +{ + if (type == 3328) + { + // 3D Mode start Thing + return true; + } + + return (type == 0); +} + +// +// P_SpawnMapThing +// The fields of the mapthing should +// already be in host byte order. +// +void P_SpawnMapThing(mapthing_t *mthing) +{ + mobjtype_t type = MT_NULL; + mobj_t *mobj; + fixed_t x, y, z; + subsector_t *ss; + + if (P_DoomEdNumIsNOP(mthing->type)) + return; // Ignore type-0 things as NOPs + + if (!objectplacing && P_SpawnNonMobjMapThing(mthing)) + return; + + type = P_GetMobjtype(mthing->type); + if (type == MT_UNKNOWN) + CONS_Alert(CONS_WARNING, M_GetText("Unknown thing type %d placed at (%d, %d)\n"), mthing->type, mthing->x, mthing->y); + + if (!P_PrepareMapThing(mthing, &x, &y, &z, &ss, &type)) + return; + + mobj = P_SpawnMobj(x, y, z, type); + + if (P_MobjWasRemoved(mobj)) + { + CONS_Alert(CONS_ERROR, "Failed to spawn map thing #%d at %d, %d. This will crash vanilla clients!\n", mthing->type, x>>FRACBITS, y>>FRACBITS); + return; + } + + mobj->spawnpoint = mthing; + + if (P_SetupSpawnedMapThing(mthing, x, y, z, ss, mobj, type)) + mthing->mobj = mobj; } static void P_SpawnNiGHTSHoop(fixed_t x, fixed_t y, fixed_t z, fixed_t hoopsize, fixed_t hoopplacement, angle_t closestangle, INT16 spewangle, mobj_t *hoopcenter, mobj_t **nextmobj, mobjtype_t type) @@ -12070,6 +12243,7 @@ boolean P_CheckMissileSpawn(mobj_t *th) P_ExplodeMissile(th); return false; } + return true; } @@ -12276,6 +12450,7 @@ mobj_t *P_SpawnMissile(mobj_t *source, mobj_t *dest, mobjtype_t type) I_Assert(source != NULL); I_Assert(dest != NULL); + if (source->type == MT_JETTGUNNER) { if (source->eflags & MFE_VERTICALFLIP) @@ -12344,6 +12519,7 @@ mobj_t *P_SpawnMissile(mobj_t *source, mobj_t *dest, mobjtype_t type) dist = P_CheckMissileSpawn(th); else dist = 1; + return dist ? th : NULL; } @@ -12353,6 +12529,11 @@ mobj_t *P_SpawnMissile(mobj_t *source, mobj_t *dest, mobjtype_t type) // void P_ColorTeamMissile(mobj_t *missile, player_t *source) { + if (missile == NULL || source == NULL) + { + return; + } + if (G_GametypeHasTeams()) { if (source->ctfteam == 2) From de35e086d3bbdb0fbf76efbff4f0615782b87461 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 21 Sep 2026 16:44:56 +0200 Subject: [PATCH 15/35] use strnlen in W_CheckNumForNamePwad we clamped this to a length of 8 eitherways so might aswell just use strnlen which is safer in any case --- src/w_wad.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/w_wad.c b/src/w_wad.c index 6c24d69c2..f9147559b 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -1106,8 +1106,7 @@ UINT16 W_CheckNumForNamePwad(const char *name, UINT16 wad, UINT16 startlump) if (!TestValidLump(wad, 0)) return INT16_MAX; - namelen = strlen(name); - namelen = min(namelen, 8); // :chaosleep: + namelen = strnlen(name, 8); // :chaosleep: hash = W_HashLumpNameLen(name, namelen); // From 7e906074ec9a19698ca5f61ae50e18f9294771bd Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 8 Apr 2010 14:16:46 -0300 Subject: [PATCH 16/35] keep memory-error message in the global state, so that its use does not depend on Lua internalizing strings to avoid a string creation on memory errors --- src/blua/ldo.c | 4 ++-- src/blua/lmem.h | 2 -- src/blua/lstate.c | 7 ++++++- src/blua/lstate.h | 1 + 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/blua/ldo.c b/src/blua/ldo.c index 1bda07f11..54d7e654d 100644 --- a/src/blua/ldo.c +++ b/src/blua/ldo.c @@ -55,8 +55,8 @@ struct lua_longjmp { void luaD_seterrorobj (lua_State *L, int lerrcode, StkId oldtop) { switch (lerrcode) { - case LUA_ERRMEM: { - setsvalue2s(L, oldtop, luaS_newliteral(L, MEMERRMSG)); + case LUA_ERRMEM: { /* memory error? */ + setsvalue2s(L, oldtop, G(L)->memerrmsg); /* reuse preregistered msg. */ break; } case LUA_ERRERR: { diff --git a/src/blua/lmem.h b/src/blua/lmem.h index ebfc22747..bc1b89575 100644 --- a/src/blua/lmem.h +++ b/src/blua/lmem.h @@ -13,8 +13,6 @@ #include "llimits.h" #include "lua.h" -#define MEMERRMSG "not enough memory" - #define luaM_reallocv(L,b,on,n,e) \ ((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \ diff --git a/src/blua/lstate.c b/src/blua/lstate.c index f6265768b..b3482c6d6 100644 --- a/src/blua/lstate.c +++ b/src/blua/lstate.c @@ -64,6 +64,9 @@ static void freestack (lua_State *L, lua_State *L1) { } +#define MEMERRMSG "not enough memory" + + /* ** open parts that may cause memory-allocation errors */ @@ -76,7 +79,9 @@ static void f_luaopen (lua_State *L, void *ud) { luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ luaT_init(L); luaX_init(L); - luaS_fix(luaS_newliteral(L, MEMERRMSG)); + /* pre-create memory-error message */ + g->memerrmsg = luaS_newliteral(L, MEMERRMSG); + luaS_fix(g->memerrmsg); /* it should never be collected */ g->GCthreshold = 4*g->totalbytes; } diff --git a/src/blua/lstate.h b/src/blua/lstate.h index 2d97fe30a..224119f06 100644 --- a/src/blua/lstate.h +++ b/src/blua/lstate.h @@ -88,6 +88,7 @@ typedef struct global_State { lua_CFunction panic; /* to be called in unprotected errors */ TValue l_registry; struct lua_State *mainthread; + TString *memerrmsg; /* memory-error message */ UpVal uvhead; /* head of double-linked list of all open upvalues */ struct Table *mt[NUM_TAGS]; /* metatables for basic types */ TString *tmname[TM_N]; /* array with tag-method names */ From 7fb3f7a1aa0ed4091df9319283dd6c34c1674d4e Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 21 Sep 2026 17:31:24 +0200 Subject: [PATCH 17/35] YES THANKS MICHEALSOFT VERY COOL --- src/z_zone.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/z_zone.cpp b/src/z_zone.cpp index 68d91dd48..8a8f751aa 100644 --- a/src/z_zone.cpp +++ b/src/z_zone.cpp @@ -568,7 +568,7 @@ void Z_CheckHeap(INT32 tag) #endif if (block->tag != j) { - HeapError(va(" block is contained in the wrong headlist (got: %d expected: %zu)", block->tag, j)); + HeapError(va(" block is contained in the wrong headlist (got: %d expected: %s)", block->tag, sizeu1(j))); } } } From a0d6d452a0b7fefdac38be667df9fb4d5d321f8c Mon Sep 17 00:00:00 2001 From: orbitalviolet Date: Sun, 20 Sep 2026 22:31:30 +0000 Subject: [PATCH 18/35] Fix regression #1507 --- src/hardware/hw_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index ad5137eaa..25acb72bc 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -1236,7 +1236,7 @@ static void HWR_DrawSkyWall(FOutVector *wallVerts, FSurfaceInfo *Surf) // Returns true if the midtexture is visible, and false if... it isn't... static inline boolean HWR_BlendMidtextureSurface(FSurfaceInfo *pSurf) { - FUINT blendmode = PF_Masked | PF_Translucent; + FUINT blendmode = PF_Masked; pSurf->PolyColor.s.alpha = 0xFF; From 110e93f4ed9545e78d8a6fc526ec58c18cebff82 Mon Sep 17 00:00:00 2001 From: Indev Date: Mon, 21 Sep 2026 20:53:44 +0300 Subject: [PATCH 19/35] Add command to change skin color to prefcolor --- src/d_netcmd.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 253f353db..913d6c8e6 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -147,6 +147,11 @@ static void Command_Addfilelocal(void); static void Command_Addfile(void); static void Command_Addskins(void); static void Command_GLocalSkin(void); +static void SetPrefcolor(int splitplayer); +static void Command_Prefcolor(void); +static void Command_Prefcolor2(void); +static void Command_Prefcolor3(void); +static void Command_Prefcolor4(void); static void Command_ListWADS_f(void); static void Command_LocateLump_f(void); static void Command_ListDoomednums_f(void); @@ -866,6 +871,11 @@ void D_RegisterClientCommands(void) COM_AddCommand("localskin", Command_GLocalSkin); + COM_AddCommand("prefcolor", Command_Prefcolor); + COM_AddCommand("prefcolor2", Command_Prefcolor2); + COM_AddCommand("prefcolor3", Command_Prefcolor3); + COM_AddCommand("prefcolor4", Command_Prefcolor4); + K_RegisterClientKartStuff(); // SRB2kart CV_RegisterVar(&cv_screenshot_option); @@ -4334,6 +4344,49 @@ static void Command_GLocalSkin(void) } } +static void SetPrefcolor(int splitplayer) +{ + // splitscreen + if (splitscreen < splitplayer) + return; + + const INT32 pnum = P_GetLocalPlayerNumForNum(splitplayer); + + player_t *player = &players[pnum]; + consvar_t *colorvars[] = {&cv_playercolor, &cv_playercolor2, &cv_playercolor3, &cv_playercolor4}; + consvar_t *playercolor = colorvars[splitplayer]; + + if (skins[player->skin].prefcolor) + { + CV_SetValue(playercolor, skins[player->skin].prefcolor); + CONS_Printf("Set color to %s%s\n", HU_SkinColorToConsoleColor(skins[player->skin].prefcolor), KartColor_Names[skins[player->skin].prefcolor]); + } + else + { + CONS_Printf("\x86Your skin has no prefcolor set\n"); + } +} + +static void Command_Prefcolor(void) +{ + SetPrefcolor(0); +} + +static void Command_Prefcolor2(void) +{ + SetPrefcolor(1); +} + +static void Command_Prefcolor3(void) +{ + SetPrefcolor(2); +} + +static void Command_Prefcolor4(void) +{ + SetPrefcolor(3); +} + static void Got_RequestAddfilecmd(const UINT8 **cp, INT32 playernum) { char filename[241]; From c9177081847f8df341a23529340c4770c267567c Mon Sep 17 00:00:00 2001 From: Indev Date: Mon, 21 Sep 2026 20:57:18 +0300 Subject: [PATCH 20/35] Actually change command name to useprefcolor, so its a bit more intuitive --- src/d_netcmd.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 913d6c8e6..500fa9b16 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -148,10 +148,10 @@ static void Command_Addfile(void); static void Command_Addskins(void); static void Command_GLocalSkin(void); static void SetPrefcolor(int splitplayer); -static void Command_Prefcolor(void); -static void Command_Prefcolor2(void); -static void Command_Prefcolor3(void); -static void Command_Prefcolor4(void); +static void Command_UsePrefcolor(void); +static void Command_UsePrefcolor2(void); +static void Command_UsePrefcolor3(void); +static void Command_UsePrefcolor4(void); static void Command_ListWADS_f(void); static void Command_LocateLump_f(void); static void Command_ListDoomednums_f(void); @@ -871,10 +871,10 @@ void D_RegisterClientCommands(void) COM_AddCommand("localskin", Command_GLocalSkin); - COM_AddCommand("prefcolor", Command_Prefcolor); - COM_AddCommand("prefcolor2", Command_Prefcolor2); - COM_AddCommand("prefcolor3", Command_Prefcolor3); - COM_AddCommand("prefcolor4", Command_Prefcolor4); + COM_AddCommand("useprefcolor", Command_UsePrefcolor); + COM_AddCommand("useprefcolor2", Command_UsePrefcolor2); + COM_AddCommand("useprefcolor3", Command_UsePrefcolor3); + COM_AddCommand("useprefcolor4", Command_UsePrefcolor4); K_RegisterClientKartStuff(); // SRB2kart @@ -4367,22 +4367,22 @@ static void SetPrefcolor(int splitplayer) } } -static void Command_Prefcolor(void) +static void Command_UsePrefcolor(void) { SetPrefcolor(0); } -static void Command_Prefcolor2(void) +static void Command_UsePrefcolor2(void) { SetPrefcolor(1); } -static void Command_Prefcolor3(void) +static void Command_UsePrefcolor3(void) { SetPrefcolor(2); } -static void Command_Prefcolor4(void) +static void Command_UsePrefcolor4(void) { SetPrefcolor(3); } From 4f7e2968859b3624ecd3a64949eca804910625b9 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 21 Sep 2026 20:40:50 +0200 Subject: [PATCH 21/35] fun times with M_DoAssignJoystick my tired ass forgor cv_usejoystick gets reassinged within this, so the cvar string also changes --- src/m_menu.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 82bc1d584..cc168c57e 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -9290,9 +9290,11 @@ static void M_Setup4PJoystickMenu(INT32 choice) static void M_DoAssignJoystick(UINT8 pnum, INT32 choice) { INT32 oldchoice, oldstringchoice; - const int joynum = atoi(cv_usejoystick[pnum].string); - oldchoice = oldstringchoice = joynum > numcontrollers ? joynum : cv_usejoystick[pnum].value; +#define joynum atoi(cv_usejoystick[pnum].string) +#define joyoldchoice (joynum > numcontrollers ? joynum : cv_usejoystick[pnum].value) + + oldchoice = oldstringchoice = joyoldchoice; CV_SetValue(&cv_usejoystick[pnum], choice); // Just in case last-minute changes were made to cv_usejoystick.value, @@ -9308,16 +9310,21 @@ static void M_DoAssignJoystick(UINT8 pnum, INT32 choice) if (oldchoice != choice) { if (choice && oldstringchoice > numcontrollers) // if we did not select "None", we likely selected a used device + { CV_SetValue(&cv_usejoystick[pnum], (oldstringchoice > numcontrollers ? oldstringchoice : oldchoice)); + } - if (oldstringchoice == - (joynum > numcontrollers ? joynum : cv_usejoystick[pnum].value)) + if (oldstringchoice == joyoldchoice) + { M_StartMessage("This joystick is used by another\n" "player. Reset the joystick\n" "for that player first.\n\n" "(Press a key)\n", NULL, MM_NOTHING); + } } } +#undef joynum +#undef joyoldchoice } #endif From 2c9a82e2d30f176e742b561b9ee4f4a05e1fbd0f Mon Sep 17 00:00:00 2001 From: Indev Date: Mon, 21 Sep 2026 22:35:21 +0300 Subject: [PATCH 22/35] 20 --- src/m_menu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index cc168c57e..42871b3b7 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -9399,7 +9399,7 @@ static void M_SetupControlsMenu(UINT8 pnum) { // Hide P1-only controls OP_AllControlsMenu[19].status = IT_GRAYEDOUT2; // Chat - OP_AllControlsMenu[10].status = IT_GRAYEDOUT2; // Rankings + OP_AllControlsMenu[20].status = IT_GRAYEDOUT2; // Rankings OP_AllControlsMenu[21].status = IT_GRAYEDOUT2; // Pause OP_AllControlsMenu[22].status = IT_GRAYEDOUT2; // Screenshot OP_AllControlsMenu[23].status = IT_GRAYEDOUT2; // GIF @@ -9411,7 +9411,7 @@ static void M_SetupControlsMenu(UINT8 pnum) { // Unhide P1-only controls OP_AllControlsMenu[19].status = IT_CONTROL; // Chat - OP_AllControlsMenu[10].status = IT_CONTROL; // Rankings + OP_AllControlsMenu[20].status = IT_CONTROL; // Rankings OP_AllControlsMenu[21].status = IT_CONTROL; // Pause OP_AllControlsMenu[22].status = IT_CONTROL; // Screenshot OP_AllControlsMenu[23].status = IT_CONTROL; // GIF From 604fa7281bcc4f4eae457f67b3057fef5bd0bb86 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 23 Sep 2026 18:24:30 +0200 Subject: [PATCH 23/35] dont reset JoyInfo in I_InitJoystick seems to fix wonky behavior when changing controllers per player --- src/sdl/i_system.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 6f7478f81..510db2802 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -1021,6 +1021,8 @@ void I_InitJoystick(UINT8 index) } } +#if 0 // no dont do this + // reset everything just in case JoyInfo[index].dev = NULL; JoyInfo[index].oldjoy = -1; #if (SDL_VERSION_ATLEAST(2,32,4)) @@ -1028,6 +1030,7 @@ void I_InitJoystick(UINT8 index) #endif JoyInfo[index].hasled = false; JoyInfo[index].hasrumble = false; +#endif if (cv_usejoystick[index].value) newcontroller = SDL_GameControllerOpen(cv_usejoystick[index].value-1); From 56bb20f4e1e2fa74809690a068e9bbc38a638636 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 23 Sep 2026 18:31:40 +0200 Subject: [PATCH 24/35] cleanup controller menu stuff a little more --- src/m_menu.c | 60 ++++++++++++++-------------------------------------- 1 file changed, 16 insertions(+), 44 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 42871b3b7..7b08296af 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -9205,7 +9205,7 @@ static void M_DrawJoystick(void) compareval4 = cv_usejoystick[3].value; compareval3 = cv_usejoystick[2].value; compareval2 = cv_usejoystick[1].value; - compareval = cv_usejoystick[0].value; + compareval = cv_usejoystick[0].value; #endif if ((setupcontrolplayer == 4 && (i == compareval4)) @@ -9244,14 +9244,13 @@ void M_SetupJoystickMenu(INT32 choice) // // Update cv_usejoystick.string here so that the user can // properly change this value. - if (i == cv_usejoystick[0].value) - CV_SetValue(&cv_usejoystick[0], i); - if (i == cv_usejoystick[1].value) - CV_SetValue(&cv_usejoystick[1], i); - if (i == cv_usejoystick[2].value) - CV_SetValue(&cv_usejoystick[2], i); - if (i == cv_usejoystick[3].value) - CV_SetValue(&cv_usejoystick[3], i); + for (INT32 f = 0; f < MAXSPLITSCREENPLAYERS; f++) + { + if (i == cv_usejoystick[f].value) + { + CV_SetValue(&cv_usejoystick[f], i); + } + } #endif } @@ -9291,8 +9290,8 @@ static void M_DoAssignJoystick(UINT8 pnum, INT32 choice) { INT32 oldchoice, oldstringchoice; -#define joynum atoi(cv_usejoystick[pnum].string) -#define joyoldchoice (joynum > numcontrollers ? joynum : cv_usejoystick[pnum].value) +#define joystrnum (atoi(cv_usejoystick[pnum].string)) +#define joyoldchoice ((joystrnum > numcontrollers) ? joystrnum : cv_usejoystick[pnum].value) oldchoice = oldstringchoice = joyoldchoice; CV_SetValue(&cv_usejoystick[pnum], choice); @@ -9304,14 +9303,15 @@ static void M_DoAssignJoystick(UINT8 pnum, INT32 choice) { CV_SetValue(&cv_usejoystick[pnum], cv_usejoystick[pnum].value); - if (oldchoice > numcontrollers) /* reset this so the comparison is valid*/ + // reset this so the comparison is valid + if (oldchoice > numcontrollers) oldchoice = cv_usejoystick[pnum].value; if (oldchoice != choice) { if (choice && oldstringchoice > numcontrollers) // if we did not select "None", we likely selected a used device { - CV_SetValue(&cv_usejoystick[pnum], (oldstringchoice > numcontrollers ? oldstringchoice : oldchoice)); + CV_SetValue(&cv_usejoystick[pnum], ((oldstringchoice > numcontrollers) ? oldstringchoice : oldchoice)); } if (oldstringchoice == joyoldchoice) @@ -9323,7 +9323,7 @@ static void M_DoAssignJoystick(UINT8 pnum, INT32 choice) } } } -#undef joynum +#undef joystrnum #undef joyoldchoice } #endif @@ -9331,37 +9331,9 @@ static void M_DoAssignJoystick(UINT8 pnum, INT32 choice) static void M_AssignJoystick(INT32 choice) { #ifdef JOYSTICK_HOTPLUG - switch (setupcontrolplayer) - { - case 4: - M_DoAssignJoystick(3, choice); - break; - case 3: - M_DoAssignJoystick(2, choice); - break; - case 2: - M_DoAssignJoystick(1, choice); - break; - case 1: - M_DoAssignJoystick(0, choice); - break; - } + M_DoAssignJoystick((setupcontrolplayer-1), choice); #else - switch (setupcontrolplayer) - { - case 4: - CV_SetValue(&cv_usejoystick[3], choice); - break; - case 3: - CV_SetValue(&cv_usejoystick[2], choice); - break; - case 2: - CV_SetValue(&cv_usejoystick[1], choice); - break; - case 1: - CV_SetValue(&cv_usejoystick[0], choice); - break; - } + CV_SetValue(&cv_usejoystick[(setupcontrolplayer-1)], choice); #endif } From 9521183eb3c465c3546ecb835e5237316cfa7469 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 23 Sep 2026 19:16:56 +0200 Subject: [PATCH 25/35] cast this to boolean no effective change just wanna be more explicit there --- src/p_spec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_spec.c b/src/p_spec.c index 8c35a5d0d..bc6267a7c 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -5474,7 +5474,7 @@ void P_SpawnSpecials(INT32 fromnetsave, boolean reloadinggamestate) else sectors[s].flags &= ~SF_GRAVITYFLIP; - CheckForReverseGravity = (sectors[s].flags & SF_GRAVITYFLIP); + CheckForReverseGravity = (boolean)(sectors[s].flags & SF_GRAVITYFLIP); } break; From dd2a227529f2e100b3199fda5c7a1aef42223fbb Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 25 Sep 2026 18:41:29 +0200 Subject: [PATCH 26/35] mobj hnext/hprev list fixes for phobos build too lazy to cherry pick so https://gitlab.com/kart-krew-dev/ring-racers/-/commit/a392996a5437742d5b7a91d0fce9da49c3a8bd76 and https://gitlab.com/kart-krew-dev/ring-racers/-/commit/8b5bd645ca5d8ef9269aa6ccf4375337bd0c1672 both of which might change behavior so phobos only --- src/k_kart.c | 23 +++++++++++++++++++++-- src/p_mobj.c | 16 ++++++++++++++-- src/p_setup.c | 1 + 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index 07fbacfdf..496c4d701 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -4399,8 +4399,7 @@ void K_KillBananaChain(mobj_t *banana, mobj_t *inflictor, mobj_t *source) mobj_t *cachenext; killnext: - - if (!banana) + if (P_MobjWasRemovedCompat(banana)) return; cachenext = banana->hnext; @@ -4439,10 +4438,21 @@ void K_UpdateHnextList(player_t *player, boolean clean) nextwork = work->hnext; if (!clean && (!work->movedir || work->movedir <= (UINT16)player->kartstuff[k_itemamount])) + { continue; + } P_RemoveMobj(work); } + +#ifdef PHOBOS_BUILD + if (P_MobjWasRemoved(player->mo->hnext)) + { + // Like below, try to clean up the pointer if it's NULL. + // Maybe this was a cause of the shrink/eggbox fails? + P_SetTarget(&player->mo->hnext, NULL); + } +#endif } // For getting hit! @@ -4507,7 +4517,9 @@ void K_DropHnextList(player_t *player) } dropwork = P_SpawnMobj(work->x, work->y, work->z, type); + P_SetTarget(&dropwork->target, player->mo); + dropwork->angle = work->angle; dropwork->flags2 = work->flags2; dropwork->flags |= MF_NOCLIPTHING; @@ -4575,10 +4587,13 @@ void K_DropHnextList(player_t *player) // we need this here too because this is done in afterthink - pointers are cleaned up at the START of each tic... P_SetTarget(&player->mo->hnext, NULL); + player->kartstuff[k_bananadrag] = 0; if (player->kartstuff[k_eggmanheld]) + { player->kartstuff[k_eggmanheld] = 0; + } else if (player->kartstuff[k_itemheld] && (dropall || (--player->kartstuff[k_itemamount] <= 0))) { @@ -4879,7 +4894,9 @@ static void K_MoveHeldObjects(player_t *player) player->kartstuff[k_bananadrag] = 0; if (player->kartstuff[k_eggmanheld]) + { player->kartstuff[k_eggmanheld] = 0; + } else if (player->kartstuff[k_itemheld]) { player->kartstuff[k_itemamount] = player->kartstuff[k_itemheld] = 0; @@ -4896,7 +4913,9 @@ static void K_MoveHeldObjects(player_t *player) player->kartstuff[k_bananadrag] = 0; if (player->kartstuff[k_eggmanheld]) + { player->kartstuff[k_eggmanheld] = 0; + } else if (player->kartstuff[k_itemheld]) { player->kartstuff[k_itemamount] = player->kartstuff[k_itemheld] = 0; diff --git a/src/p_mobj.c b/src/p_mobj.c index fbb821e88..5b9deaaf7 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -10338,13 +10338,25 @@ void P_RemoveMobj(mobj_t *mobj) if (!P_MobjWasRemoved(mobj->hnext)) { - P_SetTarget(&mobj->hnext->hprev, mobj->hprev); +#ifdef PHOBOS_BUILD + if (mobj->hnext->hprev == mobj) +#endif + { + P_SetTarget(&mobj->hnext->hprev, mobj->hprev); + } + P_SetTarget(&mobj->hnext, NULL); } if (!P_MobjWasRemoved(mobj->hprev)) { - P_SetTarget(&mobj->hprev->hnext, cachenext); +#ifdef PHOBOS_BUILD + if (mobj->hprev->hnext == mobj) +#endif + { + P_SetTarget(&mobj->hprev->hnext, cachenext); + } + P_SetTarget(&mobj->hprev, NULL); } diff --git a/src/p_setup.c b/src/p_setup.c index 2201c0b9f..2c1c1cfed 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3328,6 +3328,7 @@ static boolean P_CheckSoundReplacements(UINT16 wadnum, char *name, size_t i) return false; } + // // P_CheckReplacMapReplacements // From 5e1ae2155f3c5a2c5d782ac6263aa47f3f731c1e Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 25 Sep 2026 20:30:48 +0200 Subject: [PATCH 27/35] cleanup and make safer, orbit item handling in K_MoveHeldObjects based on https://gitlab.com/kart-krew-dev/ring-racers/-/commit/4e9d2295c9da30888fea77825c276bac831aecb3 --- src/k_kart.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index 496c4d701..02c282cda 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -4930,20 +4930,24 @@ static void K_MoveHeldObjects(player_t *player) case MT_ORBINAUT_SHIELD: // Kart orbit items case MT_JAWZ_SHIELD: { - mobj_t *cur = player->mo->hnext; - fixed_t speed = ((8 - min(4, player->kartstuff[k_itemamount])) * cur->info->speed) / 7; + mobj_t *cur = NULL, *next = player->mo->hnext; + fixed_t speed = 0; + + if (next == NULL) + return; + + speed = ((8 - min(4, player->kartstuff[k_itemamount])) * next->info->speed) / 7; player->kartstuff[k_bananadrag] = 0; // Just to make sure - while (!P_MobjWasRemoved(cur)) + while ((cur = next) != NULL && !P_MobjWasRemoved(cur)) { fixed_t z; + next = cur->hnext; + if (!cur->health) - { - cur = cur->hnext; continue; - } const fixed_t radius = FixedHypot(player->mo->radius, player->mo->radius) + FixedHypot(cur->radius, cur->radius); // mobj's distance from its Target, or Radius. @@ -4978,8 +4982,13 @@ static void K_MoveHeldObjects(player_t *player) cur->flags &= ~MF_NOCLIPTHING; if (!P_TryMove(cur, player->mo->x + cur->momx, player->mo->y + cur->momy, true)) + { P_SlideMove(cur, true); + if (P_MobjWasRemovedCompat(cur)) + continue; + } + if (P_IsObjectOnGround(player->mo)) { if (P_MobjFlip(cur) > 0) @@ -5000,8 +5009,6 @@ static void K_MoveHeldObjects(player_t *player) cur->z = z; cur->momx = cur->momy = 0; cur->angle += ANGLE_90; - - cur = cur->hnext; } } break; From 91f016fd0c87796e0abd03f748686ae865f54c52 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 25 Sep 2026 20:34:34 +0200 Subject: [PATCH 28/35] remove inline from P_TagDamage not only this is basically unused its also quite huge so no need to inline this at all --- src/p_inter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_inter.c b/src/p_inter.c index 0bb273ace..94e026ed9 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -2016,7 +2016,7 @@ static inline void P_NiGHTSDamage(mobj_t *target, mobj_t *source) } } -static inline boolean P_TagDamage(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 damage) +static boolean P_TagDamage(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 damage) { player_t *player = target->player; (void)damage; //unused parm From 13241d1880a3389245a6b82012dfecaea259d816 Mon Sep 17 00:00:00 2001 From: Indev Date: Fri, 25 Sep 2026 21:54:43 +0300 Subject: [PATCH 29/35] Prevent orbit from being freed by using P_SetTarget in K_RepairOrbitChain --- src/k_kart.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/k_kart.c b/src/k_kart.c index 02c282cda..497a61ccc 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -4706,6 +4706,10 @@ void K_DropKitchenSink(player_t *player) // When an item in the hnext chain dies. void K_RepairOrbitChain(mobj_t *orbit) { + // Prevent orbit from being freed + mobj_t *dummy = NULL; + P_SetTarget(&dummy, orbit); + mobj_t *cachenext = orbit->hnext; // First, repair the chain @@ -4742,6 +4746,8 @@ void K_RepairOrbitChain(mobj_t *orbit) if (!P_MobjWasRemovedCompat(orbit->target)) orbit->target->player->kartstuff[k_itemamount] = num; } + + P_SetTarget(&dummy, NULL); } // Simplified version of a code bit in P_MobjFloorZ From 58403cf4a5cad2f1ea5c543af68771e336b79173 Mon Sep 17 00:00:00 2001 From: Indev Date: Fri, 25 Sep 2026 22:04:15 +0300 Subject: [PATCH 30/35] Revert "Prevent orbit from being freed by using P_SetTarget in K_RepairOrbitChain" This reverts commit 13241d1880a3389245a6b82012dfecaea259d816. --- src/k_kart.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index 497a61ccc..02c282cda 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -4706,10 +4706,6 @@ void K_DropKitchenSink(player_t *player) // When an item in the hnext chain dies. void K_RepairOrbitChain(mobj_t *orbit) { - // Prevent orbit from being freed - mobj_t *dummy = NULL; - P_SetTarget(&dummy, orbit); - mobj_t *cachenext = orbit->hnext; // First, repair the chain @@ -4746,8 +4742,6 @@ void K_RepairOrbitChain(mobj_t *orbit) if (!P_MobjWasRemovedCompat(orbit->target)) orbit->target->player->kartstuff[k_itemamount] = num; } - - P_SetTarget(&dummy, NULL); } // Simplified version of a code bit in P_MobjFloorZ From fa753c3694a8b28b3f09483513a780820be3b260 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 25 Sep 2026 22:03:03 +0200 Subject: [PATCH 31/35] Revert "cleanup and make safer, orbit item handling in K_MoveHeldObjects" This reverts commit 5e1ae2155f3c5a2c5d782ac6263aa47f3f731c1e. --- src/k_kart.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index 02c282cda..496c4d701 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -4930,24 +4930,20 @@ static void K_MoveHeldObjects(player_t *player) case MT_ORBINAUT_SHIELD: // Kart orbit items case MT_JAWZ_SHIELD: { - mobj_t *cur = NULL, *next = player->mo->hnext; - fixed_t speed = 0; - - if (next == NULL) - return; - - speed = ((8 - min(4, player->kartstuff[k_itemamount])) * next->info->speed) / 7; + mobj_t *cur = player->mo->hnext; + fixed_t speed = ((8 - min(4, player->kartstuff[k_itemamount])) * cur->info->speed) / 7; player->kartstuff[k_bananadrag] = 0; // Just to make sure - while ((cur = next) != NULL && !P_MobjWasRemoved(cur)) + while (!P_MobjWasRemoved(cur)) { fixed_t z; - next = cur->hnext; - if (!cur->health) + { + cur = cur->hnext; continue; + } const fixed_t radius = FixedHypot(player->mo->radius, player->mo->radius) + FixedHypot(cur->radius, cur->radius); // mobj's distance from its Target, or Radius. @@ -4982,13 +4978,8 @@ static void K_MoveHeldObjects(player_t *player) cur->flags &= ~MF_NOCLIPTHING; if (!P_TryMove(cur, player->mo->x + cur->momx, player->mo->y + cur->momy, true)) - { P_SlideMove(cur, true); - if (P_MobjWasRemovedCompat(cur)) - continue; - } - if (P_IsObjectOnGround(player->mo)) { if (P_MobjFlip(cur) > 0) @@ -5009,6 +5000,8 @@ static void K_MoveHeldObjects(player_t *player) cur->z = z; cur->momx = cur->momy = 0; cur->angle += ANGLE_90; + + cur = cur->hnext; } } break; From 7e92482ced171594c7114b8a1cc5be3ab64e4768 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 25 Sep 2026 22:03:30 +0200 Subject: [PATCH 32/35] add orbit mobj check into K_MoveHeldObjects --- src/k_kart.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/k_kart.c b/src/k_kart.c index 496c4d701..aaa5b4962 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -4931,7 +4931,12 @@ static void K_MoveHeldObjects(player_t *player) case MT_JAWZ_SHIELD: { mobj_t *cur = player->mo->hnext; - fixed_t speed = ((8 - min(4, player->kartstuff[k_itemamount])) * cur->info->speed) / 7; + fixed_t speed = 0; + + if (cur == NULL) + return; + + speed = ((8 - min(4, player->kartstuff[k_itemamount])) * cur->info->speed) / 7; player->kartstuff[k_bananadrag] = 0; // Just to make sure @@ -4978,8 +4983,13 @@ static void K_MoveHeldObjects(player_t *player) cur->flags &= ~MF_NOCLIPTHING; if (!P_TryMove(cur, player->mo->x + cur->momx, player->mo->y + cur->momy, true)) + { P_SlideMove(cur, true); + if (P_MobjWasRemovedCompat(cur)) + continue; + } + if (P_IsObjectOnGround(player->mo)) { if (P_MobjFlip(cur) > 0) From d988876bca2ac4d36dbc49affaa0e0c3a9cf4349 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 26 Sep 2026 11:57:23 +0200 Subject: [PATCH 33/35] change version number for phobos phobos is NOT vanilla compatible and is not meant to be this should prevent the game be able to connect to vanilla servers hopefully --- src/doomdef.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/doomdef.h b/src/doomdef.h index 5a62d0a86..fe6e8c5e2 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -128,8 +128,13 @@ extern char logfilename[1024]; // most interface strings are ignored in development mode. // we use comprevision and compbranch instead. #else +#ifdef PHOBOS_BUILD +#define VERSION 1 // Game version +#define SUBVERSION 69 // more precise version number +#else #define VERSION 1 // Game version #define SUBVERSION 6 // more precise version number +#endif #ifdef PHOBOS_BUILD #define CLIENTNAME "Phobos" From e6033322c632c724ab7581f331ff59f46b3375c0 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 26 Sep 2026 12:02:57 +0200 Subject: [PATCH 34/35] disable phobos in cmake stupid copy paste error --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c763ab3b8..4bf2e5132 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -257,7 +257,7 @@ set(SRB2_CONFIG_SATURNJOIN ON CACHE BOOL set(SRB2_CONFIG_SCREENFBO ON CACHE BOOL "Enable hardware renderer (OpenGL) FBO downsampling support") -set(SRB2_CONFIG_PHOBOS ON CACHE BOOL +set(SRB2_CONFIG_PHOBOS OFF CACHE BOOL " Compile the Phobos client. Which contains things not compatible with vanilla, such as raised skinlimits, 32 player support, bugfixes, etc.") if(${SRB2_CONFIG_DEDICATED}) From 1d8b066a6458f2f3c8942c431c9004d61df1b786 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 26 Sep 2026 15:12:10 +0200 Subject: [PATCH 35/35] fix desynchs with vanilla on Sewer System read the sectornode list stuff this means we reuse old stale data in some cases, which also causes strange bugs with orbiting items in some cases, but thats what vanilla does and we HAVE to keep vanilla compat after all i really hope this does not cause any fun impossible to debug crashes, but what can you do --- src/p_local.h | 1 + src/p_map.c | 34 +++++++++++++++++++++++++++++++++- src/p_setup.c | 3 +++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/p_local.h b/src/p_local.h index 4f59246fc..86662d12f 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -418,6 +418,7 @@ boolean P_CheckSector(sector_t *sector, boolean crunch); void P_DelSeclist(msecnode_t *node); void P_CreateSecNodeList(mobj_t *thing, fixed_t x, fixed_t y); +void P_Initsecnode(void); void P_RadiusAttack(mobj_t *spot, mobj_t *source, fixed_t damagedist); diff --git a/src/p_map.c b/src/p_map.c index 49870bf88..52690909f 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -3983,19 +3983,51 @@ boolean P_CheckSector(sector_t *sector, boolean crunch) Lots of new Boom functions that work faster and add functionality. */ +#ifndef PHOBOS_BUILD +static msecnode_t *headsecnode = NULL; +#endif + +void P_Initsecnode(void) +{ +#ifndef PHOBOS_BUILD + headsecnode = NULL; +#endif +} + // P_GetSecnode() retrieves a node from the freelist. The calling routine // should make sure it sets all fields properly. static msecnode_t *P_GetSecnode(void) { +#ifdef PHOBOS_BUILD return Z_LevelPoolCalloc(sizeof(msecnode_t)); +#else + msecnode_t *node; + + if (headsecnode) + { + // vanilla does not clear this + // so for compat reasons we also dont + // means we just reuse stale data which causes weird interactions with orbiting items in some cases + node = headsecnode; + headsecnode = headsecnode->m_thinglist_next; + } + else + node = Z_LevelPoolCalloc(sizeof(msecnode_t)); + + return node; +#endif } // P_PutSecnode() returns a node to the freelist. - static inline void P_PutSecnode(msecnode_t *node) { +#ifdef PHOBOS_BUILD Z_LevelPoolFree(node, sizeof(msecnode_t)); +#else + node->m_thinglist_next = headsecnode; + headsecnode = node; +#endif } // P_AddSecnode() searches the current list to see if this sector is diff --git a/src/p_setup.c b/src/p_setup.c index 2c1c1cfed..485c5e274 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3001,6 +3001,9 @@ boolean P_SetupLevel(boolean fromnetsave, boolean reloadinggamestate) CON_Drawer(); // let the user know what we are going to do I_FinishUpdate(); // page flip or blit buffer + // Initialize sector node list. + P_Initsecnode(); + if (netgame || multiplayer) cv_debug = botskin = 0;