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 */ 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)); } diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 253f353db..500fa9b16 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_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); @@ -866,6 +871,11 @@ void D_RegisterClientCommands(void) COM_AddCommand("localskin", Command_GLocalSkin); + COM_AddCommand("useprefcolor", Command_UsePrefcolor); + COM_AddCommand("useprefcolor2", Command_UsePrefcolor2); + COM_AddCommand("useprefcolor3", Command_UsePrefcolor3); + COM_AddCommand("useprefcolor4", Command_UsePrefcolor4); + 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_UsePrefcolor(void) +{ + SetPrefcolor(0); +} + +static void Command_UsePrefcolor2(void) +{ + SetPrefcolor(1); +} + +static void Command_UsePrefcolor3(void) +{ + SetPrefcolor(2); +} + +static void Command_UsePrefcolor4(void) +{ + SetPrefcolor(3); +} + static void Got_RequestAddfilecmd(const UINT8 **cp, INT32 playernum) { char filename[241]; 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; 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/m_menu.c b/src/m_menu.c index 82bc1d584..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 } @@ -9290,9 +9289,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 joystrnum (atoi(cv_usejoystick[pnum].string)) +#define joyoldchoice ((joystrnum > numcontrollers) ? joystrnum : 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, @@ -9302,59 +9303,37 @@ 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 == - (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 joystrnum +#undef joyoldchoice } #endif 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 } @@ -9392,7 +9371,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 @@ -9404,7 +9383,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 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; 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_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..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 // @@ -971,7 +1004,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 +1016,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; } @@ -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. @@ -3193,7 +3234,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 +3253,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; } } @@ -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) diff --git a/src/p_spec.c b/src/p_spec.c index 8b526798e..bc6267a7c 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 = (boolean)(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 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); 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) diff --git a/src/w_wad.c b/src/w_wad.c index 5d0771dc3..f9147559b 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,14 @@ 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 = strnlen(name, 8); // :chaosleep: + hash = W_HashLumpNameLen(name, namelen); // // scan forward @@ -1121,7 +1122,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; } } diff --git a/src/z_zone.cpp b/src/z_zone.cpp index 4ee72ae9c..8a8f751aa 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,47 @@ 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 + if (block->tag != j) + { + HeapError(va(" block is contained in the wrong headlist (got: %d expected: %s)", block->tag, sizeu1(j))); + } + } } } @@ -590,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; } @@ -640,18 +665,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 // ----------------------- @@ -665,8 +693,8 @@ 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("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)); CONS_Printf(M_GetText("Static (music) : %7s KB\n"), sizeu1(Z_TagUsage(PU_MUSIC)>>10)); @@ -680,7 +708,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 +737,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); + 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); } + } } #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