Skip to content

Commit

Permalink
KYRA: (EOB) - Start implementing EOB1 party transfer (not working yet)
Browse files Browse the repository at this point in the history
(ScummVM specific solution which allows the selection of save files of all configured EOB1 targets)
  • Loading branch information
athrxx authored and Johannes Schickel committed Dec 26, 2011
1 parent 53e1bf2 commit c0e782f
Show file tree
Hide file tree
Showing 16 changed files with 297 additions and 47 deletions.
157 changes: 153 additions & 4 deletions engines/kyra/chargen.cpp
Expand Up @@ -26,8 +26,13 @@
#include "kyra/resource.h"
#include "kyra/sound_intern.h"

#include "common/savefile.h"
#include "common/str-array.h"

namespace Kyra {

// Character Generator

class CharacterGenerator {
public:
CharacterGenerator(EoBCoreEngine *vm, Screen_EoB *screen);
Expand Down Expand Up @@ -191,7 +196,7 @@ bool CharacterGenerator::start(EoBCharacter *characters, uint8 ***faceShapes) {
loop = false;
} else {
_activeBox = inputFlag;
inputFlag = 43;
inputFlag = _vm->_keyMap[Common::KEYCODE_RETURN];
}
}

Expand Down Expand Up @@ -1426,13 +1431,157 @@ const int16 CharacterGenerator::_raceModifiers[] = {
0, 0, 0, 0, 1, -1, 0, 1, -1, 0, 0, 0, -1, 0, 0, 1, 0, 0
};

// Transfer Party

class TransferPartyWiz {
public:
TransferPartyWiz(EoBCoreEngine *vm, Screen_EoB *screen);
~TransferPartyWiz();

bool start();

private:
bool selectAndLoadTransferFile();
Common::String transferFileDialogue();

void convertStats();

EoBCoreEngine *_vm;
Screen_EoB *_screen;
};

TransferPartyWiz::TransferPartyWiz(EoBCoreEngine *vm, Screen_EoB *screen) : _vm(vm), _screen(screen) {
}

TransferPartyWiz::~TransferPartyWiz() {

}

bool TransferPartyWiz::start() {
_screen->copyPage(0, 12);

if (!selectAndLoadTransferFile())
return false;

convertStats();

return true;
}

bool TransferPartyWiz::selectAndLoadTransferFile() {
for (int numLoops = 1; numLoops; numLoops--) {
_screen->copyPage(12, 0);
_vm->_savegameFilename = transferFileDialogue();
if (_vm->_savegameFilename.empty()) {
if (_vm->_gui->confirmDialogue2(15, 68, 1))
numLoops++;
}
}

if (_vm->_savegameFilename.equals(_vm->_saveLoadStrings[1]))
return false;

if (_vm->loadGameState(-1).getCode() != Common::kNoError)
return false;

return true;
}

Common::String TransferPartyWiz::transferFileDialogue() {
Common::StringArray saveFileList = _vm->_saveFileMan->listSavefiles("*.*");
Common::StringArray targets;
Common::String tfile;

KyraEngine_v1::SaveHeader header;
Common::InSaveFile *in;

for (Common::StringArray::iterator i = saveFileList.begin(); i != saveFileList.end(); ++i) {
if (!(in = _vm->_saveFileMan->openForLoading(*i)))
continue;

if (KyraEngine_v1::readSaveHeader(in, false, header)) {
delete in;
continue;
}

delete in;

if (header.gameID != GI_EOB1)
continue;

i->insertChar('\0', i->size() - 4);

Common::StringArray::iterator ii = targets.begin();
for (; ii != targets.end(); ++ii) {
if (!i->compareToIgnoreCase(*ii))
break;
}

if (ii == targets.end())
targets.push_back(*i);
}

if (targets.begin() == targets.end())
return tfile;

Common::String target = _vm->_gui->transferTargetMenu(targets);
_screen->copyPage(12, 0);

if (target.equals(_vm->_saveLoadStrings[1]))
return target;

tfile = target + ".fin";
in = _vm->_saveFileMan->openForLoading(tfile);
if (in) {
delete in;
if (_vm->_gui->confirmDialogue2(15, -2, 1))
return tfile;
}

_screen->copyPage(12, 0);

tfile = _vm->_gui->transferFileMenu(target);
_screen->copyPage(12, 0);

return tfile;
}

void TransferPartyWiz::convertStats() {
for (int i = 0; i < 6; i++) {
EoBCharacter *c = &_vm->_characters[i];
uint32 aflags = 0;

for (int ii = 0; ii < 25; ii++) {
if (c->mageSpellsAvailableFlags & (1 << ii)) {
int8 f = (int8)_vm->_transferConvertTable[i + 1] - 1;
if (f != -1)
aflags |= (1 << f);
}
}
c->mageSpellsAvailableFlags = aflags;

c->flags &= 1;
c->hitPointsCur = c->hitPointsMax;
c->food = 100;

for (int ii = 0; ii < 3; ii++) {
int t = _vm->getCharacterClassType(c->cClass, ii);
if (t == -1)
continue;
if (c->experience[ii] < _vm->_transferExpTable[t])
c->experience[ii] = _vm->_transferExpTable[t];
}
}
}

// Start functions

bool EoBCoreEngine::startCharacterGeneration() {
return CharacterGenerator(this, _screen).start(_characters, &_faceShapes);
}

bool EoBCoreEngine::transferParty() {

return false;
bool EoBCoreEngine::startPartyTransfer() {
return TransferPartyWiz(this, _screen).start();
}

} // End of namespace Kyra
Expand Down
3 changes: 2 additions & 1 deletion engines/kyra/eobcommon.cpp
Expand Up @@ -167,6 +167,7 @@ EoBCoreEngine::EoBCoreEngine(OSystem *system, const GameFlags &flags) : KyraRpgE
_expObjectAnimTbl1Size = _expObjectAnimTbl2Size = _expObjectAnimTbl3Size = _wllFlagPresetSize = _scriptTimersCount = _buttonList1Size = _buttonList2Size =
_buttonList3Size = _buttonList4Size = _buttonList5Size = _buttonList6Size = _buttonList7Size = _buttonList8Size = 0;
_inventorySlotsY = _mnDef = 0;
_transferStringsScummVM = 0;
_buttonDefs = 0;
_npcPreset = 0;
_chargenStatStrings = _chargenRaceSexStrings = _chargenClassStrings = _chargenAlignmentStrings = _pryDoorStrings = _warningStrings = _ripItemStrings =
Expand Down Expand Up @@ -463,7 +464,7 @@ Common::Error EoBCoreEngine::go() {
startupNew();
} else if (action == -3) {
// transfer party
repeatLoop = transferParty();
repeatLoop = startPartyTransfer();
if (repeatLoop && !shouldQuit())
startupNew();
}
Expand Down
4 changes: 3 additions & 1 deletion engines/kyra/eobcommon.h
Expand Up @@ -245,6 +245,7 @@ friend class GUI_EoB;
friend class EoBInfProcessor;
friend class DarkmoonSequenceHelper;
friend class CharacterGenerator;
friend class TransferPartyWiz;
public:
EoBCoreEngine(OSystem *system, const GameFlags &flags);
virtual ~EoBCoreEngine();
Expand Down Expand Up @@ -318,7 +319,7 @@ friend class CharacterGenerator;

// Character generation / party transfer
bool startCharacterGeneration();
bool transferParty();
bool startPartyTransfer();

uint8 **_faceShapes;

Expand Down Expand Up @@ -1125,6 +1126,7 @@ friend class CharacterGenerator;
const char *_menuOkString;

const char *const *_menuStringsTransfer;
const char *const *_transferStringsScummVM;
const char *const *_menuStringsSpec;
const char *const *_menuStringsSpellNo;
const char *const *_menuYesNoStrings;
Expand Down
12 changes: 6 additions & 6 deletions engines/kyra/gui.cpp
Expand Up @@ -46,8 +46,8 @@ GUI::~GUI() {
}
}

