[Scummvm-git-logs] scummvm master -> 738a8a17f80491d92e8d828eb4d1bd317a0d3aa7

neuromancer noreply at scummvm.org
Thu Oct 31 21:02:19 UTC 2024


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

Summary:
13b487efda FREESCAPE: show key names when clicking in castle
738a8a17f8 FREESCAPE: refactor and fix some conditional code in castle


Commit: 13b487efda013469641932b54aa7a2b93b2c2253
    https://github.com/scummvm/scummvm/commit/13b487efda013469641932b54aa7a2b93b2c2253
Author: neuromancer (gustavo.grieco at gmail.com)
Date: 2024-10-31T22:03:59+01:00

Commit Message:
FREESCAPE: show key names when clicking in castle

Changed paths:
    engines/freescape/freescape.cpp
    engines/freescape/games/castle/castle.cpp


diff --git a/engines/freescape/freescape.cpp b/engines/freescape/freescape.cpp
index f649ef348ae..d5d240605ba 100644
--- a/engines/freescape/freescape.cpp
+++ b/engines/freescape/freescape.cpp
@@ -662,9 +662,24 @@ void FreescapeEngine::processInput() {
 }
 
 Common::Point FreescapeEngine::getNormalizedPosition(Common::Point position) {
+	// Retrieve the screen and viewport dimensions
 	Common::Point resolution(g_system->getWidth(), g_system->getHeight());
-	position.x = _screenW * position.x / resolution.x;
-	position.y = _screenH * position.y / resolution.y;
+
+	int32 viewportWidth = MIN<int32>(resolution.x, resolution.y * float(4) / 3);
+	int32 viewportHeight = MIN<int32>(resolution.y, resolution.x * float(3) / 4);
+
+	// Calculate pillarbox offset
+	int32 offsetX = (resolution.x - viewportWidth) / 2;
+	int32 offsetY = (resolution.y - viewportHeight) / 2;
+
+	// Adjust mouse position by removing the offset
+	position.x -= offsetX;
+	position.y -= offsetY;
+
+	// Scale position to match the 320x200 internal resolution
+	position.x = position.x * 320 / viewportWidth;
+	position.y = position.y * 200 / viewportHeight;
+
 	return position;
 }
 
