shithub: cstory

Download patch

ref: 86412f052815b1f714370ff77bf24c05ee88cba2
parent: d83665ff2af66813350aef8ebb6850e9e3aaf5e2
author: Clownacy <Clownacy@users.noreply.github.com>
date: Tue Jan 7 01:40:58 EST 2020

More-accurate Map.cpp variable arrangement

--- a/src/Map.cpp
+++ b/src/Map.cpp
@@ -16,7 +16,7 @@
 
 MAP_DATA gMap;
 
-static const char *code_pxma = "PXM";
+const char *code_pxma = "PXM";
 
 BOOL InitMapData2(void)
 {
@@ -26,19 +26,19 @@
 
 BOOL LoadMapData2(const char *path_map)
 {
-	unsigned char dum;
+	FILE *fp;
+	char check[3];
+	char path[MAX_PATH];
 
 	// Get path
-	char path[MAX_PATH];
 	sprintf(path, "%s\\%s", gDataPath, path_map);
 
 	// Open file
-	FILE *fp = fopen(path, "rb");
+	fp = fopen(path, "rb");
 	if (fp == NULL)
 		return FALSE;
 
 	// Make sure file begins with "PXM"
-	char check[3];
 	fread(check, 1, 3, fp);
 
 	if (memcmp(check, code_pxma, 3))
@@ -47,6 +47,7 @@
 		return FALSE;
 	}
 
+	unsigned char dum;
 	fread(&dum, 1, 1, fp);
 	// Get width and height
 	// This fails on big-endian hardware, and platforms where short is not two bytes long.
@@ -67,11 +68,13 @@
 
 BOOL LoadAttributeData(const char *path_atrb)
 {
-	// Open file
+	FILE *fp;
 	char path[MAX_PATH];
+
+	// Open file
 	sprintf(path, "%s\\%s", gDataPath, path_atrb);
 
-	FILE *fp = fopen(path, "rb");
+	fp = fopen(path, "rb");
 	if (fp == NULL)
 		return FALSE;
 
@@ -105,10 +108,12 @@
 
 unsigned char GetAttribute(int x, int y)
 {
+	size_t a;
+
 	if (x < 0 || y < 0 || x >= gMap.width || y >= gMap.length)
 		return 0;
 
-	const size_t a = *(gMap.data + x + (y * gMap.width));	// Yes, the original code really does do this instead of a regular array access
+	a = *(gMap.data + x + (y * gMap.width));	// Yes, the original code really does do this instead of a regular array access
 	return gMap.atrb[a];
 }
 
@@ -139,22 +144,18 @@
 
 void PutStage_Back(int fx, int fy)
 {
-	int num_y;
-	int put_x;
-	int put_y;
-	int i;
-	int j;
-	int offset;
-	int atrb;
+	int i, j;
 	RECT rect;
-	int num_x;
+	int offset;
 
 	// Get range to draw
-	num_x = ((WINDOW_WIDTH + (16 - 1)) / 16) + 1;
-	num_y = ((WINDOW_HEIGHT + (16 - 1)) / 16) + 1;
-	put_x = ((fx / 0x200) + 8) / 16;
-	put_y = ((fy / 0x200) + 8) / 16;
+	int num_x = ((WINDOW_WIDTH + (16 - 1)) / 16) + 1;
+	int num_y = ((WINDOW_HEIGHT + (16 - 1)) / 16) + 1;
+	int put_x = ((fx / 0x200) + 8) / 16;
+	int put_y = ((fy / 0x200) + 8) / 16;
 
+	int atrb;
+
 	for (j = put_y; j < put_y + num_y; ++j)
 	{
 		for (i = put_x; i < put_x + num_x; ++i)
@@ -180,22 +181,18 @@
 void PutStage_Front(int fx, int fy)
 {
 	RECT rcSnack = {256, 48, 272, 64};
-	int num_y;
-	int put_x;
-	int put_y;
-	int j;
-	int i;
-	int offset;
-	int atrb;
+	int i, j;
 	RECT rect;
-	int num_x;
+	int offset;
 
 	// Get range to draw
-	num_x = ((WINDOW_WIDTH + (16 - 1)) / 16) + 1;
-	num_y = ((WINDOW_HEIGHT + (16 - 1)) / 16) + 1;
-	put_x = ((fx / 0x200) + 8) / 16;
-	put_y = ((fy / 0x200) + 8) / 16;
+	int num_x = ((WINDOW_WIDTH + (16 - 1)) / 16) + 1;
+	int num_y = ((WINDOW_HEIGHT + (16 - 1)) / 16) + 1;
+	int put_x = ((fx / 0x200) + 8) / 16;
+	int put_y = ((fy / 0x200) + 8) / 16;
 
+	int atrb;
+
 	for (j = put_y; j < put_y + num_y; ++j)
 	{
 		for (i = put_x; i < put_x + num_x; ++i)
@@ -223,18 +220,20 @@
 
 void PutMapDataVector(int fx, int fy)
 {
+	int i, j;
+	RECT rect;
+	int offset;
+
+	int num_x;
 	int num_y;
 	int put_x;
 	int put_y;
-	int i;
-	int j;
-	int offset;
+
+	static unsigned char count = 0;
+
 	int atrb;
-	RECT rect;
-	int num_x;
 
 	// Animate the wind
-	static unsigned char count = 0;
 	count += 2;
 
 	// Get range to draw