From ac50daf5f3828231a8a8f6602b9d783ff61ddbd5 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 30 Dec 2022 16:21:09 +0100 Subject: [PATCH] - split a large bunch of code out of movetransports that can be consolidated between Duke and RR. --- source/games/duke/src/actors.cpp | 166 +++++++++++++++++++++++++++++ source/games/duke/src/actors_d.cpp | 110 +------------------ source/games/duke/src/actors_r.cpp | 166 +---------------------------- source/games/duke/src/funct.h | 1 + 4 files changed, 173 insertions(+), 270 deletions(-) diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index f9e0f958e..cbb01f7e0 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -686,6 +686,172 @@ void movefallers(void) } } +//--------------------------------------------------------------------------- +// +// well, also surfacing... +// +//--------------------------------------------------------------------------- + +void checkdive(DDukeActor* transporter, DDukeActor* transported) +{ + auto sectp = transporter->sector(); + int sectlotag = sectp->lotag; + auto Owner = transporter->GetOwner(); + int warpdir; + int onfloorz = transporter->temp_data[4]; + Collision coll; + + double ll = abs(transported->vel.Z), ll2; + if (transported->vel.Z >= 0) + warpdir = 2; + else + warpdir = 1; + + int warpspriteto = 0; + if (ll && sectlotag == ST_2_UNDERWATER && transported->spr.pos.Z < sectp->ceilingz + ll && warpdir == 1) + warpspriteto = 1; + + if (ll && sectlotag == ST_1_ABOVE_WATER && transported->spr.pos.Z > sectp->floorz - ll && warpdir == 2) + warpspriteto = 1; + + if (ud.mapflags & MFLAG_ALLSECTORTYPES) + { + if (ll && sectlotag == ST_161_CEILING_TELEPORT && transported->spr.pos.Z < (sectp->ceilingz + ll) && warpdir == 1) + { + warpspriteto = 1; + ll2 = ll - abs(transported->spr.pos.Z - sectp->ceilingz); + } + else if (sectlotag == ST_161_CEILING_TELEPORT && transported->spr.pos.Z < (sectp->ceilingz + 3.90625) && warpdir == 1) + { + warpspriteto = 1; + ll2 = zmaptoworld; + } + if (ll && sectlotag == ST_160_FLOOR_TELEPORT && transported->spr.pos.Z > (sectp->floorz - ll) && warpdir == 2) + { + warpspriteto = 1; + ll2 = ll - abs(sectp->floorz - transported->spr.pos.Z); + } + else if (sectlotag == ST_160_FLOOR_TELEPORT && transported->spr.pos.Z > (sectp->floorz - 3.90625) && warpdir == 2) + { + warpspriteto = 1; + ll2 = zmaptoworld; + } + } + + if (sectlotag == ST_0_NO_EFFECT && (onfloorz || abs(transported->spr.pos.Z - transporter->spr.pos.Z) < 16)) + { + if ((!Owner || Owner->GetOwner() != Owner) && onfloorz && transporter->counter > 0 && transported->spr.statnum != STAT_MISC) + { + transporter->counter++; + return; + } + warpspriteto = 1; + } + + if (warpspriteto) + { + if ((transported->flags1 & SFLAG_NOTELEPORT)) return; + if (transported->GetClass() == DukePlayerOnWaterClass) + { + if (sectlotag == ST_2_UNDERWATER) + { + transported->spr.cstat &= ~CSTAT_SPRITE_INVISIBLE; + return; + } + } + if (transported->GetClass() != DukeWaterBubbleClass) + { + if (transported->spr.statnum == STAT_MISC && !(sectlotag == ST_1_ABOVE_WATER || sectlotag == ST_2_UNDERWATER || ((ud.mapflags & MFLAG_ALLSECTORTYPES) && (sectlotag == ST_160_FLOOR_TELEPORT || sectlotag == ST_161_CEILING_TELEPORT)))) + return; + } + if (sectlotag > 0) + { + auto spawned = spawn(transported, DukeWaterSplashClass); + if (spawned && sectlotag == 1 && transported->spr.statnum == 4) + { + spawned->vel.X = transported->vel.X * 0.5; + spawned->spr.Angles.Yaw = transported->spr.Angles.Yaw; + ssp(spawned, CLIPMASK0); + } + } + + switch (sectlotag) + { + case ST_0_NO_EFFECT: + if (onfloorz) + { + if (transported->spr.statnum == STAT_PROJECTILE || (checkcursectnums(transporter->sector()) == -1 && checkcursectnums(Owner->sector()) == -1)) + { + transported->spr.pos += (Owner->spr.pos - transporter->spr.pos.XY()).plusZ(-Owner->sector()->floorz); + transported->spr.Angles.Yaw = Owner->spr.Angles.Yaw; + + transported->backupang(); + + if (transporter->spr.pal == 0 || isRR()) + { + auto beam = spawn(transporter, DukeTransporterBeamClass); + if (beam) S_PlayActorSound(TELEPORTER, beam); + + beam = spawn(Owner, DukeTransporterBeamClass); + if (beam) S_PlayActorSound(TELEPORTER, beam); + } + + if (Owner && Owner->GetOwner() == Owner) + { + transporter->counter = 13; + Owner->counter = 13; + } + + ChangeActorSect(transported, Owner->sector()); + } + } + else + { + transported->spr.pos.XY() += Owner->spr.pos.XY() - transporter->spr.pos.XY(); + transported->spr.pos.Z = Owner->spr.pos.Z + 16; + transported->backupz(); + ChangeActorSect(transported, Owner->sector()); + } + break; + case ST_1_ABOVE_WATER: + transported->spr.pos.XY() += Owner->spr.pos.XY() - transporter->spr.pos.XY(); + transported->spr.pos.Z = Owner->sector()->ceilingz + ll; + transported->backupz(); + ChangeActorSect(transported, Owner->sector()); + break; + case ST_2_UNDERWATER: + transported->spr.pos.XY() += Owner->spr.pos.XY() - transporter->spr.pos.XY(); + transported->spr.pos.Z = Owner->sector()->ceilingz - ll; + transported->backupz(); + ChangeActorSect(transported, Owner->sector()); + break; + + case ST_160_FLOOR_TELEPORT: + if (!(ud.mapflags & MFLAG_ALLSECTORTYPES)) break; + transported->spr.pos.XY() += Owner->spr.pos.XY() - transporter->spr.pos.XY(); + transported->spr.pos.Z = Owner->sector()->ceilingz + ll2; + transported->backupz(); + + ChangeActorSect(transported, Owner->sector()); + + movesprite_ex(transported, DVector3(transported->spr.Angles.Yaw.ToVector() * transported->vel.X, 0), CLIPMASK1, coll); + + break; + case ST_161_CEILING_TELEPORT: + if (!(ud.mapflags & MFLAG_ALLSECTORTYPES)) break; + transported->spr.pos += Owner->spr.pos.XY() - transporter->spr.pos.XY(); + transported->spr.pos.Z = Owner->sector()->floorz - ll; + transported->backupz(); + + ChangeActorSect(transported, Owner->sector()); + + movesprite_ex(transported, DVector3(transported->spr.Angles.Yaw.ToVector() * transported->vel.X, 0), CLIPMASK1, coll); + + break; + } + } +} + //--------------------------------------------------------------------------- // // diff --git a/source/games/duke/src/actors_d.cpp b/source/games/duke/src/actors_d.cpp index c7e5c566c..3b50bab4d 100644 --- a/source/games/duke/src/actors_d.cpp +++ b/source/games/duke/src/actors_d.cpp @@ -261,9 +261,6 @@ int ifhitbyweapon_d(DDukeActor *actor) void movetransports_d(void) { - int warpspriteto; - double ll; - DukeStatIterator iti(STAT_TRANSPORT); while (auto act = iti.Next()) { @@ -422,119 +419,18 @@ void movetransports_d(void) break; case STAT_ACTOR: - if ((act->flags3 & SFLAG3_DONTDIVEALIVE) && act2->spr.extra > 0) continue; + if ((act2->flags3 & SFLAG3_DONTDIVEALIVE) && act2->spr.extra > 0) continue; [[fallthrough]]; case STAT_PROJECTILE: case STAT_MISC: case STAT_FALLER: case STAT_DUMMYPLAYER: - if ((act->flags2 & SFLAG2_DONTDIVE)) continue; - - ll = abs(act2->vel.Z); - - { - warpspriteto = 0; - if (ll && sectlotag == 2 && act2->spr.pos.Z < (sectp->ceilingz + ll) && act2->vel.Z < 0) - warpspriteto = 1; - - if (ll && sectlotag == 1 && act2->spr.pos.Z > (sectp->floorz - ll) && act2->vel.Z > 0) - warpspriteto = 1; - - if (sectlotag == ST_0_NO_EFFECT && (onfloorz || abs(act2->spr.pos.Z - act->spr.pos.Z) < 16)) - { - if ((!Owner || Owner->GetOwner() != Owner) && onfloorz && act->counter > 0 && act2->spr.statnum != STAT_MISC) - { - act->counter++; - goto BOLT; - } - warpspriteto = 1; - } - - if (warpspriteto) - { - if ((act2->flags1 & SFLAG_NOTELEPORT)) continue; - if (act2->GetClass() == DukePlayerOnWaterClass) - { - if (sectlotag == ST_2_UNDERWATER) - { - act2->spr.cstat &= ~CSTAT_SPRITE_INVISIBLE; - continue; - } - } - if (act2->GetClass() != DukeWaterBubbleClass) - { - if (act2->spr.statnum == STAT_MISC && !(sectlotag == ST_1_ABOVE_WATER || sectlotag == ST_2_UNDERWATER || ((ud.mapflags & MFLAG_ALLSECTORTYPES) && (sectlotag == ST_160_FLOOR_TELEPORT || sectlotag == ST_161_CEILING_TELEPORT)))) - continue; - } - if (sectlotag > 0) - { - auto k = spawn(act2, DukeWaterSplashClass); - if (k && sectlotag == 1 && act2->spr.statnum == 4) - { - k->vel.X = act2->vel.X * 0.5; - k->spr.Angles.Yaw = act2->spr.Angles.Yaw; - ssp(k, CLIPMASK0); - } - } - - switch (sectlotag) - { - case ST_0_NO_EFFECT: - if (onfloorz) - { - if (act2->spr.statnum == STAT_PROJECTILE || (checkcursectnums(act->sector()) == -1 && checkcursectnums(Owner->sector()) == -1)) - { - act2->spr.pos += (Owner->spr.pos - act->spr.pos.XY()).plusZ(-Owner->sector()->floorz); - act2->spr.Angles.Yaw = Owner->spr.Angles.Yaw; - - act2->backupang(); - - if (act->spr.pal == 0) - { - auto k = spawn(act, DukeTransporterBeamClass); - if (k) S_PlayActorSound(TELEPORTER, k); - - k = spawn(Owner, DukeTransporterBeamClass); - if (k) S_PlayActorSound(TELEPORTER, k); - } - - if (Owner && Owner->GetOwner() == Owner) - { - act->counter = 13; - Owner->counter = 13; - } - - ChangeActorSect(act2, Owner->sector()); - } - } - else - { - act2->spr.pos.XY() += Owner->spr.pos.XY() - act->spr.pos.XY(); - act2->spr.pos.Z = Owner->spr.pos.Z + 16; - act2->backupz(); - ChangeActorSect(act2, Owner->sector()); - } - break; - case ST_1_ABOVE_WATER: - act2->spr.pos.XY() += Owner->spr.pos.XY() - act->spr.pos.XY(); - act2->spr.pos.Z = Owner->sector()->ceilingz + ll; - act2->backupz(); - ChangeActorSect(act2, Owner->sector()); - break; - case ST_2_UNDERWATER: - act2->spr.pos.XY() += Owner->spr.pos.XY() - act->spr.pos.XY(); - act2->spr.pos.Z = Owner->sector()->ceilingz - ll; - act2->backupz(); - ChangeActorSect(act2, Owner->sector()); - break; - } - } - } + if ((act2->flags2 & SFLAG2_DONTDIVE)) continue; + checkdive(act, act2); break; } } - BOLT:; } } diff --git a/source/games/duke/src/actors_r.cpp b/source/games/duke/src/actors_r.cpp index b86641a4e..00bc3b799 100644 --- a/source/games/duke/src/actors_r.cpp +++ b/source/games/duke/src/actors_r.cpp @@ -240,11 +240,9 @@ int ifhitbyweapon_r(DDukeActor *actor) void movetransports_r(void) { - uint8_t warpdir = 0, warpspriteto; + uint8_t warpdir = 0; int k, p, sectlotag; int onfloorz; - double ll, ll2 = 0; - Collision coll; //Transporters @@ -415,166 +413,8 @@ void movetransports_r(void) case STAT_PROJECTILE: case STAT_MISC: case STAT_DUMMYPLAYER: - if ((act->flags2 & SFLAG2_DONTDIVE)) continue; - - ll = abs(act2->vel.Z); - if (isRRRA()) - { - if (act2->vel.Z >= 0) - warpdir = 2; - else - warpdir = 1; - } - - { - warpspriteto = 0; - if (ll && sectlotag == ST_2_UNDERWATER && act2->spr.pos.Z < (sectp->ceilingz + ll)) - warpspriteto = 1; - - if (ll && sectlotag == ST_1_ABOVE_WATER && act2->spr.pos.Z > (sectp->floorz - ll)) - warpspriteto = 1; - - if (ud.mapflags & MFLAG_ALLSECTORTYPES) - { - if (ll && sectlotag == ST_161_CEILING_TELEPORT && act2->spr.pos.Z < (sectp->ceilingz + ll) && warpdir == 1) - { - warpspriteto = 1; - ll2 = ll - abs(act2->spr.pos.Z - sectp->ceilingz); - } - else if (sectlotag == ST_161_CEILING_TELEPORT && act2->spr.pos.Z < (sectp->ceilingz + 3.90625) && warpdir == 1) - { - warpspriteto = 1; - ll2 = zmaptoworld; - } - if (ll && sectlotag == ST_160_FLOOR_TELEPORT && act2->spr.pos.Z > (sectp->floorz - ll) && warpdir == 2) - { - warpspriteto = 1; - ll2 = ll - abs(sectp->floorz - act2->spr.pos.Z); - } - else if (sectlotag == ST_160_FLOOR_TELEPORT && act2->spr.pos.Z > (sectp->floorz - 3.90625) && warpdir == 2) - { - warpspriteto = 1; - ll2 = zmaptoworld; - } - } - - if (sectlotag == ST_0_NO_EFFECT && (onfloorz || abs(act2->spr.pos.Z - act->spr.pos.Z) < 16)) - { - if (Owner->GetOwner() != Owner && onfloorz && act->counter > 0 && act2->spr.statnum != 5) - { - act->counter++; - continue; - } - warpspriteto = 1; - } - - if (warpspriteto) - { - if ((act2->flags1 & SFLAG_NOTELEPORT)) continue; - if (act2->GetClass() == DukePlayerOnWaterClass) - { - if (sectlotag == ST_2_UNDERWATER) - { - act2->spr.cstat &= ~CSTAT_SPRITE_INVISIBLE; - continue; - } - } - if (act2->GetClass() != DukeWaterBubbleClass) - { - if (act2->spr.statnum == STAT_MISC && !(sectlotag == ST_1_ABOVE_WATER || sectlotag == ST_2_UNDERWATER || ((ud.mapflags & MFLAG_ALLSECTORTYPES) && (sectlotag == ST_160_FLOOR_TELEPORT || sectlotag == ST_161_CEILING_TELEPORT)))) - continue; - } - if (sectlotag > 0) - { - auto spawned = spawn(act2, DukeWaterSplashClass); - if (spawned && sectlotag == 1 && act2->spr.statnum == 4) - { - spawned->vel.X = act2->vel.X * 0.5; - spawned->spr.Angles.Yaw = act2->spr.Angles.Yaw; - ssp(spawned, CLIPMASK0); - } - } - - switch (sectlotag) - { - case ST_0_NO_EFFECT: - if (onfloorz) - { - if (checkcursectnums(act->sector()) == -1 && checkcursectnums(Owner->sector()) == -1) - { - act2->spr.pos += (Owner->spr.pos - act->spr.pos.XY()).plusZ(-Owner->sector()->floorz); - act2->spr.Angles.Yaw = Owner->spr.Angles.Yaw; - - act2->backupang(); - - auto beam = spawn(act, DukeTransporterBeamClass); - if (beam) S_PlayActorSound(TELEPORTER, beam); - - beam = spawn(Owner, DukeTransporterBeamClass); - if (beam) S_PlayActorSound(TELEPORTER, beam); - - if (Owner->GetOwner() != Owner) - { - act->counter = 13; - Owner->counter = 13; - } - - ChangeActorSect(act2, Owner->sector()); - } - } - else - { - act2->spr.pos.XY() += Owner->spr.pos.XY() - act->spr.pos.XY(); - act2->spr.pos.Z = Owner->spr.pos.Z + 16; - act2->backupz(); - - ChangeActorSect(act2, Owner->sector()); - } - break; - case ST_1_ABOVE_WATER: - act2->spr.pos.XY() += Owner->spr.pos.XY() - act->spr.pos.XY(); - act2->spr.pos.Z = Owner->sector()->ceilingz + ll; - act2->backupz(); - - ChangeActorSect(act2, Owner->sector()); - - break; - case ST_2_UNDERWATER: - act2->spr.pos.XY() += Owner->spr.pos.XY() - act->spr.pos.XY(); - act2->spr.pos.Z = Owner->sector()->ceilingz - ll; - act2->backupz(); - - ChangeActorSect(act2, Owner->sector()); - - break; - - case ST_160_FLOOR_TELEPORT: - if (!(ud.mapflags & MFLAG_ALLSECTORTYPES)) break; - act2->spr.pos.XY() += Owner->spr.pos.XY() - act->spr.pos.XY(); - act2->spr.pos.Z = Owner->sector()->ceilingz + ll2; - act2->backupz(); - - ChangeActorSect(act2, Owner->sector()); - - movesprite_ex(act2, DVector3(act2->spr.Angles.Yaw.ToVector() * act2->vel.X, 0), CLIPMASK1, coll); - - break; - case ST_161_CEILING_TELEPORT: - if (!(ud.mapflags & MFLAG_ALLSECTORTYPES)) break; - act2->spr.pos += Owner->spr.pos.XY() - act->spr.pos.XY(); - act2->spr.pos.Z = Owner->sector()->floorz - ll; - act2->backupz(); - - ChangeActorSect(act2, Owner->sector()); - - movesprite_ex(act2, DVector3(act2->spr.Angles.Yaw.ToVector() * act2->vel.X, 0), CLIPMASK1, coll); - - break; - } - - break; - } - } + if ((act2->flags2 & SFLAG2_DONTDIVE)) continue; + checkdive(act, act2); break; } diff --git a/source/games/duke/src/funct.h b/source/games/duke/src/funct.h index 759a6383b..d8f334bcd 100644 --- a/source/games/duke/src/funct.h +++ b/source/games/duke/src/funct.h @@ -32,6 +32,7 @@ void resetlanepics(void); void moveplayers(); void movefallers(); void doanimations(); +void checkdive(DDukeActor* transporter, DDukeActor* transported); void tickstat(int stat, bool deleteinvalid = false); void operaterespawns(int low); void moveclouds(double interpfrac);