1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
// ____ _ __
// / __ )____ _____ | | / /___ ___________
// / __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
// / /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
// /_____/\____/____/ |__/|__/\__,_/_/ /____/
//
// A futuristic real-time strategy game.
// This file is part of Bos Wars.
//
/**@name savegame.cpp - Save game. */
//
// (c) Copyright 2001-2007 by Lutz Sammer, Andreas Arens
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; only version 2 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
//@{
/*----------------------------------------------------------------------------
-- Includes
----------------------------------------------------------------------------*/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
#include <string>
#include "stratagus.h"
#include "ui.h"
#include "unit.h"
#include "upgrade.h"
#include "missile.h"
#include "map.h"
#include "player.h"
#include "ai.h"
#include "trigger.h"
#include "iolib.h"
#include "replay.h"
#include "script.h"
#include "actions.h"
#include "version.h"
/*----------------------------------------------------------------------------
-- Variables
----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------
-- Functions
----------------------------------------------------------------------------*/
/**
** Get the save directory
*/
static std::string GetSaveDir()
{
std::string dir;
dir = UserDirectory + "save/";
return dir;
}
/**
** Save a game to file.
**
** @param filename File name to be stored.
**
** @note Later we want to store in a more compact binary format.
*/
void SaveGame(const std::string &filename)
{
time_t now;
CFile file;
char *s;
char *s1;
std::string fullpath;
fullpath = GetSaveDir() + filename;
if (file.open(fullpath.c_str(), CL_WRITE_GZ | CL_OPEN_WRITE) == -1) {
fprintf(stderr, "Can't save to `%s'\n", filename.c_str());
return;
}
time(&now);
s = ctime(&now);
if ((s1 = strchr(s, '\n'))) {
*s1 = '\0';
}
// Parseable header
file.printf("SavedGameInfo({\n");
file.printf("--- generator = \"Generated by Bos Wars Version " VERSION "\",\n");
file.printf("--- comment = \"Visit http://www.boswars.org for more informations\",\n");
file.printf("--- type = \"%s\",\n", "single-player");
file.printf("--- date = \"%s\",\n", s);
file.printf("--- map = \"%s\",\n", Map.Info.Description.c_str());
file.printf("--- media-version = \"%s\",\n", "Undefined");
file.printf("--- engine = {%d, %d, %d},\n",
StratagusMajorVersion, StratagusMinorVersion, StratagusPatchLevel);
file.printf(" SyncHash = %d, \n", SyncHash);
file.printf(" SyncRandSeed = %d, \n", SyncRandSeed);
file.printf(" SaveFile = \"%s\"\n", CurrentMapPath);
file.printf("} )\n\n");
// FIXME: probably not the right place for this
file.printf("GameCycle = %lu\n", GameCycle);
SaveCcl(&file);
Map.Save(&file);
SavePlayers(&file);
SaveUpgrades(&file);
SaveUnits(&file);
SaveUserInterface(&file);
SaveAi(&file);
SaveSelections(&file);
SaveGroups(&file);
SaveMissiles(&file);
SaveTriggers(&file);
SaveReplayList(&file);
// FIXME: find all state information which must be saved.
s = SaveGlobal(Lua, true);
if (s != NULL) {
file.printf("-- Lua state\n\n%s\n", s);
delete[] s;
}
file.close();
}
//@}
|