//--------------------------------------------------------------------------------------- // Determine if a given file name exists in the content/SkookumScript folder of either game or engine // #Author(s): Markus Breyer bool SkUERuntime::content_file_exists(const TCHAR * file_name_p, FString * folder_path_p) const { FString folder_path; // Check if we got a game FString game_name(FApp::GetGameName()); if (game_name.IsEmpty()) { // No game, look for default project binaries folder_path = FPaths::EngineContentDir() / TEXT("skookumscript") /*TEXT(SK_BITS_ID)*/; if (!FPaths::FileExists(folder_path / file_name_p)) { return false; } } else { // We have a game, so first check if it exists in the game content folder folder_path = FPaths::GameContentDir() / TEXT("skookumscript") /*TEXT(SK_BITS_ID)*/; if (!FPaths::FileExists(folder_path / file_name_p)) { #if WITH_EDITORONLY_DATA // If not found in game, check in temp location folder_path = FPaths::GameIntermediateDir() / TEXT("SkookumScript/Content/skookumscript"); if (!FPaths::FileExists(folder_path / file_name_p)) { return false; } #else return false; #endif } } *folder_path_p = folder_path; return true; }
void report_summary(summary * s, summary * o, bool full) { FILE *F = NULL; int i, newplayers = 0; faction *f; char zText[MAX_PATH]; if (full) { sprintf(zText, "%s/parteien.full", basepath()); } else { sprintf(zText, "%s/parteien", basepath()); } F = fopen(zText, "w"); if (!F) { perror(zText); return; } #ifdef SUMMARY_BOM else { const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 }; fwrite(utf8_bom, 1, 3, F); } #endif log_info("writing summary to file: parteien.\n"); fprintf(F, "%s\n%s\n\n", game_name(), gamedate2(default_locale)); fprintf(F, "Auswertung Nr: %d\n\n", turn); fprintf(F, "Parteien: %s\n", pcomp(s->factions, o->factions)); fprintf(F, "Einheiten: %s\n", pcomp(s->nunits, o->nunits)); fprintf(F, "Spielerpopulation: %s\n", pcomp(s->playerpop, o->playerpop)); fprintf(F, " davon bewaffnet: %s\n", pcomp(s->armed_men, o->armed_men)); fprintf(F, " Helden: %s\n", pcomp(s->heroes, o->heroes)); if (full) { fprintf(F, "Regionen: %d\n", listlen(regions)); fprintf(F, "Bewohnte Regionen: %d\n", s->inhabitedregions); fprintf(F, "Landregionen: %d\n", s->landregionen); fprintf(F, "Spielerregionen: %d\n", s->regionen_mit_spielern); fprintf(F, "Landspielerregionen: %d\n", s->landregionen_mit_spielern); fprintf(F, "Orkifizierte Regionen: %d\n", s->orkifizierte_regionen); fprintf(F, "Inaktive Vulkane: %d\n", s->inactive_volcanos); fprintf(F, "Aktive Vulkane: %d\n\n", s->active_volcanos); } for (i = 0; i < MAXRACES; i++) { if (i != RC_TEMPLATE && i != RC_CLONE && s->factionrace[i]) { const race *rc = get_race(i); if (rc && playerrace(rc)) { fprintf(F, "%13s%s: %s\n", LOC(default_locale, rc_name(rc, NAME_CATEGORY)), LOC(default_locale, "stat_tribe_p"), pcomp(s->factionrace[i], o->factionrace[i])); } } } if (full) { fprintf(F, "\n"); { struct language *plang = s->languages; while (plang != NULL) { struct language *olang = o->languages; int nold = 0; while (olang && olang->locale != plang->locale) olang = olang->next; if (olang) nold = olang->number; fprintf(F, "Sprache %12s: %s\n", locale_name(plang->locale), rcomp(plang->number, nold)); plang = plang->next; } } } fprintf(F, "\n"); if (full) { for (i = 0; i < MAXRACES; i++) { if (s->poprace[i]) { const race *rc = get_race(i); fprintf(F, "%20s: %s\n", LOC(default_locale, rc_name(rc, NAME_PLURAL)), rcomp(s->poprace[i], o->poprace[i])); } } } else { for (i = 0; i < MAXRACES; i++) { if (i != RC_TEMPLATE && i != RC_CLONE && s->poprace[i]) { const race *rc = get_race(i); if (playerrace(rc)) { fprintf(F, "%20s: %s\n", LOC(default_locale, rc_name(rc, NAME_PLURAL)), rcomp(s->poprace[i], o->poprace[i])); } } } } if (full) { fprintf(F, "\nWaffen: %s\n", pcomp(s->waffen, o->waffen)); fprintf(F, "Ruestungen: %s\n", pcomp(s->ruestungen, o->ruestungen)); fprintf(F, "ungezaehmte Pferde: %s\n", pcomp(s->pferde, o->pferde)); fprintf(F, "gezaehmte Pferde: %s\n", pcomp(s->spielerpferde, o->spielerpferde)); fprintf(F, "Schiffe: %s\n", pcomp(s->schiffe, o->schiffe)); fprintf(F, "Gebaeude: %s\n", pcomp(s->gebaeude, o->gebaeude)); fprintf(F, "\nBauernpopulation: %s\n", pcomp(s->peasants, o->peasants)); fprintf(F, "Population gesamt: %d\n\n", s->playerpop + s->peasants); fprintf(F, "Reichtum Spieler: %s Silber\n", pcomp(s->playermoney, o->playermoney)); fprintf(F, "Reichtum Bauern: %s Silber\n", pcomp(s->peasantmoney, o->peasantmoney)); fprintf(F, "Reichtum gesamt: %s Silber\n\n", pcomp(s->playermoney + s->peasantmoney, o->playermoney + o->peasantmoney)); } fprintf(F, "\n\n"); newplayers = update_nmrs(); for (i = 0; i <= NMRTimeout(); ++i) { if (i == NMRTimeout()) { fprintf(F, "+ NMR:\t\t %d\n", nmrs[i]); } else { fprintf(F, "%d NMR:\t\t %d\n", i, nmrs[i]); } } if (age) { if (age[2] != 0) { fprintf(F, "Erstabgaben:\t %d%%\n", 100 - (dropouts[0] * 100 / age[2])); } if (age[3] != 0) { fprintf(F, "Zweitabgaben:\t %d%%\n", 100 - (dropouts[1] * 100 / age[3])); } } fprintf(F, "Neue Spieler:\t %d\n", newplayers); if (full) { if (factions) fprintf(F, "\nParteien:\n\n"); for (f = factions; f; f = f->next) { out_faction(F, f); } if (NMRTimeout() && full) { fprintf(F, "\n\nFactions with NMRs:\n"); for (i = NMRTimeout(); i > 0; --i) { for (f = factions; f; f = f->next) { if (i == NMRTimeout()) { if (turn - f->lastorders >= i) { out_faction(F, f); } } else { if (turn - f->lastorders == i) { out_faction(F, f); } } } } } } fclose(F); if (full) { log_info("writing date & turn\n"); writeturn(); } free(nmrs); nmrs = NULL; }
/* restore saved game handler */ void restore(void) { char username[64]; FILE *restfd; char *sptr; #ifndef __QNX__ printf("What is the name of the saved game? "); fflush(stdout); if (NULL == gets(username)) exit(0); if (sptr = strchr(username, '.')) *sptr = '\0'; /* kill extension */ if (strlen(username) > 8) username[8] = '\0'; /* max 8 char filename */ strcat(username, ".adv"); #else (void)sptr; game_name(username); #endif restfd = fopen(username, "r"); if (restfd == NULL) { printf("Sorry, no game to load...\n"); return; } fread(&turns, sizeof(int), 1, restfd); fread(&loc, sizeof(int), 1, restfd); fread(&oldloc, sizeof(int), 1, restfd); fread(&oldloc2, sizeof(int), 1, restfd); fread(&newloc, sizeof(int), 1, restfd); /* location variables */ fread(&cond[0], sizeof(int), MAXLOC, restfd); /* location status */ fread(&place[0], sizeof(int), MAXOBJ, restfd); /* object location */ fread(&fixed[0], sizeof(int), MAXOBJ, restfd); /* second object loc */ fread(&visited[0], sizeof(int), MAXLOC, restfd); /* >0 if has been here */ fread(&prop[0], sizeof(int), MAXOBJ, restfd); /* status of object */ fread(&tally, sizeof(int), 1, restfd); fread(&tally2, sizeof(int), 1, restfd); /* item counts */ fread(&limit, sizeof(int), 1, restfd); /* time limit */ fread(&lmwarn, sizeof(int), 1, restfd); /* lamp warning flag */ fread(&wzdark, sizeof(int), 1, restfd); fread(&closing, sizeof(int), 1, restfd); fread(&closed, sizeof(int), 1, restfd); /* game state flags */ fread(&holding, sizeof(int), 1, restfd); /* count of held items */ fread(&detail, sizeof(int), 1, restfd); /* LOOK count */ fread(&knfloc, sizeof(int), 1, restfd); /* knife location */ fread(&clock1, sizeof(int), 1, restfd); fread(&clock2, sizeof(int), 1, restfd); fread(&panic, sizeof(int), 1, restfd); /* timing variables */ fread(&dloc[0], sizeof(int), DWARFMAX, restfd); /* dwarf locations */ fread(&dflag, sizeof(int), 1, restfd); /* dwarf flag */ fread(&dseen[0], sizeof(int), DWARFMAX, restfd); /* dwarf seen flag */ fread(&odloc[0], sizeof(int), DWARFMAX, restfd); /* dwarf old locations */ fread(&daltloc, sizeof(int), 1, restfd); /* alternate appearance */ fread(&dkill, sizeof(int), 1, restfd); /* dwarves killed */ fread(&chloc, sizeof(int), 1, restfd); fread(&chloc2, sizeof(int), 1, restfd); /* chest locations */ fread(&bonus, sizeof(int), 1, restfd); /* to pass to end */ fread(&numdie, sizeof(int), 1, restfd); /* number of deaths */ fread(&object1, sizeof(int), 1, restfd); /* to help intrans. */ fread(&gaveup, sizeof(int), 1, restfd); /* 1 if he quit early */ fread(&foobar, sizeof(int), 1, restfd); /* fie fie foe foo... */ if (fclose(restfd) == -1) { printf("Warning -- can't close save file...%s\n", username); } printf("Game restored...\n"); describe(); }
void report_summary(const summary * s, bool full) { FILE *F = NULL; int newplayers = 0; faction *f; char zText[4096]; int timeout = NMRTimeout(); if (full) { path_join(basepath(), "parteien.full", zText, sizeof(zText)); } else { path_join(basepath(), "parteien", zText, sizeof(zText)); } F = fopen(zText, "w"); if (!F) { perror(zText); return; } #ifdef SUMMARY_BOM else { const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 }; fwrite(utf8_bom, 1, 3, F); } #endif log_info("writing summary to file: parteien.\n"); fprintf(F, "%s\n%s\n\n", game_name(), gamedate2(default_locale)); fprintf(F, "Auswertung Nr: %8d\n\n", turn); fprintf(F, "Parteien: %8d\n", s->factions); fprintf(F, "Einheiten: %8d\n", s->nunits); fprintf(F, "Spielerpopulation: %8d\n", s->playerpop); fprintf(F, " davon bewaffnet: %8d\n", s->armed_men); fprintf(F, " Helden: %8d\n", s->heroes); if (full) { fprintf(F, "Regionen: %8d\n", (int)listlen(regions)); fprintf(F, "Bewohnte Regionen: %8d\n", s->inhabitedregions); fprintf(F, "Landregionen: %8d\n", s->landregionen); fprintf(F, "Spielerregionen: %8d\n", s->regionen_mit_spielern); fprintf(F, "Landspielerregionen: %8d\n", s->landregionen_mit_spielern); fprintf(F, "Inaktive Vulkane: %8d\n", s->inactive_volcanos); fprintf(F, "Aktive Vulkane: %8d\n\n", s->active_volcanos); } summarize_players(s, F); if (full) { fprintf(F, "\n"); { struct language *plang = s->languages; while (plang != NULL) { fprintf(F, "Sprache %2s: %8d\n", locale_name(plang->locale), plang->number); plang = plang->next; } } } fprintf(F, "\n"); summarize_races(s, F, full); if (full) { fprintf(F, "\nWaffen: %8d\n", s->waffen); fprintf(F, "Ruestungen: %8d\n", s->ruestungen); fprintf(F, "ungezaehmte Pferde: %8d\n", s->pferde); fprintf(F, "gezaehmte Pferde: %8d\n", s->spielerpferde); fprintf(F, "Schiffe: %8d\n", s->schiffe); fprintf(F, "Gebaeude: %8d\n", s->gebaeude); fprintf(F, "\nBauernpopulation: %8d\n", s->peasants); fprintf(F, "Population gesamt: %8d\n\n", s->playerpop + s->peasants); fprintf(F, "Reichtum Spieler: %12lld Silber\n", s->playermoney); fprintf(F, "Reichtum Bauern: %12lld Silber\n", s->peasantmoney); fprintf(F, "Reichtum gesamt: %12lld Silber\n\n", s->playermoney + s->peasantmoney); } fprintf(F, "\n"); newplayers = update_nmrs(); if (nmrs) { int i; for (i = 0; i <= timeout; ++i) { if (i == timeout) { fprintf(F, "+ NMR: %3d\n", nmrs[i]); } else { fprintf(F, "%d NMR: %3d\n", i, nmrs[i]); } } } if (age) { if (age[2] != 0) { fprintf(F, "Erstabgaben: %3d%%\n", 100 - (dropouts[0] * 100 / age[2])); } if (age[3] != 0) { fprintf(F, "Zweitabgaben: %3d%%\n", 100 - (dropouts[1] * 100 / age[3])); } } fprintf(F, "Neue Spieler: %d\n", newplayers); if (full) { if (factions) { fprintf(F, "\nParteien:\n\n"); for (f = factions; f; f = f->next) { out_faction(F, f); } } if (timeout>0 && full) { int i; fprintf(F, "\n\nFactions with NMRs:\n"); for (i = timeout; i > 0; --i) { for (f = factions; f; f = f->next) { if (i == timeout) { if (turn - f->lastorders >= i) { out_faction(F, f); } } else { if (turn - f->lastorders == i) { out_faction(F, f); } } } } } } fclose(F); if (full) { log_info("writing date & turn\n"); writeturn(); } free(nmrs); nmrs = NULL; }
static int parse_args(int argc, char **argv, int *exitcode) { int i; for (i = 1; i != argc; ++i) { char *argi = argv[i]; if (argi[0] != '-') { luafile = argi; } else if (argi[1] == '-') { /* long format */ if (strcmp(argi + 2, "version") == 0) { printf("\n%s PBEM host\n" "Copyright (C) 1996-2005 C. Schlittchen, K. Zedel, E. Rehling, H. Peters.\n\n" "Compilation: " __DATE__ " at " __TIME__ "\nVersion: %d.%d.%d\n\n", game_name(), VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD); #ifdef USE_CURSES } else if (strcmp(argi + 2, "color") == 0) { /* force the editor to have colors */ force_color = 1; #endif } else if (strcmp(argi + 2, "help") == 0) { return usage(argv[0], NULL); } else { return usage(argv[0], argi); } } else { const char *arg; switch (argi[1]) { case 'r': i = get_arg(argc, argv, 2, i, &arg, 0); set_param(&global.parameters, "config.rules", arg); break; case 'f': i = get_arg(argc, argv, 2, i, &luafile, 0); break; case 'l': i = get_arg(argc, argv, 2, i, &logfile, 0); break; case 't': i = get_arg(argc, argv, 2, i, &arg, 0); turn = atoi(arg); break; case 'q': verbosity = 0; break; case 'v': i = get_arg(argc, argv, 2, i, &arg, 0); verbosity = arg ? atoi(arg) : 0xff; break; case 'h': usage(argv[0], NULL); return 1; default: *exitcode = -1; usage(argv[0], argi); return 1; } } } switch (verbosity) { case 0: log_stderr = 0; break; case 1: log_stderr = LOG_CPERROR; break; case 2: log_stderr = LOG_CPERROR | LOG_CPWARNING; break; case 3: log_stderr = LOG_CPERROR | LOG_CPWARNING | LOG_CPINFO; break; default: log_stderr = LOG_CPERROR | LOG_CPWARNING | LOG_CPINFO | LOG_CPDEBUG; break; } return 0; }
FString FSkookumScriptEditor::make_project_editable() { FString error_msg; FString game_name(FApp::GetGameName()); if (game_name.IsEmpty()) { error_msg = TEXT("Tried to make project editable but engine has no project loaded!"); } else { // Check if maybe already editable - if so, silently do nothing FString editable_scripts_path = FPaths::GameDir() / TEXT("Scripts"); FString editable_project_path(editable_scripts_path / TEXT("Skookum-project.ini")); if (!FPaths::FileExists(editable_project_path)) { // Check temporary location (in `Intermediate` folder) FString temp_root_path(FPaths::GameIntermediateDir() / TEXT("SkookumScript")); FString temp_scripts_path(temp_root_path / TEXT("Scripts")); FString temp_project_path = temp_scripts_path / TEXT("Skookum-project.ini"); if (!FPaths::FileExists(temp_project_path)) { error_msg = TEXT("Tried to make project editable but neither an editable nor a non-editable project was found!"); } else { if (!IFileManager::Get().Move(*editable_scripts_path, *temp_scripts_path, true, true)) { error_msg = TEXT("Failed moving project information from temporary to editable location!"); } else { // Move compiled binaries for convenience // We don't care if this succeeds FString temp_binary_folder_path = temp_root_path / TEXT("Content/skookumscript"); FString editable_binary_folder_path = FPaths::GameDir() / TEXT("Content/skookumscript"); IFileManager::Get().Move(*editable_binary_folder_path, *temp_binary_folder_path, true, true); // Change project packaging settings to include Sk binaries UProjectPackagingSettings * packaging_settings_p = Cast<UProjectPackagingSettings>(UProjectPackagingSettings::StaticClass()->GetDefaultObject()); const TCHAR * binary_path_name_p = TEXT("skookumscript"); for (TArray<FDirectoryPath>::TConstIterator dir_path(packaging_settings_p->DirectoriesToAlwaysStageAsNonUFS); dir_path; ++dir_path) { if (dir_path->Path == binary_path_name_p) { binary_path_name_p = nullptr; break; } } if (binary_path_name_p) { FDirectoryPath binary_path; binary_path.Path = binary_path_name_p; packaging_settings_p->DirectoriesToAlwaysStageAsNonUFS.Add(binary_path); FString config_file_name = FPaths::GameConfigDir() / TEXT("DefaultGame.ini"); if (ISourceControlModule::Get().IsEnabled()) { SourceControlHelpers::CheckOutFile(config_file_name); } packaging_settings_p->SaveConfig(CPF_Config, *config_file_name); } // Create Project overlay folder IFileManager::Get().MakeDirectory(*(editable_scripts_path / TEXT("Project/Object")), true); // Change project to be editable FString proj_ini; verify(FFileHelper::LoadFileToString(proj_ini, *editable_project_path)); proj_ini = proj_ini.Replace(m_editable_ini_settings_p, TEXT("")); // Remove editable settings proj_ini += TEXT("Overlay7=Project|Project\r\n"); // Create Project overlay definition verify(FFileHelper::SaveStringToFile(proj_ini, *editable_project_path, FFileHelper::EEncodingOptions::ForceAnsi)); } } } } return error_msg; }