src/gamelog.cpp
author Tero Marttila <terom@fixme.fi>
Tue, 22 Jul 2008 21:51:14 +0300
changeset 11180 982e9f814f97
parent 11169 60cbac6bc442
permissions -rw-r--r--
scan for tarfiles in CACHE_DIR, remember what Subdirectory a tar was found in, set the GCF_FLAG on GRFs loaded from there, and hide those in the NewGRF GUI
10824
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
     1
/* $Id$ */
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
     2
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
     3
/** @file gamelog.cpp Definition of functions used for logging of important changes in the game */
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
     4
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
     5
#include "stdafx.h"
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
     6
#include "openttd.h"
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
     7
#include "saveload.h"
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
     8
#include "core/alloc_func.hpp"
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
     9
#include "core/bitmath_func.hpp"
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    10
#include "core/math_func.hpp"
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    11
#include "network/core/config.h"
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    12
#include "variables.h"
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    13
#include "string_func.h"
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    14
#include "settings_type.h"
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    15
#include "newgrf_config.h"
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    16
#include <string.h>
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    17
#include <stdarg.h>
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    18
#include "gamelog.h"
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    19
#include "console_func.h"
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    20
#include "debug.h"
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    21
#include "rev.h"
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    22
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    23
extern const uint16 SAVEGAME_VERSION;  ///< current savegame version
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    24
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    25
extern SavegameType _savegame_type; ///< type of savegame we are loading
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    26
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    27
extern uint32 _ttdp_version;     ///< version of TTDP savegame (if applicable)
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    28
extern uint16 _sl_version;       ///< the major savegame version identifier
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    29
extern byte   _sl_minor_version; ///< the minor savegame version, DO NOT USE!
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    30
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    31
/** Type of logged change */
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    32
enum GamelogChangeType {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    33
	GLCT_MODE,        ///< Scenario editor x Game, different landscape
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    34
	GLCT_REVISION,    ///< Changed game revision string
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    35
	GLCT_OLDVER,      ///< Loaded from savegame without logged data
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    36
	GLCT_PATCH,       ///< Non-networksafe patch value changed
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    37
	GLCT_GRFADD,      ///< Removed GRF
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    38
	GLCT_GRFREM,      ///< Added GRF
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    39
	GLCT_GRFCOMPAT,   ///< Loading compatible GRF
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    40
	GLCT_GRFPARAM,    ///< GRF parameter changed
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    41
	GLCT_GRFMOVE,     ///< GRF order changed
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    42
	GLCT_END,         ///< So we know how many GLCTs are there
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    43
	GLCT_NONE = 0xFF, ///< In savegames, end of list
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    44
};
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    45
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    46
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    47
/** Contains information about one logged change */
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    48
struct LoggedChange {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    49
	GamelogChangeType ct; ///< Type of change logged in this struct
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    50
	union {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    51
		struct {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    52
			byte mode;       ///< new game mode - Editor x Game
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    53
			byte landscape;  ///< landscape (temperate, arctic, ...)
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    54
		} mode;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    55
		struct {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    56
			char text[NETWORK_REVISION_LENGTH]; ///< revision string, _openttd_revision
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    57
			uint32 newgrf;   ///< _openttd_newgrf_version
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    58
			uint16 slver;    ///< _sl_version
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    59
			byte modified;   ///< _openttd_revision_modified
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    60
		} revision;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    61
		struct {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    62
			uint32 type;     ///< type of savegame, @see SavegameType
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    63
			uint32 version;  ///< major and minor version OR ttdp version
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    64
		} oldver;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    65
		GRFIdentifier grfadd;    ///< ID and md5sum of added GRF
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    66
		struct {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    67
			uint32 grfid;    ///< ID of removed GRF
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    68
		} grfrem;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    69
		GRFIdentifier grfcompat; ///< ID and new md5sum of changed GRF
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    70
		struct {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    71
			uint32 grfid;    ///< ID of GRF with changed parameters
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    72
		} grfparam;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    73
		struct {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    74
			uint32 grfid;    ///< ID of moved GRF
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    75
			int32 offset;    ///< offset, positive = move down
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    76
		} grfmove;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    77
		struct {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    78
			char *name;      ///< name of the patch
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    79
			int32 oldval;    ///< old value
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    80
			int32 newval;    ///< new value
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    81
		} patch;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    82
	};
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    83
};
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    84
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    85
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    86
/** Contains information about one logged action that caused at least one logged change */
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    87
struct LoggedAction {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    88
	LoggedChange *change; ///< First logged change in this action
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    89
	uint32 changes;       ///< Number of changes in this action
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    90
	GamelogActionType at; ///< Type of action
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    91
	uint16 tick;          ///< Tick when it happened
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    92
};
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    93
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    94
static GamelogActionType _gamelog_action_type = GLAT_NONE; ///< action to record if anything changes
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    95
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    96
static LoggedAction *_gamelog_action = NULL; ///< first logged action
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    97
static uint _gamelog_actions         = 0;    ///< number of actions
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    98
static LoggedAction *_current_action = NULL; ///< current action we are logging, NULL when there is no action active
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
    99
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   100
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   101
/** Stores information about new action, but doesn't allocate it
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   102
 * Action is allocated only when there is at least one change
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   103
 * @param at type of action
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   104
 */
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   105
void GamelogStartAction(GamelogActionType at)
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   106
{
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   107
	assert(_gamelog_action_type == GLAT_NONE); // do not allow starting new action without stopping the previous first
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   108
	_gamelog_action_type = at;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   109
}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   110
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   111
/** Stops logging of any changes
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   112
 */
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   113
void GamelogStopAction()
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   114
{
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   115
	assert(_gamelog_action_type != GLAT_NONE); // nobody should try to stop if there is no action in progress
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   116
11169
60cbac6bc442 (svn r13727) -Fix (r13375): compilation with NO_DEBUG_MESSAGES was broken
smatz
parents: 10966
diff changeset
   117
	bool print = _current_action != NULL;
60cbac6bc442 (svn r13727) -Fix (r13375): compilation with NO_DEBUG_MESSAGES was broken
smatz
parents: 10966
diff changeset
   118
10824
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   119
	_current_action = NULL;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   120
	_gamelog_action_type = GLAT_NONE;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   121
11169
60cbac6bc442 (svn r13727) -Fix (r13375): compilation with NO_DEBUG_MESSAGES was broken
smatz
parents: 10966
diff changeset
   122
	if (print) GamelogPrintDebug(5);
10824
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   123
}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   124
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   125
/** Resets and frees all memory allocated - used before loading or starting a new game
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   126
 */
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   127
void GamelogReset()
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   128
{
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   129
	assert(_gamelog_action_type == GLAT_NONE);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   130
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   131
	for (uint i = 0; i < _gamelog_actions; i++) {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   132
		const LoggedAction *la = &_gamelog_action[i];
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   133
		for (uint j = 0; j < la->changes; j++) {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   134
			const LoggedChange *lc = &la->change[j];
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   135
			if (lc->ct == GLCT_PATCH) free(lc->patch.name);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   136
		}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   137
		free(la->change);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   138
	}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   139
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   140
	free(_gamelog_action);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   141
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   142
	_gamelog_action  = NULL;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   143
	_gamelog_actions = 0;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   144
	_current_action  = NULL;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   145
}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   146
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   147
enum {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   148
	GAMELOG_BUF_LEN = 1024 ///< length of buffer for one line of text
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   149
};
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   150
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   151
static int _dbgofs = 0; ///< offset in current output buffer
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   152
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   153
static void AddDebugText(char *buf, const char *s, ...)
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   154
{
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   155
	if (GAMELOG_BUF_LEN <= _dbgofs) return;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   156
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   157
	va_list va;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   158
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   159
	va_start(va, s);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   160
	_dbgofs += vsnprintf(buf + _dbgofs, GAMELOG_BUF_LEN - _dbgofs, s, va);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   161
	va_end(va);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   162
}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   163
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   164
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   165
/** Prints GRF filename if found
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   166
 * @param grfid GRF which filename to print
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   167
 */
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   168
static void PrintGrfFilename(char *buf, uint grfid)
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   169
{
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   170
	const GRFConfig *gc = FindGRFConfig(grfid);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   171
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   172
	if (gc == NULL) return;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   173
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   174
	AddDebugText(buf, ", filename: %s", gc->filename);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   175
}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   176
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   177
/** Prints GRF ID, checksum and filename if found
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   178
 * @param grfid GRF ID
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   179
 * @param md5sum array of md5sum to print
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   180
 */
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   181
static void PrintGrfInfo(char *buf, uint grfid, const uint8 *md5sum)
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   182
{
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   183
	char txt[40];
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   184
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   185
	md5sumToString(txt, lastof(txt), md5sum);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   186
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   187
	AddDebugText(buf, "GRF ID %08X, checksum %s", BSWAP32(grfid), txt);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   188
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   189
	PrintGrfFilename(buf, grfid);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   190
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   191
	return;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   192
}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   193
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   194
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   195
/** Text messages for various logged actions */
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   196
static const char *la_text[] = {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   197
	"new game started",
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   198
	"game loaded",
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   199
	"GRF config changed",
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   200
	"cheat was used",
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   201
	"patch settings changed"
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   202
};
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   203
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   204
assert_compile(lengthof(la_text) == GLAT_END);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   205
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   206
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   207
/** Prints active gamelog */
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   208
void GamelogPrint(GamelogPrintProc *proc)
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   209
{
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   210
	char buf[GAMELOG_BUF_LEN];
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   211
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   212
	proc("---- gamelog start ----");
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   213
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   214
	const LoggedAction *laend = &_gamelog_action[_gamelog_actions];
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   215
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   216
	for (const LoggedAction *la = _gamelog_action; la != laend; la++) {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   217
		assert((uint)la->at < GLAT_END);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   218
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   219
		snprintf(buf, GAMELOG_BUF_LEN, "Tick %u: %s", (uint)la->tick, la_text[(uint)la->at]);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   220
		proc(buf);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   221
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   222
		const LoggedChange *lcend = &la->change[la->changes];
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   223
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   224
		for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   225
			_dbgofs = 0;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   226
			AddDebugText(buf, "     ");
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   227
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   228
			switch (lc->ct) {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   229
				default: NOT_REACHED();
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   230
				case GLCT_MODE:
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   231
					AddDebugText(buf, "New game mode: %u landscape: %u",
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   232
						(uint)lc->mode.mode, (uint)lc->mode.landscape);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   233
					break;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   234
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   235
				case GLCT_REVISION:
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   236
					AddDebugText(buf, "Revision text changed to %s, savegame version %u, ",
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   237
						lc->revision.text, lc->revision.slver);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   238
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   239
					switch (lc->revision.modified) {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   240
						case 0: AddDebugText(buf, "not "); break;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   241
						case 1: AddDebugText(buf, "maybe "); break;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   242
						default: break;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   243
					}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   244
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   245
					AddDebugText(buf, "modified, _openttd_newgrf_version = 0x%08x", lc->revision.newgrf);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   246
					break;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   247
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   248
				case GLCT_OLDVER:
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   249
					AddDebugText(buf, "Conversion from ");
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   250
					switch (lc->oldver.type) {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   251
						default: NOT_REACHED();
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   252
						case SGT_OTTD:
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   253
							AddDebugText(buf, "OTTD savegame without gamelog: version %u, %u",
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   254
								GB(lc->oldver.version, 8, 16), GB(lc->oldver.version, 0, 8));
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   255
							break;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   256
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   257
						case SGT_TTD:
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   258
							AddDebugText(buf, "TTD savegame");
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   259
							break;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   260
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   261
						case SGT_TTDP1:
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   262
						case SGT_TTDP2:
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   263
							AddDebugText(buf, "TTDP savegame, %s format",
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   264
								lc->oldver.type == SGT_TTDP1 ? "old" : "new");
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   265
							if (lc->oldver.version != 0) {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   266
								AddDebugText(buf, ", TTDP version %u.%u.%u.%u",
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   267
									GB(lc->oldver.version, 24, 8), GB(lc->oldver.version, 20, 4),
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   268
									GB(lc->oldver.version, 16, 4), GB(lc->oldver.version, 0, 16));
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   269
							}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   270
							break;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   271
					}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   272
					break;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   273
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   274
				case GLCT_PATCH:
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   275
					AddDebugText(buf, "Patch setting changed: %s : %d -> %d", lc->patch.name, lc->patch.oldval, lc->patch.newval);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   276
					break;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   277
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   278
				case GLCT_GRFADD:
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   279
					AddDebugText(buf, "Added NewGRF: ");
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   280
					PrintGrfInfo(buf, lc->grfadd.grfid, lc->grfadd.md5sum);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   281
					break;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   282
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   283
				case GLCT_GRFREM:
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   284
					AddDebugText(buf, "Removed NewGRF: %08X", BSWAP32(lc->grfrem.grfid));
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   285
					PrintGrfFilename(buf, lc->grfrem.grfid);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   286
					break;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   287
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   288
				case GLCT_GRFCOMPAT:
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   289
					AddDebugText(buf, "Compatible NewGRF loaded: ");
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   290
					PrintGrfInfo(buf, lc->grfcompat.grfid, lc->grfcompat.md5sum);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   291
					break;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   292
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   293
				case GLCT_GRFPARAM:
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   294
					AddDebugText(buf, "GRF parameter changed: %08X", BSWAP32(lc->grfparam.grfid));
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   295
					PrintGrfFilename(buf, lc->grfparam.grfid);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   296
					break;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   297
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   298
				case GLCT_GRFMOVE:
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   299
					AddDebugText(buf, "GRF order changed: %08X moved %d places %s",
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   300
						BSWAP32(lc->grfmove.grfid), abs(lc->grfmove.offset), lc->grfmove.offset >= 0 ? "down" : "up" );
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   301
					PrintGrfFilename(buf, lc->grfmove.grfid);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   302
					break;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   303
			}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   304
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   305
			proc(buf);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   306
		}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   307
	}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   308
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   309
	proc("---- gamelog end ----");
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   310
}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   311
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   312
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   313
static void GamelogPrintConsoleProc(const char *s)
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   314
{
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   315
	IConsolePrint(CC_WARNING, s);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   316
}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   317
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   318
void GamelogPrintConsole()
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   319
{
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   320
	GamelogPrint(&GamelogPrintConsoleProc);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   321
}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   322
11169
60cbac6bc442 (svn r13727) -Fix (r13375): compilation with NO_DEBUG_MESSAGES was broken
smatz
parents: 10966
diff changeset
   323
