Fix a couple of issues identified in the preceding commit.

- In S_PlaySound(), move the sound index bound check above an indexing.
- For A_CheckHitSprite(), and A_FindPlayer(), allow NULL second arg.
- In A_ShootWithZvel(), make some one-letter vars be int32_t, making
  storing safeldist() results in them meaningful.
- In MaybeTrainKillEnemies(), remove two redundant checks and move another
  one further up.
- Comment that SIDEBOLT1 will never be translucent as was probably intended.
- In G_MoveFX(), fix an always-true comparison.

git-svn-id: https://svn.eduke32.com/eduke32@3680 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2013-04-15 10:48:13 +00:00
parent 8064bd2f30
commit 3b39a87bd1
6 changed files with 43 additions and 39 deletions

View file

@ -765,7 +765,7 @@ static void A_MoveSector(int32_t i)
}
}
#ifndef LUNATIC
#if !defined LUNATIC
# define LIGHTRAD_PICOFS (T5 ? *(script+T5) + (*(script+T5+2))*T4 : 0)
#else
// SACTION
@ -1367,9 +1367,7 @@ ACTOR_STATIC void G_MoveFX(void)
int32_t j;
for (SPRITES_OF(STAT_FX, j))
// XXX: PN is sprite[*i*].picnum
if (PN == MUSICANDSFX && j != i && sprite[j].lotag < 999 &&
actor[j].t_data[0] == 1 &&
if (j != i && S_IsAmbientSFX(j) && actor[j].t_data[0] == 1 &&
dist(&sprite[j], &sprite[peekps->i]) > x)
{
S_StopEnvSound(sprite[j].lotag,j);
@ -1522,8 +1520,6 @@ ACTOR_STATIC void G_MoveStandables(void)
int32_t i = headspritestat[STAT_STANDABLE], j, switchpicnum;
int32_t l=0, x;
int16_t m;
while (i >= 0)
{
const int32_t nexti = nextspritestat[i];
@ -1603,8 +1599,7 @@ ACTOR_STATIC void G_MoveStandables(void)
{
if (s->owner==-2)
{
// XXX: A_FindPlayer() often called with unused *d / x
int32_t p = A_FindPlayer(s,&x);
int32_t p = A_FindPlayer(s, NULL);
A_PlaySound(DUKE_GRUNT,g_player[p].ps->i);
if (g_player[p].ps->on_crane == i)
g_player[p].ps->on_crane = -1;
@ -1692,9 +1687,9 @@ ACTOR_STATIC void G_MoveStandables(void)
if (s->owner != -1)
{
int32_t p = A_FindPlayer(s,&x);
int32_t p = A_FindPlayer(s, NULL);
if ((j = A_IncurDamage(i)) >= 0)
if (A_IncurDamage(i) >= 0)
{
if (s->owner == -2)
if (g_player[p].ps->on_crane == i)
@ -1861,6 +1856,9 @@ ACTOR_STATIC void G_MoveStandables(void)
break;
case 32:
{
int16_t m;
l = s->ang;
s->ang = T6;
@ -1873,7 +1871,7 @@ ACTOR_STATIC void G_MoveStandables(void)
setsprite(i,(vec3_t *)s);
x = A_CheckHitSprite(i,&m);
x = A_CheckHitSprite(i, &m);
actor[i].lastvx = x;
@ -1925,6 +1923,7 @@ ACTOR_STATIC void G_MoveStandables(void)
A_PlaySound(LASERTRIP_ARMING,i);
}
break;
}
case 33:
T2++;
@ -1938,8 +1937,7 @@ ACTOR_STATIC void G_MoveStandables(void)
setsprite(i,(vec3_t *)s);
// XXX: m unused
x = A_CheckHitSprite(i,&m);
x = A_CheckHitSprite(i, NULL);
s->x = T4;
s->y = T5;
@ -2258,7 +2256,8 @@ CLEAR_THE_BOLT2:
}
s->picnum++;
// XXX: Um, was this 'l' assigned to last at the beginning of this function?
// NOTE: Um, this 'l' was assigned to last at the beginning of this function.
// SIDEBOLT1 never gets translucent as a consequence, unlike BOLT1.
if (l&1) s->cstat ^= 2;
if ((krand()&1) && sector[sect].floorpicnum == HURTRAIL)
@ -5560,13 +5559,12 @@ static void MaybeTrainKillEnemies(int32_t i, int32_t numguts)
{
const int32_t nextj = nextspritesect[j];
if (sprite[j].statnum == STAT_ACTOR && A_CheckEnemySprite(&sprite[j]) &&
sprite[j].picnum != SECTOREFFECTOR && sprite[j].picnum != LOCATORS)
if (sprite[j].extra >= 0 && sprite[j].statnum == STAT_ACTOR && A_CheckEnemySprite(&sprite[j]))
{
int16_t k = sprite[j].sectnum;
updatesector(sprite[j].x,sprite[j].y,&k);
if (sprite[j].extra >= 0 && k == sprite[i].sectnum)
if (k == sprite[i].sectnum)
{
A_DoGutsDir(j,JIBS6,numguts);
A_PlaySound(SQUISHED,j);
@ -6220,8 +6218,6 @@ ACTOR_STATIC void G_MoveEffectors(void) //STATNUM 3
case 3:
{
if (t[4] == 0) break;
A_FindPlayer(s,&x);
// XXX: x is dead here; A_FindPlayer() call necessary?
// if(t[5] > 0) { t[5]--; break; }
@ -7479,7 +7475,7 @@ ACTOR_STATIC void G_MoveEffectors(void) //STATNUM 3
sprite[j].cstat &= 32767;
A_Spawn(j,SMALLSMOKE);
p = A_FindPlayer(s,&x);
p = A_FindPlayer(s, NULL);
ps = g_player[p].ps;
x = ldist(&sprite[ps->i], &sprite[j]);

View file

@ -3968,7 +3968,6 @@ finish_qsprintf:
insptr++;
{
int32_t j;
// Gv_SetVarX(g_iReturnVarID, A_FindPlayer(&sprite[vm.g_i],&j));
aGameVars[g_iReturnVarID].val.lValue = A_FindPlayer(&sprite[vm.g_i],&j);
Gv_SetVarX(*insptr++, j);
}

View file

@ -1283,6 +1283,7 @@ function _movesprite(spritenum, x, y, z, cliptype)
return ffiC.A_MoveSprite(spritenum, vel, cliptype)
end
-- NOTE: returns two args (in C version, hit sprite is a pointer input arg)
local function A_CheckHitSprite(spr, angadd)
local zoff = (spr:isenemy() and 42*256) or (spr.picnum==D.APLAYER and 39*256) or 0

View file

@ -521,11 +521,10 @@ static void P_PreFireHitscan(int32_t i, int32_t p, int32_t atwith,
static void A_PreFireHitscan(const spritetype *s, vec3_t *srcvect, int32_t *zvel, int16_t *sa,
int32_t not_accurate_p)
{
int32_t dummydist;
const int32_t j = A_FindPlayer(s, &dummydist);
const int32_t j = A_FindPlayer(s, NULL);
const DukePlayer_t *targetps = g_player[j].ps;
int32_t d = safeldist(targetps->i, s);
const int32_t d = safeldist(targetps->i, s);
*zvel = ((targetps->pos.z-srcvect->z)<<8) / d;
srcvect->z -= (4<<8);
@ -826,8 +825,9 @@ static void Proj_HandleKnee(hitdata_t *hit, int32_t i, int32_t p, int32_t atwith
#define MinibossScale(s) (((s)*sprite[i].yrepeat)/80)
int32_t A_ShootWithZvel(int32_t i, int32_t atwith, int32_t override_zvel)
{
int16_t l, sa, j, k=-1;
int32_t vel, zvel = 0, x, oldzvel;
int16_t sa;
int32_t j, k=-1, l;
int32_t vel, zvel = 0;
hitdata_t hit;
vec3_t srcvect;
spritetype *const s = &sprite[i];
@ -937,6 +937,7 @@ int32_t A_ShootWithZvel(int32_t i, int32_t atwith, int32_t override_zvel)
}
else if (!(proj->workslike & PROJECTILE_NOAIM))
{
int32_t x;
j = g_player[A_FindPlayer(s,&x)].ps->i;
zvel = ((sprite[j].z-srcvect.z)<<8) / (x+1);
sa = getangle(sprite[j].x-srcvect.x,sprite[j].y-srcvect.y);
@ -1091,7 +1092,7 @@ int32_t A_ShootWithZvel(int32_t i, int32_t atwith, int32_t override_zvel)
{
if (!(proj->workslike & PROJECTILE_NOAIM))
{
j = A_FindPlayer(s,&x);
j = A_FindPlayer(s, NULL);
sa = getangle(g_player[j].ps->opos.x-srcvect.x,g_player[j].ps->opos.y-srcvect.y);
l = safeldist(g_player[j].ps->i, s);
@ -1164,6 +1165,7 @@ int32_t A_ShootWithZvel(int32_t i, int32_t atwith, int32_t override_zvel)
}
else
{
int32_t x;
j = g_player[A_FindPlayer(s,&x)].ps->i;
zvel = ((sprite[j].z-srcvect.z)<<8) / (x+1);
sa = getangle(sprite[j].x-srcvect.x,sprite[j].y-srcvect.y);
@ -1283,7 +1285,7 @@ int32_t A_ShootWithZvel(int32_t i, int32_t atwith, int32_t override_zvel)
}
else
{
j = A_FindPlayer(s,&x);
j = A_FindPlayer(s, NULL);
// sa = getangle(g_player[j].ps->opos.x-sx,g_player[j].ps->opos.y-sy);
sa += 16-(krand()&31);
hit.pos.x = safeldist(g_player[j].ps->i, s);
@ -1291,7 +1293,6 @@ int32_t A_ShootWithZvel(int32_t i, int32_t atwith, int32_t override_zvel)
}
zvel = A_GetShootZvel(i, zvel);
oldzvel = zvel; // NOTE: assigned to after last store to zvel, so redundant
if (atwith == SPIT)
{
@ -1334,7 +1335,7 @@ int32_t A_ShootWithZvel(int32_t i, int32_t atwith, int32_t override_zvel)
sprite[j].clipdist = 4;
sa = s->ang+32-(krand()&63);
zvel = oldzvel+512-(krand()&1023);
zvel += 512-(krand()&1023);
return j;
}
@ -1342,7 +1343,7 @@ int32_t A_ShootWithZvel(int32_t i, int32_t atwith, int32_t override_zvel)
case FREEZEBLAST__STATIC:
srcvect.z += (3<<8);
case RPG__STATIC:
// XXX: "CODEDUP"
if (s->extra >= 0) s->shade = -96;
vel = 644;
@ -1361,7 +1362,7 @@ int32_t A_ShootWithZvel(int32_t i, int32_t atwith, int32_t override_zvel)
}
else
{
j = A_FindPlayer(s,&x);
j = A_FindPlayer(s, NULL);
sa = getangle(g_player[j].ps->opos.x-srcvect.x,g_player[j].ps->opos.y-srcvect.y);
if (PN == BOSS3)
srcvect.z -= MinibossScale(32<<8);
@ -1531,12 +1532,15 @@ int32_t A_ShootWithZvel(int32_t i, int32_t atwith, int32_t override_zvel)
}
return j?k:-1;
}
case BOUNCEMINE__STATIC:
case MORTER__STATIC:
{
int32_t x;
if (s->extra >= 0) s->shade = -96;
j = g_player[A_FindPlayer(s,&x)].ps->i;
j = g_player[A_FindPlayer(s, NULL)].ps->i;
x = ldist(&sprite[j],s);
zvel = -x>>1;
@ -1551,6 +1555,7 @@ int32_t A_ShootWithZvel(int32_t i, int32_t atwith, int32_t override_zvel)
srcvect.y+(sintable[(sa+512)&2047]>>8),
srcvect.z+(6<<8),atwith,-64,32,32,sa,vel,zvel,i,1);
break;
}
case GROWSPARK__STATIC:
@ -1569,7 +1574,7 @@ int32_t A_ShootWithZvel(int32_t i, int32_t atwith, int32_t override_zvel)
}
else
{
j = A_FindPlayer(s,&x);
j = A_FindPlayer(s, NULL);
srcvect.z -= (4<<8);
hit.pos.x = safeldist(g_player[j].ps->i, s);
zvel = ((g_player[j].ps->pos.z-srcvect.z) <<8) / hit.pos.x;
@ -1632,7 +1637,7 @@ int32_t A_ShootWithZvel(int32_t i, int32_t atwith, int32_t override_zvel)
}
else if (s->statnum != STAT_EFFECTOR)
{
j = A_FindPlayer(s,&x);
j = A_FindPlayer(s, NULL);
l = safeldist(g_player[j].ps->i, s);
zvel = ((g_player[j].ps->opos.z-srcvect.z)*512) / l ;
}

View file

@ -205,7 +205,8 @@ int32_t __fastcall A_FindPlayer(const spritetype *s, int32_t *d)
{
DukePlayer_t *const myps = g_player[myconnectindex].ps;
*d = A_FP_ManhattanDist(myps, s);
if (d)
*d = A_FP_ManhattanDist(myps, s);
return myconnectindex;
}
@ -225,7 +226,8 @@ int32_t __fastcall A_FindPlayer(const spritetype *s, int32_t *d)
}
}
*d = closest;
if (d)
*d = closest;
return closest_player;
}
}
@ -2965,7 +2967,8 @@ int32_t A_CheckHitSprite(int32_t i, int16_t *hitsp)
0,&hit,CLIPMASK1);
SZ += zoff;
*hitsp = hit.sprite;
if (hitsp)
*hitsp = hit.sprite;
if (hit.wall >= 0 && (wall[hit.wall].cstat&16) && A_CheckEnemySprite(&sprite[i]))
return 1<<30;

View file

@ -705,7 +705,6 @@ int32_t S_PlaySound(int32_t num)
if (ud.config.FXDevice < 0) return -1;
if (ud.config.SoundToggle==0) return -1;
if (!(ud.config.VoiceToggle&1) && (g_sounds[num].m&4)) return -1;
if ((unsigned)num > (unsigned)g_maxSoundPos || (g_sounds[num].filename == NULL && g_sounds[num].filename1 == NULL))
{
@ -713,6 +712,7 @@ int32_t S_PlaySound(int32_t num)
return -1;
}
if (!(ud.config.VoiceToggle&1) && (g_sounds[num].m&4)) return -1;
if ((g_sounds[num].m&8) && ud.lockout) return -1;
if (FX_VoiceAvailable(g_sounds[num].pr) == 0) return -1;