Changeset - r18219:9a85d923ce33
[Not reviewed]
master
0 7 0
yexo - 13 years ago 2011-10-30 13:47:45
yexo@openttd.org
(svn r23065) -Add: -q option to read a savegame, write some general info and exit
7 files changed with 123 insertions and 7 deletions:
0 comments (0 inline, 0 general)
docs/openttd.6
Show inline comments
 
@@ -18,12 +18,13 @@
 
.Op Fl l Ar host[:port]
 
.Op Fl m Ar driver
 
.Op Fl M Ar musicset
 
.Op Fl n Ar host[:port][#player]
 
.Op Fl p Ar password
 
.Op Fl P Ar password
 
.Op Fl q Ar savegame
 
.Op Fl r Ar widthxheight
 
.Op Fl s Ar driver
 
.Op Fl S Ar soundset
 
.Op Fl t Ar year
 
.Op Fl v Ar driver
 
.Sh OPTIONS
 
@@ -80,12 +81,14 @@ Join a network game, optionally specify 
 
.It Fl p Ar password
 
Password used to join server. Only useful with
 
.Fl n
 
.It Fl P Ar password
 
Password used to join company. Only useful with
 
.Fl n
 
.It Fl q Ar savegame
 
Write some information about the savegame and exit
 
.It Fl r Ar widthxheight
 
Set the resolution
 
.It Fl s Ar driver
 
Set the sound driver, see
 
.Fl h
 
for a full list
src/fios.h
Show inline comments
 
@@ -34,13 +34,16 @@ struct LoadCheckData {
 

	
 
	CompanyPropertiesMap companies;               ///< Company information.
 

	
 
	GRFConfig *grfconfig;                         ///< NewGrf configuration from save.
 
	GRFListCompatibility grf_compatibility;       ///< Summary state of NewGrfs, whether missing files or only compatible found.
 

	
 
	LoadCheckData() : error_data(NULL), grfconfig(NULL)
 
	struct LoggedAction *gamelog_action;          ///< Gamelog actions
 
	uint gamelog_actions;                         ///< Number of gamelog actions
 

	
 
	LoadCheckData() : error_data(NULL), grfconfig(NULL), gamelog_action(NULL)
 
	{
 
		this->Clear();
 
	}
 

	
 
	/**
 
	 * Don't leak memory at program exit
src/fios_gui.cpp
Show inline comments
 
@@ -54,12 +54,16 @@ void LoadCheckData::Clear()
 
	const CompanyPropertiesMap::iterator end = this->companies.End();
 
	for (CompanyPropertiesMap::iterator it = this->companies.Begin(); it != end; it++) {
 
		delete it->second;
 
	}
 
	companies.Clear();
 

	
 
	free(this->gamelog_action);
 
	this->gamelog_action = NULL;
 
	this->gamelog_actions = 0;
 

	
 
	ClearGRFConfigList(&this->grfconfig);
 
}
 

	
 

	
 
enum SaveLoadWindowWidgets {
 
	SLWW_WINDOWTITLE,
src/gamelog.cpp
Show inline comments
 
@@ -771,6 +771,36 @@ void GamelogGRFUpdate(const GRFConfig *o
 
	while (o < ol->n) GamelogGRFRemove(ol->grf[o++]->ident.grfid); // remaining GRFs were removed ...
 
	while (n < nl->n) GamelogGRFAdd   (nl->grf[n++]);              // ... or added
 

	
 
	free(ol);
 
	free(nl);
 
}
 

	
 
/**
 
 * Get some basic information from the given gamelog.
 
 * @param gamelog_action Pointer to the gamelog to extract information from.
 
 * @param gamelog_actions Number of actions in the given gamelog.
 
 * @param [out] last_ottd_rev OpenTTD NewGRF version from the binary that saved the savegame last.
 
 * @param [out] ever_modified Max value of 'modified' from all binaries that ever saved this savegame.
 
 * @param [out] removed_newgrfs Set to true if any NewGRFs have been removed.
 
 */
 
void GamelogInfo(LoggedAction *gamelog_action, uint gamelog_actions, uint32 *last_ottd_rev, byte *ever_modified, bool *removed_newgrfs)
 
{
 
	const LoggedAction *laend = &gamelog_action[gamelog_actions];
 
	for (const LoggedAction *la = gamelog_action; la != laend; la++) {
 
		const LoggedChange *lcend = &la->change[la->changes];
 
		for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
 
			switch (lc->ct) {
 
				default: break;
 

	
 
				case GLCT_REVISION:
 
					*last_ottd_rev = lc->revision.newgrf;
 
					*ever_modified = max(*ever_modified, lc->revision.modified);
 
					break;
 

	
 
				case GLCT_GRFREM:
 
					*removed_newgrfs = true;
 
					break;
 
			}
 
		}
 
	}
 
}
src/gamelog.h
Show inline comments
 
@@ -58,7 +58,9 @@ void GamelogGRFCompatible(const GRFIdent
 

	
 
void GamelogTestRevision();
 
void GamelogTestMode();
 

	
 
bool GamelogGRFBugReverse(uint32 grfid, uint16 internal_id);
 

	
 
void GamelogInfo(struct LoggedAction *gamelog_action, uint gamelog_actions, uint32 *last_ottd_rev, byte *ever_modified, bool *removed_newgrfs);
 

	
 
#endif /* GAMELOG_H */
src/openttd.cpp
Show inline comments
 
@@ -176,12 +176,13 @@ static void ShowHelp()
 
#endif /* ENABLE_NETWORK */
 
		"  -I graphics_set     = Force the graphics set (see below)\n"
 
		"  -S sounds_set       = Force the sounds set (see below)\n"
 
		"  -M music_set        = Force the music set (see below)\n"
 
		"  -c config_file      = Use 'config_file' instead of 'openttd.cfg'\n"
 
		"  -x                  = Do not automatically save to config file on exit\n"
 
		"  -q savegame         = Write some information about the savegame and exit\n"
 
		"\n",
 
		lastof(buf)
 
	);
 

	
 
	/* List the graphics packs */
 
	p = BaseGraphics::GetSetsList(p, lastof(buf));
 
@@ -210,12 +211,50 @@ static void ShowHelp()
 
	printf("%s\n", buf);
 
#else
 
	ShowInfo(buf);
 
#endif
 
}
 

	
 
