2018-11-10 12:21:23 -08:00
|
|
|
/* 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 2
|
|
|
|
* 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, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-11-13 19:47:07 -08:00
|
|
|
#include "glk/frotz/frotz.h"
|
|
|
|
#include "glk/frotz/frotz_types.h"
|
2018-11-25 12:41:39 -08:00
|
|
|
#include "glk/frotz/screen.h"
|
2018-11-26 22:18:45 -08:00
|
|
|
#include "glk/frotz/quetzal.h"
|
2018-11-11 21:44:15 -08:00
|
|
|
#include "common/config-manager.h"
|
2018-11-10 12:21:23 -08:00
|
|
|
|
2018-11-13 20:05:59 -08:00
|
|
|
namespace Glk {
|
2018-11-10 12:21:23 -08:00
|
|
|
namespace Frotz {
|
|
|
|
|
2018-11-10 17:54:35 -08:00
|
|
|
Frotz *g_vm;
|
|
|
|
|
2018-11-14 18:01:42 -08:00
|
|
|
Frotz::Frotz(OSystem *syst, const GlkGameDescription &gameDesc) :
|
2018-11-11 21:18:50 -08:00
|
|
|
Processor(syst, gameDesc) {
|
2018-11-10 17:54:35 -08:00
|
|
|
g_vm = this;
|
2018-11-10 12:21:23 -08:00
|
|
|
}
|
|
|
|
|
2018-11-12 18:42:45 -08:00
|
|
|
Frotz::~Frotz() {
|
|
|
|
reset_memory();
|
|
|
|
}
|
|
|
|
|
2018-11-25 12:41:39 -08:00
|
|
|
Screen *Frotz::createScreen() {
|
|
|
|
return new FrotzScreen();
|
|
|
|
}
|
|
|
|
|
2019-01-02 23:13:13 -08:00
|
|
|
void Frotz::runGame() {
|
|
|
|
story_fp = &_gameFile;
|
2018-11-10 21:43:03 -08:00
|
|
|
initialize();
|
|
|
|
|
2018-11-26 22:30:42 -08:00
|
|
|
// If save was selected from the launcher, handle loading it
|
|
|
|
int saveSlot = ConfMan.hasKey("save_slot") ? ConfMan.getInt("save_slot") : -1;
|
|
|
|
if (saveSlot != -1) {
|
2018-12-19 20:34:39 -08:00
|
|
|
int loadResult = loadGameState(saveSlot).getCode() == Common::kNoError ? 2 : -1;
|
2018-11-26 22:30:42 -08:00
|
|
|
|
|
|
|
if (h_version <= V3)
|
2018-12-19 20:34:39 -08:00
|
|
|
branch(loadResult);
|
2018-11-26 22:30:42 -08:00
|
|
|
else
|
2018-12-19 20:34:39 -08:00
|
|
|
store(loadResult);
|
2018-11-26 22:30:42 -08:00
|
|
|
}
|
|
|
|
|
2018-11-12 18:42:45 -08:00
|
|
|
// Game loop
|
|
|
|
interpret();
|
2018-11-23 21:08:53 -08:00
|
|
|
|
|
|
|
if (!shouldQuit()) {
|
|
|
|
flush_buffer();
|
|
|
|
glk_exit();
|
|
|
|
}
|
2018-11-10 12:21:23 -08:00
|
|
|
}
|
|
|
|
|
2018-11-11 21:44:15 -08:00
|
|
|
void Frotz::initialize() {
|
|
|
|
// Call process initialization
|
|
|
|
Processor::initialize();
|
2018-11-11 21:57:30 -08:00
|
|
|
|
|
|
|
// Restart the game
|
|
|
|
z_restart();
|
2018-11-11 21:44:15 -08:00
|
|
|
}
|
|
|
|
|
2018-11-25 22:25:31 -08:00
|
|
|
Common::Error Frotz::saveGameData(strid_t file, const Common::String &desc) {
|
2018-11-26 22:18:45 -08:00
|
|
|
Quetzal q(story_fp);
|
|
|
|
bool success = q.save(*file, this, desc);
|
2018-11-17 16:52:47 -08:00
|
|
|
|
2018-11-26 22:18:45 -08:00
|
|
|
if (!success)
|
2018-11-17 16:52:47 -08:00
|
|
|
print_string("Error writing save file\n");
|
|
|
|
|
2018-11-10 12:21:23 -08:00
|
|
|
return Common::kNoError;
|
|
|
|
}
|
|
|
|
|
2018-11-17 16:52:47 -08:00
|
|
|
Common::Error Frotz::loadGameData(strid_t file) {
|
2018-11-26 22:18:45 -08:00
|
|
|
Quetzal q(story_fp);
|
|
|
|
bool success = q.restore(*file, this) == 2;
|
|
|
|
|
|
|
|
if (success) {
|
|
|
|
zbyte old_screen_rows;
|
|
|
|
zbyte old_screen_cols;
|
|
|
|
|
|
|
|
// In V3, reset the upper window.
|
|
|
|
if (h_version == V3)
|
|
|
|
split_window(0);
|
|
|
|
|
|
|
|
LOW_BYTE(H_SCREEN_ROWS, old_screen_rows);
|
|
|
|
LOW_BYTE(H_SCREEN_COLS, old_screen_cols);
|
|
|
|
|
|
|
|
// Reload cached header fields
|
2018-12-18 21:55:07 -08:00
|
|
|
restart_header();
|
2018-11-26 22:18:45 -08:00
|
|
|
|
|
|
|
/* Since QUETZAL files may be saved on many different machines,
|
|
|
|
* the screen sizes may vary a lot. Erasing the status window
|
|
|
|
* seems to cover up most of the resulting badness.
|
|
|
|
*/
|
|
|
|
if (h_version > V3 && h_version != V6 && (h_screen_rows != old_screen_rows
|
|
|
|
|| h_screen_cols != old_screen_cols))
|
2018-12-18 21:55:07 -08:00
|
|
|
erase_window(1);
|
2018-11-17 16:52:47 -08:00
|
|
|
} else {
|
2018-11-26 22:18:45 -08:00
|
|
|
error("Error reading save file");
|
2018-11-17 16:52:47 -08:00
|
|
|
}
|
|
|
|
|
2018-11-10 12:21:23 -08:00
|
|
|
return Common::kNoError;
|
|
|
|
}
|
|
|
|
|
2019-01-01 19:04:12 -08:00
|
|
|
} // End of namespace Frotz
|
2018-11-13 20:05:59 -08:00
|
|
|
} // End of namespace Glk
|