[Scummvm-git-logs] scummvm master -> 8f775a4cc214a6f83a8536f62bf85c8518ce65a9

sev- noreply at scummvm.org
Fri Jan 20 11:07:27 UTC 2023


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:
8f775a4cc2 NEVERHOOD: Reload BOBBY puzzle when changing languages with NHC.


Commit: 8f775a4cc214a6f83a8536f62bf85c8518ce65a9
    https://github.com/scummvm/scummvm/commit/8f775a4cc214a6f83a8536f62bf85c8518ce65a9
Author: Vladimir Serbinenko (phcoder at gmail.com)
Date: 2023-01-20T12:07:23+01:00

Commit Message:
NEVERHOOD: Reload BOBBY puzzle when changing languages with NHC.

This has slightly different logic that original NHC override library.
Original library attempts to rotate the solution and current state by the
same amount. We do the following:

1. If correct solution didn't change, load as usual
2. If correct solution changed and puzzle was already solved, set both current
   and correct solution to the new correct solution
3. If correct solution changed and puzzle was not already solved, reinit the
   puzzle

Changed paths:
    engines/neverhood/gamemodule.cpp
    engines/neverhood/gamemodule.h
    engines/neverhood/saveload.cpp


diff --git a/engines/neverhood/gamemodule.cpp b/engines/neverhood/gamemodule.cpp
index e10e61e0dd0..927537b6ecb 100644
--- a/engines/neverhood/gamemodule.cpp
+++ b/engines/neverhood/gamemodule.cpp
@@ -292,6 +292,24 @@ void GameModule::initCubeSymbolsPuzzle() {
 	}
 }
 
+byte GameModule::parseCrystalColor(char colorLetter) {
+	switch (colorLetter) {
+	case 'B':
+		return 4;
+	case 'G':
+		return 3;
+	case 'O':
+		return 1;
+	case 'R':
+		return 0;
+	case 'V':
+		return 5;
+	case 'Y':
+		return 2;
+	default:
+		return 0;
+	}
+}
 void GameModule::initCrystalColorsPuzzle() {
 	if (!getGlobalVar(V_CRYSTAL_COLORS_INIT)) {
 		TextResource textResource(_vm);
@@ -300,29 +318,7 @@ void GameModule::initCrystalColorsPuzzle() {
 		textStart = textResource.getString(0, textEnd);
 		for (uint index = 0; index < 5; index++) {
 			char colorLetter = (byte)textStart[index];
-			byte correctColorNum = 0, misalignedColorNum;
-			switch (colorLetter) {
-			case 'B':
-				correctColorNum = 4;
-				break;
-			case 'G':
-				correctColorNum = 3;
-				break;
-			case 'O':
-				correctColorNum = 1;
-				break;
-			case 'R':
-				correctColorNum = 0;
-				break;
-			case 'V':
-				correctColorNum = 5;
-				break;
-			case 'Y':
-				correctColorNum = 2;
-				break;
-			default:
-				break;
-			}
+			byte correctColorNum = parseCrystalColor(colorLetter), misalignedColorNum;
 			do {
 				misalignedColorNum = _vm->_rnd->getRandomNumber(6 - 1);
 			} while (misalignedColorNum == correctColorNum);
diff --git a/engines/neverhood/gamemodule.h b/engines/neverhood/gamemodule.h
index 52eae03358f..99d0acb245e 100644
--- a/engines/neverhood/gamemodule.h
+++ b/engines/neverhood/gamemodule.h
@@ -60,6 +60,7 @@ public:
 	int getPreviousModuleNum() { return _moduleNum; }
 
 	void createModule(int moduleNum, int which);
+	static byte parseCrystalColor(char colorLetter);
 protected:
 	int _moduleNum;
 	Entity *_prevChildObject;
diff --git a/engines/neverhood/saveload.cpp b/engines/neverhood/saveload.cpp
index 94a040c164b..f9199da8fc7 100644
--- a/engines/neverhood/saveload.cpp
+++ b/engines/neverhood/saveload.cpp
@@ -119,6 +119,38 @@ bool NeverhoodEngine::loadgame(const char *filename) {
 
 	_gameVars->loadState(in);
 
+	// If user has changed NHC it may have changed the correct solution for
+	// crystal puzzle. If it did and it was already solved, changed solors to the new solution
+	// if it wasn't solved, just let the code do full reinit.
+	if (_gameVars->getGlobalVar(V_CRYSTAL_COLORS_INIT)) {
+		TextResource textResource(this);
+		const char *textStart, *textEnd;
+		bool colorsChanged = false, colorsAreCorrect = true;
+		textResource.load(0x46691611);
+		textStart = textResource.getString(0, textEnd);
+		byte newCorrectColorNum[5];
+		for (uint index = 0; index < 5; index++) {
+			newCorrectColorNum[index] = GameModule::parseCrystalColor(textStart[index]);
+		}
+		for (uint index = 0; index < 5; index++) {
+			if (_gameVars->getSubVar(VA_GOOD_CRYSTAL_COLORS, index) != newCorrectColorNum[index]) {
+				colorsChanged = true;
+			}
+			if (_gameVars->getSubVar(VA_GOOD_CRYSTAL_COLORS, index) != _gameVars->getSubVar(VA_CURR_CRYSTAL_COLORS, index)) {
+				colorsAreCorrect = false;
+			}
+		}
+		if (colorsChanged && colorsAreCorrect) {
+			for (uint index = 0; index < 5; index++) {
+				_gameVars->setSubVar(VA_GOOD_CRYSTAL_COLORS, index, newCorrectColorNum[index]);
+				_gameVars->setSubVar(VA_CURR_CRYSTAL_COLORS, index, newCorrectColorNum[index]);
+			}
+		}
+		if (colorsChanged && !colorsAreCorrect) {
+			_gameVars->setGlobalVar(V_CRYSTAL_COLORS_INIT, 0);
+		}
+	}
+
 	_gameState.sceneNum = _gameVars->getGlobalVar(V_CURRENT_SCENE);
 	_gameState.which = _gameVars->getGlobalVar(V_CURRENT_SCENE_WHICH);
 




More information about the Scummvm-git-logs mailing list