From dc06a93a4fd0246d3b5b86b701068b111a2ef9b6 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 2 Dec 2022 17:10:50 +0100 Subject: [PATCH] - scriptified RR's UFO teleporter. --- source/core/vmexports.cpp | 18 +++++++ source/games/duke/src/actors_r.cpp | 49 ++----------------- source/games/duke/src/spawn_r.cpp | 6 --- source/games/duke/src/vmexports.cpp | 31 +++++------- .../static/filter/redneck/engine/engine.def | 2 + wadsrc/static/zscript.txt | 1 + wadsrc/static/zscript/coreactor.zs | 3 ++ .../zscript/games/duke/actors/rrteleport.zs | 48 ++++++++++++++++++ wadsrc/static/zscript/games/duke/dukeactor.zs | 2 - wadsrc/static/zscript/games/duke/dukegame.zs | 1 + 10 files changed, 90 insertions(+), 71 deletions(-) create mode 100644 wadsrc/static/zscript/games/duke/actors/rrteleport.zs diff --git a/source/core/vmexports.cpp b/source/core/vmexports.cpp index d86b8ab51..faf7346d6 100644 --- a/source/core/vmexports.cpp +++ b/source/core/vmexports.cpp @@ -875,6 +875,24 @@ DEFINE_ACTION_FUNCTION_NATIVE(DCoreActor, isAwayFromWall, isAwayFromWall) return 0; } +DEFINE_ACTION_FUNCTION_NATIVE(DCoreActor, ChangeSector, ChangeActorSect) +{ + PARAM_SELF_PROLOGUE(DCoreActor); + PARAM_POINTER(sec, sectortype); + PARAM_INT(tail); + ChangeActorSect(self, sec, tail); + return 0; +} + +DEFINE_ACTION_FUNCTION_NATIVE(DCoreActor, ChangeStat, ChangeActorStat) +{ + PARAM_SELF_PROLOGUE(DCoreActor); + PARAM_INT(stat); + PARAM_INT(tail); + ChangeActorStat(self, stat, tail); + return 0; +} + diff --git a/source/games/duke/src/actors_r.cpp b/source/games/duke/src/actors_r.cpp index b784b224f..6ac276bfe 100644 --- a/source/games/duke/src/actors_r.cpp +++ b/source/games/duke/src/actors_r.cpp @@ -1174,47 +1174,6 @@ void resetswitch(int tag) } } -void rr_specialstats() -{ - tickstat(STAT_LUMBERMILL); - - if (ud.chickenplant) - { - tickstat(STAT_CHICKENPLANT); - } - - tickstat(STAT_BOWLING); - - DukeStatIterator it(STAT_TELEPORT); - while (auto act = it.Next()) - { - if (act->spr.picnum == RRTELEPORT) - { - double xx; - int p = findplayer(act, &xx); - if (xx < 128) - { - DukeStatIterator it2(STAT_TELEPORT); - while (auto act2 = it2.Next()) - { - if (act2->spr.picnum == RRTELEPORTDEST) - { - ps[p].Angles.setYaw(act2->spr.Angles.Yaw, true); - ps[p].GetActor()->spr.pos = act2->spr.pos.plusZ(-36 + gs.playerheight); - ps[p].GetActor()->backuppos(); - ps[p].setbobpos(); - auto pact = ps[p].GetActor(); - ChangeActorSect(pact, act2->sector()); - ps[p].setCursector(pact->sector()); - S_PlayActorSound(70, act2); - act2->Destroy(); - } - } - } - } - } -} - //--------------------------------------------------------------------------- // // @@ -1234,13 +1193,14 @@ void moveactors_r(void) { rrra_specialstats(); } - rr_specialstats(); + tickstat(STAT_LUMBERMILL); + if (ud.chickenplant) tickstat(STAT_CHICKENPLANT); + tickstat(STAT_BOWLING); + tickstat(STAT_TELEPORT); DukeStatIterator it(STAT_ACTOR); while (auto act = it.Next()) { - bool deleteafterexecute = false; // taking a cue here from RedNukem to not run scripts on deleted sprites. - if( act->spr.scale.X == 0 || !act->insector() || actorflag(act, SFLAG2_DIENOW)) { act->Destroy(); @@ -1291,7 +1251,6 @@ void moveactors_r(void) p = findplayer(act, &xx); execute(act,p,xx); - if (deleteafterexecute) act->Destroy(); } } diff --git a/source/games/duke/src/spawn_r.cpp b/source/games/duke/src/spawn_r.cpp index 57c4b12cc..af3955449 100644 --- a/source/games/duke/src/spawn_r.cpp +++ b/source/games/duke/src/spawn_r.cpp @@ -157,12 +157,6 @@ DDukeActor* spawninit_r(DDukeActor* actj, DDukeActor* act, TArray* act->clipdist = 8; ChangeActorStat(act, STAT_ZOMBIEACTOR); break; - case RRTELEPORT: - case RRTELEPORTDEST: - act->spr.scale = DVector2(1, 1); - act->clipdist = 16; - ChangeActorStat(act, STAT_TELEPORT); - break; case DUKELYINGDEAD: if (actj && actj->isPlayer()) { diff --git a/source/games/duke/src/vmexports.cpp b/source/games/duke/src/vmexports.cpp index da0859041..1c49bc927 100644 --- a/source/games/duke/src/vmexports.cpp +++ b/source/games/duke/src/vmexports.cpp @@ -528,24 +528,6 @@ DEFINE_ACTION_FUNCTION_NATIVE(DDukeActor, hitasprite, hitasprite) return min(numret, 2); } -DEFINE_ACTION_FUNCTION_NATIVE(DDukeActor, ChangeSector, ChangeActorSect) -{ - PARAM_SELF_PROLOGUE(DDukeActor); - PARAM_POINTER(sec, sectortype); - PARAM_INT(tail); - ChangeActorSect(self, sec, tail); - return 0; -} - -DEFINE_ACTION_FUNCTION_NATIVE(DDukeActor, ChangeStat, ChangeActorStat) -{ - PARAM_SELF_PROLOGUE(DDukeActor); - PARAM_INT(stat); - PARAM_INT(tail); - ChangeActorStat(self, stat, tail); - return 0; -} - void DukeActor_detonate(DDukeActor* origin, int intname) { // all callers use "EXPLOSION2", so ignore the parameter for now. This should be fixed once EXPLOSION2 gets scriptified. @@ -1123,6 +1105,19 @@ DEFINE_ACTION_FUNCTION_NATIVE(_DukePlayer, GetPitchwithView, DukePlayer_GetPitch ACTION_RETURN_FLOAT(DukePlayer_GetPitchwithView(self)); } +inline void DukePlayer_setbobpos(player_struct* pl) +{ + return pl->setbobpos(); +} + +DEFINE_ACTION_FUNCTION_NATIVE(_DukePlayer, setbobpos, DukePlayer_setbobpos) +{ + PARAM_SELF_STRUCT_PROLOGUE(player_struct); + self->setbobpos(); + return 0; +} + + static DDukeActor* duke_firstStat(DukeStatIterator* it, int statnum) diff --git a/wadsrc/static/filter/redneck/engine/engine.def b/wadsrc/static/filter/redneck/engine/engine.def index f16fe1fb3..181d79abb 100644 --- a/wadsrc/static/filter/redneck/engine/engine.def +++ b/wadsrc/static/filter/redneck/engine/engine.def @@ -139,6 +139,8 @@ spawnclasses 3440 = RedneckBowlingPin 3430 = RedneckBowlingBall 4897 = RedneckHenstand + 296 = RedneckTeleport + 297 = RedneckTeleportDest 3114 = DukeGenericDestructible, "RRTILE3114", "RRTILE3117", "GLASS_BREAKING", spawnglass 2876 = DukeGenericDestructible, "RRTILE2876", "RRTILE2990", "GLASS_BREAKING", spawnglass diff --git a/wadsrc/static/zscript.txt b/wadsrc/static/zscript.txt index dbbe9e76b..14f13fe1d 100644 --- a/wadsrc/static/zscript.txt +++ b/wadsrc/static/zscript.txt @@ -101,6 +101,7 @@ version "4.10" #include "zscript/games/duke/actors/redneckmisc.zs" +#include "zscript/games/duke/actors/rrteleport.zs" #include "zscript/games/duke/actors/bowling.zs" #include "zscript/games/duke/actors/rabbitspawner.zs" #include "zscript/games/duke/actors/chickenplant.zs" diff --git a/wadsrc/static/zscript/coreactor.zs b/wadsrc/static/zscript/coreactor.zs index 44034a4ab..4169c41ba 100644 --- a/wadsrc/static/zscript/coreactor.zs +++ b/wadsrc/static/zscript/coreactor.zs @@ -69,6 +69,9 @@ class CoreActor native native void setPositionZ(Vector3 pos); native bool isAwayFromWall(double dist); + native void ChangeSector(sectortype s, bool forcetail = false); + native void ChangeStat(int s, bool forcetail = false); + native clearscope static double deltaangle(double ang1, double ang2); native clearscope static double absangle(double ang1, double ang2); native clearscope static double Normalize180(double ang); diff --git a/wadsrc/static/zscript/games/duke/actors/rrteleport.zs b/wadsrc/static/zscript/games/duke/actors/rrteleport.zs new file mode 100644 index 000000000..324433d24 --- /dev/null +++ b/wadsrc/static/zscript/games/duke/actors/rrteleport.zs @@ -0,0 +1,48 @@ + +class RedneckTeleportDest : DukeActor +{ + default + { + pic "RRTELEPORTDEST"; + statnum STAT_TELEPORT; + ScaleX 1; + ScaleY 1; + clipdist 16; + } +} + +class RedneckTeleport : RedneckTeleportDest +{ + default + { + pic "RRTELEPORT"; + } + + override void Tick() + { + double xx; + DukePlayer p; + [p, xx] = self.findplayer(); + if (xx < 128) + { + DukeStatIterator it; + for(let act2 = it.First(STAT_TELEPORT); act2; act2 = it.Next()) + { + if (act2.GetClassName() == 'RedneckTeleportDest') + { + p.setTargetAngle(act2.angle, true); + let pactor = p.actor; + pactor.pos = act2.pos.plusZ(-36 + gs.playerheight); + pactor.backuppos(); + p.setbobpos(); + pactor.ChangeSector(act2.sector); + p.cursector = pactor.sector; + act2.PlayActorSound("TELEPORTER"); + act2.cstat = CSTAT_SPRITE_INVISIBLE; + act2.cstat2 |= CSTAT2_SPRITE_NOFIND; + act2.ChangeStat(STAT_REMOVED); // this is still needed for the sound so don't destroy. + } + } + } + } +} diff --git a/wadsrc/static/zscript/games/duke/dukeactor.zs b/wadsrc/static/zscript/games/duke/dukeactor.zs index f970587a7..043310933 100644 --- a/wadsrc/static/zscript/games/duke/dukeactor.zs +++ b/wadsrc/static/zscript/games/duke/dukeactor.zs @@ -203,8 +203,6 @@ class DukeActor : CoreActor native native void RandomScrap(); native void hitradius(int r, int hp1, int hp2, int hp3, int hp4); native double, DukeActor hitasprite(); - native void ChangeSector(sectortype s, bool forcetail = false); - native void ChangeStat(int s, bool forcetail = false); native int badguy(); native int isplayer(); native void lotsofstuff(Name type, int count); diff --git a/wadsrc/static/zscript/games/duke/dukegame.zs b/wadsrc/static/zscript/games/duke/dukegame.zs index aa6aee38b..85d5b1f6f 100644 --- a/wadsrc/static/zscript/games/duke/dukegame.zs +++ b/wadsrc/static/zscript/games/duke/dukegame.zs @@ -358,6 +358,7 @@ struct DukePlayer native native void addweapon(int type, bool switchit); native bool hitablockingwall(); native double getPitchWithView(); + native void setbobpos(); }