示例#1
0
void FloorManager::kill() {
	setFloorNull();
	if (_currentFloor) {
		delete _currentFloor;
		_currentFloor = nullptr;
	}
}
示例#2
0
bool FloorManager::load(Common::SeekableReadStream *stream) {
	if (stream->readByte()) {
		if (!setFloor(stream->readUint16BE()))
			return false;
	} else {
		setFloorNull();
	}
	return true;
}
示例#3
0
bool FloorManager::setFloor(int fileNum) {

	int i, j;

	setFloorNull();

	setResourceForFatal(fileNum);

	if (!g_sludge->_resMan->openFileFromNum(fileNum))
		return false;

	// Find out how many polygons there are and reserve memory

	_currentFloor->originalNum = fileNum;
	_currentFloor->numPolygons = g_sludge->_resMan->getData()->readByte();
	_currentFloor->polygon = new FloorPolygon[_currentFloor->numPolygons];
	if (!checkNew(_currentFloor->polygon))
		return false;

	// Read in each polygon

	for (i = 0; i < _currentFloor->numPolygons; i++) {

		// Find out how many vertex IDs there are and reserve memory

		_currentFloor->polygon[i].numVertices = g_sludge->_resMan->getData()->readByte();
		_currentFloor->polygon[i].vertexID = new int[_currentFloor->polygon[i].numVertices];
		if (!checkNew(_currentFloor->polygon[i].vertexID))
			return false;

		// Read in each vertex ID

		for (j = 0; j < _currentFloor->polygon[i].numVertices; j++) {
			_currentFloor->polygon[i].vertexID[j] = g_sludge->_resMan->getData()->readUint16BE();
		}
	}

	// Find out how many vertices there are and reserve memory

	i = g_sludge->_resMan->getData()->readUint16BE();
	_currentFloor->vertex = new Common::Point[i];
	if (!checkNew(_currentFloor->vertex))
		return false;

	for (j = 0; j < i; j++) {

		_currentFloor->vertex[j].x = g_sludge->_resMan->getData()->readUint16BE();
		_currentFloor->vertex[j].y = g_sludge->_resMan->getData()->readUint16BE();
	}

	g_sludge->_resMan->finishAccess();

	// Now build the movement martix

	_currentFloor->matrix = new int *[_currentFloor->numPolygons];
	int **distanceMatrix = new int *[_currentFloor->numPolygons];

	if (!checkNew(_currentFloor->matrix))
		return false;

	for (i = 0; i < _currentFloor->numPolygons; i++) {
		_currentFloor->matrix[i] = new int[_currentFloor->numPolygons];
		distanceMatrix[i] = new int[_currentFloor->numPolygons];
		if (!checkNew(_currentFloor->matrix[i]))
			return false;
		for (j = 0; j < _currentFloor->numPolygons; j++) {
			_currentFloor->matrix[i][j] = -1;
			distanceMatrix[i][j] = 10000;
		}
	}

	for (i = 0; i < _currentFloor->numPolygons; i++) {
		for (j = 0; j < _currentFloor->numPolygons; j++) {
			if (i != j) {
				if (polysShareSide(_currentFloor->polygon[i], _currentFloor->polygon[j])) {
					_currentFloor->matrix[i][j] = j;
					distanceMatrix[i][j] = 1;
				}
			} else {
				_currentFloor->matrix[i][j] = -2;
				distanceMatrix[i][j] = 0;
			}
		}
	}

	bool madeChange;
	int lookForDistance = 0;

	do {
		lookForDistance++;
		madeChange = false;
		for (i = 0; i < _currentFloor->numPolygons; i++) {
			for (j = 0; j < _currentFloor->numPolygons; j++) {
				if (_currentFloor->matrix[i][j] == -1) {

					// OK, so we don't know how to get from i to j...
					for (int d = 0; d < _currentFloor->numPolygons; d++) {
						if (d != i && d != j) {
							if (_currentFloor->matrix[i][d] == d && _currentFloor->matrix[d][j] >= 0 && distanceMatrix[d][j] <= lookForDistance) {
								_currentFloor->matrix[i][j] = d;
								distanceMatrix[i][j] = lookForDistance + 1;
								madeChange = true;
							}
						}
					}
				}
			}
		}
	} while (madeChange);

	for (i = 0; i < _currentFloor->numPolygons; i++) {
		delete[] distanceMatrix[i];
	}

	delete []distanceMatrix;
	distanceMatrix = nullptr;

	setResourceForFatal(-1);

	return true;
}
示例#4
0
bool loadGame(const Common::String &fname) {
	Common::InSaveFile *fp = g_system->getSavefileManager()->openForLoading(fname);
	FILETIME savedGameTime;

	while (allRunningFunctions)
		finishFunction(allRunningFunctions);

	if (fp == NULL)
		return false;

	bool headerBad = false;
	if (fp->readByte() != 'S')
		headerBad = true;
	if (fp->readByte() != 'L')
		headerBad = true;
	if (fp->readByte() != 'U')
		headerBad = true;
	if (fp->readByte() != 'D')
		headerBad = true;
	if (fp->readByte() != 'S')
		headerBad = true;
	if (fp->readByte() != 'A')
		headerBad = true;
	if (headerBad) {
		fatal(ERROR_GAME_LOAD_NO, fname);
		return NULL;
	}
	char c;
	c = fp->readByte();
	while ((c = fp->readByte()))
		;

	int majVersion = fp->readByte();
	int minVersion = fp->readByte();
	ssgVersion = VERSION(majVersion, minVersion);

	if (ssgVersion >= VERSION(1, 4)) {
		if (!g_sludge->_gfxMan->skipThumbnail(fp))
			return fatal(ERROR_GAME_LOAD_CORRUPT, fname);
	}

	uint32 bytes_read = fp->read(&savedGameTime, sizeof(FILETIME));
	if (bytes_read != sizeof(FILETIME) && fp->err()) {
		warning("Reading error in loadGame.");
	}

	if (savedGameTime.dwLowDateTime != fileTime.dwLowDateTime || savedGameTime.dwHighDateTime != fileTime.dwHighDateTime) {
		return fatal(ERROR_GAME_LOAD_WRONG, fname);
	}

	// DON'T ADD ANYTHING NEW BEFORE THIS POINT!

	if (ssgVersion >= VERSION(1, 4)) {
		allowAnyFilename = fp->readByte();
	}
	captureAllKeys = fp->readByte();
	fp->readByte();  // updateDisplay (part of movie playing)

	g_sludge->_txtMan->loadFont(ssgVersion, fp);

	killAllPeople();
	killAllRegions();

	int camerX = fp->readUint16BE();
	int camerY = fp->readUint16BE();
	float camerZ;
	if (ssgVersion >= VERSION(2, 0)) {
		camerZ = fp->readFloatLE();
	} else {
		camerZ = 1.0;
	}

	brightnessLevel = fp->readByte();

	g_sludge->_gfxMan->loadHSI(fp, 0, 0, true);
	g_sludge->_evtMan->loadHandlers(fp);
	loadRegions(fp);

	if (!g_sludge->_cursorMan->loadCursor(fp)) {
		return false;
	}

	LoadedFunction *rFunc;
	LoadedFunction **buildList = &allRunningFunctions;

	int countFunctions = fp->readUint16BE();
	while (countFunctions--) {
		rFunc = loadFunction(fp);
		rFunc->next = NULL;
		(*buildList) = rFunc;
		buildList = &(rFunc->next);
	}

	for (int a = 0; a < numGlobals; a++) {
		unlinkVar(globalVars[a]);
		loadVariable(&globalVars[a], fp);
	}

	loadPeople(fp);

	if (fp->readByte()) {
		if (!setFloor(fp->readUint16BE()))
			return false;
	} else
		setFloorNull();

	if (!g_sludge->_gfxMan->loadZBuffer(fp))
		return false;

	if (!g_sludge->_gfxMan->loadLightMap(ssgVersion, fp)) {
		return false;
	}

	fadeMode = fp->readByte();
	g_sludge->_speechMan->load(fp);
	loadStatusBars(fp);
	g_sludge->_soundMan->loadSounds(fp);

	saveEncoding = fp->readUint16BE();

	if (ssgVersion >= VERSION(1, 6)) {
		if (ssgVersion < VERSION(2, 0)) {
			// aaLoad
			fp->readByte();
			fp->readFloatLE();
			fp->readFloatLE();
		}

		blur_loadSettings(fp);
	}

	if (ssgVersion >= VERSION(1, 3)) {
		g_sludge->_gfxMan->loadColors(fp);

		// Read parallax layers
		while (fp->readByte()) {
			int im = fp->readUint16BE();
			int fx = fp->readUint16BE();
			int fy = fp->readUint16BE();

			if (!g_sludge->_gfxMan->loadParallax(im, fx, fy))
				return false;
		}

		g_sludge->_languageMan->loadLanguageSetting(fp);
	}

	g_sludge->_gfxMan->nosnapshot();
	if (ssgVersion >= VERSION(1, 4)) {
		if (fp->readByte()) {
			if (!g_sludge->_gfxMan->restoreSnapshot(fp))
				return false;
		}
	}

	delete fp;

	g_sludge->_gfxMan->setCamera(camerX, camerY, camerZ);

	clearStackLib();
	return true;
}