From b13398c268b4ba6775ee1cbda92321a5fb911331 Mon Sep 17 00:00:00 2001
From: Christoph Oelckers <coelckers@users.noreply.github.com>
Date: Sun, 7 Nov 2021 08:46:15 +0100
Subject: [PATCH] - quick global wall[] replacements.

---
 source/games/duke/src/actors.cpp    | 32 ++++++++++++++---------------
 source/games/duke/src/player_d.cpp  |  2 +-
 source/games/duke/src/player_r.cpp  |  2 +-
 source/games/duke/src/premap_d.cpp  |  2 +-
 source/games/duke/src/sectors.cpp   |  2 +-
 source/games/duke/src/sectors_d.cpp |  8 ++++----
 source/games/duke/src/sectors_r.cpp | 12 +++++------
 7 files changed, 30 insertions(+), 30 deletions(-)

diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp
index 445873639..326d71991 100644
--- a/source/games/duke/src/actors.cpp
+++ b/source/games/duke/src/actors.cpp
@@ -331,14 +331,14 @@ void movecyclers(void)
 		c->lotag += sect->extra;
 		if (c->state)
 		{
-			auto wal = &wall[sect->wallptr];
+			auto wal = sect->firstWall();
 			for (int x = sect->wallnum; x > 0; x--, wal++)
 				if (wal->hitag != 1)
 				{
 					wal->shade = j;
 
 					if ((wal->cstat & CSTAT_WALL_BOTTOM_SWAP) && wal->nextwall >= 0)
-						wall[wal->nextwall].shade = j;
+						wal->nextWall()->shade = j;
 
 				}
 			sect->floorshade = sect->ceilingshade = j;
@@ -3314,7 +3314,7 @@ void handle_se03(DDukeActor *actor)
 	sc->ceilingshade = t[0];
 	sc->floorshade = t[0];
 
-	auto wal = &wall[sc->wallptr];
+	auto wal = sc->firstWall();
 
 	for (x = sc->wallnum; x > 0; x--, wal++)
 	{
@@ -3323,7 +3323,7 @@ void handle_se03(DDukeActor *actor)
 			wal->shade = t[0];
 			if ((wal->cstat & 2) && wal->nextwall >= 0)
 			{
-				wall[wal->nextwall].shade = wal->shade;
+				wal->nextWall()->shade = wal->shade;
 			}
 		}
 	}
@@ -3368,7 +3368,7 @@ void handle_se04(DDukeActor *actor)
 	sc->floorshade = t[1];
 	sc->ceilingshade = t[1];
 
-	auto wal = &wall[sc->wallptr];
+	auto wal = sc->firstWall();
 
 	for (int x = sc->wallnum; x > 0; x--, wal++)
 	{
@@ -3379,7 +3379,7 @@ void handle_se04(DDukeActor *actor)
 		{
 			wal->shade = t[0];
 			if ((wal->cstat & 2) && wal->nextwall >= 0)
-				wall[wal->nextwall].shade = wal->shade;
+				wal->nextWall()->shade = wal->shade;
 		}
 	}
 
@@ -3544,7 +3544,7 @@ void handle_se08(DDukeActor *actor, bool checkhitag1)
 				auto sect = ac->getSector();
 				int m = ac->s->shade;
 
-				auto wal = &wall[sect->wallptr];
+				auto wal = sect->firstWall();
 
 				for (int l = sect->wallnum; l > 0; l--, wal++)
 				{
@@ -3558,8 +3558,8 @@ void handle_se08(DDukeActor *actor, bool checkhitag1)
 							wal->shade = ac->temp_data[2];
 
 						if (wal->nextwall >= 0)
-							if (wall[wal->nextwall].hitag != 1)
-								wall[wal->nextwall].shade = wal->shade;
+							if (wal->nextWall()->hitag != 1)
+								wal->nextWall()->shade = wal->shade;
 					}
 				}
 
@@ -3718,7 +3718,7 @@ void handle_se12(DDukeActor *actor, int planeonly)
 		sc->floorpal = 0;
 		sc->ceilingpal = 0;
 
