diff options
| -rw-r--r-- | engines/zvision/graphics/cursors/cursor_manager.cpp | 31 | ||||
| -rw-r--r-- | engines/zvision/scripting/script_manager.cpp | 196 | 
2 files changed, 141 insertions, 86 deletions
diff --git a/engines/zvision/graphics/cursors/cursor_manager.cpp b/engines/zvision/graphics/cursors/cursor_manager.cpp index 1e048efedf..eeab18f4ba 100644 --- a/engines/zvision/graphics/cursors/cursor_manager.cpp +++ b/engines/zvision/graphics/cursors/cursor_manager.cpp @@ -124,31 +124,30 @@ void CursorManager::cursorDown(bool pushed) {  }  void CursorManager::changeCursor(int id) { -	int _id = id; - -	if (_item && -	        (_id == CursorIndex_Active || -	         _id == CursorIndex_Idle || -	         _id == CursorIndex_HandPu)) { - -		if (_id == CursorIndex_Idle) -			_id = CursorIndex_ItemIdle; -		else -			_id = CursorIndex_ItemAct; +	if (_item && (id == CursorIndex_Active || +	              id == CursorIndex_Idle || +	              id == CursorIndex_HandPu)) { +		if (id == CursorIndex_Idle) { +			id = CursorIndex_ItemIdle; +		} else { +			id = CursorIndex_ItemAct; +		}  	} -	if (_currentCursor != _id || -	        ((_id == CursorIndex_ItemAct || _id == CursorIndex_ItemIdle) && _lastitem != _item)) { -		_currentCursor = _id; +	if (_currentCursor != id || ((id == CursorIndex_ItemAct || id == CursorIndex_ItemIdle) && _lastitem != _item)) { +		_currentCursor = id;  		_lastitem = _item;  		changeCursor(_cursors[_currentCursor][_cursorIsPushed]);  	}  }  int CursorManager::getCursorId(const Common::String &name) { -	for (int i = 0; i < NUM_CURSORS; i++) -		if (name.equals(_cursorNames[i])) +	for (int i = 0; i < NUM_CURSORS; i++) { +		if (name.equals(_cursorNames[i])) {  			return i; +		} +	} +  	return CursorIndex_Idle;  } diff --git a/engines/zvision/scripting/script_manager.cpp b/engines/zvision/scripting/script_manager.cpp index ad049434c3..4792a02045 100644 --- a/engines/zvision/scripting/script_manager.cpp +++ b/engines/zvision/scripting/script_manager.cpp @@ -72,21 +72,24 @@ void ScriptManager::initialize() {  }  void ScriptManager::update(uint deltaTimeMillis) { -	if (_currentLocation.node != _nextLocation.node || -	        _currentLocation.room != _nextLocation.room || -	        _currentLocation.view != _nextLocation.view || -	        _currentLocation.world != _nextLocation.world) +	if (_currentLocation.node != _nextLocation.node || _currentLocation.room != _nextLocation.room || +	        _currentLocation.view != _nextLocation.view || _currentLocation.world != _nextLocation.world) {  		ChangeLocationReal(); +	}  	updateNodes(deltaTimeMillis); -	if (! execScope(nodeview)) +	if (! execScope(nodeview)) {  		return; -	if (! execScope(room)) +	} +	if (! execScope(room)) {  		return; -	if (! execScope(world)) +	} +	if (! execScope(world)) {  		return; -	if (! execScope(universe)) +	} +	if (! execScope(universe)) {  		return; +	}  	updateControls(deltaTimeMillis);  } @@ -97,17 +100,22 @@ bool ScriptManager::execScope(ScriptScope &scope) {  	scope.scopeQueue = tmp;  	scope.scopeQueue->clear(); -	for (PuzzleList::iterator PuzzleIter = scope.puzzles.begin(); PuzzleIter != scope.puzzles.end(); ++PuzzleIter) +	for (PuzzleList::iterator PuzzleIter = scope.puzzles.begin(); PuzzleIter != scope.puzzles.end(); ++PuzzleIter) {  		(*PuzzleIter)->addedBySetState = false; +	}  	if (scope.procCount < 2 || getStateValue(StateKey_ExecScopeStyle)) { -		for (PuzzleList::iterator PuzzleIter = scope.puzzles.begin(); PuzzleIter != scope.puzzles.end(); ++PuzzleIter) -			if (!checkPuzzleCriteria(*PuzzleIter, scope.procCount)) +		for (PuzzleList::iterator PuzzleIter = scope.puzzles.begin(); PuzzleIter != scope.puzzles.end(); ++PuzzleIter) { +			if (!checkPuzzleCriteria(*PuzzleIter, scope.procCount)) {  				return false; +			} +		}  	} else { -		for (PuzzleList::iterator PuzzleIter = scope.execQueue->begin(); PuzzleIter != scope.execQueue->end(); ++PuzzleIter) -			if (!checkPuzzleCriteria(*PuzzleIter, scope.procCount)) +		for (PuzzleList::iterator PuzzleIter = scope.execQueue->begin(); PuzzleIter != scope.execQueue->end(); ++PuzzleIter) { +			if (!checkPuzzleCriteria(*PuzzleIter, scope.procCount)) {  				return false; +			} +		}  	}  	if (scope.procCount < 2) { @@ -119,9 +127,11 @@ bool ScriptManager::execScope(ScriptScope &scope) {  void ScriptManager::referenceTableAddPuzzle(uint32 key, PuzzleRef ref) {  	if (_referenceTable.contains(key)) {  		Common::Array<PuzzleRef> *arr = &_referenceTable[key]; -		for (uint32 i = 0; i < arr->size(); i++) -			if ((*arr)[i].puz == ref.puz) +		for (uint32 i = 0; i < arr->size(); i++) { +			if ((*arr)[i].puz == ref.puz) {  				return; +			} +		}  	}  	_referenceTable[key].push_back(ref); @@ -139,9 +149,11 @@ void ScriptManager::addPuzzlesToReferenceTable(ScriptScope &scope) {  		referenceTableAddPuzzle(puzzlePtr->key, ref);  		// Iterate through each CriteriaEntry and add a reference from the criteria key to the Puzzle -		for (Common::List<Common::List<Puzzle::CriteriaEntry> >::iterator criteriaIter = (*PuzzleIter)->criteriaList.begin(); criteriaIter != (*PuzzleIter)->criteriaList.end(); ++criteriaIter) -			for (Common::List<Puzzle::CriteriaEntry>::iterator entryIter = criteriaIter->begin(); entryIter != criteriaIter->end(); ++entryIter) +		for (Common::List<Common::List<Puzzle::CriteriaEntry> >::iterator criteriaIter = (*PuzzleIter)->criteriaList.begin(); criteriaIter != (*PuzzleIter)->criteriaList.end(); ++criteriaIter) { +			for (Common::List<Puzzle::CriteriaEntry>::iterator entryIter = criteriaIter->begin(); entryIter != criteriaIter->end(); ++entryIter) {  				referenceTableAddPuzzle(entryIter->key, ref); +			} +		}  	}  } @@ -159,8 +171,9 @@ void ScriptManager::updateNodes(uint deltaTimeMillis) {  }  void ScriptManager::updateControls(uint deltaTimeMillis) { -	if (!_activeControls) +	if (!_activeControls) {  		return; +	}  	// Process only one event  	if (!_controlEvents.empty()) { @@ -187,9 +200,11 @@ void ScriptManager::updateControls(uint deltaTimeMillis) {  		_controlEvents.pop_front();  	} -	for (ControlList::iterator iter = _activeControls->begin(); iter != _activeControls->end(); iter++) -		if ((*iter)->process(deltaTimeMillis)) +	for (ControlList::iterator iter = _activeControls->begin(); iter != _activeControls->end(); iter++) { +		if ((*iter)->process(deltaTimeMillis)) {  			break; +		} +	}  }  bool ScriptManager::checkPuzzleCriteria(Puzzle *puzzle, uint counter) { @@ -200,8 +215,9 @@ bool ScriptManager::checkPuzzleCriteria(Puzzle *puzzle, uint counter) {  	}  	// Check each Criteria -	if (counter == 0 && (getStateFlag(puzzle->key) & Puzzle::DO_ME_NOW) == 0) +	if (counter == 0 && (getStateFlag(puzzle->key) & Puzzle::DO_ME_NOW) == 0) {  		return true; +	}  	bool criteriaMet = false;  	for (Common::List<Common::List<Puzzle::CriteriaEntry> >::iterator criteriaIter = puzzle->criteriaList.begin(); criteriaIter != puzzle->criteriaList.end(); ++criteriaIter) { @@ -210,10 +226,11 @@ bool ScriptManager::checkPuzzleCriteria(Puzzle *puzzle, uint counter) {  		for (Common::List<Puzzle::CriteriaEntry>::iterator entryIter = criteriaIter->begin(); entryIter != criteriaIter->end(); ++entryIter) {  			// Get the value to compare against  			int argumentValue; -			if (entryIter->argumentIsAKey) +			if (entryIter->argumentIsAKey) {  				argumentValue = getStateValue(entryIter->argument); -			else +			} else {  				argumentValue = entryIter->argument; +			}  			// Do the comparison  			switch (entryIter->criteriaOperator) { @@ -251,8 +268,9 @@ bool ScriptManager::checkPuzzleCriteria(Puzzle *puzzle, uint counter) {  		setStateValue(puzzle->key, 1);  		for (Common::List<ResultAction *>::iterator resultIter = puzzle->resultActions.begin(); resultIter != puzzle->resultActions.end(); ++resultIter) { -			if (!(*resultIter)->execute()) +			if (!(*resultIter)->execute()) {  				return false; +			}  		}  	} @@ -275,13 +293,15 @@ void ScriptManager::cleanScriptScope(ScriptScope &scope) {  	scope.privQueueTwo.clear();  	scope.scopeQueue = &scope.privQueueOne;  	scope.execQueue = &scope.privQueueTwo; -	for (PuzzleList::iterator iter = scope.puzzles.begin(); iter != scope.puzzles.end(); ++iter) +	for (PuzzleList::iterator iter = scope.puzzles.begin(); iter != scope.puzzles.end(); ++iter) {  		delete(*iter); +	}  	scope.puzzles.clear(); -	for (ControlList::iterator iter = scope.controls.begin(); iter != scope.controls.end(); ++iter) +	for (ControlList::iterator iter = scope.controls.begin(); iter != scope.controls.end(); ++iter) {  		delete(*iter); +	}  	scope.controls.clear(); @@ -289,44 +309,49 @@ void ScriptManager::cleanScriptScope(ScriptScope &scope) {  }  int ScriptManager::getStateValue(uint32 key) { -	if (_globalState.contains(key)) +	if (_globalState.contains(key)) {  		return _globalState[key]; -	else +	} else {  		return 0; +	}  }  void ScriptManager::queuePuzzles(uint32 key) {  	if (_referenceTable.contains(key)) {  		Common::Array<PuzzleRef> *arr = &_referenceTable[key]; -		for (int32 i = arr->size() - 1; i >= 0; i--) +		for (int32 i = arr->size() - 1; i >= 0; i--) {  			if (!(*arr)[i].puz->addedBySetState) {  				(*arr)[i].scope->scopeQueue->push_back((*arr)[i].puz);  				(*arr)[i].puz->addedBySetState = true;  			} +		}  	}  }  void ScriptManager::setStateValue(uint32 key, int value) { -	if (value == 0) +	if (value == 0) {  		_globalState.erase(key); -	else +	} else {  		_globalState[key] = value; +	}  	queuePuzzles(key);  }  void ScriptManager::setStateValueSilent(uint32 key, int value) { -	if (value == 0) +	if (value == 0) {  		_globalState.erase(key); -	else +	} else {  		_globalState[key] = value; +	}  }  uint ScriptManager::getStateFlag(uint32 key) { -	if (_globalStateFlags.contains(key)) +	if (_globalStateFlags.contains(key)) {  		return _globalStateFlags[key]; -	else +	} else {  		return 0; +	}  }  void ScriptManager::setStateFlag(uint32 key, uint value) { @@ -336,10 +361,11 @@ void ScriptManager::setStateFlag(uint32 key, uint value) {  }  void ScriptManager::setStateFlagSilent(uint32 key, uint value) { -	if (value == 0) +	if (value == 0) {  		_globalStateFlags.erase(key); -	else +	} else {  		_globalStateFlags[key] = value; +	}  }  void ScriptManager::unsetStateFlag(uint32 key, uint value) { @@ -348,23 +374,29 @@ void ScriptManager::unsetStateFlag(uint32 key, uint value) {  	if (_globalStateFlags.contains(key)) {  		_globalStateFlags[key] &= ~value; -		if (_globalStateFlags[key] == 0) +		if (_globalStateFlags[key] == 0) {  			_globalStateFlags.erase(key); +		}  	}  }  Control *ScriptManager::getControl(uint32 key) { -	for (ControlList::iterator iter = _activeControls->begin(); iter != _activeControls->end(); ++iter) -		if ((*iter)->getKey() == key) +	for (ControlList::iterator iter = _activeControls->begin(); iter != _activeControls->end(); ++iter) { +		if ((*iter)->getKey() == key) {  			return *iter; +		} +	} +  	return nullptr;  }  void ScriptManager::focusControl(uint32 key) { -	if (!_activeControls) +	if (!_activeControls) {  		return; -	if (_currentlyFocusedControl == key) +	} +	if (_currentlyFocusedControl == key) {  		return; +	}  	for (ControlList::iterator iter = _activeControls->begin(); iter != _activeControls->end(); ++iter) {  		uint32 controlKey = (*iter)->getKey(); @@ -443,50 +475,60 @@ void ScriptManager::killSideFxType(ScriptingEffect::ScriptingEffectType type) {  }  void ScriptManager::onMouseDown(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) { -	if (!_activeControls) +	if (!_activeControls) {  		return; +	}  	for (ControlList::iterator iter = _activeControls->reverse_begin(); iter != _activeControls->end(); iter--) { -		if ((*iter)->onMouseDown(screenSpacePos, backgroundImageSpacePos)) +		if ((*iter)->onMouseDown(screenSpacePos, backgroundImageSpacePos)) {  			return; +		}  	}  }  void ScriptManager::onMouseUp(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) { -	if (!_activeControls) +	if (!_activeControls) {  		return; +	}  	for (ControlList::iterator iter = _activeControls->reverse_begin(); iter != _activeControls->end(); iter--) { -		if ((*iter)->onMouseUp(screenSpacePos, backgroundImageSpacePos)) +		if ((*iter)->onMouseUp(screenSpacePos, backgroundImageSpacePos)) {  			return; +		}  	}  }  bool ScriptManager::onMouseMove(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) { -	if (!_activeControls) +	if (!_activeControls) {  		return false; +	}  	for (ControlList::iterator iter = _activeControls->reverse_begin(); iter != _activeControls->end(); iter--) { -		if ((*iter)->onMouseMove(screenSpacePos, backgroundImageSpacePos)) +		if ((*iter)->onMouseMove(screenSpacePos, backgroundImageSpacePos)) {  			return true; +		}  	}  	return false;  }  void ScriptManager::onKeyDown(Common::KeyState keyState) { -	if (!_activeControls) +	if (!_activeControls) {  		return; +	}  	for (ControlList::iterator iter = _activeControls->begin(); iter != _activeControls->end(); ++iter) { -		if ((*iter)->onKeyDown(keyState)) +		if ((*iter)->onKeyDown(keyState)) {  			return; +		}  	}  }  void ScriptManager::onKeyUp(Common::KeyState keyState) { -	if (!_activeControls) +	if (!_activeControls) {  		return; +	}  	for (ControlList::iterator iter = _activeControls->begin(); iter != _activeControls->end(); ++iter) { -		if ((*iter)->onKeyUp(keyState)) +		if ((*iter)->onKeyUp(keyState)) {  			return; +		}  	}  } @@ -539,8 +581,9 @@ void ScriptManager::ChangeLocationReal() {  				_currentLocation.node = '0';  				_currentLocation.view = '0';  				_currentLocation.offset = 0; -			} else +			} else {  				return; +			}  		}  	} @@ -563,12 +606,13 @@ void ScriptManager::ChangeLocationReal() {  	}  	if (_nextLocation.world == 'g' && _nextLocation.room == 'j') { -		if (_nextLocation.node == 's' && _nextLocation.view == 'e' && -		        _currentLocation.world != 'g' && _currentLocation.room != 'j') +		if (_nextLocation.node == 's' && _nextLocation.view == 'e' && _currentLocation.world != 'g' && _currentLocation.room != 'j') {  			_engine->getSaveManager()->prepareSaveBuffer(); +		}  	} else { -		if (_currentLocation.world == 'g' && _currentLocation.room == 'j') +		if (_currentLocation.world == 'g' && _currentLocation.room == 'j') {  			_engine->getSaveManager()->flushSaveBuffer(); +		}  	}  	setStateValue(StateKey_World, _nextLocation.world); @@ -664,26 +708,30 @@ void ScriptManager::serialize(Common::WriteStream *stream) {  	stream->writeByte(getStateValue(StateKey_View));  	stream->writeUint32LE(getStateValue(StateKey_ViewPos)); -	for (SideFXList::iterator iter = _activeSideFx.begin(); iter != _activeSideFx.end(); ++iter) +	for (SideFXList::iterator iter = _activeSideFx.begin(); iter != _activeSideFx.end(); ++iter) {  		(*iter)->serialize(stream); +	}  	stream->writeUint32BE(MKTAG('F', 'L', 'A', 'G'));  	int32 slots = 20000; -	if (_engine->getGameId() == GID_NEMESIS) +	if (_engine->getGameId() == GID_NEMESIS) {  		slots = 30000; +	}  	stream->writeUint32LE(slots * 2); -	for (int32 i = 0; i < slots; i++) +	for (int32 i = 0; i < slots; i++) {  		stream->writeUint16LE(getStateFlag(i)); +	}  	stream->writeUint32BE(MKTAG('P', 'U', 'Z', 'Z'));  	stream->writeUint32LE(slots * 2); -	for (int32 i = 0; i < slots; i++) +	for (int32 i = 0; i < slots; i++) {  		stream->writeSint16LE(getStateValue(i)); +	}  }  void ScriptManager::deserialize(Common::SeekableReadStream *stream) { @@ -700,8 +748,9 @@ void ScriptManager::deserialize(Common::SeekableReadStream *stream) {  	_currentLocation.room = 0;  	_currentLocation.view = 0; -	for (SideFXList::iterator iter = _activeSideFx.begin(); iter != _activeSideFx.end(); iter++) +	for (SideFXList::iterator iter = _activeSideFx.begin(); iter != _activeSideFx.end(); iter++) {  		delete(*iter); +	}  	_activeSideFx.clear(); @@ -734,20 +783,23 @@ void ScriptManager::deserialize(Common::SeekableReadStream *stream) {  		case MKTAG('T', 'I', 'M', 'R'): {  			uint32 key = stream->readUint32LE();  			uint32 time = stream->readUint32LE(); -			if (_engine->getGameId() == GID_GRANDINQUISITOR) +			if (_engine->getGameId() == GID_GRANDINQUISITOR) {  				time /= 100; -			else if (_engine->getGameId() == GID_NEMESIS) +			} else if (_engine->getGameId() == GID_NEMESIS) {  				time /= 1000; +			}  			addSideFX(new TimerNode(_engine, key, time));  		}  		break;  		case MKTAG('F', 'L', 'A', 'G'): -			for (uint32 i = 0; i < tagSize / 2; i++) +			for (uint32 i = 0; i < tagSize / 2; i++) {  				setStateFlagSilent(i, stream->readUint16LE()); +			}  			break;  		case MKTAG('P', 'U', 'Z', 'Z'): -			for (uint32 i = 0; i < tagSize / 2; i++) +			for (uint32 i = 0; i < tagSize / 2; i++) {  				setStateValueSilent(i, stream->readUint16LE()); +			}  			break;  		default:  			stream->seek(tagSize, SEEK_CUR); @@ -801,10 +853,11 @@ void ScriptManager::flushEvent(Common::EventType type) {  	EventList::iterator it = _controlEvents.begin();  	while (it != _controlEvents.end()) { -		if ((*it).type == type) +		if ((*it).type == type) {  			it = _controlEvents.erase(it); -		else +		} else {  			it++; +		}  	}  } @@ -833,12 +886,15 @@ ValueSlot::ValueSlot(ScriptManager *scriptManager, const char *slotValue):  }  int16 ValueSlot::getValue() {  	if (slot) { -		if (value >= 0) +		if (value >= 0) {  			return _scriptManager->getStateValue(value); -		else +		} +		else {  			return 0; -	} else +		} +	} else {  		return value; +	}  }  } // End of namespace ZVision  | 
