From b069904be1ad36209074a449b28f054433f8b179 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 20 Nov 2022 13:57:51 +0100 Subject: [PATCH] - scriptified the remaining controller sprites. --- source/core/vmexports.cpp | 2 + source/games/duke/src/actors.cpp | 13 ++++ source/games/duke/src/actors_lava.cpp | 26 +++++-- source/games/duke/src/duke3d.h | 1 + source/games/duke/src/funct.h | 5 +- source/games/duke/src/game.cpp | 8 +++ source/games/duke/src/namelist_r.h | 8 +-- source/games/duke/src/premap.cpp | 23 +----- source/games/duke/src/premap_r.cpp | 41 +---------- source/games/duke/src/vmexports.cpp | 67 +++++++++++++---- wadsrc/static/filter/duke/engine/engine.def | 2 + .../static/filter/redneck/engine/engine.def | 8 +++ .../static/zscript/games/duke/actors/bolt.zs | 4 +- .../zscript/games/duke/actors/controllers.zs | 71 +++++++++++++++++++ wadsrc/static/zscript/games/duke/dukeactor.zs | 6 ++ wadsrc/static/zscript/games/duke/dukegame.zs | 1 - wadsrc/static/zscript/maptypes.zs | 3 + 17 files changed, 199 insertions(+), 90 deletions(-) diff --git a/source/core/vmexports.cpp b/source/core/vmexports.cpp index 3b4d44f61..43ef4f383 100644 --- a/source/core/vmexports.cpp +++ b/source/core/vmexports.cpp @@ -102,6 +102,8 @@ DEFINE_FIELD_X(sectortype, sectortype, exflags) DEFINE_FIELD_X(sectortype, sectortype, floorz) DEFINE_FIELD_X(sectortype, sectortype, ceilingz) +DEFINE_FIELD_X(sectortype, sectortype, shadedsector) + DEFINE_FIELD_NAMED_X(walltype, walltype, xpan_, xpan) DEFINE_FIELD_NAMED_X(walltype, walltype, ypan_, ypan) DEFINE_FIELD_X(walltype, walltype, pos) diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index 40631a3c4..a16ffbf78 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -334,6 +334,19 @@ void movecyclers(void) } } +void addcycler(sectortype* sector, int lotag, int shade, int shade2, int hitag, int state) +{ + if (numcyclers >= MAXCYCLERS) + I_Error("Too many cycling sectors."); + cyclers[numcyclers].sector = sector; + cyclers[numcyclers].lotag = lotag; + cyclers[numcyclers].shade1 = shade; + cyclers[numcyclers].shade2 = shade2; + cyclers[numcyclers].hitag = hitag; + cyclers[numcyclers].state = state; + numcyclers++; +} + //--------------------------------------------------------------------------- // // diff --git a/source/games/duke/src/actors_lava.cpp b/source/games/duke/src/actors_lava.cpp index c5c68778f..9b4332576 100644 --- a/source/games/duke/src/actors_lava.cpp +++ b/source/games/duke/src/actors_lava.cpp @@ -146,24 +146,24 @@ void lava_serialize(FSerializer& arc) ("windertime", windertime); } -void addtorch(DDukeActor* actor) +void addtorch(sectortype* sect, int shade, int lotag) { if (torchcnt >= 64) I_Error("Too many torch effects"); - torchsector[torchcnt] = actor->sector(); - torchsectorshade[torchcnt] = actor->sector()->floorshade; - torchtype[torchcnt] = actor->spr.lotag; + torchsector[torchcnt] = sect; + torchsectorshade[torchcnt] = shade; + torchtype[torchcnt] = lotag; torchcnt++; } -void addlightning(DDukeActor* actor) +void addlightning(sectortype* sect, int shade) { if (lightnincnt >= 64) I_Error("Too many lightnin effects"); - lightninsector[lightnincnt] = actor->sector(); - lightninsectorshade[lightnincnt] = actor->sector()->floorshade; + lightninsector[lightnincnt] = sect; + lightninsectorshade[lightnincnt] = shade; lightnincnt++; } @@ -526,4 +526,16 @@ void thunder(void) } } +int addambient(int hitag, int lotag) +{ + if (ambientfx >= 64) + I_Error("Too many ambient effects"); + else + { + ambienthitag[ambientfx] = hitag; + ambientlotag[ambientfx] = lotag; + return ambientfx++; + } +} + END_DUKE_NS diff --git a/source/games/duke/src/duke3d.h b/source/games/duke/src/duke3d.h index 6bcf9337a..7acced1f5 100644 --- a/source/games/duke/src/duke3d.h +++ b/source/games/duke/src/duke3d.h @@ -123,6 +123,7 @@ void CallOnHurt(DDukeActor* actor, player_struct* hitter); bool CallOnUse(DDukeActor* actor, player_struct* user); void CallOnRespawn(DDukeActor* actor, int low); bool CallAnimate(DDukeActor* actor, tspritetype* hitter); +void CallStaticSetup(DDukeActor* actor); END_DUKE_NS diff --git a/source/games/duke/src/funct.h b/source/games/duke/src/funct.h index 4ba4ad3aa..9879a441c 100644 --- a/source/games/duke/src/funct.h +++ b/source/games/duke/src/funct.h @@ -17,8 +17,9 @@ BEGIN_DUKE_NS void lava_cleararrays(); void addjaildoor(int p1, int p2, int iht, int jlt, int p3, sectortype* h); void addminecart(int p1, int p2, sectortype* i, int iht, int p3, sectortype* childsectnum); -void addtorch(DDukeActor* i); -void addlightning(DDukeActor* i); +void addtorch(sectortype* sect, int shade, int lotag); +void addlightning(sectortype* sect, int shade); +int addambient(int hitag, int lotag); void movecyclers(void); void movedummyplayers(void); diff --git a/source/games/duke/src/game.cpp b/source/games/duke/src/game.cpp index b14908416..bfc30f0bb 100644 --- a/source/games/duke/src/game.cpp +++ b/source/games/duke/src/game.cpp @@ -479,5 +479,13 @@ bool CallAnimate(DDukeActor* actor, tspritetype* tspr) return nval; } +void CallStaticSetup(DDukeActor* actor) +{ + IFVIRTUALPTR(actor, DDukeActor, StaticSetup) + { + VMValue val = actor; + VMCall(func, &val, 1, nullptr, 0); + } +} END_DUKE_NS diff --git a/source/games/duke/src/namelist_r.h b/source/games/duke/src/namelist_r.h index b39342762..e409aa9fd 100644 --- a/source/games/duke/src/namelist_r.h +++ b/source/games/duke/src/namelist_r.h @@ -4,7 +4,7 @@ x(RPG2SPRITE, 14) x(DUKETAG, 15) x(SIGN1, 16) x(SIGN2, 17) -y(RRTILE18, 18) +y(TORCHCTRL, 18) y(RRTILE19, 19) x(ARROW, 20) x(FIRSTGUNSPRITE, 21) @@ -21,7 +21,7 @@ x(AMMOBOX, 31) x(GROWSPRITEICON, 32) x(INVENTORYBOX, 33) y(RRTILE34, 34) -y(RRTILE35, 35) +y(LIGHTNINGCTRL, 35) x(DESTRUCTO, 36) x(FREEZEAMMO, 37) y(RRJAILDOORSOUND, 38) @@ -50,8 +50,8 @@ y(RRTILE63, 63) y(RRMINECART, 64) y(RRMINECARTSOUND, 65) y(RRMINECARTINNER, 66) -y(RRTILE67, 67) -y(RRTILE68, 68) +y(DUMMYCTRL, 67) +y(SHADEDSECTORCTRL, 68) x(MIRRORBROKE, 70) x(SOUNDFX, 71) x(TECHLIGHT2, 72) diff --git a/source/games/duke/src/premap.cpp b/source/games/duke/src/premap.cpp index c9cc5ef05..a0e0f5353 100644 --- a/source/games/duke/src/premap.cpp +++ b/source/games/duke/src/premap.cpp @@ -45,29 +45,10 @@ int which_palookup = 9; void premapcontroller(DDukeActor* ac) { - switch (ac->spr.picnum) + CallStaticSetup(ac); + if (ac->spr.picnum == SECTOREFFECTOR) { - case SECTOREFFECTOR: ac->spr.cstat &= ~(CSTAT_SPRITE_BLOCK | CSTAT_SPRITE_BLOCK_HITSCAN | CSTAT_SPRITE_ALIGNMENT_MASK); - break; - - case GPSPEED: - ac->sector()->extra = ac->spr.lotag; - deletesprite(ac); - break; - - case CYCLER: - if (numcyclers >= MAXCYCLERS) - I_Error("Too many cycling sectors."); - cyclers[numcyclers].sector = ac->sector(); - cyclers[numcyclers].lotag = ac->spr.lotag; - cyclers[numcyclers].shade1 = ac->spr.shade; - cyclers[numcyclers].shade2 = ac->sector()->floorshade; - cyclers[numcyclers].hitag = ac->spr.hitag; - cyclers[numcyclers].state = (ac->spr.angle == DAngle270); - numcyclers++; - deletesprite(ac); - break; } } diff --git a/source/games/duke/src/premap_r.cpp b/source/games/duke/src/premap_r.cpp index 5b6e47200..5c2e71f72 100644 --- a/source/games/duke/src/premap_r.cpp +++ b/source/games/duke/src/premap_r.cpp @@ -534,48 +534,9 @@ void prelevel_r(int g, TArray& actors) { ps[0].Exit = ac->spr.pos.XY(); } - else switch (ac->spr.picnum) + else { - default: premapcontroller(ac); - break; - - case NUKEBUTTON: - chickenplant = 1; - break; - - case RRTILE18: - addtorch(ac); - deletesprite(ac); - break; - - case RRTILE35: - addlightning(ac); - deletesprite(ac); - break; - - case RRTILE68: - ac->sector()->shadedsector = 1; - deletesprite(ac); - break; - - case RRTILE67: - ac->spr.cstat |= CSTAT_SPRITE_INVISIBLE; - break; - - case SOUNDFX: - if (ambientfx >= 64) - I_Error("Too many ambient effects"); - else - { - ambienthitag[ambientfx] = ac->spr.hitag; - ambientlotag[ambientfx] = ac->spr.lotag; - ac->spr.detail = ambientfx; - ambientfx++; - ac->spr.lotag = 0; - ac->spr.hitag = 0; - } - break; } } diff --git a/source/games/duke/src/vmexports.cpp b/source/games/duke/src/vmexports.cpp index d936d4ec8..66129be64 100644 --- a/source/games/duke/src/vmexports.cpp +++ b/source/games/duke/src/vmexports.cpp @@ -84,18 +84,6 @@ DEFINE_ACTION_FUNCTION_NATIVE(_Duke, checkcursectnums, duke_checkcursectnums) ACTION_RETURN_POINTER(duke_checkcursectnums(sect)); } -int duke_floorflags(sectortype* sector) -{ - return gs.tileinfo[sector->floorpicnum].flags; -} - -DEFINE_ACTION_FUNCTION_NATIVE(_Duke, floorflags, duke_floorflags) -{ - PARAM_PROLOGUE; - PARAM_POINTER(sect, sectortype); - ACTION_RETURN_INT(duke_floorflags(sect)); -} - int duke_global_random() { return global_random; @@ -867,7 +855,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(_DukeLevel, operatemasterswitches, operatemastersw return 0; } -DEFINE_ACTION_FUNCTION(_DukeLevel, operateactivators)//, operateactivators) +DEFINE_ACTION_FUNCTION_NATIVE(_DukeLevel, operateactivators, operateactivators) { PARAM_PROLOGUE; PARAM_INT(lotag); @@ -876,6 +864,59 @@ DEFINE_ACTION_FUNCTION(_DukeLevel, operateactivators)//, operateactivators) return 0; } +int duke_floorflags(sectortype* sector) +{ + return gs.tileinfo[sector->floorpicnum].flags; +} + +DEFINE_ACTION_FUNCTION_NATIVE(_DukeLevel, floorflags, duke_floorflags) +{ + PARAM_PROLOGUE; + PARAM_POINTER(sect, sectortype); + ACTION_RETURN_INT(duke_floorflags(sect)); +} + +DEFINE_ACTION_FUNCTION_NATIVE(_DukeLevel, addcycler, addcycler) +{ + PARAM_PROLOGUE; + PARAM_POINTER(sect, sectortype); + PARAM_INT(lotag); + PARAM_INT(shade); + PARAM_INT(shade2); + PARAM_INT(hitag); + PARAM_INT(state); + addcycler(sect, lotag, shade, shade2, hitag, state); + return 0; +} + +DEFINE_ACTION_FUNCTION_NATIVE(_DukeLevel, addtorch, addtorch) +{ + PARAM_PROLOGUE; + PARAM_POINTER(sect, sectortype); + PARAM_INT(shade); + PARAM_INT(lotag); + addtorch(sect, shade, lotag); + return 0; +} + +DEFINE_ACTION_FUNCTION_NATIVE(_DukeLevel, addlightning, addlightning) +{ + PARAM_PROLOGUE; + PARAM_POINTER(sect, sectortype); + PARAM_INT(shade); + addlightning(sect, shade); + return 0; +} + +DEFINE_ACTION_FUNCTION_NATIVE(_DukeLevel, addambient, addambient) +{ + PARAM_PROLOGUE; + PARAM_INT(hitag); + PARAM_INT(lotag); + ACTION_RETURN_INT(addambient(hitag, lotag)); + return 0; +} + DEFINE_FIELD_X(DukeGameInfo, DukeGameInfo, playerfriction); DEFINE_FIELD_X(DukeGameInfo, DukeGameInfo, gravity); DEFINE_FIELD_X(DukeGameInfo, DukeGameInfo, respawnactortime); diff --git a/wadsrc/static/filter/duke/engine/engine.def b/wadsrc/static/filter/duke/engine/engine.def index d0208bd99..804b83e7e 100644 --- a/wadsrc/static/filter/duke/engine/engine.def +++ b/wadsrc/static/filter/duke/engine/engine.def @@ -5,8 +5,10 @@ spawnclasses 4 = DukeActivatorLocked 5 = DukeSoundController 6 = DukeLocator + 7 = DukeCycler 8 = DukeMasterSwitch 9 = DukeRespawnController + 10 = DukeGPSpeed 1221 = DukeCranePole 1222 = DukeCrane diff --git a/wadsrc/static/filter/redneck/engine/engine.def b/wadsrc/static/filter/redneck/engine/engine.def index e02cb3af1..cedc1e347 100644 --- a/wadsrc/static/filter/redneck/engine/engine.def +++ b/wadsrc/static/filter/redneck/engine/engine.def @@ -5,8 +5,16 @@ spawnclasses 4 = DukeActivatorLocked 5 = DukeSoundController 6 = DukeLocator + 7 = DukeCycler 8 = DukeMasterSwitch 9 = DukeRespawnController + 10 = DukeGPSpeed + + 18 = DukeTorchCtrl + 35 = DukeLightningCtrl + 68 = DukeShadeCtrl + 67 = DukeDummyCtrl + 71 = DukeSoundFX 1298 = DukeCranePole 1299 = DukeCrane diff --git a/wadsrc/static/zscript/games/duke/actors/bolt.zs b/wadsrc/static/zscript/games/duke/actors/bolt.zs index 760650219..4729a3adc 100644 --- a/wadsrc/static/zscript/games/duke/actors/bolt.zs +++ b/wadsrc/static/zscript/games/duke/actors/bolt.zs @@ -53,7 +53,7 @@ class DukeBolt1 : DukeActor if (l & 1) self.cstat ^= CSTAT_SPRITE_TRANSLUCENT; - if (self.spritesetindex == 1 && random(0, 7) == 0 && (Duke.floorflags(sectp) & Duke.TFLAG_ELECTRIC)) + if (self.spritesetindex == 1 && random(0, 7) == 0 && (dlevel.floorflags(sectp) & Duke.TFLAG_ELECTRIC)) self.PlayActorSound(DukeSnd.SHORT_CIRCUIT); if (self.spritesetindex & 1) @@ -132,7 +132,7 @@ class DukeSideBolt1 : DukeBolt1 } self.SetSpriteSetImage((self.spritesetindex + 1) % self.GetSpriteSetSize()); - if (random(0, 1) && (Duke.floorflags(sectp) & Duke.TFLAG_ELECTRIC)) + if (random(0, 1) && (dlevel.floorflags(sectp) & Duke.TFLAG_ELECTRIC)) self.PlayActorSound(DukeSnd.SHORT_CIRCUIT); } diff --git a/wadsrc/static/zscript/games/duke/actors/controllers.zs b/wadsrc/static/zscript/games/duke/actors/controllers.zs index 54914c3d5..578db9606 100644 --- a/wadsrc/static/zscript/games/duke/actors/controllers.zs +++ b/wadsrc/static/zscript/games/duke/actors/controllers.zs @@ -106,3 +106,74 @@ class DukeActivatorLocked : DukeActor */ } +// Note: StaticSetup is run much earlier than Initialize! This is only meant for things that modify global game state. + +class DukeCycler : DukeActor +{ + override void StaticSetup() + { + dlevel.AddCycler(self.sector, self.lotag, self.shade, self.sector.floorshade, self.hitag, self.intangle == 1536); + self.Destroy(); + } +} + +class DukeGPSpeed : DukeActor +{ + override void StaticSetup() + { + self.sector.extra = self.lotag; + self.Destroy(); + } +} + +// the following ones are only used in RR. +class TorchCtrl : DukeActor +{ + override void StaticSetup() + { + dlevel.addtorch(self.sector, self.sector.floorshade, self.lotag); + self.Destroy(); + } +} + +class DukeLightningCtrl : DukeActor +{ + override void StaticSetup() + { + dlevel.addlightning(self.sector, self.sector.floorshade); + self.Destroy(); + } +} + +class DukeShadeCtrl : DukeActor +{ + override void StaticSetup() + { + self.sector.shadedsector = 1; + self.Destroy(); + } +} + +class DukeDummyCtrl : DukeActor +{ + override void StaticSetup() + { + self.cstat |= CSTAT_SPRITE_INVISIBLE; + } +} + +class DukeSoundFX : DukeActor +{ + default + { + statnum STAT_ZOMBIEACTOR; + } + + override void StaticSetup() + { + self.cstat = CSTAT_SPRITE_INVISIBLE; + self.detail = dlevel.addambient(self.hitag, self.lotag); + self.lotag = self.hitag = 0; + } +} + diff --git a/wadsrc/static/zscript/games/duke/dukeactor.zs b/wadsrc/static/zscript/games/duke/dukeactor.zs index 0faf593ad..98af70a9c 100644 --- a/wadsrc/static/zscript/games/duke/dukeactor.zs +++ b/wadsrc/static/zscript/games/duke/dukeactor.zs @@ -168,6 +168,7 @@ class DukeActor : CoreActor native native void operatesectors(sectortype sec); virtual void BeginPlay() {} + virtual void StaticSetup() {} virtual void Initialize() {} virtual void Tick() {} virtual void onHit(DukeActor hitter) { checkhitdefault(hitter); } @@ -209,6 +210,11 @@ struct DukeLevel native static int check_activator_motion(int lotag); native static void operatemasterswitches(int lotag); native static void operateactivators(int lotag, DukePlayer p); + native static int floorflags(sectortype s); + native static void AddCycler(sectortype sector, int lotag, int shade, int shade2, int hitag, int state); + native static void addtorch(sectortype sector, int shade, int lotag); + native static void addlightning(sectortype sector, int shade); + native static int addambient(int hitag, int lotag); } struct DukeStatIterator diff --git a/wadsrc/static/zscript/games/duke/dukegame.zs b/wadsrc/static/zscript/games/duke/dukegame.zs index 5a67ee740..134b809c3 100644 --- a/wadsrc/static/zscript/games/duke/dukegame.zs +++ b/wadsrc/static/zscript/games/duke/dukegame.zs @@ -97,7 +97,6 @@ struct Duke native native static DukePlayer GetViewPlayer(); native static int MaxAmmoAmount(int weap); native static DukePlayer checkcursectnums(sectortype sect); - native static int floorflags(sectortype s); native static int global_random(); native static int GetSoundFlags(int sound); native static int badguyID(int id); diff --git a/wadsrc/static/zscript/maptypes.zs b/wadsrc/static/zscript/maptypes.zs index 6fdb4a436..4381af336 100644 --- a/wadsrc/static/zscript/maptypes.zs +++ b/wadsrc/static/zscript/maptypes.zs @@ -145,6 +145,9 @@ struct sectortype native native uint8 exflags; + // Duke + native uint8 shadedsector; + /* // Game specific extensions. Only export what's really needed. union