From 0024332f34adfbaea543f44fa5ebe62b902aeb09 Mon Sep 17 00:00:00 2001 From: James R Date: Thu, 29 Sep 2022 06:10:53 -0700 Subject: [PATCH] Let relativeteleport work online Requires all x, y, z arguments. Floats supported. Old: rteleport -x 1 -y 2 -z 3 New: rteleport 1.1 2.2 3.3 --- src/d_netcmd.c | 39 ++++++++++++++++++++++++++++++++++ src/m_cheat.c | 57 +++++++------------------------------------------- src/m_cheat.h | 1 + 3 files changed, 47 insertions(+), 50 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index e95df4d75..1efae4c43 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -2009,6 +2009,12 @@ void D_Cheat(INT32 playernum, INT32 cheat, ...) case CHEAT_HURT: COPY(WRITEINT32, INT32); break; + + case CHEAT_RELATIVE_TELEPORT: + COPY(WRITEFIXED, fixed_t); + COPY(WRITEFIXED, fixed_t); + COPY(WRITEFIXED, fixed_t); + break; } #undef COPY @@ -5565,6 +5571,39 @@ static void Got_Cheat(UINT8 **cp, INT32 playernum) break; } + case CHEAT_RELATIVE_TELEPORT: { + fixed_t x = READFIXED(*cp); + fixed_t y = READFIXED(*cp); + fixed_t z = READFIXED(*cp); + + float f[3] = { + FIXED_TO_FLOAT(x), + FIXED_TO_FLOAT(y), + FIXED_TO_FLOAT(z), + }; + char t[3][9]; + + if (!P_MobjWasRemoved(player->mo)) + { + P_MapStart(); + P_SetOrigin(player->mo, + player->mo->x + x, + player->mo->y + y, + player->mo->z + z); + P_MapEnd(); + + S_StartSound(player->mo, sfx_mixup); + } + + strlcpy(t[0], M_Ftrim(f[0]), sizeof t[0]); + strlcpy(t[1], M_Ftrim(f[1]), sizeof t[1]); + strlcpy(t[2], M_Ftrim(f[2]), sizeof t[2]); + + CV_CheaterWarning(targetPlayer, va("relative teleport by %d%s, %d%s, %d%s", + (int)f[0], t[0], (int)f[1], t[1], (int)f[2], t[2])); + break; + } + case NUMBER_OF_CHEATS: break; } diff --git a/src/m_cheat.c b/src/m_cheat.c index 70758b864..21e5645fb 100644 --- a/src/m_cheat.c +++ b/src/m_cheat.c @@ -306,64 +306,21 @@ void Command_Hurtme_f(void) void Command_RTeleport_f(void) { - fixed_t intx, inty, intz; - size_t i; - player_t *p = &players[consoleplayer]; - subsector_t *ss; + float x = atof(COM_Argv(1)); + float y = atof(COM_Argv(2)); + float z = atof(COM_Argv(3)); REQUIRE_CHEATS; REQUIRE_INLEVEL; - REQUIRE_SINGLEPLAYER; // TODO: make multiplayer compatible - if (COM_Argc() < 3 || COM_Argc() > 7) + if (COM_Argc() != 4) { - CONS_Printf(M_GetText("rteleport -x -y -z : relative teleport to a location\n")); + CONS_Printf(M_GetText("rteleport : relative teleport to a location\n")); return; } - if (!p->mo) - return; - - i = COM_CheckParm("-x"); - if (i) - intx = atoi(COM_Argv(i + 1)); - else - intx = 0; - - i = COM_CheckParm("-y"); - if (i) - inty = atoi(COM_Argv(i + 1)); - else - inty = 0; - - ss = R_PointInSubsectorOrNull(p->mo->x + intx*FRACUNIT, p->mo->y + inty*FRACUNIT); - if (!ss || ss->sector->ceilingheight - ss->sector->floorheight < p->mo->height) - { - CONS_Alert(CONS_NOTICE, M_GetText("Not a valid location.\n")); - return; - } - i = COM_CheckParm("-z"); - if (i) - { - intz = atoi(COM_Argv(i + 1)); - intz <<= FRACBITS; - intz += p->mo->z; - if (intz < ss->sector->floorheight) - intz = ss->sector->floorheight; - if (intz > ss->sector->ceilingheight - p->mo->height) - intz = ss->sector->ceilingheight - p->mo->height; - } - else - intz = p->mo->z; - - CONS_Printf(M_GetText("Teleporting by %d, %d, %d...\n"), intx, inty, FixedInt((intz-p->mo->z))); - - P_MapStart(); - if (!P_SetOrigin(p->mo, p->mo->x+intx*FRACUNIT, p->mo->y+inty*FRACUNIT, intz)) - CONS_Alert(CONS_WARNING, M_GetText("Unable to teleport to that spot!\n")); - else - S_StartSound(p->mo, sfx_mixup); - P_MapEnd(); + D_Cheat(consoleplayer, CHEAT_RELATIVE_TELEPORT, + FLOAT_TO_FIXED(x), FLOAT_TO_FIXED(y), FLOAT_TO_FIXED(z)); } void Command_Teleport_f(void) diff --git a/src/m_cheat.h b/src/m_cheat.h index e12366b0f..40ff3fe00 100644 --- a/src/m_cheat.h +++ b/src/m_cheat.h @@ -27,6 +27,7 @@ typedef enum { CHEAT_SCALE, CHEAT_FLIP, CHEAT_HURT, + CHEAT_RELATIVE_TELEPORT, NUMBER_OF_CHEATS } cheat_t;