From 99894812d8445b5e21247e51e8c0e872ffd1200d Mon Sep 17 00:00:00 2001 From: helixhorned Date: Fri, 20 Dec 2013 18:31:26 +0000 Subject: [PATCH] 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 --- polymer/eduke32/source/actors.c | 63 ++++++++++++---------- polymer/eduke32/source/lunatic/control.lua | 1 - polymer/eduke32/source/lunatic/test.lua | 4 +- polymer/eduke32/source/player.c | 34 ++++++++---- 4 files changed, 59 insertions(+), 43 deletions(-) diff --git a/polymer/eduke32/source/actors.c b/polymer/eduke32/source/actors.c index 3ac735349..e805a69c3 100644 --- a/polymer/eduke32/source/actors.c +++ b/polymer/eduke32/source/actors.c @@ -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]; wx-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 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,15 +2894,10 @@ ACTOR_STATIC void Proj_MoveCustom(int32_t i) case 16384: setsprite(i, &davect); - if (s->zvel < 0) + if (Proj_MaybeDamageCF(s)) { - if (sector[s->sectnum].ceilingstat&1 && sector[s->sectnum].ceilingpal == 0) - { - A_DeleteSprite(i); - return; - } - - Sect_DamageCeiling(s->sectnum); + A_DeleteSprite(i); + return; } if (proj->workslike & PROJECTILE_BOUNCESOFFWALLS) @@ -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,14 +3143,8 @@ 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) - KILLIT(i); - - Sect_DamageCeiling(s->sectnum); - } + if (Proj_MaybeDamageCF(s)) + KILLIT(i); if (s->picnum == FREEZEBLAST) { diff --git a/polymer/eduke32/source/lunatic/control.lua b/polymer/eduke32/source/lunatic/control.lua index 6f8648def..357cadda4 100644 --- a/polymer/eduke32/source/lunatic/control.lua +++ b/polymer/eduke32/source/lunatic/control.lua @@ -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 diff --git a/polymer/eduke32/source/lunatic/test.lua b/polymer/eduke32/source/lunatic/test.lua index 237cbe486..19042b882 100644 --- a/polymer/eduke32/source/lunatic/test.lua +++ b/polymer/eduke32/source/lunatic/test.lua @@ -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 diff --git a/polymer/eduke32/source/player.c b/polymer/eduke32/source/player.c index 5018ba42e..e1bbc2b44 100644 --- a/polymer/eduke32/source/player.c +++ b/polymer/eduke32/source/player.c @@ -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

. is the inserted SHOTSPARK1. // * is passed to Proj_MaybeSpawn() // * and are for wall impact @@ -614,16 +632,11 @@ 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 (Proj_MaybeDamageCF2(zvel, hit->sect)) { - if (sector[hit->sect].ceilingstat&1) - { - sprite[k].xrepeat = 0; - sprite[k].yrepeat = 0; - return -1; - } - else - Sect_DamageCeiling(hit->sect); + sprite[k].xrepeat = 0; + sprite[k].yrepeat = 0; + return -1; } 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)