[Scummvm-cvs-logs] SF.net SVN: scummvm:[53791] scummvm/trunk/engines/gob

drmccoy at users.sourceforge.net drmccoy at users.sourceforge.net
Mon Oct 25 05:38:34 CEST 2010


Revision: 53791
          http://scummvm.svn.sourceforge.net/scummvm/?rev=53791&view=rev
Author:   drmccoy
Date:     2010-10-25 03:38:34 +0000 (Mon, 25 Oct 2010)

Log Message:
-----------
GOB: Minor map cleanup

Make the direction a named enum and create a function moveDirection()
for increasing coordinates according to a direction.

Modified Paths:
--------------
    scummvm/trunk/engines/gob/goblin_v1.cpp
    scummvm/trunk/engines/gob/goblin_v2.cpp
    scummvm/trunk/engines/gob/map.cpp
    scummvm/trunk/engines/gob/map.h

Modified: scummvm/trunk/engines/gob/goblin_v1.cpp
===================================================================
--- scummvm/trunk/engines/gob/goblin_v1.cpp	2010-10-25 03:38:12 UTC (rev 53790)
+++ scummvm/trunk/engines/gob/goblin_v1.cpp	2010-10-25 03:38:34 UTC (rev 53791)
@@ -173,10 +173,10 @@
 			_pathExistence = 0;
 		}
 
-		nextAct = _vm->_map->getDirection(_vm->_map->_curGoblinX,
+		nextAct = (int16) _vm->_map->getDirection(_vm->_map->_curGoblinX,
 				_vm->_map->_curGoblinY, _vm->_map->_destX, _vm->_map->_destY);
 
-		if (nextAct == 0)
+		if (nextAct == Map::kDirNone)
 			_pathExistence = 0;
 	} else if (_pathExistence == 3) {
 		_vm->_map->_curGoblinX = _gobPositions[_currentGoblin].x;
@@ -229,7 +229,7 @@
 					}
 				}
 			}
-			nextAct = _vm->_map->getDirection(_vm->_map->_curGoblinX,
+			nextAct = (int16) _vm->_map->getDirection(_vm->_map->_curGoblinX,
 					_vm->_map->_curGoblinY, _vm->_map->_destX, _vm->_map->_destY);
 		}
 	}

Modified: scummvm/trunk/engines/gob/goblin_v2.cpp
===================================================================
--- scummvm/trunk/engines/gob/goblin_v2.cpp	2010-10-25 03:38:12 UTC (rev 53790)
+++ scummvm/trunk/engines/gob/goblin_v2.cpp	2010-10-25 03:38:34 UTC (rev 53791)
@@ -39,10 +39,10 @@
 
 Goblin_v2::Goblin_v2(GobEngine *vm) : Goblin_v1(vm) {
 	_gobsCount = -1;
-	_rotStates[0][0] = 0; _rotStates[0][1] = 18; _rotStates[0][2] = 19; _rotStates[0][3] = 20;
-	_rotStates[1][0] = 13; _rotStates[1][1] = 2; _rotStates[1][2] = 12; _rotStates[1][3] = 14;
-	_rotStates[2][0] = 16; _rotStates[2][1] = 15; _rotStates[2][2] = 4; _rotStates[2][3] = 17;
-	_rotStates[3][0] = 23; _rotStates[3][1] = 21; _rotStates[3][2] = 22; _rotStates[3][3] = 6;
+	_rotStates[0][0] =  0; _rotStates[0][1] = 18; _rotStates[0][2] = 19; _rotStates[0][3] = 20;
+	_rotStates[1][0] = 13; _rotStates[1][1] =  2; _rotStates[1][2] = 12; _rotStates[1][3] = 14;
+	_rotStates[2][0] = 16; _rotStates[2][1] = 15; _rotStates[2][2] =  4; _rotStates[2][3] = 17;
+	_rotStates[3][0] = 23; _rotStates[3][1] = 21; _rotStates[3][2] = 22; _rotStates[3][3] =  6;
 }
 
 void Goblin_v2::freeObjects() {
@@ -142,12 +142,12 @@
 	animData->destY = gobDestY;
 	animData->order = gobY;
 
-	int16 dir = 0;
+	Map::Direction dir = Map::kDirNone;
 
 	if (animData->pathExistence == 1) {
 
 		dir = _vm->_map->getDirection(gobX, gobY, destX, destY);
-		if (dir == 0)
+		if (dir == Map::kDirNone)
 			animData->pathExistence = 0;
 		if ((gobX == gobDestX) && (gobY == gobDestY))
 			animData->pathExistence = 4;

Modified: scummvm/trunk/engines/gob/map.cpp
===================================================================
--- scummvm/trunk/engines/gob/map.cpp	2010-10-25 03:38:12 UTC (rev 53790)
+++ scummvm/trunk/engines/gob/map.cpp	2010-10-25 03:38:34 UTC (rev 53791)
@@ -90,14 +90,14 @@
 	kDown  = (1 << 3)
 };
 
-int16 Map::getDirection(int16 x0, int16 y0, int16 x1, int16 y1) {
+Map::Direction Map::getDirection(int16 x0, int16 y0, int16 x1, int16 y1) {
 	if ((x0 == x1) && (y0 == y1))
 		// Already at the destination
-		return 0;
+		return kDirNone;
 
 	if ((x1 < 0) || (x1 > _mapWidth) || (y1 < 0) || (y1 > _mapHeight))
 		// Destination out of range
-		return 0;
+		return kDirNone;
 
 	int16 dir = 0;
 
@@ -134,7 +134,7 @@
 			return kDirW;
 
 		// Can't go
-		return 0;
+		return kDirNone;
 	}
 
 	// Want to go left
@@ -144,7 +144,7 @@
 			return kDirE;
 
 		// Can't go
-		return 0;
+		return kDirNone;
 	}
 
 
@@ -163,7 +163,7 @@
 			return kDirNE;
 
 		// Can't go at all
-		return 0;
+		return kDirNone;
 	}
 
 	// Want to go down