static void WriteSavegameInfo(const char *name)
 
{
 
	extern uint16 _sl_version;
 
	uint32 last_ottd_rev = 0;
 
	byte ever_modified = 0;
 
	bool removed_newgrfs = false;
 

	
 
	GamelogInfo(_load_check_data.gamelog_action, _load_check_data.gamelog_actions, &last_ottd_rev, &ever_modified, &removed_newgrfs);
 

	
 
	char buf[8192];
 
	char *p = buf;
 
	p += seprintf(p, lastof(buf), "Name:         %s\n", name);
 
	p += seprintf(p, lastof(buf), "Savegame ver: %d\n", _sl_version);
 
	p += seprintf(p, lastof(buf), "NewGRF ver:   0x%08X\n", last_ottd_rev);
 
	p += seprintf(p, lastof(buf), "Modified:     %d\n", ever_modified);
 

	
 
	if (removed_newgrfs) {
 
		p += seprintf(p, lastof(buf), "NewGRFs have been removed\n");
 
	}
 

	
 
	p = strecpy(p, "NewGRFs:\n", lastof(buf));
 
	if (_load_check_data.HasNewGrfs()) {
 
		for (GRFConfig *c = _load_check_data.grfconfig; c != NULL; c = c->next) {
 
			char md5sum[33];
 
			md5sumToString(md5sum, lastof(md5sum), HasBit(c->flags, GCF_COMPATIBLE) ? c->original_md5sum : c->ident.md5sum);
 
			p += seprintf(p, lastof(buf), "%08X %s %s\n", c->ident.grfid, md5sum, c->filename);
 
		}
 
	}
 

	
 
	/* ShowInfo put output to stderr, but version information should go
 
	 * to stdout; this is the only exception */
 
#if !defined(WIN32) && !defined(WIN64)
 
	printf("%s\n", buf);
 
#else
 
	ShowInfo(buf);
 
#endif
 
}
 

	
 

	
 