static int _gamelog_print_level = 0; ///< gamelog debug level we need to print stuff
10824
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   324
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   325
static void GamelogPrintDebugProc(const char *s)
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   326
{
11169
60cbac6bc442 (svn r13727) -Fix (r13375): compilation with NO_DEBUG_MESSAGES was broken
smatz
parents: 10966
diff changeset
   327
	DEBUG(gamelog, _gamelog_print_level, s);
10824
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   328
}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   329
11169
60cbac6bc442 (svn r13727) -Fix (r13375): compilation with NO_DEBUG_MESSAGES was broken
smatz
parents: 10966
diff changeset
   330
60cbac6bc442 (svn r13727) -Fix (r13375): compilation with NO_DEBUG_MESSAGES was broken
smatz
parents: 10966
diff changeset
   331
/** Prints gamelog to debug output. Code is executed even when
60cbac6bc442 (svn r13727) -Fix (r13375): compilation with NO_DEBUG_MESSAGES was broken
smatz
parents: 10966
diff changeset
   332
 * there will be no output. It is called very seldom, so it
60cbac6bc442 (svn r13727) -Fix (r13375): compilation with NO_DEBUG_MESSAGES was broken
smatz
parents: 10966
diff changeset
   333
 * doesn't matter that much. At least it gives more uniform code...
60cbac6bc442 (svn r13727) -Fix (r13375): compilation with NO_DEBUG_MESSAGES was broken
smatz
parents: 10966
diff changeset
   334
 * @param level debug level we need to print stuff
60cbac6bc442 (svn r13727) -Fix (r13375): compilation with NO_DEBUG_MESSAGES was broken
smatz
parents: 10966
diff changeset
   335
 */