@@ -181,7 +181,7 @@
 			return kDirSE;
 
 		// Can't go at all
-		return 0;
+		return kDirNone;
 	}
 
 
@@ -200,7 +200,7 @@
 			return kDirE;
 
 		// Can't go at all
-		return 0;
+		return kDirNone;
 	}
 
 	// Want to go down and right
@@ -218,7 +218,7 @@
 			return kDirE;
 
 		// Can't go at all
-		return 0;
+		return kDirNone;
 	}
 
 	// Want to go up and left
@@ -236,7 +236,7 @@
 			return kDirW;
 
 		// Can't go at all
-		return 0;
+		return kDirNone;
 	}
 
 	// Want to go left and down
@@ -254,11 +254,11 @@
 			return kDirW;
 
 		// Can't go at all
-		return 0;
+		return kDirNone;
 	}
 
 	warning("Map::getDirection(): Invalid direction?!?");
-	return -1;
+	return kDirNone;
 }
 
 int16 Map::findNearestWayPoint(int16 x, int16 y) {
@@ -350,13 +350,57 @@
 		gobDestY -= distance;
 }
 
-int16 Map::checkDirectPath(Mult::Mult_Object *obj,
-		int16 x0, int16 y0, int16 x1, int16 y1) {
+void Map::moveDirection(Direction dir, int16 &x, int16 &y) {
+	switch (dir) {
+	case kDirNW:
+		x--;
+		y--;
+		break;
 
+	case kDirN:
+		y--;
+		break;
+
+	case kDirNE:
+		x++;
+		y--;
+		break;
+
+	case kDirW:
+		x--;
+		break;
+
+	case kDirE:
+		x++;
+		break;
+
+	case kDirSW:
+		x--;
+		y++;
+		break;
+
+	case kDirS:
+		y++;
+		break;
+
+	case kDirSE:
+		x++;
+		y++;
+		break;
+
+	default:
+		break;
+	}
+}
+
+int16 Map::checkDirectPath(Mult::Mult_Object *obj, int16 x0, int16 y0, int16 x1, int16 y1) {
+
 	while (1) {
-		uint16 dir = getDirection(x0, y0, x1, y1);
+		Direction dir = getDirection(x0, y0, x1, y1);
 
 		if (obj) {
+			// Check for a blocking waypoint
+
 			if (obj->nearestWayPoint < obj->nearestDest)
 				if ((obj->nearestWayPoint + 1) < _wayPointsCount)
 					if (_wayPoints[obj->nearestWayPoint + 1].notWalkable == 1)
@@ -369,54 +413,18 @@
 		}
 
 		if ((x0 == x1) && (y0 == y1))
+			// Successfully reached the destination
 			return 1;
 
-		if (dir == 0)
+		if (dir == kDirNone)
+			// No way
 			return 3;
 
-		switch (dir) {
-		case kDirNW:
-			x0--;
-			y0--;
-			break;
-
-		case kDirN:
-			y0--;
-			break;
-
-		case kDirNE:
-			x0++;
-			y0--;
-			break;
-
-		case kDirW:
-			x0--;
-			break;
-
-		case kDirE:
-			x0++;
-			break;
-
-		case kDirSW:
-			x0--;
-			y0++;
-			break;
-
-		case kDirS:
-			y0++;
-			break;
-
-		case kDirSE:
-			x0++;
-			y0++;
-			break;
-		}
+		moveDirection(dir, x0, y0);
 	}
 }
 
-int16 Map::checkLongPath(int16 x0, int16 y0,
-		int16 x1, int16 y1, int16 i0, int16 i1) {
-	uint16 dir = 0;
+int16 Map::checkLongPath(int16 x0, int16 y0, int16 x1, int16 y1, int16 i0, int16 i1) {
 	int16 curX = x0;
 	int16 curY = y0;
 	int16 nextLink = 1;
@@ -449,47 +457,13 @@
 				return 1;
 			return 0;
 		}
-		dir = getDirection(x0, y0, curX, curY);
-		switch (dir) {
-		case 0:
+
+		Direction dir = getDirection(x0, y0, curX, curY);
+		if (dir == kDirNone)
+			// No way
 			return 0;
 
-		case kDirNW:
-			x0--;
-			y0--;
-			break;
-
-		case kDirN:
-			y0--;
-			break;
-
-		case kDirNE:
-			x0++;
-			y0--;
-			break;
-
-		case kDirW:
-			x0--;
-			break;
-
-		case kDirE:
-			x0++;
-			break;
-
-		case kDirSW:
-			x0--;
-			y0++;
-			break;
-
-		case kDirS:
-			y0++;
-			break;
-
-		case kDirSE:
-			x0++;
-			y0++;
-			break;
-		}
+		moveDirection(dir, x0, y0);
 	}
 }
 