/**
 
 * Extract the resolution from the given string and store
 
 * it in the 'res' parameter.
 
 * @param res variable to store the resolution in.
 
 * @param s   the string to decompose.
 
@@ -429,12 +468,13 @@ static const OptionData _options[] = {
 
	GETOPT_SHORT_OPTVAL('d'),
 
	 GETOPT_SHORT_NOVAL('e'),
 
	GETOPT_SHORT_OPTVAL('g'),
 
	 GETOPT_SHORT_VALUE('G'),
 
	 GETOPT_SHORT_VALUE('c'),
 
	 GETOPT_SHORT_NOVAL('x'),
 
	 GETOPT_SHORT_VALUE('q'),
 
	 GETOPT_SHORT_NOVAL('h'),
 
	GETOPT_END()
 
};
 

	
 

	
 
int ttd_main(int argc, char *argv[])
 
@@ -539,12 +579,36 @@ int ttd_main(int argc, char *argv[])
 
			_switch_mode = SM_NEWGAME;
 
			/* Give a random map if no seed has been given */
 
			if (scanner->generation_seed == GENERATE_NEW_SEED) {
 
				scanner->generation_seed = InteractiveRandom();
 
			}
 
			break;
 
		case 'q': {
 
			DeterminePaths(argv[0]);
 
			if (StrEmpty(mgo.opt)) return 1;
 
			char title[80];
 
			title[0] = '\0';
 
			FiosGetSavegameListCallback(SLD_LOAD_GAME, mgo.opt, strrchr(mgo.opt, '.'), title, lastof(title));
 

	
 
			_load_check_data.Clear();
 
			SaveOrLoadResult res = SaveOrLoad(mgo.opt, SL_LOAD_CHECK, SAVE_DIR, false);
 
			if (res != SL_OK || _load_check_data.HasErrors()) {
 
				fprintf(stderr, "Failed to open savegame\n");
 
				if (_load_check_data.HasErrors()) {
 
					char buf[256];
 
					SetDParamStr(0, _load_check_data.error_data);
 
					GetString(buf, _load_check_data.error, lastof(buf));
 
					fprintf(stderr, "%s\n", buf);
 
				}
 
				return 1;
 
			}
 

	
 
			WriteSavegameInfo(title);
 

	
 
			return 0;
 
		}
 
		case 'G': scanner->generation_seed = atoi(mgo.opt); break;
 
		case 'c': _config_file = strdup(mgo.opt); break;
 
		case 'x': save_config = false; break;
 
		case 'h':
 
			i = -2; // Force printing of help.
 
			break;
src/saveload/gamelog_sl.cpp
Show inline comments
 
@@ -8,12 +8,13 @@
 
 */
 

	
 
/** @file gamelog_sl.cpp Code handling saving and loading of gamelog data */
 

	
 
#include "../stdafx.h"
 
#include "../gamelog_internal.h"
 
#include "../fios.h"
 

	
 
#include "saveload.h"
 

	
 
static const SaveLoad _glog_action_desc[] = {
 
	SLE_VAR(LoggedAction, tick,              SLE_UINT16),
 
	SLE_END()
 
@@ -98,21 +99,21 @@ static const SaveLoad * const _glog_desc
 
	_glog_grfbug_desc,
 
	_glog_emergency_desc,
 
};
 

	
 
assert_compile(lengthof(_glog_desc) == GLCT_END);
 

	
 
static void Load_GLOG()
 
static void Load_GLOG_common(LoggedAction *&gamelog_action, uint &gamelog_actions)
 
{
 
	assert(_gamelog_action == NULL);
 
	assert(_gamelog_actions == 0);
 
	assert(gamelog_action == NULL);
 
	assert(gamelog_actions == 0);
 

	
 
	GamelogActionType at;
 
	while ((at = (GamelogActionType)SlReadByte()) != GLAT_NONE) {
 
		_gamelog_action = ReallocT(_gamelog_action, _gamelog_actions + 1);
 
		LoggedAction *la = &_gamelog_action[_gamelog_actions++];
 
		gamelog_action = ReallocT(gamelog_action, gamelog_actions + 1);
 
		LoggedAction *la = &gamelog_action[gamelog_actions++];
 

	
 
		la->at = at;
 

	
 
		SlObject(la, _glog_action_desc); // has to be saved after 'DATE'!
 
		la->change = NULL;
 
		la->changes = 0;
 
@@ -162,10 +163,19 @@ static void Save_GLOG()
 
		}
 
		SlWriteByte(GLCT_NONE);
 
	}
 
	SlWriteByte(GLAT_NONE);
 
}
 

	
 
static void Load_GLOG()
 
{
 
	Load_GLOG_common(_gamelog_action, _gamelog_actions);
 
}
 

	
 
static void Check_GLOG()
 
{
 
	Load_GLOG_common(_load_check_data.gamelog_action, _load_check_data.gamelog_actions);
 
}
 

	
 
extern const ChunkHandler _gamelog_chunk_handlers[] = {
 
	{ 'GLOG', Save_GLOG, Load_GLOG, NULL, NULL, CH_RIFF | CH_LAST }
 
	{ 'GLOG', Save_GLOG, Load_GLOG, NULL, Check_GLOG, CH_RIFF | CH_LAST }
 
};
0 comments (0 inline, 0 general)