Minor no-functionality-changing tweaks.

- factor out: G_WallSpriteDist()
- factor out: Proj_MaybeDamageCF() and Proj_MaybeDamageCF2()
  in preparation for the next commit
- Make PROJ_DECAYVELOCITY macro take an arg for readability's sake

git-svn-id: https://svn.eduke32.com/eduke32@4204 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2013-12-20 18:31:26 +00:00
parent 0f6e22e20e
commit 99894812d8
4 changed files with 59 additions and 43 deletions

View file

@ -107,6 +107,12 @@ void G_ClearCameraView(DukePlayer_t *ps)
sprite[k].yvel = 0;
}
// Manhattan distance between wall-point and sprite.
static int32_t G_WallSpriteDist(const walltype *wal, const spritetype *spr)
{
return klabs(wal->x - spr->x) + klabs(wal->y - spr->y);
}
void A_RadiusDamage(int32_t i, int32_t r, int32_t hp1, int32_t hp2, int32_t hp3, int32_t hp4)
{
int32_t d, q, stati;
@ -143,19 +149,13 @@ void A_RadiusDamage(int32_t i, int32_t r, int32_t hp1, int32_t hp2, int32_t hp3,
{
const int32_t w2 = wall[startwall].point2;
d = klabs(wall[startwall].x-s->x)+klabs(wall[startwall].y-s->y);
if (d < r)
if (G_WallSpriteDist(&wall[startwall], s) < r ||
G_WallSpriteDist(&wall[wall[w2].point2], s) < r)
Sect_DamageCeiling(dasect);
else
{
d = klabs(wall[wall[w2].point2].x-s->x)+klabs(wall[wall[w2].point2].y-s->y);
if (d < r)
Sect_DamageCeiling(dasect);
}
}
for (w=startwall,wal=&wall[startwall]; w<endwall; w++,wal++)
if ((klabs(wal->x-s->x)+klabs(wal->y-s->y)) < r)
if (G_WallSpriteDist(wal, s) < r)
{
int16_t sect = -1;
const int32_t nextsect = wal->nextsector;
@ -2650,7 +2650,23 @@ static void Proj_BounceOffWall(spritetype *s, int32_t j)
s->ang = ((k<<1) - s->ang)&2047;
}
#define PROJ_DECAYVELOCITY s->xvel >>= 1, s->zvel >>= 1
#define PROJ_DECAYVELOCITY(s) s->xvel >>= 1, s->zvel >>= 1
// Maybe damage a ceiling or floor as the consequence of projectile impact.
// Returns 1 if sprite <s> should be killed.
// NOTE: Compare with Proj_MaybeDamageCF2() in sector.c
static int32_t Proj_MaybeDamageCF(const spritetype *s)
{
if (s->zvel < 0)
{
if ((sector[s->sectnum].ceilingstat&1) && sector[s->sectnum].ceilingpal == 0)
return 1;
Sect_DamageCeiling(s->sectnum);
}
return 0;
}
ACTOR_STATIC void Proj_MoveCustom(int32_t i)
{
@ -2804,7 +2820,7 @@ ACTOR_STATIC void Proj_MoveCustom(int32_t i)
A_PlaySound(proj->bsound, i);
if (proj->workslike & PROJECTILE_LOSESVELOCITY)
PROJ_DECAYVELOCITY;
PROJ_DECAYVELOCITY(s);
if (!(proj->workslike & PROJECTILE_FORCEIMPACT))
return;
@ -2868,7 +2884,7 @@ ACTOR_STATIC void Proj_MoveCustom(int32_t i)
A_PlaySound(proj->bsound, i);
if (proj->workslike & PROJECTILE_LOSESVELOCITY)
PROJ_DECAYVELOCITY;
PROJ_DECAYVELOCITY(s);
return;
}
@ -2878,17 +2894,12 @@ ACTOR_STATIC void Proj_MoveCustom(int32_t i)
case 16384:
setsprite(i, &davect);
if (s->zvel < 0)
{
if (sector[s->sectnum].ceilingstat&1 && sector[s->sectnum].ceilingpal == 0)
if (Proj_MaybeDamageCF(s))
{
A_DeleteSprite(i);
return;
}
Sect_DamageCeiling(s->sectnum);
}
if (proj->workslike & PROJECTILE_BOUNCESOFFWALLS)
{
A_DoProjectileBounce(i);
@ -2900,7 +2911,7 @@ ACTOR_STATIC void Proj_MoveCustom(int32_t i)
A_PlaySound(proj->bsound, i);
if (proj->workslike & PROJECTILE_LOSESVELOCITY)
PROJ_DECAYVELOCITY;
PROJ_DECAYVELOCITY(s);
return;
}
@ -3132,15 +3143,9 @@ ACTOR_STATIC void G_MoveWeapons(void)
case 16384:
setsprite(i, &davect);
if (s->zvel < 0)
{
if (sector[s->sectnum].ceilingstat&1)
if (sector[s->sectnum].ceilingpal == 0)
if (Proj_MaybeDamageCF(s))
KILLIT(i);
Sect_DamageCeiling(s->sectnum);
}
if (s->picnum == FREEZEBLAST)
{
A_DoProjectileBounce(i);

View file

@ -1850,7 +1850,6 @@ function _setgamepalette(pli, basepal)
end
-- Map state persistence.
-- TODO: saving/restoration of per-player or per-actor gamevars.
function _savemapstate()
ffiC.G_SaveMapState()
end

View file

@ -684,7 +684,7 @@ local FADE_SPEED = {
5,
127, -- freezer; such a fast fade is not visible, but it clears any
-- existing one (if of higher priority)
[WEAPON.GROW] = 9.9, -- test banker's rouding -- should be like 10
[WEAPON.GROW] = 9.9, -- test banker's rounding -- should be like 10
}
-- Test player[]:fadecol(), a better palfrom.
@ -711,7 +711,7 @@ gameevent
function(aci, pli)
local ps = player[pli]
-- WARNING: This function uses INTERNAL interfaces.
-- WARNING: _pals in INTERNAL and off-limits to users!
local curf = ps._pals.f
if (curf > last_f) then
-- Starting a tint

View file

@ -599,6 +599,24 @@ static void HandleHitWall(hitdata_t *hit)
hit->wall = hitwal->nextwall;
}
// Maybe damage a ceiling or floor as the consequence of projectile impact.
// Returns 1 if projectile hit a parallaxed ceiling.
// NOTE: Compare with Proj_MaybeDamageCF() in actors.c
static int32_t Proj_MaybeDamageCF2(int32_t zvel, int32_t hitsect)
{
if (zvel < 0)
{
Bassert(hitsect >= 0);
if (sector[hitsect].ceilingstat&1)
return 1;
Sect_DamageCeiling(hitsect);
}
return 0;
}
// Finish shooting hitscan weapon from player <p>. <k> is the inserted SHOTSPARK1.
// * <spawnatimpacttile> is passed to Proj_MaybeSpawn()
// * <decaltile> and <damagewalltile> are for wall impact
@ -614,17 +632,12 @@ static int32_t P_PostFireHitscan(int32_t p, int32_t k, hitdata_t *hit, int32_t i
{
if (hit->wall == -1 && hit->sprite == -1)
{
if (zvel < 0)
{
if (sector[hit->sect].ceilingstat&1)
if (Proj_MaybeDamageCF2(zvel, hit->sect))
{
sprite[k].xrepeat = 0;
sprite[k].yrepeat = 0;
return -1;
}
else
Sect_DamageCeiling(hit->sect);
}
Proj_MaybeSpawn(k, spawnatimpacttile, hit);
}
@ -1272,8 +1285,7 @@ int32_t A_ShootWithZvel(int32_t i, int32_t atwith, int32_t override_zvel)
if (hit.wall == -1 && hit.sprite == -1 && hit.sect >= 0)
{
if (zvel < 0 && (sector[hit.sect].ceilingstat&1) == 0)
Sect_DamageCeiling(hit.sect);
Proj_MaybeDamageCF2(zvel, hit.sect);
}
else if (hit.sprite >= 0) A_DamageObject(hit.sprite,j);
else if (hit.wall >= 0 && wall[hit.wall].picnum != ACCESSSWITCH && wall[hit.wall].picnum != ACCESSSWITCH2)