From ec12a6fcaa2474eaea1188b023e15d4ca587b8c8 Mon Sep 17 00:00:00 2001 From: /dev/humancontroller Date: Sun, 13 Jul 2014 16:53:10 +0200 Subject: change setviewpos to work as it sounds like setviewpos now precisely puts the player's view origin to the specified coordinates, and does not spit the player forward; it now optionally takes yaw and pitch arguments for this, setviewpos takes ps->viewheight into account when teleporting the player; TeleportPlayer() now takes an additional float argument specifying the spitting speed of the player; currently, TeleportPlayer() is called with a non-0 argument only from the setviewpos function --- src/game/g_cmds.c | 22 +++++++++++++++------- src/game/g_local.h | 2 +- src/game/g_misc.c | 15 +++++++++------ src/game/g_mover.c | 2 +- src/game/g_target.c | 2 +- src/game/g_trigger.c | 2 +- 6 files changed, 28 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/game/g_cmds.c b/src/game/g_cmds.c index 4e6288a8..85dd24f9 100644 --- a/src/game/g_cmds.c +++ b/src/game/g_cmds.c @@ -1562,24 +1562,32 @@ void Cmd_SetViewpos_f( gentity_t *ent ) char buffer[ MAX_TOKEN_CHARS ]; int i; - if( trap_Argc( ) != 5 ) + if( trap_Argc( ) < 4 ) { - trap_SendServerCommand( ent-g_entities, "print \"usage: setviewpos x y z yaw\n\"" ); + trap_SendServerCommand( ent-g_entities, "print \"usage: setviewpos [ []]\n\"" ); return; } - VectorClear( angles ); - for( i = 0; i < 3; i++ ) { trap_Argv( i + 1, buffer, sizeof( buffer ) ); origin[ i ] = atof( buffer ); } + origin[ 2 ] -= ent->client->ps.viewheight; + + VectorCopy( ent->client->ps.viewangles, angles ); + angles[ ROLL ] = 0; - trap_Argv( 4, buffer, sizeof( buffer ) ); - angles[ YAW ] = atof( buffer ); + if( trap_Argc() >= 5 ) { + trap_Argv( 4, buffer, sizeof( buffer ) ); + angles[ YAW ] = atof( buffer ); + if( trap_Argc() >= 6 ) { + trap_Argv( 5, buffer, sizeof( buffer ) ); + angles[ PITCH ] = atof( buffer ); + } + } - TeleportPlayer( ent, origin, angles ); + TeleportPlayer( ent, origin, angles, 0.0f ); } #define AS_OVER_RT3 ((ALIENSENSE_RANGE*0.5f)/M_ROOT3) diff --git a/src/game/g_local.h b/src/game/g_local.h index 255359f5..2f6fa6da 100644 --- a/src/game/g_local.h +++ b/src/game/g_local.h @@ -911,7 +911,7 @@ void G_Checktrigger_stages( team_t team, stage_t stage ); // // g_misc.c // -void TeleportPlayer( gentity_t *player, vec3_t origin, vec3_t angles ); +void TeleportPlayer( gentity_t *player, vec3_t origin, vec3_t angles, float speed ); // // g_weapon.c diff --git a/src/game/g_misc.c b/src/game/g_misc.c index 8fb70b1b..fa2c8705 100644 --- a/src/game/g_misc.c +++ b/src/game/g_misc.c @@ -70,19 +70,22 @@ TELEPORTERS ================================================================================= */ -void TeleportPlayer( gentity_t *player, vec3_t origin, vec3_t angles ) +void TeleportPlayer( gentity_t *player, vec3_t origin, vec3_t angles, float speed ) { // unlink to make sure it can't possibly interfere with G_KillBox trap_UnlinkEntity( player ); VectorCopy( origin, player->client->ps.origin ); - player->client->ps.origin[ 2 ] += 1; + player->client->ps.groundEntityNum = ENTITYNUM_NONE; + player->client->ps.stats[ STAT_STATE ] &= ~SS_GRABBED; - // spit the player out AngleVectors( angles, player->client->ps.velocity, NULL, NULL ); - VectorScale( player->client->ps.velocity, 400, player->client->ps.velocity ); - player->client->ps.pm_time = 160; // hold time - player->client->ps.pm_flags |= PMF_TIME_KNOCKBACK; + VectorScale( player->client->ps.velocity, speed, player->client->ps.velocity ); + player->client->ps.pm_time = 0.4f * fabs( speed ); // duration of loss of control + if( player->client->ps.pm_time > 160 ) + player->client->ps.pm_time = 160; + if( player->client->ps.pm_time != 0 ) + player->client->ps.pm_flags |= PMF_TIME_KNOCKBACK; // toggle the teleport bit so the client knows to not lerp player->client->ps.eFlags ^= EF_TELEPORT_BIT; diff --git a/src/game/g_mover.c b/src/game/g_mover.c index 1cf681ae..be821c21 100644 --- a/src/game/g_mover.c +++ b/src/game/g_mover.c @@ -1169,7 +1169,7 @@ static void Touch_DoorTriggerSpectator( gentity_t *ent, gentity_t *other, trace_ } vectoangles( dir, angles ); - TeleportPlayer( other, origin, angles ); + TeleportPlayer( other, origin, angles, 400.0f ); } diff --git a/src/game/g_target.c b/src/game/g_target.c index 8b2bb261..057decbb 100644 --- a/src/game/g_target.c +++ b/src/game/g_target.c @@ -211,7 +211,7 @@ void target_teleporter_use( gentity_t *self, gentity_t *other, gentity_t *activa return; } - TeleportPlayer( activator, dest->s.origin, dest->s.angles ); + TeleportPlayer( activator, dest->s.origin, dest->s.angles, 400.0f ); } /*QUAKED target_teleporter (1 0 0) (-8 -8 -8) (8 8 8) diff --git a/src/game/g_trigger.c b/src/game/g_trigger.c index 97cb557d..caed1d75 100644 --- a/src/game/g_trigger.c +++ b/src/game/g_trigger.c @@ -295,7 +295,7 @@ void trigger_teleporter_touch( gentity_t *self, gentity_t *other, trace_t *trace return; } - TeleportPlayer( other, dest->s.origin, dest->s.angles ); + TeleportPlayer( other, dest->s.origin, dest->s.angles, 400.0f ); } /* -- cgit