player.c: hitscan projectile handling cleanup continued.

git-svn-id: https://svn.eduke32.com/eduke32@3359 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2013-01-01 15:24:33 +00:00
parent 15b7444b46
commit f65f547fef

View file

@ -336,7 +336,7 @@ static int32_t GetAutoAimAngle(int32_t i, int32_t p, int32_t atwith,
const vec3_t *srcvect, int32_t vel, const vec3_t *srcvect, int32_t vel,
int32_t *zvel, int16_t *sa) int32_t *zvel, int16_t *sa)
{ {
int32_t j; int32_t j = -1;
Bassert((unsigned)p < MAXPLAYERS); Bassert((unsigned)p < MAXPLAYERS);
@ -345,7 +345,6 @@ static int32_t GetAutoAimAngle(int32_t i, int32_t p, int32_t atwith,
if (G_HaveEvent(EVENT_GETAUTOAIMANGLE)) if (G_HaveEvent(EVENT_GETAUTOAIMANGLE))
VM_OnEvent(EVENT_GETAUTOAIMANGLE, i, p, -1, 0); VM_OnEvent(EVENT_GETAUTOAIMANGLE, i, p, -1, 0);
j = -1;
{ {
int32_t aimang = Gv_GetVar(g_iAimAngleVarID, i, p); int32_t aimang = Gv_GetVar(g_iAimAngleVarID, i, p);
if (aimang > 0) if (aimang > 0)
@ -385,26 +384,37 @@ static void Proj_MaybeSpawn(int32_t k, int32_t atwith, const hitdata_t *hit)
if (ProjectileData[atwith].spawns >= 0) if (ProjectileData[atwith].spawns >= 0)
{ {
int32_t wh = A_Spawn(k,ProjectileData[atwith].spawns); int32_t wh = A_Spawn(k,ProjectileData[atwith].spawns);
if (ProjectileData[atwith].sxrepeat > 4) sprite[wh].xrepeat=ProjectileData[atwith].sxrepeat;
if (ProjectileData[atwith].syrepeat > 4) sprite[wh].yrepeat=ProjectileData[atwith].syrepeat; if (ProjectileData[atwith].sxrepeat > 4)
sprite[wh].xrepeat = ProjectileData[atwith].sxrepeat;
if (ProjectileData[atwith].syrepeat > 4)
sprite[wh].yrepeat = ProjectileData[atwith].syrepeat;
A_SetHitData(wh, hit); A_SetHitData(wh, hit);
} }
} }
static int32_t Proj_InsertShotspark(const hitdata_t *hit, int32_t i, int32_t atwith, int32_t sz, int32_t ang) static int32_t Proj_InsertShotspark(const hitdata_t *hit, int32_t i, int32_t atwith,
int32_t xyrepeat, int32_t ang, int32_t extra)
{ {
int32_t k = A_InsertSprite(hit->sect,hit->pos.x,hit->pos.y,hit->pos.z,SHOTSPARK1,-15, int32_t k = A_InsertSprite(hit->sect, hit->pos.x, hit->pos.y, hit->pos.z,
sz,sz,ang,0,0,i,4); SHOTSPARK1,-15, xyrepeat,xyrepeat, ang,0,0,i,4);
sprite[k].extra = extra;
sprite[k].extra = ProjectileData[atwith].extra; // This is a hack to allow you to detect which weapon spawned a SHOTSPARK1:
if (ProjectileData[atwith].extra_rand > 0) sprite[k].yvel = atwith;
sprite[k].extra += (krand()%ProjectileData[atwith].extra_rand);
sprite[k].yvel = atwith; // this is a hack to allow you to detect which weapon spawned a SHOTSPARK1
A_SetHitData(k, hit); A_SetHitData(k, hit);
return k; return k;
} }
static int32_t Proj_GetExtra(int32_t atwith)
{
int32_t extra = ProjectileData[atwith].extra;
if (ProjectileData[atwith].extra_rand > 0)
extra += (krand()%ProjectileData[atwith].extra_rand);
return extra;
}
static void Proj_MaybeAddSpread(int32_t not_accurate_p, int32_t *zvel, int16_t *sa, static void Proj_MaybeAddSpread(int32_t not_accurate_p, int32_t *zvel, int16_t *sa,
int32_t zRange, int32_t angRange) int32_t zRange, int32_t angRange)
{ {
@ -506,6 +516,27 @@ static void A_PreFireHitscan(const spritetype *s, vec3_t *srcvect, int32_t *zvel
} }
} }
static inline int32_t Proj_DoHitscan(int32_t i, int32_t cstatmask,
const vec3_t *srcvect, int32_t zvel, int16_t sa,
hitdata_t *hit)
{
spritetype *const s = &sprite[i];
s->cstat &= ~cstatmask;
if (actor[i].shootzvel)
zvel = actor[i].shootzvel;
hitscan(srcvect, s->sectnum,
sintable[(sa+512)&2047],
sintable[sa&2047],
zvel<<6, hit, CLIPMASK1);
s->cstat |= cstatmask;
return (hit->sect < 0);
}
int32_t A_Shoot(int32_t i, int32_t atwith) int32_t A_Shoot(int32_t i, int32_t atwith)
{ {
int16_t l, sa, j, k=-1; int16_t l, sa, j, k=-1;
@ -798,23 +829,12 @@ int32_t A_Shoot(int32_t i, int32_t atwith)
A_PreFireHitscan(s, &srcvect, &zvel, &sa, A_PreFireHitscan(s, &srcvect, &zvel, &sa,
!(ProjectileData[atwith].workslike & PROJECTILE_ACCURATE)); !(ProjectileData[atwith].workslike & PROJECTILE_ACCURATE));
if (ProjectileData[atwith].cstat >= 0) s->cstat &= ~ProjectileData[atwith].cstat; if (Proj_DoHitscan(i, (ProjectileData[atwith].cstat >= 0) ? ProjectileData[atwith].cstat : 256+1,
else s->cstat &= ~257; &srcvect, zvel, sa, &hit))
return -1;
if (actor[i].shootzvel) zvel = actor[i].shootzvel; if (ProjectileData[atwith].range > 0 &&
hitscan((const vec3_t *)&srcvect,sect, klabs(srcvect.x-hit.pos.x)+klabs(srcvect.y-hit.pos.y) > ProjectileData[atwith].range)
sintable[(sa+512)&2047],
sintable[sa&2047],
zvel<<6,&hit,CLIPMASK1);
if (ProjectileData[atwith].cstat >= 0) s->cstat |= ProjectileData[atwith].cstat;
else s->cstat |= 257;
if (hit.sect < 0) return -1;
if ((ProjectileData[atwith].range > 0) &&
((klabs(srcvect.x-hit.pos.x)+klabs(srcvect.y-hit.pos.y)) > ProjectileData[atwith].range))
return -1; return -1;
if (ProjectileData[atwith].trail >= 0) if (ProjectileData[atwith].trail >= 0)
@ -823,12 +843,13 @@ int32_t A_Shoot(int32_t i, int32_t atwith)
if (ProjectileData[atwith].workslike & PROJECTILE_WATERBUBBLES) if (ProjectileData[atwith].workslike & PROJECTILE_WATERBUBBLES)
{ {
if ((krand()&15) == 0 && sector[hit.sect].lotag == ST_2_UNDERWATER) if ((krand()&15) == 0 && sector[hit.sect].lotag == ST_2_UNDERWATER)
A_DoWaterTracers(hit.pos.x,hit.pos.y,hit.pos.z,srcvect.x,srcvect.y,srcvect.z,8-(ud.multimode>>1)); A_DoWaterTracers(hit.pos.x,hit.pos.y,hit.pos.z,
srcvect.x,srcvect.y,srcvect.z,8-(ud.multimode>>1));
} }
if (p >= 0) if (p >= 0)
{ {
k = Proj_InsertShotspark(&hit, i, atwith, 10, sa); k = Proj_InsertShotspark(&hit, i, atwith, 10, sa, Proj_GetExtra(atwith));
if (hit.wall == -1 && hit.sprite == -1) if (hit.wall == -1 && hit.sprite == -1)
{ {
@ -956,7 +977,7 @@ DOSKIPBULLETHOLE:
} }
else else
{ {
k = Proj_InsertShotspark(&hit, i, atwith, 24, sa); k = Proj_InsertShotspark(&hit, i, atwith, 24, sa, Proj_GetExtra(atwith));
if (hit.sprite >= 0) if (hit.sprite >= 0)
{ {
@ -1223,15 +1244,8 @@ DOSKIPBULLETHOLE:
else else
A_PreFireHitscan(s, &srcvect, &zvel, &sa, 1); A_PreFireHitscan(s, &srcvect, &zvel, &sa, 1);
s->cstat &= ~257; if (Proj_DoHitscan(i, 256+1, &srcvect, zvel, sa, &hit))
if (actor[i].shootzvel) zvel = actor[i].shootzvel; return -1;
hitscan((const vec3_t *)&srcvect,sect,
sintable[(sa+512)&2047],
sintable[sa&2047],
zvel<<6,&hit,CLIPMASK1);
s->cstat |= 257;
if (hit.sect < 0) return -1;
if ((krand()&15) == 0 && sector[hit.sect].lotag == ST_2_UNDERWATER) if ((krand()&15) == 0 && sector[hit.sect].lotag == ST_2_UNDERWATER)
A_DoWaterTracers(hit.pos.x,hit.pos.y,hit.pos.z, A_DoWaterTracers(hit.pos.x,hit.pos.y,hit.pos.z,
@ -1239,12 +1253,8 @@ DOSKIPBULLETHOLE:
if (p >= 0) if (p >= 0)
{ {
k = A_InsertSprite(hit.sect,hit.pos.x,hit.pos.y,hit.pos.z,SHOTSPARK1,-15,10,10,sa,0,0,i,4); k = Proj_InsertShotspark(&hit, i, atwith, 10, sa,
sprite[k].extra = G_InitialActorStrength(atwith); G_InitialActorStrength(atwith) + (krand()%6));
sprite[k].extra += (krand()%6);
sprite[k].yvel = atwith; // this is a hack to allow you to detect which weapon spawned a SHOTSPARK1
A_SetHitData(k, &hit);
if (hit.wall == -1 && hit.sprite == -1) if (hit.wall == -1 && hit.sprite == -1)
{ {
@ -1266,8 +1276,9 @@ DOSKIPBULLETHOLE:
if (hit.sprite >= 0) if (hit.sprite >= 0)
{ {
A_DamageObject(hit.sprite,k); A_DamageObject(hit.sprite,k);
if (sprite[hit.sprite].picnum == APLAYER && (ud.ffire == 1 || (!GTFLAGS(GAMETYPE_PLAYERSFRIENDLY) && if (sprite[hit.sprite].picnum == APLAYER &&
GTFLAGS(GAMETYPE_TDM) && g_player[sprite[hit.sprite].yvel].ps->team != g_player[sprite[i].yvel].ps->team))) (ud.ffire == 1 || (!GTFLAGS(GAMETYPE_PLAYERSFRIENDLY) && GTFLAGS(GAMETYPE_TDM) &&
g_player[sprite[hit.sprite].yvel].ps->team != g_player[sprite[i].yvel].ps->team)))
{ {
l = A_Spawn(k,JIBS6); l = A_Spawn(k,JIBS6);
sprite[k].xrepeat = sprite[k].yrepeat = 0; sprite[k].xrepeat = sprite[k].yrepeat = 0;
@ -1329,6 +1340,8 @@ DOSKIPBULLETHOLE:
goto SKIPBULLETHOLE; goto SKIPBULLETHOLE;
l = nextspritestat[l]; l = nextspritestat[l];
} }
{
l = A_Spawn(k,BULLETHOLE); l = A_Spawn(k,BULLETHOLE);
if (!A_CheckSpriteFlags(l , SPRITE_DECAL)) if (!A_CheckSpriteFlags(l , SPRITE_DECAL))
@ -1346,6 +1359,7 @@ DOSKIPBULLETHOLE:
sprite[l].y -= mulscale13(1,sintable[(sprite[l].ang+2048)&2047]); sprite[l].y -= mulscale13(1,sintable[(sprite[l].ang+2048)&2047]);
A_SetSprite(l,CLIPMASK0); A_SetSprite(l,CLIPMASK0);
} }
}
SKIPBULLETHOLE: SKIPBULLETHOLE:
@ -1359,10 +1373,7 @@ SKIPBULLETHOLE:
} }
else else
{ {
k = A_InsertSprite(hit.sect,hit.pos.x,hit.pos.y,hit.pos.z,SHOTSPARK1,-15,24,24,sa,0,0,i,4); k = Proj_InsertShotspark(&hit, i, atwith, 24, sa, G_InitialActorStrength(atwith));
sprite[k].extra = G_InitialActorStrength(atwith);
sprite[k].yvel = atwith; // this is a hack to allow you to detect which weapon spawned a SHOTSPARK1
A_SetHitData(k, &hit);
if (hit.sprite >= 0) if (hit.sprite >= 0)
{ {