60cbac6bc442 (svn r13727) -Fix (r13375): compilation with NO_DEBUG_MESSAGES was broken
smatz
parents: 10966
diff changeset
   336
void GamelogPrintDebug(int level)
10824
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   337
{
11169
60cbac6bc442 (svn r13727) -Fix (r13375): compilation with NO_DEBUG_MESSAGES was broken
smatz
parents: 10966
diff changeset
   338
	_gamelog_print_level = level;
10824
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   339
	GamelogPrint(&GamelogPrintDebugProc);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   340
}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   341
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   342
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   343
/** Allocates new LoggedChange and new LoggedAction if needed.
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   344
 * If there is no action active, NULL is returned.
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   345
 * @param ct type of change
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   346
 * @return new LoggedChange, or NULL if there is no action active
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   347
 */
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   348
static LoggedChange *GamelogChange(GamelogChangeType ct)
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   349
{
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   350
	if (_current_action == NULL) {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   351
		if (_gamelog_action_type == GLAT_NONE) return NULL;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   352
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   353
		_gamelog_action  = ReallocT(_gamelog_action, _gamelog_actions + 1);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   354
		_current_action  = &_gamelog_action[_gamelog_actions++];
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   355
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   356
		_current_action->at      = _gamelog_action_type;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   357
		_current_action->tick    = _tick_counter;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   358
		_current_action->change  = NULL;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   359
		_current_action->changes = 0;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   360
	}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   361
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   362
	_current_action->change = ReallocT(_current_action->change, _current_action->changes + 1);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   363
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   364
	LoggedChange *lc = &_current_action->change[_current_action->changes++];
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   365
	lc->ct = ct;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   366
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   367
	return lc;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   368
}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   369
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   370
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   371
/** Logs a change in game revision
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   372
 * @param revision new revision string
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   373
 */
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   374
void GamelogRevision()
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   375
{
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   376
	assert(_gamelog_action_type == GLAT_START || _gamelog_action_type == GLAT_LOAD);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   377
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   378
	LoggedChange *lc = GamelogChange(GLCT_REVISION);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   379
	if (lc == NULL) return;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   380
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   381
	strncpy(lc->revision.text, _openttd_revision, lengthof(lc->revision.text));
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   382
	lc->revision.slver = SAVEGAME_VERSION;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   383
	lc->revision.modified = _openttd_revision_modified;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   384
	lc->revision.newgrf = _openttd_newgrf_version;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   385
}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   386
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   387
/** Logs a change in game mode (scenario editor or game)
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   388
 */
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   389
void GamelogMode()
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   390
{
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   391
	assert(_gamelog_action_type == GLAT_START || _gamelog_action_type == GLAT_LOAD || _gamelog_action_type == GLAT_CHEAT);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   392
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   393
	LoggedChange *lc = GamelogChange(GLCT_MODE);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   394
	if (lc == NULL) return;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   395
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   396
	lc->mode.mode      = _game_mode;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   397
	lc->mode.landscape = _settings_game.game_creation.landscape;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   398
}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   399
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   400
/** Logs loading from savegame without gamelog
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   401
 */
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   402
void GamelogOldver()
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   403
{
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   404
	assert(_gamelog_action_type == GLAT_LOAD);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   405
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   406
	LoggedChange *lc = GamelogChange(GLCT_OLDVER);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   407
	if (lc == NULL) return;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   408
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   409
	lc->oldver.type = _savegame_type;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   410
	lc->oldver.version = (_savegame_type == SGT_OTTD ? ((uint32)_sl_version << 8 | _sl_minor_version) : _ttdp_version);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   411
}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   412
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   413
/** Logs change in game patches. Only non-networksafe patches are logged
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   414
 * @param name patch name
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   415
 * @param oldval old patch value
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   416
 * @param newval new patch value
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   417
 */
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   418
void GamelogPatch(const char *name, int32 oldval, int32 newval)
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   419
{
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   420
	assert(_gamelog_action_type == GLAT_PATCH);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   421
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   422
	LoggedChange *lc = GamelogChange(GLCT_PATCH);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   423
	if (lc == NULL) return;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   424
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   425
	lc->patch.name = strdup(name);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   426
	lc->patch.oldval = oldval;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   427
	lc->patch.newval = newval;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   428
}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   429
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   430
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   431
/** Finds out if current revision is different than last revision stored in the savegame.
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   432
 * Appends GLCT_REVISION when the revision string changed
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   433
 */
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   434
void GamelogTestRevision()
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   435
{
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   436
	const LoggedChange *rev = NULL;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   437
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   438
	const LoggedAction *laend = &_gamelog_action[_gamelog_actions];
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   439
	for (const LoggedAction *la = _gamelog_action; la != laend; la++) {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   440
		const LoggedChange *lcend = &la->change[la->changes];
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   441
		for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   442
			if (lc->ct == GLCT_REVISION) rev = lc;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   443
		}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   444
	}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   445
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   446
	if (rev == NULL || strcmp(rev->revision.text, _openttd_revision) != 0 ||
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   447
			rev->revision.modified != _openttd_revision_modified ||
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   448
			rev->revision.newgrf != _openttd_newgrf_version) {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   449
		GamelogRevision();
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   450
	}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   451
}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   452
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   453
/** Finds last stored game mode or landscape.
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   454
 * Any change is logged
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   455
 */
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   456
void GamelogTestMode()
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   457
{
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   458
	const LoggedChange *mode = NULL;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   459
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   460
	const LoggedAction *laend = &_gamelog_action[_gamelog_actions];
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   461
	for (const LoggedAction *la = _gamelog_action; la != laend; la++) {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   462
		const LoggedChange *lcend = &la->change[la->changes];
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   463
		for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   464
			if (lc->ct == GLCT_MODE) mode = lc;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   465
		}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   466
	}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   467
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   468
	if (mode == NULL || mode->mode.mode != _game_mode || mode->mode.landscape != _settings_game.game_creation.landscape) GamelogMode();
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   469
}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   470
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   471
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   472
/** Decides if GRF should be logged
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   473
 * @param g grf to determine
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   474
 * @return true iff GRF is not static and is loaded
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   475
 */
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   476
static inline bool IsLoggableGrfConfig(const GRFConfig *g)
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   477
{
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   478
	return !HasBit(g->flags, GCF_STATIC) && g->status != GCS_NOT_FOUND;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   479
}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   480
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   481
/** Logs removal of a GRF
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   482
 * @param grfid ID of removed GRF
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   483
 */
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   484
void GamelogGRFRemove(uint32 grfid)
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   485
{
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   486
	assert(_gamelog_action_type == GLAT_LOAD || _gamelog_action_type == GLAT_GRF);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   487
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   488
	LoggedChange *lc = GamelogChange(GLCT_GRFREM);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   489
	if (lc == NULL) return;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   490
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   491
	lc->grfrem.grfid = grfid;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   492
}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   493
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   494
/** Logs adding of a GRF
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   495
 * @param newg added GRF
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   496
 */
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   497
void GamelogGRFAdd(const GRFConfig *newg)
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   498
{
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   499
	assert(_gamelog_action_type == GLAT_LOAD || _gamelog_action_type == GLAT_START || _gamelog_action_type == GLAT_GRF);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   500
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   501
	if (!IsLoggableGrfConfig(newg)) return;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   502
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   503
	LoggedChange *lc = GamelogChange(GLCT_GRFADD);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   504
	if (lc == NULL) return;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   505
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   506
	memcpy(&lc->grfadd, newg, sizeof(GRFIdentifier));
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   507
}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   508
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   509
/** Logs loading compatible GRF
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   510
 * (the same ID, but different MD5 hash)
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   511
 * @param newg new (updated) GRF
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   512
 */
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   513
void GamelogGRFCompatible(const GRFIdentifier *newg)
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   514
{
10845
4cc81b7cf711 (svn r13396) -Fix (r13375): assertion failing when changing grfs in game (compatible grfs)
glx
parents: 10824
diff changeset
   515
	assert(_gamelog_action_type == GLAT_LOAD || _gamelog_action_type == GLAT_GRF);
10824
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   516
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   517
	LoggedChange *lc = GamelogChange(GLCT_GRFCOMPAT);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   518
	if (lc == NULL) return;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   519
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   520
	memcpy(&lc->grfcompat, newg, sizeof(GRFIdentifier));
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   521
}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   522
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   523
/** Logs changing GRF order
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   524
 * @param grfid GRF that is moved
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   525
 * @param offset how far it is moved, positive = moved down
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   526
 */
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   527
static void GamelogGRFMove(uint32 grfid, int32 offset)
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   528
{
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   529
	assert(_gamelog_action_type == GLAT_GRF);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   530
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   531
	LoggedChange *lc = GamelogChange(GLCT_GRFMOVE);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   532
	if (lc == NULL) return;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   533
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   534
	lc->grfmove.grfid  = grfid;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   535
	lc->grfmove.offset = offset;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   536
}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   537
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   538
/** Logs change in GRF parameters.
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   539
 * Details about parameters changed are not stored
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   540
 * @param grfid ID of GRF to store
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   541
 */
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   542
static void GamelogGRFParameters(uint32 grfid)
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   543
{
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   544
	assert(_gamelog_action_type == GLAT_GRF);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   545
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   546
	LoggedChange *lc = GamelogChange(GLCT_GRFPARAM);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   547
	if (lc == NULL) return;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   548
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   549
	lc->grfparam.grfid = grfid;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   550
}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   551
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   552
/** Logs adding of list of GRFs.
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   553
 * Useful when old savegame is loaded or when new game is started
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   554
 * @param newg head of GRF linked list
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   555
 */
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   556
void GamelogGRFAddList(const GRFConfig *newg)
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   557
{
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   558
	assert(_gamelog_action_type == GLAT_START || _gamelog_action_type == GLAT_LOAD);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   559
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   560
	for (; newg != NULL; newg = newg->next) {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   561
		GamelogGRFAdd(newg);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   562
	}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   563
}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   564
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   565
/** List of GRFs using array of pointers instead of linked list */
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   566
struct GRFList {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   567
	uint n;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   568
	const GRFConfig *grf[VARARRAY_SIZE];
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   569
};
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   570
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   571
/** Generates GRFList
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   572
 * @param grfc head of GRF linked list
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   573
 */
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   574
static GRFList *GenerateGRFList(const GRFConfig *grfc)
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   575
{
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   576
	uint n = 0;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   577
	for (const GRFConfig *g = grfc; g != NULL; g = g->next) {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   578
		if (IsLoggableGrfConfig(g)) n++;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   579
	}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   580
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   581
	GRFList *list = (GRFList*)MallocT<byte>(sizeof(GRFList) + n * sizeof(GRFConfig*));
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   582
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   583
	list->n = 0;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   584
	for (const GRFConfig *g = grfc; g != NULL; g = g->next) {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   585
		if (IsLoggableGrfConfig(g)) list->grf[list->n++] = g;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   586
	}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   587
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   588
	return list;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   589
}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   590
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   591
/** Compares two NewGRF lists and logs any change
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   592
 * @param oldc original GRF list
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   593
 * @param newc new GRF list
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   594
 */
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   595
void GamelogGRFUpdate(const GRFConfig *oldc, const GRFConfig *newc)
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   596
{
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   597
	GRFList *ol = GenerateGRFList(oldc);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   598
	GRFList *nl = GenerateGRFList(newc);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   599
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   600
	uint o = 0, n = 0;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   601
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   602
	while (o < ol->n && n < nl->n) {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   603
		const GRFConfig *og = ol->grf[o];
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   604
		const GRFConfig *ng = nl->grf[n];
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   605
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   606
		if (og->grfid != ng->grfid) {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   607
			uint oi, ni;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   608
			for (oi = 0; oi < ol->n; oi++) {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   609
				if (ol->grf[oi]->grfid == nl->grf[n]->grfid) break;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   610
			}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   611
			if (oi < o) {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   612
				/* GRF was moved, this change has been logged already */
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   613
				n++;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   614
				continue;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   615
			}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   616
			if (oi == ol->n) {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   617
				/* GRF couldn't be found in the OLD list, GRF was ADDED */
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   618
				GamelogGRFAdd(nl->grf[n++]);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   619
				continue;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   620
			}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   621
			for (ni = 0; ni < nl->n; ni++) {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   622
				if (nl->grf[ni]->grfid == ol->grf[o]->grfid) break;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   623
			}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   624
			if (ni < n) {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   625
				/* GRF was moved, this change has been logged already */
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   626
				o++;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   627
				continue;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   628
			}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   629
			if (ni == nl->n) {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   630
				/* GRF couldn't be found in the NEW list, GRF was REMOVED */
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   631
				GamelogGRFRemove(ol->grf[o++]->grfid);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   632
				continue;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   633
			}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   634
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   635
			/* o < oi < ol->n
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   636
			 * n < ni < nl->n */
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   637
			assert(ni > n && ni < nl->n);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   638
			assert(oi > o && oi < ol->n);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   639
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   640
			ni -= n; // number of GRFs it was moved downwards
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   641
			oi -= o; // number of GRFs it was moved upwards
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   642
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   643
			if (ni >= oi) { // prefer the one that is moved further
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   644
				/* GRF was moved down */
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   645
				GamelogGRFMove(ol->grf[o++]->grfid, ni);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   646
			} else {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   647
				GamelogGRFMove(nl->grf[n++]->grfid, -(int)oi);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   648
			}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   649
		} else {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   650
			if (memcmp(og->md5sum, ng->md5sum, sizeof(og->md5sum)) != 0) {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   651
				/* md5sum changed, probably loading 'compatible' GRF */
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   652
				GamelogGRFCompatible(nl->grf[n]);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   653
			}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   654
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   655
			if (og->num_params != ng->num_params || memcmp(og->param, ng->param, og->num_params * sizeof(og->param[0])) != 0) {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   656
				GamelogGRFParameters(ol->grf[o]->grfid);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   657
			}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   658
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   659
			o++;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   660
			n++;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   661
		}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   662
	}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   663
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   664
	while (o < ol->n) GamelogGRFRemove(ol->grf[o++]->grfid); // remaining GRFs were removed ...
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   665
	while (n < nl->n) GamelogGRFAdd   (nl->grf[n++]);    // ... or added
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   666
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   667
	free(ol);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   668
	free(nl);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   669
}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   670
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   671
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   672
static const SaveLoad _glog_action_desc[] = {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   673
	SLE_VAR(LoggedAction, tick,              SLE_UINT16),
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   674
	SLE_END()
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   675
};
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   676
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   677
static const SaveLoad _glog_mode_desc[] = {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   678
	SLE_VAR(LoggedChange, mode.mode,         SLE_UINT8),
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   679
	SLE_VAR(LoggedChange, mode.landscape,    SLE_UINT8),
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   680
	SLE_END()
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   681
};
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   682
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   683
static const SaveLoad _glog_revision_desc[] = {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   684
	SLE_ARR(LoggedChange, revision.text,     SLE_UINT8,  NETWORK_REVISION_LENGTH),
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   685
	SLE_VAR(LoggedChange, revision.newgrf,   SLE_UINT32),
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   686
	SLE_VAR(LoggedChange, revision.slver,    SLE_UINT16),
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   687
	SLE_VAR(LoggedChange, revision.modified, SLE_UINT8),
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   688
	SLE_END()
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   689
};
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   690
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   691
static const SaveLoad _glog_oldver_desc[] = {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   692
	SLE_VAR(LoggedChange, oldver.type,       SLE_UINT32),
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   693
	SLE_VAR(LoggedChange, oldver.version,    SLE_UINT32),
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   694
	SLE_END()
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   695
};
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   696
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   697
static const SaveLoad _glog_patch_desc[] = {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   698
	SLE_STR(LoggedChange, patch.name,        SLE_STR,    128),
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   699
	SLE_VAR(LoggedChange, patch.oldval,      SLE_INT32),
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   700
	SLE_VAR(LoggedChange, patch.newval,      SLE_INT32),
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   701
	SLE_END()
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   702
};
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   703
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   704
static const SaveLoad _glog_grfadd_desc[] = {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   705
	SLE_VAR(LoggedChange, grfadd.grfid,      SLE_UINT32    ),
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   706
	SLE_ARR(LoggedChange, grfadd.md5sum,     SLE_UINT8,  16),
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   707
	SLE_END()
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   708
};
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   709
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   710
static const SaveLoad _glog_grfrem_desc[] = {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   711
	SLE_VAR(LoggedChange, grfrem.grfid,      SLE_UINT32),
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   712
	SLE_END()
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   713
};
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   714
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   715
static const SaveLoad _glog_grfcompat_desc[] = {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   716
	SLE_VAR(LoggedChange, grfcompat.grfid,   SLE_UINT32    ),
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   717
	SLE_ARR(LoggedChange, grfcompat.md5sum,  SLE_UINT8,  16),
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   718
	SLE_END()
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   719
};
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   720
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   721
static const SaveLoad _glog_grfparam_desc[] = {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   722
	SLE_VAR(LoggedChange, grfparam.grfid,    SLE_UINT32),
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   723
	SLE_END()
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   724
};
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   725
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   726
static const SaveLoad _glog_grfmove_desc[] = {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   727
	SLE_VAR(LoggedChange, grfmove.grfid,    SLE_UINT32),
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   728
	SLE_VAR(LoggedChange, grfmove.offset,   SLE_INT32),
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   729
	SLE_END()
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   730
};
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   731
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   732
static const SaveLoad *_glog_desc[] = {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   733
	_glog_mode_desc,
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   734
	_glog_revision_desc,
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   735
	_glog_oldver_desc,
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   736
	_glog_patch_desc,
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   737
	_glog_grfadd_desc,
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   738
	_glog_grfrem_desc,
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   739
	_glog_grfcompat_desc,
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   740
	_glog_grfparam_desc,
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   741
	_glog_grfmove_desc
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   742
};
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   743
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   744
assert_compile(lengthof(_glog_desc) == GLCT_END);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   745
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   746
static void Load_GLOG()
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   747
{
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   748
	assert(_gamelog_action == NULL);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   749
	assert(_gamelog_actions == 0);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   750
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   751
	GamelogActionType at;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   752
	while ((at = (GamelogActionType)SlReadByte()) != GLAT_NONE) {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   753
		_gamelog_action = ReallocT(_gamelog_action, _gamelog_actions + 1);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   754
		LoggedAction *la = &_gamelog_action[_gamelog_actions++];
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   755
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   756
		la->at = at;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   757
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   758
		SlObject(la, _glog_action_desc); // has to be saved after 'DATE'!
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   759
		la->change = NULL;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   760
		la->changes = 0;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   761
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   762
		GamelogChangeType ct;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   763
		while ((ct = (GamelogChangeType)SlReadByte()) != GLCT_NONE) {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   764
			la->change = ReallocT(la->change, la->changes + 1);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   765
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   766
			LoggedChange *lc = &la->change[la->changes++];
10966
3de9939c8a91 (svn r13520) -Fix (r13375): pointer has to be valid before it can be loaded to (SLE_STR)
smatz
parents: 10845
diff changeset
   767
			/* for SLE_STR, pointer has to be valid! so make it NULL */
3de9939c8a91 (svn r13520) -Fix (r13375): pointer has to be valid before it can be loaded to (SLE_STR)
smatz
parents: 10845
diff changeset
   768
			memset(lc, 0, sizeof(*lc));
10824
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   769
			lc->ct = ct;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   770
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   771
			assert((uint)ct < GLCT_END);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   772
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   773
			SlObject(lc, _glog_desc[ct]);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   774
		}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   775
	}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   776
}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   777
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   778
static void Save_GLOG()
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   779
{
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   780
	const LoggedAction *laend = &_gamelog_action[_gamelog_actions];
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   781
	size_t length = 0;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   782
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   783
	for (const LoggedAction *la = _gamelog_action; la != laend; la++) {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   784
		const LoggedChange *lcend = &la->change[la->changes];
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   785
		for (LoggedChange *lc = la->change; lc != lcend; lc++) {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   786
			assert((uint)lc->ct < lengthof(_glog_desc));
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   787
			length += SlCalcObjLength(lc, _glog_desc[lc->ct]) + 1;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   788
		}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   789
		length += 4;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   790
	}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   791
	length++;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   792
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   793
	SlSetLength(length);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   794
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   795
	for (LoggedAction *la = _gamelog_action; la != laend; la++) {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   796
		SlWriteByte(la->at);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   797
		SlObject(la, _glog_action_desc);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   798
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   799
		const LoggedChange *lcend = &la->change[la->changes];
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   800
		for (LoggedChange *lc = la->change; lc != lcend; lc++) {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   801
			SlWriteByte(lc->ct);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   802
			assert((uint)lc->ct < GLCT_END);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   803
			SlObject(lc, _glog_desc[lc->ct]);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   804
		}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   805
		SlWriteByte(GLCT_NONE);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   806
	}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   807
	SlWriteByte(GLAT_NONE);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   808
}
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   809
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   810
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   811
extern const ChunkHandler _gamelog_chunk_handlers[] = {
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   812
	{ 'GLOG', Save_GLOG, Load_GLOG, CH_RIFF | CH_LAST }
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
diff changeset
   813
};