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(Holder<SaveGame> save, const char *slotname) { if (!slotname) { return -1; } if (int cansave = CanSave()) return cansave; GameControl *gc = core->GetGameControl(); int index; if (save) { index = save->GetSaveID(); DeleteSaveGame(save); save.release(); } else { //leave space for autosaves //probably the hardcoded slot names should be read by this object //in that case 7 == size of hardcoded slot names array (savegame.2da) index = 7; for (size_t i = 0; i < save_slots.size(); ++i) { Holder<SaveGame> save = save_slots[i]; if (save->GetSaveID() >= index) { index = save->GetSaveID() + 1; } } } char Path[_MAX_PATH]; 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 displaymsg->DisplayConstantString(STR_SAVESUCCEED, DMC_BG2XPGREEN); if (gc) { gc->SetDisplayText(STR_SAVESUCCEED, 30); } return 0; }