Merge pull request #1 from mjr4077au/Client_AimFixWithCVAR

Implement accurate-aiming CVAR in slightmechanicaldestruction game code.
This commit is contained in:
Yamagi 2020-04-21 12:45:13 +02:00 committed by GitHub
commit 09c37f30c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 15 deletions

View file

@ -90,7 +90,7 @@ extern void NoAmmoWeaponChange ( edict_t * ent ) ;
extern void ChangeWeapon ( edict_t * ent ) ;
extern qboolean Pickup_Weapon ( edict_t * ent , edict_t * other ) ;
extern void PlayerNoise ( edict_t * who , vec3_t where , int type ) ;
extern void P_ProjectSource ( gclient_t * client , vec3_t point , vec3_t distance , vec3_t forward , vec3_t right , vec3_t result ) ;
extern void P_ProjectSource ( edict_t * ent , vec3_t distance , vec3_t forward , vec3_t right , vec3_t result ) ;
extern void ClientEndServerFrame ( edict_t * ent ) ;
extern void WhatsIt ( edict_t * ent ) ;
extern void G_SetClientFrame ( edict_t * ent ) ;

View file

@ -773,6 +773,8 @@ extern cvar_t *vid_ref;
extern cvar_t *zoomrate;
extern cvar_t *zoomsnap;
extern cvar_t *aimfix;
extern int max_modelindex;
extern int max_soundindex;
@ -1281,7 +1283,7 @@ void ClientEndServerFrame (edict_t *ent);
// p_weapon.c
//
void PlayerNoise(edict_t *who, vec3_t where, int type);
void P_ProjectSource (gclient_t *client, vec3_t point, vec3_t distance, vec3_t forward, vec3_t right, vec3_t result);
void P_ProjectSource (edict_t *ent, vec3_t distance, vec3_t forward, vec3_t right, vec3_t result);
void kick_attack (edict_t *ent);
// ROGUE

View file

@ -102,6 +102,8 @@ cvar_t *vid_ref;
cvar_t *zoomrate;
cvar_t *zoomsnap;
cvar_t *aimfix;
void SpawnEntities (char *mapname, char *entities, char *spawnpoint);
void ClientThink (edict_t *ent, usercmd_t *cmd);
qboolean ClientConnect (edict_t *ent, char *userinfo);

View file

@ -421,6 +421,9 @@ void InitGame (void)
bounce_bounce = gi.cvar("bounce_bounce", "0.5", 0);
bounce_minv = gi.cvar("bounce_minv", "60", 0);
/* others */
aimfix = gi.cvar("aimfix", "0", CVAR_ARCHIVE);
// items
InitItems ();

View file

