aboutsummaryrefslogtreecommitdiff
path: root/gob/goblin.cpp
diff options
context:
space:
mode:
authorTorbjörn Andersson2005-04-28 10:34:48 +0000
committerTorbjörn Andersson2005-04-28 10:34:48 +0000
commit589b65945ac2b257a88c15808f5c35fe4a74aff6 (patch)
tree9bb6853d1e3c48fa039fcbb8e5f0e41ded45b55b /gob/goblin.cpp
parent98ed7a10d093286eca3b23226bcb45d6885630e9 (diff)
downloadscummvm-rg350-589b65945ac2b257a88c15808f5c35fe4a74aff6.tar.gz
scummvm-rg350-589b65945ac2b257a88c15808f5c35fe4a74aff6.tar.bz2
scummvm-rg350-589b65945ac2b257a88c15808f5c35fe4a74aff6.zip
This should fix a crash which could happen when placing several objects too
close to each other on the ground. (Happened to me on the first level after destroying the voodoo doll, where I'd drop the banana, the soap and the false nose close to each other on the ground after using them.) Reasoning behind the change: From what I understand, map_itemsMap[] contains information for each "cell" 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.) svn-id: r17851
Diffstat (limited to 'gob/goblin.cpp')
-rw-r--r--gob/goblin.cpp75
1 files changed, 13 insertions, 62 deletions
diff --git a/gob/goblin.cpp b/gob/goblin.cpp
index 80c007c6b1..45779846c5 100644
--- a/gob/goblin.cpp
+++ b/gob/goblin.cpp
@@ -2197,77 +2197,28 @@ void gob_placeItem(int16 indexInPocket, int16 idInPocket) {
- (scen_toRedrawLeft + scen_toRedrawRight) / 2;
}
- if ((map_itemsMap[yPos][xPos] & 0xff00) != 0) {
- map_itemsMap[yPos][xPos] =
- (map_itemsMap[yPos][xPos] & 0xff00) + idInPocket;
+ map_placeItem(xPos, yPos, 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;
-
- 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) {