From cb005062cd072df274d9d39532ef1844a280cbe8 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 20 Nov 2022 12:43:24 +0100 Subject: [PATCH] - scriptified activators and locators. --- source/core/namedef_custom.h | 3 + source/games/duke/src/actors.cpp | 8 +- source/games/duke/src/gameexec.cpp | 2 +- source/games/duke/src/inlines.h | 15 +++ source/games/duke/src/player_r.cpp | 2 +- source/games/duke/src/premap.cpp | 4 - source/games/duke/src/sectors.cpp | 2 +- source/games/duke/src/sectors_d.cpp | 6 +- source/games/duke/src/sectors_r.cpp | 6 +- source/games/duke/src/spawn.cpp | 4 +- source/games/duke/src/spawn_d.cpp | 25 ---- source/games/duke/src/spawn_r.cpp | 12 -- wadsrc/static/filter/duke/engine/engine.def | 3 + .../static/filter/redneck/engine/engine.def | 3 + wadsrc/static/zscript.txt | 1 + .../zscript/games/duke/actors/controllers.zs | 108 ++++++++++++++++++ 16 files changed, 148 insertions(+), 56 deletions(-) create mode 100644 wadsrc/static/zscript/games/duke/actors/controllers.zs diff --git a/source/core/namedef_custom.h b/source/core/namedef_custom.h index 667ff40aa..ba66d721b 100644 --- a/source/core/namedef_custom.h +++ b/source/core/namedef_custom.h @@ -16,3 +16,6 @@ xx(DukeMasterSwitch) xx(DukeTouchplate) xx(DukeSoundController) xx(DukeRespawnController) +xx(DukeActivator) +xx(DukeActivatorLocked) +xx(DukeLocator) diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index c252584c3..40631a3c4 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -2123,7 +2123,7 @@ void handle_se14(DDukeActor* actor, bool checkstat, int RPG, int JIBS6) { if (a2->spr.statnum != STAT_PLAYER && a2->sector()->lotag != 2 && (a2->spr.picnum != SECTOREFFECTOR || a2->spr.lotag == SE_49_POINT_LIGHT || a2->spr.lotag == SE_50_SPOT_LIGHT) && - a2->spr.picnum != LOCATORS) + !islocator(a2)) { a2->spr.pos.XY() = rotatepoint(actor->spr.pos.XY(), a2->spr.pos.XY(), diffangle) + vec; a2->spr.angle += diffangle; @@ -2166,7 +2166,7 @@ void handle_se14(DDukeActor* actor, bool checkstat, int RPG, int JIBS6) DukeSectIterator itr(actOwner->sector()); while (auto a2 = itr.Next()) { - if (a2->spr.statnum == 1 && badguy(a2) && a2->spr.picnum != SECTOREFFECTOR && a2->spr.picnum != LOCATORS) + if (a2->spr.statnum == 1 && badguy(a2) && a2->spr.picnum != SECTOREFFECTOR && !islocator(a2)) { auto k = a2->sector(); updatesector(a2->spr.pos, &k); @@ -2285,7 +2285,7 @@ void handle_se30(DDukeActor *actor, int JIBS6) DukeSectIterator its(actor->sector()); while (auto a2 = its.Next()) { - if (a2->spr.picnum != SECTOREFFECTOR && a2->spr.picnum != LOCATORS) + if (a2->spr.picnum != SECTOREFFECTOR && !islocator(a2)) { a2->spr.pos += vect; @@ -2324,7 +2324,7 @@ void handle_se30(DDukeActor *actor, int JIBS6) DukeSectIterator it(Owner->sector()); while (auto a2 = it.Next()) { - if (a2->spr.statnum == STAT_ACTOR && badguy(a2) && a2->spr.picnum != SECTOREFFECTOR && a2->spr.picnum != LOCATORS) + if (a2->spr.statnum == STAT_ACTOR && badguy(a2) && a2->spr.picnum != SECTOREFFECTOR && !islocator(a2)) { // if(a2->spr.sector != actor->spr.sector) { diff --git a/source/games/duke/src/gameexec.cpp b/source/games/duke/src/gameexec.cpp index 87112d607..957a55f89 100644 --- a/source/games/duke/src/gameexec.cpp +++ b/source/games/duke/src/gameexec.cpp @@ -2498,7 +2498,7 @@ int ParseState::parse(void) DDukeActor* a2; while ((a2 = it.Next())) { - if (a2->spr.picnum == ACTIVATOR) + if (isactivator(a2)) break; } if (a2 == nullptr) diff --git a/source/games/duke/src/inlines.h b/source/games/duke/src/inlines.h index dc9fc2d64..56a8bc9d4 100644 --- a/source/games/duke/src/inlines.h +++ b/source/games/duke/src/inlines.h @@ -29,6 +29,21 @@ inline int isrespawncontroller(DDukeActor* actor) return actor->GetClass()->TypeName == NAME_DukeRespawnController; } +inline int isactivator(DDukeActor* actor) +{ + return actor->GetClass()->TypeName == NAME_DukeActivator; +} + +inline int islockedactivator(DDukeActor* actor) +{ + return actor->GetClass()->TypeName == NAME_DukeActivatorLocked; +} + +inline int islocator(DDukeActor* actor) +{ + return actor->GetClass()->TypeName == NAME_DukeLocator; +} + inline int badguypic(int const tileNum) { return ((gs.actorinfo[tileNum].flags & (SFLAG_INTERNAL_BADGUY | SFLAG_BADGUY)) != 0); diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index 51ec9b400..45e8e95c4 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -2446,7 +2446,7 @@ void onMotorcycleHit(int snum, DDukeActor* victim) p->TurbCount = 6; } else if ((victim->spr.picnum == RRTILE2431 || victim->spr.picnum == RRTILE2443 || victim->spr.picnum == RRTILE2451 || victim->spr.picnum == RRTILE2455) - && victim->spr.picnum != ACTIVATORLOCKED && p->MotoSpeed > 45) + && !islockedactivator(victim) && p->MotoSpeed > 45) { S_PlayActorSound(SQUISHED, victim); if (victim->spr.picnum == RRTILE2431 || victim->spr.picnum == RRTILE2451) diff --git a/source/games/duke/src/premap.cpp b/source/games/duke/src/premap.cpp index 448308a93..c9cc5ef05 100644 --- a/source/games/duke/src/premap.cpp +++ b/source/games/duke/src/premap.cpp @@ -47,10 +47,6 @@ void premapcontroller(DDukeActor* ac) { switch (ac->spr.picnum) { - case ACTIVATOR: - case ACTIVATORLOCKED: - case LOCATORS: - case MUSICANDSFX: case SECTOREFFECTOR: ac->spr.cstat &= ~(CSTAT_SPRITE_BLOCK | CSTAT_SPRITE_BLOCK_HITSCAN | CSTAT_SPRITE_ALIGNMENT_MASK); break; diff --git a/source/games/duke/src/sectors.cpp b/source/games/duke/src/sectors.cpp index 5f0796e79..4ad06268a 100644 --- a/source/games/duke/src/sectors.cpp +++ b/source/games/duke/src/sectors.cpp @@ -1128,7 +1128,7 @@ void operateactivators(int low, player_struct* plr) { if (act->spr.lotag == low) { - if (act->spr.picnum == ACTIVATORLOCKED) + if (islockedactivator(act)) { act->sector()->lotag ^= 16384; diff --git a/source/games/duke/src/sectors_d.cpp b/source/games/duke/src/sectors_d.cpp index 17cab1eaf..c3b70213e 100644 --- a/source/games/duke/src/sectors_d.cpp +++ b/source/games/duke/src/sectors_d.cpp @@ -592,7 +592,7 @@ void activatebysector_d(sectortype* sect, DDukeActor* activator) DukeSectIterator it(sect); while (auto act = it.Next()) { - if (act->spr.picnum == ACTIVATOR) + if (isactivator(act)) { operateactivators(act->spr.lotag, nullptr); didit = 1; @@ -1669,7 +1669,7 @@ void checksectors_d(int snum) DukeSectIterator it(near.hitSector); while (auto act = it.Next()) { - if (act->spr.picnum == ACTIVATOR || ismasterswitch(act)) + if (isactivator(act) || ismasterswitch(act)) return; } operatesectors(near.hitSector, p->GetActor()); @@ -1681,7 +1681,7 @@ void checksectors_d(int snum) DukeSectIterator it(p->GetActor()->sector()); while (auto act = it.Next()) { - if (act->spr.picnum == ACTIVATOR || ismasterswitch(act)) return; + if (isactivator(act) || ismasterswitch(act)) return; } operatesectors(p->GetActor()->sector(), p->GetActor()); } diff --git a/source/games/duke/src/sectors_r.cpp b/source/games/duke/src/sectors_r.cpp index deb5d587f..1759aefce 100644 --- a/source/games/duke/src/sectors_r.cpp +++ b/source/games/duke/src/sectors_r.cpp @@ -875,7 +875,7 @@ void activatebysector_r(sectortype* sect, DDukeActor* activator) DukeSectIterator it(sect); while (auto act = it.Next()) { - if (act->spr.picnum == ACTIVATOR) + if (isactivator(act)) { operateactivators(act->spr.lotag, nullptr); // return; @@ -2637,7 +2637,7 @@ void checksectors_r(int snum) DukeSectIterator it(near.hitSector); while (auto act = it.Next()) { - if (act->spr.picnum == ACTIVATOR || ismasterswitch(act)) + if (isactivator(act) || ismasterswitch(act)) return; } if (haskey(near.hitSector, snum)) @@ -2658,7 +2658,7 @@ void checksectors_r(int snum) DukeSectIterator it(p->GetActor()->sector()); while (auto act = it.Next()) { - if (act->spr.picnum == ACTIVATOR || ismasterswitch(act)) + if (isactivator(act) || ismasterswitch(act)) return; } if (haskey(near.hitSector, snum)) diff --git a/source/games/duke/src/spawn.cpp b/source/games/duke/src/spawn.cpp index 018c7f369..30c26dc61 100644 --- a/source/games/duke/src/spawn.cpp +++ b/source/games/duke/src/spawn.cpp @@ -297,7 +297,7 @@ void spawninitdefault(DDukeActor* actj, DDukeActor *act) act->clipdist = 20; if (actj) { - if (actj->spr.picnum == RESPAWN) + if (isrespawncontroller(actj)) act->tempval = act->spr.pal = actj->spr.pal; ChangeActorStat(act, STAT_ACTOR); } @@ -917,7 +917,7 @@ void spawneffector(DDukeActor* actor, TArray* actors) DukeSectIterator it(actor->sector()); while (auto itActor = it.Next()) { - if (itActor->spr.picnum == ACTIVATOR || itActor->spr.picnum == ACTIVATORLOCKED) + if (isactivator(itActor) || islockedactivator(itActor)) actor->flags2 |= SFLAG2_USEACTIVATOR; } ChangeActorStat(actor, STAT_LIGHT); diff --git a/source/games/duke/src/spawn_d.cpp b/source/games/duke/src/spawn_d.cpp index 4be711f55..127006db8 100644 --- a/source/games/duke/src/spawn_d.cpp +++ b/source/games/duke/src/spawn_d.cpp @@ -520,18 +520,6 @@ DDukeActor* spawninit_d(DDukeActor* actj, DDukeActor* act, TArray* initshell(actj, act, act->spr.picnum == SHELL); break; - case RESPAWN: - act->spr.extra = 66 - 13; - if (ud.multimode < 2 && act->spr.pal == 1) - { - act->spr.scale = DVector2(0, 0); - ChangeActorStat(act, STAT_MISC); - break; - } - act->spr.cstat = CSTAT_SPRITE_INVISIBLE; - ChangeActorStat(act, STAT_FX); - break; - case ONFIRE: // Twentieth Anniversary World Tour if (!isWorldTour()) @@ -779,19 +767,6 @@ DDukeActor* spawninit_d(DDukeActor* actj, DDukeActor* act, TArray* break; - case LOCATORS: - act->spr.cstat |= CSTAT_SPRITE_INVISIBLE; - ChangeActorStat(act, STAT_LOCATOR); - break; - - case ACTIVATORLOCKED: - case ACTIVATOR: - act->spr.cstat = CSTAT_SPRITE_INVISIBLE; - if (act->spr.picnum == ACTIVATORLOCKED) - act->sector()->lotag |= 16384; - ChangeActorStat(act, STAT_ACTIVATOR); - break; - case OOZ: case OOZ2: { diff --git a/source/games/duke/src/spawn_r.cpp b/source/games/duke/src/spawn_r.cpp index 17d6c0f11..9ddbd34c1 100644 --- a/source/games/duke/src/spawn_r.cpp +++ b/source/games/duke/src/spawn_r.cpp @@ -948,18 +948,6 @@ DDukeActor* spawninit_r(DDukeActor* actj, DDukeActor* act, TArray* } break; - case LOCATORS: - act->spr.cstat |= CSTAT_SPRITE_INVISIBLE; - ChangeActorStat(act, STAT_LOCATOR); - break; - - case ACTIVATORLOCKED: - case ACTIVATOR: - act->spr.cstat |= CSTAT_SPRITE_INVISIBLE; - if (act->spr.picnum == ACTIVATORLOCKED) - sectp->lotag ^= 16384; - ChangeActorStat(act, STAT_ACTIVATOR); - break; case OOZ: { diff --git a/wadsrc/static/filter/duke/engine/engine.def b/wadsrc/static/filter/duke/engine/engine.def index 582038888..d0208bd99 100644 --- a/wadsrc/static/filter/duke/engine/engine.def +++ b/wadsrc/static/filter/duke/engine/engine.def @@ -1,7 +1,10 @@ spawnclasses { + 2 = DukeActivator 3 = DukeTouchplate + 4 = DukeActivatorLocked 5 = DukeSoundController + 6 = DukeLocator 8 = DukeMasterSwitch 9 = DukeRespawnController diff --git a/wadsrc/static/filter/redneck/engine/engine.def b/wadsrc/static/filter/redneck/engine/engine.def index 4a6b5da24..e02cb3af1 100644 --- a/wadsrc/static/filter/redneck/engine/engine.def +++ b/wadsrc/static/filter/redneck/engine/engine.def @@ -1,7 +1,10 @@ spawnclasses { + 2 = DukeActivator 3 = DukeTouchplate + 4 = DukeActivatorLocked 5 = DukeSoundController + 6 = DukeLocator 8 = DukeMasterSwitch 9 = DukeRespawnController diff --git a/wadsrc/static/zscript.txt b/wadsrc/static/zscript.txt index 3601c46e0..3a5f63824 100644 --- a/wadsrc/static/zscript.txt +++ b/wadsrc/static/zscript.txt @@ -50,6 +50,7 @@ version "4.10" #include "zscript/games/duke/ui/screens.zs" #include "zscript/games/duke/ui/cutscenes.zs" #include "zscript/games/duke/ui/menu.zs" +#include "zscript/games/duke/actors/controllers.zs" #include "zscript/games/duke/actors/masterswitch.zs" #include "zscript/games/duke/actors/touchplate.zs" #include "zscript/games/duke/actors/soundcontroller.zs" diff --git a/wadsrc/static/zscript/games/duke/actors/controllers.zs b/wadsrc/static/zscript/games/duke/actors/controllers.zs new file mode 100644 index 000000000..54914c3d5 --- /dev/null +++ b/wadsrc/static/zscript/games/duke/actors/controllers.zs @@ -0,0 +1,108 @@ + +class DukeActivator : DukeActor +{ + default + { + statnum STAT_ACTIVATOR; + } + + override void Initialize() + { + self.cstat = CSTAT_SPRITE_INVISIBLE; + } + + /* this first needs work on the sector effectors. + override void onActivate(int low, DukePlayer plr) + { + switch (self.hitag) + { + case 0: + break; + case 1: + if (self.sector.floorz != self.sector.ceilingz) + { + continue; + } + break; + case 2: + if (self.sector.floorz == self.sector.ceilingz) + { + continue; + } + break; + } + + if (self.sector.lotag < 3) + { + DukeSectIterator itr; + for(let a2 = itr.First(self.sector); a2; a2 = itr.Next()) + { + // todo: move this into the effectors as a virtual override. + if (a2.statnum == STAT_EFFECTOR) switch (a2.lotag) + { + case SE_18_INCREMENTAL_SECTOR_RISE_FALL: + if (Raze.isRRRA()) break; + + case SE_36_PROJ_SHOOTER: + case SE_31_FLOOR_RISE_FALL: + case SE_32_CEILING_RISE_FALL: + a2.temp_data[0] = 1 - a2.temp_data[0]; + a2.callsound(self.sector()); + break; + } + } + } + + if (k == -1 && (self.sector.lotag & 0xff) == SE_22_TEETH_DOOR) + k = act.callsound(self.sector); + + self.operatesectors(self.sector); + } + */ +} + +class DukeLocator : DukeActor +{ + default + { + statnum STAT_LOCATOR; + } + + override void Initialize() + { + self.cstat = CSTAT_SPRITE_INVISIBLE; + } +} + +class DukeActivatorLocked : DukeActor +{ + default + { + statnum STAT_ACTIVATOR; + } + + override void Initialize() + { + self.cstat = CSTAT_SPRITE_INVISIBLE; + if (!Raze.IsRR()) self.lotag |= 16384; + else self.lotag ^= 16384; + } + + /* must wait until Activator.onActivate can be done. + override void onActivate(int low, DukePlayer plr) + { + if (self.lotag == low) + { + self.sector.lotag ^= 16384; + + if (plr) + { + if (self.sector.lotag & 16384) + plr.FTA(QUOTE_LOCKED, true); + else plr.FTA(QUOTE_UNLOCKED, true); + } + } + } + */ +} +