@ -11,9 +11,11 @@ static byte is_silenced;
void weapon_grenade_fire (edict_t *ent, qboolean held);
void P_ProjectSource (gclient_t *client, vec3_t point, vec3_t distance, vec3_t forward, vec3_t right, vec3_t result)
void P_ProjectSource (edict_t *ent, vec3_t distance, vec3_t forward, vec3_t right, vec3_t result)
{
vec3_t _distance;
gclient_t *client = ent->client;
float *point = ent->s.origin;
vec3_t _distance;
VectorCopy (distance, _distance);
// DWH
@ -25,6 +27,22 @@ void P_ProjectSource (gclient_t *client, vec3_t point, vec3_t distance, vec3_t f
else if (client->pers.hand == CENTER_HANDED)
_distance[1] = 0;
G_ProjectSource (point, _distance, forward, right, result);
// Berserker: fix - now the projectile hits exactly where the scope is pointing.
if (aimfix->value)
{
vec3_t start, end;
VectorSet(start, ent->s.origin[0], ent->s.origin[1], ent->s.origin[2] + ent->viewheight);
VectorMA(start, 8192, forward, end);
trace_t tr = gi.trace(start, NULL, NULL, end, ent, MASK_SHOT);
if (tr.fraction < 1)
{
VectorSubtract(tr.endpos, result, forward);
VectorNormalize(forward);
}
}
}
/*
@ -663,7 +681,7 @@ void weapon_grenade_fire (edict_t *ent, qboolean held)
VectorSet(offset, 8, 8, ent->viewheight-8);
AngleVectors (ent->client->v_angle, forward, right, NULL);
P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
P_ProjectSource (ent, offset, forward, right, start);
timer = ent->client->grenade_time - level.time;
speed = GRENADE_MINSPEED + (GRENADE_TIMER - timer) * ((GRENADE_MAXSPEED - GRENADE_MINSPEED) / GRENADE_TIMER);
@ -824,7 +842,7 @@ void weapon_grenadelauncher_fire (edict_t *ent)
VectorSet(offset, 8, 8, ent->viewheight-8);
AngleVectors (ent->client->v_angle, forward, right, NULL);
P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
P_ProjectSource (ent, offset, forward, right, start);
VectorScale (forward, -2, ent->client->kick_origin);
ent->client->kick_angles[0] = -1;
@ -929,7 +947,7 @@ void Weapon_RocketLauncher_Fire (edict_t *ent)
ent->client->kick_angles[0] = -1;
VectorSet(offset, 8, 8, ent->viewheight-8);
P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
P_ProjectSource (ent, offset, forward, right, start);
if(ent->client->pers.fire_mode)
{
edict_t *target;
@ -1001,7 +1019,7 @@ void Blaster_Fire (edict_t *ent, vec3_t g_offset, int damage, qboolean hyper, in
AngleVectors (ent->client->v_angle, forward, right, NULL);
VectorSet(offset, 24, 8, ent->viewheight-8);
VectorAdd (offset, g_offset, offset);
P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
P_ProjectSource (ent, offset, forward, right, start);
VectorScale (forward, -2, ent->client->kick_origin);
ent->client->kick_angles[0] = -1;
@ -1187,7 +1205,7 @@ void Machinegun_Fire (edict_t *ent)
VectorAdd (ent->client->v_angle, ent->client->kick_angles, angles);
AngleVectors (angles, forward, right, NULL);
VectorSet(offset, 0, 8, ent->viewheight-8);
P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
P_ProjectSource (ent, offset, forward, right, start);
fire_bullet (ent, start, forward, damage, kick, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MOD_MACHINEGUN);
gi.WriteByte (svc_muzzleflash);
@ -1323,7 +1341,7 @@ void Chaingun_Fire (edict_t *ent)
r = 7 + crandom()*4;
u = crandom()*4;
VectorSet(offset, 0, r, u + ent->viewheight-8);
P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
P_ProjectSource (ent, offset, forward, right, start);
fire_bullet (ent, start, forward, damage, kick, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MOD_CHAINGUN);
}
@ -1378,7 +1396,7 @@ void weapon_shotgun_fire (edict_t *ent)
ent->client->kick_angles[0] = -2;
VectorSet(offset, 0, 8, ent->viewheight-8);
P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
P_ProjectSource (ent, offset, forward, right, start);
if (is_quad)
{
@ -1428,7 +1446,7 @@ void weapon_supershotgun_fire (edict_t *ent)
ent->client->kick_angles[0] = -2;
VectorSet(offset, 0, 8, ent->viewheight-8);
P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
P_ProjectSource (ent, offset, forward, right, start);
if (is_quad)
{
@ -1507,7 +1525,7 @@ void weapon_railgun_fire (edict_t *ent)
ent->client->kick_angles[0] = -3;
VectorSet(offset, 0, 7, ent->viewheight-8);
P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
P_ProjectSource (ent, offset, forward, right, start);
fire_rail (ent, start, forward, damage, kick);
// send muzzle flash
@ -1588,7 +1606,7 @@ void weapon_bfg_fire (edict_t *ent)
ent->client->v_dmg_time = level.time + DAMAGE_TIME;
VectorSet(offset, 8, 8, ent->viewheight-8);
P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
P_ProjectSource (ent, offset, forward, right, start);
fire_bfg (ent, start, forward, damage, 400, damage_radius);
ent->client->ps.gunframe++;
@ -1635,7 +1653,7 @@ void kick_attack (edict_t * ent )
VectorScale (forward, 0, ent->client->kick_origin);
VectorSet(offset, 0, 0, ent->viewheight-20);
P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
P_ProjectSource (ent, offset, forward, right, start);
VectorMA( start, 25, forward, end );