Initial commit
This commit is contained in:
127
engines/ultima/ultima4/filesys/rle.cpp
Normal file
127
engines/ultima/ultima4/filesys/rle.cpp
Normal file
@@ -0,0 +1,127 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "ultima/ultima4/filesys/rle.h"
|
||||
|
||||
namespace Ultima {
|
||||
namespace Ultima4 {
|
||||
|
||||
/**
|
||||
* Decompress an RLE encoded file.
|
||||
*/
|
||||
long rleDecompressFile(Common::ReadStream *in, long inlen, void **out) {
|
||||
void *indata;
|
||||
long outlen;
|
||||
|
||||
/* input file should be longer than 0 bytes */
|
||||
if (inlen <= 0)
|
||||
return -1;
|
||||
|
||||
/* load compressed file into memory */
|
||||
indata = malloc(inlen);
|
||||
in->read(indata, inlen);
|
||||
|
||||
outlen = rleDecompressMemory(indata, inlen, out);
|
||||
|
||||
free(indata);
|
||||
|
||||
return outlen;
|
||||
}
|
||||
|
||||
long rleDecompressMemory(void *in, long inlen, void **out) {
|
||||
byte *indata, *outdata;
|
||||
long outlen;
|
||||
|
||||
/* input should be longer than 0 bytes */
|
||||
if (inlen <= 0)
|
||||
return -1;
|
||||
|
||||
indata = (byte *)in;
|
||||
|
||||
/* determine decompressed file size */
|
||||
outlen = rleGetDecompressedSize(indata, inlen);
|
||||
|
||||
if (outlen <= 0)
|
||||
return -1;
|
||||
|
||||
/* decompress file from inlen to outlen */
|
||||
outdata = (byte *) malloc(outlen);
|
||||
rleDecompress(indata, inlen, outdata, outlen);
|
||||
|
||||
*out = outdata;
|
||||
|
||||
return outlen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the uncompressed size of RLE compressed data.
|
||||
*/
|
||||
long rleGetDecompressedSize(byte *indata, long inlen) {
|
||||
byte *p;
|
||||
byte ch, count;
|
||||
long len = 0;
|
||||
|
||||
p = indata;
|
||||
while ((p - indata) < inlen) {
|
||||
ch = *p++;
|
||||
if (ch == RLE_RUNSTART) {
|
||||
count = *p++;
|
||||
p++;
|
||||
len += count;
|
||||
} else
|
||||
len++;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decompress a block of RLE encoded memory.
|
||||
*/
|
||||
long rleDecompress(byte *indata, long inlen, byte *outdata, long outlen) {
|
||||
int i;
|
||||
byte *p, *q;
|
||||
byte ch, count, val;
|
||||
|
||||
p = indata;
|
||||
q = outdata;
|
||||
while ((p - indata) < inlen) {
|
||||
ch = *p++;
|
||||
if (ch == RLE_RUNSTART) {
|
||||
count = *p++;
|
||||
val = *p++;
|
||||
for (i = 0; i < count; i++) {
|
||||
*q++ = val;
|
||||
if ((q - outdata) >= outlen)
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
*q++ = ch;
|
||||
if ((q - outdata) >= outlen)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return q - outdata;
|
||||
}
|
||||
|
||||
} // End of namespace Ultima4
|
||||
} // End of namespace Ultima
|
||||
40
engines/ultima/ultima4/filesys/rle.h
Normal file
40
engines/ultima/ultima4/filesys/rle.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ULTIMA4_FILESYS_RLE_H
|
||||
#define ULTIMA4_FILESYS_RLE_H
|
||||
|
||||
#include "common/stream.h"
|
||||
|
||||
namespace Ultima {
|
||||
namespace Ultima4 {
|
||||
|
||||
#define RLE_RUNSTART 02
|
||||
|
||||
long rleDecompressFile(Common::ReadStream *in, long inlen, void **out);
|
||||
long rleDecompressMemory(void *in, long inlen, void **out);
|
||||
long rleGetDecompressedSize(byte *indata, long inlen);
|
||||
long rleDecompress(byte *indata, long inlen, byte *outdata, long outlen);
|
||||
|
||||
} // End of namespace Ultima4
|
||||
} // End of namespace Ultima
|
||||
|
||||
#endif
|
||||
362
engines/ultima/ultima4/filesys/savegame.cpp
Normal file
362
engines/ultima/ultima4/filesys/savegame.cpp
Normal file
@@ -0,0 +1,362 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "ultima/ultima4/filesys/savegame.h"
|
||||
#include "ultima/ultima4/core/types.h"
|
||||
#include "ultima/ultima4/game/context.h"
|
||||
#include "ultima/ultima4/game/game.h"
|
||||
#include "ultima/ultima4/game/item.h"
|
||||
#include "ultima/ultima4/game/object.h"
|
||||
#include "ultima/ultima4/game/player.h"
|
||||
#include "ultima/ultima4/game/spell.h"
|
||||
#include "ultima/ultima4/views/stats.h"
|
||||
#include "ultima/ultima4/map/location.h"
|
||||
#include "ultima/ultima4/map/mapmgr.h"
|
||||
|
||||
namespace Ultima {
|
||||
namespace Ultima4 {
|
||||
|
||||
void SaveGame::save(Common::WriteStream *stream) {
|
||||
Common::Serializer ser(nullptr, stream);
|
||||
assert(g_context && g_context->_location);
|
||||
|
||||
_positions.load();
|
||||
synchronize(ser);
|
||||
|
||||
/*
|
||||
* Save monsters
|
||||
*/
|
||||
|
||||
// fix creature animations. This was done for compatibility with u4dos,
|
||||
// so may be redundant now
|
||||
g_context->_location->_map->resetObjectAnimations();
|
||||
g_context->_location->_map->fillMonsterTable();
|
||||
|
||||
SaveGameMonsterRecord::synchronize(g_context->_location->_map->_monsterTable, ser);
|
||||
|
||||
/**
|
||||
* Write dungeon info
|
||||
*/
|
||||
if (g_context->_location && g_context->_location->_prev) {
|
||||
/**
|
||||
* Write out monsters
|
||||
*/
|
||||
|
||||
// fix creature animations so they are compatible with u4dos.
|
||||
// This may be redundant now for ScummVM
|
||||
g_context->_location->_prev->_map->resetObjectAnimations();
|
||||
g_context->_location->_prev->_map->fillMonsterTable(); /* fill the monster table so we can save it */
|
||||
|
||||
SaveGameMonsterRecord::synchronize(g_context->_location->_prev->_map->_monsterTable, ser);
|
||||
}
|
||||
}
|
||||
|
||||
void SaveGame::load(Common::SeekableReadStream *stream) {
|
||||
Common::Serializer *ser = nullptr;
|
||||
assert(g_context);
|
||||
|
||||
if (stream) {
|
||||
ser = new Common::Serializer(stream, nullptr);
|
||||
synchronize(*ser);
|
||||
}
|
||||
|
||||
// initialize our party
|
||||
if (g_context->_party) {
|
||||
g_context->_party->deleteObserver(g_game);
|
||||
delete g_context->_party;
|
||||
}
|
||||
g_context->_party = new Party(this);
|
||||
g_context->_party->addObserver(g_game);
|
||||
|
||||
// Delete any prior map
|
||||
while (g_context->_location)
|
||||
locationFree(&g_context->_location);
|
||||
|
||||
// set the map to the world map
|
||||
Map *map = mapMgr->get(MAP_WORLD);
|
||||
g_game->setMap(map, 0, nullptr);
|
||||
assert(g_context->_location && g_context->_location->_map);
|
||||
g_context->_location->_map->clearObjects();
|
||||
|
||||
// initialize the moons (must be done from the world map)
|
||||
g_game->initMoons();
|
||||
|
||||
// initialize overworld position and any secondary map we're in
|
||||
g_context->_location->_coords = _positions[0];
|
||||
|
||||
for (uint idx = 1; idx < _positions.size(); ++idx) {
|
||||
map = mapMgr->get(_positions[idx]._map);
|
||||
g_game->setMap(map, 1, nullptr);
|
||||
g_context->_location->_coords = _positions[idx];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix the coordinates if they're out of bounds. This happens every
|
||||
* time on the world map because (z == -1) is no longer valid.
|
||||
* To maintain compatibility with u4dos, this value gets translated
|
||||
* when the game is saved and loaded
|
||||
*/
|
||||
if (MAP_IS_OOB(g_context->_location->_map, g_context->_location->_coords))
|
||||
g_context->_location->_coords.putInBounds(g_context->_location->_map);
|
||||
|
||||
// load in creatures
|
||||
if (ser)
|
||||
SaveGameMonsterRecord::synchronize(g_context->_location->_map->_monsterTable, *ser);
|
||||
gameFixupObjects(g_context->_location->_map);
|
||||
|
||||
/* we have previous creature information as well, load it! */
|
||||
if (g_context->_location->_prev) {
|
||||
if (ser)
|
||||
SaveGameMonsterRecord::synchronize(g_context->_location->_prev->_map->_monsterTable, *ser);
|
||||
gameFixupObjects(g_context->_location->_prev->_map);
|
||||
}
|
||||
|
||||
g_spells->spellSetEffectCallback(&gameSpellEffect);
|
||||
g_items->setDestroyAllCreaturesCallback(&gameDestroyAllCreatures);
|
||||
|
||||
g_context->_stats->resetReagentsMenu();
|
||||
|
||||
/* add some observers */
|
||||
g_context->_aura->addObserver(g_context->_stats);
|
||||
g_context->_party->addObserver(g_context->_stats);
|
||||
|
||||
g_game->initScreenWithoutReloadingState();
|
||||
|
||||
delete ser;
|
||||
}
|
||||
|
||||
void SaveGame::newGame() {
|
||||
// Most default state has already been set up by the IntroController.
|
||||
// Call the load method with no stream to handle pre-game setup
|
||||
load(nullptr);
|
||||
}
|
||||
|
||||
void SaveGame::synchronize(Common::Serializer &s) {
|
||||
int i;
|
||||
|
||||
s.syncAsUint32LE(_unknown1);
|
||||
s.syncAsUint32LE(_moves);
|
||||
|
||||
for (i = 0; i < 8; ++i)
|
||||
_players[i].synchronize(s);
|
||||
|
||||
s.syncAsUint32LE(_food);
|
||||
s.syncAsUint16LE(_gold);
|
||||
|
||||
for (i = 0; i < 8; ++i)
|
||||
s.syncAsUint16LE(_karma[i]);
|
||||
|
||||
s.syncAsUint16LE(_torches);
|
||||
s.syncAsUint16LE(_gems);
|
||||
s.syncAsUint16LE(_keys);
|
||||
s.syncAsUint16LE(_sextants);
|
||||
|
||||
for (i = 0; i < ARMR_MAX; ++i)
|
||||
s.syncAsUint16LE(_armor[i]);
|
||||
|
||||
for (i = 0; i < WEAP_MAX; ++i)
|
||||
s.syncAsUint16LE(_weapons[i]);
|
||||
|
||||
for (i = 0; i < REAG_MAX; ++i)
|
||||
s.syncAsUint16LE(_reagents[i]);
|
||||
|
||||
for (i = 0; i < SPELL_MAX; ++i)
|
||||
s.syncAsUint16LE(_mixtures[i]);
|
||||
|
||||
_positions.synchronize(s);
|
||||
s.syncAsUint16LE(_orientation);
|
||||
|
||||
s.syncAsUint16LE(_items);
|
||||
s.syncAsByte(_stones);
|
||||
s.syncAsByte(_runes);
|
||||
s.syncAsUint16LE(_members);
|
||||
s.syncAsUint16LE(_transport);
|
||||
s.syncAsUint16LE(_balloonState);
|
||||
s.syncAsUint16LE(_trammelPhase);
|
||||
s.syncAsUint16LE(_feluccaPhase);
|
||||
s.syncAsUint16LE(_shipHull);
|
||||
s.syncAsUint16LE(_lbIntro);
|
||||
s.syncAsUint16LE(_lastCamp);
|
||||
s.syncAsUint16LE(_lastReagent);
|
||||
s.syncAsUint16LE(_lastMeditation);
|
||||
s.syncAsUint16LE(_lastVirtue);
|
||||
}
|
||||
|
||||
void SaveGame::init(const SaveGamePlayerRecord *avatarInfo) {
|
||||
int i;
|
||||
|
||||
_unknown1 = 0;
|
||||
_moves = 0;
|
||||
|
||||
_players[0] = *avatarInfo;
|
||||
for (i = 1; i < 8; ++i)
|
||||
_players[i].init();
|
||||
|
||||
_food = 0;
|
||||
_gold = 0;
|
||||
|
||||
for (i = 0; i < 8; ++i)
|
||||
_karma[i] = 20;
|
||||
|
||||
_torches = 0;
|
||||
_gems = 0;
|
||||
_keys = 0;
|
||||
_sextants = 0;
|
||||
|
||||
for (i = 0; i < ARMR_MAX; ++i)
|
||||
_armor[i] = 0;
|
||||
|
||||
for (i = 0; i < WEAP_MAX; ++i)
|
||||
_weapons[i] = 0;
|
||||
|
||||
for (i = 0; i < REAG_MAX; ++i)
|
||||
_reagents[i] = 0;
|
||||
|
||||
for (i = 0; i < SPELL_MAX; ++i)
|
||||
_mixtures[i] = 0;
|
||||
|
||||
_items = 0;
|
||||
_stones = 0;
|
||||
_runes = 0;
|
||||
_members = 1;
|
||||
_transport = 0x1f;
|
||||
_balloonState = 0;
|
||||
_trammelPhase = 0;
|
||||
_feluccaPhase = 0;
|
||||
_shipHull = 50;
|
||||
_lbIntro = 0;
|
||||
_lastCamp = 0;
|
||||
_lastReagent = 0;
|
||||
_lastMeditation = 0;
|
||||
_lastVirtue = 0;
|
||||
_orientation = 0;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------*/
|
||||
|
||||
void SaveGamePlayerRecord::synchronize(Common::Serializer &s) {
|
||||
s.syncAsUint16LE(_hp);
|
||||
s.syncAsUint16LE(_hpMax);
|
||||
s.syncAsUint16LE(_xp);
|
||||
s.syncAsUint16LE(_str);
|
||||
s.syncAsUint16LE(_dex);
|
||||
s.syncAsUint16LE(_intel);
|
||||
s.syncAsUint16LE(_mp);
|
||||
s.syncAsUint16LE(_unknown);
|
||||
s.syncAsUint16LE(_weapon);
|
||||
s.syncAsUint16LE(_armor);
|
||||
s.syncBytes((byte *)_name, 16);
|
||||
s.syncAsByte(_sex);
|
||||
s.syncAsByte(_class);
|
||||
s.syncAsByte(_status);
|
||||
}
|
||||
|
||||
void SaveGamePlayerRecord::init() {
|
||||
int i;
|
||||
|
||||
_hp = 0;
|
||||
_hpMax = 0;
|
||||
_xp = 0;
|
||||
_str = 0;
|
||||
_dex = 0;
|
||||
_intel = 0;
|
||||
_mp = 0;
|
||||
_unknown = 0;
|
||||
_weapon = WEAP_HANDS;
|
||||
_armor = ARMR_NONE;
|
||||
|
||||
for (i = 0; i < 16; ++i)
|
||||
_name[i] = '\0';
|
||||
|
||||
_sex = SEX_MALE;
|
||||
_class = CLASS_MAGE;
|
||||
_status = STAT_GOOD;
|
||||
}
|
||||
|
||||
void SaveGameMonsterRecord::synchronize(SaveGameMonsterRecord *monsterTable, Common::Serializer &s) {
|
||||
int i;
|
||||
const uint32 IDENT = MKTAG('M', 'O', 'N', 'S');
|
||||
uint32 val = IDENT;
|
||||
|
||||
s.syncAsUint32BE(val);
|
||||
if (s.isLoading() && val != IDENT)
|
||||
error("Invalid savegame");
|
||||
|
||||
if (s.isSaving() && !monsterTable) {
|
||||
int dataSize = MONSTERTABLE_SIZE * 8;
|
||||
byte b = 0;
|
||||
while (dataSize-- > 0)
|
||||
s.syncAsByte(b);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < MONSTERTABLE_SIZE; ++i)
|
||||
s.syncAsByte(monsterTable[i]._tile);
|
||||
for (i = 0; i < MONSTERTABLE_SIZE; ++i)
|
||||
s.syncAsByte(monsterTable[i]._x);
|
||||
for (i = 0; i < MONSTERTABLE_SIZE; ++i)
|
||||
s.syncAsByte(monsterTable[i]._y);
|
||||
for (i = 0; i < MONSTERTABLE_SIZE; ++i)
|
||||
s.syncAsByte(monsterTable[i]._prevTile);
|
||||
for (i = 0; i < MONSTERTABLE_SIZE; ++i)
|
||||
s.syncAsByte(monsterTable[i]._prevX);
|
||||
for (i = 0; i < MONSTERTABLE_SIZE; ++i)
|
||||
s.syncAsByte(monsterTable[i]._prevY);
|
||||
for (i = 0; i < MONSTERTABLE_SIZE; ++i)
|
||||
s.syncAsByte(monsterTable[i]._unused1);
|
||||
for (i = 0; i < MONSTERTABLE_SIZE; ++i)
|
||||
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
|
||||
336
engines/ultima/ultima4/filesys/savegame.h
Normal file
336
engines/ultima/ultima4/filesys/savegame.h
Normal file
@@ -0,0 +1,336 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#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 {
|
||||
|
||||
#define PARTY_SAV_BASE_FILENAME "party.sav"
|
||||
#define MONSTERS_SAV_BASE_FILENAME "monsters.sav"
|
||||
#define OUTMONST_SAV_BASE_FILENAME "outmonst.sav"
|
||||
|
||||
#define MONSTERTABLE_SIZE 32
|
||||
#define MONSTERTABLE_CREATURES_SIZE 8
|
||||
#define MONSTERTABLE_OBJECTS_SIZE (MONSTERTABLE_SIZE - MONSTERTABLE_CREATURES_SIZE)
|
||||
|
||||
class Object;
|
||||
|
||||
/**
|
||||
* The list of all weapons. These values are used in both the
|
||||
* inventory fields and character records of the savegame.
|
||||
*/
|
||||
enum WeaponType {
|
||||
WEAP_HANDS,
|
||||
WEAP_STAFF,
|
||||
WEAP_DAGGER,
|
||||
WEAP_SLING,
|
||||
WEAP_MACE,
|
||||
WEAP_AXE,
|
||||
WEAP_SWORD,
|
||||
WEAP_BOW,
|
||||
WEAP_CROSSBOW,
|
||||
WEAP_OIL,
|
||||
WEAP_HALBERD,
|
||||
WEAP_MAGICAXE,
|
||||
WEAP_MAGICSWORD,
|
||||
WEAP_MAGICBOW,
|
||||
WEAP_MAGICWAND,
|
||||
WEAP_MYSTICSWORD,
|
||||
WEAP_MAX
|
||||
};
|
||||
|
||||
/**
|
||||
* The list of all armor types. These values are used in both the
|
||||
* inventory fields and character records of the savegame.
|
||||
*/
|
||||
enum ArmorType {
|
||||
ARMR_NONE,
|
||||
ARMR_CLOTH,
|
||||
ARMR_LEATHER,
|
||||
ARMR_CHAIN,
|
||||
ARMR_PLATE,
|
||||
ARMR_MAGICCHAIN,
|
||||
ARMR_MAGICPLATE,
|
||||
ARMR_MYSTICROBES,
|
||||
ARMR_MAX
|
||||
};
|
||||
|
||||
/**
|
||||
* The list of sex values for the savegame character records. The
|
||||
* values match the male and female symbols in the character set.
|
||||
*/
|
||||
enum SexType {
|
||||
SEX_MALE = 0xb,
|
||||
SEX_FEMALE = 0xc
|
||||
};
|
||||
|
||||
/**
|
||||
* The list of class types for the savegame character records.
|
||||
*/
|
||||
enum ClassType {
|
||||
CLASS_MAGE,
|
||||
CLASS_BARD,
|
||||
CLASS_FIGHTER,
|
||||
CLASS_DRUID,
|
||||
CLASS_TINKER,
|
||||
CLASS_PALADIN,
|
||||
CLASS_RANGER,
|
||||
CLASS_SHEPHERD
|
||||
};
|
||||
|
||||
/**
|
||||
* The list of status values for the savegame character records. The
|
||||
* values match the letter that's appear in the ztats area.
|
||||
*/
|
||||
enum StatusType {
|
||||
STAT_GOOD = 'G',
|
||||
STAT_POISONED = 'P',
|
||||
STAT_SLEEPING = 'S',
|
||||
STAT_DEAD = 'D'
|
||||
};
|
||||
|
||||
enum Virtue {
|
||||
VIRT_HONESTY,
|
||||
VIRT_COMPASSION,
|
||||
VIRT_VALOR,
|
||||
VIRT_JUSTICE,
|
||||
VIRT_SACRIFICE,
|
||||
VIRT_HONOR,
|
||||
VIRT_SPIRITUALITY,
|
||||
VIRT_HUMILITY,
|
||||
VIRT_MAX
|
||||
};
|
||||
|
||||
enum BaseVirtue {
|
||||
VIRT_NONE = 0x00,
|
||||
VIRT_TRUTH = 0x01,
|
||||
VIRT_LOVE = 0x02,
|
||||
VIRT_COURAGE = 0x04
|
||||
};
|
||||
|
||||
enum Reagent {
|
||||
REAG_ASH,
|
||||
REAG_GINSENG,
|
||||
REAG_GARLIC,
|
||||
REAG_SILK,
|
||||
REAG_MOSS,
|
||||
REAG_PEARL,
|
||||
REAG_NIGHTSHADE,
|
||||
REAG_MANDRAKE,
|
||||
REAG_MAX
|
||||
};
|
||||
|
||||
#define SPELL_MAX 26
|
||||
|
||||
enum Item {
|
||||
ITEM_SKULL = 0x01,
|
||||
ITEM_SKULL_DESTROYED = 0x02,
|
||||
ITEM_CANDLE = 0x04,
|
||||
ITEM_BOOK = 0x08,
|
||||
ITEM_BELL = 0x10,
|
||||
ITEM_KEY_C = 0x20,
|
||||
ITEM_KEY_L = 0x40,
|
||||
ITEM_KEY_T = 0x80,
|
||||
ITEM_HORN = 0x100,
|
||||
ITEM_WHEEL = 0x200,
|
||||
ITEM_CANDLE_USED = 0x400,
|
||||
ITEM_BOOK_USED = 0x800,
|
||||
ITEM_BELL_USED = 0x1000
|
||||
};
|
||||
|
||||
enum Stone {
|
||||
STONE_BLUE = 0x01,
|
||||
STONE_YELLOW = 0x02,
|
||||
STONE_RED = 0x04,
|
||||
STONE_GREEN = 0x08,
|
||||
STONE_ORANGE = 0x10,
|
||||
STONE_PURPLE = 0x20,
|
||||
STONE_WHITE = 0x40,
|
||||
STONE_BLACK = 0x80
|
||||
};
|
||||
|
||||
enum Rune {
|
||||
RUNE_HONESTY = 0x01,
|
||||
RUNE_COMPASSION = 0x02,
|
||||
RUNE_VALOR = 0x04,
|
||||
RUNE_JUSTICE = 0x08,
|
||||
RUNE_SACRIFICE = 0x10,
|
||||
RUNE_HONOR = 0x20,
|
||||
RUNE_SPIRITUALITY = 0x40,
|
||||
RUNE_HUMILITY = 0x80
|
||||
};
|
||||
|
||||
/**
|
||||
* The Ultima IV savegame player record data.
|
||||
*/
|
||||
struct SaveGamePlayerRecord {
|
||||
void synchronize(Common::Serializer &s);
|
||||
void init();
|
||||
|
||||
unsigned short _hp;
|
||||
unsigned short _hpMax;
|
||||
unsigned short _xp;
|
||||
unsigned short _str, _dex, _intel;
|
||||
unsigned short _mp;
|
||||
unsigned short _unknown;
|
||||
WeaponType _weapon;
|
||||
ArmorType _armor;
|
||||
char _name[16];
|
||||
SexType _sex;
|
||||
ClassType _class;
|
||||
StatusType _status;
|
||||
};
|
||||
|
||||
/**
|
||||
* How Ultima IV stores monster information
|
||||
*/
|
||||
struct SaveGameMonsterRecord {
|
||||
byte _tile;
|
||||
byte _x;
|
||||
byte _y;
|
||||
byte _prevTile;
|
||||
byte _prevX;
|
||||
byte _prevY;
|
||||
byte _unused1;
|
||||
byte _unused2;
|
||||
|
||||
SaveGameMonsterRecord() {
|
||||
clear();
|
||||
}
|
||||
|
||||
void clear() {
|
||||
_tile = _x = _y = 0;
|
||||
_prevTile = _prevX = _prevY = 0;
|
||||
_unused1 = _unused2 = 0;
|
||||
}
|
||||
|
||||
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.
|
||||
*/
|
||||
struct SaveGame {
|
||||
/**
|
||||
* Initialize a new savegame structure
|
||||
*/
|
||||
void init(const SaveGamePlayerRecord *avatarInfo);
|
||||
|
||||
/**
|
||||
* Load an entire savegame, including monsters
|
||||
*/
|
||||
void save(Common::WriteStream *stream);
|
||||
|
||||
/**
|
||||
* Save an entire savegame, including monsters
|
||||
*/
|
||||
void load(Common::SeekableReadStream *stream);
|
||||
|
||||
/**
|
||||
* Called when a new game is started without loading an existing
|
||||
* savegame from launcher.
|
||||
*/
|
||||
void newGame();
|
||||
|
||||
/**
|
||||
* Synchronizes data for the savegame structure
|
||||
*/
|
||||
void synchronize(Common::Serializer &s);
|
||||
|
||||
uint _unknown1;
|
||||
uint _moves;
|
||||
SaveGamePlayerRecord _players[8];
|
||||
int _food;
|
||||
short _gold;
|
||||
short _karma[VIRT_MAX];
|
||||
short _torches;
|
||||
short _gems;
|
||||
short _keys;
|
||||
short _sextants;
|
||||
short _armor[ARMR_MAX];
|
||||
short _weapons[WEAP_MAX];
|
||||
short _reagents[REAG_MAX];
|
||||
short _mixtures[SPELL_MAX];
|
||||
unsigned short _items;
|
||||
LocationCoordsArray _positions;
|
||||
unsigned short _orientation;
|
||||
|
||||
byte _stones;
|
||||
byte _runes;
|
||||
unsigned short _members;
|
||||
unsigned short _transport;
|
||||
union {
|
||||
unsigned short _balloonState;
|
||||
unsigned short _torchDuration;
|
||||
};
|
||||
unsigned short _trammelPhase;
|
||||
unsigned short _feluccaPhase;
|
||||
unsigned short _shipHull;
|
||||
unsigned short _lbIntro;
|
||||
unsigned short _lastCamp;
|
||||
unsigned short _lastReagent;
|
||||
unsigned short _lastMeditation;
|
||||
unsigned short _lastVirtue;
|
||||
};
|
||||
|
||||
} // End of namespace Ultima4
|
||||
} // End of namespace Ultima
|
||||
|
||||
#endif
|
||||
44
engines/ultima/ultima4/filesys/u4file.cpp
Normal file
44
engines/ultima/ultima4/filesys/u4file.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "ultima/ultima4/filesys/u4file.h"
|
||||
#include "common/file.h"
|
||||
|
||||
namespace Ultima {
|
||||
namespace Ultima4 {
|
||||
|
||||
Std::vector<Common::String> u4read_stringtable(const Common::String &filename) {
|
||||
Common::File f;
|
||||
if (!f.open(Common::Path(Common::String::format("data/text/%s.dat", filename.c_str()))))
|
||||
error("Could not open string table '%s'", filename.c_str());
|
||||
|
||||
Std::vector<Common::String> strs;
|
||||
Common::String line;
|
||||
int64 filesize = f.size();
|
||||
|
||||
while (f.pos() < filesize)
|
||||
strs.push_back(f.readString());
|
||||
|
||||
return strs;
|
||||
}
|
||||
|
||||
} // End of namespace Ultima4
|
||||
} // End of namespace Ultima
|
||||
41
engines/ultima/ultima4/filesys/u4file.h
Normal file
41
engines/ultima/ultima4/filesys/u4file.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ULTIMA4_FILE_H
|
||||
#define ULTIMA4_FILE_H
|
||||
|
||||
#include "common/str.h"
|
||||
#include "ultima/shared/std/containers.h"
|
||||
|
||||
namespace Ultima {
|
||||
namespace Ultima4 {
|
||||
|
||||
/**
|
||||
* Read a series of zero terminated strings from a file. The strings
|
||||
* are read from the given offset, or the current file position if
|
||||
* offset is -1.
|
||||
*/
|
||||
extern Std::vector<Common::String> u4read_stringtable(const Common::String &filename);
|
||||
|
||||
} // End of namespace Ultima4
|
||||
} // End of namespace Ultima
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user