Ejemplo n.º 1
0
/**
 * 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;
}
Ejemplo n.º 2
0
/**
 * 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_LoadOld(FILE *fp, uint32 length)
{
	VARIABLE_NOT_USED(length);

	if (!SaveLoad_Load(s_saveInfoOld, fp, NULL)) return false;

	return true;
}
Ejemplo n.º 3
0
/**
 * 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;
}
Ejemplo n.º 4
0
/**
 * Load from a file into a struct.
 * @param sld The description of the struct.
 * @param fp The file to read from.
 * @param object The object instance to read to.
 * @return True if and only if the reading was successful.
 */
bool SaveLoad_Load(const SaveLoadDesc *sld, FILE *fp, void *object)
{
	while (sld->type_disk != SLDT_NULL) {
		uint32 value = 0;
		uint16 i;

		for (i = 0; i < sld->count; i++) {
			void *ptr = (sld->address == NULL ? ((uint8 *)object) + sld->offset : (uint8 *)sld->address) + i * sld->size;

			switch (sld->type_disk) {
				case SLDT_CALLBACK:
				case SLDT_SLD:
				case SLDT_NULL:
					value = 0;
					break;

				case SLDT_UINT8: {
					uint8 v;

					if (fread(&v, sizeof(uint8), 1, fp) != 1) return false;

					value = v;
				} break;

				case SLDT_UINT16: {
					uint16 v;

					if (fread(&v, sizeof(uint16), 1, fp) != 1) return false;

					value = v;
				} break;

				case SLDT_UINT32: {
					uint32 v;

					if (fread(&v, sizeof(uint32), 1, fp) != 1) return false;

					value = v;
				} break;


				case SLDT_INT8: {
					int8 v;

					if (fread(&v, sizeof(int8), 1, fp) != 1) return false;

					value = v;
				} break;

				case SLDT_INT16: {
					int16 v;

					if (fread(&v, sizeof(int16), 1, fp) != 1) return false;

					value = v;
				} break;

				case SLDT_INT32: {
					int32 v;

					if (fread(&v, sizeof(int32), 1, fp) != 1) return false;

					value = v;
				} break;
			}

			switch (sld->type_memory) {
				case SLDT_NULL:
					break;

				case SLDT_UINT8:
					*(uint8 *)ptr = (uint8)value;
					break;

				case SLDT_UINT16:
					*(uint16 *)ptr = (uint16)value;
					break;

				case SLDT_UINT32:
					*(uint32 *)ptr = (uint32)value;
					break;


				case SLDT_INT8:
					*(int8 *)ptr = (uint8)value;
					break;

				case SLDT_INT16:
					*(int16 *)ptr = (uint16)value;
					break;

				case SLDT_INT32:
					*(int32 *)ptr = (uint32)value;
					break;


				case SLDT_SLD:
					if (!SaveLoad_Load(sld->sld, fp, ptr)) return false;
					break;

				case SLDT_CALLBACK:
					sld->callback(object, value, true);
					break;
			}
		}

		sld++;
	}

	return true;
}