-		auto wal = &wall[sc->wallptr];
+		auto wal = sc->firstWall();
 		for (int j = sc->wallnum; j > 0; j--, wal++)
 			if (wal->hitag != 1)
 			{
@@ -3759,7 +3759,7 @@ void handle_se12(DDukeActor *actor, int planeonly)
 			if (planeonly != 2) sc->floorshade -= 2;
 			if (planeonly != 1) sc->ceilingshade -= 2;
 
-			auto wal = &wall[sc->wallptr];
+			auto wal = sc->firstWall();
 			for (int j = sc->wallnum; j > 0; j--, wal++)
 				if (wal->hitag != 1)
 				{
@@ -3833,7 +3833,7 @@ void handle_se13(DDukeActor* actor)
 
 			if (s->ang == 512)
 			{
-				auto wal = &wall[sc->wallptr];
+				auto wal = sc->firstWall();
 				for (j = sc->wallnum; j > 0; j--, wal++)
 					wal->shade = s->shade;
 
@@ -4753,22 +4753,22 @@ void handle_se128(DDukeActor *actor)
 		wal->cstat |= 16;
 		if (wal->nextwall >= 0)
 		{
-			wall[wal->nextwall].cstat &= (255 - 32);
-			wall[wal->nextwall].cstat |= 16;
+			wal->nextWall()->cstat &= (255 - 32);
+			wal->nextWall()->cstat |= 16;
 		}
 	}
 //	else return;
 
 	wal->overpicnum++;
 	if (wal->nextwall >= 0)
-		wall[wal->nextwall].overpicnum++;
+		wal->nextWall()->overpicnum++;
 
 	if (t[0] < t[1]) t[0]++;
 	else
 	{
 		wal->cstat &= (128 + 32 + 8 + 4 + 2);
 		if (wal->nextwall >= 0)
-			wall[wal->nextwall].cstat &= (128 + 32 + 8 + 4 + 2);
+			wal->nextWall()->cstat &= (128 + 32 + 8 + 4 + 2);
 		deletesprite(actor);
 	}
 }
diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp
index e84c65b2d..4739dd318 100644
--- a/source/games/duke/src/player_d.cpp
+++ b/source/games/duke/src/player_d.cpp
@@ -487,7 +487,7 @@ static void shootweapon(DDukeActor *actor, int p, int sx, int sy, int sz, int sa
 				return;
 			}
 
-			if (wal->hitag != 0 || (wal->nextwall >= 0 && wall[wal->nextwall].hitag != 0))
+			if (wal->hitag != 0 || (wal->nextwall >= 0 && wal->nextWall()->hitag != 0))
 				goto SKIPBULLETHOLE;
 
 			if (hitsect >= 0 && sector[hitsect].lotag == 0)
diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp
index 26d4af874..e165d800a 100644
--- a/source/games/duke/src/player_r.cpp
+++ b/source/games/duke/src/player_r.cpp
@@ -387,7 +387,7 @@ static void shootweapon(DDukeActor* actor, int p, int sx, int sy, int sz, int sa
 				return;
 			}
 
-			if (wal->hitag != 0 || (wal->nextwall >= 0 && wall[wal->nextwall].hitag != 0))
+			if (wal->hitag != 0 || (wal->nextwall >= 0 && wal->nextWall()->hitag != 0))
 				goto SKIPBULLETHOLE;
 
 			if (hitsect >= 0 && sector[hitsect].lotag == 0)
diff --git a/source/games/duke/src/premap_d.cpp b/source/games/duke/src/premap_d.cpp
index fb10b6f5d..9f23e701f 100644
--- a/source/games/duke/src/premap_d.cpp
+++ b/source/games/duke/src/premap_d.cpp
@@ -426,7 +426,7 @@ void prelevel_d(int g)
 			else wal->cstat |= 85 + 256;
 
 			if (wal->lotag && wal->nextwall >= 0)
-				wall[wal->nextwall].lotag = wal->lotag;
+				wal->nextWall()->lotag = wal->lotag;
 
 		case BIGFORCE:
 
diff --git a/source/games/duke/src/sectors.cpp b/source/games/duke/src/sectors.cpp
index b9ac18651..c51f332b7 100644
--- a/source/games/duke/src/sectors.cpp
+++ b/source/games/duke/src/sectors.cpp
@@ -1091,7 +1091,7 @@ void operateactivators(int low, int plnum)
 			p->state = !p->state;
 
 			sect->floorshade = sect->ceilingshade = (int8_t)p->shade2;
-			wal = &wall[sect->wallptr];
+			wal = sect->firstWall();
 			for (j = sect->wallnum; j > 0; j--, wal++)
 				wal->shade = (int8_t)p->shade2;
 		}
