Overhaul teleport command, let it work in netgames

Old syntax with -x, -y, -z, -ang, -aim parameters is
simply replaced with 3 argument syntax like rteleport.

Before - teleport -x 100 -y 50 -z 25
After  - teleport 100 50 25

The lost angle, aiming and star post features can be added
back in separate commands.
This commit is contained in:
James R 2023-04-08 00:47:30 -07:00
parent 39ea73a4ad
commit dc18fa745a
3 changed files with 26 additions and 215 deletions

View file

@ -2032,6 +2032,7 @@ void D_Cheat(INT32 playernum, INT32 cheat, ...)
break;
case CHEAT_RELATIVE_TELEPORT:
case CHEAT_TELEPORT:
COPY(WRITEFIXED, fixed_t);
COPY(WRITEFIXED, fixed_t);
COPY(WRITEFIXED, fixed_t);
@ -5699,7 +5700,8 @@ static void Got_Cheat(UINT8 **cp, INT32 playernum)
break;
}
case CHEAT_RELATIVE_TELEPORT: {
case CHEAT_RELATIVE_TELEPORT:
case CHEAT_TELEPORT: {
fixed_t x = READFIXED(*cp);
fixed_t y = READFIXED(*cp);
fixed_t z = READFIXED(*cp);
@ -5714,10 +5716,17 @@ static void Got_Cheat(UINT8 **cp, INT32 playernum)
if (!P_MobjWasRemoved(player->mo))
{
P_MapStart();
P_SetOrigin(player->mo,
player->mo->x + x,
player->mo->y + y,
player->mo->z + z);
if (cheat == CHEAT_RELATIVE_TELEPORT)
{
P_SetOrigin(player->mo,
player->mo->x + x,
player->mo->y + y,
player->mo->z + z);
}
else
{
P_SetOrigin(player->mo, x, y, z);
}
P_MapEnd();
S_StartSound(player->mo, sfx_mixup);
@ -5727,7 +5736,10 @@ static void Got_Cheat(UINT8 **cp, INT32 playernum)
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",
CV_CheaterWarning(targetPlayer, va("%s %d%s, %d%s, %d%s",
cheat == CHEAT_RELATIVE_TELEPORT
? "relative teleport by"
: "teleport to",
(int)f[0], t[0], (int)f[1], t[1], (int)f[2], t[2]));
break;
}

View file

@ -327,223 +327,21 @@ void Command_RTeleport_f(void)
void Command_Teleport_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() > 11)
if (COM_Argc() != 4)
{
CONS_Printf(M_GetText("teleport -x <value> -y <value> -z <value> -ang <value> -aim <value>: teleport to a location\nteleport -sp <sequence> <placement>: teleport to specified checkpoint\n"));
CONS_Printf(M_GetText("teleport <x> <y> <z>: teleport to a location\n"));
return;
}
if (!p->mo)
return;
i = COM_CheckParm("-sp");
if (i)
{
INT32 starpostnum = atoi(COM_Argv(i + 1)); // starpost number
INT32 starpostpath = atoi(COM_Argv(i + 2)); // quick, dirty way to distinguish between paths
if (starpostnum < 0 || starpostpath < 0)
{
CONS_Alert(CONS_NOTICE, M_GetText("Negative starpost indexing is not valid.\n"));
return;
}
if (!starpostnum) // spawnpoints...
{
mapthing_t *mt;
fixed_t offset;
if (starpostpath >= numcoopstarts)
{
CONS_Alert(CONS_NOTICE, M_GetText("Player %d spawnpoint not found (%d max).\n"), starpostpath+1, numcoopstarts-1);
return;
}
mt = playerstarts[starpostpath]; // Given above check, should never be NULL.
intx = mt->x<<FRACBITS;
inty = mt->y<<FRACBITS;
offset = mt->z<<FRACBITS;
ss = R_PointInSubsectorOrNull(intx, inty);
if (!ss || ss->sector->ceilingheight - ss->sector->floorheight < p->mo->height)
{
CONS_Alert(CONS_NOTICE, M_GetText("Spawnpoint not in a valid location.\n"));
return;
}
// Flagging a player's ambush will make them start on the ceiling
// Objectflip inverts
if (!!(mt->args[0]) ^ !!(mt->options & MTF_OBJECTFLIP))
intz = ss->sector->ceilingheight - p->mo->height - offset;
else
intz = ss->sector->floorheight + offset;
if (mt->options & MTF_OBJECTFLIP) // flip the player!
{
p->mo->eflags |= MFE_VERTICALFLIP;
p->mo->flags2 |= MF2_OBJECTFLIP;
}
else
{
p->mo->eflags &= ~MFE_VERTICALFLIP;
p->mo->flags2 &= ~MF2_OBJECTFLIP;
}
p->mo->angle = p->drawangle = FixedAngle(mt->angle<<FRACBITS);
P_SetPlayerAngle(p, p->mo->angle);
}
else // scan the thinkers to find starposts...
{
mobj_t *mo2 = NULL;
thinker_t *th;
INT32 starpostmax = 0;
intz = starpostpath; // variable reuse - counting down for selection purposes
for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next)
{
if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed)
continue;
mo2 = (mobj_t *)th;
if (mo2->type != MT_STARPOST)
continue;
if (mo2->health != starpostnum)
{
if (mo2->health > starpostmax)
starpostmax = mo2->health;
continue;
}
if (intz--)
continue;
break;
}
if (th == &thlist[THINK_MOBJ])
{
if (intz == starpostpath)
CONS_Alert(CONS_NOTICE, M_GetText("No starpost of position %d found (%d max).\n"), starpostnum, starpostmax);
else
CONS_Alert(CONS_NOTICE, M_GetText("Starpost of position %d, %d not found (%d, %d max).\n"), starpostnum, starpostpath, starpostmax, (starpostpath-intz)-1);
return;
}
ss = R_PointInSubsectorOrNull(mo2->x, mo2->y);
if (!ss || ss->sector->ceilingheight - ss->sector->floorheight < p->mo->height)
{
CONS_Alert(CONS_NOTICE, M_GetText("Starpost not in a valid location.\n"));
return;
}
intx = mo2->x;
inty = mo2->y;
intz = mo2->z;
if (mo2->flags2 & MF2_OBJECTFLIP) // flip the player!
{
p->mo->eflags |= MFE_VERTICALFLIP;
p->mo->flags2 |= MF2_OBJECTFLIP;
}
else
{
p->mo->eflags &= ~MFE_VERTICALFLIP;
p->mo->flags2 &= ~MF2_OBJECTFLIP;
}
p->mo->angle = p->drawangle = mo2->angle;
P_SetPlayerAngle(p, p->mo->angle);
}
CONS_Printf(M_GetText("Teleporting to checkpoint %d, %d...\n"), starpostnum, starpostpath);
}
else
{
i = COM_CheckParm("-nop"); // undocumented stupid addition to allow pivoting on the spot with -ang and -aim
if (i)
{
intx = p->mo->x;
inty = p->mo->y;
}
else
{
i = COM_CheckParm("-x");
if (i)
intx = atoi(COM_Argv(i + 1))<<FRACBITS;
else
{
CONS_Alert(CONS_NOTICE, M_GetText("%s value not specified.\n"), "X");
return;
}
i = COM_CheckParm("-y");
if (i)
inty = atoi(COM_Argv(i + 1))<<FRACBITS;
else
{
CONS_Alert(CONS_NOTICE, M_GetText("%s value not specified.\n"), "Y");
return;
}
}
ss = R_PointInSubsectorOrNull(intx, inty);
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))<<FRACBITS;
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->eflags & MFE_VERTICALFLIP) ? ss->sector->ceilingheight : ss->sector->floorheight);
i = COM_CheckParm("-ang");
if (i)
{
p->drawangle = p->mo->angle = FixedAngle(atoi(COM_Argv(i + 1))<<FRACBITS);
P_SetPlayerAngle(p, p->mo->angle);
}
i = COM_CheckParm("-aim");
if (i)
{
angle_t aim = FixedAngle(atoi(COM_Argv(i + 1))<<FRACBITS);
if (aim >= ANGLE_90 && aim <= ANGLE_270)
{
CONS_Alert(CONS_NOTICE, M_GetText("Not a valid aiming angle (between +/-90).\n"));
return;
}
localaiming[0] = p->aiming = aim;
}
CONS_Printf(M_GetText("Teleporting to %d, %d, %d...\n"), FixedInt(intx), FixedInt(inty), FixedInt(intz));
}
P_MapStart();
if (!P_SetOrigin(p->mo, intx, inty, 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_TELEPORT,
FLOAT_TO_FIXED(x), FLOAT_TO_FIXED(y), FLOAT_TO_FIXED(z));
}
void Command_Skynum_f(void)

View file

@ -33,6 +33,7 @@ typedef enum {
CHEAT_FLIP,
CHEAT_HURT,
CHEAT_RELATIVE_TELEPORT,
CHEAT_TELEPORT,
CHEAT_DEVMODE,
CHEAT_GIVEITEM,
CHEAT_SCORE,