Exemple #1
0
void Game::oop_playSoundLowerPriority() {
	debug(DBG_OPCODES, "Game::oop_playSoundLowerPriority()");
	int num = _objectScript.fetchNextWord();
	int priority = _objectScript.fetchNextWord();
	if (priority >= _currentPlayingSoundPriority) {
		if (win16_sndPlaySound(22) == 0) {
			return;
		}
	}
	SceneObject *so = derefSceneObject(_objectScript.currentObjectNum);
	num += _animationsTable[_sceneObjectMotionsTable[so->motionNum1].animNum].firstSoundBufferIndex - 1;
	assert(num >= 0 && num < _soundBuffersCount);
	win16_sndPlaySound(3, _soundBuffersTable[num].filename); // win16_sndPlaySound(7, _soundBuffersTable[num].buffer);
	_currentPlayingSoundPriority = priority;
}
Exemple #2
0
void Game::clearSceneData(int anim) {
	debug(DBG_GAME, "Game::clearSceneData(%d)", anim);
	if (anim == -1) {
		_sceneConditionsCount = 0;
		_soundBuffersCount = 0;
		_animationsCount = 0;
		_sceneObjectsCount = 0;
		_sceneObjectMotionsCount = 0;
		_sceneObjectFramesCount = 0;
		_loadDataState = 0;
	} else {
		_animationsCount = anim + 1;
		SceneAnimation *sa = &_animationsTable[anim];
		_sceneObjectMotionsCount = sa->firstMotionIndex + sa->motionsCount;
		SceneObjectMotion *som = &_sceneObjectMotionsTable[_sceneObjectMotionsCount - 1];
		_sceneObjectFramesCount = som->firstFrameIndex + som->count;
		_sceneObjectsCount = sa->firstObjectIndex + sa->objectsCount;
		_soundBuffersCount = sa->firstSoundBufferIndex + sa->soundBuffersCount;
		_sceneConditionsCount = 0;
		_loadDataState = 2;
	}
	win16_sndPlaySound(7);
//	for (int i = NUM_SOUND_BUFFERS - 1; i >= _soundBuffersCount; --i) {
//		SoundBuffer *sb = &_soundBuffersTable[i];
//		if (sb->buffer) {
//			free(sb->buffer);
//			sb->buffer = 0;
//		}
//	}
//	for (int i = NUM_SCENE_OBJECT_FRAMES - 1; i >= _sceneObjectFramesCount; --i) {
	for (int i = _sceneObjectFramesCount; i < NUM_SCENE_OBJECT_FRAMES; ++i) {
		SceneObjectFrame *sof = &_sceneObjectFramesTable[i];
		if (sof->data) {
			free(sof->data);
			sof->data = 0;
		}
	}
//	for (int i = NUM_SCENE_ANIMATIONS - 1; i >= _animationsCount; --i) {
	for (int i = _animationsCount; i < NUM_SCENE_ANIMATIONS; ++i) {
		SceneAnimation *sa = &_animationsTable[i];
		if (sa->scriptData) {
			free(sa->scriptData);
			sa->scriptData = 0;
		}
	}
//	for (int i = NUM_SCENE_OBJECTS - 1; i >= _sceneObjectsCount; --i) {
	for (int i = _sceneObjectsCount; i < NUM_SCENE_OBJECTS; ++i) {
		SceneObject *so = &_sceneObjectsTable[i];
		so->state = 0;
		memset(so->varsTable, 0, sizeof(so->varsTable));
	}
	for (int i = 0; i < 10; ++i) {
		_boxesCountTable[i] = 0;
	}
}
Exemple #3
0
void Game::mainLoop() {
	if (_nextState != _state) {
		// fini
		switch (_state) {
		case kStateGame:
			break;
		case kStateDialogue:
			finiDialogue();
			break;
		case kStateMenu1:
		case kStateMenu2:
			finiMenu();
			break;
		}
		_state = _nextState;
		// init
		switch (_state) {
		case kStateGame:
			break;
		case kStateDialogue:
			initDialogue();
			break;
		case kStateBitmap:
			displayTitleBitmap();
			break;
		case kStateMenu1:
		case kStateMenu2:
			initMenu(1 + _state - kStateMenu1);
			break;
		}
	}
	switch (_state) {
	case kStateGame:
		while (_switchScene) {
			_switchScene = false;
			if (stringEndsWith(_tempTextBuffer, "SCN")) {
				win16_sndPlaySound(6);
				debug(DBG_GAME, "switch to scene '%s'", _tempTextBuffer);
				if (strcmp(_tempTextBuffer, "PIC4.SCN") == 0) {
					debug(DBG_INFO, "End of game");
					break;
				}
				strcpy(_currentSceneScn, _tempTextBuffer);
				parseSCN(_tempTextBuffer);
			} else {
				debug(DBG_GAME, "load mov '%s'", _tempTextBuffer);
				loadMOV(_tempTextBuffer);
			}
			if (_loadState) {
				_loadState = false;
				if (_currentSceneSav[0]) {
					FileHolder fh(_fs, _currentSceneSav);
					if (!fh._fp) {
						warning("Unable to load game state from file '%s'", _tempTextBuffer);
					} else {
						warning("Loading game state from '%s'", _currentSceneSav);
						loadState(fh._fp, kDemoSavSlot, false);
						loadKBR(_currentSceneSav);
					}
				} else {
					char filePath[MAXPATHLEN];
					snprintf(filePath, sizeof(filePath), kGameStateFileNameFormat, _savePath, _stateSlot);
					File f;
					if (!f.open(filePath, "rb")) {
						warning("Unable to load game state from file '%s'", filePath);
					} else {
						loadState(&f, _stateSlot, false);
					}
				}
				playMusic(_musicName);
				memset(_keysPressed, 0, sizeof(_keysPressed));
			}
			assert(_sceneObjectsCount != 0);
			if (_currentBagObject == -1) {
				_currentBagObject = _bagObjectsCount - 1;
				if (_currentBagObject > 0) {
					_currentBagObject = 0;
				}
			}
			if (_loadDataState != 0) {
				_stub->setPalette(_bitmapBuffer0 + kOffsetBitmapPalette, 256);
				_stub->copyRectWidescreen(kGameScreenWidth, kGameScreenHeight, _bitmapBuffer1.bits, _bitmapBuffer1.pitch);
			}
			_gameOver = false;
			_workaroundRaftFlySceneBug = strncmp(_currentSceneScn, "FLY", 3) == 0;
		}
		updateKeysPressedTable();
		updateMouseButtonsPressed();
		runObjectsScript();
		if (_startDialogue) {
			_startDialogue = false;
			_nextState = kStateDialogue;
		}
		break;
	case kStateBag:
		handleBagMenu();
		break;
	case kStateDialogue:
		handleDialogue();
		if (_dialogueEndedFlag) {
			_nextState = kStateGame;
		}
		break;
	case kStateBitmap:
		if (_stub->_pi.enter) {
			_stub->_pi.enter = false;
			playVideo("DATA/INTRO.AVI");
			_nextState = kStateGame;
		}
		break;
	case kStateMenu1:
		handleMenu();
		switch (_menuOption) {
		case kMenuOptionNewGame:
			restart();
			_nextState = kStateGame;
			break;
		case kMenuOptionLoadGame:
			_stub->_pi.load = true;
			_nextState = kStateGame;
			break;
		case kMenuOptionSaveGame:
			_stub->_pi.save = true;
			_nextState = kStateGame;
			break;
		case kMenuOptionQuitGame:
			_nextState = kStateMenu2;
			break;
		}
		if (_stub->_pi.escape) {
			_stub->_pi.escape = false;
			_nextState = kStateGame;
		}
		break;
	case kStateMenu2:
		handleMenu();
		switch (_menuOption) {
		case kMenuOptionExitGame:
			_stub->_quit = true;
			break;
		case kMenuOptionReturnGame:
			_nextState = kStateGame;
			break;
		}
		if (_stub->_pi.escape) {
			_stub->_pi.escape = false;
			_nextState = kStateGame;
		}
		break;
	}
	_stub->updateScreen();
}
Exemple #4
0
void Game::mainLoop() {
	_stub->init(_gameWindowTitle, kGameScreenWidth, kGameScreenHeight);
	allocateTables();
	loadCommonSprites();
	_mixer->open();
	restart();
	if (_isDemo) {
		playBitmapSequenceDemo();
	} else {
		playVideo("DATA/LOGO.AVI");
		playVideo("DATA/INTRO.AVI");
	}
	_lastFrameTimeStamp = _stub->getTimeStamp();
	while (!_stub->_quit) {
		if (_switchScene) {
			_switchScene = false;
			if (stringEndsWith(_tempTextBuffer, "SCN")) {
				win16_sndPlaySound(6);
				debug(DBG_GAME, "switch to scene '%s'", _tempTextBuffer);
				if (strcmp(_tempTextBuffer, "PIC4.SCN") == 0) {
					debug(DBG_INFO, "End of game");
					break;
				}
				strcpy(_currentSceneScn, _tempTextBuffer);
				parseSCN(_tempTextBuffer);
			} else if (stringEndsWith(_tempTextBuffer, "SAV")) {
				if (_isDemo && strcmp(_tempTextBuffer, "A16.SAV") == 0) {
					debug(DBG_GAME, "End of demo interactive part");
					restart();
					continue;
				}
				warning("Ignoring savestate load '%s'", _tempTextBuffer);
				// should work though, as the original savestates load fine
				// now, but this "feature" is only used in the demo AFAICT,
				// so no need to bother...
			} else {
				debug(DBG_GAME, "load mov '%s'", _tempTextBuffer);
				loadMOV(_tempTextBuffer);
			}
			if (_loadState) {
				_loadState = false;
				loadState(_stateSlot, false);
				playMusic(_musicName);
				memset(_keysPressed, 0, sizeof(_keysPressed));
			}
			assert(_sceneObjectsCount != 0);
			if (_currentBagObject == -1) {
				_currentBagObject = _bagObjectsCount - 1;
				if (_currentBagObject > 0) {
					_currentBagObject = 0;
				}
			}
			if (_loadDataState != 0) {
				setupScreenPalette(_bitmapBuffer0 + kOffsetBitmapPalette);
			}
			_gameOver = false;
			_workaroundRaftFlySceneBug = strncmp(_currentSceneScn, "FLY", 3) == 0;
		}
		updateKeysPressedTable();
		updateMouseButtonsPressed();
		runObjectsScript();
		if (!_switchScene) {
			_stub->updateScreen();
			uint32 end = _lastFrameTimeStamp + kCycleDelay;
			do {
				_stub->sleep(10);
				_stub->processEvents();
			} while (!_stub->_pi.fastMode && _stub->getTimeStamp() < end);
			_lastFrameTimeStamp = _stub->getTimeStamp();
		}
		if (_startDialogue) {
			_startDialogue = false;
			handleDialogue();
		}
	}
	clearSceneData(-1);
	deallocateTables();
	unloadCommonSprites();
	_mixer->close();
	_stub->destroy();
}