From 5fea500f92f0204a47ab768af58989b9091893be Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 14 Nov 2022 16:31:45 +0100 Subject: [PATCH] - flammable actors scriptified. --- source/games/duke/src/actors.cpp | 59 --------- source/games/duke/src/actors_d.cpp | 5 - source/games/duke/src/actors_r.cpp | 6 - source/games/duke/src/dispatch.cpp | 5 - source/games/duke/src/flags_d.cpp | 5 - source/games/duke/src/flags_r.cpp | 5 - source/games/duke/src/funct.h | 1 - source/games/duke/src/inlines.h | 5 - source/games/duke/src/names.h | 5 - source/games/duke/src/sectors_d.cpp | 15 --- source/games/duke/src/sectors_r.cpp | 15 --- source/games/duke/src/spawn_d.cpp | 15 +-- source/games/duke/src/spawn_r.cpp | 13 +- source/games/duke/src/vmexports.cpp | 46 +++++++ wadsrc/static/filter/duke/engine/engine.def | 6 +- .../static/filter/redneck/engine/engine.def | 5 + wadsrc/static/zscript.txt | 1 + wadsrc/static/zscript/coreactor.zs | 1 + .../zscript/games/duke/actors/flammables.zs | 117 ++++++++++++++++++ wadsrc/static/zscript/games/duke/dukeactor.zs | 62 ++++++++++ 20 files changed, 239 insertions(+), 153 deletions(-) create mode 100644 wadsrc/static/zscript/games/duke/actors/flammables.zs diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index b27abb5ff..6a6537671 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -614,65 +614,6 @@ void movefx(void) } } -//--------------------------------------------------------------------------- -// -// -// -//--------------------------------------------------------------------------- - -void moveflammable(DDukeActor* actor, int pool) -{ - double scale; - if (actor->temp_data[0] == 1) - { - actor->temp_data[1]++; - if ((actor->temp_data[1] & 3) > 0) return; - - if (actorflag(actor, SFLAG_FLAMMABLEPOOLEFFECT) && actor->temp_data[1] == 32) - { - actor->spr.cstat = 0; - auto spawned = spawn(actor, pool); - if (spawned) - { - spawned->spr.pal = 2; - spawned->spr.shade = 127; - } - } - else - { - if (actor->spr.shade < 64) actor->spr.shade++; - else - { - deletesprite(actor); - return; - } - } - - scale = actor->spr.scale.X - (krand() & 7) * REPEAT_SCALE; - if (scale < 0.15625) - { - deletesprite(actor); - return; - } - - actor->spr.scale.X = (scale); - - scale = actor->spr.scale.Y - (krand() & 7) * REPEAT_SCALE; - if (scale < 0.0625) - { - deletesprite(actor); - return; - } - actor->spr.scale.Y = (scale); - } - if (actorflag(actor, SFLAG_FALLINGFLAMMABLE)) - { - makeitfall(actor); - actor->ceilingz = actor->sector()->ceilingz; - } -} - - //--------------------------------------------------------------------------- // // diff --git a/source/games/duke/src/actors_d.cpp b/source/games/duke/src/actors_d.cpp index 5c873b488..46ebdcd21 100644 --- a/source/games/duke/src/actors_d.cpp +++ b/source/games/duke/src/actors_d.cpp @@ -1188,11 +1188,6 @@ void movestandables_d(void) continue; } - else if (AFLAMABLE(picnum)) - { - moveflammable(act, BLOODPOOL); - } - else if (picnum == TRIPBOMB) { movetripbomb(act); diff --git a/source/games/duke/src/actors_r.cpp b/source/games/duke/src/actors_r.cpp index df021b82f..d6c568ab1 100644 --- a/source/games/duke/src/actors_r.cpp +++ b/source/games/duke/src/actors_r.cpp @@ -826,12 +826,6 @@ void movestandables_r(void) continue; } - else if (AFLAMABLE(picnum)) - { - moveflammable(act, BLOODPOOL); - } - - else if (picnum >= CRACK1 && picnum <= CRACK1 + 3) { movecrack(act); diff --git a/source/games/duke/src/dispatch.cpp b/source/games/duke/src/dispatch.cpp index a75823e9a..90db556f3 100644 --- a/source/games/duke/src/dispatch.cpp +++ b/source/games/duke/src/dispatch.cpp @@ -192,11 +192,6 @@ void SetDispatcher() } -int TILE_BOX; -int TILE_TREE1; -int TILE_TREE2; -int TILE_TIRE; -int TILE_CONE; int TILE_W_FORCEFIELD; int TILE_SCRAP6; int TILE_APLAYER; diff --git a/source/games/duke/src/flags_d.cpp b/source/games/duke/src/flags_d.cpp index 4d8f24db1..976b91451 100644 --- a/source/games/duke/src/flags_d.cpp +++ b/source/games/duke/src/flags_d.cpp @@ -311,11 +311,6 @@ void initactorflags_d() gs.weaponsandammosprites[13] = FREEZESPRITE; gs.weaponsandammosprites[14] = FREEZEAMMO; - TILE_BOX = BOX; - TILE_TREE1 = TREE1; - TILE_TREE2 = TREE2; - TILE_TIRE = TIRE; - TILE_CONE = CONE; TILE_W_FORCEFIELD = W_FORCEFIELD; TILE_SCRAP6 = SCRAP6; TILE_APLAYER = APLAYER; diff --git a/source/games/duke/src/flags_r.cpp b/source/games/duke/src/flags_r.cpp index c0ac06909..60725a8b1 100644 --- a/source/games/duke/src/flags_r.cpp +++ b/source/games/duke/src/flags_r.cpp @@ -281,11 +281,6 @@ void initactorflags_r() gs.weaponsandammosprites[13] = TITSPRITE; gs.weaponsandammosprites[14] = FREEZEAMMO; - TILE_BOX = BOX; - TILE_TREE1 = TREE1; - TILE_TREE2 = TREE2; - TILE_TIRE = TIRE; - TILE_CONE = CONE; TILE_W_FORCEFIELD = W_FORCEFIELD; TILE_SCRAP6 = SCRAP6; TILE_APLAYER = APLAYER; diff --git a/source/games/duke/src/funct.h b/source/games/duke/src/funct.h index 67cb1df8e..3f91eb508 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 movecrane(DDukeActor* i, int crane); -void moveflammable(DDukeActor* i, int pool); void detonate(DDukeActor* i, int explosion); void movemasterswitch(DDukeActor* i); void movetrash(DDukeActor* i); diff --git a/source/games/duke/src/inlines.h b/source/games/duke/src/inlines.h index 5645344d2..3bf6bd643 100644 --- a/source/games/duke/src/inlines.h +++ b/source/games/duke/src/inlines.h @@ -11,11 +11,6 @@ inline int rnd(int X) return ((krand() >> 8) >= (255 - (X))); } -inline bool AFLAMABLE(int X) -{ - return (X == TILE_BOX || X == TILE_TREE1 || X == TILE_TREE2 || X == TILE_TIRE || X == TILE_CONE); -} - inline int badguypic(int const tileNum) { return ((gs.actorinfo[tileNum].flags & (SFLAG_INTERNAL_BADGUY | SFLAG_BADGUY)) != 0); diff --git a/source/games/duke/src/names.h b/source/games/duke/src/names.h index d594cdd46..b055653c9 100644 --- a/source/games/duke/src/names.h +++ b/source/games/duke/src/names.h @@ -3,11 +3,6 @@ BEGIN_DUKE_NS // These are all globally accessed tiles. -extern int TILE_BOX; -extern int TILE_TREE1; -extern int TILE_TREE2; -extern int TILE_TIRE; -extern int TILE_CONE; extern int TILE_W_FORCEFIELD; extern int TILE_SCRAP6; extern int TILE_APLAYER; diff --git a/source/games/duke/src/sectors_d.cpp b/source/games/duke/src/sectors_d.cpp index 676ff5db5..e7a83daaf 100644 --- a/source/games/duke/src/sectors_d.cpp +++ b/source/games/duke/src/sectors_d.cpp @@ -1064,21 +1064,6 @@ void checkhitsprite_d(DDukeActor* targ, DDukeActor* proj) } } break; - case TREE1: - case TREE2: - case TIRE: - case CONE: - case BOX: - if (actorflag(proj, SFLAG_INFLAME)) - { - if (targ->temp_data[0] == 0) - { - targ->spr.cstat &= ~CSTAT_SPRITE_BLOCK_ALL; - targ->temp_data[0] = 1; - spawn(targ, BURNING); - } - } - break; case CACTUS: // case CACTUSBROKE: if (actorflag(proj, SFLAG_INFLAME)) diff --git a/source/games/duke/src/sectors_r.cpp b/source/games/duke/src/sectors_r.cpp index 995160067..7e5b83960 100644 --- a/source/games/duke/src/sectors_r.cpp +++ b/source/games/duke/src/sectors_r.cpp @@ -2108,21 +2108,6 @@ void checkhitsprite_r(DDukeActor* targ, DDukeActor* proj) } break; - case TREE1: - case TREE2: - case TIRE: - case BOX: - if (actorflag(proj, SFLAG_INFLAME)) - { - if (targ->temp_data[0] == 0) - { - targ->spr.cstat &= ~CSTAT_SPRITE_BLOCK_ALL; - targ->temp_data[0] = 1; - spawn(targ, BURNING); - } - } - break; - case CACTUS: // case CACTUSBROKE: if (actorflag(proj, SFLAG_INFLAME)) diff --git a/source/games/duke/src/spawn_d.cpp b/source/games/duke/src/spawn_d.cpp index 6d6cf817f..43090297d 100644 --- a/source/games/duke/src/spawn_d.cpp +++ b/source/games/duke/src/spawn_d.cpp @@ -285,16 +285,13 @@ DDukeActor* spawninit_d(DDukeActor* actj, DDukeActor* act, TArray* { if (actj->spr.pal == 1) act->spr.pal = 1; - else if (actj->spr.pal != 6 && actj->spr.picnum != NUKEBARREL && actj->spr.picnum != TIRE) + else if (actj->spr.pal != 6 && actj->spr.picnum != NUKEBARREL) { if (actj->spr.picnum == FECES) act->spr.pal = 7; // Brown else act->spr.pal = 2; // Red } else act->spr.pal = 0; // green - - if (actj->spr.picnum == TIRE) - act->spr.shade = 127; } act->spr.cstat |= CSTAT_SPRITE_ALIGNMENT_FLOOR; if (act->spr.picnum == LAVAPOOL) // Twentieth Anniversary World Tour @@ -1031,16 +1028,6 @@ DDukeActor* spawninit_d(DDukeActor* actj, DDukeActor* act, TArray* } break; - case TREE1: - case TREE2: - case TIRE: - case CONE: - case BOX: - act->spr.cstat = CSTAT_SPRITE_BLOCK_ALL; // Make it hitable - act->spr.extra = 1; - ChangeActorStat(act, STAT_STANDABLE); - break; - case FLOORFLAME: act->spr.shade = -127; ChangeActorStat(act, STAT_STANDABLE); diff --git a/source/games/duke/src/spawn_r.cpp b/source/games/duke/src/spawn_r.cpp index 45b101875..f1774e72a 100644 --- a/source/games/duke/src/spawn_r.cpp +++ b/source/games/duke/src/spawn_r.cpp @@ -331,14 +331,11 @@ DDukeActor* spawninit_r(DDukeActor* actj, DDukeActor* act, TArray* { if (actj->spr.pal == 1) act->spr.pal = 1; - else if (actj->spr.pal != 6 && actj->spr.picnum != NUKEBARREL && actj->spr.picnum != TIRE) + else if (actj->spr.pal != 6 && actj->spr.picnum != NUKEBARREL) { act->spr.pal = 2; // Red } else act->spr.pal = 0; // green - - if (actj->spr.picnum == TIRE) - act->spr.shade = 127; } act->spr.cstat |= CSTAT_SPRITE_ALIGNMENT_FLOOR; [[fallthrough]]; @@ -1237,14 +1234,6 @@ DDukeActor* spawninit_r(DDukeActor* actj, DDukeActor* act, TArray* } act->spr.shade = act->sector()->floorshade; break; - case TREE1: - case TREE2: - case TIRE: - act->spr.cstat = CSTAT_SPRITE_BLOCK_ALL; // Make it hitable - act->spr.extra = 1; - ChangeActorStat(act, STAT_STANDABLE); - break; - case CAMERA1: case CAMERA1 + 1: case CAMERA1 + 2: diff --git a/source/games/duke/src/vmexports.cpp b/source/games/duke/src/vmexports.cpp index fc8ca04f1..26ae508bf 100644 --- a/source/games/duke/src/vmexports.cpp +++ b/source/games/duke/src/vmexports.cpp @@ -191,6 +191,14 @@ DDukeActor* DukeActor_Spawn(DDukeActor* origin, int intname) { picnum = TileFiles.tileForName("TOILETWATER"); } + else if (FName(ENamedName(intname)) == FName("DukeBurning")) + { + picnum = TileFiles.tileForName("BURNIMG"); + } + if (FName(ENamedName(intname)) == FName("DukeBloodPool")) + { + picnum = TileFiles.tileForName("BLOODPOOL"); + } if (picnum == -1) { @@ -224,6 +232,44 @@ DEFINE_ACTION_FUNCTION_NATIVE(DDukeActor, lotsofglass, DukeActor_Lotsofglass) return 0; } +DEFINE_ACTION_FUNCTION_NATIVE(DDukeActor, makeitfall, makeitfall) +{ + PARAM_SELF_PROLOGUE(DDukeActor); + makeitfall(self); + return 0; +} + +// temporary helpers. +DEFINE_ACTION_FUNCTION(DDukeActor, actorflag1) +{ + PARAM_SELF_PROLOGUE(DDukeActor); + PARAM_INT(mask); + ACTION_RETURN_BOOL(!!actorflag(self, EDukeFlags1::FromInt(mask))); +} + +DEFINE_ACTION_FUNCTION(DDukeActor, actorflag2) +{ + PARAM_SELF_PROLOGUE(DDukeActor); + PARAM_INT(mask); + ACTION_RETURN_BOOL(!!actorflag(self, EDukeFlags2::FromInt(mask))); +} + +DEFINE_ACTION_FUNCTION(DDukeActor, attackerflag1) +{ + PARAM_SELF_PROLOGUE(DDukeActor); + PARAM_INT(mask); + ACTION_RETURN_BOOL(!!attackerflag(self, EDukeFlags1::FromInt(mask))); +} + +DEFINE_ACTION_FUNCTION(DDukeActor, attackerflag2) +{ + PARAM_SELF_PROLOGUE(DDukeActor); + PARAM_INT(mask); + ACTION_RETURN_BOOL(!!attackerflag(self, EDukeFlags2::FromInt(mask))); +} + + + //--------------------------------------------------------------------------- // // DukePlayer diff --git a/wadsrc/static/filter/duke/engine/engine.def b/wadsrc/static/filter/duke/engine/engine.def index ae0aaf69c..c92455940 100644 --- a/wadsrc/static/filter/duke/engine/engine.def +++ b/wadsrc/static/filter/duke/engine/engine.def @@ -7,5 +7,9 @@ spawnclasses 565 = DukeWaterFountain 566 = DukeWaterFountain 567 = DukeWaterFountainBroke - + 951 = DukeBox + 978 = DukeCone + 908 = DukeTree1 + 910 = DukeTree2 + 990 = DukeTire } diff --git a/wadsrc/static/filter/redneck/engine/engine.def b/wadsrc/static/filter/redneck/engine/engine.def index 5afc46377..bd0797ccd 100644 --- a/wadsrc/static/filter/redneck/engine/engine.def +++ b/wadsrc/static/filter/redneck/engine/engine.def @@ -7,4 +7,9 @@ spawnclasses 1094 = DukeWaterFountain 1095 = DukeWaterFountain 1096 = DukeWaterFountainBroke + 1211 = DukeBox + 1191 = DukeTree1 + 1193 = DukeTree2 + 1230 = DukeTire } + diff --git a/wadsrc/static/zscript.txt b/wadsrc/static/zscript.txt index accb3f2f6..9c3247de4 100644 --- a/wadsrc/static/zscript.txt +++ b/wadsrc/static/zscript.txt @@ -52,6 +52,7 @@ version "4.9" #include "zscript/games/duke/ui/menu.zs" #include "zscript/games/duke/actors/crane.zs" #include "zscript/games/duke/actors/waterfountain.zs" +#include "zscript/games/duke/actors/flammables.zs" #include "zscript/games/blood/bloodgame.zs" #include "zscript/games/blood/ui/menu.zs" diff --git a/wadsrc/static/zscript/coreactor.zs b/wadsrc/static/zscript/coreactor.zs index 3fa4303ea..7d94a4191 100644 --- a/wadsrc/static/zscript/coreactor.zs +++ b/wadsrc/static/zscript/coreactor.zs @@ -7,6 +7,7 @@ enum EClipMask class CoreActor native { + const REPEAT_SCALE = 1. / 64.; native readonly sectortype sector; native int16 cstat; diff --git a/wadsrc/static/zscript/games/duke/actors/flammables.zs b/wadsrc/static/zscript/games/duke/actors/flammables.zs new file mode 100644 index 000000000..a800f7edb --- /dev/null +++ b/wadsrc/static/zscript/games/duke/actors/flammables.zs @@ -0,0 +1,117 @@ +class DukeFlammable : DukeActor +{ + default + { + statnum STAT_STANDABLE; + } + + override void Initialize() + { + self.cstat = CSTAT_SPRITE_BLOCK_ALL; // Make it hitable + self.extra = 1; + } + + override void Tick() + { + if (self.temp_data[0] == 1) + { + self.temp_data[1]++; + if ((self.temp_data[1] & 3) > 0) return; + + if (self.actorflag1(SFLAG_FLAMMABLEPOOLEFFECT) && self.temp_data[1] == 32) + { + self.cstat = 0; + let spawned = self.spawn("DukeBloodPool"); + if (spawned) + { + spawned.pal = 2; + spawned.shade = 127; + } + } + else + { + if (self.shade < 64) self.shade++; + else + { + self.Destroy(); + return; + } + } + + double scale = self.scale.X - random(0, 7) * REPEAT_SCALE; + if (scale < 0.15625) + { + self.Destroy(); + return; + } + self.scale.X = scale; + + scale = self.scale.Y - random(0, 7) * REPEAT_SCALE; + if (scale < 0.0625) + { + self.Destroy(); + return; + } + self.scale.Y = scale; + } + if (self.actorflag1(SFLAG_FALLINGFLAMMABLE)) + { + self.makeitfall(); + self.ceilingz = self.sector.ceilingz; + } + } + + override void onHit(DukeActor hitter) + { + if (hitter.actorflag1(SFLAG_INFLAME)) + { + if (self.temp_data[0] == 0) + { + self.cstat &= ~CSTAT_SPRITE_BLOCK_ALL; + self.temp_data[0] = 1; + self.spawn("DukeBurning"); + } + } + } +} + +class DukeBox : DukeFlammable +{ + default + { + pic "BOX"; + } +} + +class DukeTree1 : DukeFlammable +{ + default + { + pic "TREE1"; + } +} + +class DukeTree2 : DukeFlammable +{ + default + { + pic "TREE2"; + } +} + +class DukeTire : DukeFlammable +{ + default + { + pic "TIRE"; + } +} + +class DukeCone : DukeFlammable +{ + default + { + pic "CONE"; + } +} + diff --git a/wadsrc/static/zscript/games/duke/dukeactor.zs b/wadsrc/static/zscript/games/duke/dukeactor.zs index 47c593d06..2118724f2 100644 --- a/wadsrc/static/zscript/games/duke/dukeactor.zs +++ b/wadsrc/static/zscript/games/duke/dukeactor.zs @@ -71,6 +71,7 @@ class DukeActor : CoreActor native native void PlayActorSound(int snd); native DukeActor spawn(Name type); native void lotsofglass(int count); + native void makeitfall(); virtual void BeginPlay() {} virtual void Initialize() {} @@ -79,6 +80,14 @@ class DukeActor : CoreActor native virtual void onUse(DukePlayer user) {} virtual bool animate(tspritetype tspr) { return false; } virtual void RunState() {} // this is the CON function. + + // temporary flag accessors - need to be eliminated once we can have true actor flags + native int actorflag1(int mask); + native int actorflag2(int mask); + native int attackerflag1(int mask); + native int attackerflag2(int mask); + + } extend struct _ @@ -114,3 +123,56 @@ struct DukeSpriteIterator native DukeActor Next(); native DukeActor First(); } + + +// this is only temporary. We cannot check the actor flags as long as we still need to deal with internal actors whose picnum defines their type. +enum sflags_t +{ + SFLAG_INVENTORY = 0x00000001, + SFLAG_SHRINKAUTOAIM = 0x00000002, + SFLAG_BADGUY = 0x00000004, + SFLAG_FORCEAUTOAIM = 0x00000008, + SFLAG_BOSS = 0x00000010, + SFLAG_BADGUYSTAYPUT = 0x00000020, + SFLAG_GREENSLIMEFOOD = 0x00800040, + SFLAG_NODAMAGEPUSH = 0x00000080, + SFLAG_NOWATERDIP = 0x00000100, + SFLAG_INTERNAL_BADGUY = 0x00000200, // a separate flag is needed for the internal ones because SFLAG_BADGUY has additional semantics. + SFLAG_KILLCOUNT = 0x00000400, + SFLAG_NOCANSEECHECK = 0x00000800, + SFLAG_HITRADIUSCHECK = 0x00001000, + SFLAG_MOVEFTA_CHECKSEE = 0x00002000, + SFLAG_MOVEFTA_MAKESTANDABLE = 0x00004000, + SFLAG_TRIGGER_IFHITSECTOR = 0x00008000, + SFLAG_MOVEFTA_WAKEUPCHECK = 0x00010000, + SFLAG_MOVEFTA_CHECKSEEWITHPAL8 = 0x00020000, // let's hope this can be done better later. For now this was what blocked merging the Duke and RR variants of movefta + SFLAG_NOSHADOW = 0x00040000, + SFLAG_SE24_NOCARRY = 0x00080000, + SFLAG_NOINTERPOLATE = 0x00100000, + SFLAG_FALLINGFLAMMABLE = 0x00200000, + SFLAG_FLAMMABLEPOOLEFFECT = 0x00400000, + SFLAG_INFLAME = 0x00800000, + SFLAG_NOFLOORFIRE = 0x01000000, + SFLAG_HITRADIUS_FLAG1 = 0x02000000, + SFLAG_HITRADIUS_FLAG2 = 0x04000000, + SFLAG_CHECKSLEEP = 0x08000000, + SFLAG_NOTELEPORT = 0x10000000, + SFLAG_SE24_REMOVE = 0x20000000, + SFLAG_BLOCK_TRIPBOMB = 0x40000000, + SFLAG_NOFALLER = 0x80000000, +}; + +enum sflags2_t +{ + SFLAG2_USEACTIVATOR = 0x00000001, + SFLAG2_NOROTATEWITHSECTOR = 0x00000002, + SFLAG2_SHOWWALLSPRITEONMAP = 0x00000004, + SFLAG2_NOFLOORPAL = 0x00000008, + SFLAG2_EXPLOSIVE = 0x00000010, + SFLAG2_BRIGHTEXPLODE = 0x00000020, + SFLAG2_DOUBLEDMGTHRUST = 0x00000040, + SFLAG2_BREAKMIRRORS = 0x00000080, + SFLAG2_CAMERA = 0x00000100, + SFLAG2_DONTANIMATE = 0x00000200, + SFLAG2_INTERPOLATEANGLE = 0x00000400, +};