[Scummvm-git-logs] scummvm master -> 4623096adc5ef4ae91244c0281d21c22fbfa591a

dreammaster paulfgilbert at gmail.com
Sun Apr 26 19:55:58 UTC 2020


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

Summary:
55d3598a47 ULTIMA4: Refactor codex code into it's own class
7742473312 ULTIMA4: Move map loaders into the engine class
d243684ae2 ULTIMA4: Script _actionMap doesn't need to be static
4623096adc ULTIMA4: Fix transparency of tiles drawn on the map


Commit: 55d3598a472763a98e05483d53a335b5797305ce
    https://github.com/scummvm/scummvm/commit/55d3598a472763a98e05483d53a335b5797305ce
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-04-26T12:30:11-07:00

Commit Message:
ULTIMA4: Refactor codex code into it's own class

Changed paths:
    engines/ultima/ultima4/game/codex.cpp
    engines/ultima/ultima4/game/codex.h
    engines/ultima/ultima4/game/item.cpp
    engines/ultima/ultima4/ultima4.cpp
    engines/ultima/ultima4/ultima4.h


diff --git a/engines/ultima/ultima4/game/codex.cpp b/engines/ultima/ultima4/game/codex.cpp
index 0285ca2eb7..fc1dd8c747 100644
--- a/engines/ultima/ultima4/game/codex.cpp
+++ b/engines/ultima/ultima4/game/codex.cpp
@@ -37,86 +37,64 @@
 namespace Ultima {
 namespace Ultima4 {
 
-using namespace std;
-
-int codexInit();
-void codexDelete();
-void codexEject(CodexEjectCode code);
-void codexHandleWOP(const Common::String &word);
-void codexHandleVirtues(const Common::String &virtue);
-void codexHandleInfinity(const Common::String &answer);
-void codexImpureThoughts();
-
-/**
- * Key handlers
- */
-bool codexHandleInfinityAnyKey(int key, void *data);
-bool codexHandleEndgameAnyKey(int key, void *data);
+Codex *g_codex;
 
-Std::vector<Common::String> codexVirtueQuestions;
-Std::vector<Common::String> codexEndgameText1;
-Std::vector<Common::String> codexEndgameText2;
+Codex::Codex() {
+	g_codex = this;
+}
 
-/**
- * Initializes the Chamber of the Codex sequence (runs from codexStart())
- */
-int codexInit() {
+Codex::~Codex() {
+	g_codex = nullptr;
+}
+
+int Codex::init() {
 	Common::File *avatar;
 
 	avatar = u4fopen("avatar.exe");
 	if (!avatar)
 		return 0;
 
-	codexVirtueQuestions = u4read_stringtable(avatar, 0x0fc7b, 11);
-	codexEndgameText1 = u4read_stringtable(avatar, 0x0fee4, 7);
-	codexEndgameText2 = u4read_stringtable(avatar, 0x10187, 5);
+	_virtueQuestions = u4read_stringtable(avatar, 0x0fc7b, 11);
+	_endgameText1 = u4read_stringtable(avatar, 0x0fee4, 7);
+	_endgameText2 = u4read_stringtable(avatar, 0x10187, 5);
 
 	u4fclose(avatar);
 
 	return 1;
 }
 
-/**
- * Frees all memory associated with the Codex sequence
- */
-void codexDelete() {
-	codexVirtueQuestions.clear();
-	codexEndgameText1.clear();
-	codexEndgameText2.clear();
+void Codex::deinit() {
+	_virtueQuestions.clear();
+	_endgameText1.clear();
+	_endgameText2.clear();
 }
 
-void codexStart() {
-	codexInit();
+void Codex::start() {
+	init();
 
-	/**
-	 * disable the whirlpool cursor and black out the screen
-	 */
+	// Disable the whirlpool cursor and black out the screen	
 #ifdef IOS_ULTIMA4
 	U4IOS::IOSHideGameControllerHelper hideControllsHelper;
 #endif
 	g_screen->screenDisableCursor();
 	g_screen->screenUpdate(&g_game->_mapArea, false, true);
 
-	/**
-	 * make the avatar alone
-	 */
+	// Make the avatar alone
+	
 	g_context->_stats->setView(STATS_PARTY_OVERVIEW);
-	g_context->_stats->update(true);     /* show just the avatar */
+	g_context->_stats->update(true);     // show just the avatar
 	g_screen->update();
 
-	/**
-	 * change the view mode so the dungeon doesn't get shown
-	 */
+	// Change the view mode so the dungeon doesn't get shown
+	
 	gameSetViewMode(VIEW_CODEX);
 
 	g_screen->screenMessage("\n\n\n\nThere is a sudden darkness, and you find yourself alone in an empty chamber.\n");
 	EventHandler::sleep(4000);
 
-	/**
-	 * check to see if you have the 3-part key
-	 */
+	// Check to see if you have the 3-part key	
 	if ((g_ultima->_saveGame->_items & (ITEM_KEY_C | ITEM_KEY_L | ITEM_KEY_T)) != (ITEM_KEY_C | ITEM_KEY_L | ITEM_KEY_T)) {
-		codexEject(CODEX_EJECT_NO_3_PART_KEY);
+		eject(CODEX_EJECT_NO_3_PART_KEY);
 		return;
 	}
 
@@ -128,21 +106,15 @@ void codexStart() {
 
 	g_screen->screenMessage("\nA voice rings out:\n\"What is the Word of Passage?\"\n\n");
 
-	/**
-	 * Get the Word of Passage
-	 */
+	// Get the Word of Passage	
 #ifdef IOS_ULTIMA4
 	U4IOS::IOSConversationHelper::setIntroString("What is the Word of Passage?");
 #endif
-	codexHandleWOP(gameGetInput());
+	handleWOP(gameGetInput());
 }
 
-/**
- * Ejects you from the chamber of the codex (and the Abyss, for that matter)
- * with the correct message.
- */
-void codexEject(CodexEjectCode code) {
-	struct {
+void Codex::eject(CodexEjectCode code) {
+	const struct {
 		int x, y;
 	} startLocations[] = {
 		{ 231, 136 },
@@ -195,19 +167,19 @@ void codexEject(CodexEjectCode code) {
 
 	EventHandler::sleep(2000);
 
-	/* free memory associated with the Codex */
-	codexDelete();
+	// Free memory associated with the Codex
+	deinit();
 
-	/* re-enable the cursor and show it */
+	// Re-enable the cursor and show it
 	g_screen->screenEnableCursor();
 	g_screen->screenShowCursor();
 
-	/* return view to normal and exit the Abyss */
+	// Return view to normal and exit the Abyss
 	gameSetViewMode(VIEW_NORMAL);
 	g_game->exitToParentMap();
 	g_music->play();
 
-	/**
+	/*
 	 * if being ejected because of a missed virtue question,
 	 * then teleport the party to the starting location for
 	 * that virtue.
@@ -218,39 +190,36 @@ void codexEject(CodexEjectCode code) {
 		g_context->_location->_coords.y = startLocations[virtue].y;
 	}
 
-	/* finally, finish the turn */
+	// finally, finish the turn
 	g_context->_location->_turnCompleter->finishTurn();
 	eventHandler->setController(g_game);
 }
 
-/**
- * Handles entering the Word of Passage
- */
-void codexHandleWOP(const Common::String &word) {
+void Codex::handleWOP(const Common::String &word) {
 	static int tries = 1;
 	int i;
 
 	eventHandler->popKeyHandler();
 
-	/* slight pause before continuing */
+	// slight pause before continuing
 	g_screen->screenMessage("\n");
 	g_screen->screenDisableCursor();
 	EventHandler::sleep(1000);
 
-	/* entered correctly */
+	// entered correctly
 	if (scumm_stricmp(word.c_str(), "veramocor") == 0) {
-		tries = 1; /* reset 'tries' in case we need to enter this again later */
+		tries = 1; // reset 'tries' in case we need to enter this again later
 
-		/* eject them if they don't have all 8 party members */
+		// eject them if they don't have all 8 party members
 		if (g_ultima->_saveGame->_members != 8) {
-			codexEject(CODEX_EJECT_NO_FULL_PARTY);
+			eject(CODEX_EJECT_NO_FULL_PARTY);
 			return;
 		}
 
-		/* eject them if they're not a full avatar at this point */
+		// eject them if they're not a full avatar at this point
 		for (i = 0; i < VIRT_MAX; i++) {
 			if (g_ultima->_saveGame->_karma[i] != 0) {
-				codexEject(CODEX_EJECT_NO_FULL_AVATAR);
+				eject(CODEX_EJECT_NO_FULL_AVATAR);
 				return;
 			}
 		}
@@ -261,37 +230,34 @@ void codexHandleWOP(const Common::String &word) {
 		g_screen->screenEraseMapArea();
 		g_screen->screenRedrawMapArea();
 
-		/* Ask the Virtue questions */
+		// Ask the Virtue questions
 		g_screen->screenMessage("\n\nThe voice asks:\n");
 		EventHandler::sleep(2000);
-		g_screen->screenMessage("\n%s\n\n", codexVirtueQuestions[0].c_str());
+		g_screen->screenMessage("\n%s\n\n", _virtueQuestions[0].c_str());
 
-		codexHandleVirtues(gameGetInput());
+		handleVirtues(gameGetInput());
 
 		return;
 	}
 
-	/* entered incorrectly - give 3 tries before ejecting */
+	// entered incorrectly - give 3 tries before ejecting
 	else if (tries++ < 3) {
-		codexImpureThoughts();
+		impureThoughts();
 		g_screen->screenMessage("\"What is the Word of Passage?\"\n\n");
 #ifdef IOS_ULTIMA4
 		U4IOS::IOSConversationHelper::setIntroString("Which virtue?");
 #endif
-		codexHandleWOP(gameGetInput());
+		handleWOP(gameGetInput());
 	}
 
-	/* 3 tries are up... eject! */
+	// 3 tries are up... eject!
 	else {
 		tries = 1;
-		codexEject(CODEX_EJECT_BAD_WOP);
+		eject(CODEX_EJECT_BAD_WOP);
 	}
 }
 
-/**
- * Handles naming of virtues in the Chamber of the Codex
- */
-void codexHandleVirtues(const Common::String &virtue) {
+void Codex::handleVirtues(const Common::String &virtue) {
 	static const char *codexImageNames[] = {
 		BKGD_HONESTY, BKGD_COMPASSN, BKGD_VALOR, BKGD_JUSTICE,
 		BKGD_SACRIFIC, BKGD_HONOR, BKGD_SPIRIT, BKGD_HUMILITY,
@@ -303,12 +269,12 @@ void codexHandleVirtues(const Common::String &virtue) {
 
 	eventHandler->popKeyHandler();
 
-	/* slight pause before continuing */
+	// slight pause before continuing
 	g_screen->screenMessage("\n");
 	g_screen->screenDisableCursor();
 	EventHandler::sleep(1000);
 
-	/* answered with the correct one of eight virtues */
+	// answered with the correct one of eight virtues
 	if ((current < VIRT_MAX) &&
 	        (scumm_stricmp(virtue.c_str(), getVirtueName(static_cast<Virtue>(current))) == 0)) {
 
@@ -327,14 +293,14 @@ void codexHandleVirtues(const Common::String &virtue) {
 
 		g_screen->screenMessage("\n\nThe voice asks:\n");
 		EventHandler::sleep(2000);
-		g_screen->screenMessage("\n%s\n\n", codexVirtueQuestions[current].c_str());
+		g_screen->screenMessage("\n%s\n\n", _virtueQuestions[current].c_str());
 #ifdef IOS_ULTIMA4
 		U4IOS::IOSConversationHelper::setIntroString((current != VIRT_MAX) ? "Which virtue?" : "Which principle?");
 #endif
-		codexHandleVirtues(gameGetInput());
+		handleVirtues(gameGetInput());
 	}
 
-	/* answered with the correct base virtue (truth, love, courage) */
+	// answered with the correct base virtue (truth, love, courage)
 	else if ((current >= VIRT_MAX) &&
 	         (scumm_stricmp(virtue.c_str(), getBaseVirtueName(static_cast<BaseVirtue>(1 << (current - VIRT_MAX)))) == 0)) {
 
@@ -347,11 +313,11 @@ void codexHandleVirtues(const Common::String &virtue) {
 		if (current < VIRT_MAX + 3) {
 			g_screen->screenMessage("\n\nThe voice asks:\n");
 			EventHandler::sleep(2000);
-			g_screen->screenMessage("\n%s\n\n", codexVirtueQuestions[current].c_str());
+			g_screen->screenMessage("\n%s\n\n", _virtueQuestions[current].c_str());
 #ifdef IOS_ULTIMA4
 			U4IOS::IOSConversationHelper::setIntroString("Which principle?");
 #endif
-			codexHandleVirtues(gameGetInput());
+			handleVirtues(gameGetInput());
 		} else {
 			g_screen->screenMessage("\nThe ground rumbles beneath your feet.\n");
 			EventHandler::sleep(1000);
@@ -365,30 +331,30 @@ void codexHandleVirtues(const Common::String &virtue) {
 			U4IOS::beginChoiceConversation();
 			U4IOS::updateChoicesInDialog(" ", "", -1);
 #endif
-			eventHandler->pushKeyHandler(&codexHandleInfinityAnyKey);
+			eventHandler->pushKeyHandler(&handleInfinityAnyKey);
 		}
 	}
 
-	/* give them 3 tries to enter the correct virtue, then eject them! */
+	// give them 3 tries to enter the correct virtue, then eject them!
 	else if (tries++ < 3) {
-		codexImpureThoughts();
-		g_screen->screenMessage("%s\n\n", codexVirtueQuestions[current].c_str());
+		impureThoughts();
+		g_screen->screenMessage("%s\n\n", _virtueQuestions[current].c_str());
 #ifdef IOS_ULTIMA4
 		U4IOS::IOSConversationHelper::setIntroString("Which virtue?");
 #endif
-		codexHandleVirtues(gameGetInput());
+		handleVirtues(gameGetInput());
 	}
 
-	/* failed 3 times... eject! */
+	// failed 3 times... eject!
 	else {
-		codexEject(static_cast<CodexEjectCode>(CODEX_EJECT_HONESTY + current));
+		eject(static_cast<CodexEjectCode>(CODEX_EJECT_HONESTY + current));
 
 		tries = 1;
 		current = 0;
 	}
 }
 
-bool codexHandleInfinityAnyKey(int key, void *data) {
+bool Codex::handleInfinityAnyKey(int key, void *data) {
 	eventHandler->popKeyHandler();
 
 	g_screen->screenMessage("\n\nThen what is the one thing which encompasses and is the whole of all undeniable Truth, unending Love, and unyielding Courage?\n\n");
@@ -396,18 +362,18 @@ bool codexHandleInfinityAnyKey(int key, void *data) {
 	U4IOS::endChoiceConversation();
 	U4IOS::IOSConversationHelper::setIntroString("What is the whole of all undeniable Truth, unending Love, and unyielding Courage?");
 #endif
-	codexHandleInfinity(gameGetInput());
+	g_codex->handleInfinity(gameGetInput());
 	return true;
 }
 
-void codexHandleInfinity(const Common::String &answer) {
+void Codex::handleInfinity(const Common::String &answer) {
 	static int tries = 1;
 
 	eventHandler->popKeyHandler();
 #ifdef IOS_ULTIMA4
 	U4IOS::IOSHideGameControllerHelper hideControllsHelper;
 #endif
-	/* slight pause before continuing */
+	// slight pause before continuing
 	g_screen->screenMessage("\n");
 	g_screen->screenDisableCursor();
 	EventHandler::sleep(1000);
@@ -417,7 +383,7 @@ void codexHandleInfinity(const Common::String &answer) {
 		g_screen->screenShake(10);
 
 		g_screen->screenEnableCursor();
-		g_screen->screenMessage("\n%s", codexEndgameText1[0].c_str());
+		g_screen->screenMessage("\n%s", _endgameText1[0].c_str());
 #ifdef IOS_ULTIMA4
 		// Ugh, we now enter happy callback land, so I know how to do these things manually. Good thing I kept these separate functions.
 		U4IOS::hideGameButtons();
@@ -425,15 +391,15 @@ void codexHandleInfinity(const Common::String &answer) {
 		U4IOS::updateChoicesInDialog(" ", "", -1);
 		U4IOS::testFlightPassCheckPoint("Game won!");
 #endif
-		eventHandler->pushKeyHandler(&codexHandleEndgameAnyKey);
+		eventHandler->pushKeyHandler(&handleEndgameAnyKey);
 	} else if (tries++ < 3) {
-		codexImpureThoughts();
+		impureThoughts();
 		g_screen->screenMessage("\nAbove the din, the voice asks:\n\nIf all eight virtues of the Avatar combine into and are derived from the Three Principles of Truth, Love and Courage...");
-		eventHandler->pushKeyHandler(&codexHandleInfinityAnyKey);
-	} else codexEject(CODEX_EJECT_BAD_INFINITY);
+		eventHandler->pushKeyHandler(&handleInfinityAnyKey);
+	} else eject(CODEX_EJECT_BAD_INFINITY);
 }
 
-bool codexHandleEndgameAnyKey(int key, void *data) {
+bool Codex::handleEndgameAnyKey(int key, void *data) {
 	static int index = 1;
 
 	eventHandler->popKeyHandler();
@@ -445,20 +411,21 @@ bool codexHandleEndgameAnyKey(int key, void *data) {
 				g_screen->screenEraseMapArea();
 				g_screen->screenRedrawMapArea();
 			}
-			g_screen->screenMessage("%s", codexEndgameText1[index].c_str());
+			g_screen->screenMessage("%s", g_codex->_endgameText1[index].c_str());
 		} else if (index == 7) {
 			g_screen->screenDrawImageInMapArea(BKGD_STONCRCL);
 			g_screen->screenRedrawMapArea();
-			g_screen->screenMessage("\n\n%s", codexEndgameText2[index - 7].c_str());
+			g_screen->screenMessage("\n\n%s", g_codex->_endgameText2[index - 7].c_str());
 		} else if (index > 7)
-			g_screen->screenMessage("%s", codexEndgameText2[index - 7].c_str());
+			g_screen->screenMessage("%s", g_codex->_endgameText2[index - 7].c_str());
 
 		index++;
-		eventHandler->pushKeyHandler(&codexHandleEndgameAnyKey);
+		eventHandler->pushKeyHandler(&g_codex->handleEndgameAnyKey);
 	} else {
-		/* CONGRATULATIONS!... you have completed the game in x turns */
+		// CONGRATULATIONS!... you have completed the game in x turns
 		g_screen->screenDisableCursor();
-		g_screen->screenMessage("%s%d%s", codexEndgameText2[index - 7].c_str(), g_ultima->_saveGame->_moves, codexEndgameText2[index - 6].c_str());
+		g_screen->screenMessage("%s%d%s", g_codex->_endgameText2[index - 7].c_str(),
+			g_ultima->_saveGame->_moves, g_codex->_endgameText2[index - 6].c_str());
 #ifdef IOS_ULTIMA4
 		U4IOS::endChoiceConversation();
 #endif
@@ -468,10 +435,7 @@ bool codexHandleEndgameAnyKey(int key, void *data) {
 	return true;
 }
 
-/**
- * Pretty self-explanatory
- */
-void codexImpureThoughts() {
+void Codex::impureThoughts() {
 	g_screen->screenMessage("\nThy thoughts are not pure.\nI ask again.\n");
 	EventHandler::sleep(2000);
 }
diff --git a/engines/ultima/ultima4/game/codex.h b/engines/ultima/ultima4/game/codex.h
index 519558d997..121948e11f 100644
--- a/engines/ultima/ultima4/game/codex.h
+++ b/engines/ultima/ultima4/game/codex.h
@@ -23,6 +23,8 @@
 #ifndef ULTIMA4_GAME_CODEX_H
 #define ULTIMA4_GAME_CODEX_H
 
+#include "common/array.h"
+
 namespace Ultima {
 namespace Ultima4 {
 
@@ -45,10 +47,68 @@ enum CodexEjectCode {
 	CODEX_EJECT_BAD_INFINITY
 };
 
-/**
- * Begins the Chamber of the Codex sequence
- */
-void codexStart();
+class Codex {
+private:
+	Common::Array<Common::String> _virtueQuestions;
+	Common::Array<Common::String> _endgameText1;
+	Common::Array<Common::String> _endgameText2;
+private:
+	/**
+	 * Initializes the Chamber of the Codex sequence (runs from codexStart())
+	 */
+	int init();
+
+	/**
+	 * Frees all memory associated with the Codex sequence
+	 */
+	void deinit();
+
+	/**
+	 * Ejects you from the chamber of the codex (and the Abyss, for that matter)
+	 * with the correct message.
+	 */
+	void eject(CodexEjectCode code);
+
+	/**
+	 * Handles entering the Word of Passage
+	 */
+	void handleWOP(const Common::String &word);
+
+	/**
+	 * Handles naming of virtues in the Chamber of the Codex
+	 */
+	void handleVirtues(const Common::String &virtue);
+
+	void handleInfinity(const Common::String &answer);
+
+	/**
+	 * Pretty self-explanatory
+	 */
+	void impureThoughts();
+
+	/**
+	 * Key handlers
+	 */
+	static bool handleInfinityAnyKey(int key, void *data);
+	static bool handleEndgameAnyKey(int key, void *data);
+public:
+	/**
+	 * Constructor
+	 */
+	Codex();
+
+	/**
+	 * Destructor
+	 */
+	~Codex();
+
+	/**
+	 * Begins the Chamber of the Codex sequence
+	 */
+	void start();
+};
+
+extern Codex *g_codex;
 
 } // End of namespace Ultima4
 } // End of namespace Ultima
diff --git a/engines/ultima/ultima4/game/item.cpp b/engines/ultima/ultima4/game/item.cpp
index 6b75294f2a..57eccab35f 100644
--- a/engines/ultima/ultima4/game/item.cpp
+++ b/engines/ultima/ultima4/game/item.cpp
@@ -544,10 +544,8 @@ void useStone(int item) {
 
 					stoneMask = 0; /* reset the mask so you can try again */
 				}
-			}
-
-			/* Otherwise, we're asking for a stone while in the abyss on top of an altar */
-			else {
+			} else {
+				/* Otherwise, we're asking for a stone while in the abyss on top of an altar */
 				/* see if they entered the correct stone */
 				if (stone == (1 << g_context->_location->_coords.z)) {
 					if (g_context->_location->_coords.z < 7) {
@@ -556,12 +554,13 @@ void useStone(int item) {
 						g_screen->screenMessage("\n\nThe altar changes before thyne eyes!\n");
 						g_context->_location->getCurrentPosition(&pos);
 						g_context->_location->_map->_annotations->add(pos, g_context->_location->_map->_tileSet->getByName("down_ladder")->getId());
+					} else {
+						// Start chamber of the codex sequence...
+						g_codex->start();
 					}
-					/* start chamber of the codex sequence... */
-					else {
-						codexStart();
-					}
-				} else g_screen->screenMessage("\nHmm...No effect!\n");
+				} else {
+					g_screen->screenMessage("\nHmm...No effect!\n");
+				}
 			}
 		} else {
 			g_screen->screenMessage("\nNot a Usable Item!\n");
diff --git a/engines/ultima/ultima4/ultima4.cpp b/engines/ultima/ultima4/ultima4.cpp
index d85310fefe..c84d118e8c 100644
--- a/engines/ultima/ultima4/ultima4.cpp
+++ b/engines/ultima/ultima4/ultima4.cpp
@@ -30,6 +30,7 @@
 #include "ultima/ultima4/events/event_handler.h"
 #include "ultima/ultima4/filesys/savegame.h"
 #include "ultima/ultima4/game/armor.h"
+#include "ultima/ultima4/game/codex.h"
 #include "ultima/ultima4/game/context.h"
 #include "ultima/ultima4/game/game.h"
 #include "ultima/ultima4/game/moongate.h"
@@ -53,12 +54,13 @@ Ultima4Engine *g_ultima;
 
 Ultima4Engine::Ultima4Engine(OSystem *syst, const Ultima::UltimaGameDescription *gameDesc) :
 		Shared::UltimaEngine(syst, gameDesc), _saveSlotToLoad(-1), _armors(nullptr),
-		_config(nullptr), _context(nullptr), _dialogueLoaders(nullptr), _game(nullptr),
-		_music(nullptr), _imageLoaders(nullptr), _moongates(nullptr), _saveGame(nullptr),
-		_screen(nullptr), _shrines(nullptr), _tileMaps(nullptr), _tileRules(nullptr),
-		_tileSets(nullptr), _weapons(nullptr) {
+		_codex(nullptr), _config(nullptr), _context(nullptr), _dialogueLoaders(nullptr),
+		_game(nullptr), _music(nullptr), _imageLoaders(nullptr), _moongates(nullptr),
+		_saveGame(nullptr), _screen(nullptr), _shrines(nullptr), _tileMaps(nullptr),
+		_tileRules(nullptr), _tileSets(nullptr), _weapons(nullptr) {
 	g_ultima = this;
 	g_armors = nullptr;
+	g_codex = nullptr;
 	g_context = nullptr;
 	g_game = nullptr;
 	g_moongates = nullptr;
@@ -72,6 +74,7 @@ Ultima4Engine::Ultima4Engine(OSystem *syst, const Ultima::UltimaGameDescription
 
 Ultima4Engine::~Ultima4Engine() {
 	delete _armors;
+	delete _codex;
 	delete _config;
 	delete _context;
 	delete _dialogueLoaders;
@@ -100,6 +103,7 @@ bool Ultima4Engine::initialize() {
 	// Initialize the sub-systems
 	_config = new Config();
 	_armors = new Armors();
+	_codex = new Codex();
 	_context = new Context();
 	_dialogueLoaders = new DialogueLoaders();
 	_moongates = new Moongates();
diff --git a/engines/ultima/ultima4/ultima4.h b/engines/ultima/ultima4/ultima4.h
index b2beaab043..5cd94601db 100644
--- a/engines/ultima/ultima4/ultima4.h
+++ b/engines/ultima/ultima4/ultima4.h
@@ -30,6 +30,7 @@ namespace Ultima {
 namespace Ultima4 {
 
 class Armors;
+class Codex;
 class Config;
 class Context;
 class DialogueLoaders;
@@ -62,6 +63,7 @@ protected:
 	bool isDataRequired(Common::String &folder, int &majorVersion, int &minorVersion) override;
 public:
 	Armors *_armors;
+	Codex *_codex;
 	Config *_config;
 	Context *_context;
 	DialogueLoaders *_dialogueLoaders;


Commit: 7742473312dc510c6d295f2e61cfb445b4bab3df
    https://github.com/scummvm/scummvm/commit/7742473312dc510c6d295f2e61cfb445b4bab3df
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-04-26T12:30:11-07:00

Commit Message:
ULTIMA4: Move map loaders into the engine class

Changed paths:
    engines/ultima/ultima4/map/maploader.cpp
    engines/ultima/ultima4/map/maploader.h
    engines/ultima/ultima4/map/mapmgr.cpp
    engines/ultima/ultima4/ultima4.cpp
    engines/ultima/ultima4/ultima4.h


diff --git a/engines/ultima/ultima4/map/maploader.cpp b/engines/ultima/ultima4/map/maploader.cpp
index 1a9fff25da..571900a73d 100644
--- a/engines/ultima/ultima4/map/maploader.cpp
+++ b/engines/ultima/ultima4/map/maploader.cpp
@@ -46,31 +46,30 @@
 namespace Ultima {
 namespace Ultima4 {
 
-Std::map<Map::Type, MapLoader *, MapType_Hash> *MapLoader::loaderMap = nullptr;
+MapLoaders *g_mapLoaders;
 
-MapLoader *CityMapLoader::_instance = MapLoader::registerLoader(new CityMapLoader, Map::CITY);
-MapLoader *ConMapLoader::_instance = MapLoader::registerLoader(MapLoader::registerLoader(new ConMapLoader, Map::COMBAT), Map::SHRINE);
-MapLoader *DngMapLoader::_instance = MapLoader::registerLoader(new DngMapLoader, Map::DUNGEON);
-MapLoader *WorldMapLoader::_instance = MapLoader::registerLoader(new WorldMapLoader, Map::WORLD);
+MapLoaders::MapLoaders() {
+	g_mapLoaders = this;
 
-MapLoader *MapLoader::getLoader(Map::Type type) {
-	ASSERT(loaderMap != nullptr, "ImageLoader::getLoader loaderMap not initialized");
-	if (loaderMap->find(type) == loaderMap->end())
-		return nullptr;
-	return (*loaderMap)[type];
+	(*this)[Map::CITY] = new CityMapLoader();
+	(*this)[Map::SHRINE] = new ConMapLoader();
+	(*this)[Map::DUNGEON] = new DngMapLoader();
+	(*this)[Map::WORLD] = new WorldMapLoader();
 }
 
-MapLoader *MapLoader::registerLoader(MapLoader *loader, Map::Type type) {
-	if (loaderMap == nullptr)
-		loaderMap = new Std::map<Map::Type, MapLoader *, MapType_Hash>();
+MapLoaders::~MapLoaders() {
+	g_mapLoaders = nullptr;
+}
 
-	if (loaderMap->find(type) != loaderMap->end())
-		error("map loader already registered for type %d", type);
+MapLoader *MapLoaders::getLoader(Map::Type type) {
+	if (find(type) == end())
+		return nullptr;
 
-	(*loaderMap)[type] = loader;
-	return loader;
+	return (*this)[type];
 }
 
+/*-------------------------------------------------------------------*/
+
 bool MapLoader::loadData(Map *map, Common::File *f) {
 	uint x, xch, y, ych;
 
diff --git a/engines/ultima/ultima4/map/maploader.h b/engines/ultima/ultima4/map/maploader.h
index 45988ba876..b5623c498d 100644
--- a/engines/ultima/ultima4/map/maploader.h
+++ b/engines/ultima/ultima4/map/maploader.h
@@ -57,11 +57,6 @@ class MapLoader {
 public:
 	virtual ~MapLoader() {}
 
-	/**
-	 * Gets a map loader for the given map type.
-	 */
-	static MapLoader *getLoader(Map::Type type);
-
 	virtual bool load(Map *map) = 0;
 
 protected:
@@ -81,8 +76,6 @@ private:
 };
 
 class CityMapLoader : public MapLoader {
-	static MapLoader *_instance;
-
 public:
 	/**
 	 * Load city data from 'ult' and 'tlk' files.
@@ -91,8 +84,6 @@ public:
 };
 
 class ConMapLoader : public MapLoader {
-	static MapLoader *_instance;
-
 public:
 	/**
 	 * Loads a combat map from the 'con' file
@@ -101,8 +92,6 @@ public:
 };
 
 class DngMapLoader : public MapLoader {
-	static MapLoader *_instance;
-
 public:
 	/**
 	 * Loads a dungeon map from the 'dng' file
@@ -117,7 +106,6 @@ private:
 };
 
 class WorldMapLoader : public MapLoader {
-	static MapLoader *_instance;
 public:
 	/**
 	 * Loads the world map data in from the 'world' file.
@@ -125,6 +113,26 @@ public:
 	bool load(Map *map) override;
 };
 
+class MapLoaders : public Std::map<Map::Type, MapLoader *, MapType_Hash> {
+public:
+	/**
+	 * Constructor
+	 */
+	MapLoaders();
+
+	/**
+	 * Destructor
+	 */
+	~MapLoaders();
+
+	/**
+	 * Gets a map loader for the given map type.
+	 */
+	MapLoader *getLoader(Map::Type type);
+};
+
+extern MapLoaders *g_mapLoaders;
+
 } // End of namespace Ultima4
 } // End of namespace Ultima
 
diff --git a/engines/ultima/ultima4/map/mapmgr.cpp b/engines/ultima/ultima4/map/mapmgr.cpp
index 4fea26bbd1..441f0f28fb 100644
--- a/engines/ultima/ultima4/map/mapmgr.cpp
+++ b/engines/ultima/ultima4/map/mapmgr.cpp
@@ -130,12 +130,13 @@ Map *MapMgr::initMap(Map::Type type) {
 Map *MapMgr::get(MapId id) {
 	// if the map hasn't been loaded yet, load it!
 	if (!_mapList[id]->_data.size()) {
-		MapLoader *loader = MapLoader::getLoader(_mapList[id]->_type);
+		MapLoader *loader = g_mapLoaders->getLoader(_mapList[id]->_type);
 		if (loader == nullptr)
 			error("can't load map of type \"%d\"", _mapList[id]->_type);
 
 		loader->load(_mapList[id]);
 	}
+
 	return _mapList[id];
 }
 
diff --git a/engines/ultima/ultima4/ultima4.cpp b/engines/ultima/ultima4/ultima4.cpp
index c84d118e8c..364165f804 100644
--- a/engines/ultima/ultima4/ultima4.cpp
+++ b/engines/ultima/ultima4/ultima4.cpp
@@ -39,6 +39,7 @@
 #include "ultima/ultima4/gfx/screen.h"
 #include "ultima/ultima4/gfx/imageloader.h"
 #include "ultima/ultima4/gfx/imagemgr.h"
+#include "ultima/ultima4/map/maploader.h"
 #include "ultima/ultima4/map/shrine.h"
 #include "ultima/ultima4/map/tilemap.h"
 #include "ultima/ultima4/map/tileset.h"
@@ -55,14 +56,15 @@ Ultima4Engine *g_ultima;
 Ultima4Engine::Ultima4Engine(OSystem *syst, const Ultima::UltimaGameDescription *gameDesc) :
 		Shared::UltimaEngine(syst, gameDesc), _saveSlotToLoad(-1), _armors(nullptr),
 		_codex(nullptr), _config(nullptr), _context(nullptr), _dialogueLoaders(nullptr),
-		_game(nullptr), _music(nullptr), _imageLoaders(nullptr), _moongates(nullptr),
-		_saveGame(nullptr), _screen(nullptr), _shrines(nullptr), _tileMaps(nullptr),
-		_tileRules(nullptr), _tileSets(nullptr), _weapons(nullptr) {
+		_game(nullptr), _music(nullptr), _imageLoaders(nullptr), _mapLoaders(nullptr),
+		_moongates(nullptr), _saveGame(nullptr), _screen(nullptr), _shrines(nullptr),
+		_tileMaps(nullptr), _tileRules(nullptr), _tileSets(nullptr), _weapons(nullptr) {
 	g_ultima = this;
 	g_armors = nullptr;
 	g_codex = nullptr;
 	g_context = nullptr;
 	g_game = nullptr;
+	g_mapLoaders = nullptr;
 	g_moongates = nullptr;
 	g_screen = nullptr;
 	g_shrines = nullptr;
@@ -80,6 +82,7 @@ Ultima4Engine::~Ultima4Engine() {
 	delete _dialogueLoaders;
 	delete _game;
 	delete _imageLoaders;
+	delete _mapLoaders;
 	delete _moongates;
 	delete _music;
 	delete _saveGame;
@@ -106,6 +109,7 @@ bool Ultima4Engine::initialize() {
 	_codex = new Codex();
 	_context = new Context();
 	_dialogueLoaders = new DialogueLoaders();
+	_mapLoaders = new MapLoaders();
 	_moongates = new Moongates();
 	_screen = new Screen();
 	_screen->init();
diff --git a/engines/ultima/ultima4/ultima4.h b/engines/ultima/ultima4/ultima4.h
index 5cd94601db..cd6138e233 100644
--- a/engines/ultima/ultima4/ultima4.h
+++ b/engines/ultima/ultima4/ultima4.h
@@ -36,6 +36,7 @@ class Context;
 class DialogueLoaders;
 class ImageLoaders;
 class GameController;
+class MapLoaders;
 class Moongates;
 class Music;
 struct SaveGame;
@@ -69,6 +70,7 @@ public:
 	DialogueLoaders *_dialogueLoaders;
 	ImageLoaders *_imageLoaders;
 	GameController *_game;
+	MapLoaders *_mapLoaders;
 	Moongates *_moongates;
 	Music *_music;
 	SaveGame *_saveGame;


Commit: d243684ae2e28c468c02a524d61727734902bbcf
    https://github.com/scummvm/scummvm/commit/d243684ae2e28c468c02a524d61727734902bbcf
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-04-26T12:30:11-07:00

Commit Message:
ULTIMA4: Script _actionMap doesn't need to be static

Changed paths:
    engines/ultima/ultima4/conversation/conversation.cpp
    engines/ultima/ultima4/game/script.cpp
    engines/ultima/ultima4/game/script.h


diff --git a/engines/ultima/ultima4/conversation/conversation.cpp b/engines/ultima/ultima4/conversation/conversation.cpp
index 4c1aea5689..255a97c445 100644
--- a/engines/ultima/ultima4/conversation/conversation.cpp
+++ b/engines/ultima/ultima4/conversation/conversation.cpp
@@ -234,7 +234,6 @@ Conversation::Conversation() : _state(INTRO), _script(new Script()) {
 #ifdef IOS_ULTIMA4
 	U4IOS::incrementConversationCount();
 #endif
-
 }
 
 Conversation::~Conversation() {
diff --git a/engines/ultima/ultima4/game/script.cpp b/engines/ultima/ultima4/game/script.cpp
index 9fc86e7153..a227e8c7b5 100644
--- a/engines/ultima/ultima4/game/script.cpp
+++ b/engines/ultima/ultima4/game/script.cpp
@@ -94,11 +94,6 @@ bool Script::Variable::isSet() const {
 	return _set;
 }
 
-/*
- * Static member variables
- */
-Script::ActionMap Script::_actionMap;
-
 Script::Script() : _vendorScriptDoc(nullptr), _scriptNode(nullptr), _debug(false), _state(STATE_UNLOADED),
 	_nounName("item"), _idPropName("id") {
 	_actionMap["context"]           = ACTION_SET_CONTEXT;
diff --git a/engines/ultima/ultima4/game/script.h b/engines/ultima/ultima4/game/script.h
index 37d0cfc5ef..548163444c 100644
--- a/engines/ultima/ultima4/game/script.h
+++ b/engines/ultima/ultima4/game/script.h
@@ -412,7 +412,7 @@ private:
 	 */
 private:
 	typedef Std::map<Common::String, Action> ActionMap;
-	static ActionMap _actionMap;
+	ActionMap _actionMap;
 
 private:
 	void removeCurrentVariable(const Common::String &name);


Commit: 4623096adc5ef4ae91244c0281d21c22fbfa591a
    https://github.com/scummvm/scummvm/commit/4623096adc5ef4ae91244c0281d21c22fbfa591a
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-04-26T12:30:11-07:00

Commit Message:
ULTIMA4: Fix transparency of tiles drawn on the map

The PNG tiles use alpha to handle transprency, so we need the image
surfacese to remain 32-bits to keep the values intact

Changed paths:
    engines/ultima/ultima4/gfx/image.cpp


diff --git a/engines/ultima/ultima4/gfx/image.cpp b/engines/ultima/ultima4/gfx/image.cpp
index 3f5795c8e6..6e994ba544 100644
--- a/engines/ultima/ultima4/gfx/image.cpp
+++ b/engines/ultima/ultima4/gfx/image.cpp
@@ -47,7 +47,8 @@ Image *Image::create(int w, int h, bool paletted, Image::Type type) {
 void Image::create(int w, int h, bool paletted) {
 	_paletted = paletted;
 	_surface = new Graphics::ManagedSurface(w, h, paletted ?
-		Graphics::PixelFormat::createFormatCLUT8() : g_screen->format);
+		Graphics::PixelFormat::createFormatCLUT8() :
+		Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0));
 	_disposeAfterUse = DisposeAfterUse::YES;
 }
 




More information about the Scummvm-git-logs mailing list