void initGameState(int stg) { initGameStateFirst(); hiScore.stage = stage = stg; hiScore.mode = mode; makeStageStr(stg); initStageState(stg); }
void initTitleStage(int stg) { initFoes(); initStageState(stg); }
bool GuiManager::isValidStageFile(const char *srcFilename, BerryBotsEngine *engine) { // TODO: Is this too slow? Should we keep this list in the cache so we don't // have to do this on every startup / refresh - at least for packaged // stages? In fact, just the presence in the cache could be considered // a sign of validity. // TODO: Move this out of the GUI code. if (fileManager_->isLuaFilename(srcFilename) || fileManager_->isZipFilename(srcFilename)) { char *stagesDir = 0; char *stageFilename = 0; try { fileManager_->loadStageFileData(getStagesDir().c_str(), srcFilename, &stagesDir, &stageFilename, getCacheDir().c_str()); } catch (FileNotFoundException *fnfe) { // Only possible if user deletes file from disk after we find it on disk // but before we validate it. Seems safe to fail silently. if (stagesDir != 0) { delete stagesDir; } if (stageFilename != 0) { delete stageFilename; } delete fnfe; return false; } catch (ZipperException *ze) { if (stagesDir != 0) { delete stagesDir; } if (stageFilename != 0) { delete stageFilename; } errorConsole_->print(srcFilename); errorConsole_->print(": "); errorConsole_->println(ze->what()); wxMessageDialog errorMessage(NULL, ze->what(), "Unzip failure", wxOK | wxICON_EXCLAMATION); errorMessage.ShowModal(); delete ze; return false; } catch (PackagedSymlinkException *pse) { if (stagesDir != 0) { delete stagesDir; } if (stageFilename != 0) { delete stageFilename; } errorConsole_->print(srcFilename); errorConsole_->print(": "); errorConsole_->println(pse->what()); delete pse; return false; } lua_State *stageState; initStageState(&stageState, stagesDir); if (luaL_loadfile(stageState, stageFilename) || engine->callUserLuaCode(stageState, 0, "", PCALL_VALIDATE)) { logErrorMessage(stageState, "Problem loading stage: %s"); lua_close(stageState); delete stagesDir; delete stageFilename; return false; } lua_getglobal(stageState, "configure"); if (lua_isnil(stageState, -1)) { lua_close(stageState); delete stagesDir; delete stageFilename; return false; } lua_close(stageState); delete stagesDir; delete stageFilename; return true; } return false; }