Ejemplo n.º 1
0
int SaveGameIterator::CreateSaveGame(int index, bool mqs)
{
	AutoTable tab("savegame");
	const char *slotname = NULL;
	int qsave = 0;

	if (tab) {
		slotname = tab->QueryField(index);
		qsave = atoi(tab->QueryField(index, 1));
	}

	if (mqs) {
		assert(qsave);
		PruneQuickSave(slotname);
	}

	if (int cansave = CanSave())
		return cansave;

	//if index is not an existing savegame, we create a unique slotname
	for (size_t i = 0; i < save_slots.size(); ++i) {
		Holder<SaveGame> save = save_slots[i];
		if (save->GetSaveID() == index) {
			DeleteSaveGame(save);
			break;
		}
	}
	char Path[_MAX_PATH];
	GameControl *gc = core->GetGameControl();

	if (!CreateSavePath(Path, index, slotname)) {
		displaymsg->DisplayConstantString(STR_CANTSAVE, DMC_BG2XPGREEN);
		if (gc) {
			gc->SetDisplayText(STR_CANTSAVE, 30);
		}
		return -1;
	}

	if (!DoSaveGame(Path)) {
		displaymsg->DisplayConstantString(STR_CANTSAVE, DMC_BG2XPGREEN);
		if (gc) {
			gc->SetDisplayText(STR_CANTSAVE, 30);
		}
		return -1;
	}

	// Save succesful / Quick-save succesful
	if (qsave) {
		displaymsg->DisplayConstantString(STR_QSAVESUCCEED, DMC_BG2XPGREEN);
		if (gc) {
			gc->SetDisplayText(STR_QSAVESUCCEED, 30);
		}
	} else {
		displaymsg->DisplayConstantString(STR_SAVESUCCEED, DMC_BG2XPGREEN);
		if (gc) {
			gc->SetDisplayText(STR_SAVESUCCEED, 30);
		}
	}
	return 0;
}
int SaveGameIterator::CreateSaveGame(int index, bool mqs)
{
	AutoTable tab("savegame");
	const char *slotname = NULL;
	if (tab) {
		slotname = tab->QueryField(index);
	}

	if (mqs) {
		assert(index==1);
		PruneQuickSave(slotname);
	}

	//if index is not an existing savegame, we create a unique slotname
	for (size_t i = 0; i < save_slots.size(); ++i) {
		Holder<SaveGame> save = save_slots[i];
		if (save->GetSaveID() == index) {
			DeleteSaveGame(save);
			break;
		}
	}
	char Path[_MAX_PATH];
	CreateSavePath(Path, index, slotname);

	if (!DoSaveGame(Path)) {
		return -1;
	}

	// Save succesful / Quick-save succesful
	if (index == 1) {
		displaymsg->DisplayConstantString(STR_QSAVESUCCEED, 0xbcefbc);
		if (core->GetGameControl()) {
			core->GetGameControl()->SetDisplayText(STR_QSAVESUCCEED, 30);
		}
	} else {
		displaymsg->DisplayConstantString(STR_SAVESUCCEED, 0xbcefbc);
		if (core->GetGameControl()) {
			core->GetGameControl()->SetDisplayText(STR_SAVESUCCEED, 30);
		}
	}
	return 0;
}