[Scummvm-cvs-logs] SF.net SVN: scummvm: [26747] scummvm/trunk/engines/lure

dreammaster at users.sourceforge.net dreammaster at users.sourceforge.net
Sat May 5 03:00:03 CEST 2007


Revision: 26747
          http://scummvm.svn.sourceforge.net/scummvm/?rev=26747&view=rev
Author:   dreammaster
Date:     2007-05-04 18:00:01 -0700 (Fri, 04 May 2007)

Log Message:
-----------
Bugfix for random destination setting so NPCs don't walk outside the valid walkable areas of a room

Modified Paths:
--------------
    scummvm/trunk/engines/lure/hotspots.cpp
    scummvm/trunk/engines/lure/res_struct.cpp
    scummvm/trunk/engines/lure/res_struct.h

Modified: scummvm/trunk/engines/lure/hotspots.cpp
===================================================================
--- scummvm/trunk/engines/lure/hotspots.cpp	2007-05-04 12:56:48 UTC (rev 26746)
+++ scummvm/trunk/engines/lure/hotspots.cpp	2007-05-05 01:00:01 UTC (rev 26747)
@@ -536,7 +536,6 @@
 	RoomData *roomData = res.getRoom(roomNumber());
 	Common::Rect &rect = roomData->walkBounds;
 	Common::RandomSource rnd;
-	int tryCtr = 0;
 	int16 xp, yp;
 
 	if (_currentActions.isEmpty())
@@ -545,13 +544,15 @@
 		_currentActions.top().setAction(START_WALKING);
 	_walkFlag = true;
 
-	while (tryCtr ++ <= 20) {
+	// Try up to 20 times to find an unoccupied destination 
+	for (int tryCtr = 0; tryCtr < 20; ++tryCtr) {
 		xp = rect.left + rnd.getRandomNumber(rect.right - rect.left);
-		yp = rect.left + rnd.getRandomNumber(rect.right - rect.left);
+		yp = rect.left + rnd.getRandomNumber(rect.bottom - rect.top);
 		setDestPosition(xp, yp);
 		setDestHotspot(0);
 
-		if (!roomData->paths.isOccupied(xp, yp) && !roomData->paths.isOccupied(xp, yp)) 
+		// Check if three sequential blocks at chosen destination are unoccupied
+		if (!roomData->paths.isOccupied(xp, yp, 3))  
 			break;
 	}
 }

Modified: scummvm/trunk/engines/lure/res_struct.cpp
===================================================================
--- scummvm/trunk/engines/lure/res_struct.cpp	2007-05-04 12:56:48 UTC (rev 26746)
+++ scummvm/trunk/engines/lure/res_struct.cpp	2007-05-05 01:00:01 UTC (rev 26747)
@@ -158,6 +158,15 @@
 	return (_data[y * 5 + (x >> 3)] & (0x80 >> (x % 8))) != 0;
 }
 
+bool RoomPathsData::isOccupied(int x, int y, int width) {
+	for (int blockCtr = 0; blockCtr < width; ++blockCtr) {
+		if (isOccupied(x + 8 * blockCtr, y))
+			return true;
+	}
+
+	return false;
+}
+
 void RoomPathsData::setOccupied(int x, int y, int width) {
 	if ((x < 0) || (y < 0) || (x >= ROOM_PATHS_WIDTH) || (y >= ROOM_PATHS_HEIGHT))
 		return;
@@ -212,6 +221,8 @@
 		*pOut-- = 0;
 
 	for (int y = 0; y < ROOM_PATHS_HEIGHT; ++y) {
+		charState = false;
+
 		for (int x = 0; x < (ROOM_PATHS_WIDTH / 8); ++x) {
 			// Get next byte, which containing bits for 8 blocks
 			v = *pIn--;		

Modified: scummvm/trunk/engines/lure/res_struct.h
===================================================================
--- scummvm/trunk/engines/lure/res_struct.h	2007-05-04 12:56:48 UTC (rev 26746)
+++ scummvm/trunk/engines/lure/res_struct.h	2007-05-05 01:00:01 UTC (rev 26747)
@@ -311,6 +311,7 @@
 		memcpy(_data, srcData, ROOM_PATHS_SIZE);
 	}
 	bool isOccupied(int x, int y);
+	bool isOccupied(int x, int y, int width);
 	void setOccupied(int x, int y, int width);
 	void clearOccupied(int x, int y, int width);
 	void decompress(RoomPathsDecompressedData &dataOut, int characterWidth);


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list