From 8655b8f1f15f0b138d9c85af07a6f1b4a7a4dff1 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Thu, 29 Aug 2019 01:57:58 -0400 Subject: [PATCH 1/3] Add spawn object linedef special. Note that spawning a object within a random range does not fully work yet and crashes the game --- src/p_setup.c | 1 + src/p_spec.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/p_setup.c b/src/p_setup.c index d0cd14b22..65335be3f 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1480,6 +1480,7 @@ static void P_LoadRawSideDefs2(void *data) case 425: // Calls P_SetMobjState on calling mobj case 434: // Custom Power case 442: // Calls P_SetMobjState on mobjs of a given type in the tagged sectors + case 461: // Spawns an object on the map based on texture offsets { char process[8*3+1]; memset(process,0,8*3+1); diff --git a/src/p_spec.c b/src/p_spec.c index 37a1652f0..325f5ebe7 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -3953,6 +3953,27 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) } break; + case 461: // Spawns an object on the map based on texture offsets + { + const mobjtype_t type = (mobjtype_t)(sides[line->sidenum[0]].toptexture); + + fixed_t x, y, z; + x = sides[line->sidenum[0]].textureoffset; + y = sides[line->sidenum[0]].rowoffset; + z = line->frontsector->floorheight; + + if (line->flags & ML_NOCLIMB) // If noclimb is set, spawn randomly within a range + { + x = P_RandomRange(sides[line->sidenum[0]].textureoffset, sides[line->sidenum[1]].textureoffset); + y = P_RandomRange(sides[line->sidenum[0]].rowoffset, sides[line->sidenum[1]].rowoffset); + z = P_RandomRange(line->frontsector->floorheight, line->frontsector->ceilingheight); + } + + CONS_Printf("mobjtype_t: %d\n", type); + P_SpawnMobj(x, y, z, type); + } + break; + #ifdef POLYOBJECTS case 480: // Polyobj_DoorSlide case 481: // Polyobj_DoorSwing From 10ea0f21ae3b61b2584b599adab57a5b65b29c82 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Thu, 29 Aug 2019 23:56:15 -0400 Subject: [PATCH 2/3] Fix spawning within random range --- src/p_spec.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/p_spec.c b/src/p_spec.c index 325f5ebe7..014a09845 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -3964,13 +3964,24 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) if (line->flags & ML_NOCLIMB) // If noclimb is set, spawn randomly within a range { - x = P_RandomRange(sides[line->sidenum[0]].textureoffset, sides[line->sidenum[1]].textureoffset); - y = P_RandomRange(sides[line->sidenum[0]].rowoffset, sides[line->sidenum[1]].rowoffset); - z = P_RandomRange(line->frontsector->floorheight, line->frontsector->ceilingheight); + if (line->sidenum[1] != 0xffff) // Make sure the linedef has a back side + { + x = P_RandomRange(sides[line->sidenum[0]].textureoffset>>FRACBITS, sides[line->sidenum[1]].textureoffset>>FRACBITS)<sidenum[0]].rowoffset>>FRACBITS, sides[line->sidenum[1]].rowoffset>>FRACBITS)<frontsector->floorheight>>FRACBITS, line->frontsector->ceilingheight>>FRACBITS)<special); + break; + } } - CONS_Printf("mobjtype_t: %d\n", type); - P_SpawnMobj(x, y, z, type); + mobj_t *mobj = P_SpawnMobj(x, y, z, type); + if (mobj) + CONS_Debug(DBG_GAMELOGIC, "Linedef Type %d - Spawn Object: %d spawned at (%d, %d, %d)\n", line->special, mobj->type, mobj->x>>FRACBITS, mobj->y>>FRACBITS, mobj->z>>FRACBITS); //TODO: Convert mobj->type to a string somehow. + else + CONS_Alert(CONS_ERROR,"Linedef Type %d - Spawn Object: Object did not spawn!\n", line->special); } break; From 1bf78a242341c2a770690bf16b8968567d0906e6 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Sun, 8 Sep 2019 17:14:47 -0400 Subject: [PATCH 3/3] Move mobj_t declaration to top of the block --- src/p_spec.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/p_spec.c b/src/p_spec.c index 014a09845..74bea7266 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -3956,6 +3956,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) case 461: // Spawns an object on the map based on texture offsets { const mobjtype_t type = (mobjtype_t)(sides[line->sidenum[0]].toptexture); + mobj_t *mobj; fixed_t x, y, z; x = sides[line->sidenum[0]].textureoffset; @@ -3977,7 +3978,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) } } - mobj_t *mobj = P_SpawnMobj(x, y, z, type); + mobj = P_SpawnMobj(x, y, z, type); if (mobj) CONS_Debug(DBG_GAMELOGIC, "Linedef Type %d - Spawn Object: %d spawned at (%d, %d, %d)\n", line->special, mobj->type, mobj->x>>FRACBITS, mobj->y>>FRACBITS, mobj->z>>FRACBITS); //TODO: Convert mobj->type to a string somehow. else