[Scummvm-git-logs] scummvm master -> f90bf31bea635b8c78b72fb5147cf7108f4227db

Strangerke Strangerke at scummvm.org
Sun Sep 11 09:56:27 CEST 2016


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
f90bf31bea DM: Move some globals to DMEngine


Commit: f90bf31bea635b8c78b72fb5147cf7108f4227db
    https://github.com/scummvm/scummvm/commit/f90bf31bea635b8c78b72fb5147cf7108f4227db
Author: Strangerke (strangerke at scummvm.org)
Date: 2016-09-11T09:46:35+02:00

Commit Message:
DM: Move some globals to DMEngine

Changed paths:
    engines/dm/champion.cpp
    engines/dm/dm.cpp
    engines/dm/dm.h
    engines/dm/dungeonman.cpp
    engines/dm/eventman.cpp
    engines/dm/gfx.cpp
    engines/dm/group.cpp
    engines/dm/inventory.cpp
    engines/dm/menus.cpp
    engines/dm/movesens.cpp
    engines/dm/projexpl.cpp
    engines/dm/sounds.cpp
    engines/dm/timeline.cpp



diff --git a/engines/dm/champion.cpp b/engines/dm/champion.cpp
index 71e864e..2d5ea5e 100644
--- a/engines/dm/champion.cpp
+++ b/engines/dm/champion.cpp
@@ -237,7 +237,7 @@ bool ChampionMan::isObjectThrown(uint16 champIndex, int16 slotIndex, int16 side)
 	int16 attack = getBoundedValue((uint16)40, (uint16)((skillLevel << 3) + _vm->getRandomNumber(32)), (uint16)200);
 	int16 stepEnergy = MAX(5, 11 - skillLevel);
 	_vm->_projexpl->createProjectile(curThing, _vm->_dungeonMan->_partyMapX, _vm->_dungeonMan->_partyMapY,
-										  normalizeModulo4(_vm->_dungeonMan->_partyDir + side),
+										  _vm->normalizeModulo4(_vm->_dungeonMan->_partyDir + side),
 										  _vm->_dungeonMan->_partyDir, kineticEnergy, attack, stepEnergy);
 	_vm->_projectileDisableMovementTicks = 4;
 	_vm->_lastProjectileDisabledMovementDirection = _vm->_dungeonMan->_partyDir;
