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

dreammaster paulfgilbert at gmail.com
Wed May 13 02:27:32 UTC 2020


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:
b377177007 ULTIMA4: Further cleanup of saving/loading map(s) locations


Commit: b3771770073983d1a6ca971925a62ba50c01b61b
    https://github.com/scummvm/scummvm/commit/b3771770073983d1a6ca971925a62ba50c01b61b
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-05-12T19:21:14-07:00

Commit Message:
ULTIMA4: Further cleanup of saving/loading map(s) locations

Changed paths:
    engines/ultima/ultima4/controllers/intro_controller.cpp
    engines/ultima/ultima4/filesys/savegame.cpp
    engines/ultima/ultima4/filesys/savegame.h
    engines/ultima/ultima4/game/player.cpp


diff --git a/engines/ultima/ultima4/controllers/intro_controller.cpp b/engines/ultima/ultima4/controllers/intro_controller.cpp
index 7d9ec9ab3e..2990c4f3f5 100644
--- a/engines/ultima/ultima4/controllers/intro_controller.cpp
+++ b/engines/ultima/ultima4/controllers/intro_controller.cpp
@@ -34,6 +34,7 @@
 #include "ultima/ultima4/filesys/u4file.h"
 #include "ultima/ultima4/gfx/imagemgr.h"
 #include "ultima/ultima4/gfx/screen.h"
+#include "ultima/ultima4/map/mapmgr.h"
 #include "ultima/ultima4/map/shrine.h"
 #include "ultima/ultima4/map/tileset.h"
 #include "ultima/ultima4/map/tilemap.h"
@@ -1316,14 +1317,15 @@ void IntroController::initPlayers(SaveGame *saveGame) {
 	saveGame->_players[0]._class = static_cast<ClassType>(_questionTree[14]);
 
 	ASSERT((int)saveGame->_players[0]._class < 8, "bad class: %d", saveGame->_players[0]._class);
+	saveGame->_positions.resize(1);
+	saveGame->_positions[0] = LocationCoords(MAP_WORLD,
+		initValuesForClass[saveGame->_players[0]._class].x,
+		initValuesForClass[saveGame->_players[0]._class].y,
+		0);
 
 	saveGame->_players[0]._weapon = initValuesForClass[saveGame->_players[0]._class].weapon;
 	saveGame->_players[0]._armor = initValuesForClass[saveGame->_players[0]._class].armor;
 	saveGame->_players[0]._xp = initValuesForClass[saveGame->_players[0]._class].xp;
-	saveGame->_pos.x = initValuesForClass[saveGame->_players[0]._class].x;
-	saveGame->_pos.y = initValuesForClass[saveGame->_players[0]._class].y;
-	saveGame->_pos.z = 0;
-
 	saveGame->_players[0]._str = 15;
 	saveGame->_players[0]._dex = 15;
 	saveGame->_players[0]._intel = 15;
diff --git a/engines/ultima/ultima4/filesys/savegame.cpp b/engines/ultima/ultima4/filesys/savegame.cpp
index 6cda0b5fb6..1689f923e8 100644
--- a/engines/ultima/ultima4/filesys/savegame.cpp
+++ b/engines/ultima/ultima4/filesys/savegame.cpp
@@ -39,16 +39,7 @@ void SaveGame::save(Common::WriteStream *stream) {
 	Common::Serializer ser(nullptr, stream);
 	assert(g_context && g_context->_location);
 
-	_location = g_context->_location->_map->_id;
-	_pos = g_context->_location->_coords;
-
-	if (g_context->_location->_prev) {
-		_overworldPos.x = g_context->_location->_prev->_coords.x;
-		_overworldPos.y = g_context->_location->_prev->_coords.y;
-	} else {
-		_overworldPos.x = _overworldPos.y = 0;
-	}
-
+	_positions.load();
 	synchronize(ser);
 
 	/*
@@ -109,19 +100,13 @@ void SaveGame::load(Common::SeekableReadStream *stream) {
 	// initialize the moons (must be done from the world map)
 	g_game->initMoons();
 
-	// initialize our start location
-	map = mapMgr->get(MapId(_location));
+	// initialize overworld position and any secondary map we're in
+	g_context->_location->_coords = _positions[0];
 
-	if (map->_type != Map::WORLD) {
-		// Set up the secondary map
+	for (uint idx = 1; idx < _positions.size(); ++idx) {
+		map = mapMgr->get(_positions[idx]._map);
 		g_game->setMap(map, 1, nullptr);
-
-		// Set position within map and in overworld
-		g_context->_location->_coords = _pos;
-		g_context->_location->_prev->_coords = MapCoords(_overworldPos.x, _overworldPos.y, 0);
-	} else {
-		// On overworld, simply set position
-		g_context->_location->_coords = _pos;
+		g_context->_location->_coords = _positions[idx];
 	}
 
 	/**
@@ -197,13 +182,8 @@ void SaveGame::synchronize(Common::Serializer &s) {
 	for (i = 0; i < SPELL_MAX; ++i)
 		s.syncAsUint16LE(_mixtures[i]);
 
-	s.syncAsByte(_pos.x);
-	s.syncAsByte(_pos.y);
-	s.syncAsUint16LE(_pos.z);
-	s.syncAsByte(_overworldPos.x);
-	s.syncAsByte(_overworldPos.y);
+	_positions.synchronize(s);
 	s.syncAsUint16LE(_orientation);
-	s.syncAsUint16LE(_location);
 
 	s.syncAsUint16LE(_items);
 	s.syncAsByte(_stones);
@@ -255,8 +235,6 @@ void SaveGame::init(const SaveGamePlayerRecord *avatarInfo) {
 		_mixtures[i] = 0;
 
 	_items = 0;
-	_pos = Coords(0, 0, 0xffff);
-	_overworldPos = Common::Point();
 	_stones = 0;
 	_runes = 0;
 	_members = 1;
@@ -271,7 +249,6 @@ void SaveGame::init(const SaveGamePlayerRecord *avatarInfo) {
 	_lastMeditation = 0;
 	_lastVirtue = 0;
 	_orientation = 0;
-	_location = 0;
 }
 
 /*-------------------------------------------------------------------*/
@@ -351,5 +328,36 @@ void SaveGameMonsterRecord::synchronize(SaveGameMonsterRecord *monsterTable, Com
 		s.syncAsByte(monsterTable[i]._unused2);
 }
 
+/*-------------------------------------------------------------------*/
+
+void LocationCoordsArray::load() {
+	clear();
+
+	for (Location *l = g_context->_location; l; l = l->_prev)
+		insert_at(0, LocationCoords(l->_map->_id, l->_coords));
+}
+
+void LocationCoords::synchronize(Common::Serializer &s) {
+	s.syncAsByte(x);
+	s.syncAsByte(y);
+	s.syncAsByte(z);
+	s.syncAsByte(_map);
+}
+
+/*-------------------------------------------------------------------*/
+
+void LocationCoordsArray::synchronize(Common::Serializer &s) {
+	byte count = size();
+	s.syncAsByte(count);
+
+	if (s.isLoading())
+		resize(count);
+
+	for (uint idx = 0; idx < count; ++idx)
+		(*this)[idx].synchronize(s);
+
+	assert(!empty() && (*this)[0]._map == MAP_WORLD);
+}
+
 } // End of namespace Ultima4
 } // End of namespace Ultima
