No subject


Fri Aug 26 12:11:03 CEST 2016


of the map about which objects are there. Each cell can contain two objects
which are stored in the upper and lower byte of a 16-bit word.

When dropping an object, it is written into map_itemsMap[], but not just to
the indicated cell but also to a few of the surrounding ones. Presumably to
make it easier to pick it up afterwards.

When writing an object to a cell, we check if one of the bytes is already
occupied. If it is, write to the other byte. Otherwise, write to that byte.
(If both bytes are occupied, one will be overwritten.)

The old code assumed that if one byte was free at position (x,y) the same
byte would automatically be the free one in the surrounding cells. This
could cause bad values in the array, since the item was added to an
existing value, rather than replacing it.

This new code makes the check for each cell that is modified. (It also gets
rid of some code duplication.)


Index: goblin.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/goblin.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- goblin.cpp	13 Apr 2005 18:27:27 -0000	1.12
+++ goblin.cpp	28 Apr 2005 10:34:47 -0000	1.13
@@ -2197,77 +2197,28 @@
 		    - (scen_toRedrawLeft + scen_toRedrawRight) / 2;
 	}
 
-	if ((map_itemsMap[yPos][xPos] & 0xff00) != 0) {
-		map_itemsMap[yPos][xPos] =
-		    (map_itemsMap[yPos][xPos] & 0xff00) + idInPocket;
-
-		if (yPos > 0) {
-
-			map_itemsMap[yPos - 1][xPos] =
-			    (map_itemsMap[yPos - 1][xPos] & 0xff00) +
-			    idInPocket;
-		}
-
-		if (lookDir == 4) {
-			if (xPos < 25) {
-
-				map_itemsMap[yPos][xPos + 1] =
-				    (map_itemsMap[yPos][xPos + 1] & 0xff00) +
-				    idInPocket;
+	map_placeItem(xPos, yPos, idInPocket);
 
-				if (yPos > 0) {
-					map_itemsMap[yPos - 1][xPos + 1] =
-					    (map_itemsMap[yPos - 1][xPos +
-						1] & 0xff00) + idInPocket;
-				}
-			}
-		} else {
-			if (xPos > 0) {
+	if (yPos > 0) {
+		map_placeItem(xPos, yPos - 1, idInPocket);
+	}
 
-				map_itemsMap[yPos][xPos - 1] =
-				    (map_itemsMap[yPos][xPos - 1] & 0xff00) +
-				    idInPocket;
+	if (lookDir == 4) {
+		if (xPos < 25) {
+			map_placeItem(xPos + 1, yPos, idInPocket);
 
-				if (yPos > 0) {
-					map_itemsMap[yPos - 1][xPos - 1] =
-					    (map_itemsMap[yPos - 1][xPos -
-						1] & 0xff00) + idInPocket;
-				}
+			if (yPos > 0) {
+				map_placeItem(xPos + 1, yPos - 1, idInPocket);
 			}
 		}
 	} else {
+		if (xPos > 0) {
+			map_placeItem(xPos - 1, yPos, idInPocket);
 
-		map_itemsMap[yPos][xPos] += (idInPocket << 8);
-
-		if (yPos > 0) {
-
-			map_itemsMap[yPos - 1][xPos] += (idInPocket << 8);
-		}
-
-		if (lookDir == 4) {
-			if (xPos < 25) {
-
-				map_itemsMap[yPos][xPos + 1] +=
-				    (idInPocket << 8);
-
-				if (yPos > 0) {
-					map_itemsMap[yPos - 1][xPos + 1] +=
-					    (idInPocket << 8);
-				}
-			}
-		} else {
-			if (xPos > 0) {
-
-				map_itemsMap[yPos][xPos - 1] +=
-				    (idInPocket << 8);
-
-				if (yPos > 0) {
-					map_itemsMap[yPos - 1][xPos - 1] +=
-					    (idInPocket << 8);
-				}
+			if (yPos > 0) {
+				map_placeItem(xPos - 1, yPos - 1, idInPocket);
 			}
 		}
-
 	}
 
 	if (idInPocket >= 0 && idInPocket < 20) {

Index: map.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/map.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- map.cpp	11 Apr 2005 20:44:33 -0000	1.9
+++ map.cpp	28 Apr 2005 10:34:48 -0000	1.10
@@ -48,6 +48,13 @@
 char map_sourceFile[15];
 static char *map_avoDataPtr;
 
+void map_placeItem(int16 x, int16 y, int16 id) {
+	if ((map_itemsMap[y][x] & 0xff00) != 0)
+		map_itemsMap[y][x] = (map_itemsMap[y][x] & 0xff00) | id;
+	else
+		map_itemsMap[y][x] = (map_itemsMap[y][x] & 0x00ff) | (id << 8);
+}
+
 int16 map_getDirection(int16 x0, int16 y0, int16 x1, int16 y1) {
 	int16 dir;
 

Index: map.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/map.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- map.h	11 Apr 2005 20:04:14 -0000	1.4
+++ map.h	28 Apr 2005 10:34:48 -0000	1.5
@@ -54,6 +54,8 @@
 extern Map_ItemPos map_itemPoses[40];
 extern char map_sourceFile[15];
 
+void map_placeItem(int16 x, int16 y, int16 id);
+
 int16 map_getDirection(int16 x0, int16 y0, int16 x1, int16 y1);
 void map_findNearestToGob(void);
 void map_findNearestToDest(void);





More information about the Scummvm-git-logs mailing list