diff --git a/engines/freescape/games/castle/castle.cpp b/engines/freescape/games/castle/castle.cpp
index 15017aa4165..637f460028c 100644
--- a/engines/freescape/games/castle/castle.cpp
+++ b/engines/freescape/games/castle/castle.cpp
@@ -493,6 +493,8 @@ void CastleEngine::drawInfoMenu() {
 	int score = _gameStateVars[k8bitVariableScore];
 	int shield = _gameStateVars[k8bitVariableShield];
 	int spiritsDestroyed = _gameStateVars[k8bitVariableSpiritsDestroyed];
+	Common::Array<Common::Rect> keyRects;
+
 	if (isDOS()) {
 		g_system->lockMouse(false);
 		g_system->showMouse(true);
@@ -512,10 +514,15 @@ void CastleEngine::drawInfoMenu() {
 		drawStringInSurface(spiritsDestroyedString, 145 , 132,  front, black, surface);
 
 		for (int  i = 0; i < int(_keysCollected.size()) ; i++) {
-			if (i % 2 == 0)
-				surface->copyRectToSurfaceWithKey(*_keysBorderFrames[i], 58, 58 + (i / 2) * 18, Common::Rect(0, 0, _keysBorderFrames[i]->w, _keysBorderFrames[i]->h), black);
-			else
-				surface->copyRectToSurfaceWithKey(*_keysBorderFrames[i], 80, 58 + (i / 2) * 18, Common::Rect(0, 0, _keysBorderFrames[i]->w, _keysBorderFrames[i]->h), black);
+			int y = 58 + (i / 2) * 18;
+
+			if (i % 2 == 0) {
+				surface->copyRectToSurfaceWithKey(*_keysBorderFrames[i], 58, y, Common::Rect(0, 0, _keysBorderFrames[i]->w, _keysBorderFrames[i]->h), black);
+				keyRects.push_back(Common::Rect(58, y, 58 + _keysBorderFrames[i]->w / 2, y + _keysBorderFrames[i]->h));
+			} else {
+				surface->copyRectToSurfaceWithKey(*_keysBorderFrames[i], 80, y, Common::Rect(0, 0, _keysBorderFrames[i]->w, _keysBorderFrames[i]->h), black);
+				keyRects.push_back(Common::Rect(80, y, 80 + _keysBorderFrames[i]->w / 2, y + _keysBorderFrames[i]->h));
+			}
 		}
 	} else if (isSpectrum()) {
 		Common::Array<Common::String> lines;
@@ -544,10 +551,20 @@ void CastleEngine::drawInfoMenu() {
 		surface = drawStringsInSurface(lines, surface);
 	}
 
-	Texture *menuTexture = _gfx->createTexture(surface);
 	Common::Event event;
 	Common::Point mousePos;
 	bool cont = true;
+
+	Common::Rect loadGameRect(101, 67, 133, 79);
+	Common::Rect saveGameRect(101, 82, 133, 95);
+	Common::Rect toggleSoundRect(101, 101, 133, 114);
+	Common::Rect cycleRect(101, 116, 133, 129);
+	Common::Rect backRect(101, 131, 133, 144);
+
+	Graphics::Surface *originalSurface = new Graphics::Surface();
+	originalSurface->copyFrom(*surface);
+
+	Texture *menuTexture = _gfx->createTexture(surface);
 	while (!shouldQuit() && cont) {
 		while (_eventManager->pollEvent(event)) {
 
@@ -557,8 +574,10 @@ void CastleEngine::drawInfoMenu() {
 				if (event.customType == kActionLoad) {
 					_gfx->setViewport(_fullscreenViewArea);
 					_eventManager->purgeKeyboardEvents();
+					_eventManager->purgeMouseEvents();
 
 					loadGameDialog();
+					_eventManager->purgeMouseEvents();
 					if (isDOS() || isAmiga() || isAtariST()) {
 						g_system->lockMouse(false);
 						g_system->showMouse(true);
@@ -568,8 +587,10 @@ void CastleEngine::drawInfoMenu() {
 				} else if (event.customType == kActionSave) {
 					_gfx->setViewport(_fullscreenViewArea);
 					_eventManager->purgeKeyboardEvents();
+					_eventManager->purgeMouseEvents();
 
 					saveGameDialog();
+					_eventManager->purgeMouseEvents();
 					if (isDOS() || isAmiga() || isAtariST()) {
 						g_system->lockMouse(false);
 						g_system->showMouse(true);
@@ -598,7 +619,17 @@ void CastleEngine::drawInfoMenu() {
 					break;
 
 				mousePos = getNormalizedPosition(event.mouse);
-				if (Common::Rect(101, 67, 133, 79).contains(mousePos)) {
+				for (int i = 0; i < int(keyRects.size()); i++) {
+					if (keyRects[i].contains(mousePos)) {
+						surface->copyFrom(*originalSurface);
+						surface->frameRect(keyRects[i], front);
+						drawStringInSurface(_messagesList[ 145 + _keysCollected[i] ], 103, 41,  front, black, surface);
+						menuTexture->update(surface);
+						break;
+					}
+				}
+
+				if (loadGameRect.contains(mousePos)) {
 					_gfx->setViewport(_fullscreenViewArea);
 					_eventManager->purgeKeyboardEvents();
 					loadGameDialog();
@@ -606,7 +637,7 @@ void CastleEngine::drawInfoMenu() {
 					g_system->showMouse(true);
 
 					_gfx->setViewport(_viewArea);
-				} else if (Common::Rect(101, 82, 133, 95).contains(mousePos)) {
+				} else if (saveGameRect.contains(mousePos)) {
 					_gfx->setViewport(_fullscreenViewArea);
 					_eventManager->purgeKeyboardEvents();
 					saveGameDialog();
@@ -614,12 +645,12 @@ void CastleEngine::drawInfoMenu() {
 					g_system->showMouse(true);
 
 					_gfx->setViewport(_viewArea);
-				} else if (Common::Rect(101, 101, 133, 114).contains(mousePos)) {
+				} else if (toggleSoundRect.contains(mousePos)) {
 					// Toggle sounds
-				} else if (Common::Rect(101, 116, 133, 129).contains(mousePos)) {
+				} else if (cycleRect.contains(mousePos)) {
 					// Cycle between crawl, walk or run
 					// It can fail if there is no room
-				} else if (Common::Rect(101, 131, 133, 144).contains(mousePos))
+				} else if (backRect.contains(mousePos))
 					cont = false; // Back to game
 				break;
 			default:
@@ -639,8 +670,12 @@ void CastleEngine::drawInfoMenu() {
 	_savedScreen->free();
 	delete _savedScreen;
 	_savedScreen = nullptr;
+
+	originalSurface->free();
+	delete originalSurface;
 	surface->free();
 	delete surface;
+
 	delete menuTexture;
 	pauseToken.clear();
 	g_system->lockMouse(true);
@@ -790,8 +825,6 @@ void CastleEngine::drawFullscreenGameOverAndWait() {
 	delete surface;
 }
 
-
-
 // Same as FreescapeEngine::executeExecute but updates the spirits destroyed counter
 void CastleEngine::executeDestroy(FCLInstruction &instruction) {
 	uint16 objectID = 0;


Commit: 738a8a17f80491d92e8d828eb4d1bd317a0d3aa7
    https://github.com/scummvm/scummvm/commit/738a8a17f80491d92e8d828eb4d1bd317a0d3aa7
Author: neuromancer (gustavo.grieco at gmail.com)
Date: 2024-10-31T22:03:59+01:00

Commit Message:
FREESCAPE: refactor and fix some conditional code in castle

Changed paths:
    engines/freescape/games/castle/castle.cpp
    engines/freescape/games/castle/castle.h
    engines/freescape/games/castle/dos.cpp
    engines/freescape/games/castle/zx.cpp
    engines/freescape/language/instruction.cpp
    engines/freescape/movement.cpp


diff --git a/engines/freescape/games/castle/castle.cpp b/engines/freescape/games/castle/castle.cpp
index 637f460028c..15ad2994452 100644
--- a/engines/freescape/games/castle/castle.cpp
+++ b/engines/freescape/games/castle/castle.cpp
@@ -43,7 +43,9 @@ CastleEngine::CastleEngine(OSystem *syst, const ADGameDescription *gd) : Freesca
 	_soundIndexAreaChange = 5;
 	k8bitVariableShield = 29;
 
-	if (isSpectrum())
+	if (isDOS())
+		initDOS();
+	else if (isSpectrum())
 		initZX();
 
 	_playerHeightNumber = 1;
@@ -876,6 +878,35 @@ void CastleEngine::executeRedraw(FCLInstruction &instruction) {
 
 void CastleEngine::loadAssets() {
 	FreescapeEngine::loadAssets();
+
+	addGhosts();
+	// Discard the first three global conditions
+	// It is unclear why they hide/unhide objects that formed the spirits
+	for (int i = 0; i < 3; i++) {
+		debugC(kFreescapeDebugParser, "Discarding condition %s", _conditionSources[1].c_str());
+		_conditions.remove_at(1);
+		_conditionSources.remove_at(1);
+	}
+
+	_endArea = 1;
+	_endEntrance = 42;
+
+	_timeoutMessage = _messagesList[1];
+	// Shield is unused in Castle Master
+	_noEnergyMessage = _messagesList[2];
+	_crushedMessage = _messagesList[3];
+	_fallenMessage = _messagesList[4];
+	_outOfReachMessage = _messagesList[7];
+	_noEffectMessage = _messagesList[8];
+
+	Graphics::Surface *tmp;
+	tmp = loadBundledImage("castle_gate", !isDOS());
+	_gameOverBackgroundFrame = new Graphics::ManagedSurface;
+	_gameOverBackgroundFrame->copyFrom(*tmp);
+	_gameOverBackgroundFrame->convertToInPlace(_gfx->_texturePixelFormat);
+	tmp->free();
+	delete tmp;
+
 	if (isDOS()) {
 		for (auto &it : _areaMap) {
 			it._value->addStructure(_areaMap[255]);
diff --git a/engines/freescape/games/castle/castle.h b/engines/freescape/games/castle/castle.h
index 269824ef82f..c0c8812c830 100644
--- a/engines/freescape/games/castle/castle.h
+++ b/engines/freescape/games/castle/castle.h
@@ -64,6 +64,7 @@ public:
 	void drawOption();
 
 	void initZX();
+	void initDOS();
 
 	void drawDOSUI(Graphics::Surface *surface) override;
 	void drawZXUI(Graphics::Surface *surface) override;
diff --git a/engines/freescape/games/castle/dos.cpp b/engines/freescape/games/castle/dos.cpp
index 1dc21812d18..ac767e9dd87 100644
--- a/engines/freescape/games/castle/dos.cpp
+++ b/engines/freescape/games/castle/dos.cpp
@@ -142,13 +142,15 @@ Graphics::ManagedSurface *CastleEngine::loadFrameWithHeaderDOS(Common::SeekableR
 	return frame;
 }
 
+void CastleEngine::initDOS() {
+	_viewArea = Common::Rect(40, 33 - 2, 280, 152);
+}
+
 void CastleEngine::loadAssetsDOSFullGame() {
 	Common::File file;
 	Common::SeekableReadStream *stream = nullptr;
 
 	if (_renderMode == Common::kRenderEGA) {
-		_viewArea = Common::Rect(40, 33 - 2, 280, 152);
-
 		file.open("CME.EXE");
 		stream = unpackEXE(file);
 		if (stream) {
@@ -296,25 +298,6 @@ void CastleEngine::loadAssetsDOSFullGame() {
 	} else
 		error("Not implemented yet");
 
-	addGhosts();
-	// Discard the first three global conditions
-	// It is unclear why they hide/unhide objects that formed the spirits
-	for (int i = 0; i < 3; i++) {
-		debugC(kFreescapeDebugParser, "Discarding condition %s", _conditionSources[1].c_str());
-		_conditions.remove_at(1);
-		_conditionSources.remove_at(1);
-	}
-
-	_endArea = 1;
-	_endEntrance = 42;
-
-	Graphics::Surface *tmp;
-	tmp = loadBundledImage("castle_gate", false);
-	_gameOverBackgroundFrame = new Graphics::ManagedSurface;
-	_gameOverBackgroundFrame->copyFrom(*tmp);
-	_gameOverBackgroundFrame->convertToInPlace(_gfx->_texturePixelFormat);
-	tmp->free();
-	delete tmp;
 
 	// CPC
 	// file = gameDir.createReadStreamForMember("cm.bin");
@@ -328,8 +311,6 @@ void CastleEngine::loadAssetsDOSDemo() {
 	Common::SeekableReadStream *stream = nullptr;
 
 	if (_renderMode == Common::kRenderEGA) {
-		_viewArea = Common::Rect(40, 33, 280, 152);
-
 		file.open("CMDE.EXE");
 		stream = unpackEXE(file);
 		if (stream) {
@@ -441,26 +422,6 @@ void CastleEngine::loadAssetsDOSDemo() {
 	} else
 		error("Not implemented yet");
 
-
-	addGhosts();
-	// Discard the first three global conditions
-	// It is unclear why they hide/unhide objects that formed the spirits
-	for (int i = 0; i < 3; i++) {
-		debugC(kFreescapeDebugParser, "Discarding condition %s", _conditionSources[1].c_str());
-		_conditions.remove_at(1);
-		_conditionSources.remove_at(1);
-	}
-
-	_endArea = 1;
-	_endEntrance = 42;
-
-	Graphics::Surface *tmp;
-	tmp = loadBundledImage("castle_gate", false);
-	_gameOverBackgroundFrame = new Graphics::ManagedSurface;
-	_gameOverBackgroundFrame->copyFrom(*tmp);
-	_gameOverBackgroundFrame->convertToInPlace(_gfx->_texturePixelFormat);
-	tmp->free();
-	delete tmp;
 }
 
 void CastleEngine::drawDOSUI(Graphics::Surface *surface) {
diff --git a/engines/freescape/games/castle/zx.cpp b/engines/freescape/games/castle/zx.cpp
index e8c73b7cec8..a857435d080 100644
--- a/engines/freescape/games/castle/zx.cpp
+++ b/engines/freescape/games/castle/zx.cpp
@@ -197,7 +197,6 @@ void CastleEngine::loadAssetsZXFullGame() {
 	_thunderFrame = loadFrame(&file, _thunderFrame, thunderWidth, thunderHeight, front);
 
 	Graphics::Surface *tmp;
-
 	tmp = loadBundledImage("castle_riddle_top_frame");
 	_riddleTopFrame = new Graphics::ManagedSurface;
 	_riddleTopFrame->copyFrom(*tmp);
@@ -234,35 +233,8 @@ void CastleEngine::loadAssetsZXFullGame() {
 			it._value->addObjectFromArea(id, _areaMap[255]);
 		}
 	}
-	addGhosts();
 	_areaMap[1]->addFloor();
 	_areaMap[2]->addFloor();
-
-	// Discard the first three global conditions
-	// It is unclear why they hide/unhide objects that formed the spirits
-	for (int i = 0; i < 3; i++) {
-		debugC(kFreescapeDebugParser, "Discarding condition %s", _conditionSources[0].c_str());
-		_conditions.remove_at(0);
-		_conditionSources.remove_at(0);
-	}
-
-	_timeoutMessage = _messagesList[1];
-	// Shield is unused in Castle Master
-	_noEnergyMessage = _messagesList[1];
-	_fallenMessage = _messagesList[4];
-	_crushedMessage = _messagesList[3];
-	_outOfReachMessage = _messagesList[7];
-	_noEffectMessage = _messagesList[8];
-
-	_endArea = 1;
-	_endEntrance = 42;
-
-	tmp = loadBundledImage("castle_gate");
-	_gameOverBackgroundFrame = new Graphics::ManagedSurface;
-	_gameOverBackgroundFrame->copyFrom(*tmp);
-	_gameOverBackgroundFrame->convertToInPlace(_gfx->_texturePixelFormat);
-	tmp->free();
-	delete tmp;
 }
 
 void CastleEngine::drawZXUI(Graphics::Surface *surface) {
diff --git a/engines/freescape/language/instruction.cpp b/engines/freescape/language/instruction.cpp
index 0ccf4395f2b..e23ce7423f1 100644
--- a/engines/freescape/language/instruction.cpp
+++ b/engines/freescape/language/instruction.cpp
@@ -187,7 +187,7 @@ bool FreescapeEngine::executeCode(FCLInstructionVector &code, bool shot, bool co
 			continue;
 		}
 
-		if (instruction.getType() != Token::CONDITIONAL)
+		if (instruction.getType() != Token::CONDITIONAL && !instruction.isConditional())
 			executed = true;
 
 		switch (instruction.getType()) {
@@ -200,7 +200,7 @@ bool FreescapeEngine::executeCode(FCLInstructionVector &code, bool shot, bool co
 
 		case Token::CONDITIONAL:
 			if (checkConditional(instruction, shot, collided, timer, activated))
-				executeCode(*instruction._thenInstructions, shot, collided, timer, activated);
+				executed = executeCode(*instruction._thenInstructions, shot, collided, timer, activated);
 			// else branch is always empty
 			assert(instruction._elseInstructions == nullptr);
 			break;
diff --git a/engines/freescape/movement.cpp b/engines/freescape/movement.cpp
index f070553b1c5..204ca5905cc 100644
--- a/engines/freescape/movement.cpp
+++ b/engines/freescape/movement.cpp
@@ -199,6 +199,9 @@ void FreescapeEngine::activate() {
 			debugC(1, kFreescapeDebugMove, "Must use interact = true when executing: %s", gobj->_conditionSource.c_str());
 
 		executeObjectConditions(gobj, false, false, true);
+	} else {
+		if (!_outOfReachMessage.empty())
+			insertTemporaryMessage(_outOfReachMessage, _countdown - 2);
 	}
 	//executeLocalGlobalConditions(true, false, false); // Only execute "on shot" room/global conditions
 }




More information about the Scummvm-git-logs mailing list