void GUI::updateSaveFileList(bool excludeQuickSaves) {
Common::String pattern = _vm->_targetName + ".???";
void GUI::updateSaveFileList(Common::String targetName, bool excludeQuickSaves) {
Common::String pattern = targetName + ".???";
Common::StringArray saveFileList = _vm->_saveFileMan->listSavefiles(pattern);
_saveSlots.clear();

Expand Down Expand Up @@ -93,8 +93,8 @@ int GUI::getNextSavegameSlot() {
return 0;
}

void GUI::updateSaveSlotsList() {
if (!_saveSlotsListUpdateNeeded)
void GUI::updateSaveSlotsList(Common::String targetName, bool force) {
if (!_saveSlotsListUpdateNeeded && !force)
return;

_saveSlotsListUpdateNeeded = false;
Expand All @@ -105,7 +105,7 @@ void GUI::updateSaveSlotsList() {
delete[] _savegameList;
}

updateSaveFileList(true);
updateSaveFileList(targetName, true);
int numSaves = _savegameListSize = _saveSlots.size();
bool allowEmptySlots = (_vm->game() == GI_EOB1 || _vm->game() == GI_EOB2);

Expand All @@ -120,7 +120,7 @@ void GUI::updateSaveSlotsList() {
memset(_savegameList, 0, _savegameListSize * sizeof(char*));

for (int i = 0; i < numSaves; i++) {
in = _vm->openSaveForReading(_vm->getSavegameFilename(_saveSlots[i]), header);
in = _vm->openSaveForReading(_vm->getSavegameFilename(targetName, _saveSlots[i]).c_str(), header, targetName == _vm->_targetName);
char **listEntry = &_savegameList[allowEmptySlots? _saveSlots[i] : i];
if (in) {
*listEntry = new char[header.description.size() + 1];
Expand Down
4 changes: 2 additions & 2 deletions engines/kyra/gui.h
Expand Up @@ -118,9 +118,9 @@ class GUI {
// Since ScummVM's savegame indices aren't, we re-index them.
// The integers stored in _saveSlots are ScummVM savegame indices.
Common::Array<int> _saveSlots;
void updateSaveFileList(bool excludeQuickSaves = false);
void updateSaveFileList(Common::String targetName, bool excludeQuickSaves = false);
int getNextSavegameSlot();
void updateSaveSlotsList();
void updateSaveSlotsList(Common::String targetName, bool force = false);

virtual void sortSaveSlots();

Expand Down

0 comments on commit c0e782f

Please sign in to comment.