- 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...)
This commit is contained in:
Christoph Oelckers 2022-01-28 19:02:36 +01:00
parent 6fbecf2348
commit 4d38f62a14
4 changed files with 97 additions and 156 deletions

View file

@ -43,20 +43,23 @@ static sectortype* torchsector[64];
static short torchsectorshade[64]; static short torchsectorshade[64];
static short torchtype[64]; static short torchtype[64];
static short jaildoorsound[32]; struct jaildoor
static int jaildoordrag[32]; {
static int jaildoorspeed[32]; sectortype* sect;
static short jaildoorsecthtag[32]; int speed;
static int jaildoordist[32]; float dist;
static short jaildoordir[32]; float drag;
static short jaildooropen[32]; int16_t direction;
static sectortype* jaildoorsect[32]; int16_t sound;
int16_t open;
int16_t hitag;
};
struct minecart struct minecart
{ {
sectortype* sect; sectortype* sect;
sectortype* childsect; sectortype* childsect;
float speed; int speed;
float dist; float dist;
float drag; float drag;
int16_t direction; int16_t direction;
@ -64,20 +67,9 @@ struct minecart
int16_t open; int16_t open;
}; };
static TArray<jaildoor> jaildoors;
static TArray<minecart> minecarts; static TArray<minecart> 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 sectortype* lightninsector[64];
static short lightninsectorshade[64]; static short lightninsectorshade[64];
@ -98,6 +90,23 @@ void lava_cleararrays()
lightnincnt = 0; 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) FSerializer& Serialize(FSerializer& arc, const char* key, minecart& c, minecart* def)
{ {
if (arc.BeginObject(key)) if (arc.BeginObject(key))
@ -118,7 +127,8 @@ FSerializer& Serialize(FSerializer& arc, const char* key, minecart& c, minecart*
void lava_serialize(FSerializer& arc) void lava_serialize(FSerializer& arc)
{ {
arc("torchcnt", torchcnt) arc("torchcnt", torchcnt)
("jaildoorcnt", jaildoorcnt) ("jaildoors", jaildoors)
("minecarts", minecarts)
("lightnincnt", lightnincnt); ("lightnincnt", lightnincnt);
if (torchcnt) if (torchcnt)
@ -126,16 +136,6 @@ void lava_serialize(FSerializer& arc)
.Array("torchsectorshade", torchsectorshade, torchcnt) .Array("torchsectorshade", torchsectorshade, torchcnt)
.Array("torchtype", torchtype, 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) if (lightnincnt)
arc.Array("lightninsector", lightninsector, lightnincnt) arc.Array("lightninsector", lightninsector, lightnincnt)
.Array("lightninsectorshade", lightninsectorshade, 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) 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) if (jlt != 10 && jlt != 20 && jlt != 30 && jlt != 40)
{ {
Printf(PRINT_HIGH, "Bad direction %d for jail door with tag %d\n", jlt, iht); Printf(PRINT_HIGH, "Bad direction %d for jail door with tag %d\n", jlt, iht);
return; // wouldn't work so let's skip it. return; // wouldn't work so let's skip it.
} }
jaildoordist[jaildoorcnt] = p1; jaildoors.Reserve(1);
jaildoorspeed[jaildoorcnt] = p2; auto& jd = jaildoors.Last();
jaildoorsecthtag[jaildoorcnt] = iht;
jaildoorsect[jaildoorcnt] = j; jd.dist = p1;
jaildoordrag[jaildoorcnt] = 0; jd.speed = p2;
jaildooropen[jaildoorcnt] = 0; jd.hitag = iht;
jaildoordir[jaildoorcnt] = jlt; jd.sect = j;
jaildoorsound[jaildoorcnt] = p3; jd.drag = 0;
jd.open = 0;
jd.direction = jlt;
jd.sound = p3;
setsectinterpolate(j); setsectinterpolate(j);
jaildoorcnt++;
} }
void addminecart(int p1, int p2, sectortype* i, int iht, int p3, sectortype* childsectnum) 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); minecarts.Reserve(1);
auto& mc = minecarts.Last(); auto& mc = minecarts.Last();
mc.dist = p1; mc.dist = p1;
mc.speed = p2 * maptoworld; mc.speed = p2;
mc.sect = i; mc.sect = i;
mc.direction = i->hitag; mc.direction = i->hitag;
mc.drag = p1; mc.drag = p1;
@ -272,36 +271,31 @@ void dotorch(void)
void dojaildoor(void) void dojaildoor(void)
{ {
for (int i = 0; i < jaildoorcnt; i++) for(auto& jd : jaildoors)
{ {
int speed; auto sectp = jd.sect;
auto sectp = jaildoorsect[i]; double speed = max(2, jd.speed) * maptoworld;
if (numplayers > 2)
speed = jaildoorspeed[i]; if (jd.open == 1 || jd.open == 3)
else
speed = jaildoorspeed[i];
if (speed < 2)
speed = 2;
if (jaildooropen[i] == 1)
{ {
jaildoordrag[i] -= speed; jd.drag -= speed;
if (jaildoordrag[i] <= 0) if (jd.drag <= 0)
{ {
jaildoordrag[i] = 0; jd.drag = 0;
jaildooropen[i] = 2; jd.open ^= 3;
switch (jaildoordir[i]) switch (jd.direction)
{ {
case 10: case 10:
jaildoordir[i] = 30; jd.direction = 30;
break; break;
case 20: case 20:
jaildoordir[i] = 40; jd.direction = 40;
break; break;
case 30: case 30:
jaildoordir[i] = 10; jd.direction = 10;
break; break;
case 40: case 40:
jaildoordir[i] = 20; jd.direction = 20;
break; break;
} }
} }
@ -309,80 +303,48 @@ void dojaildoor(void)
{ {
for (auto& wal : wallsofsector(sectp)) for (auto& wal : wallsofsector(sectp))
{ {
int x = wal.wall_int_pos().X; DVector2 vec = wal.pos;
int y = wal.wall_int_pos().Y; switch (jd.direction)
switch (jaildoordir[i])
{ {
case 10: case 10:
y += speed; vec.Y += speed;
break; break;
case 20: case 20:
x -= speed; vec.X -= speed;
break; break;
case 30: case 30:
y -= speed; vec.Y -= speed;
break; break;
case 40: case 40:
x += speed; vec.X += speed;
break; 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 (jd.open == 0)
if (jaildoordrag[i] <= 0)
{ {
jaildoordrag[i] = 0; jd.open = 1;
jaildooropen[i] = 0; jd.drag = jd.dist;
switch (jaildoordir[i]) if (!isRRRA() || jd.sound != 0)
{ S_PlayActorSound(jd.sound, ps[screenpeek].GetActor());
case 10:
jaildoordir[i] = 30;
break;
case 20:
jaildoordir[i] = 40;
break;
case 30:
jaildoordir[i] = 10;
break;
case 40:
jaildoordir[i] = 20;
break;
}
} }
else if (jd.open == 2)
{ {
for (auto& wal : wallsofsector(sectp)) jd.open = 3;
{ jd.drag = jd.dist;
int x, y; if (!isRRRA() || jd.sound != 0)
switch (jaildoordir[i]) S_PlayActorSound(jd.sound, ps[screenpeek].GetActor());
{
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);
}
} }
} }
} }
@ -399,7 +361,7 @@ void moveminecart(void)
for(auto& mc : minecarts) for(auto& mc : minecarts)
{ {
auto sectp = mc.sect; auto sectp = mc.sect;
auto speed = max<double>(2 * maptoworld, mc.speed); double speed = max(2, mc.speed) * maptoworld;
if (mc.open == 1 || mc.open == 2) 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) void thunder(void)
{ {
struct player_struct* p; struct player_struct* p;
@ -512,7 +450,7 @@ void thunder(void)
if (!thunderflash) if (!thunderflash)
{ {
if (testgotpic(RRTILE2577, true)) if (testgotpic(RRTHUNDERSKY, true))
{ {
g_relvisibility = 0; g_relvisibility = 0;
if (krand() > 65000) if (krand() > 65000)

View file

@ -118,6 +118,9 @@ enum
ST_29_TEETH_DOOR = 29, ST_29_TEETH_DOOR = 29,
ST_30_ROTATE_RISE_BRIDGE = 30, ST_30_ROTATE_RISE_BRIDGE = 30,
ST_31_TWO_WAY_TRAIN = 31, ST_31_TWO_WAY_TRAIN = 31,
ST_41_JAILDOOR = 41,
ST_42_MINECART = 42,
// left: ST 32767, 65534, 65535 // left: ST 32767, 65534, 65535
}; };

View file

@ -1,4 +1,4 @@
y(RRTILE11, 11) y(RRJAILDOOR, 11)
x(PLEASEWAIT, 12) x(PLEASEWAIT, 12)
x(RPG2SPRITE, 14) x(RPG2SPRITE, 14)
x(DUKETAG, 15) x(DUKETAG, 15)
@ -24,7 +24,7 @@ y(RRTILE34, 34)
y(RRTILE35, 35) y(RRTILE35, 35)
x(DESTRUCTO, 36) x(DESTRUCTO, 36)
x(FREEZEAMMO, 37) x(FREEZEAMMO, 37)
y(RRTILE38, 38) y(RRJAILDOORSOUND, 38)
x(AMMO, 40) x(AMMO, 40)
x(BATTERYAMMO, 41) x(BATTERYAMMO, 41)
x(DEVISTATORAMMO, 42) x(DEVISTATORAMMO, 42)
@ -680,7 +680,7 @@ y(RRTILE2562, 2562)
y(RRTILE2564, 2564) y(RRTILE2564, 2564)
y(RRTILE2573, 2573) y(RRTILE2573, 2573)
y(RRTILE2574, 2574) y(RRTILE2574, 2574)
y(RRTILE2577, 2577) y(RRTHUNDERSKY, 2577)
y(RRTILE2578, 2578) y(RRTILE2578, 2578)
y(RRTILE2581, 2581) y(RRTILE2581, 2581)
y(RRTILE2583, 2583) y(RRTILE2583, 2583)

View file

@ -449,24 +449,24 @@ void prelevel_r(int g, TArray<DDukeActor*>& actors)
for (auto&sect: sector) for (auto&sect: sector)
{ {
auto sectp = &sect; auto sectp = &sect;
if (sectp->ceilingpicnum == RRTILE2577) if (sectp->ceilingpicnum == RRTHUNDERSKY)
thunderon = 1; thunderon = 1;
switch (sectp->lotag) switch (sectp->lotag)
{ {
case 41: case ST_41_JAILDOOR:
{ {
DukeSectIterator it(sectp); DukeSectIterator it(sectp);
dist = 0; dist = 0;
while (auto act = it.Next()) 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; speed = act->spr.hitag;
deletesprite(act); deletesprite(act);
} }
if (act->spr.picnum == RRTILE38) if (act->spr.picnum == RRJAILDOORSOUND)
{ {
sound = act->spr.lotag; sound = act->spr.lotag;
deletesprite(act); deletesprite(act);
@ -483,7 +483,7 @@ void prelevel_r(int g, TArray<DDukeActor*>& actors)
} }
break; break;
} }
case 42: case ST_42_MINECART:
{ {
sectortype* childsectnum = nullptr; sectortype* childsectnum = nullptr;
dist = 0; dist = 0;