diff --git a/engines/ultima/ultima4/filesys/savegame.h b/engines/ultima/ultima4/filesys/savegame.h
index 4fedf10a4a..8e0750c42c 100644
--- a/engines/ultima/ultima4/filesys/savegame.h
+++ b/engines/ultima/ultima4/filesys/savegame.h
@@ -23,10 +23,12 @@
 #ifndef ULTIMA4_FILESYS_SAVEGAME_H
 #define ULTIMA4_FILESYS_SAVEGAME_H
 
+#include "common/array.h"
 #include "common/rect.h"
 #include "common/stream.h"
 #include "common/serializer.h"
 #include "ultima/ultima4/core/coords.h"
+#include "ultima/ultima4/core/types.h"
 
 namespace Ultima {
 namespace Ultima4 {
@@ -233,6 +235,36 @@ struct SaveGameMonsterRecord {
 	static void synchronize(SaveGameMonsterRecord *monsterTable, Common::Serializer &s);
 };
 
+class LocationCoords : public Coords {
+public:
+	MapId _map;
+
+	LocationCoords() : Coords(), _map(0xff) {}
+	LocationCoords(MapId map, int x, int y, int z) :
+		Coords(x, y, z), _map(map) {}
+	LocationCoords(MapId map, const Coords &pos) :
+		Coords(pos), _map(map) {}
+
+	/**
+	 * Synchronize to/from a savegame
+	 */
+	void synchronize(Common::Serializer &s);
+};
+
+class LocationCoordsArray : public Common::Array<LocationCoords> {
+public:
+
+	/**
+	 * Loads the list of map & coordinates from the game context
+	 */
+	void load();
+
+	/**
+	 * Synchronize to/from a savegame
+	 */
+	void synchronize(Common::Serializer &s);
+};
+
 /**
  * Represents the on-disk contents of PARTY.SAV.
  */
@@ -278,10 +310,8 @@ struct SaveGame {
 	short _reagents[REAG_MAX];
 	short _mixtures[SPELL_MAX];
 	unsigned short _items;
-	Coords _pos;
-	Common::Point _overworldPos;
+	LocationCoordsArray _positions;
 	unsigned short _orientation;
-	unsigned short _location;
 
 	byte _stones;
 	byte _runes;
diff --git a/engines/ultima/ultima4/game/player.cpp b/engines/ultima/ultima4/game/player.cpp
index 6476cdce0f..3f6cf249f9 100644
--- a/engines/ultima/ultima4/game/player.cpp
+++ b/engines/ultima/ultima4/game/player.cpp
@@ -549,7 +549,8 @@ MapTile PartyMember::tileForClass(int klass) {
 /*-------------------------------------------------------------------*/
 
 Party::Party(SaveGame *s) : _saveGame(s), _transport(0), _torchDuration(0), _activePlayer(-1) {
-	if (MAP_DECEIT <= _saveGame->_location && _saveGame->_location <= MAP_ABYSS)
+	MapId map = _saveGame->_positions.back()._map;
+	if (map >= MAP_DECEIT && map <= MAP_ABYSS)
 		_torchDuration = _saveGame->_torchDuration;
 	for (int i = 0; i < _saveGame->_members; i++) {
 		// add the members to the party




More information about the Scummvm-git-logs mailing list