From 4d38f62a14a1fce13f0bfacc8bee88a27f1bdb18 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 28 Jan 2022 19:02:36 +0100 Subject: [PATCH] - cleaned up and floatified the jaildoor code (which should probably be renamed to 'slidedoor' because it gets used for lots of stuff other than actual jail doors...) --- source/games/duke/src/actors_lava.cpp | 232 ++++++++++---------------- source/games/duke/src/constants.h | 3 + source/games/duke/src/namelist_r.h | 6 +- source/games/duke/src/premap_r.cpp | 12 +- 4 files changed, 97 insertions(+), 156 deletions(-) diff --git a/source/games/duke/src/actors_lava.cpp b/source/games/duke/src/actors_lava.cpp index ad4384e97..f7faf5075 100644 --- a/source/games/duke/src/actors_lava.cpp +++ b/source/games/duke/src/actors_lava.cpp @@ -43,20 +43,23 @@ static sectortype* torchsector[64]; static short torchsectorshade[64]; static short torchtype[64]; -static short jaildoorsound[32]; -static int jaildoordrag[32]; -static int jaildoorspeed[32]; -static short jaildoorsecthtag[32]; -static int jaildoordist[32]; -static short jaildoordir[32]; -static short jaildooropen[32]; -static sectortype* jaildoorsect[32]; +struct jaildoor +{ + sectortype* sect; + int speed; + float dist; + float drag; + int16_t direction; + int16_t sound; + int16_t open; + int16_t hitag; +}; struct minecart { sectortype* sect; sectortype* childsect; - float speed; + int speed; float dist; float drag; int16_t direction; @@ -64,20 +67,9 @@ struct minecart int16_t open; }; +static TArray jaildoors; static TArray minecarts; -/* -static int minecartcnt; -static sectortype* minecartsect[16]; -static sectortype* minecartchildsect[16]; -static int minecartspeed[16]; -static int minecartdist[16]; -static int minecartdrag[16]; -*/ - -static short minecartdir[16]; -static short minecartsound[16]; -static short minecartopen[16]; static sectortype* lightninsector[64]; static short lightninsectorshade[64]; @@ -98,6 +90,23 @@ void lava_cleararrays() lightnincnt = 0; } +FSerializer& Serialize(FSerializer& arc, const char* key, jaildoor& c, jaildoor* def) +{ + if (arc.BeginObject(key)) + { + arc("sect", c.sect) + ("hitag", c.hitag) + ("speed", c.speed) + ("dist", c.dist) + ("drag", c.drag) + ("dir", c.direction) + ("sound", c.sound) + ("open", c.open) + .EndObject(); + } + return arc; +} + FSerializer& Serialize(FSerializer& arc, const char* key, minecart& c, minecart* def) { if (arc.BeginObject(key)) @@ -118,7 +127,8 @@ FSerializer& Serialize(FSerializer& arc, const char* key, minecart& c, minecart* void lava_serialize(FSerializer& arc) { arc("torchcnt", torchcnt) - ("jaildoorcnt", jaildoorcnt) + ("jaildoors", jaildoors) + ("minecarts", minecarts) ("lightnincnt", lightnincnt); if (torchcnt) @@ -126,16 +136,6 @@ void lava_serialize(FSerializer& arc) .Array("torchsectorshade", torchsectorshade, torchcnt) .Array("torchtype", torchtype, torchcnt); - if (jaildoorcnt) - arc.Array("jaildoorsound", jaildoorsound, jaildoorcnt) - .Array("jaildoordrag", jaildoordrag, jaildoorcnt) - .Array("jaildoorspeed", jaildoorspeed, jaildoorcnt) - .Array("jaildoorsecthtag", jaildoorsecthtag, jaildoorcnt) - .Array("jaildoordist", jaildoordist, jaildoorcnt) - .Array("jaildoordir", jaildoordir, jaildoorcnt) - .Array("jaildooropen", jaildooropen, jaildoorcnt) - .Array("jaildoorsect", jaildoorsect, jaildoorcnt); - if (lightnincnt) arc.Array("lightninsector", lightninsector, lightnincnt) .Array("lightninsectorshade", lightninsectorshade, lightnincnt); @@ -170,25 +170,24 @@ void addlightning(DDukeActor* actor) void addjaildoor(int p1, int p2, int iht, int jlt, int p3, sectortype* j) { - if (jaildoorcnt >= 32) - I_Error("Too many jaildoor sectors"); - if (jlt != 10 && jlt != 20 && jlt != 30 && jlt != 40) { Printf(PRINT_HIGH, "Bad direction %d for jail door with tag %d\n", jlt, iht); return; // wouldn't work so let's skip it. } - jaildoordist[jaildoorcnt] = p1; - jaildoorspeed[jaildoorcnt] = p2; - jaildoorsecthtag[jaildoorcnt] = iht; - jaildoorsect[jaildoorcnt] = j; - jaildoordrag[jaildoorcnt] = 0; - jaildooropen[jaildoorcnt] = 0; - jaildoordir[jaildoorcnt] = jlt; - jaildoorsound[jaildoorcnt] = p3; + jaildoors.Reserve(1); + auto& jd = jaildoors.Last(); + + jd.dist = p1; + jd.speed = p2; + jd.hitag = iht; + jd.sect = j; + jd.drag = 0; + jd.open = 0; + jd.direction = jlt; + jd.sound = p3; setsectinterpolate(j); - jaildoorcnt++; } void addminecart(int p1, int p2, sectortype* i, int iht, int p3, sectortype* childsectnum) @@ -196,7 +195,7 @@ void addminecart(int p1, int p2, sectortype* i, int iht, int p3, sectortype* chi minecarts.Reserve(1); auto& mc = minecarts.Last(); mc.dist = p1; - mc.speed = p2 * maptoworld; + mc.speed = p2; mc.sect = i; mc.direction = i->hitag; mc.drag = p1; @@ -272,36 +271,31 @@ void dotorch(void) void dojaildoor(void) { - for (int i = 0; i < jaildoorcnt; i++) + for(auto& jd : jaildoors) { - int speed; - auto sectp = jaildoorsect[i]; - if (numplayers > 2) - speed = jaildoorspeed[i]; - else - speed = jaildoorspeed[i]; - if (speed < 2) - speed = 2; - if (jaildooropen[i] == 1) + auto sectp = jd.sect; + double speed = max(2, jd.speed) * maptoworld; + + if (jd.open == 1 || jd.open == 3) { - jaildoordrag[i] -= speed; - if (jaildoordrag[i] <= 0) + jd.drag -= speed; + if (jd.drag <= 0) { - jaildoordrag[i] = 0; - jaildooropen[i] = 2; - switch (jaildoordir[i]) + jd.drag = 0; + jd.open ^= 3; + switch (jd.direction) { case 10: - jaildoordir[i] = 30; + jd.direction = 30; break; case 20: - jaildoordir[i] = 40; + jd.direction = 40; break; case 30: - jaildoordir[i] = 10; + jd.direction = 10; break; case 40: - jaildoordir[i] = 20; + jd.direction = 20; break; } } @@ -309,80 +303,48 @@ void dojaildoor(void) { for (auto& wal : wallsofsector(sectp)) { - int x = wal.wall_int_pos().X; - int y = wal.wall_int_pos().Y; - switch (jaildoordir[i]) + DVector2 vec = wal.pos; + switch (jd.direction) { case 10: - y += speed; + vec.Y += speed; break; case 20: - x -= speed; + vec.X -= speed; break; case 30: - y -= speed; + vec.Y -= speed; break; case 40: - x += speed; + vec.X += speed; break; } - dragpoint(&wal, x, y); + dragpoint(&wal, vec); } } } - if (jaildooropen[i] == 3) + } +} + +void operatejaildoors(int hitag) +{ + for (auto& jd : jaildoors) + { + if (jd.hitag == hitag) { - jaildoordrag[i] -= speed; - if (jaildoordrag[i] <= 0) + if (jd.open == 0) { - jaildoordrag[i] = 0; - jaildooropen[i] = 0; - switch (jaildoordir[i]) - { - case 10: - jaildoordir[i] = 30; - break; - case 20: - jaildoordir[i] = 40; - break; - case 30: - jaildoordir[i] = 10; - break; - case 40: - jaildoordir[i] = 20; - break; - } + jd.open = 1; + jd.drag = jd.dist; + if (!isRRRA() || jd.sound != 0) + S_PlayActorSound(jd.sound, ps[screenpeek].GetActor()); } - else + if (jd.open == 2) { - for (auto& wal : wallsofsector(sectp)) - { - int x, y; - switch (jaildoordir[i]) - { - default: // make case of bad parameters well defined. - x = wal.wall_int_pos().X; - y = wal.wall_int_pos().Y; - break; - case 10: - x = wal.wall_int_pos().X; - y = wal.wall_int_pos().Y + speed; - break; - case 20: - x = wal.wall_int_pos().X - speed; - y = wal.wall_int_pos().Y; - break; - case 30: - x = wal.wall_int_pos().X; - y = wal.wall_int_pos().Y - speed; - break; - case 40: - x = wal.wall_int_pos().X + speed; - y = wal.wall_int_pos().Y; - break; - } - dragpoint(&wal, x, y); - } + jd.open = 3; + jd.drag = jd.dist; + if (!isRRRA() || jd.sound != 0) + S_PlayActorSound(jd.sound, ps[screenpeek].GetActor()); } } } @@ -399,7 +361,7 @@ void moveminecart(void) for(auto& mc : minecarts) { auto sectp = mc.sect; - auto speed = max(2 * maptoworld, mc.speed); + double speed = max(2, mc.speed) * maptoworld; if (mc.open == 1 || mc.open == 2) { @@ -477,30 +439,6 @@ void moveminecart(void) } } -void operatejaildoors(int hitag) -{ - for (int i = 0; i < jaildoorcnt; i++) - { - if (jaildoorsecthtag[i] == hitag) - { - if (jaildooropen[i] == 0) - { - jaildooropen[i] = 1; - jaildoordrag[i] = jaildoordist[i]; - if (!isRRRA() || jaildoorsound[i] != 0) - S_PlayActorSound(jaildoorsound[i], ps[screenpeek].GetActor()); - } - if (jaildooropen[i] == 2) - { - jaildooropen[i] = 3; - jaildoordrag[i] = jaildoordist[i]; - if (!isRRRA() || jaildoorsound[i] != 0) - S_PlayActorSound(jaildoorsound[i], ps[screenpeek].GetActor()); - } - } - } -} - void thunder(void) { struct player_struct* p; @@ -512,7 +450,7 @@ void thunder(void) if (!thunderflash) { - if (testgotpic(RRTILE2577, true)) + if (testgotpic(RRTHUNDERSKY, true)) { g_relvisibility = 0; if (krand() > 65000) diff --git a/source/games/duke/src/constants.h b/source/games/duke/src/constants.h index 5e135a79f..ae24775b9 100644 --- a/source/games/duke/src/constants.h +++ b/source/games/duke/src/constants.h @@ -118,6 +118,9 @@ enum ST_29_TEETH_DOOR = 29, ST_30_ROTATE_RISE_BRIDGE = 30, ST_31_TWO_WAY_TRAIN = 31, + + ST_41_JAILDOOR = 41, + ST_42_MINECART = 42, // left: ST 32767, 65534, 65535 }; diff --git a/source/games/duke/src/namelist_r.h b/source/games/duke/src/namelist_r.h index 2599e8609..b51dc3137 100644 --- a/source/games/duke/src/namelist_r.h +++ b/source/games/duke/src/namelist_r.h @@ -1,4 +1,4 @@ -y(RRTILE11, 11) +y(RRJAILDOOR, 11) x(PLEASEWAIT, 12) x(RPG2SPRITE, 14) x(DUKETAG, 15) @@ -24,7 +24,7 @@ y(RRTILE34, 34) y(RRTILE35, 35) x(DESTRUCTO, 36) x(FREEZEAMMO, 37) -y(RRTILE38, 38) +y(RRJAILDOORSOUND, 38) x(AMMO, 40) x(BATTERYAMMO, 41) x(DEVISTATORAMMO, 42) @@ -680,7 +680,7 @@ y(RRTILE2562, 2562) y(RRTILE2564, 2564) y(RRTILE2573, 2573) y(RRTILE2574, 2574) -y(RRTILE2577, 2577) +y(RRTHUNDERSKY, 2577) y(RRTILE2578, 2578) y(RRTILE2581, 2581) y(RRTILE2583, 2583) diff --git a/source/games/duke/src/premap_r.cpp b/source/games/duke/src/premap_r.cpp index 32c4693f5..16cf95a9f 100644 --- a/source/games/duke/src/premap_r.cpp +++ b/source/games/duke/src/premap_r.cpp @@ -449,24 +449,24 @@ void prelevel_r(int g, TArray& actors) for (auto§: sector) { auto sectp = § - if (sectp->ceilingpicnum == RRTILE2577) + if (sectp->ceilingpicnum == RRTHUNDERSKY) thunderon = 1; switch (sectp->lotag) { - case 41: + case ST_41_JAILDOOR: { DukeSectIterator it(sectp); dist = 0; while (auto act = it.Next()) { - if (act->spr.picnum == RRTILE11) + if (act->spr.picnum == RRJAILDOOR) { - dist = act->spr.lotag << 4; + dist = act->spr.lotag; speed = act->spr.hitag; deletesprite(act); } - if (act->spr.picnum == RRTILE38) + if (act->spr.picnum == RRJAILDOORSOUND) { sound = act->spr.lotag; deletesprite(act); @@ -483,7 +483,7 @@ void prelevel_r(int g, TArray& actors) } break; } - case 42: + case ST_42_MINECART: { sectortype* childsectnum = nullptr; dist = 0;