00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00030
00031
00032
00033
00034
00035 #include <string.h>
00036 #include <stdio.h>
00037 #include <stdlib.h>
00038 #include <time.h>
00039 #include <ctype.h>
00040 #include <string>
00041
00042 #include "stratagus.h"
00043 #include "ui.h"
00044 #include "unit.h"
00045 #include "upgrade.h"
00046 #include "missile.h"
00047 #include "map.h"
00048 #include "player.h"
00049 #include "ai.h"
00050 #include "trigger.h"
00051 #include "iolib.h"
00052 #include "replay.h"
00053 #include "script.h"
00054 #include "actions.h"
00055 #include "version.h"
00056
00057
00058
00059
00060
00061
00062
00063
00064
00068 static std::string GetSaveDir()
00069 {
00070 std::string dir;
00071
00072 dir = UserDirectory + "save/";
00073
00074 return dir;
00075 }
00076
00084 void SaveGame(const std::string &filename)
00085 {
00086 time_t now;
00087 CFile file;
00088 char *s;
00089 char *s1;
00090 std::string fullpath;
00091
00092 fullpath = GetSaveDir() + filename;
00093 if (file.open(fullpath.c_str(), CL_WRITE_GZ | CL_OPEN_WRITE) == -1) {
00094 fprintf(stderr, "Can't save to `%s'\n", filename.c_str());
00095 return;
00096 }
00097
00098 time(&now);
00099 s = ctime(&now);
00100 if ((s1 = strchr(s, '\n'))) {
00101 *s1 = '\0';
00102 }
00103
00104
00105
00106
00107 file.printf("SavedGameInfo({\n");
00108 file.printf("--- \"comment\", \"Generated by Bos Wars Version " VERSION "\",\n");
00109 file.printf("--- \"comment\", \"Visit http://www.boswars.org for more informations\",\n");
00110 file.printf("--- \"type\", \"%s\",\n", "single-player");
00111 file.printf("--- \"date\", \"%s\",\n", s);
00112 file.printf("--- \"map\", \"%s\",\n", Map.Info.Description.c_str());
00113 file.printf("--- \"media-version\", \"%s\"", "Undefined");
00114 file.printf("--- \"engine\", {%d, %d, %d},\n",
00115 StratagusMajorVersion, StratagusMinorVersion, StratagusPatchLevel);
00116 file.printf(" SyncHash = %d, \n", SyncHash);
00117 file.printf(" SyncRandSeed = %d, \n", SyncRandSeed);
00118 file.printf(" SaveFile = \"%s\"\n", CurrentMapPath);
00119 file.printf("\n--- \"preview\", \"%s.pam\",\n", filename.c_str());
00120 file.printf("} )\n\n");
00121
00122
00123 file.printf("GameCycle = %lu\n", GameCycle);
00124
00125 SaveCcl(&file);
00126 SaveUpgrades(&file);
00127 SavePlayers(&file);
00128 Map.Save(&file);
00129 SaveUnits(&file);
00130 SaveUserInterface(&file);
00131 SaveAi(&file);
00132 SaveSelections(&file);
00133 SaveGroups(&file);
00134 SaveMissiles(&file);
00135 SaveTriggers(&file);
00136 SaveReplayList(&file);
00137
00138 s = SaveGlobal(Lua, true);
00139 if (s != NULL) {
00140 file.printf("-- Lua state\n\n %s\n", s);
00141 delete[] s;
00142 }
00143 file.close();
00144 }
00145