Implement accurate-aiming CVAR in xatrix game code.

This commit is contained in:
Mitchell Richters 2020-04-21 07:28:18 +10:00
parent 3a073766c7
commit 2f105cdbe3
4 changed files with 39 additions and 15 deletions

View file

@ -62,6 +62,8 @@ cvar_t *sv_maplist;
cvar_t *gib_on;
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

@ -535,6 +535,8 @@ extern cvar_t *flood_waitdelay;
extern cvar_t *sv_maplist;
extern cvar_t *aimfix;
#define world (&g_edicts[0])
/* item spawnflags */

View file

@ -28,9 +28,11 @@ void weapon_grenade_fire(edict_t *ent, qboolean held);
void weapon_trap_fire(edict_t *ent, qboolean held);
void
P_ProjectSource(gclient_t *client, vec3_t point, vec3_t distance,
P_ProjectSource(edict_t *ent, vec3_t distance,
vec3_t forward, vec3_t right, vec3_t result)
{
gclient_t *client = ent->client;
float *point = ent->s.origin;
vec3_t _distance;
if (!client)
@ -50,6 +52,21 @@ P_ProjectSource(gclient_t *client, vec3_t point, vec3_t distance,
}
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);
}
}
}
/*
@ -746,7 +763,7 @@ 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) *
@ -943,7 +960,7 @@ 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;
@ -1013,7 +1030,7 @@ 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);
fire_rocket(ent, start, forward, damage, 650, damage_radius, radius_damage);
/* send muzzle flash */
@ -1076,7 +1093,7 @@ Blaster_Fire(edict_t *ent, vec3_t g_offset, int damage,
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;
@ -1341,7 +1358,7 @@ 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);
@ -1523,7 +1540,7 @@ 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,
P_ProjectSource(ent, offset, forward,
right, start);
fire_bullet(ent, start, forward, damage, kick, DEFAULT_BULLET_HSPREAD,
@ -1592,7 +1609,7 @@ 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)
{
@ -1660,7 +1677,7 @@ 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)
{
@ -1755,7 +1772,7 @@ 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 */
@ -1855,7 +1872,7 @@ 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++;
@ -1932,7 +1949,7 @@ weapon_ionripper_fire(edict_t *ent)
VectorSet(offset, 16, 7, ent->viewheight - 8);
P_ProjectSource(ent->client, ent->s.origin, offset, forward, right, start);
P_ProjectSource(ent, offset, forward, right, start);
fire_ionripper(ent, start, forward, damage, 500, EF_IONRIPPER);
@ -2012,7 +2029,7 @@ weapon_phalanx_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 (ent->client->ps.gunframe == 8)
{
@ -2101,7 +2118,7 @@ weapon_trap_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) *

View file

@ -235,6 +235,9 @@ InitGame(void)
/* dm map list */
sv_maplist = gi.cvar ("sv_maplist", "", 0);
/* others */
aimfix = gi.cvar("aimfix", "0", CVAR_ARCHIVE);
/* items */
InitItems ();