Modified: scummvm/trunk/engines/gob/map.h
===================================================================
--- scummvm/trunk/engines/gob/map.h	2010-10-25 03:38:12 UTC (rev 53790)
+++ scummvm/trunk/engines/gob/map.h	2010-10-25 03:38:34 UTC (rev 53791)
@@ -34,15 +34,16 @@
 
 class Map {
 public:
-	enum {
-		kDirNW = 0x4700,
-		kDirN  = 0x4800,
-		kDirNE = 0x4900,
-		kDirW  = 0x4B00,
-		kDirE  = 0x4D00,
-		kDirSW = 0x4F00,
-		kDirS  = 0x5000,
-		kDirSE = 0x5100
+	enum Direction {
+		kDirNone = 0x0000,
+		kDirNW   = 0x4700,
+		kDirN    = 0x4800,
+		kDirNE   = 0x4900,
+		kDirW    = 0x4B00,
+		kDirE    = 0x4D00,
+		kDirSW   = 0x4F00,
+		kDirS    = 0x5000,
+		kDirSE   = 0x5100
 	};
 
 #include "common/pack-start.h"	// START STRUCT PACKING
@@ -94,7 +95,8 @@
 
 	void placeItem(int16 x, int16 y, int16 id);
 
-	int16 getDirection(int16 x0, int16 y0, int16 x1, int16 y1);
+	Direction getDirection(int16 x0, int16 y0, int16 x1, int16 y1);
+
 	int16 checkDirectPath(Mult::Mult_Object *obj, int16 x0,
 			int16 y0, int16 x1, int16 y1);
 	int16 checkLongPath(int16 x0, int16 y0,
@@ -122,6 +124,10 @@
 	GobEngine *_vm;
 
 	int16 findNearestWayPoint(int16 x, int16 y);
+
+private:
+	// Move the x and y values according to the direction
+	void moveDirection(Direction dir, int16 &x, int16 &y);
 };
 
 class Map_v1 : public Map {


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