diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index df580db4c..09f0f2a1f 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -363,7 +363,7 @@ void movedummyplayers(void) p = act->GetOwner()->PlayerIndex(); auto spri = act->s; - if ((!isRR() && ps[p].on_crane != nullptr) || sector[ps[p].cursectnum].lotag != 1 || ps->GetActor()->s->extra <= 0) + if ((!isRR() && ps[p].on_crane != nullptr) || ps[p].cursector()->lotag != 1 || ps->GetActor()->s->extra <= 0) { ps[p].dummyplayersprite = nullptr; deletesprite(act); @@ -371,7 +371,7 @@ void movedummyplayers(void) } else { - if (ps[p].on_ground && ps[p].on_warping_sector == 1 && sector[ps[p].cursectnum].lotag == 1) + if (ps[p].on_ground && ps[p].on_warping_sector == 1 && ps[p].cursector()->lotag == 1) { spri->cstat = CSTAT_SPRITE_BLOCK_ALL; spri->z = spri->sector()->ceilingz + (27 << 8); @@ -2918,7 +2918,7 @@ void handle_se14(DDukeActor* actor, bool checkstat, int RPG, int JIBS6) for (int p = connecthead; p >= 0; p = connectpoint2[p]) { auto psp = ps[p].GetActor(); - if (sector[ps[p].cursectnum].lotag != 2) + if (ps[p].cursector()->lotag != 2) { if (po[p].os == s->sectnum) { diff --git a/source/games/duke/src/game_misc.cpp b/source/games/duke/src/game_misc.cpp index a35b73ef1..b57f76103 100644 --- a/source/games/duke/src/game_misc.cpp +++ b/source/games/duke/src/game_misc.cpp @@ -61,7 +61,7 @@ FString GameInterface::GetCoordString() out.Format("pos= %d, %d, %d - angle = %2.3f - sector = %d, lotag = %d, hitag = %d", ps[snum].pos.x, ps[snum].pos.y, ps[snum].pos.z, ps[snum].angle.ang.asdeg(), ps[snum].cursectnum, - sector[ps[snum].cursectnum].lotag, sector[ps[snum].cursectnum].hitag); + ps[snum].cursector()->lotag, ps[snum].cursector()->hitag); return out; } @@ -252,7 +252,7 @@ void drawoverlays(double smoothratio) { fi.displayweapon(screenpeek, smoothratio); if (pp->over_shoulder_on == 0) - fi.displaymasks(screenpeek, pp->GetActor()->s->pal == 1 ? 1 : sector[pp->cursectnum].floorpal, smoothratio); + fi.displaymasks(screenpeek, pp->GetActor()->s->pal == 1 ? 1 : pp->cursector()->floorpal, smoothratio); } if (!isRR()) moveclouds(smoothratio); diff --git a/source/games/duke/src/hudweapon_d.cpp b/source/games/duke/src/hudweapon_d.cpp index c6a21b8f6..17a789daf 100644 --- a/source/games/duke/src/hudweapon_d.cpp +++ b/source/games/duke/src/hudweapon_d.cpp @@ -263,7 +263,7 @@ void displayweapon_d(int snum, double smoothratio) shade = p->GetActor()->s->shade; if(shade > 24) shade = 24; - pal = p->GetActor()->s->pal == 1 ? 1 : sector[p->cursectnum].floorpal; + pal = p->GetActor()->s->pal == 1 ? 1 : p->cursector()->floorpal; if (pal == 0) pal = p->palookup; @@ -1173,7 +1173,7 @@ void displayweapon_d(int snum, double smoothratio) auto displayflamethrower = [&]() { - if (*kb < 1 || sector[p->cursectnum].lotag == 2) + if (*kb < 1 || p->cursector()->lotag == 2) { hud_drawpal(weapon_xoffset + 210 - look_anghalf, looking_arc + 261 - gun_pos, FLAMETHROWER, shade, o, pal); hud_drawpal(weapon_xoffset + 210 - look_anghalf, looking_arc + 261 - gun_pos, FLAMETHROWERPILOT, shade, o, pal); diff --git a/source/games/duke/src/hudweapon_r.cpp b/source/games/duke/src/hudweapon_r.cpp index 3b5d408ab..1a5da699b 100644 --- a/source/games/duke/src/hudweapon_r.cpp +++ b/source/games/duke/src/hudweapon_r.cpp @@ -150,7 +150,7 @@ void displayweapon_r(int snum, double smoothratio) shade = p->GetActor()->s->shade; if(shade > 24) shade = 24; - pal = p->GetActor()->s->pal == 1 ? 1 : pal = sector[p->cursectnum].floorpal; + pal = p->GetActor()->s->pal == 1 ? 1 : pal = p->cursector()->floorpal; if(p->newOwner != nullptr || ud.cameraactor != nullptr || p->over_shoulder_on > 0 || (p->GetActor()->s->pal != 1 && p->GetActor()->s->extra <= 0)) return; diff --git a/source/games/duke/src/inlines.h b/source/games/duke/src/inlines.h index 59bc1c057..a58af5166 100644 --- a/source/games/duke/src/inlines.h +++ b/source/games/duke/src/inlines.h @@ -189,7 +189,7 @@ inline bool playrunning() inline void doslopetilting(player_struct* p, double const scaleAdjust = 1) { - bool const canslopetilt = p->on_ground && sector[p->cursectnum].lotag != ST_2_UNDERWATER && (sector[p->cursectnum].floorstat & 2); + bool const canslopetilt = p->on_ground && p->cursector()->lotag != ST_2_UNDERWATER && (p->cursector()->floorstat & 2); p->horizon.calcviewpitch(p->pos.vec2, p->angle.ang, p->aim_mode == 0, canslopetilt, p->cursectnum, scaleAdjust); } @@ -202,7 +202,7 @@ inline void doslopetilting(player_struct* p, double const scaleAdjust = 1) inline void hud_draw(double x, double y, int tilenum, int shade, int orientation) { - int p = sector[ps[screenpeek].cursectnum].floorpal; + int p = ps[screenpeek].cursector()->floorpal; hud_drawsprite(x, y, 65536, 0, tilenum, shade, p, 2 | orientation); } diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 204adb1f0..281055ea3 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -337,7 +337,7 @@ void hud_input(int plnum) S_PlayActorSound(390, pact); p->noise_radius = 16384; madenoise(plnum); - if (sector[p->cursectnum].lotag == 857) + if (p->cursector()->lotag == 857) { if (p->GetActor()->s->extra <= gs.max_player_health) { @@ -528,7 +528,7 @@ enum static void processInputBits(player_struct *p, ControlInfo* const hidInput) { // Set-up crouch bools. - int const sectorLotag = p->cursectnum != -1 ? sector[p->cursectnum].lotag : 0; + int const sectorLotag = p->cursectnum != -1 ? p->cursector()->lotag : 0; bool const crouchable = sectorLotag != ST_2_UNDERWATER && (sectorLotag != ST_1_ABOVE_WATER || p->spritebridge); bool const disableToggle = p->jetpack_on || (!crouchable && p->on_ground) || (isRRRA() && (p->OnMotorcycle || p->OnBoat)); diff --git a/source/games/duke/src/player.cpp b/source/games/duke/src/player.cpp index 970367ff0..51c6b97fd 100644 --- a/source/games/duke/src/player.cpp +++ b/source/games/duke/src/player.cpp @@ -84,8 +84,8 @@ int setpal(struct player_struct* p) if (p->DrugMode) palette = DRUGPAL; else if (p->heat_on) palette = SLIMEPAL; else if (p->cursectnum < 0) palette = BASEPAL; // don't crash if out of range. - else if (sector[p->cursectnum].ceilingpicnum >= TILE_FLOORSLIME && sector[p->cursectnum].ceilingpicnum <= TILE_FLOORSLIME + 2) palette = SLIMEPAL; - else if (sector[p->cursectnum].lotag == ST_2_UNDERWATER) palette = WATERPAL; + else if (p->cursector()->ceilingpicnum >= TILE_FLOORSLIME && p->cursector()->ceilingpicnum <= TILE_FLOORSLIME + 2) palette = SLIMEPAL; + else if (p->cursector()->lotag == ST_2_UNDERWATER) palette = WATERPAL; else palette = BASEPAL; return palette; } @@ -494,7 +494,7 @@ void footprints(int snum) auto psect = s->sectnum; if (p->footprintcount > 0 && p->on_ground) - if ((sector[p->cursectnum].floorstat & 2) != 2) + if ((p->cursector()->floorstat & 2) != 2) { int j = -1; DukeSectIterator it(psect); @@ -511,7 +511,7 @@ void footprints(int snum) if (j < 0) { p->footprintcount--; - if (sector[p->cursectnum].lotag == 0 && sector[p->cursectnum].hitag == 0) + if (p->cursector()->lotag == 0 && p->cursector()->hitag == 0) { DDukeActor* fprint; switch (krand() & 3) diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index 23484a6b2..979fd3746 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -1561,7 +1561,7 @@ int doincrements_d(struct player_struct* p) } } - if (p->scuba_on == 0 && sector[p->cursectnum].lotag == 2) + if (p->scuba_on == 0 && p->cursector()->lotag == 2) { if (p->scuba_amount > 0) { @@ -1765,7 +1765,7 @@ static void movement(int snum, ESyncBits actions, int psect, int fz, int cz, int p->dummyplayersprite = spawn(pact, PLAYERONWATER); p->footprintcount = 6; - if (sector[p->cursectnum].floorpicnum == FLOORSLIME) + if (p->cursector()->floorpicnum == FLOORSLIME) p->footprintpal = 8; else p->footprintpal = 0; p->footprintshade = 0; @@ -1798,7 +1798,7 @@ static void movement(int snum, ESyncBits actions, int psect, int fz, int cz, int if ((p->pos.z + p->poszv) >= (fz - (i << 8))) // hit the ground { S_StopSound(DUKE_SCREAM, pact); - if (sector[p->cursectnum].lotag != 1) + if (p->cursector()->lotag != 1) { if (p->falling_counter > 62) quickkill(p); @@ -2146,7 +2146,7 @@ static void fireweapon(int snum) if (isWorldTour() && p->ammo_amount[FLAMETHROWER_WEAPON] > 0) { p->kickback_pic = 1; - if (sector[p->cursectnum].lotag != 2) + if (p->cursector()->lotag != 2) S_PlayActorSound(FLAMETHROWER_INTRO, pact); } break; @@ -2545,7 +2545,7 @@ static void operateweapon(int snum, ESyncBits actions, int psect) p->kickback_pic++; if (p->kickback_pic == 2) { - if (sector[p->cursectnum].lotag != 2) + if (p->cursector()->lotag != 2) { p->ammo_amount[FLAMETHROWER_WEAPON]--; if (snum == screenpeek) @@ -2845,7 +2845,7 @@ void processinput_d(int snum) s->xvel = clamp(ksqrt((p->pos.x - p->bobposx) * (p->pos.x - p->bobposx) + (p->pos.y - p->bobposy) * (p->pos.y - p->bobposy)), 0, 512); if (p->on_ground) p->bobcounter += p->GetActor()->s->xvel >> 1; - p->backuppos(ud.clipping == 0 && (sector[p->cursectnum].floorpicnum == MIRROR || p->cursectnum < 0 || p->cursectnum >= MAXSECTORS)); + p->backuppos(ud.clipping == 0 && (p->cursector()->floorpicnum == MIRROR || p->cursectnum < 0 || p->cursectnum >= MAXSECTORS)); // Shrinking code @@ -3007,7 +3007,7 @@ HORIZONLY: if (psectlotag == 1 || p->spritebridge == 1) ii = (4L << 8); else ii = (20L << 8); - if (sector[p->cursectnum].lotag == 2) k = 0; + if (p->cursector()->lotag == 2) k = 0; else k = 1; Collision clip{}; @@ -3061,7 +3061,7 @@ HORIZONLY: } } - if (truefdist < gs.playerheight && p->on_ground && psectlotag != 1 && shrunk == 0 && sector[p->cursectnum].lotag == 1) + if (truefdist < gs.playerheight && p->on_ground && psectlotag != 1 && shrunk == 0 && p->cursector()->lotag == 1) if (!S_CheckActorSoundPlaying(pact, DUKE_ONWATER)) S_PlayActorSound(DUKE_ONWATER, pact); diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index eb1e43850..b80ea5e26 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -1423,7 +1423,7 @@ int doincrements_r(struct player_struct* p) } } - if (p->scuba_on == 0 && sector[p->cursectnum].lotag == 2) + if (p->scuba_on == 0 && p->cursector()->lotag == 2) { if (p->scuba_amount > 0) { @@ -2079,12 +2079,12 @@ static void movement(int snum, ESyncBits actions, int psect, int fz, int cz, int p->dummyplayersprite = spawn(pact, PLAYERONWATER); p->footprintcount = 6; - if (sector[p->cursectnum].floorpicnum == FLOORSLIME) + if (p->cursector()->floorpicnum == FLOORSLIME) { p->footprintpal = 8; p->footprintshade = 0; } - else if (isRRRA() && (sector[p->cursectnum].floorpicnum == RRTILE7756 || sector[p->cursectnum].floorpicnum == RRTILE7888)) + else if (isRRRA() && (p->cursector()->floorpicnum == RRTILE7756 || p->cursector()->floorpicnum == RRTILE7888)) { p->footprintpal = 0; p->footprintshade = 40; @@ -2143,10 +2143,10 @@ static void movement(int snum, ESyncBits actions, int psect, int fz, int cz, int if ((p->pos.z + p->poszv) >= (fz - (i << 8))) // hit the ground { S_StopSound(DUKE_SCREAM, pact); - if (sector[p->cursectnum].lotag != 1) + if (p->cursector()->lotag != 1) { if (isRRRA()) p->MotoOnGround = 1; - if (p->falling_counter > 62 || (isRRRA() && p->falling_counter > 2 && sector[p->cursectnum].lotag == 802)) + if (p->falling_counter > 62 || (isRRRA() && p->falling_counter > 2 && p->cursector()->lotag == 802)) quickkill(p); else if (p->falling_counter > 9) @@ -3564,7 +3564,7 @@ void processinput_r(int snum) s->xvel = clamp(ksqrt((p->pos.x - p->bobposx) * (p->pos.x - p->bobposx) + (p->pos.y - p->bobposy) * (p->pos.y - p->bobposy)), 0, 512); if (p->on_ground) p->bobcounter += p->GetActor()->s->xvel >> 1; - p->backuppos(ud.clipping == 0 && (sector[p->cursectnum].floorpicnum == MIRROR || p->cursectnum < 0 || p->cursectnum >= MAXSECTORS)); + p->backuppos(ud.clipping == 0 && (p->cursector()->floorpicnum == MIRROR || p->cursectnum < 0 || p->cursectnum >= MAXSECTORS)); // Shrinking code @@ -3675,7 +3675,7 @@ void processinput_r(int snum) break; case 1: if ((krand() & 1) == 0) - if (!isRRRA() || (!p->OnBoat && !p->OnMotorcycle && sector[p->cursectnum].hitag != 321)) + if (!isRRRA() || (!p->OnBoat && !p->OnMotorcycle && p->cursector()->hitag != 321)) S_PlayActorSound(DUKE_ONWATER, pact); p->walking_snd_toggle = 1; break; @@ -3770,7 +3770,7 @@ HORIZONLY: if (psectlotag == 1 || p->spritebridge == 1) i = (4L << 8); else i = (20L << 8); - if (sector[p->cursectnum].lotag == 2) k = 0; + if (p->cursector()->lotag == 2) k = 0; else k = 1; Collision clip{}; @@ -3905,9 +3905,9 @@ HORIZONLY: } } - if (truefdist < gs.playerheight && p->on_ground && psectlotag != 1 && shrunk == 0 && sector[p->cursectnum].lotag == 1) + if (truefdist < gs.playerheight && p->on_ground && psectlotag != 1 && shrunk == 0 && p->cursector()->lotag == 1) if (!S_CheckActorSoundPlaying(pact, DUKE_ONWATER)) - if (!isRRRA() || (!p->OnBoat && !p->OnMotorcycle && sector[p->cursectnum].hitag != 321)) + if (!isRRRA() || (!p->OnBoat && !p->OnMotorcycle && p->cursector()->hitag != 321)) S_PlayActorSound(DUKE_ONWATER, pact); if (p->cursectnum != s->sectnum) @@ -3940,7 +3940,7 @@ HORIZONLY: fi.activatebysector(psect, pact); } - if (ud.clipping == 0 && sector[p->cursectnum].ceilingz > (sector[p->cursectnum].floorz - (12 << 8))) + if (ud.clipping == 0 && p->cursector()->ceilingz > (p->cursector()->floorz - (12 << 8))) { quickkill(p); return; @@ -4044,7 +4044,7 @@ void processmove_r(int snum, ESyncBits actions, int psect, int fz, int cz, int s void OnMotorcycle(struct player_struct *p, DDukeActor* motosprite) { - if (!p->OnMotorcycle && !(sector[p->cursectnum].lotag == 2)) + if (!p->OnMotorcycle && !(p->cursector()->lotag == 2)) { if (motosprite) { diff --git a/source/games/duke/src/sectors_d.cpp b/source/games/duke/src/sectors_d.cpp index d5d82d5d4..adaf46b55 100644 --- a/source/games/duke/src/sectors_d.cpp +++ b/source/games/duke/src/sectors_d.cpp @@ -1500,30 +1500,30 @@ void checksectors_d(int snum) p = &ps[snum]; auto pact = p->GetActor(); - switch (sector[p->cursectnum].lotag) + switch (p->cursector()->lotag) { case 32767: - sector[p->cursectnum].lotag = 0; + p->cursector()->lotag = 0; FTA(9, p); p->secret_rooms++; SECRET_Trigger(p->cursectnum); return; case -1: - sector[p->cursectnum].lotag = 0; + p->cursector()->lotag = 0; setnextmap(false); return; case -2: - sector[p->cursectnum].lotag = 0; + p->cursector()->lotag = 0; p->timebeforeexit = 26 * 8; - p->customexitsound = sector[p->cursectnum].hitag; + p->customexitsound = p->cursector()->hitag; return; default: - if (sector[p->cursectnum].lotag >= 10000 && sector[p->cursectnum].lotag < 16383) + if (p->cursector()->lotag >= 10000 && p->cursector()->lotag < 16383) { if (snum == screenpeek || ud.coop == 1) - S_PlayActorSound(sector[p->cursectnum].lotag - 10000, pact); - sector[p->cursectnum].lotag = 0; + S_PlayActorSound(p->cursector()->lotag - 10000, pact); + p->cursector()->lotag = 0; } break; @@ -1626,7 +1626,7 @@ void checksectors_d(int snum) return; if (neartagsprite == nullptr && neartagwall == -1) - if (sector[p->cursectnum].lotag == 2) + if (p->cursector()->lotag == 2) { DDukeActor* hit; oldz = hitasprite(p->GetActor(), &hit); diff --git a/source/games/duke/src/sectors_r.cpp b/source/games/duke/src/sectors_r.cpp index 7c4196d55..9bb903be9 100644 --- a/source/games/duke/src/sectors_r.cpp +++ b/source/games/duke/src/sectors_r.cpp @@ -2445,17 +2445,17 @@ void checksectors_r(int snum) p = &ps[snum]; auto pact = p->GetActor(); - switch (sector[p->cursectnum].lotag) + switch (p->cursector()->lotag) { case 32767: - sector[p->cursectnum].lotag = 0; + p->cursector()->lotag = 0; FTA(9, p); p->secret_rooms++; SECRET_Trigger(p->cursectnum); return; case -1: - sector[p->cursectnum].lotag = 0; + p->cursector()->lotag = 0; if (!isRRRA() || !RRRA_ExitedLevel) { setnextmap(false); @@ -2463,16 +2463,16 @@ void checksectors_r(int snum) } return; case -2: - sector[p->cursectnum].lotag = 0; + p->cursector()->lotag = 0; p->timebeforeexit = 26 * 8; - p->customexitsound = sector[p->cursectnum].hitag; + p->customexitsound = p->cursector()->hitag; return; default: - if (sector[p->cursectnum].lotag >= 10000) + if (p->cursector()->lotag >= 10000) { if (snum == screenpeek || ud.coop == 1) - S_PlayActorSound(sector[p->cursectnum].lotag - 10000, pact); - sector[p->cursectnum].lotag = 0; + S_PlayActorSound(p->cursector()->lotag - 10000, pact); + p->cursector()->lotag = 0; } break; @@ -2598,7 +2598,7 @@ void checksectors_r(int snum) return; if (neartagsprite == nullptr && neartagwall == -1) - if (sector[p->cursectnum].lotag == 2) + if (p->cursector()->lotag == 2) { DDukeActor* hit; oldz = hitasprite(p->GetActor(), &hit); diff --git a/source/games/duke/src/sounds.cpp b/source/games/duke/src/sounds.cpp index 92c673832..5736e73d8 100644 --- a/source/games/duke/src/sounds.cpp +++ b/source/games/duke/src/sounds.cpp @@ -491,7 +491,7 @@ int S_PlaySound3D(int sndnum, DDukeActor* actor, const vec3_t* pos, int channel, bool explosion = ((userflags & (SF_GLOBAL | SF_DTAG)) == (SF_GLOBAL | SF_DTAG)) || ((sndnum == PIPEBOMB_EXPLODE || sndnum == LASERTRIP_EXPLODE || sndnum == RPG_EXPLODE)); - bool underwater = ps[screenpeek].cursectnum > -1 && sector[ps[screenpeek].cursectnum].lotag == ST_2_UNDERWATER; + bool underwater = ps[screenpeek].cursectnum > -1 && ps[screenpeek].cursector()->lotag == ST_2_UNDERWATER; if (explosion) { if (underwater) diff --git a/source/games/duke/src/types.h b/source/games/duke/src/types.h index 309187541..64acaf057 100644 --- a/source/games/duke/src/types.h +++ b/source/games/duke/src/types.h @@ -292,6 +292,11 @@ struct player_struct return (psectlotag == ST_2_UNDERWATER)? avel * 0.875f : avel; } + sectortype* cursector() const + { + return &::sector[cursectnum]; + } + };