diff --git a/source/games/duke/src/sectors_d.cpp b/source/games/duke/src/sectors_d.cpp
index 7d768e1c5..e0d65ef33 100644
--- a/source/games/duke/src/sectors_d.cpp
+++ b/source/games/duke/src/sectors_d.cpp
@@ -701,8 +701,8 @@ void checkhitwall_d(DDukeActor* spr, int dawallnum, int x, int y, int z, int atw
 					wal->cstat &= 65535 - 65;
 					if (wal->nextwall >= 0)
 					{
-						wall[wal->nextwall].overpicnum = FANSPRITEBROKE;
-						wall[wal->nextwall].cstat &= 65535 - 65;
+						wal->nextWall()->overpicnum = FANSPRITEBROKE;
+						wal->nextWall()->cstat &= 65535 - 65;
 					}
 					S_PlayActorSound(VENT_BUST, spr);
 					S_PlayActorSound(GLASS_BREAKING, spr);
@@ -716,7 +716,7 @@ void checkhitwall_d(DDukeActor* spr, int dawallnum, int x, int y, int z, int atw
 					wal->cstat = 0;
 
 					if (wal->nextwall >= 0)
-						wall[wal->nextwall].cstat = 0;
+						wal->nextWall()->cstat = 0;
 
 					auto spawned = EGS(sn, x, y, z, SECTOREFFECTOR, 0, 0, 0, ps[0].angle.ang.asbuild(), 0, 0, spr, 3);
 					spawned->s->lotag = 128; 
@@ -730,7 +730,7 @@ void checkhitwall_d(DDukeActor* spr, int dawallnum, int x, int y, int z, int atw
 					lotsofcolourglass(spr, dawallnum, 80);
 					wal->cstat = 0;
 					if (wal->nextwall >= 0)
-						wall[wal->nextwall].cstat = 0;
+						wal->nextWall()->cstat = 0;
 					S_PlayActorSound(VENT_BUST, spr);
 					S_PlayActorSound(GLASS_BREAKING, spr);
 					return;
diff --git a/source/games/duke/src/sectors_r.cpp b/source/games/duke/src/sectors_r.cpp
index 0ae2739b6..6bb4bc194 100644
--- a/source/games/duke/src/sectors_r.cpp
+++ b/source/games/duke/src/sectors_r.cpp
@@ -1015,8 +1015,8 @@ void checkhitwall_r(DDukeActor* spr, int dawallnum, int x, int y, int z, int atw
 					wal->cstat &= 65535 - 65;
 					if (wal->nextwall >= 0)
 					{
-						wall[wal->nextwall].overpicnum = FANSPRITEBROKE;
-						wall[wal->nextwall].cstat &= 65535 - 65;
+						wal->nextWall()->overpicnum = FANSPRITEBROKE;
+						wal->nextWall()->cstat &= 65535 - 65;
 					}
 					S_PlayActorSound(VENT_BUST, spr);
 					S_PlayActorSound(GLASS_BREAKING, spr);
@@ -1030,7 +1030,7 @@ void checkhitwall_r(DDukeActor* spr, int dawallnum, int x, int y, int z, int atw
 					wal->cstat = 0;
 
 					if (wal->nextwall >= 0)
-						wall[wal->nextwall].cstat = 0;
+						wal->nextWall()->cstat = 0;
 
 					auto spawned = EGS(sn, x, y, z, SECTOREFFECTOR, 0, 0, 0, ps[0].angle.ang.asbuild(), 0, 0, spr, 3);
 					spawned->s->lotag = 128; 
@@ -1047,7 +1047,7 @@ void checkhitwall_r(DDukeActor* spr, int dawallnum, int x, int y, int z, int atw
 					wal->cstat = 0;
 
 					if (wal->nextwall >= 0)
-						wall[wal->nextwall].cstat = 0;
+						wal->nextWall()->cstat = 0;
 
 					auto spawned = EGS(sn, x, y, z, SECTOREFFECTOR, 0, 0, 0, ps[0].angle.ang.asbuild(), 0, 0, spr, 3);
 					spawned->s->lotag = 128;
@@ -1061,7 +1061,7 @@ void checkhitwall_r(DDukeActor* spr, int dawallnum, int x, int y, int z, int atw
 					lotsofcolourglass(spr, dawallnum, 80);
 					wal->cstat = 0;
 					if (wal->nextwall >= 0)
-						wall[wal->nextwall].cstat = 0;
+						wal->nextWall()->cstat = 0;
 					S_PlayActorSound(VENT_BUST, spr);
 					S_PlayActorSound(GLASS_BREAKING, spr);
 					return;
@@ -1080,7 +1080,7 @@ void checkhitwall_r(DDukeActor* spr, int dawallnum, int x, int y, int z, int atw
 		int sect;
 		int unk = 0;
 		int startwall, endwall;
-		sect = wall[wal->nextwall].nextsector;
+		sect = wal->nextWall()->nextsector;
 		DukeSectIterator it(sect);
 		while (auto act = it.Next())
 		{