From 046ba1ae0cd8e1964ac4fe6ea5717496907495e6 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 19 Nov 2022 15:40:35 +0100 Subject: [PATCH] - scriptified touchplate --- source/core/namedef_custom.h | 1 + source/games/duke/src/actors.cpp | 87 +------------ source/games/duke/src/actors_d.cpp | 7 +- source/games/duke/src/actors_r.cpp | 7 +- source/games/duke/src/funct.h | 3 +- source/games/duke/src/gameexec.cpp | 2 +- source/games/duke/src/sectors.cpp | 9 +- source/games/duke/src/sectors_d.cpp | 4 +- source/games/duke/src/sectors_r.cpp | 6 +- source/games/duke/src/vmexports.cpp | 39 ++++++ wadsrc/static/filter/duke/engine/engine.def | 1 + .../static/filter/redneck/engine/engine.def | 1 + wadsrc/static/zscript.txt | 1 + wadsrc/static/zscript/coreactor.zs | 2 + .../zscript/games/duke/actors/touchplate.zs | 123 ++++++++++++++++++ wadsrc/static/zscript/games/duke/dukeactor.zs | 3 + wadsrc/static/zscript/games/duke/dukegame.zs | 1 + 17 files changed, 187 insertions(+), 110 deletions(-) create mode 100644 wadsrc/static/zscript/games/duke/actors/touchplate.zs diff --git a/source/core/namedef_custom.h b/source/core/namedef_custom.h index 788297313..4c989ff5d 100644 --- a/source/core/namedef_custom.h +++ b/source/core/namedef_custom.h @@ -13,3 +13,4 @@ xx(AltHud) // internal Duke actor classes that need direct checking xx(DukeMasterSwitch) +xx(DukeTouchplate) diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index 11fe5cdfb..2b5600f4b 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -673,89 +673,6 @@ void detonate(DDukeActor *actor, int explosion) // //--------------------------------------------------------------------------- -void movetouchplate(DDukeActor* actor, int plate) -{ - auto sectp = actor->sector(); - int p; - - if (actor->temp_data[1] == 1 && actor->spr.hitag >= 0) //Move the sector floor - { - double X = sectp->floorz; - double add = sectp->extra * zmaptoworld; - - if (actor->temp_data[3] == 1) - { - if (X >= actor->temp_pos.Z) - { - sectp->setfloorz(X); - actor->temp_data[1] = 0; - } - else - { - sectp->addfloorz(add); - p = checkcursectnums(actor->sector()); - if (p >= 0) ps[p].pos.Z += add; - } - } - else - { - if (X <= actor->spr.pos.Z) - { - sectp->setfloorz(actor->spr.pos.Z); - actor->temp_data[1] = 0; - } - else - { - sectp->floorz -= add; - p = checkcursectnums(actor->sector()); - if (p >= 0) - ps[p].pos.Z -= add; - } - } - return; - } - - if (actor->temp_data[5] == 1) return; - - p = checkcursectnums(actor->sector()); - if (p >= 0 && (ps[p].on_ground || actor->spr.intangle == 512)) - { - if (actor->temp_data[0] == 0 && !check_activator_motion(actor->spr.lotag)) - { - actor->temp_data[0] = 1; - actor->temp_data[1] = 1; - actor->temp_data[3] = !actor->temp_data[3]; - operatemasterswitches(actor->spr.lotag); - operateactivators(actor->spr.lotag, p); - if (actor->spr.hitag > 0) - { - actor->spr.hitag--; - if (actor->spr.hitag == 0) actor->temp_data[5] = 1; - } - } - } - else actor->temp_data[0] = 0; - - if (actor->temp_data[1] == 1) - { - DukeStatIterator it(STAT_STANDABLE); - while (auto act2 = it.Next()) - { - if (act2 != actor && act2->spr.picnum == plate && act2->spr.lotag == actor->spr.lotag) - { - act2->temp_data[1] = 1; - act2->temp_data[3] = actor->temp_data[3]; - } - } - } -} - -//--------------------------------------------------------------------------- -// -// -// -//--------------------------------------------------------------------------- - void movecanwithsomething(DDukeActor* actor) { makeitfall(actor); @@ -2429,7 +2346,7 @@ void handle_se30(DDukeActor *actor, int JIBS6) else { if (actor->vel.X == 0) - operateactivators(actor->spr.hitag + (!actor->temp_data[3]), -1); + operateactivators(actor->spr.hitag + (!actor->temp_data[3]), nullptr); if (actor->vel.X < 16) actor->vel.X += 1; } @@ -2444,7 +2361,7 @@ void handle_se30(DDukeActor *actor, int JIBS6) else { actor->vel.X = 0; - operateactivators(actor->spr.hitag + (short)actor->temp_data[3], -1); + operateactivators(actor->spr.hitag + (short)actor->temp_data[3], nullptr); actor->SetOwner(nullptr); actor->spr.angle += DAngle180; actor->temp_data[4] = 0; diff --git a/source/games/duke/src/actors_d.cpp b/source/games/duke/src/actors_d.cpp index 66a19a894..10a52132e 100644 --- a/source/games/duke/src/actors_d.cpp +++ b/source/games/duke/src/actors_d.cpp @@ -849,11 +849,6 @@ void movestandables_d(void) moveviewscreen(act); } - else if (picnum == TOUCHPLATE) - { - movetouchplate(act, TOUCHPLATE); - } - else if (isIn(picnum, CANWITHSOMETHING, CANWITHSOMETHING2, CANWITHSOMETHING3, CANWITHSOMETHING4)) { movecanwithsomething(act); @@ -2417,7 +2412,7 @@ void moveactors_d(void) if (k == 1) { - operateactivators(act->spr.lotag, -1); + operateactivators(act->spr.lotag, nullptr); fi.operateforcefields(act, act->spr.lotag); operatemasterswitches(act->spr.lotag); } diff --git a/source/games/duke/src/actors_r.cpp b/source/games/duke/src/actors_r.cpp index 7e8f20bb7..0def1e04d 100644 --- a/source/games/duke/src/actors_r.cpp +++ b/source/games/duke/src/actors_r.cpp @@ -732,11 +732,6 @@ void movestandables_r(void) continue; } - else if (picnum == TOUCHPLATE) - { - movetouchplate(act, TOUCHPLATE); - } - else if (picnum == CANWITHSOMETHING) { movecanwithsomething(act); @@ -3581,7 +3576,7 @@ void fakebubbaspawn(DDukeActor *actor, int g_p) break; case 4: spawn(actor, VIXEN); - operateactivators(666, g_p); + operateactivators(666, &ps[g_p]); break; } } diff --git a/source/games/duke/src/funct.h b/source/games/duke/src/funct.h index 41f271938..68e627933 100644 --- a/source/games/duke/src/funct.h +++ b/source/games/duke/src/funct.h @@ -32,7 +32,6 @@ void movefta(); void clearcameras(int i, player_struct* p); void RANDOMSCRAP(DDukeActor* i); void detonate(DDukeActor* i, int explosion); -void movetouchplate(DDukeActor* i, int plate); void movecanwithsomething(DDukeActor* i); void bounce(DDukeActor* i); void movetongue(DDukeActor* i, int tongue, int jaw); @@ -139,7 +138,7 @@ void allignwarpelevators(void); bool isablockdoor(int tileNum); bool activatewarpelevators(DDukeActor* s, int w); int check_activator_motion(int lotag); -void operateactivators(int l, int w); +void operateactivators(int l, player_struct* w); void operateforcefields_common(DDukeActor* s, int low, const std::initializer_list& tiles); void operatemasterswitches(int lotag); void operatesectors(sectortype* s, DDukeActor* i); diff --git a/source/games/duke/src/gameexec.cpp b/source/games/duke/src/gameexec.cpp index 04a95c27b..87112d607 100644 --- a/source/games/duke/src/gameexec.cpp +++ b/source/games/duke/src/gameexec.cpp @@ -1615,7 +1615,7 @@ int ParseState::parse(void) insptr++; break; case concmd_mamatrigger: - operateactivators(667, g_p); + operateactivators(667, &ps[g_p]); insptr++; break; case concmd_mamaspawn: diff --git a/source/games/duke/src/sectors.cpp b/source/games/duke/src/sectors.cpp index 75f471d99..a63e69c86 100644 --- a/source/games/duke/src/sectors.cpp +++ b/source/games/duke/src/sectors.cpp @@ -1099,7 +1099,7 @@ void operatesectors(sectortype* sptr, DDukeActor *actor) // //--------------------------------------------------------------------------- -void operateactivators(int low, int plnum) +void operateactivators(int low, player_struct* plr) { int i, j, k; Cycler * p; @@ -1132,11 +1132,11 @@ void operateactivators(int low, int plnum) { act->sector()->lotag ^= 16384; - if (plnum >= 0) + if (plr) { if (act->sector()->lotag & 16384) - FTA(4, &ps[plnum]); - else FTA(8, &ps[plnum]); + FTA(4, plr); + else FTA(8, plr); } } else @@ -1204,7 +1204,6 @@ void operatemasterswitches(int low) if (ismasterswitch(act2) && act2->spr.lotag == low && act2->spr.yint == 0) { act2->spr.yint = 1; - Printf("triggering %d\n", act2->time); } } } diff --git a/source/games/duke/src/sectors_d.cpp b/source/games/duke/src/sectors_d.cpp index f92baff92..5e5de2f29 100644 --- a/source/games/duke/src/sectors_d.cpp +++ b/source/games/duke/src/sectors_d.cpp @@ -578,7 +578,7 @@ bool checkhitswitch_d(int snum, walltype* wwal, DDukeActor *act) } } - operateactivators(lotag, snum); + operateactivators(lotag, &ps[snum]); fi.operateforcefields(ps[snum].GetActor(), lotag); operatemasterswitches(lotag); @@ -622,7 +622,7 @@ void activatebysector_d(sectortype* sect, DDukeActor* activator) { if (act->spr.picnum == ACTIVATOR) { - operateactivators(act->spr.lotag, -1); + operateactivators(act->spr.lotag, nullptr); didit = 1; // return; } diff --git a/source/games/duke/src/sectors_r.cpp b/source/games/duke/src/sectors_r.cpp index 3b5547283..a552cb720 100644 --- a/source/games/duke/src/sectors_r.cpp +++ b/source/games/duke/src/sectors_r.cpp @@ -771,7 +771,7 @@ bool checkhitswitch_r(int snum, walltype* wwal, DDukeActor* act) { if (ps[snum].SeaSick == 0) ps[snum].SeaSick = 350; - operateactivators(668, snum); + operateactivators(668, &ps[snum]); operatemasterswitches(668); S_PlayActorSound(328, ps[snum].GetActor()); return 1; @@ -867,7 +867,7 @@ bool checkhitswitch_r(int snum, walltype* wwal, DDukeActor* act) } } - operateactivators(lotag, snum); + operateactivators(lotag, &ps[snum]); fi.operateforcefields(ps[snum].GetActor(), lotag); operatemasterswitches(lotag); @@ -909,7 +909,7 @@ void activatebysector_r(sectortype* sect, DDukeActor* activator) { if (act->spr.picnum == ACTIVATOR) { - operateactivators(act->spr.lotag, -1); + operateactivators(act->spr.lotag, nullptr); // return; } } diff --git a/source/games/duke/src/vmexports.cpp b/source/games/duke/src/vmexports.cpp index 5693fe513..831e0cad2 100644 --- a/source/games/duke/src/vmexports.cpp +++ b/source/games/duke/src/vmexports.cpp @@ -654,6 +654,21 @@ DEFINE_ACTION_FUNCTION_NATIVE(_DukePlayer, setpos, dukeplayer_setpos) return 0; } +void dukeplayer_addpos(player_struct* self, double x, double y, double z) +{ + self->pos += { x, y, z }; +} + +DEFINE_ACTION_FUNCTION_NATIVE(_DukePlayer, addpos, dukeplayer_addpos) +{ + PARAM_SELF_STRUCT_PROLOGUE(player_struct); + PARAM_FLOAT(x); + PARAM_FLOAT(y); + PARAM_FLOAT(z); + dukeplayer_addpos(self, x, y, z); + return 0; +} + void dukeplayer_settargetangle(player_struct* self, double a, int backup) { self->angle.settarget(DAngle::fromDeg(a), backup); @@ -775,6 +790,30 @@ DEFINE_ACTION_FUNCTION_NATIVE(_DukeLevel, SpawnActor, DukeLevel_SpawnActor) ACTION_RETURN_POINTER(DukeLevel_SpawnActor(self, sect, x, y, z, static_cast(type), shade, scalex, scaley, angle, vel, zvel, owner, stat)); } +DEFINE_ACTION_FUNCTION_NATIVE(_DukeLevel, check_activator_motion, check_activator_motion) +{ + PARAM_PROLOGUE; + PARAM_INT(lotag); + ACTION_RETURN_INT(check_activator_motion(lotag)); +} + +DEFINE_ACTION_FUNCTION_NATIVE(_DukeLevel, operatemasterswitches, operatemasterswitches) +{ + PARAM_PROLOGUE; + PARAM_INT(lotag); + operatemasterswitches(lotag); + return 0; +} + +DEFINE_ACTION_FUNCTION_NATIVE(_DukeLevel, operateactivators, operateactivators) +{ + PARAM_PROLOGUE; + PARAM_INT(lotag); + PARAM_POINTER(p, player_struct); + operateactivators(lotag, p); + 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 1d1564205..077ea46a8 100644 --- a/wadsrc/static/filter/duke/engine/engine.def +++ b/wadsrc/static/filter/duke/engine/engine.def @@ -1,6 +1,7 @@ spawnclasses { 8 = DukeMasterSwitch + 3 = DukeTouchplate 1221 = DukeCranePole 1222 = DukeCrane diff --git a/wadsrc/static/filter/redneck/engine/engine.def b/wadsrc/static/filter/redneck/engine/engine.def index 7c1720a96..2993c749f 100644 --- a/wadsrc/static/filter/redneck/engine/engine.def +++ b/wadsrc/static/filter/redneck/engine/engine.def @@ -1,6 +1,7 @@ spawnclasses { 8 = DukeMasterSwitch + 3 = DukeTouchplate 1298 = DukeCranePole 1299 = DukeCrane diff --git a/wadsrc/static/zscript.txt b/wadsrc/static/zscript.txt index 35082d22e..624840223 100644 --- a/wadsrc/static/zscript.txt +++ b/wadsrc/static/zscript.txt @@ -51,6 +51,7 @@ version "4.10" #include "zscript/games/duke/ui/cutscenes.zs" #include "zscript/games/duke/ui/menu.zs" #include "zscript/games/duke/actors/masterswitch.zs" +#include "zscript/games/duke/actors/touchplate.zs" #include "zscript/games/duke/actors/crane.zs" #include "zscript/games/duke/actors/waterfountain.zs" #include "zscript/games/duke/actors/flammables.zs" diff --git a/wadsrc/static/zscript/coreactor.zs b/wadsrc/static/zscript/coreactor.zs index b6df8935e..eb05721e8 100644 --- a/wadsrc/static/zscript/coreactor.zs +++ b/wadsrc/static/zscript/coreactor.zs @@ -7,6 +7,8 @@ enum EClipMask const MAXPLAYERS = 8; const MAXSTATUS = 1024; +const zmaptoworld = (1. / 256.); +const maptoworld = (1. / 16.); class CoreActor native { diff --git a/wadsrc/static/zscript/games/duke/actors/touchplate.zs b/wadsrc/static/zscript/games/duke/actors/touchplate.zs new file mode 100644 index 000000000..a1f3f795d --- /dev/null +++ b/wadsrc/static/zscript/games/duke/actors/touchplate.zs @@ -0,0 +1,123 @@ + +class DukeTouchPlate : DukeActor +{ + default + { + statnum STAT_STANDABLE; + } + + private bool checkspawn() + { + if (!Raze.isWorldTour()) + { + if (self.pal && ud.multimode > 1) return false; + } + else { // Twentieth Anniversary World Tour addition - needs to be guarded because some mods surely will run afoul of it + if ((self.pal == 1 && ud.multimode > 1) // Single-game Only + || (self.pal == 2 && (ud.multimode == 1 || (ud.multimode > 1 && ud.coop != 1))) // Co-op Only + || (self.pal == 3 && (ud.multimode == 1 || (ud.multimode > 1 && ud.coop == 1)))) // Dukematch Only + { + return false; + } + } + return true; + } + + override void Initialize() + { + let sectp = self.sector; + self.temp_data[2] = sectp.floorz; + if (sectp.lotag != 1 && sectp.lotag != 2) + sectp.setfloorz(self.pos.Z); + if (!checkspawn()) + { + self.Scale = (0, 0); + self.ChangeStat(STAT_MISC); + return; + } + self.cstat |= CSTAT_SPRITE_INVISIBLE; + } + + + //--------------------------------------------------------------------------- + // + // + // + //--------------------------------------------------------------------------- + + override void Tick() + { + let sectp = self.sector; + DukePlayer p; + + if (self.temp_data[1] == 1 && self.hitag >= 0) //Move the sector floor + { + double Z = sectp.floorz; + double add = sectp.extra * zmaptoworld; + + if (self.temp_data[3] == 1) + { + if (Z >= self.temp_pos.Z) + { + sectp.setfloorz(Z); + self.temp_data[1] = 0; + } + else + { + sectp.addfloorz(add); + p = Duke.checkcursectnums(sectp); + if (p != null) p.addpos((0, 0, add)); + } + } + else + { + if (Z <= self.pos.Z) + { + sectp.setfloorz(self.pos.Z); + self.temp_data[1] = 0; + } + else + { + sectp.addfloorz(-add); + p = Duke.checkcursectnums(sectp); + if (p != null) p.addpos((0, 0, -add)); + } + } + return; + } + + if (self.temp_data[5] == 1) return; + + p = Duke.checkcursectnums(sectp); + if (p != null && (p.on_ground || self.intangle == 512)) + { + if (self.temp_data[0] == 0 && !dlevel.check_activator_motion(self.lotag)) + { + self.temp_data[0] = 1; + self.temp_data[1] = 1; + self.temp_data[3] = !self.temp_data[3]; + dlevel.operatemasterswitches(self.lotag); + dlevel.operateactivators(self.lotag, p); + if (self.hitag > 0) + { + self.hitag--; + if (self.hitag == 0) self.temp_data[5] = 1; + } + } + } + else self.temp_data[0] = 0; + + if (self.temp_data[1] == 1) + { + DukeStatIterator it; + for(let act2 = it.first(STAT_STANDABLE); act2; act2 = it.Next()) + { + if (act2 != self && act2 is 'DukeTouchPlate' && act2.lotag == self.lotag) + { + act2.temp_data[1] = 1; + act2.temp_data[3] = self.temp_data[3]; + } + } + } + } +} diff --git a/wadsrc/static/zscript/games/duke/dukeactor.zs b/wadsrc/static/zscript/games/duke/dukeactor.zs index 11c7e5c42..bd1ec7f67 100644 --- a/wadsrc/static/zscript/games/duke/dukeactor.zs +++ b/wadsrc/static/zscript/games/duke/dukeactor.zs @@ -172,6 +172,9 @@ extend struct _ struct DukeLevel { native DukeActor SpawnActor(sectortype sect, Vector3 pos, class type, int shade, Vector2 scale, double angle, double vel, double zvel, DukeActor owner, int stat = -1); + native static int check_activator_motion(int lotag); + native static void operatemasterswitches(int lotag); + native static void operateactivators(int lotag, DukePlayer p); } struct DukeStatIterator diff --git a/wadsrc/static/zscript/games/duke/dukegame.zs b/wadsrc/static/zscript/games/duke/dukegame.zs index e3c88e057..7e318f743 100644 --- a/wadsrc/static/zscript/games/duke/dukegame.zs +++ b/wadsrc/static/zscript/games/duke/dukegame.zs @@ -277,6 +277,7 @@ struct DukePlayer native native void backuppos(); native void backupxyz(); native void setpos(Vector3 pos); + native void addpos(Vector3 pos); native void settargetangle(double angle, bool backup = false); native double angle();