From 1597cf5400e87689f18936786b9b5a70fafae56d Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 23 Dec 2022 10:49:41 +0100 Subject: [PATCH] - exported the grower's shoot function and moved stuff to a separate file. --- source/games/duke/src/player_d.cpp | 86 ------------------ wadsrc/static/zscript.txt | 1 + .../zscript/games/duke/actors/dukeitems.zs | 16 ---- .../games/duke/actors/dukeweapons/grower.zs | 88 +++++++++++++++++++ 4 files changed, 89 insertions(+), 102 deletions(-) create mode 100644 wadsrc/static/zscript/games/duke/actors/dukeweapons/grower.zs diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index 4b6a6180d..f184bc576 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -787,88 +787,6 @@ static void shootlaser(DDukeActor* actor, int p, DVector3 pos, DAngle ang) // //--------------------------------------------------------------------------- -static void shootgrowspark(DDukeActor* actor, int p, DVector3 pos, DAngle ang) -{ - auto sect = actor->sector(); - double vel = 1024., zvel; - int k; - HitInfo hit{}; - - if (p >= 0) - { - auto aimed = aim(actor, AUTO_AIM_ANGLE); - if (aimed) - { - auto tex = TexMan.GetGameTexture(aimed->spr.spritetexture()); - double dal = ((aimed->spr.scale.X * tex->GetDisplayHeight()) * 0.5) + 5; - switch (aimed->spr.picnum) - { - case DTILE_GREENSLIME: - case DTILE_ROTATEGUN: - dal -= 8; - break; - } - double dist = (ps[p].GetActor()->spr.pos.XY() - aimed->spr.pos.XY()).Length(); - zvel = ((aimed->spr.pos.Z - pos.Z - dal) * 16) / dist; - ang = (aimed->spr.pos.XY() - pos.XY()).Angle(); - } - else - { - ang += DAngle22_5 / 8 - randomAngle(22.5 / 4); - setFreeAimVelocity(vel, zvel, ps[p].Angles.getPitchWithView(), 16.); - zvel += 0.5 - krandf(1); - } - - pos.Z -= 2; - } - else - { - double x; - int j = findplayer(actor, &x); - pos.Z -= 4; - double dist = (ps[j].GetActor()->spr.pos.XY() - actor->spr.pos.XY()).Length(); - zvel = ((ps[j].GetActor()->getOffsetZ() - pos.Z) * 16) / dist; - zvel += 0.5 - krandf(1); - ang += DAngle22_5 / 4 - randomAngle(22.5 / 2); - } - - k = 0; - - //RESHOOTGROW: - - actor->spr.cstat &= ~CSTAT_SPRITE_BLOCK_ALL; - hitscan(pos, sect, DVector3(ang.ToVector() * vel, zvel * 64), hit, CLIPMASK1); - - actor->spr.cstat |= CSTAT_SPRITE_BLOCK_ALL; - - auto spark = CreateActor(sect, hit.hitpos, DTILE_GROWSPARK, -16, DVector2(0.4375, 0.4375), ang, 0., 0., actor, 1); - if (!spark) return; - - spark->spr.pal = 2; - spark->spr.cstat |= CSTAT_SPRITE_YCENTER | CSTAT_SPRITE_TRANSLUCENT; - spark->spr.scale = DVector2(REPEAT_SCALE, REPEAT_SCALE); - - if (hit.hitWall == nullptr && hit.actor() == nullptr && hit.hitSector != nullptr) - { - if (zvel < 0 && (hit.hitSector->ceilingstat & CSTAT_SECTOR_SKY) == 0) - checkhitceiling(hit.hitSector); - } - else if (hit.actor() != nullptr) checkhitsprite(hit.actor(), spark); - else if (hit.hitWall != nullptr) - { - if (!isaccessswitch(hit.hitWall->walltexture)) - { - checkhitwall(spark, hit.hitWall, hit.hitpos); - } - } -} - -//--------------------------------------------------------------------------- -// -// -// -//--------------------------------------------------------------------------- - static void shootmortar(DDukeActor* actor, int p, const DVector3& pos, DAngle ang, int atwith) { auto sect = actor->sector(); @@ -976,10 +894,6 @@ void shoot_d(DDukeActor* actor, int atwith, PClass *cls) case DTILE_MORTER: shootmortar(actor, p, spos, sang, atwith); return; - - case DTILE_GROWSPARK: - shootgrowspark(actor, p, spos, sang); - break; } return; } diff --git a/wadsrc/static/zscript.txt b/wadsrc/static/zscript.txt index feb9cecfb..093282cad 100644 --- a/wadsrc/static/zscript.txt +++ b/wadsrc/static/zscript.txt @@ -160,6 +160,7 @@ version "4.10" #include "zscript/games/duke/actors/dukeweapons/shrinker.zs" +#include "zscript/games/duke/actors/dukeweapons/grower.zs" #include "zscript/games/duke/world/dukebreak.zs" diff --git a/wadsrc/static/zscript/games/duke/actors/dukeitems.zs b/wadsrc/static/zscript/games/duke/actors/dukeitems.zs index 4dc0e9341..698f98e29 100644 --- a/wadsrc/static/zscript/games/duke/actors/dukeitems.zs +++ b/wadsrc/static/zscript/games/duke/actors/dukeitems.zs @@ -270,19 +270,3 @@ class DukeAccessCard : DukeItemBase } -class DukeGrowSpark : DukeActor -{ - default - { - spriteset "GROWSPARK", "GROWSPARK1", "GROWSPARK2", "GROWSPARK3"; - +FULLBRIGHT; - +NOFLOORPAL; - } - - override bool animate(tspritetype t) - { - t.setSpritePic(self, (PlayClock >> 4) & 3); - return true; - } -} - diff --git a/wadsrc/static/zscript/games/duke/actors/dukeweapons/grower.zs b/wadsrc/static/zscript/games/duke/actors/dukeweapons/grower.zs new file mode 100644 index 000000000..213c83df4 --- /dev/null +++ b/wadsrc/static/zscript/games/duke/actors/dukeweapons/grower.zs @@ -0,0 +1,88 @@ + +class DukeGrowSpark : DukeActor +{ + default + { + spriteset "GROWSPARK", "GROWSPARK1", "GROWSPARK2", "GROWSPARK3"; + +FULLBRIGHT; + +NOFLOORPAL; + } + + + override bool ShootThis(DukeActor shooter, DukePlayer p, Vector3 pos, double ang) const + { + let sect = shooter.sector; + double vel = 1024., zvel; + int k; + HitInfo hit; + + if (p != null) + { + let aimed = shooter.aim(self); + if (aimed) + { + double dal = ((aimed.scale.Y * aimed.spriteHeight()) * 0.5) + aimed.sparkoffset; // originally used aimed.scale.X which is not correct. + double dist = (p.actor.pos.XY - aimed.pos.XY).Length(); + zvel = ((aimed.pos.Z - pos.Z - dal) * 16) / dist; + ang = (aimed.pos.XY - pos.XY).Angle(); + } + else + { + ang += 22.5 / 8 - frandom(0, 22.5 / 4); + [vel, zvel] = Raze.setFreeAimVelocity(vel, zvel, p.getPitchWithView(), 16.); + zvel += 0.5 - frandom(0, 1); + } + + pos.Z -= 2; + } + else + { + double x; + DukePlayer j; + [j, x] = self.findplayer(); + pos.Z -= 4; + double dist = (j.actor.pos.XY - shooter.pos.XY).Length(); + zvel = ((j.actor.viewzoffset - pos.Z) * 16) / dist; + zvel += 0.5 - frandom(0, 1); + ang += 22.5 / 4 - frandom(0, 22.5 / 2); + } + + k = 0; + + //RESHOOTGROW: + + shooter.cstat &= ~CSTAT_SPRITE_BLOCK_ALL; + Raze.hitscan(pos, sect, (ang.ToVector() * vel, zvel * 64), hit, CLIPMASK1); + + shooter.cstat |= CSTAT_SPRITE_BLOCK_ALL; + + let spark = dlevel.SpawnActor(sect, hit.hitpos, "DukeGrowSpark", -16, (0.4375, 0.4375), ang, 0., 0., shooter, 1); + if (!spark) return true; + + spark.pal = 2; + spark.cstat |= CSTAT_SPRITE_YCENTER | CSTAT_SPRITE_TRANSLUCENT; + spark.scale = (REPEAT_SCALE, REPEAT_SCALE); + + if (hit.hitWall == nullptr && hit.hitActor == nullptr && hit.hitSector != nullptr) + { + if (zvel < 0 && (hit.hitSector.ceilingstat & CSTAT_SECTOR_SKY) == 0) + dlevel.checkhitceiling(hit.hitSector, spark); + } + else if (hit.hitActor != nullptr) DukeActor(hit.hitActor).OnHit(spark); + else if (hit.hitWall != nullptr) + { + if (!Duke.isaccessswitch(hit.hitWall.walltexture)) + { + dlevel.checkhitwall(hit.hitWall, spark, hit.hitpos); + } + } + return true; + } + + override bool animate(tspritetype t) + { + t.setSpritePic(self, (PlayClock >> 4) & 3); + return true; + } +} +