shithub: cstory

Download patch

ref: f8c2e176554ff94ce0ee233d2269477cf6aca51e
parent: c368734a5c88b4606cb3a28ba6991e0d76232416
author: Clownacy <Clownacy@users.noreply.github.com>
date: Mon Sep 9 19:46:35 EDT 2019

Clean up Map.cpp

--- a/src/Map.cpp
+++ b/src/Map.cpp
@@ -112,26 +112,26 @@
 	if (x < 0 || y < 0 || x >= gMap.width || y >= gMap.length)
 		return 0;
 
-	const size_t a = *(gMap.data + x + gMap.width * y);
+	const size_t a = *(gMap.data + x + (y * gMap.width));	// Yes, the original code really does do this
 	return gMap.atrb[a];
 }
 
 void DeleteMapParts(int x, int y)
 {
-	*(gMap.data + x + gMap.width * y) = 0;
+	*(gMap.data + x + (y * gMap.width)) = 0;
 }
 
 void ShiftMapParts(int x, int y)
 {
-	*(gMap.data + x + gMap.width * y) -= 1;
+	*(gMap.data + x + (y * gMap.width)) -= 1;
 }
 
 BOOL ChangeMapParts(int x, int y, unsigned char no)
 {
-	if (*(gMap.data + x + gMap.width * y) == no)
+	if (*(gMap.data + x + (y * gMap.width)) == no)
 		return FALSE;
 
-	*(gMap.data + x + gMap.width * y) = no;
+	*(gMap.data + x + (y * gMap.width)) = no;
 
 	for (int i = 0; i < 3; i++)
 		SetNpChar(4, x * 0x200 * 0x10, y * 0x200 * 0x10, 0, 0, 0, 0, 0);
@@ -152,10 +152,10 @@
 	int num_x;
 
 	// Get range to draw
-	num_x = ((WINDOW_WIDTH + 0xF) / 0x10) + 1;
-	num_y = ((WINDOW_HEIGHT + 0xF) / 0x10) + 1;
-	put_x = (fx / 0x200 + 8) / 0x10;
-	put_y = (fy / 0x200 + 8) / 0x10;
+	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;
 
 	for (j = put_y; j < put_y + num_y; j++)
 	{
@@ -169,12 +169,12 @@
 				continue;
 
 			// Draw tile
-			rect.left = 16 * (gMap.data[offset] % 0x10);
-			rect.top = 16 * (gMap.data[offset] / 0x10);
+			rect.left = 16 * (gMap.data[offset] % 16);
+			rect.top = 16 * (gMap.data[offset] / 16);
 			rect.right = rect.left + 16;
 			rect.bottom = rect.top + 16;
 
-			PutBitmap3(&grcGame, 0x10 * i - 8 - fx / 0x200, 0x10 * j - 8 - fy / 0x200, &rect, SURFACE_ID_LEVEL_TILESET);
+			PutBitmap3(&grcGame, (i * 16 - 8) - (fx / 0x200), (j * 16 - 8) - (fy / 0x200), &rect, SURFACE_ID_LEVEL_TILESET);
 		}
 	}
 }
@@ -193,8 +193,8 @@
 	int num_x;
 
 	// Get range to draw
-	num_x = ((WINDOW_WIDTH + 0xF) >> 4) + 1;
-	num_y = ((WINDOW_HEIGHT + 0xF) >> 4) + 1;
+	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;
 
@@ -210,15 +210,15 @@
 				continue;
 
 			// Draw tile
-			rect.left = 16 * (gMap.data[offset] % 0x10);
-			rect.top = 16 * (gMap.data[offset] / 0x10);
+			rect.left = 16 * (gMap.data[offset] % 16);
+			rect.top = 16 * (gMap.data[offset] / 16);
 			rect.right = rect.left + 16;
 			rect.bottom = rect.top + 16;
 
-			PutBitmap3(&grcGame, 16 * i - 8 - fx / 0x200, 16 * j - 8 - fy / 0x200, &rect, SURFACE_ID_LEVEL_TILESET);
+			PutBitmap3(&grcGame, (i * 16 - 8) - (fx / 0x200), (j * 16 - 8) - (fy / 0x200), &rect, SURFACE_ID_LEVEL_TILESET);
 
 			if (atrb == 0x43)
-				PutBitmap3(&grcGame, 16 * i - 8 - fx / 0x200, 16 * j - 8 - fy / 0x200, &rcSnack, SURFACE_ID_NPC_SYM);
+				PutBitmap3(&grcGame, (i * 16 - 8) - (fx / 0x200), (j * 16 - 8) - (fy / 0x200), &rcSnack, SURFACE_ID_NPC_SYM);
 		}
 	}
 }
@@ -240,8 +240,8 @@
 	count += 2;
 
 	// Get range to draw
-	num_x = ((WINDOW_WIDTH + 0xF) >> 4) + 1;
-	num_y = ((WINDOW_HEIGHT + 0xF) >> 4) + 1;
+	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;
 
@@ -267,7 +267,7 @@
 			{
 				case 128:
 				case 160:
-					rect.left = 224 + (count % 0x10);
+					rect.left = 224 + (count % 16);
 					rect.right = rect.left + 16;
 					rect.top = 48;
 					rect.bottom = rect.top + 16;
@@ -276,12 +276,12 @@
 				case 161:
 					rect.left = 224;
 					rect.right = rect.left + 16;
-					rect.top = 48 + (count % 0x10);
+					rect.top = 48 + (count % 16);
 					rect.bottom = rect.top + 16;
 					break;
 				case 130:
 				case 162:
-					rect.left = 240 - (count % 0x10);
+					rect.left = 240 - (count % 16);
 					rect.right = rect.left + 16;
 					rect.top = 48;
 					rect.bottom = rect.top + 16;
@@ -290,12 +290,12 @@
 				case 163:
 					rect.left = 224;
 					rect.right = rect.left + 16;
-					rect.top = 64 - (count % 0x10);
+					rect.top = 64 - (count % 16);
 					rect.bottom = rect.top + 16;
 					break;
 			}
 
-			PutBitmap3(&grcGame, 16 * i - 8 - fx / 0x200, 16 * j - 8 - fy / 0x200, &rect, SURFACE_ID_CARET);
+			PutBitmap3(&grcGame, (i * 16 - 8) - (fx / 0x200), (j * 16 - 8) - (fy / 0x200), &rect, SURFACE_ID_CARET);
 		}
 	}
 }