@@ -931,7 +931,7 @@ void ChampionMan::disableAction(uint16 champIndex, uint16 ticks) {
 
 	int16 eventIndex = curChampion->_enableActionEventIndex;
 	if (eventIndex >= 0) {
-		int32 currentEnableActionEventTime = filterTime(_vm->_timeline->_events[eventIndex]._mapTime);
+		int32 currentEnableActionEventTime = _vm->filterTime(_vm->_timeline->_events[eventIndex]._mapTime);
 		if (updatedEnableActionEventTime >= currentEnableActionEventTime) {
 			updatedEnableActionEventTime += (currentEnableActionEventTime - _vm->_gameTime) >> 1;
 		} else {
@@ -942,7 +942,7 @@ void ChampionMan::disableAction(uint16 champIndex, uint16 ticks) {
 		setFlag(curChampion->_attributes, kDMAttributeActionHand | kDMAttributeDisableAction);
 		drawChampionState((ChampionIndex)champIndex);
 	}
-	setMapAndTime(curEvent._mapTime, _vm->_dungeonMan->_partyMapIndex, updatedEnableActionEventTime);
+	_vm->setMapAndTime(curEvent._mapTime, _vm->_dungeonMan->_partyMapIndex, updatedEnableActionEventTime);
 	curChampion->_enableActionEventIndex = _vm->_timeline->addEventGetEventIndex(&curEvent);
 }
 
@@ -1070,7 +1070,7 @@ int16 ChampionMan::getDamagedChampionCount(uint16 attack, int16 wounds, int16 at
 }
 
 int16 ChampionMan::getTargetChampionIndex(int16 mapX, int16 mapY, uint16 cell) {
-	if (_partyChampionCount && (getDistance(mapX, mapY, _vm->_dungeonMan->_partyMapX, _vm->_dungeonMan->_partyMapY) <= 1)) {
+	if (_partyChampionCount && (_vm->getDistance(mapX, mapY, _vm->_dungeonMan->_partyMapX, _vm->_dungeonMan->_partyMapY) <= 1)) {
 		signed char orderedCellsToAttack[4];
 		_vm->_groupMan->setOrderedCellsToAttack(orderedCellsToAttack, _vm->_dungeonMan->_partyMapX, _vm->_dungeonMan->_partyMapY, mapX, mapY, cell);
 		for (uint16 i = 0; i < 4; i++) {
@@ -1117,7 +1117,7 @@ void ChampionMan::championPoison(int16 champIndex, uint16 attack) {
 		TimelineEvent newEvent;
 		newEvent._type = k75_TMEventTypePoisonChampion;
 		newEvent._priority = champIndex;
-		setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + 36);
+		_vm->setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + 36);
 		newEvent._Bu._attack = attack;
 		_vm->_timeline->addEventGetEventIndex(&newEvent);
 	}
@@ -1129,14 +1129,14 @@ void ChampionMan::setPartyDirection(int16 dir) {
 	if (dir == _vm->_dungeonMan->_partyDir)
 		return;
 
-	int16 L0834_i_Delta = dir - _vm->_dungeonMan->_partyDir;
-	if (L0834_i_Delta < 0)
-		L0834_i_Delta += 4;
+	int16 dirDiff = dir - _vm->_dungeonMan->_partyDir;
+	if (dirDiff < 0)
+		dirDiff += 4;
 
 	Champion *curChampion = _champions;
 	for (int16 i = kDMChampionFirst; i < _partyChampionCount; i++) {
-		curChampion->_cell = (ViewCell)normalizeModulo4(curChampion->_cell + L0834_i_Delta);
-		curChampion->_dir = (Direction)normalizeModulo4(curChampion->_dir + L0834_i_Delta);
+		curChampion->_cell = (ViewCell)_vm->normalizeModulo4(curChampion->_cell + dirDiff);
+		curChampion->_dir = (Direction)_vm->normalizeModulo4(curChampion->_dir + dirDiff);
 		curChampion++;
 	}
 
@@ -1357,7 +1357,7 @@ bool ChampionMan::isProjectileSpellCast(uint16 champIndex, Thing thing, int16 ki
 
 void ChampionMan::championShootProjectile(Champion *champ, Thing thing, int16 kineticEnergy, int16 attack, int16 stepEnergy) {
 	Direction newDirection = champ->_dir;
-	_vm->_projexpl->createProjectile(thing, _vm->_dungeonMan->_partyMapX, _vm->_dungeonMan->_partyMapY, normalizeModulo4((((champ->_cell - newDirection + 1) & 0x0002) >> 1) + newDirection), newDirection, kineticEnergy, attack, stepEnergy);
+	_vm->_projexpl->createProjectile(thing, _vm->_dungeonMan->_partyMapX, _vm->_dungeonMan->_partyMapY, _vm->normalizeModulo4((((champ->_cell - newDirection + 1) & 0x0002) >> 1) + newDirection), newDirection, kineticEnergy, attack, stepEnergy);
 	_vm->_projectileDisableMovementTicks = 4;
 	_vm->_lastProjectileDisabledMovementDirection = newDirection;
 }
@@ -1432,12 +1432,12 @@ void ChampionMan::applyAndDrawPendingDamageAndWounds() {
 			if (eventIndex == -1) {
 				TimelineEvent newEvent;
 				newEvent._type = k12_TMEventTypeHideDamageReceived;
-				setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + 5);
+				_vm->setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + 5);
 				newEvent._priority = championIndex;
 				championPtr->_hideDamageReceivedIndex = _vm->_timeline->addEventGetEventIndex(&newEvent);
 			} else {
 				TimelineEvent *curEvent = &_vm->_timeline->_events[eventIndex];
-				setMapAndTime(curEvent->_mapTime, _vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + 5);
+				_vm->setMapAndTime(curEvent->_mapTime, _vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + 5);
 				_vm->_timeline->fixChronology(_vm->_timeline->getIndex(eventIndex));
 			}
 			drawChampionState((ChampionIndex)championIndex);
@@ -1476,7 +1476,7 @@ void ChampionMan::championKill(uint16 champIndex) {
 		L0966_ps_Junk->setDoNotDiscard(true);
 		L0966_ps_Junk->setChargeCount(champIndex);
 		curCell = curChampion->_cell;
-		_vm->_moveSens->getMoveResult(thingWithNewCell(unusedThing, curCell), kM1_MapXNotOnASquare, 0, _vm->_dungeonMan->_partyMapX, _vm->_dungeonMan->_partyMapY);
+		_vm->_moveSens->getMoveResult(_vm->thingWithNewCell(unusedThing, curCell), kM1_MapXNotOnASquare, 0, _vm->_dungeonMan->_partyMapX, _vm->_dungeonMan->_partyMapY);
 	}
 	curChampion->_symbolStep = 0;
 	curChampion->_symbols[0] = '\0';
@@ -1553,7 +1553,7 @@ void ChampionMan::dropAllObjects(uint16 champIndex) {
 	for (uint16 slotIndex = kDMSlotReadyHand; slotIndex < kDMSlotChest1; slotIndex++) {
 		Thing curThing = getObjectRemovedFromSlot(champIndex, slotDropOrder[slotIndex]);
 		if (curThing != Thing::_none)
-			_vm->_moveSens->getMoveResult(thingWithNewCell(curThing, curCell), kM1_MapXNotOnASquare, 0, _vm->_dungeonMan->_partyMapX, _vm->_dungeonMan->_partyMapY);
+			_vm->_moveSens->getMoveResult(_vm->thingWithNewCell(curThing, curCell), kM1_MapXNotOnASquare, 0, _vm->_dungeonMan->_partyMapX, _vm->_dungeonMan->_partyMapY);
 	}
 }
 
@@ -1881,10 +1881,10 @@ void ChampionMan::addCandidateChampionToParty(uint16 championPortraitIndex) {
 	championPtr->_hideDamageReceivedIndex = -1;
 	championPtr->_dir = _vm->_dungeonMan->_partyDir;
 	uint16 viewCell = k0_ViewCellFronLeft;
-	while (getIndexInCell(normalizeModulo4(viewCell + _vm->_dungeonMan->_partyDir)) != kDMChampionNone)
+	while (getIndexInCell(_vm->normalizeModulo4(viewCell + _vm->_dungeonMan->_partyDir)) != kDMChampionNone)
 		viewCell++;
 
-	championPtr->_cell = (ViewCell)normalizeModulo4(viewCell + _vm->_dungeonMan->_partyDir);
+	championPtr->_cell = (ViewCell)_vm->normalizeModulo4(viewCell + _vm->_dungeonMan->_partyDir);
 	championPtr->_attributes = kDMAttributeIcon;
 	championPtr->_directionMaximumDamageReceived = _vm->_dungeonMan->_partyDir;
 	championPtr->_food = 1500 + _vm->getRandomNumber(256);
@@ -1960,7 +1960,7 @@ void ChampionMan::addCandidateChampionToParty(uint16 championPortraitIndex) {
 
 	int16 curMapX = _vm->_dungeonMan->_partyMapX;
 	int16 curMapY = _vm->_dungeonMan->_partyMapY;
-	uint16 championObjectsCell = returnOppositeDir(_vm->_dungeonMan->_partyDir);
+	uint16 championObjectsCell = _vm->returnOppositeDir(_vm->_dungeonMan->_partyDir);
 	curMapX += _vm->_dirIntoStepCountEast[_vm->_dungeonMan->_partyDir], curMapY += _vm->_dirIntoStepCountNorth[_vm->_dungeonMan->_partyDir];
 	curThing = _vm->_dungeonMan->getSquareFirstThing(curMapX, curMapY);
 	int16 slotIdx = kDMSlotBackpackLine1_1;
diff --git a/engines/dm/dm.cpp b/engines/dm/dm.cpp
index cb1014e..199752a 100644
--- a/engines/dm/dm.cpp
+++ b/engines/dm/dm.cpp
@@ -75,59 +75,59 @@ const char *debugGetDirectionName(Direction dir) {
 	return directionNames[dir];
 }
 
-void turnDirRight(Direction &dir) {
+void DMEngine::turnDirRight(Direction &dir) {
 	dir = (Direction)((dir + 1) & 3);
 }
 
-void turnDirLeft(Direction &dir) {
+void DMEngine::turnDirLeft(Direction &dir) {
 	dir = (Direction)((dir - 1) & 3);
 }
 
-Direction returnOppositeDir(Direction dir) {
+Direction DMEngine::returnOppositeDir(Direction dir) {
 	return (Direction)((dir + 2) & 3);
 }
 
-uint16 returnPrevVal(uint16 val) {
+uint16 DMEngine::returnPrevVal(uint16 val) {
 	return (Direction)((val + 3) & 3);
 }
 
-uint16 returnNextVal(uint16 val) {
+uint16 DMEngine::returnNextVal(uint16 val) {
 	return (val + 1) & 0x3;
 }
 
-bool isOrientedWestEast(Direction dir) {
+bool DMEngine::isOrientedWestEast(Direction dir) {
 	return dir & 1;
 }
 
-uint16 toggleFlag(uint16& val, uint16 mask) {
+uint16 DMEngine::toggleFlag(uint16& val, uint16 mask) {
 	return val ^= mask;
 }
 
-uint16 bitmapByteCount(uint16 pixelWidth, uint16 height) {
+uint16 DMEngine::bitmapByteCount(uint16 pixelWidth, uint16 height) {
 	return pixelWidth / 2 * height;
 }
 
-uint16 normalizeModulo4(uint16 val) {
+uint16 DMEngine::normalizeModulo4(uint16 val) {
 	return val & 3;
 }
 
-int32 filterTime(int32 mapTime) {
+int32 DMEngine::filterTime(int32 mapTime) {
 	return mapTime & 0x00FFFFFF;
 }
 
-int32 setMapAndTime(int32 &mapTime, uint32 map, uint32 time) {
+int32 DMEngine::setMapAndTime(int32 &mapTime, uint32 map, uint32 time) {
 	return (mapTime) = ((time) | (((long)(map)) << 24));
 }
 
-uint16 getMap(int32 mapTime) {
+uint16 DMEngine::getMap(int32 mapTime) {
 	return ((uint16)((mapTime) >> 24));
 }
 
-Thing thingWithNewCell(Thing thing, int16 cell) {
+Thing DMEngine::thingWithNewCell(Thing thing, int16 cell) {
 	return Thing(((thing.toUint16()) & 0x3FFF) | ((cell) << 14));
 }
 
-int16 getDistance(int16 mapx1, int16 mapy1, int16 mapx2, int16 mapy2) {
+int16 DMEngine::getDistance(int16 mapx1, int16 mapy1, int16 mapx2, int16 mapy2) {
 	return ABS(mapx1 - mapx2) + ABS(mapy1 - mapy2);
 }
 
diff --git a/engines/dm/dm.h b/engines/dm/dm.h
index 051b5e8..c37ab23 100644
--- a/engines/dm/dm.h
+++ b/engines/dm/dm.h
@@ -200,26 +200,10 @@ public:
 	bool operator!=(const Thing &rhs) const { return _data != rhs._data; }
 }; // @ THING
 
-void turnDirRight(Direction &dir);
-void turnDirLeft(Direction &dir);
-Direction returnOppositeDir(Direction dir);	// @ M18_OPPOSITE
-uint16 returnPrevVal(uint16 val); // @ M19_PREVIOUS
-uint16 returnNextVal(uint16 val); // @ M17_NEXT
-bool isOrientedWestEast(Direction dir);	// @ M16_IS_ORIENTED_WEST_EAST
-
 #define setFlag(val, mask) ((val) |= (mask))
 #define getFlag(val, mask) ((val) & (mask))
 #define clearFlag(val, mask) ((val) &= (~(mask))) // @ M09_CLEAR
 
-uint16 toggleFlag(uint16 &val, uint16 mask); // @ M10_TOGGLE
-uint16 bitmapByteCount(uint16 pixelWidth, uint16 height);  // @ M75_BITMAP_BYTE_COUNT
-uint16 normalizeModulo4(uint16 val); // @ M21_NORMALIZE
-int32 filterTime(int32 map_time); // @ M30_TIME
-int32 setMapAndTime(int32 &map_time, uint32 map, uint32 time); // @ M33_SET_MAP_AND_TIME
-uint16 getMap(int32 map_time); // @ M29_MAP
-Thing thingWithNewCell(Thing thing, int16 cell); // @ M15_THING_WITH_NEW_CELL
-int16 getDistance(int16 mapx1, int16 mapy1, int16 mapx2, int16 mapy2);// @ M38_DISTANCE
-
 //TODO: Directly use CLIP
 template<typename T>
 inline T getBoundedValue(T min, T val, T max) {
@@ -272,6 +256,21 @@ public:
 	void fuseSequenceUpdate(); // @ F0445_STARTEND_FuseSequenceUpdate
 	Common::Language getGameLanguage();
 
+	void turnDirRight(Direction &dir);
+	void turnDirLeft(Direction &dir);
+	Direction returnOppositeDir(Direction dir);	// @ M18_OPPOSITE
+	uint16 returnPrevVal(uint16 val); // @ M19_PREVIOUS
+	uint16 returnNextVal(uint16 val); // @ M17_NEXT
+	bool isOrientedWestEast(Direction dir);	// @ M16_IS_ORIENTED_WEST_EAST
+	uint16 toggleFlag(uint16 &val, uint16 mask); // @ M10_TOGGLE
+	uint16 bitmapByteCount(uint16 pixelWidth, uint16 height);  // @ M75_BITMAP_BYTE_COUNT
+	uint16 normalizeModulo4(uint16 val); // @ M21_NORMALIZE
+	int32 filterTime(int32 map_time); // @ M30_TIME
+	int32 setMapAndTime(int32 &map_time, uint32 map, uint32 time); // @ M33_SET_MAP_AND_TIME
+	uint16 getMap(int32 map_time); // @ M29_MAP
+	Thing thingWithNewCell(Thing thing, int16 cell); // @ M15_THING_WITH_NEW_CELL
+	int16 getDistance(int16 mapx1, int16 mapy1, int16 mapx2, int16 mapy2);// @ M38_DISTANCE
+
 private:
 	uint16 _dungeonId; // @ G0526_ui_DungeonID
 	byte *_entranceDoorAnimSteps[10]; // @ G0562_apuc_Bitmap_EntranceDoorAnimationSteps
diff --git a/engines/dm/dungeonman.cpp b/engines/dm/dungeonman.cpp
index f10d69b..cb602d0 100644
--- a/engines/dm/dungeonman.cpp
+++ b/engines/dm/dungeonman.cpp
@@ -40,7 +40,7 @@ namespace DM {
 void DungeonMan::mapCoordsAfterRelMovement(Direction dir, int16 stepsForward, int16 stepsRight, int16 &posX, int16 &posY) {
 	posX += _vm->_dirIntoStepCountEast[dir] * stepsForward;
 	posY += _vm->_dirIntoStepCountNorth[dir] * stepsForward;
-	turnDirRight(dir);
+	_vm->turnDirRight(dir);
 	posX += _vm->_dirIntoStepCountEast[dir] * stepsRight;
 	posY += _vm->_dirIntoStepCountNorth[dir] * stepsRight;
 }
@@ -895,7 +895,7 @@ T0172010_ClosedFakeWall:
 		setSquareAspectOrnOrdinals(aspectArray, leftRandomWallOrnamentAllowed, frontRandomWallOrnamentAllowed, rightRandomWallOrnamentAllowed, dir, mapX, mapY, squareIsFakeWall);
 		while ((curThing != Thing::_endOfList) && (curThing.getType() <= kDMThingTypeSensor)) {
 			ThingType curThingType = curThing.getType();
-			int16 AL0310_i_SideIndex = normalizeModulo4(curThing.getCell() - dir);
+			int16 AL0310_i_SideIndex = _vm->normalizeModulo4(curThing.getCell() - dir);
 			if (AL0310_i_SideIndex) { /* Invisible on the back wall if 0 */
 				Sensor *curSensor = (Sensor *)getThingData(curThing);
 				if (curThingType == kDMstringTypeText) {
@@ -960,14 +960,14 @@ T0172010_ClosedFakeWall:
 
 		break;
 	case k3_ElementTypeStairs:
-		aspectArray[k0_ElementAspect] = (bool((getFlag(AL0307_uc_Square, k0x0008_StairsNorthSouthOrient) >> 3)) == isOrientedWestEast(dir)) ? k18_ElementTypeStairsSide : k19_ElementTypeStaisFront;
+		aspectArray[k0_ElementAspect] = (bool((getFlag(AL0307_uc_Square, k0x0008_StairsNorthSouthOrient) >> 3)) == _vm->isOrientedWestEast(dir)) ? k18_ElementTypeStairsSide : k19_ElementTypeStaisFront;
 		aspectArray[k2_StairsUpAspect] = getFlag(AL0307_uc_Square, k0x0004_StairsUp);
 		AL0307_uc_FootprintsAllowed = false;
 		while ((curThing != Thing::_endOfList) && (curThing.getType() <= kDMThingTypeSensor))
 			curThing = getNextThing(curThing);
 		break;
 	case k4_DoorElemType:
-		if (bool((getFlag(AL0307_uc_Square, k0x0008_DoorNorthSouthOrient) >> 3)) == isOrientedWestEast(dir)) {
+		if (bool((getFlag(AL0307_uc_Square, (byte) k0x0008_DoorNorthSouthOrient) >> 3)) == _vm->isOrientedWestEast(dir)) {
 			aspectArray[k0_ElementAspect] = k16_DoorSideElemType;
 		} else {
 			aspectArray[k0_ElementAspect] = k17_DoorFrontElemType;
@@ -991,9 +991,9 @@ void DungeonMan::setSquareAspectOrnOrdinals(uint16 *aspectArray, bool leftAllowe
 												 int16 mapX, int16 mapY, bool isFakeWall) {
 
 	int16 randomWallOrnamentCount = _currMap->_randWallOrnCount;
-	aspectArray[k2_RightWallOrnOrdAspect] = getRandomOrnOrdinal(leftAllowed, randomWallOrnamentCount, mapX, ++mapY * (normalizeModulo4(++dir) + 1), 30);
-	aspectArray[k3_FrontWallOrnOrdAspect] = getRandomOrnOrdinal(frontAllowed, randomWallOrnamentCount, mapX, mapY * (normalizeModulo4(++dir) + 1), 30);
-	aspectArray[k4_LeftWallOrnOrdAspect] = getRandomOrnOrdinal(rightAllowed, randomWallOrnamentCount, mapX, mapY-- * (normalizeModulo4(++dir) + 1), 30);
+	aspectArray[k2_RightWallOrnOrdAspect] = getRandomOrnOrdinal(leftAllowed, randomWallOrnamentCount, mapX, ++mapY * (_vm->normalizeModulo4(++dir) + 1), 30);
+	aspectArray[k3_FrontWallOrnOrdAspect] = getRandomOrnOrdinal(frontAllowed, randomWallOrnamentCount, mapX, mapY * (_vm->normalizeModulo4(++dir) + 1), 30);
+	aspectArray[k4_LeftWallOrnOrdAspect] = getRandomOrnOrdinal(rightAllowed, randomWallOrnamentCount, mapX, mapY-- * (_vm->normalizeModulo4(++dir) + 1), 30);
 	if (isFakeWall || (mapX < 0) || (mapX >= _currMapWidth) || (mapY < 0) || (mapY >= _currMapHeight)) { /* If square is a fake wall or is out of map bounds */
 		for (int16 sideIndex = k2_RightWallOrnOrdAspect; sideIndex <= k4_LeftWallOrnOrdAspect; sideIndex++) { /* Loop to remove any random ornament that is an alcove */
 			if (isWallOrnAnAlcove(_vm->ordinalToIndex(aspectArray[sideIndex])))
@@ -1531,7 +1531,7 @@ void DungeonMan::setGroupDirections(Group *group, int16 dir, uint16 mapIndex) {
 	if (mapIndex == _partyMapIndex)
 		_vm->_groupMan->_activeGroups[group->getActiveGroupIndex()]._directions = (Direction)dir;
 	else
-		group->setDir(normalizeModulo4(dir));
+		group->setDir(_vm->normalizeModulo4(dir));
 }
 
 bool DungeonMan::isCreatureAllowedOnMap(Thing thing, uint16 mapIndex) {
diff --git a/engines/dm/eventman.cpp b/engines/dm/eventman.cpp
index 73c47d1..8e6e993 100644
--- a/engines/dm/eventman.cpp
+++ b/engines/dm/eventman.cpp
@@ -728,7 +728,7 @@ void EventManager::processCommandQueue() {
 
 	Command cmd = _commandQueue.pop();
 	CommandType cmdType = cmd._type;
-	if ((cmdType >= k3_CommandMoveForward) && (cmdType <= k6_CommandMoveLeft) && (_vm->_disabledMovementTicks || (_vm->_projectileDisableMovementTicks && (_vm->_lastProjectileDisabledMovementDirection == (normalizeModulo4(_vm->_dungeonMan->_partyDir + cmdType - k3_CommandMoveForward)))))) { /* If movement is disabled */
+	if ((cmdType >= k3_CommandMoveForward) && (cmdType <= k6_CommandMoveLeft) && (_vm->_disabledMovementTicks || (_vm->_projectileDisableMovementTicks && (_vm->_lastProjectileDisabledMovementDirection == (_vm->normalizeModulo4(_vm->_dungeonMan->_partyDir + cmdType - k3_CommandMoveForward)))))) { /* If movement is disabled */
 		_isCommandQueueLocked = false;
 		processPendingClick();
 		return;
@@ -941,7 +941,7 @@ void EventManager::commandTurnParty(CommandType cmdType) {
 	}
 
 	_vm->_moveSens->processThingAdditionOrRemoval(_vm->_dungeonMan->_partyMapX, _vm->_dungeonMan->_partyMapY, Thing::_party, true, false);
-	_vm->_championMan->setPartyDirection(normalizeModulo4(_vm->_dungeonMan->_partyDir + ((cmdType == k2_CommandTurnRight) ? 1 : 3)));
+	_vm->_championMan->setPartyDirection(_vm->normalizeModulo4(_vm->_dungeonMan->_partyDir + ((cmdType == k2_CommandTurnRight) ? 1 : 3)));
 	_vm->_moveSens->processThingAdditionOrRemoval(_vm->_dungeonMan->_partyMapX, _vm->_dungeonMan->_partyMapY, Thing::_party, true, true);
 }
 
@@ -1007,8 +1007,8 @@ void EventManager::commandMoveParty(CommandType cmdType) {
 	if (_vm->_championMan->_partyChampionCount) {
 		if (isMovementBlocked) {
 			movementArrowIdx += (_vm->_dungeonMan->_partyDir + 2);
-			int16 L1124_i_FirstDamagedChampionIndex = _vm->_championMan->getTargetChampionIndex(partyMapX, partyMapY, normalizeModulo4(movementArrowIdx));
-			int16 L1125_i_SecondDamagedChampionIndex = _vm->_championMan->getTargetChampionIndex(partyMapX, partyMapY, returnNextVal(movementArrowIdx));
+			int16 L1124_i_FirstDamagedChampionIndex = _vm->_championMan->getTargetChampionIndex(partyMapX, partyMapY, _vm->normalizeModulo4(movementArrowIdx));
+			int16 L1125_i_SecondDamagedChampionIndex = _vm->_championMan->getTargetChampionIndex(partyMapX, partyMapY, _vm->returnNextVal(movementArrowIdx));
 			int16 damage = _vm->_championMan->addPendingDamageAndWounds_getDamage(L1124_i_FirstDamagedChampionIndex, 1, kDMWoundTorso | kDMWoundLegs, kDMAttackTypeSelf);
 			if (L1124_i_FirstDamagedChampionIndex != L1125_i_SecondDamagedChampionIndex)
 				damage |= _vm->_championMan->addPendingDamageAndWounds_getDamage(L1125_i_SecondDamagedChampionIndex, 1, kDMWoundTorso | kDMWoundLegs, kDMAttackTypeSelf);
@@ -1137,7 +1137,7 @@ void EventManager::commandProcessType80ClickInDungeonViewTouchFrontWall() {
 
 	if ((mapX >= 0) && (mapX < _vm->_dungeonMan->_currMapWidth)
 		&& (mapY >= 0) && (mapY < _vm->_dungeonMan->_currMapHeight))
-		_vm->_stopWaitingForPlayerInput = _vm->_moveSens->sensorIsTriggeredByClickOnWall(mapX, mapY, returnOppositeDir(_vm->_dungeonMan->_partyDir));
+		_vm->_stopWaitingForPlayerInput = _vm->_moveSens->sensorIsTriggeredByClickOnWall(mapX, mapY, _vm->returnOppositeDir(_vm->_dungeonMan->_partyDir));
 }
 
 void EventManager::commandProcessType80ClickInDungeonView(int16 posX, int16 posY) {
@@ -1350,7 +1350,7 @@ void EventManager::processType80_clickInDungeonView_grabLeaderHandObject(uint16
 		Thing groupThing = _vm->_groupMan->groupGetThing(mapX, mapY);
 		if ((groupThing != Thing::_endOfList) &&
 			!_vm->_moveSens->isLevitating(groupThing) &&
-			_vm->_groupMan->getCreatureOrdinalInCell((Group*)_vm->_dungeonMan->getThingData(groupThing), normalizeModulo4(viewCell + _vm->_dungeonMan->_partyDir))) {
+			_vm->_groupMan->getCreatureOrdinalInCell((Group*)_vm->_dungeonMan->getThingData(groupThing), _vm->normalizeModulo4(viewCell + _vm->_dungeonMan->_partyDir))) {
 			return; /* It is not possible to grab an object on floor if there is a non levitating creature on its cell */
 		}
 	}
@@ -1377,13 +1377,13 @@ void EventManager::processType80_clickInDungeonViewDropLeaderHandObject(uint16 v
 	if (viewCell > k1_ViewCellFrontRight)
 		mapX += _vm->_dirIntoStepCountEast[_vm->_dungeonMan->_partyDir], mapY += _vm->_dirIntoStepCountNorth[_vm->_dungeonMan->_partyDir];
 
-	uint16 currCell = normalizeModulo4(_vm->_dungeonMan->_partyDir + viewCell);
+	uint16 currCell = _vm->normalizeModulo4(_vm->_dungeonMan->_partyDir + viewCell);
 	Thing removedThing = _vm->_championMan->getObjectRemovedFromLeaderHand();
-	_vm->_moveSens->getMoveResult(thingWithNewCell(removedThing, currCell), kM1_MapXNotOnASquare, 0, mapX, mapY);
+	_vm->_moveSens->getMoveResult(_vm->thingWithNewCell(removedThing, currCell), kM1_MapXNotOnASquare, 0, mapX, mapY);
 	if (droppingIntoAnAlcove && _vm->_dungeonMan->_isFacingViAltar && (_vm->_objectMan->getIconIndex(removedThing) == kDMIconIndiceJunkChampionBones)) {
 		Junk *removedJunk = (Junk*)_vm->_dungeonMan->getThingData(removedThing);
 		TimelineEvent newEvent;
-		setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + 1);
+		_vm->setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + 1);
 		newEvent._type = k13_TMEventTypeViAltarRebirth;
 		newEvent._priority = removedJunk->getChargeCount();
 		newEvent._Bu._location._mapX = mapX;
@@ -1454,7 +1454,7 @@ void EventManager::mouseProcessCommands125To128_clickOnChampionIcon(uint16 champ
 
 	_preventBuildPointerScreenArea = true;
 	if (!_useChampionIconOrdinalAsMousePointerBitmap) {
-		if (_vm->_championMan->getIndexInCell(normalizeModulo4(champIconIndex + _vm->_dungeonMan->_partyDir)) == kDMChampionNone) {
+		if (_vm->_championMan->getIndexInCell(_vm->normalizeModulo4(champIconIndex + _vm->_dungeonMan->_partyDir)) == kDMChampionNone) {
 			_preventBuildPointerScreenArea = false;
 			return;
 		}
@@ -1474,20 +1474,20 @@ void EventManager::mouseProcessCommands125To128_clickOnChampionIcon(uint16 champ
 		_mousePointerBitmapUpdated = true;
 		uint16 championIconIndex = _vm->ordinalToIndex(_useChampionIconOrdinalAsMousePointerBitmap);
 		_useChampionIconOrdinalAsMousePointerBitmap = _vm->indexToOrdinal(kDMChampionNone);
-		int16 championCellIndex = _vm->_championMan->getIndexInCell(normalizeModulo4(championIconIndex + _vm->_dungeonMan->_partyDir));
+		int16 championCellIndex = _vm->_championMan->getIndexInCell(_vm->normalizeModulo4(championIconIndex + _vm->_dungeonMan->_partyDir));
 		if (championIconIndex == champIconIndex) {
 			setFlag(_vm->_championMan->_champions[championCellIndex]._attributes, kDMAttributeIcon);
 			_vm->_championMan->drawChampionState((ChampionIndex)championCellIndex);
 		} else {
-			int16 championIndex = _vm->_championMan->getIndexInCell(normalizeModulo4(champIconIndex + _vm->_dungeonMan->_partyDir));
+			int16 championIndex = _vm->_championMan->getIndexInCell(_vm->normalizeModulo4(champIconIndex + _vm->_dungeonMan->_partyDir));
 			if (championIndex >= 0) {
-				_vm->_championMan->_champions[championIndex]._cell = (ViewCell)normalizeModulo4(championIconIndex + _vm->_dungeonMan->_partyDir);
+				_vm->_championMan->_champions[championIndex]._cell = (ViewCell)_vm->normalizeModulo4(championIconIndex + _vm->_dungeonMan->_partyDir);
 				setFlag(_vm->_championMan->_champions[championIndex]._attributes, kDMAttributeIcon);
 				_vm->_championMan->drawChampionState((ChampionIndex)championIndex);
 			} else
 				_vm->_displayMan->fillScreenBox(_vm->_championMan->_boxChampionIcons[championIconIndex], k0_ColorBlack);
 
-			_vm->_championMan->_champions[championCellIndex]._cell = (ViewCell)normalizeModulo4(champIconIndex + _vm->_dungeonMan->_partyDir);
+			_vm->_championMan->_champions[championCellIndex]._cell = (ViewCell)_vm->normalizeModulo4(champIconIndex + _vm->_dungeonMan->_partyDir);
 			setFlag(_vm->_championMan->_champions[championCellIndex]._attributes, kDMAttributeIcon);
 			_vm->_championMan->drawChampionState((ChampionIndex)championCellIndex);
 		}
diff --git a/engines/dm/gfx.cpp b/engines/dm/gfx.cpp
index 4fcba5b..ab6a585 100644
--- a/engines/dm/gfx.cpp
+++ b/engines/dm/gfx.cpp
@@ -1249,7 +1249,7 @@ void DisplayMan::drawSquareD3L(Direction dir, int16 posX, int16 posY) {
 		drawObjectsCreaturesProjectilesExplosions(Thing(squareAspect[k1_FirstGroupOrObjectAspect]), dir, posX, posY, k1_ViewSquare_D3L, k0x0218_CellOrder_DoorPass1_BackLeft_BackRight);
 		drawWallSetBitmap(_bitmapWallSetDoorFrameLeftD3L, doorFrameLeftD3L);
 		drawDoor(squareAspect[k3_DoorThingIndexAspect], squareAspect[k2_DoorStateAspect],
-					  _doorNativeBitmapIndexFrontD3LCR, bitmapByteCount(48, 41), k0_ViewDoorOrnament_D3LCR, &doorFrameD3L);
+					  _doorNativeBitmapIndexFrontD3LCR, _vm->bitmapByteCount(48, 41), k0_ViewDoorOrnament_D3LCR, &doorFrameD3L);
 		order = k0x0349_CellOrder_DoorPass2_FrontLeft_FrontRight;
 		break;
 	case k2_ElementTypePit:
@@ -1333,7 +1333,7 @@ void DisplayMan::drawSquareD3R(Direction dir, int16 posX, int16 posY) {
 
 		drawDoor(squareAspect[k3_DoorThingIndexAspect],
 					  squareAspect[k2_DoorStateAspect], _doorNativeBitmapIndexFrontD3LCR,
-					  bitmapByteCount(48, 41), k0_ViewDoorOrnament_D3LCR, &doorFrameD3R);
+					  _vm->bitmapByteCount(48, 41), k0_ViewDoorOrnament_D3LCR, &doorFrameD3R);
 		break;;
 	case k2_ElementTypePit:
 		if (!squareAspect[k2_PitInvisibleAspect])
@@ -1410,7 +1410,7 @@ void DisplayMan::drawSquareD3C(Direction dir, int16 posX, int16 posY) {
 			drawDoorButton(_vm->indexToOrdinal(k0_DoorButton), k1_ViewDoorOrnament_D2LCR);
 
 		drawDoor(squareAspect[k3_DoorThingIndexAspect], squareAspect[k2_DoorStateAspect],
-					  _doorNativeBitmapIndexFrontD3LCR, bitmapByteCount(48, 41), k0_ViewDoorOrnament_D3LCR, &doorFrameD3C);
+					  _doorNativeBitmapIndexFrontD3LCR, _vm->bitmapByteCount(48, 41), k0_ViewDoorOrnament_D3LCR, &doorFrameD3C);
 		order = k0x0349_CellOrder_DoorPass2_FrontLeft_FrontRight;
 		break;
 	case k2_ElementTypePit:
@@ -1490,7 +1490,7 @@ void DisplayMan::drawSquareD2L(Direction dir, int16 posX, int16 posY) {
 		drawObjectsCreaturesProjectilesExplosions(Thing(squareAspect[k1_FirstGroupOrObjectAspect]), dir, posX, posY, k4_ViewSquare_D2L, k0x0218_CellOrder_DoorPass1_BackLeft_BackRight);
 		drawWallSetBitmap(_bitmapWallSetDoorFrameTopD2LCR, doorFrameTopD2L);
 		drawDoor(squareAspect[k3_DoorThingIndexAspect], squareAspect[k2_DoorStateAspect], _doorNativeBitmapIndexFrontD2LCR,
-					  bitmapByteCount(64, 61), k1_ViewDoorOrnament_D2LCR, &doorFrameD2L);
+					  _vm->bitmapByteCount(64, 61), k1_ViewDoorOrnament_D2LCR, &doorFrameD2L);
 		order = k0x0349_CellOrder_DoorPass2_FrontLeft_FrontRight;
 		break;
 	case k2_ElementTypePit:
@@ -1577,7 +1577,7 @@ void DisplayMan::drawSquareD2R(Direction dir, int16 posX, int16 posY) {
 		drawObjectsCreaturesProjectilesExplosions(Thing(squareAspect[k1_FirstGroupOrObjectAspect]), dir, posX, posY, k5_ViewSquare_D2R, k0x0128_CellOrder_DoorPass1_BackRight_BackLeft);
 		drawWallSetBitmap(_bitmapWallSetDoorFrameTopD2LCR, doorFrameTopD2R);
 		drawDoor(squareAspect[k3_DoorThingIndexAspect], squareAspect[k2_DoorStateAspect],
-					  _doorNativeBitmapIndexFrontD2LCR, bitmapByteCount(64, 61), k1_ViewDoorOrnament_D2LCR, &doorFrameD2R);
+					  _doorNativeBitmapIndexFrontD2LCR, _vm->bitmapByteCount(64, 61), k1_ViewDoorOrnament_D2LCR, &doorFrameD2R);
 		order = k0x0439_CellOrder_DoorPass2_FrontRight_FrontLeft;
 		break;
 	case k2_ElementTypePit:
@@ -1660,7 +1660,7 @@ void DisplayMan::drawSquareD2C(Direction dir, int16 posX, int16 posY) {
 			drawDoorButton(_vm->indexToOrdinal(k0_DoorButton), k2_viewDoorButton_D2C);
 
 		drawDoor(squareAspect[k3_DoorThingIndexAspect], squareAspect[k2_DoorStateAspect],
-					  _doorNativeBitmapIndexFrontD2LCR, bitmapByteCount(64, 61), k1_ViewDoorOrnament_D2LCR, &doorFrameD2C);
+					  _doorNativeBitmapIndexFrontD2LCR, _vm->bitmapByteCount(64, 61), k1_ViewDoorOrnament_D2LCR, &doorFrameD2C);
 		order = k0x0349_CellOrder_DoorPass2_FrontLeft_FrontRight;
 		break;
 	case k2_ElementTypePit:
@@ -1745,7 +1745,7 @@ void DisplayMan::drawSquareD1L(Direction dir, int16 posX, int16 posY) {
 		drawObjectsCreaturesProjectilesExplosions(Thing(squareAspect[k1_FirstGroupOrObjectAspect]), dir, posX, posY, k7_ViewSquare_D1L, k0x0028_CellOrder_DoorPass1_BackRight);
 		drawWallSetBitmap(_bitmapWallSetDoorFrameTopD1LCR, doorFrameTopD1L);
 		drawDoor(squareAspect[k3_DoorThingIndexAspect], squareAspect[k2_DoorStateAspect],
-					  _doorNativeBitmapIndexFrontD1LCR, bitmapByteCount(96, 88), k2_ViewDoorOrnament_D1LCR, &doorFrameD1L);
+					  _doorNativeBitmapIndexFrontD1LCR, _vm->bitmapByteCount(96, 88), k2_ViewDoorOrnament_D1LCR, &doorFrameD1L);
 		order = k0x0039_CellOrder_DoorPass2_FrontRight;
 		break;
 	case k2_ElementTypePit:
@@ -1829,7 +1829,7 @@ void DisplayMan::drawSquareD1R(Direction dir, int16 posX, int16 posY) {
 		drawObjectsCreaturesProjectilesExplosions(Thing(squareAspect[k1_FirstGroupOrObjectAspect]), dir, posX, posY, k8_ViewSquare_D1R, k0x0018_CellOrder_DoorPass1_BackLeft);
 		drawWallSetBitmap(_bitmapWallSetDoorFrameTopD1LCR, doorFrameTopD1R);
 		drawDoor(squareAspect[k3_DoorThingIndexAspect], squareAspect[k2_DoorStateAspect],
-					  _doorNativeBitmapIndexFrontD1LCR, bitmapByteCount(96, 88), k2_ViewDoorOrnament_D1LCR, &doorFrameD1R);
+					  _doorNativeBitmapIndexFrontD1LCR, _vm->bitmapByteCount(96, 88), k2_ViewDoorOrnament_D1LCR, &doorFrameD1R);
 		order = k0x0049_CellOrder_DoorPass2_FrontLeft;
 		break;
 	case k2_ElementTypePit:
@@ -1914,7 +1914,7 @@ void DisplayMan::drawSquareD1C(Direction dir, int16 posX, int16 posY) {
 			drawDoorButton(_vm->indexToOrdinal(k0_DoorButton), k3_viewDoorButton_D1C);
 
 		drawDoor(squareAspect[k3_DoorThingIndexAspect], squareAspect[k2_DoorStateAspect],
-					  _doorNativeBitmapIndexFrontD1LCR, bitmapByteCount(96, 88), k2_ViewDoorOrnament_D1LCR, _doorFrameD1C);
+					  _doorNativeBitmapIndexFrontD1LCR, _vm->bitmapByteCount(96, 88), k2_ViewDoorOrnament_D1LCR, _doorFrameD1C);
 		order = k0x0349_CellOrder_DoorPass2_FrontLeft_FrontRight;
 		break;
 	case k2_ElementTypePit:
@@ -3075,14 +3075,14 @@ void DisplayMan::drawObjectsCreaturesProjectilesExplosions(Thing thingParam, Dir
 		/* Draw objects */
 		if (L0135_B_DrawAlcoveObjects) {
 			AL_2_viewCell = k4_ViewCellAlcove; /* Index of coordinates to draw objects in alcoves */
-			cellYellowBear = returnOppositeDir(directionParam); /* Alcove is on the opposite direction of the viewing direction */
+			cellYellowBear = _vm->returnOppositeDir(directionParam); /* Alcove is on the opposite direction of the viewing direction */
 			objectShiftIndex = 2;
 		} else {
 			AL_2_viewCell = _vm->ordinalToIndex((int16)remainingViewCellOrdinalsToProcess & 0x000F); /* View cell is the index of coordinates to draw object */
 			currentViewCellToDraw = AL_2_viewCell;
 			remainingViewCellOrdinalsToProcess >>= 4; /* Proceed to the next cell ordinal */
 			cellCounter++;
-			cellYellowBear = normalizeModulo4(AL_2_viewCell + directionParam); /* Convert view cell to absolute cell */
+			cellYellowBear = _vm->normalizeModulo4(AL_2_viewCell + directionParam); /* Convert view cell to absolute cell */
 			thingParam = firstThingToDraw;
 			viewSquareIndex = AL_10_viewSquareIndexBackup; /* Restore value as it may have been modified while drawing a creature */
 			objectShiftIndex = 0;
@@ -3248,7 +3248,7 @@ T0115015_DrawProjectileAsObject:
 		} else
 			goto T0115129_DrawProjectiles; /* No creature to draw at cell, skip to projectiles */
 
-		creatureDirectionDelta = normalizeModulo4(directionParam - _vm->_groupMan->getCreatureValue(activeGroup->_directions, AL_0_creatureIndexRed));
+		creatureDirectionDelta = _vm->normalizeModulo4(directionParam - _vm->_groupMan->getCreatureValue(activeGroup->_directions, AL_0_creatureIndexRed));
 		twoHalfSquareCreaturesFrontView = false;
 		if ((AL_4_groupCells = activeGroup->_cells) == k255_CreatureTypeSingleCenteredCreature) { /* If there is a single centered creature in the group */
 			if (remainingViewCellOrdinalsToProcess || (doorFrontViewDrawingPass == 1))
@@ -3277,7 +3277,7 @@ T0115015_DrawProjectileAsObject:
 						creatureIndexGreen = 0;
 
 					twoHalfSquareCreaturesFrontView = group->getCount();
-					if (((AL_4_groupCells = _vm->_groupMan->getCreatureValue(AL_4_groupCells, AL_0_creatureIndexRed)) == directionParam) || (AL_4_groupCells == returnPrevVal(directionParam)))
+					if (((AL_4_groupCells = _vm->_groupMan->getCreatureValue(AL_4_groupCells, AL_0_creatureIndexRed)) == directionParam) || (AL_4_groupCells == _vm->returnPrevVal(directionParam)))
 						AL_2_viewCell = k0_HalfSizedViewCell_LeftColumn;
 					else
 						AL_2_viewCell = k1_HalfSizedViewCell_RightColumn;
@@ -3507,7 +3507,7 @@ T0115129_DrawProjectiles:
 					if (projectileAspectType == k3_ProjectileAspectHasNone) {
 						projectileBitmapIndexDelta = 0;
 						flipVertical = flipHorizontal = false;
-					} else if (isOrientedWestEast(Direction(projectileDirection = _vm->_timeline->_events[projectile->_eventIndex]._Cu._projectile.getDir())) != isOrientedWestEast(directionParam)) {
+					} else if (_vm->isOrientedWestEast(Direction(projectileDirection = _vm->_timeline->_events[projectile->_eventIndex]._Cu._projectile.getDir())) != _vm->isOrientedWestEast(directionParam)) {
 						if (projectileAspectType == k2_ProjectileAspectHasRotation)
 							projectileBitmapIndexDelta = 1;
 						else
@@ -3519,7 +3519,7 @@ T0115129_DrawProjectiles:
 								flipHorizontal = !flipHorizontal;
 						} else {
 							flipVertical = false;
-							flipHorizontal = (returnNextVal(directionParam) == projectileDirection);
+							flipHorizontal = (_vm->returnNextVal(directionParam) == projectileDirection);
 						}
 					} else {
 						if ((projectileAspectType >= k2_ProjectileAspectHasRotation) || ((projectileAspectType == k1_ProjectileAspectBackGraphic) && (projectileDirection != directionParam)) || (projectileAspectTypeHasBackGraphicAndRotation && projectileFlipVertical)) /* If the projectile does not have a back graphic or has one but is not seen from the back or if it has a back graphic and rotation and should be flipped vertically */
@@ -3675,7 +3675,7 @@ T0115171_BackFromT0115015_DrawProjectileAsObject:;
 					if (explosion->getCentered()) {
 						explosionCoordinates = centeredExplosionCoordinates[AL_1_viewSquareExplosionIndex];
 					} else {
-						if ((AL_2_cellPurpleMan == directionParam) || (AL_2_cellPurpleMan == returnPrevVal(directionParam)))
+						if ((AL_2_cellPurpleMan == directionParam) || (AL_2_cellPurpleMan == _vm->returnPrevVal(directionParam)))
 							AL_2_viewCell = k0_ViewCellFronLeft;
 						else
 							AL_2_viewCell = k1_ViewCellFrontRight;
diff --git a/engines/dm/group.cpp b/engines/dm/group.cpp
index e4c720f..6df3857 100644
--- a/engines/dm/group.cpp
+++ b/engines/dm/group.cpp
@@ -108,11 +108,11 @@ int16 GroupMan::getCreatureOrdinalInCell(Group *group, uint16 cell) {
 	byte creatureIndex = group->getCount();
 	if (getFlag(_vm->_dungeonMan->_creatureInfos[group->_type]._attributes, k0x0003_MaskCreatureInfo_size) == k1_MaskCreatureSizeHalf) {
 		if ((getGroupDirections(group, currMapIndex) & 1) == (cell & 1))
-			cell = returnPrevVal(cell);
+			cell = _vm->returnPrevVal(cell);
 
 		do {
 			byte creatureCell = getCreatureValue(groupCells, creatureIndex);
-			if (creatureCell == cell || creatureCell == returnNextVal(cell)) {
+			if (creatureCell == cell || creatureCell == _vm->returnNextVal(cell)) {
 				retval = _vm->indexToOrdinal(creatureIndex);
 				break;
 			}
@@ -151,7 +151,7 @@ void GroupMan::dropGroupPossessions(int16 mapX, int16 mapY, Thing groupThing, in
 		Thing nextThing;
 		do {
 			nextThing = _vm->_dungeonMan->getNextThing(currentThing);
-			currentThing = thingWithNewCell(currentThing, _vm->getRandomNumber(4));
+			currentThing = _vm->thingWithNewCell(currentThing, _vm->getRandomNumber(4));
 			if ((currentThing).getType() == kDMThingTypeWeapon) {
 				L0371_B_WeaponDropped = true;
 			}
@@ -283,7 +283,7 @@ void GroupMan::dropCreatureFixedPossessions(uint16 creatureType, int16 mapX, int
 		/* The same pointer type is used no matter the actual type k5_WeaponThingType, k6_ArmourThingType or k10_JunkThingType */
 		currWeapon->setType(currFixedPossession);
 		currWeapon->setCursed(cursedPossessions);
-		nextUnusedThing = thingWithNewCell(nextUnusedThing, ((cell == k255_CreatureTypeSingleCenteredCreature) || !_vm->getRandomNumber(4)) ? _vm->getRandomNumber(4) : cell);
+		nextUnusedThing = _vm->thingWithNewCell(nextUnusedThing, ((cell == k255_CreatureTypeSingleCenteredCreature) || !_vm->getRandomNumber(4)) ? _vm->getRandomNumber(4) : cell);
 		_vm->_moveSens->getMoveResult(nextUnusedThing, kM1_MapXNotOnASquare, 0, mapX, mapY);
 		currFixedPossession = *fixedPossessions++;
 	}
@@ -309,11 +309,11 @@ int16 GroupMan::getDirsWhereDestIsVisibleFromSource(int16 srcMapX, int16 srcMapY
 	int16 curDirection = kDMDirNorth;
 	for (;;) {
 		if (isDestVisibleFromSource(curDirection, srcMapX, srcMapY, destMapX, destMapY)) {
-			_vm->_projexpl->_secondaryDirToOrFromParty = returnNextVal(curDirection);
+			_vm->_projexpl->_secondaryDirToOrFromParty = _vm->returnNextVal(curDirection);
 			if (!isDestVisibleFromSource(_vm->_projexpl->_secondaryDirToOrFromParty, srcMapX, srcMapY, destMapX, destMapY)) {
-				_vm->_projexpl->_secondaryDirToOrFromParty = returnPrevVal(curDirection);
+				_vm->_projexpl->_secondaryDirToOrFromParty = _vm->returnPrevVal(curDirection);
 				if ((curDirection != kDMDirNorth) || !isDestVisibleFromSource(_vm->_projexpl->_secondaryDirToOrFromParty, srcMapX, srcMapY, destMapX, destMapY)) {
-					_vm->_projexpl->_secondaryDirToOrFromParty = returnNextVal((_vm->getRandomNumber(65536) & 0x0002) + curDirection);
+					_vm->_projexpl->_secondaryDirToOrFromParty = _vm->returnNextVal((_vm->getRandomNumber(65536) & 0x0002) + curDirection);
 					return curDirection;
 				}
 			}
@@ -356,7 +356,7 @@ bool GroupMan::groupIsDoorDestoryedByAttack(uint16 mapX, uint16 mapY, int16 atta
 		if (Square(*curSquare).getDoorState() == k4_doorState_CLOSED) {
 			if (ticks) {
 				TimelineEvent newEvent;
-				setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_currMapIndex, _vm->_gameTime + ticks);
+				_vm->setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_currMapIndex, _vm->_gameTime + ticks);
 				newEvent._type = k2_TMEventTypeDoorDestruction;
 				newEvent._priority = 0;
 				newEvent._Bu._location._mapX = mapX;
@@ -414,7 +414,7 @@ int16 GroupMan::groupGetDamageCreatureOutcome(Group *group, uint16 creatureIndex
 				TimelineEvent *curEvent = _vm->_timeline->_events;
 				for (uint16 eventIndex = 0; eventIndex < _vm->_timeline->_eventMaxCount; eventIndex++) {
 					uint16 curEventType = curEvent->_type;
-					if ((getMap(curEvent->_mapTime) == _vm->_dungeonMan->_currMapIndex) &&
+					if ((_vm->getMap(curEvent->_mapTime) == _vm->_dungeonMan->_currMapIndex) &&
 						(curEvent->_Bu._location._mapX == mapX) &&
 						(curEvent->_Bu._location._mapY == mapY) &&
 						(curEventType > k32_TMEventTypeUpdateAspectGroup) &&
@@ -500,7 +500,7 @@ void GroupMan::groupDeleteEvents(int16 mapX, int16 mapY) {
 	TimelineEvent *curEvent = _vm->_timeline->_events;
 	for (int16 eventIndex = 0; eventIndex < _vm->_timeline->_eventMaxCount; eventIndex++) {
 		uint16 curEventType = curEvent->_type;
-		if ((getMap(curEvent->_mapTime) == _vm->_dungeonMan->_currMapIndex) &&
+		if ((_vm->getMap(curEvent->_mapTime) == _vm->_dungeonMan->_currMapIndex) &&
 			(curEventType > k29_TMEventTypeGroupReactionDangerOnSquare - 1) && (curEventType < k41_TMEventTypeUpdateBehaviour_3 + 1) &&
 			(curEvent->_Bu._location._mapX == mapX) && (curEvent->_Bu._location._mapY == mapY)) {
 			_vm->_timeline->deleteEvent(eventIndex);
@@ -588,7 +588,7 @@ void GroupMan::processEvents29to41(int16 eventMapX, int16 eventMapY, int16 event
 	CreatureInfo creatureInfo = _vm->_dungeonMan->_creatureInfos[curGroup->_type];
 	/* Update the event */
 	TimelineEvent nextEvent;
-	setMapAndTime(nextEvent._mapTime, _vm->_dungeonMan->_currMapIndex, _vm->_gameTime);
+	_vm->setMapAndTime(nextEvent._mapTime, _vm->_dungeonMan->_currMapIndex, _vm->_gameTime);
 	nextEvent._priority = 255 - creatureInfo._movementTicks; /* The fastest creatures (with small MovementTicks value) get higher event priority */
 	nextEvent._Bu._location._mapX = eventMapX;
 	nextEvent._Bu._location._mapY = eventMapY;
@@ -705,7 +705,7 @@ T0209005_AddEventAndReturn:
 		nextEvent._type = eventType + 5;
 		if (groupGetDistanceToVisibleParty(curGroup, kM1_wholeCreatureGroup, eventMapX, eventMapY)) {
 			if ((AL0447_i_Behavior != k6_behavior_ATTACK) && (AL0447_i_Behavior != k5_behavior_FLEE)) {
-				if (getDistance(_vm->_dungeonMan->_partyMapX, _vm->_dungeonMan->_partyMapY, eventMapX, eventMapY) <= 1)
+				if (_vm->getDistance(_vm->_dungeonMan->_partyMapX, _vm->_dungeonMan->_partyMapY, eventMapX, eventMapY) <= 1)
 					goto T0209044_SetBehavior6_Attack;
 				if (((AL0447_i_Behavior == k0_behavior_WANDER) || (AL0447_i_Behavior == k3_behavior_USELESS)) && (AL0447_i_Behavior != k7_behavior_APPROACH)) /* BUG0_00 Useless code. Behavior cannot be 3 because this value is never used. Moreover, the second condition in the && is redundant (if the value is 0 or 3, it cannot be 7). The actual condition is: if (AL0447_i_Behavior == k0_behavior_WANDER) */
 					goto T0209054_SetBehavior7_Approach;
@@ -813,14 +813,14 @@ T0209061_MoveGroup:
 									activeGroup->_targetMapX = _vm->_dungeonMan->_partyMapX;
 									activeGroup->_targetMapY = _vm->_dungeonMan->_partyMapY;
 								}
-								AL0446_i_Direction = returnNextVal(AL0446_i_Direction);
+								AL0446_i_Direction = _vm->returnNextVal(AL0446_i_Direction);
 							} while (AL0446_i_Direction != AL0447_i_ReferenceDirection);
 						}
 						if (!newGroupDirectionFound &&
 							(ticksSinceLastMove != -1) &&
 							isArchEnemy &&
 							((eventType == kM3_TMEventTypeCreateReactionEvent29DangerOnSquare) || !_vm->getRandomNumber(4))) { /* BUG0_15 The game hangs when you close a door on Lord Chaos. A condition is missing in the code to manage creatures and this may create an infinite loop between two parts in the code */
-							_vm->_projexpl->_secondaryDirToOrFromParty = returnNextVal(primaryDirectionToOrFromParty = _vm->getRandomNumber(4));
+							_vm->_projexpl->_secondaryDirToOrFromParty = _vm->returnNextVal(primaryDirectionToOrFromParty = _vm->getRandomNumber(4));
 							goto T0209089_DoubleSquareMove; /* BUG0_69 Memory corruption when you close a door on Lord Chaos. The local variable (L0454_i_PrimaryDirectionToOrFromParty) containing the direction where Lord Chaos tries to move may be used as an array index without being initialized and cause memory corruption */
 						}
 						if (newGroupDirectionFound || ((!_vm->getRandomNumber(4) || (distanceToVisibleParty <= creatureInfo.getSmellRange())) && (eventType != kM3_TMEventTypeCreateReactionEvent29DangerOnSquare))) {
@@ -869,8 +869,8 @@ T0209084_SingleSquareMoveTowardParty:
 T0209085_SingleSquareMove:
 					if (isMovementPossible(&creatureInfo, eventMapX, eventMapY, AL0446_i_Direction = primaryDirectionToOrFromParty, allowMovementOverFakePitsAndFakeWalls) ||
 						isMovementPossible(&creatureInfo, eventMapX, eventMapY, AL0446_i_Direction = _vm->_projexpl->_secondaryDirToOrFromParty, allowMovementOverFakePitsAndFakeWalls && _vm->getRandomNumber(2)) ||
-						isMovementPossible(&creatureInfo, eventMapX, eventMapY, AL0446_i_Direction = returnOppositeDir((Direction)AL0446_i_Direction), false) ||
-						(!_vm->getRandomNumber(4) && isMovementPossible(&creatureInfo, eventMapX, eventMapY, AL0446_i_Direction = returnOppositeDir((Direction)primaryDirectionToOrFromParty), false))) {
+						isMovementPossible(&creatureInfo, eventMapX, eventMapY, AL0446_i_Direction = _vm->returnOppositeDir((Direction)AL0446_i_Direction), false) ||
+						(!_vm->getRandomNumber(4) && isMovementPossible(&creatureInfo, eventMapX, eventMapY, AL0446_i_Direction = _vm->returnOppositeDir((Direction)primaryDirectionToOrFromParty), false))) {
 						AL0450_i_DestinationMapX = eventMapX;
 						AL0451_i_DestinationMapY = eventMapY;
 						AL0450_i_DestinationMapX += _vm->_dirIntoStepCountEast[AL0446_i_Direction], AL0451_i_DestinationMapY += _vm->_dirIntoStepCountNorth[AL0446_i_Direction];
@@ -881,8 +881,8 @@ T0209089_DoubleSquareMove:
 						getFirstPossibleMovementDirOrdinal(&creatureInfo, eventMapX, eventMapY, false); /* BUG0_00 Useless code. Returned value is ignored. When Lord Chaos teleports two squares away the ability to move to the first square is ignored which means Lord Chaos can teleport through walls or any other obstacle */
 						if (isArchenemyDoubleMovementPossible(&creatureInfo, eventMapX, eventMapY, AL0446_i_Direction = primaryDirectionToOrFromParty) ||
 							isArchenemyDoubleMovementPossible(&creatureInfo, eventMapX, eventMapY, AL0446_i_Direction = _vm->_projexpl->_secondaryDirToOrFromParty) ||
-							(_fluxCageCount && isArchenemyDoubleMovementPossible(&creatureInfo, eventMapX, eventMapY, AL0446_i_Direction = returnOppositeDir((Direction)AL0446_i_Direction))) ||
-							((_fluxCageCount >= 2) && isArchenemyDoubleMovementPossible(&creatureInfo, eventMapX, eventMapY, AL0446_i_Direction = returnOppositeDir((Direction)primaryDirectionToOrFromParty)))) {
+							(_fluxCageCount && isArchenemyDoubleMovementPossible(&creatureInfo, eventMapX, eventMapY, AL0446_i_Direction = _vm->returnOppositeDir((Direction)AL0446_i_Direction))) ||
+							((_fluxCageCount >= 2) && isArchenemyDoubleMovementPossible(&creatureInfo, eventMapX, eventMapY, AL0446_i_Direction = _vm->returnOppositeDir((Direction)primaryDirectionToOrFromParty)))) {
 							AL0450_i_DestinationMapX = eventMapX;
 							AL0451_i_DestinationMapY = eventMapY;
 							AL0450_i_DestinationMapX += _vm->_dirIntoStepCountEast[AL0446_i_Direction] * 2, AL0451_i_DestinationMapY += _vm->_dirIntoStepCountNorth[AL0446_i_Direction] * 2;
@@ -910,7 +910,7 @@ T0209096_SetBehavior0_Wander:
 							if (_vm->getRandomNumber(2)) {
 								/* If the creature cannot move and the party is adjacent then stop fleeing */
 								if (!getFirstPossibleMovementDirOrdinal(&creatureInfo, eventMapX, eventMapY, false)) {
-									if (getDistance(eventMapX, eventMapY, _vm->_dungeonMan->_partyMapX, _vm->_dungeonMan->_partyMapY) <= 1)
+									if (_vm->getDistance(eventMapX, eventMapY, _vm->_dungeonMan->_partyMapX, _vm->_dungeonMan->_partyMapY) <= 1)
 										goto T0209096_SetBehavior0_Wander;
 								}
 								/* Set creature target to the home square where the creature was located when the party entered the map */
@@ -922,8 +922,8 @@ T0209096_SetBehavior0_Wander:
 							AL0451_i_TargetMapY = activeGroup->_targetMapY;
 						}
 						/* Try and flee from the party (opposite direction) */
-						primaryDirectionToOrFromParty = returnOppositeDir((Direction)getDirsWhereDestIsVisibleFromSource(eventMapX, eventMapY, AL0450_i_TargetMapX, AL0451_i_TargetMapY));
-						_vm->_projexpl->_secondaryDirToOrFromParty = returnOppositeDir((Direction)_vm->_projexpl->_secondaryDirToOrFromParty);
+						primaryDirectionToOrFromParty = _vm->returnOppositeDir((Direction)getDirsWhereDestIsVisibleFromSource(eventMapX, eventMapY, AL0450_i_TargetMapX, AL0451_i_TargetMapY));
+						_vm->_projexpl->_secondaryDirToOrFromParty = _vm->returnOppositeDir((Direction)_vm->_projexpl->_secondaryDirToOrFromParty);
 						movementTicks -= (movementTicks >> 2);
 						goto T0209085_SingleSquareMove;
 					}
@@ -957,17 +957,16 @@ T0209096_SetBehavior0_Wander:
 				if (!creatureCount && (creatureSize != k2_MaskCreatureSizeFull) && !((AL0446_i_GroupCellsCriteria = _vm->getRandomNumber(65536)) & 0x00C0)) {
 					if (activeGroup->_cells != k255_CreatureTypeSingleCenteredCreature) {
 						/* If the creature is not already on the center of the square then change its cell */
-						if (AL0446_i_GroupCellsCriteria & 0x0038) { /* 7/8 chances of changing cell to the center of the square */
+						if (AL0446_i_GroupCellsCriteria & 0x0038) /* 7/8 chances of changing cell to the center of the square */
 							activeGroup->_cells = k255_CreatureTypeSingleCenteredCreature;
-						} else { /* 1/8 chance of changing cell to the next or previous cell on the square */
-							AL0446_i_GroupCellsCriteria = normalizeModulo4(normalizeModulo4(activeGroup->_cells) + ((AL0446_i_GroupCellsCriteria & 0x0001) ? 1 : -1));
-						}
+						else /* 1/8 chance of changing cell to the next or previous cell on the square */
+							AL0446_i_GroupCellsCriteria = _vm->normalizeModulo4(_vm->normalizeModulo4(activeGroup->_cells) + ((AL0446_i_GroupCellsCriteria & 0x0001) ? 1 : -1));
 					}
 					/* If 1/8 chance and the creature is not adjacent to the party and is a quarter square sized creature then process projectile impacts and update the creature cell if still alive. When the creature is not in front of the party, it has 7/8 chances of dodging a projectile by moving to another cell or staying in the center of the square */
 					if (!(AL0446_i_GroupCellsCriteria & 0x0038) && (distanceToVisibleParty != 1) && (creatureSize == k0_MaskCreatureSizeQuarter)) {
 						if (_vm->_projexpl->projectileGetImpactCount(kM1_CreatureElemType, eventMapX, eventMapY, activeGroup->_cells) && (_vm->_projexpl->_creatureDamageOutcome == k2_outcomeKilledAllCreaturesInGroup)) /* This call to F0218_PROJECTILE_GetImpactCount works fine because there is a single creature in the group so L0445_ps_ActiveGroup->Cells contains only one cell index */
 							return;
-						activeGroup->_cells = normalizeModulo4(AL0446_i_GroupCellsCriteria);
+						activeGroup->_cells = _vm->normalizeModulo4(AL0446_i_GroupCellsCriteria);
 					}
 				}
 				/* If the creature can see the party and is looking in the party direction or can attack in all direction */
@@ -983,17 +982,18 @@ T0209096_SetBehavior0_Wander:
 							(creatureSize == k0_MaskCreatureSizeQuarter) &&
 							(activeGroup->_cells != k255_CreatureTypeSingleCenteredCreature) &&
 							((AL0446_i_Cell = getCreatureValue(activeGroup->_cells, AL0447_i_CreatureIndex)) != primaryDirectionToOrFromParty) &&
-							(AL0446_i_Cell != returnNextVal(primaryDirectionToOrFromParty))) { /* If the creature cannot cast spells (range = 1) and is not on a cell where it can attack the party directly and is a quarter square sized creature not in the center of the square then the creature moves to another cell and attack does not occur immediately */
+							(AL0446_i_Cell != _vm->returnNextVal(primaryDirectionToOrFromParty))) { /* If the creature cannot cast spells (range = 1) and is not on a cell where it can attack the party directly and is a quarter square sized creature not in the center of the square then the creature moves to another cell and attack does not occur immediately */
 							if (!creatureCount && _vm->getRandomNumber(2)) {
 								activeGroup->_cells = k255_CreatureTypeSingleCenteredCreature;
 							} else {
-								if ((primaryDirectionToOrFromParty & 0x0001) == (AL0446_i_Cell & 0x0001)) {
+								if ((primaryDirectionToOrFromParty & 0x0001) == (AL0446_i_Cell & 0x0001))
 									AL0446_i_Cell--;
-								} else {
+								else
 									AL0446_i_Cell++;
-								}
-								if (!getCreatureOrdinalInCell(curGroup, AL0446_i_Cell = normalizeModulo4(AL0446_i_Cell)) ||
-									(_vm->getRandomNumber(2) && !getCreatureOrdinalInCell(curGroup, AL0446_i_Cell = returnOppositeDir((Direction)AL0446_i_Cell)))) { /* If the selected cell (or the opposite cell) is not already occupied by a creature */
+
+								AL0446_i_Cell = _vm->normalizeModulo4(AL0446_i_Cell);
+								if (!getCreatureOrdinalInCell(curGroup, AL0446_i_Cell) ||
+									(_vm->getRandomNumber(2) && !getCreatureOrdinalInCell(curGroup, AL0446_i_Cell = _vm->returnOppositeDir((Direction)AL0446_i_Cell)))) { /* If the selected cell (or the opposite cell) is not already occupied by a creature */
 									if (_vm->_projexpl->projectileGetImpactCount(kM1_CreatureElemType, eventMapX, eventMapY, activeGroup->_cells) && (_vm->_projexpl->_creatureDamageOutcome == k2_outcomeKilledAllCreaturesInGroup)) /* BUG0_70 A projectile impact on a creature may be ignored. The function F0218_PROJECTILE_GetImpactCount to detect projectile impacts when a quarter square sized creature moves inside a group (to another cell on the same square) may fail if there are several creatures in the group because the function expects a single cell index for its last parameter. The function should be called once for each cell where there is a creature */
 										return;
 									if (_vm->_projexpl->_creatureDamageOutcome != k1_outcomeKilledSomeCreaturesInGroup) {
@@ -1021,7 +1021,7 @@ T0209096_SetBehavior0_Wander:
 						activeGroup->_targetMapY = _vm->_dungeonMan->_partyMapY;
 						setGroupDirection(activeGroup, primaryDirectionToOrFromParty, AL0447_i_CreatureIndex, creatureCount && (creatureSize == k1_MaskCreatureSizeHalf));
 						nextEvent._mapTime += 2;
-						nextAspectUpdateTime = filterTime(nextEvent._mapTime);
+						nextAspectUpdateTime = _vm->filterTime(nextEvent._mapTime);
 					} else { /* If the party is not visible, move to the target (last known party location) */
 						curGroup->setBehaviour(k7_behavior_APPROACH);
 						if (creatureCount) {
@@ -1134,7 +1134,7 @@ int16 GroupMan::groupGetDistanceToVisibleParty(Group *group, int16 creatureIndex
 		if (creatureIndex < 0) { /* Negative index means test if each creature in the group can see the party in their respective direction */
 			checkDirectionsCount = 0;
 			for (creatureIndex = group->getCount(); creatureIndex >= 0; creatureIndex--) {
-				int16 creatureDirection = normalizeModulo4(groupDirections >> (creatureIndex << 1));
+				int16 creatureDirection = _vm->normalizeModulo4(groupDirections >> (creatureIndex << 1));
 				int16 counter = checkDirectionsCount;
 				bool skipSet = false;
 				while (counter--) {
@@ -1170,9 +1170,8 @@ int16 GroupMan::groupGetDistanceToVisibleParty(Group *group, int16 creatureIndex
 int16 GroupMan::getDistanceBetweenUnblockedSquares(int16 srcMapX, int16 srcMapY,
 													int16 destMapX, int16 destMapY, bool (GroupMan::*isBlocked)(uint16, uint16)) {
 
-	if (getDistance(srcMapX, srcMapY, destMapX, destMapY) <= 1) {
+	if (_vm->getDistance(srcMapX, srcMapY, destMapX, destMapY) <= 1)
 		return 1;
-	}
 
 	int16 distanceX = ABS(destMapX - srcMapX);
 	int16 distanceY = ABS(destMapY - srcMapY);
@@ -1224,7 +1223,7 @@ int16 GroupMan::getDistanceBetweenUnblockedSquares(int16 srcMapX, int16 srcMapY,
 					return 0;
 			}
 		}
-	} while (getDistance(pathMapX, pathMapY, srcMapX, srcMapY) > 1);
+	} while (_vm->getDistance(pathMapX, pathMapY, srcMapX, srcMapY) > 1);
 	return getDistanceBetweenSquares(srcMapX, srcMapY, destMapX, destMapY);
 }
 
@@ -1271,7 +1270,7 @@ int32 GroupMan::getCreatureAspectUpdateTime(ActiveGroup *activeGroup, int16 crea
 			if (getFlag(creatureGraphicInfo, k0x0200_CreatureInfoGraphicMaskFlipAttack)) {
 				if (getFlag(aspect, k0x0080_MaskActiveGroupIsAttacking) && (creatureType == k18_CreatureTypeAnimatedArmourDethKnight)) {
 					if (_vm->getRandomNumber(2)) {
-						toggleFlag(aspect, k0x0040_MaskActiveGroupFlipBitmap);
+						_vm->toggleFlag(aspect, k0x0040_MaskActiveGroupFlipBitmap);
 						_vm->_sound->requestPlay(k16_soundCOMBAT_ATTACK_SKELETON_ANIMATED_ARMOUR_DETH_KNIGHT, _currentGroupMapX, _currentGroupMapY, k1_soundModePlayIfPrioritized);
 					}
 				} else if (!getFlag(aspect, k0x0080_MaskActiveGroupIsAttacking) || !getFlag(creatureGraphicInfo, k0x0400_CreatureInfoGraphicMaskFlipDuringAttack)) {
@@ -1288,7 +1287,7 @@ int32 GroupMan::getCreatureAspectUpdateTime(ActiveGroup *activeGroup, int16 crea
 			if (getFlag(creatureGraphicInfo, k0x0004_CreatureInfoGraphicMaskFlipNonAttack)) {
 				if (creatureType == k13_CreatureTypeCouatl) {
 					if (_vm->getRandomNumber(2)) {
-						toggleFlag(aspect, k0x0040_MaskActiveGroupFlipBitmap);
+						_vm->toggleFlag(aspect, k0x0040_MaskActiveGroupFlipBitmap);
 						uint16 soundIndex = _vm->_moveSens->getSound(k13_CreatureTypeCouatl);
 						if (soundIndex <= k34_D13_soundCount)
 							_vm->_sound->requestPlay(soundIndex, _currentGroupMapX, _currentGroupMapY, k1_soundModePlayIfPrioritized);
@@ -1317,8 +1316,8 @@ void GroupMan::setGroupDirection(ActiveGroup *activeGroup, int16 dir, int16 crea
 		return;
 
 	uint16 groupDirections = activeGroup->_directions;
-	if (normalizeModulo4(getCreatureValue(groupDirections, creatureIndex) - dir) == 2) { /* If current and new direction are opposites then change direction only one step at a time */
-		dir = returnNextVal((_vm->getRandomNumber(65536) & 0x0002) + dir);
+	if (_vm->normalizeModulo4(getCreatureValue(groupDirections, creatureIndex) - dir) == 2) { /* If current and new direction are opposites then change direction only one step at a time */
+		dir = _vm->returnNextVal((_vm->getRandomNumber(65536) & 0x0002) + dir);
 		groupDirections = getGroupValueUpdatedWithCreatureValue(groupDirections, creatureIndex, dir);
 	} else
 		groupDirections = getGroupValueUpdatedWithCreatureValue(groupDirections, creatureIndex, dir);
@@ -1334,13 +1333,13 @@ void GroupMan::setGroupDirection(ActiveGroup *activeGroup, int16 dir, int16 crea
 
 void GroupMan::addGroupEvent(TimelineEvent *event, uint32 time) {
 	warning("potentially dangerous cast to uint32 below");
-	if (time < (uint32)filterTime(event->_mapTime)) {
+	if (time < (uint32)_vm->filterTime(event->_mapTime)) {
 		event->_type -= 5;
-		event->_Cu._ticks = filterTime(event->_mapTime) - time;
+		event->_Cu._ticks = _vm->filterTime(event->_mapTime) - time;
 		M32_setTime(event->_mapTime, time);
-	} else {
-		event->_Cu._ticks = time - filterTime(event->_mapTime);
-	}
+	} else
+		event->_Cu._ticks = time - _vm->filterTime(event->_mapTime);
+
 	_vm->_timeline->addEventGetEventIndex(event);
 }
 
@@ -1477,7 +1476,7 @@ bool GroupMan::isCreatureAttacking(Group *group, int16 mapX, int16 mapY, uint16
 			championIndex = _vm->getRandomNumber(4);
 			int cpt;
 			for (cpt = 0; (cpt < 4) && !_vm->_championMan->_champions[championIndex]._currHealth; cpt++)
-				championIndex = returnNextVal(championIndex);
+				championIndex = _vm->returnNextVal(championIndex);
 
 			if (cpt == 4)
 				return false;
@@ -1494,7 +1493,7 @@ bool GroupMan::isCreatureAttacking(Group *group, int16 mapX, int16 mapY, uint16
 			Champion *damagedChampion = &_vm->_championMan->_champions[championIndex];
 			if (damage > damagedChampion->_maximumDamageReceived) {
 				damagedChampion->_maximumDamageReceived = damage;
-				damagedChampion->_directionMaximumDamageReceived = returnOppositeDir((Direction)primaryDirectionToParty);
+				damagedChampion->_directionMaximumDamageReceived = _vm->returnOppositeDir((Direction)primaryDirectionToParty);
 			}
 		}
 	}
@@ -1640,7 +1639,7 @@ void GroupMan::startWandering(int16 mapX, int16 mapY) {
 		L0332_ps_Group->setBehaviour(k0_behavior_WANDER);
 	}
 	TimelineEvent nextEvent;
-	setMapAndTime(nextEvent._mapTime, _vm->_dungeonMan->_currMapIndex, (_vm->_gameTime + 1));
+	_vm->setMapAndTime(nextEvent._mapTime, _vm->_dungeonMan->_currMapIndex, (_vm->_gameTime + 1));
 	nextEvent._type = k37_TMEventTypeUpdateBehaviourGroup;
 	nextEvent._priority = 255 - _vm->_dungeonMan->_creatureInfos[L0332_ps_Group->_type]._movementTicks; /* The fastest creatures (with small MovementTicks value) get higher event priority */
 	nextEvent._Cu._ticks = 0;
@@ -1685,7 +1684,7 @@ void GroupMan::removeActiveGroup(uint16 activeGroupIndex) {
 	Group *group = &((Group *)_vm->_dungeonMan->_thingData[kDMThingTypeGroup])[activeGroup->_groupThingIndex];
 	_currActiveGroupCount--;
 	group->_cells = activeGroup->_cells;
-	group->setDir(normalizeModulo4(activeGroup->_directions));
+	group->setDir(_vm->normalizeModulo4(activeGroup->_directions));
 	if (group->getBehaviour() >= k4_behavior_USELESS) {
 		group->setBehaviour(k0_behavior_WANDER);
 	}
@@ -1884,7 +1883,7 @@ void GroupMan::fluxCageAction(int16 mapX, int16 mapY) {
 	_vm->_dungeonMan->linkThingToList(unusedThing, Thing(0), mapX, mapY);
 	(((Explosion *)_vm->_dungeonMan->_thingData[kDMThingTypeExplosion])[unusedThing.getIndex()]).setType(k50_ExplosionType_Fluxcage);
 	TimelineEvent newEvent;
-	setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_currMapIndex, _vm->_gameTime + 100);
+	_vm->setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_currMapIndex, _vm->_gameTime + 100);
 	newEvent._type = k24_TMEventTypeRemoveFluxcage;
 	newEvent._priority = 0;
 	newEvent._Cu._slot = unusedThing.toUint16();
@@ -1966,7 +1965,7 @@ void GroupMan::fuseAction(uint16 mapX, uint16 mapY) {
 			int16 destMapX = mapX;
 			int16 destMapY = mapY;
 			uint16 fluxcageIndex = _vm->getRandomNumber(4);
-			for (uint16 i = 5; --i; fluxcageIndex = returnNextVal(fluxcageIndex)) {
+			for (uint16 i = 5; --i; fluxcageIndex = _vm->returnNextVal(fluxcageIndex)) {
 				if (!isFluxcages[fluxcageIndex]) {
 					isFluxcages[fluxcageIndex] = true;
 					switch (fluxcageIndex) {
diff --git a/engines/dm/inventory.cpp b/engines/dm/inventory.cpp
index 38e9833..ba9aa7e 100644
--- a/engines/dm/inventory.cpp
+++ b/engines/dm/inventory.cpp
@@ -957,7 +957,7 @@ void InventoryMan::clickOnMouth() {
 			curChampion->_shieldDefense += adjustedPotionPower;
 			TimelineEvent newEvent;
 			newEvent._type = k72_TMEventTypeChampionShield;
-			setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + (adjustedPotionPower * adjustedPotionPower));
+			_vm->setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + (adjustedPotionPower * adjustedPotionPower));
 			newEvent._priority = championIndex;
 			newEvent._Bu._defense = adjustedPotionPower;
 			_vm->_timeline->addEventGetEventIndex(&newEvent);
diff --git a/engines/dm/menus.cpp b/engines/dm/menus.cpp
index 3cc1f04..5e83cbc 100644
--- a/engines/dm/menus.cpp
+++ b/engines/dm/menus.cpp
@@ -610,7 +610,7 @@ int16 MenuMan::getChampionSpellCastResult(uint16 champIndex) {
 			_vm->_championMan->_party._event73Count_ThievesEye++;
 			spellPower = (spellPower >> 1);
 			uint16 spellTicks = spellPower * spellPower;
-			setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + spellTicks);
+			_vm->setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + spellTicks);
 			_vm->_timeline->addEventGetEventIndex(&newEvent);
 			}
 			break;
@@ -618,7 +618,7 @@ int16 MenuMan::getChampionSpellCastResult(uint16 champIndex) {
 			newEvent._type = k71_TMEventTypeInvisibility;
 			_vm->_championMan->_party._event71Count_Invisibility++;
 			uint16 spellTicks = spellPower;
-			setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + spellTicks);
+			_vm->setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + spellTicks);
 			_vm->_timeline->addEventGetEventIndex(&newEvent);
 			}
 			break;
@@ -631,7 +631,7 @@ int16 MenuMan::getChampionSpellCastResult(uint16 champIndex) {
 			_vm->_championMan->_party._shieldDefense += newEvent._Bu._defense;
 			_vm->_timeline->refreshAllChampionStatusBoxes();
 			uint16 spellTicks = spellPower * spellPower;
-			setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + spellTicks);
+			_vm->setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + spellTicks);
 			_vm->_timeline->addEventGetEventIndex(&newEvent);
 			}
 			break;
@@ -645,7 +645,7 @@ int16 MenuMan::getChampionSpellCastResult(uint16 champIndex) {
 				_vm->_championMan->_party._lastScentIndex = 0;
 
 			uint16 spellTicks = spellPower * spellPower;
-			setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + spellTicks);
+			_vm->setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + spellTicks);
 			_vm->_timeline->addEventGetEventIndex(&newEvent);
 			}
 			break;
@@ -801,7 +801,7 @@ void MenuMan::createEvent70_light(int16 lightPower, int16 ticks) {
 	TimelineEvent newEvent;
 	newEvent._type = k70_TMEventTypeLight;
 	newEvent._Bu._lightPower = lightPower;
-	setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + ticks);
+	_vm->setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + ticks);
 	newEvent._priority = 0;
 	_vm->_timeline->addEventGetEventIndex(&newEvent);
 	_vm->_inventoryMan->setDungeonViewPalette();
@@ -836,7 +836,7 @@ bool MenuMan::isPartySpellOrFireShieldSuccessful(Champion *champ, bool spellShie
 		_vm->_championMan->_party._fireShieldDefense += newEvent._Bu._defense;
 	}
 	newEvent._priority = 0;
-	setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + ticks);
+	_vm->setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + ticks);
 	_vm->_timeline->addEventGetEventIndex(&newEvent);
 	_vm->_timeline->refreshAllChampionStatusBoxes();
 
@@ -894,7 +894,7 @@ void MenuMan::addChampionSymbol(int16 symbolIndex) {
 		setFlag(casterChampion->_attributes, kDMAttributeStatistics);
 		casterChampion->_symbols[symbolStep] = 96 + (symbolStep * 6) + symbolIndex;
 		casterChampion->_symbols[symbolStep + 1] = '\0';
-		casterChampion->_symbolStep = symbolStep = returnNextVal(symbolStep);
+		casterChampion->_symbolStep = symbolStep = _vm->returnNextVal(symbolStep);
 		_vm->_eventMan->showMouse();
 		drawAvailableSymbols(symbolStep);
 		drawChampionSymbols(casterChampion);
@@ -908,7 +908,7 @@ void MenuMan::deleteChampionSymbol() {
 	if (!strlen(casterChampion->_symbols))
 		return;
 
-	int16 symbolStep = returnPrevVal(casterChampion->_symbolStep);
+	int16 symbolStep = _vm->returnPrevVal(casterChampion->_symbolStep);
 	casterChampion->_symbolStep = symbolStep;
 	casterChampion->_symbols[symbolStep] = '\0';
 	_vm->_eventMan->showMouse();
@@ -1261,7 +1261,7 @@ bool MenuMan::isActionPerformed(uint16 champIndex, int16 actionIndex) {
 		TimelineEvent newEvent;
 		newEvent._priority = 0;
 		newEvent._type = k73_TMEventTypeThievesEye;
-		setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + windowTicks);
+		_vm->setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + windowTicks);
 		_vm->_timeline->addEventGetEventIndex(&newEvent);
 		_vm->_championMan->_party._event73Count_ThievesEye++;
 		decrementCharges(curChampion);
@@ -1308,7 +1308,7 @@ bool MenuMan::isActionPerformed(uint16 champIndex, int16 actionIndex) {
 		break;
 	case kDMActionThrow:
 		setChampionDirectionToPartyDirection(curChampion);
-		actionPerformed = _vm->_championMan->isObjectThrown(champIndex, kDMSlotActionHand, (curChampion->_cell == returnNextVal(_vm->_dungeonMan->_partyDir)) || (curChampion->_cell == (ViewCell)returnOppositeDir(_vm->_dungeonMan->_partyDir)));
+		actionPerformed = _vm->_championMan->isObjectThrown(champIndex, kDMSlotActionHand, (curChampion->_cell == _vm->returnNextVal(_vm->_dungeonMan->_partyDir)) || (curChampion->_cell == (ViewCell)_vm->returnOppositeDir(_vm->_dungeonMan->_partyDir)));
 		if (actionPerformed)
 			_vm->_timeline->_events[curChampion->_enableActionEventIndex]._Bu._slotOrdinal = _vm->indexToOrdinal(kDMSlotActionHand);
 		break;
@@ -1472,13 +1472,13 @@ bool MenuMan::isMeleeActionPerformed(int16 champIndex, Champion *champ, int16 ac
 	uint16 championCell = champ->_cell;
 	int16 targetCreatureOrdinal = _vm->_groupMan->getMeleeTargetCreatureOrdinal(targetMapX, targetMapY, _vm->_dungeonMan->_partyMapX, _vm->_dungeonMan->_partyMapY, championCell);
 	if (targetCreatureOrdinal) {
-		uint16 viewCell = normalizeModulo4(championCell + 4 - champ->_dir);
+		uint16 viewCell = _vm->normalizeModulo4(championCell + 4 - champ->_dir);
 		switch (viewCell) {
 		case k2_ViewCellBackRight: /* Champion is on the back right of the square and tries to attack a creature in the front right of its square */
 		case k3_ViewCellBackLeft: /* Champion is on the back left of the square and tries to attack a creature in the front left of its square */
 			uint16 cellDelta = (viewCell == k2_ViewCellBackRight) ? 3 : 1;
 			/* Check if there is another champion in front */
-			if (_vm->_championMan->getIndexInCell(normalizeModulo4(championCell + cellDelta)) != kDMChampionNone) {
+			if (_vm->_championMan->getIndexInCell(_vm->normalizeModulo4(championCell + cellDelta)) != kDMChampionNone) {
 				_actionDamage = kM1_damageCantReach;
 				return false;
 			}
diff --git a/engines/dm/movesens.cpp b/engines/dm/movesens.cpp
index 5e39338..28a905f 100644
--- a/engines/dm/movesens.cpp
+++ b/engines/dm/movesens.cpp
@@ -146,7 +146,7 @@ bool MovesensMan::sensorIsTriggeredByClickOnWall(int16 mapX, int16 mapY, uint16
 						continue;
 
 					_vm->_championMan->getObjectRemovedFromLeaderHand();
-					_vm->_dungeonMan->linkThingToList(thingWithNewCell(leaderHandObject, cellIdx), Thing(0), mapX, mapY);
+					_vm->_dungeonMan->linkThingToList(_vm->thingWithNewCell(leaderHandObject, cellIdx), Thing(0), mapX, mapY);
 					leaderHandObject = Thing::_none;
 				}
 				triggerLocalEffect(k2_SensorEffToggle, mapX, mapY, cellIdx); /* This will cause a rotation of the sensors at the specified cell on the specified square after all sensors have been processed */
@@ -166,7 +166,7 @@ bool MovesensMan::sensorIsTriggeredByClickOnWall(int16 mapX, int16 mapY, uint16
 
 				_vm->_dungeonMan->unlinkThingFromList(thingOnSquare, Thing(0), mapX, mapY);
 				_vm->_championMan->getObjectRemovedFromLeaderHand();
-				_vm->_dungeonMan->linkThingToList(thingWithNewCell(leaderHandObject, cellIdx), Thing(0), mapX, mapY);
+				_vm->_dungeonMan->linkThingToList(_vm->thingWithNewCell(leaderHandObject, cellIdx), Thing(0), mapX, mapY);
 				_vm->_championMan->putObjectInLeaderHand(thingOnSquare, true);
 				doNotTriggerSensor = false;
 				}
@@ -290,7 +290,7 @@ bool MovesensMan::getMoveResult(Thing thing, int16 mapX, int16 mapY, int16 destM
 					if (teleporter->getAbsoluteRotation())
 						_vm->_championMan->setPartyDirection(teleporter->getRotation());
 					else
-						_vm->_championMan->setPartyDirection(normalizeModulo4(_vm->_dungeonMan->_partyDir + teleporter->getRotation()));
+						_vm->_championMan->setPartyDirection(_vm->normalizeModulo4(_vm->_dungeonMan->_partyDir + teleporter->getRotation()));
 				} else {
 					if (thingType == kDMThingTypeGroup) {
 						if (teleporter->isAudible())
@@ -301,7 +301,7 @@ bool MovesensMan::getMoveResult(Thing thing, int16 mapX, int16 mapY, int16 destM
 						if (thingType == kDMThingTypeProjectile)
 							thing = getTeleporterRotatedProjectileThing(teleporter, thing);
 						else if (!(teleporter->getAbsoluteRotation()) && (mapX != -2))
-							thing = thingWithNewCell(thing, normalizeModulo4(thing.getCell() + teleporter->getRotation()));
+							thing = _vm->thingWithNewCell(thing, _vm->normalizeModulo4(thing.getCell() + teleporter->getRotation()));
 					}
 				}
 				if (destinationIsTeleporterTarget)
@@ -353,10 +353,10 @@ bool MovesensMan::getMoveResult(Thing thing, int16 mapX, int16 mapY, int16 destM
 					}
 					direction = _vm->_dungeonMan->getStairsExitDirection(destMapX, destMapY);
 					destMapX += _vm->_dirIntoStepCountEast[direction], destMapY += _vm->_dirIntoStepCountNorth[direction];
-					direction = returnOppositeDir((Direction)direction);
+					direction = _vm->returnOppositeDir((Direction)direction);
 					uint16 thingCell = thing.getCell();
-					thingCell = normalizeModulo4((((thingCell - direction + 1) & 0x0002) >> 1) + direction);
-					thing = thingWithNewCell(thing, thingCell);
+					thingCell = _vm->normalizeModulo4((((thingCell - direction + 1) & 0x0002) >> 1) + direction);
+					thing = _vm->thingWithNewCell(thing, thingCell);
 				} else
 					break;
 			}
@@ -540,23 +540,23 @@ bool MovesensMan::moveIsKilledByProjectileImpact(int16 srcMapX, int16 srcMapY, i
 	if ((destMapX >= 0) && ((abs(srcMapX - destMapX) + abs(srcMapY - destMapY)) == 1)) {
 		/* If source and destination squares are adjacent (if party or group is not being teleported) */
 		int16 primaryDirection = _vm->_groupMan->getDirsWhereDestIsVisibleFromSource(srcMapX, srcMapY, destMapX, destMapY);
-		int16 secondaryDirection = returnNextVal(primaryDirection);
+		int16 secondaryDirection = _vm->returnNextVal(primaryDirection);
 		for (int16 i = 0; i < 4; ++i)
 			intermediaryChampionOrCreatureOrdinalInCell[i] = 0;
 
-		intermediaryChampionOrCreatureOrdinalInCell[returnPrevVal(primaryDirection)] = championOrCreatureOrdinalInCell[primaryDirection];
-		if (intermediaryChampionOrCreatureOrdinalInCell[returnPrevVal(primaryDirection)])
+		intermediaryChampionOrCreatureOrdinalInCell[_vm->returnPrevVal(primaryDirection)] = championOrCreatureOrdinalInCell[primaryDirection];
+		if (intermediaryChampionOrCreatureOrdinalInCell[_vm->returnPrevVal(primaryDirection)])
 			checkDestinationSquareProjectileImpacts = true;
 
-		intermediaryChampionOrCreatureOrdinalInCell[returnNextVal(secondaryDirection)] = championOrCreatureOrdinalInCell[secondaryDirection];
-		if (intermediaryChampionOrCreatureOrdinalInCell[returnNextVal(secondaryDirection)])
+		intermediaryChampionOrCreatureOrdinalInCell[_vm->returnNextVal(secondaryDirection)] = championOrCreatureOrdinalInCell[secondaryDirection];
+		if (intermediaryChampionOrCreatureOrdinalInCell[_vm->returnNextVal(secondaryDirection)])
 			checkDestinationSquareProjectileImpacts = true;
 
 		if (!championOrCreatureOrdinalInCell[primaryDirection])
-			championOrCreatureOrdinalInCell[primaryDirection] = championOrCreatureOrdinalInCell[returnPrevVal(primaryDirection)];
+			championOrCreatureOrdinalInCell[primaryDirection] = championOrCreatureOrdinalInCell[_vm->returnPrevVal(primaryDirection)];
 
 		if (!championOrCreatureOrdinalInCell[secondaryDirection])
-			championOrCreatureOrdinalInCell[secondaryDirection] = championOrCreatureOrdinalInCell[returnNextVal(secondaryDirection)];
+			championOrCreatureOrdinalInCell[secondaryDirection] = championOrCreatureOrdinalInCell[_vm->returnNextVal(secondaryDirection)];
 	}
 	uint16 projectileMapX = srcMapX; /* Check impacts with projectiles on the source square */
 	uint16 projectileMapY = srcMapY;
@@ -589,7 +589,7 @@ T0266017_CheckProjectileImpacts:
 
 void MovesensMan::addEvent(byte type, byte mapX, byte mapY, byte cell, byte effect, int32 time) {
 	TimelineEvent newEvent;
-	setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_currMapIndex, time);
+	_vm->setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_currMapIndex, time);
 	newEvent._type = type;
 	newEvent._priority = 0;
 	newEvent._Bu._location._mapX = mapX;
@@ -654,22 +654,22 @@ int16 MovesensMan::getTeleporterRotatedGroupResult(Teleporter *teleporter, Thing
 	if (absoluteRotation)
 		updatedGroupDirections = rotation;
 	else
-		updatedGroupDirections = normalizeModulo4(groupDirections + rotation);
+		updatedGroupDirections = _vm->normalizeModulo4(groupDirections + rotation);
 
 	uint16 updatedGroupCells = _vm->_groupMan->getGroupCells(group, mapIndex);
 	if (updatedGroupCells != k255_CreatureTypeSingleCenteredCreature) {
 		int16 groupCells = updatedGroupCells;
 		int16 creatureSize = getFlag(_vm->_dungeonMan->_creatureInfos[group->_type]._attributes, k0x0003_MaskCreatureInfo_size);
-		int16 relativeRotation = normalizeModulo4(4 + updatedGroupDirections - groupDirections);
+		int16 relativeRotation = _vm->normalizeModulo4(4 + updatedGroupDirections - groupDirections);
 		for (int16 creatureIdx = 0; creatureIdx <= group->getCount(); creatureIdx++) {
-			updatedGroupDirections = _vm->_groupMan->getGroupValueUpdatedWithCreatureValue(updatedGroupDirections, creatureIdx, absoluteRotation ? rotation : normalizeModulo4(groupDirections + rotation));
+			updatedGroupDirections = _vm->_groupMan->getGroupValueUpdatedWithCreatureValue(updatedGroupDirections, creatureIdx, absoluteRotation ? rotation : _vm->normalizeModulo4(groupDirections + rotation));
 			if (creatureSize == k0_MaskCreatureSizeQuarter) {
 				relativeRotation = absoluteRotation ? 1 : 0;
 				if (relativeRotation)
 					relativeRotation = rotation;
 			}
 			if (relativeRotation)
-				updatedGroupCells = _vm->_groupMan->getGroupValueUpdatedWithCreatureValue(updatedGroupCells, creatureIdx, normalizeModulo4(groupCells + relativeRotation));
+				updatedGroupCells = _vm->_groupMan->getGroupValueUpdatedWithCreatureValue(updatedGroupCells, creatureIdx, _vm->normalizeModulo4(groupCells + relativeRotation));
 
 			groupDirections >>= 2;
 			groupCells >>= 2;
@@ -689,8 +689,8 @@ Thing MovesensMan::getTeleporterRotatedProjectileThing(Teleporter *teleporter, T
 	if (teleporter->getAbsoluteRotation())
 		updatedDirection = rotation;
 	else {
-		updatedDirection = normalizeModulo4(updatedDirection + rotation);
-		projectileThing = thingWithNewCell(projectileThing, normalizeModulo4(projectileThing.getCell() + rotation));
+		updatedDirection = _vm->normalizeModulo4(updatedDirection + rotation);
+		projectileThing = _vm->thingWithNewCell(projectileThing, _vm->normalizeModulo4(projectileThing.getCell() + rotation));
 	}
 	_moveResultDir = updatedDirection;
 	return projectileThing;
@@ -987,7 +987,7 @@ void MovesensMan::processRotationEffect() {
 
 void MovesensMan::createEventMoveGroup(Thing groupThing, int16 mapX, int16 mapY, int16 mapIndex, bool audible) {
 	TimelineEvent newEvent;
-	setMapAndTime(newEvent._mapTime, mapIndex, _vm->_gameTime + 5);
+	_vm->setMapAndTime(newEvent._mapTime, mapIndex, _vm->_gameTime + 5);
 	newEvent._type = audible ? k61_TMEventTypeMoveGroupAudible : k60_TMEventTypeMoveGroupSilent;
 	newEvent._priority = 0;
 	newEvent._Bu._location._mapX = mapX;
diff --git a/engines/dm/projexpl.cpp b/engines/dm/projexpl.cpp
index e28b0f6..23c64c4 100644
--- a/engines/dm/projexpl.cpp
+++ b/engines/dm/projexpl.cpp
@@ -50,14 +50,14 @@ void ProjExpl::createProjectile(Thing thing, int16 mapX, int16 mapY, uint16 cell
 	if (projectileThing == Thing::_none) /* BUG0_16 If the game cannot create a projectile thing because it has run out of such things (60 maximum) then the object being thrown/shot/launched is orphaned. If the game has run out of projectile things it will try to remove a projectile from elsewhere in the dungeon, except in an area of 11x11 squares centered around the party (to make sure the player cannot actually see the thing disappear on screen) */
 		return;
 
-	projectileThing = thingWithNewCell(projectileThing, cell);
+	projectileThing = _vm->thingWithNewCell(projectileThing, cell);
 	Projectile *projectilePtr = (Projectile *)_vm->_dungeonMan->getThingData(projectileThing);
 	projectilePtr->_slot = thing;
 	projectilePtr->_kineticEnergy = MIN((int16)kineticEnergy, (int16)255);
 	projectilePtr->_attack = attack;
 	_vm->_dungeonMan->linkThingToList(projectileThing, Thing(0), mapX, mapY); /* Projectiles are added on the square and not 'moved' onto the square. In the case of a projectile launcher sensor, this means that the new projectile traverses the square in front of the launcher without any trouble: there is no impact if it is a wall, the projectile direction is not changed if it is a teleporter. Impacts with creatures and champions are still processed */
 	TimelineEvent newEvent;
-	setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_currMapIndex, _vm->_gameTime + 1);
+	_vm->setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_currMapIndex, _vm->_gameTime + 1);
 	if (_createLauncherProjectile)
 		newEvent._type = k49_TMEventTypeMoveProjectile; /* Launcher projectiles can impact immediately */
 	else
@@ -298,7 +298,7 @@ void ProjExpl::createExplosion(Thing explThing, uint16 attack, uint16 mapXCombo,
 		explosion->setCentered(true);
 	else {
 		explosion->setCentered(false);
-		unusedThing = thingWithNewCell(unusedThing, cell);
+		unusedThing = _vm->thingWithNewCell(unusedThing, cell);
 	}
 
 	explosion->setType(explThing.toUint16() - Thing::_firstExplosion.toUint16());
@@ -311,7 +311,7 @@ void ProjExpl::createExplosion(Thing explThing, uint16 attack, uint16 mapXCombo,
 
 	_vm->_dungeonMan->linkThingToList(unusedThing, Thing(0), projectileMapX, projectileMapY);
 	TimelineEvent newEvent;
-	setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_currMapIndex, _vm->_gameTime + ((explThing == Thing::_explRebirthStep1) ? 5 : 1));
+	_vm->setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_currMapIndex, _vm->_gameTime + ((explThing == Thing::_explRebirthStep1) ? 5 : 1));
 	newEvent._type = k25_TMEventTypeExplosion;
 	newEvent._priority = 0;
 	newEvent._Cu._slot = unusedThing.toUint16();
@@ -425,7 +425,7 @@ void ProjExpl::processEvents48To49(TimelineEvent *event) {
 	uint16 projectileDirection = curEvent->_Cu._projectile.getDir();
 	projectileThingNewCell = Thing(curEvent->_Bu._slot);
 	uint16 projectileNewCell = projectileThingNewCell.getCell();
-	bool projectileMovesToOtherSquare = (projectileDirection == projectileNewCell) || (returnNextVal(projectileDirection) == projectileNewCell);
+	bool projectileMovesToOtherSquare = (projectileDirection == projectileNewCell) || (_vm->returnNextVal(projectileDirection) == projectileNewCell);
 	if (projectileMovesToOtherSquare) {
 		sourceMapX = destinationMapX;
 		sourceMapY = destinationMapY;
@@ -446,13 +446,13 @@ void ProjExpl::processEvents48To49(TimelineEvent *event) {
 	else
 		projectileNewCell++;
 
-	projectileThingNewCell = thingWithNewCell(projectileThingNewCell, projectileNewCell &= 0x0003);
+	projectileThingNewCell = _vm->thingWithNewCell(projectileThingNewCell, projectileNewCell &= 0x0003);
 	if (projectileMovesToOtherSquare) {
 		_vm->_moveSens->getMoveResult(projectileThingNewCell, sourceMapX, sourceMapY, destinationMapX, destinationMapY);
 		curEvent->_Cu._projectile.setMapX(_vm->_moveSens->_moveResultMapX);
 		curEvent->_Cu._projectile.setMapY(_vm->_moveSens->_moveResultMapY);
 		curEvent->_Cu._projectile.setDir((Direction)_vm->_moveSens->_moveResultDir);
-		projectileThingNewCell = thingWithNewCell(projectileThingNewCell, _vm->_moveSens->_moveResultCell);
+		projectileThingNewCell = _vm->thingWithNewCell(projectileThingNewCell, _vm->_moveSens->_moveResultCell);
 		M31_setMap(curEvent->_mapTime, _vm->_moveSens->_moveResultMapIndex);
 	} else {
 		if ((Square(_vm->_dungeonMan->getSquare(destinationMapX, destinationMapY)).getType() == k4_DoorElemType) && hasProjectileImpactOccurred(k4_DoorElemType, destinationMapX, destinationMapY, projectileNewCell, projectileThing))
diff --git a/engines/dm/sounds.cpp b/engines/dm/sounds.cpp
index f09d831..d077ee5 100644
--- a/engines/dm/sounds.cpp
+++ b/engines/dm/sounds.cpp
@@ -202,7 +202,7 @@ void SoundMan::requestPlay(uint16 soundIndex, int16 mapX, int16 mapY, uint16 mod
 	Sound *sound = &_sounds[soundIndex];
 	if (mode > k1_soundModePlayIfPrioritized) { /* Add an event in the timeline to play the sound (mode - 1) ticks later */
 		TimelineEvent newEvent;
-		setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_currMapIndex, _vm->_gameTime + mode - 1);
+		_vm->setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_currMapIndex, _vm->_gameTime + mode - 1);
 		newEvent._type = k20_TMEventTypePlaySound;
 		newEvent._priority = sound->_priority;
 		newEvent._Cu._soundIndex = soundIndex;
diff --git a/engines/dm/timeline.cpp b/engines/dm/timeline.cpp
index aba8590..308f58f 100644
--- a/engines/dm/timeline.cpp
+++ b/engines/dm/timeline.cpp
@@ -173,9 +173,9 @@ void Timeline::fixChronology(uint16 timelineIndex) {
 }
 
 bool Timeline::isEventABeforeB(TimelineEvent *eventA, TimelineEvent *eventB) {
-	bool simultaneousFl = (filterTime(eventA->_mapTime) == filterTime(eventB->_mapTime));
+	bool simultaneousFl = (_vm->filterTime(eventA->_mapTime) == _vm->filterTime(eventB->_mapTime));
 
-	return (filterTime(eventA->_mapTime) < filterTime(eventB->_mapTime)) ||
+	return (_vm->filterTime(eventA->_mapTime) < _vm->filterTime(eventB->_mapTime)) ||
 		(simultaneousFl && (eventA->getTypePriority() > eventB->getTypePriority())) ||
 		(simultaneousFl && (eventA->getTypePriority() == eventB->getTypePriority()) && (eventA <= eventB));
 }
@@ -235,7 +235,7 @@ uint16 Timeline::addEventGetEventIndex(TimelineEvent *event) {
 	} else if (event->_type == k2_TMEventTypeDoorDestruction) {
 		TimelineEvent *curEvent = _events;
 		for (uint16 eventIndex = 0; eventIndex < _eventMaxCount; eventIndex++, curEvent++) {
-			if ((event->getMapXY() == curEvent->getMapXY()) && (getMap(event->_mapTime) == getMap(curEvent->_mapTime))) {
+			if ((event->getMapXY() == curEvent->getMapXY()) && (_vm->getMap(event->_mapTime) == _vm->getMap(curEvent->_mapTime))) {
 				if ((curEvent->_type == k1_TMEventTypeDoorAnimation) || (curEvent->_type == k10_TMEventTypeDoor))
 					deleteEvent(eventIndex);
 			}
@@ -259,7 +259,7 @@ void Timeline::processTimeline() {
 		TimelineEvent newEvent;
 		TimelineEvent *curEvent = &newEvent;
 		extractFirstEvent(curEvent);
-		_vm->_dungeonMan->setCurrentMap(getMap(newEvent._mapTime));
+		_vm->_dungeonMan->setCurrentMap(_vm->getMap(newEvent._mapTime));
 		uint16 curEventType = newEvent._type;
 		if ((curEventType > (k29_TMEventTypeGroupReactionDangerOnSquare - 1)) && (curEventType < (k41_TMEventTypeUpdateBehaviour_3 + 1)))
 			_vm->_groupMan->processEvents29to41(newEvent._Bu._location._mapX, newEvent._Bu._location._mapY, curEventType, newEvent._Cu._ticks);
@@ -369,7 +369,7 @@ void Timeline::processTimeline() {
 }
 
 bool Timeline::isFirstEventExpiered() {
-	return (_eventCount && (filterTime(_events[_timeline[0]]._mapTime) <= _vm->_gameTime));
+	return (_eventCount && (_vm->filterTime(_events[_timeline[0]]._mapTime) <= _vm->_gameTime));
 }
 
 void Timeline::extractFirstEvent(TimelineEvent *event) {
@@ -537,7 +537,7 @@ void Timeline::moveTeleporterOrPitSquareThings(uint16 mapX, uint16 mapY) {
 			newEvent->_Cu._projectile.setMapX(_vm->_moveSens->_moveResultMapX);
 			newEvent->_Cu._projectile.setMapY(_vm->_moveSens->_moveResultMapY);
 			newEvent->_Cu._projectile.setDir((Direction)_vm->_moveSens->_moveResultDir);
-			newEvent->_Bu._slot = thingWithNewCell(curThing, _vm->_moveSens->_moveResultCell).toUint16();
+			newEvent->_Bu._slot = _vm->thingWithNewCell(curThing, _vm->_moveSens->_moveResultCell).toUint16();
 			M31_setMap(newEvent->_mapTime, _vm->_moveSens->_moveResultMapIndex);
 		} else if (curThingType == kDMThingTypeExplosion) {
 			TimelineEvent *newEvent = _events;
@@ -545,7 +545,7 @@ void Timeline::moveTeleporterOrPitSquareThings(uint16 mapX, uint16 mapY) {
 				if ((newEvent->_type == k25_TMEventTypeExplosion) && (newEvent->_Cu._slot == curThing.toUint16())) { /* BUG0_23 A Fluxcage explosion remains on a square forever. If you open a pit or teleporter on a square where there is a Fluxcage explosion, the Fluxcage explosion is moved but the associated event is not updated (because Fluxcage explosions do not use k25_TMEventTypeExplosion but rather k24_TMEventTypeRemoveFluxcage) causing the Fluxcage explosion to remain in the dungeon forever on its destination square. When the k24_TMEventTypeRemoveFluxcage expires the explosion thing is not removed, but it is marked as unused. Consequently, any objects placed on the Fluxcage square after it was moved but before it expires become orphans upon expiration. After expiration, any object placed on the fluxcage square is cloned when picked up */
 					newEvent->_Bu._location._mapX = _vm->_moveSens->_moveResultMapX;
 					newEvent->_Bu._location._mapY = _vm->_moveSens->_moveResultMapY;
-					newEvent->_Cu._slot = thingWithNewCell(curThing, _vm->_moveSens->_moveResultCell).toUint16();
+					newEvent->_Cu._slot = _vm->thingWithNewCell(curThing, _vm->_moveSens->_moveResultCell).toUint16();
 					M31_setMap(newEvent->_mapTime, _vm->_moveSens->_moveResultMapIndex);
 				}
 			}
@@ -639,7 +639,7 @@ void Timeline::triggerProjectileLauncher(Sensor *sensor, TimelineEvent *event) {
 	int16 mapX = event->_Bu._location._mapX;
 	int16 mapY = event->_Bu._location._mapY;
 	uint16 cell = event->_Cu.A._cell;
-	uint16 projectileCell = returnOppositeDir((Direction)cell);
+	uint16 projectileCell = _vm->returnOppositeDir((Direction)cell);
 	int16 sensorType = sensor->getType();
 	int16 sensorData = sensor->getData();
 	int16 kineticEnergy = sensor->getActionKineticEnergy();
@@ -656,7 +656,7 @@ void Timeline::triggerProjectileLauncher(Sensor *sensor, TimelineEvent *event) {
 		firstProjectileAssociatedThing = _vm->_dungeonMan->getSquareFirstThing(mapX, mapY);
 		while (firstProjectileAssociatedThing != Thing::_none) { /* BUG0_19 The game crashes when an object launcher sensor is triggered. Thing::_none should be Thing::_endOfList. If there are no more objects on the square then this loop may return an undefined value, this can crash the game. In the original DM and CSB dungeons, the number of times that these sensors are triggered is always controlled to be equal to the number of available objects (with a countdown sensor or a number of once only sensors) */
 			uint16 projectiveThingCell = firstProjectileAssociatedThing.getCell();
-			if ((firstProjectileAssociatedThing.getType() > kDMThingTypeSensor) && ((projectiveThingCell == cell) || (projectiveThingCell == returnNextVal(cell))))
+			if ((firstProjectileAssociatedThing.getType() > kDMThingTypeSensor) && ((projectiveThingCell == cell) || (projectiveThingCell == _vm->returnNextVal(cell))))
 				break;
 			firstProjectileAssociatedThing = _vm->_dungeonMan->getNextThing(firstProjectileAssociatedThing);
 		}
@@ -668,7 +668,7 @@ void Timeline::triggerProjectileLauncher(Sensor *sensor, TimelineEvent *event) {
 			secondProjectileAssociatedThing = _vm->_dungeonMan->getSquareFirstThing(mapX, mapY);
 			while (secondProjectileAssociatedThing != Thing::_none) { /* BUG0_19 The game crashes when an object launcher sensor is triggered. Thing::_none should be Thing::_endOfList. If there are no more objects on the square then this loop may return an undefined value, this can crash the game */
 				uint16 projectiveThingCell = secondProjectileAssociatedThing.getCell();
-				if ((secondProjectileAssociatedThing.getType() > kDMThingTypeSensor) && ((projectiveThingCell == cell) || (projectiveThingCell == returnNextVal(cell))))
+				if ((secondProjectileAssociatedThing.getType() > kDMThingTypeSensor) && ((projectiveThingCell == cell) || (projectiveThingCell == _vm->returnNextVal(cell))))
 					break;
 				secondProjectileAssociatedThing = _vm->_dungeonMan->getNextThing(secondProjectileAssociatedThing);
 			}
@@ -687,7 +687,7 @@ void Timeline::triggerProjectileLauncher(Sensor *sensor, TimelineEvent *event) {
 			launchSingleProjectile = true;
 	}
 	if (launchSingleProjectile)
-		projectileCell = normalizeModulo4(projectileCell + _vm->getRandomNumber(2));
+		projectileCell = _vm->normalizeModulo4(projectileCell + _vm->getRandomNumber(2));
 
 	/* BUG0_20 The game crashes if the launcher sensor is on a map boundary and shoots in a direction outside the map */
 	mapX += _vm->_dirIntoStepCountEast[cell];
@@ -695,7 +695,7 @@ void Timeline::triggerProjectileLauncher(Sensor *sensor, TimelineEvent *event) {
 	_vm->_projexpl->_createLauncherProjectile = true;
 	_vm->_projexpl->createProjectile(firstProjectileAssociatedThing, mapX, mapY, projectileCell, (Direction)cell, kineticEnergy, 100, stepEnergy);
 	if (!launchSingleProjectile)
-		_vm->_projexpl->createProjectile(secondProjectileAssociatedThing, mapX, mapY, returnNextVal(projectileCell), (Direction)cell, kineticEnergy, 100, stepEnergy);
+		_vm->_projexpl->createProjectile(secondProjectileAssociatedThing, mapX, mapY, _vm->returnNextVal(projectileCell), (Direction)cell, kineticEnergy, 100, stepEnergy);
 
 	_vm->_projexpl->_createLauncherProjectile = false;
 }
@@ -746,7 +746,7 @@ void Timeline::processEventSquareCorridor(TimelineEvent *event) {
 
 						TimelineEvent newEvent;
 						newEvent._type = k65_TMEventTypeEnableGroupGenerator;
-						setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_currMapIndex, _vm->_gameTime + actionTicks);
+						_vm->setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_currMapIndex, _vm->_gameTime + actionTicks);
 						newEvent._priority = 0;
 						newEvent._Bu._location._mapX = mapX;
 						newEvent._Bu._location._mapY = mapY;
@@ -897,7 +897,7 @@ void Timeline::processEventLight(TimelineEvent *event) {
 		TimelineEvent newEvent;
 		newEvent._type = k70_TMEventTypeLight;
 		newEvent._Bu._lightPower = weakerLightPower;
-		setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + 4);
+		_vm->setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + 4);
 		newEvent._priority = 0;
 		addEventGetEventIndex(&newEvent);
 	}





More information about the Scummvm-git-logs mailing list