ZVISION: Simplify the checks in the location changing code

This commit is contained in:
Filippos Karapetis 2015-01-19 23:52:08 +02:00
parent ecc45b961f
commit dcac5be493

View file

@ -564,12 +564,16 @@ void ScriptManager::ChangeLocationReal() {
assert(_nextLocation.world != 0); assert(_nextLocation.world != 0);
debug(1, "Changing location to: %c %c %c %c %u", _nextLocation.world, _nextLocation.room, _nextLocation.node, _nextLocation.view, _nextLocation.offset); debug(1, "Changing location to: %c %c %c %c %u", _nextLocation.world, _nextLocation.room, _nextLocation.node, _nextLocation.view, _nextLocation.offset);
if (_nextLocation.world == 'g' && _nextLocation.room == 'j' && !ConfMan.getBool("originalsaveload")) { const bool enteringMenu = (_nextLocation.world == 'g' && _nextLocation.room == 'j');
if ((_nextLocation.node == 's' || _nextLocation.node == 'r') && _nextLocation.view == 'e') { const bool leavingMenu = (_currentLocation.world == 'g' && _currentLocation.room == 'j');
const bool isSaveScreen = (enteringMenu && _nextLocation.node == 's' && _nextLocation.view == 'e');
const bool isRestoreScreen = (enteringMenu && _nextLocation.node == 'r' && _nextLocation.view == 'e');
if (enteringMenu && !ConfMan.getBool("originalsaveload")) {
if (isSaveScreen || isRestoreScreen) {
// Hook up the ScummVM save/restore dialog // Hook up the ScummVM save/restore dialog
bool isSave = (_nextLocation.node == 's'); bool gameSavedOrLoaded = _engine->getSaveManager()->scummVMSaveLoadDialog(isSaveScreen);
bool gameSavedOrLoaded = _engine->getSaveManager()->scummVMSaveLoadDialog(isSave); if (!gameSavedOrLoaded || isSaveScreen) {
if (!gameSavedOrLoaded || isSave) {
// Reload the current room // Reload the current room
_nextLocation.world = _currentLocation.world; _nextLocation.world = _currentLocation.world;
_nextLocation.room = _currentLocation.room; _nextLocation.room = _currentLocation.room;
@ -590,30 +594,26 @@ void ScriptManager::ChangeLocationReal() {
_engine->setRenderDelay(2); _engine->setRenderDelay(2);
if (getStateValue(StateKey_World) != 'g' || getStateValue(StateKey_Room) != 'j') { if (!enteringMenu) {
if (_nextLocation.world != 'g' || _nextLocation.room != 'j') { if (!leavingMenu) {
setStateValue(StateKey_LastWorld, getStateValue(StateKey_World)); setStateValue(StateKey_LastWorld, getStateValue(StateKey_World));
setStateValue(StateKey_LastRoom, getStateValue(StateKey_Room)); setStateValue(StateKey_LastRoom, getStateValue(StateKey_Room));
setStateValue(StateKey_LastNode, getStateValue(StateKey_Node)); setStateValue(StateKey_LastNode, getStateValue(StateKey_Node));
setStateValue(StateKey_LastView, getStateValue(StateKey_View)); setStateValue(StateKey_LastView, getStateValue(StateKey_View));
setStateValue(StateKey_LastViewPos, getStateValue(StateKey_ViewPos)); setStateValue(StateKey_LastViewPos, getStateValue(StateKey_ViewPos));
} else {
setStateValue(StateKey_Menu_LastWorld, getStateValue(StateKey_World));
setStateValue(StateKey_Menu_LastRoom, getStateValue(StateKey_Room));
setStateValue(StateKey_Menu_LastNode, getStateValue(StateKey_Node));
setStateValue(StateKey_Menu_LastView, getStateValue(StateKey_View));
setStateValue(StateKey_Menu_LastViewPos, getStateValue(StateKey_ViewPos));
}
}
if (_nextLocation.world == 'g' && _nextLocation.room == 'j') {
if (_nextLocation.node == 's' && _nextLocation.view == 'e' && _currentLocation.world != 'g') {
_engine->getSaveManager()->prepareSaveBuffer();
} }
} else { } else {
if (_currentLocation.world == 'g' && _currentLocation.room == 'j') { setStateValue(StateKey_Menu_LastWorld, getStateValue(StateKey_World));
_engine->getSaveManager()->flushSaveBuffer(); setStateValue(StateKey_Menu_LastRoom, getStateValue(StateKey_Room));
} setStateValue(StateKey_Menu_LastNode, getStateValue(StateKey_Node));
setStateValue(StateKey_Menu_LastView, getStateValue(StateKey_View));
setStateValue(StateKey_Menu_LastViewPos, getStateValue(StateKey_ViewPos));
}
if (isSaveScreen && !leavingMenu) {
_engine->getSaveManager()->prepareSaveBuffer();
} else if (leavingMenu) {
_engine->getSaveManager()->flushSaveBuffer();
} }
setStateValue(StateKey_World, _nextLocation.world); setStateValue(StateKey_World, _nextLocation.world);