35 static const char* SAVE_DIR =
"SaveGame";
51 CampaignSaveGame::GetSaveDirectory()
57 CampaignSaveGame::GetSaveDirectory(
Player* player)
61 sprintf_s(save_dir,
"%s/%02d", SAVE_DIR, player->
Identity());
70 CampaignSaveGame::CreateSaveDirectory()
72 HANDLE hDir = CreateFile(SAVE_DIR, 0, 0, 0, OPEN_EXISTING, 0, 0);
74 if (hDir == INVALID_HANDLE_VALUE)
75 CreateDirectory(SAVE_DIR, NULL);
79 hDir = CreateFile(GetSaveDirectory(), 0, 0, 0, OPEN_EXISTING, 0, 0);
81 if (hDir == INVALID_HANDLE_VALUE)
82 CreateDirectory(GetSaveDirectory(), NULL);
89 static char multiline[4096];
90 static char* FormatMultiLine(
const char* s)
102 else if (*s ==
'"') {
118 static char* ParseMultiLine(
const char* s)
123 while (*s && i > 0) {
128 #pragma warning(suppress: 6269)
132 else if (*s ==
'"') {
134 #pragma warning(suppress: 6269)
156 Print(
"-------------------------\nLOADING SAVEGAME (%s).\n", filename);
159 if (!filename || !filename[0])
return;
176 Print(
"ERROR: could not parse save game '%s'\n", filename);
182 if (!file_type || file_type->
value() !=
"SAVEGAME") {
183 Print(
"ERROR: invalid save game file '%s'\n", filename);
203 delete term; term = 0;
209 if (def->
name()->
value() ==
"campaign") {
223 for (
int i = 0; i < list.
size() && !campaign; i++) {
237 else if (def->
name()->
value() ==
"grp_iff") {
241 else if (def->
name()->
value() ==
"grp_type") {
245 else if (def->
name()->
value() ==
"grp_id") {
249 else if (def->
name()->
value() ==
"unit") {
253 else if (def->
name()->
value() ==
"status") {
257 else if (def->
name()->
value() ==
"basetime") {
261 else if (def->
name()->
value() ==
"time") {
265 else if (def->
name()->
value() ==
"sitrep") {
269 else if (def->
name()->
value() ==
"orders") {
273 else if (def->
name()->
value() ==
"combatant") {
275 ::Print(
"WARNING: combatant struct missing in '%s/%s'\n", loader->
GetDataPath(), filename);
284 ZeroMemory(name,
sizeof(name));
292 else if (pdef->
name()->
value() ==
"iff") {
296 else if (pdef->
name()->
value() ==
"score") {
302 if (campaign && name[0]) {
310 ::Print(
"WARNING: could not find combatant '%s' in campaign.\n", name);
315 else if (def->
name()->
value() ==
"event") {
317 ::Print(
"WARNING: event struct missing in '%s/%s'\n", loader->
GetDataPath(), filename);
349 else if (pdef->
name()->
value() ==
"source")
352 else if (pdef->
name()->
value() ==
"region")
355 else if (pdef->
name()->
value() ==
"title")
358 else if (pdef->
name()->
value() ==
"file")
361 else if (pdef->
name()->
value() ==
"image")
364 else if (pdef->
name()->
value() ==
"scene")
367 else if (pdef->
name()->
value() ==
"info")
370 else if (pdef->
name()->
value() ==
"time")
373 else if (pdef->
name()->
value() ==
"team")
376 else if (pdef->
name()->
value() ==
"points")
381 if (campaign && type[0]) {
394 event->SetFilename(file);
395 event->SetImageFile(image);
396 event->SetSceneFile(scene);
400 event->SetInformation(ParseMultiLine(info));
402 event->SetVisited(
true);
408 else if (def->
name()->
value() ==
"action") {
410 ::Print(
"WARNING: action struct missing in '%s/%s'\n", loader->
GetDataPath(), filename);
426 else if (pdef->
name()->
value() ==
"stat")
429 else if (pdef->
name()->
value() ==
"count")
437 if (campaign &&
id >= 0) {
486 player_unit = player_group->
FindUnit(unit);
498 Print(
"CampaignSaveGame: Loading FAILED campaign, restarting '%s'\n",
510 Print(
"CampaignSaveGame: Loading COMPLETED campaign '%s', searching for next campaign...\n",
515 for (
int i = 0; i < list.
size() && !found; i++) {
523 Print(
"Advanced to campaign %d '%s'\n",
533 for (
int i = 0; i < list.
size() && !found; i++) {
541 Print(
"Completed full series, restarting at %d '%s'\n",
554 Print(
"SAVEGAME LOADED (%s).\n\n", filename);
562 if (!campaign)
return;
564 CreateSaveDirectory();
578 fprintf(f,
"SAVEGAME\n\n");
579 fprintf(f,
"campaign: \"%s\"\n\n", campaign->
Name());
580 fprintf(f,
"grp_iff: %d\n", (
int) player_group->GetIFF());
581 fprintf(f,
"grp_type: %d\n", (
int) player_group->Type());
582 fprintf(f,
"grp_id: %d\n", (
int) player_group->GetID());
584 fprintf(f,
"unit: \"%s\"\n", player_unit->
Name().
data());
586 fprintf(f,
"status: %d\n", (
int) campaign->
GetStatus());
588 fprintf(f,
"time: %f // %s\n\n",
592 fprintf(f,
"sitrep: \"%s\"\n", campaign->
Situation());
593 fprintf(f,
"orders: \"%s\"\n\n", campaign->
Orders());
599 fprintf(f,
"combatant: {");
600 fprintf(f,
" name:\"%s\",", c->
Name());
601 fprintf(f,
" iff:%d,", c->
GetIFF());
602 fprintf(f,
" score:%d,", c->
Score());
611 fprintf(f,
"action: { id:%4d, stat:%d", a->
Identity(), a->
Status());
615 fprintf(f,
", count:%d", a->
Count());
630 fprintf(f,
"event: {");
631 fprintf(f,
" type:%-18s,", e->
TypeName());
632 fprintf(f,
" time:0x%08x,", e->
Time());
633 fprintf(f,
" team:%d,", e->
GetIFF());
634 fprintf(f,
" points:%d,", e->
Points());
635 fprintf(f,
" source:\"%s\",", e->
SourceName());
636 fprintf(f,
" region:\"%s\",", e->
Region());
637 fprintf(f,
" title:\"%s\",", e->
Title());
639 fprintf(f,
" file:\"%s\",", e->
Filename());
641 fprintf(f,
" image:\"%s\",", e->
ImageFile());
643 fprintf(f,
" scene:\"%s\",", e->
SceneFile());
645 fprintf(f,
" info:\"%s\"", FormatMultiLine(e->
Information()));
649 fprintf(f,
"\n// ORDER OF BATTLE:\n\n");
664 DeleteFile(GetSaveDirectory() +
"/" + name);
671 Text save_dir = GetSaveDirectory(p) +
"/";
681 for (
int i = 0; i < save_list.
size(); i++) {
682 Text* filename = save_list[i];
683 DeleteFile(save_dir + filename->
data());
688 RemoveDirectory(GetSaveDirectory(p));
712 ::fopen_s(&f, GetSaveDirectory() +
"/AutoSave",
"r");
734 return save_list.
size();