コード例 #1
0
ファイル: structure.c プロジェクト: 166MMX/OpenDUNE
/**
 * Load all Structures from a file.
 * @param fp The file to load from.
 * @param length The length of the data chunk.
 * @return True if and only if all bytes were read successful.
 */
bool Structure_Load(FILE *fp, uint32 length)
{
	while (length > 0) {
		Structure *s;
		Structure sl;

		memset(&sl, 0, sizeof(sl));

		/* Read the next Structure from disk */
		if (!SaveLoad_Load(s_saveStructure, fp, &sl)) return false;

		length -= SaveLoad_GetLength(s_saveStructure);

		sl.o.script.scriptInfo = g_scriptStructure;
		sl.o.script.script = g_scriptStructure->start + (size_t)sl.o.script.script;
		if (sl.upgradeTimeLeft == 0) sl.upgradeTimeLeft = Structure_IsUpgradable(&sl) ? 100 : 0;

		/* Get the Structure from the pool */
		s = Structure_Get_ByIndex(sl.o.index);
		if (s == NULL) return false;

		/* Copy over the data */
		*s = sl;
	}
	if (length != 0) return false;

	Structure_Recount();

	return true;
}
コード例 #2
0
ファイル: info.c プロジェクト: 166MMX/OpenDUNE
/**
 * Load all kinds of important info from a file.
 * @param fp The file to load from.
 * @param length The length of the data chunk.
 * @return True if and only if all bytes were read successful.
 */
bool Info_Load(FILE *fp, uint32 length)
{
	if (SaveLoad_GetLength(s_saveInfo) != length) return false;
	if (!SaveLoad_Load(s_saveInfo, fp, NULL)) return false;

	g_viewportPosition = g_minimapPosition;
	g_selectionPosition = g_selectionRectanglePosition;

	Sprites_LoadTiles();

	Map_CreateLandscape(g_scenario.mapSeed);

	return true;
}
コード例 #3
0
ファイル: saveload.c プロジェクト: rofl0r/OpenDUNE
/**
 * Get the length of the struct how it would be on disk.
 * @param sld The description of the struct.
 * @return The length of the struct on disk.
 */
uint32 SaveLoad_GetLength(const SaveLoadDesc *sld)
{
	uint32 length = 0;

	while (sld->type_disk != SLDT_NULL) {
		switch (sld->type_disk) {
			case SLDT_NULL:     length += 0; break;
			case SLDT_CALLBACK: length += 0; break;
			case SLDT_UINT8:    length += sizeof(uint8)  * sld->count;  break;
			case SLDT_UINT16:   length += sizeof(uint16) * sld->count;  break;
			case SLDT_UINT32:   length += sizeof(uint32) * sld->count;  break;
			case SLDT_INT8:     length += sizeof(int8)   * sld->count;  break;
			case SLDT_INT16:    length += sizeof(int16)  * sld->count;  break;
			case SLDT_INT32:    length += sizeof(int32)  * sld->count;  break;
			case SLDT_SLD:      length += SaveLoad_GetLength(sld->sld) * sld->count; break;
		}
		sld++;
	}

	return length;
}