From 890934264b577b123f70cd8042442980fcaa79af Mon Sep 17 00:00:00 2001 From: MascaraSnake Date: Tue, 21 Sep 2021 10:14:55 +0200 Subject: [PATCH] Adapt linedef type 414 to UDMF --- extras/conf/udb/Includes/SRB222_linedefs.cfg | 39 ++++ src/p_setup.c | 59 +++++- src/p_spec.c | 196 ++++++++++--------- src/p_spec.h | 15 ++ 4 files changed, 212 insertions(+), 97 deletions(-) diff --git a/extras/conf/udb/Includes/SRB222_linedefs.cfg b/extras/conf/udb/Includes/SRB222_linedefs.cfg index a33e54d68..10a2f768f 100644 --- a/extras/conf/udb/Includes/SRB222_linedefs.cfg +++ b/extras/conf/udb/Includes/SRB222_linedefs.cfg @@ -3081,6 +3081,45 @@ udmf { title = "Linedef Executor (misc.)"; + 414 + { + title = "Play Sound Effect"; + prefix = "(414)"; + arg0 + { + title = "Source"; + type = 11; + enum + { + 0 = "Triggering object"; + 1 = "Trigger sector"; + 2 = "Nowhere"; + 3 = "Tagged sectors"; + } + } + arg1 + { + title = "Listener"; + type = 11; + enum + { + 0 = "Triggering player"; + 1 = "Everyone"; + 2 = "Everyone touching tagged sectors"; + } + } + arg2 + { + title = "Target sector tag"; + type = 13; + } + stringarg0 + { + title = "Sound name"; + type = 2; + } + } + 415 { title = "Run Script"; diff --git a/src/p_setup.c b/src/p_setup.c index 181c4eada..f834cd3fa 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1273,7 +1273,6 @@ static void P_LoadSidedefs(UINT8 *data) } case 4: // Speed pad parameters - case 414: // Play SFX { sd->toptexture = sd->midtexture = sd->bottomtexture = 0; if (msd->toptexture[0] != '-' || msd->toptexture[1] != '\0') @@ -1286,6 +1285,20 @@ static void P_LoadSidedefs(UINT8 *data) break; } + case 414: // Play SFX + { + sd->toptexture = sd->midtexture = sd->bottomtexture = 0; + if (msd->toptexture[0] != '-' || msd->toptexture[1] != '\0') + { + char process[8 + 1]; + M_Memcpy(process, msd->toptexture, 8); + process[8] = '\0'; + sd->text = Z_Malloc(strlen(process) + 1, PU_LEVEL, NULL); + M_Memcpy(sd->text, process, strlen(process) + 1); + } + break; + } + case 9: // Mace parameters case 14: // Bustable block parameters case 15: // Fan particle spawner parameters @@ -3696,6 +3709,50 @@ static void P_ConvertBinaryMap(void) case 411: //Stop plane movement lines[i].args[0] = tag; break; + case 414: //Play sound effect + lines[i].args[2] = tag; + if (tag != 0) + { + if (lines[i].flags & ML_EFFECT5) + { + lines[i].args[0] = TMSS_TAGGEDSECTOR; + lines[i].args[1] = TMSL_EVERYONE; + } + else + { + lines[i].args[0] = TMSS_NOWHERE; + lines[i].args[1] = TMSL_TAGGEDSECTOR; + } + } + else + { + if (lines[i].flags & ML_NOCLIMB) + { + lines[i].args[0] = TMSS_NOWHERE; + lines[i].args[1] = TMSL_TRIGGERER; + } + else if (lines[i].flags & ML_EFFECT4) + { + lines[i].args[0] = TMSS_NOWHERE; + lines[i].args[1] = TMSL_EVERYONE; + } + else if (lines[i].flags & ML_BLOCKMONSTERS) + { + lines[i].args[0] = TMSS_TRIGGERSECTOR; + lines[i].args[1] = TMSL_EVERYONE; + } + else + { + lines[i].args[0] = TMSS_TRIGGERMOBJ; + lines[i].args[1] = TMSL_EVERYONE; + } + } + if (sides[lines[i].sidenum[0]].text) + { + lines[i].stringargs[0] = Z_Malloc(strlen(sides[lines[i].sidenum[0]].text) + 1, PU_LEVEL, NULL); + M_Memcpy(lines[i].stringargs[0], sides[lines[i].sidenum[0]].text, strlen(sides[lines[i].sidenum[0]].text) + 1); + } + break; case 415: //Run script { INT32 scrnum; diff --git a/src/p_spec.c b/src/p_spec.c index 8e469e8e9..b828d97cd 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -1906,6 +1906,105 @@ void P_LinedefExecute(INT16 tag, mobj_t *actor, sector_t *caller) } } +static void P_PlaySFX(INT32 sfxnum, mobj_t *mo, sector_t *callsec, INT16 tag, textmapsoundsource_t source, textmapsoundlistener_t listener) +{ + if (sfxnum == sfx_None) + return; // Do nothing! + + if (sfxnum < sfx_None || sfxnum >= NUMSFX) + { + CONS_Debug(DBG_GAMELOGIC, "Line type 414 Executor: sfx number %d is invalid!\n", sfxnum); + return; + } + + // Check if you can hear the sound + switch (listener) + { + case TMSL_TRIGGERER: // only play sound if displayplayer + if (!mo) + return; + + if (!mo->player) + return; + + if (mo->player != &players[displayplayer] && mo->player != &players[secondarydisplayplayer]) + return; + + break; + case TMSL_TAGGEDSECTOR: // only play if touching tagged sectors + { + UINT8 i = 0; + mobj_t *camobj = players[displayplayer].mo; + ffloor_t *rover; + boolean foundit = false; + + for (i = 0; i < 2; camobj = players[secondarydisplayplayer].mo, i++) + { + if (!camobj) + continue; + + if (foundit || Tag_Find(&camobj->subsector->sector->tags, tag)) + { + foundit = true; + break; + } + + // Only trigger if mobj is touching the tag + for (rover = camobj->subsector->sector->ffloors; rover; rover = rover->next) + { + if (!Tag_Find(&rover->master->frontsector->tags, tag)) + continue; + + if (camobj->z > P_GetSpecialTopZ(camobj, sectors + rover->secnum, camobj->subsector->sector)) + continue; + + if (camobj->z + camobj->height < P_GetSpecialBottomZ(camobj, sectors + rover->secnum, camobj->subsector->sector)) + continue; + + foundit = true; + break; + } + } + + if (!foundit) + return; + + break; + } + case TMSL_EVERYONE: // no additional check + default: + break; + } + + // Play the sound from the specified source + switch (source) + { + case TMSS_TRIGGERMOBJ: // play the sound from mobj that triggered it + if (mo) + S_StartSound(mo, sfxnum); + break; + case TMSS_TRIGGERSECTOR: // play the sound from calling sector's soundorg + if (callsec) + S_StartSound(&callsec->soundorg, sfxnum); + else if (mo) + S_StartSound(&mo->subsector->sector->soundorg, sfxnum); + break; + case TMSS_NOWHERE: // play the sound from nowhere + S_StartSound(NULL, sfxnum); + break; + case TMSS_TAGGEDSECTOR: // play the sound from tagged sectors' soundorgs + { + INT32 secnum; + + TAG_ITER_SECTORS(tag, secnum) + S_StartSound(§ors[secnum].soundorg, sfxnum); + break; + } + default: + break; + } +} + static boolean is_rain_type (INT32 weathernum) { switch (weathernum) @@ -2368,102 +2467,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) break; case 414: // Play SFX - { - INT32 sfxnum; - - sfxnum = sides[line->sidenum[0]].toptexture; - - if (sfxnum == sfx_None) - return; // Do nothing! - if (sfxnum < sfx_None || sfxnum >= NUMSFX) - { - CONS_Debug(DBG_GAMELOGIC, "Line type 414 Executor: sfx number %d is invalid!\n", sfxnum); - return; - } - - if (tag != 0) // Do special stuff only if a non-zero linedef tag is set - { - // Play sounds from tagged sectors' origins. - if (line->flags & ML_EFFECT5) // Repeat Midtexture - { - // Additionally play the sound from tagged sectors' soundorgs - sector_t *sec; - - TAG_ITER_SECTORS(tag, secnum) - { - sec = §ors[secnum]; - S_StartSound(&sec->soundorg, sfxnum); - } - } - - // Play the sound without origin for anyone, as long as they're inside tagged areas. - else - { - UINT8 i = 0; - mobj_t* camobj = players[displayplayer].mo; - ffloor_t *rover; - boolean foundit = false; - - for (i = 0; i < 2; camobj = players[secondarydisplayplayer].mo, i++) - { - if (!camobj) - continue; - - if (foundit || Tag_Find(&camobj->subsector->sector->tags, tag)) - { - foundit = true; - break; - } - - // Only trigger if mobj is touching the tag - for(rover = camobj->subsector->sector->ffloors; rover; rover = rover->next) - { - if (!Tag_Find(&rover->master->frontsector->tags, tag)) - continue; - - if (camobj->z > P_GetSpecialTopZ(camobj, sectors + rover->secnum, camobj->subsector->sector)) - continue; - - if (camobj->z + camobj->height < P_GetSpecialBottomZ(camobj, sectors + rover->secnum, camobj->subsector->sector)) - continue; - - foundit = true; - break; - } - } - - if (foundit) - S_StartSound(NULL, sfxnum); - } - } - else - { - if (line->flags & ML_NOCLIMB) - { - // play the sound from nowhere, but only if display player triggered it - if (mo && mo->player && (mo->player == &players[displayplayer] || mo->player == &players[secondarydisplayplayer])) - S_StartSound(NULL, sfxnum); - } - else if (line->flags & ML_EFFECT4) - { - // play the sound from nowhere - S_StartSound(NULL, sfxnum); - } - else if (line->flags & ML_BLOCKMONSTERS) - { - // play the sound from calling sector's soundorg - if (callsec) - S_StartSound(&callsec->soundorg, sfxnum); - else if (mo) - S_StartSound(&mo->subsector->sector->soundorg, sfxnum); - } - else if (mo) - { - // play the sound from mobj that triggered it - S_StartSound(mo, sfxnum); - } - } - } + P_PlaySFX(line->stringargs[0] ? get_number(line->stringargs[0]) : sfx_None, mo, callsec, line->args[2], line->args[0], line->args[1]); break; case 415: // Run a script diff --git a/src/p_spec.h b/src/p_spec.h index 07f566e2a..aeb557bf6 100644 --- a/src/p_spec.h +++ b/src/p_spec.h @@ -112,6 +112,21 @@ typedef enum TMP_BOTH = 2, } textmapplanes_t; +typedef enum +{ + TMSS_TRIGGERMOBJ = 0, + TMSS_TRIGGERSECTOR = 1, + TMSS_NOWHERE = 2, + TMSS_TAGGEDSECTOR = 3, +} textmapsoundsource_t; + +typedef enum +{ + TMSL_EVERYONE = 0, + TMSL_TRIGGERER = 1, + TMSL_TAGGEDSECTOR = 2, +} textmapsoundlistener_t; + typedef enum { TML_SECTOR = 0,