2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2023-06-13 08:33:33 +00:00
|
|
|
/** @file gamelog.cpp Definition of functions used for logging of fundamental changes to the game */
|
2008-06-03 18:35:58 +00:00
|
|
|
|
|
|
|
#include "stdafx.h"
|
2009-01-04 15:32:25 +00:00
|
|
|
#include "saveload/saveload.h"
|
2008-06-03 18:35:58 +00:00
|
|
|
#include "string_func.h"
|
|
|
|
#include "settings_type.h"
|
2009-01-04 15:32:25 +00:00
|
|
|
#include "gamelog_internal.h"
|
2008-06-03 18:35:58 +00:00
|
|
|
#include "console_func.h"
|
|
|
|
#include "debug.h"
|
2023-05-04 13:14:12 +00:00
|
|
|
#include "timer/timer_game_calendar.h"
|
2023-04-24 16:55:40 +00:00
|
|
|
#include "timer/timer_game_tick.h"
|
2008-06-03 18:35:58 +00:00
|
|
|
#include "rev.h"
|
|
|
|
|
2014-04-23 20:13:33 +00:00
|
|
|
#include "safeguards.h"
|
|
|
|
|
2019-01-29 00:56:28 +00:00
|
|
|
extern const SaveLoadVersion SAVEGAME_VERSION; ///< current savegame version
|
2008-06-03 18:35:58 +00:00
|
|
|
|
|
|
|
extern SavegameType _savegame_type; ///< type of savegame we are loading
|
|
|
|
|
2023-05-08 17:01:06 +00:00
|
|
|
extern uint32_t _ttdp_version; ///< version of TTDP savegame (if applicable)
|
2019-01-29 00:56:28 +00:00
|
|
|
extern SaveLoadVersion _sl_version; ///< the major savegame version identifier
|
|
|
|
extern byte _sl_minor_version; ///< the minor savegame version, DO NOT USE!
|
2008-06-03 18:35:58 +00:00
|
|
|
|
2023-05-01 17:14:31 +00:00
|
|
|
Gamelog _gamelog; ///< Gamelog instance
|
2008-06-03 18:35:58 +00:00
|
|
|
|
2023-05-01 17:14:31 +00:00
|
|
|
Gamelog::Gamelog()
|
|
|
|
{
|
|
|
|
this->data = std::make_unique<GamelogInternalData>();
|
|
|
|
this->action_type = GLAT_NONE;
|
|
|
|
this->current_action = nullptr;
|
|
|
|
}
|
2008-06-03 18:35:58 +00:00
|
|
|
|
2023-05-01 17:14:31 +00:00
|
|
|
Gamelog::~Gamelog()
|
|
|
|
{
|
|
|
|
}
|
2008-06-03 18:35:58 +00:00
|
|
|
|
2019-01-27 15:13:28 +00:00
|
|
|
/**
|
|
|
|
* Return the revision string for the current client version, for use in gamelog.
|
|
|
|
*/
|
2023-05-09 21:10:38 +00:00
|
|
|
static std::string GetGamelogRevisionString()
|
2019-01-27 15:13:28 +00:00
|
|
|
{
|
|
|
|
if (IsReleasedVersion()) {
|
|
|
|
return _openttd_revision;
|
|
|
|
}
|
2023-05-09 21:10:38 +00:00
|
|
|
|
|
|
|
/* Prefix character indication revision status */
|
|
|
|
assert(_openttd_revision_modified < 3);
|
|
|
|
return fmt::format("{}{}",
|
|
|
|
"gum"[_openttd_revision_modified], // g = "git", u = "unknown", m = "modified"
|
|
|
|
_openttd_revision_hash);
|
2019-01-27 15:13:28 +00:00
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Stores information about new action, but doesn't allocate it
|
2008-06-03 18:35:58 +00:00
|
|
|
* Action is allocated only when there is at least one change
|
|
|
|
* @param at type of action
|
|
|
|
*/
|
2023-05-01 17:14:31 +00:00
|
|
|
void Gamelog::StartAction(GamelogActionType at)
|
2008-06-03 18:35:58 +00:00
|
|
|
{
|
2023-05-01 17:14:31 +00:00
|
|
|
assert(this->action_type == GLAT_NONE); // do not allow starting new action without stopping the previous first
|
|
|
|
this->action_type = at;
|
2008-06-03 18:35:58 +00:00
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Stops logging of any changes
|
2008-06-03 18:35:58 +00:00
|
|
|
*/
|
2023-05-01 17:14:31 +00:00
|
|
|
void Gamelog::StopAction()
|
2008-06-03 18:35:58 +00:00
|
|
|
{
|
2023-05-01 17:14:31 +00:00
|
|
|
assert(this->action_type != GLAT_NONE); // nobody should try to stop if there is no action in progress
|
2008-06-03 18:35:58 +00:00
|
|
|
|
2023-05-01 17:14:31 +00:00
|
|
|
bool print = this->current_action != nullptr;
|
2008-07-18 12:11:46 +00:00
|
|
|
|
2023-05-01 17:14:31 +00:00
|
|
|
this->current_action = nullptr;
|
|
|
|
this->action_type = GLAT_NONE;
|
2008-06-03 18:35:58 +00:00
|
|
|
|
2023-05-01 17:14:31 +00:00
|
|
|
if (print) this->PrintDebug(5);
|
2008-06-03 18:35:58 +00:00
|
|
|
}
|
|
|
|
|
2023-05-01 17:14:31 +00:00
|
|
|
void Gamelog::StopAnyAction()
|
2020-05-10 14:04:04 +00:00
|
|
|
{
|
2023-05-01 17:14:31 +00:00
|
|
|
if (this->action_type != GLAT_NONE) this->StopAction();
|
2012-02-05 15:51:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resets and frees all memory allocated - used before loading or starting a new game
|
|
|
|
*/
|
2023-05-01 17:14:31 +00:00
|
|
|
void Gamelog::Reset()
|
2012-02-05 15:51:13 +00:00
|
|
|
{
|
2023-05-01 17:14:31 +00:00
|
|
|
assert(this->action_type == GLAT_NONE);
|
|
|
|
this->data->action.clear();
|
|
|
|
this->current_action = nullptr;
|
2008-06-03 18:35:58 +00:00
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
2023-04-29 11:11:45 +00:00
|
|
|
* Adds the GRF ID, checksum and filename if found to the output iterator
|
2023-05-09 21:10:38 +00:00
|
|
|
* @param output_iterator The iterator to add the GRF info to.
|
2014-04-25 15:25:59 +00:00
|
|
|
* @param last The end of the buffer
|
2008-06-03 18:35:58 +00:00
|
|
|
* @param grfid GRF ID
|
2010-10-16 21:20:46 +00:00
|
|
|
* @param md5sum array of md5sum to print, if known
|
|
|
|
* @param gc GrfConfig, if known
|
2008-06-03 18:35:58 +00:00
|
|
|
*/
|
2023-05-18 20:38:56 +00:00
|
|
|
static void AddGrfInfo(std::back_insert_iterator<std::string> &output_iterator, uint32_t grfid, const MD5Hash *md5sum, const GRFConfig *gc)
|
2008-06-03 18:35:58 +00:00
|
|
|
{
|
2019-04-10 21:07:06 +00:00
|
|
|
if (md5sum != nullptr) {
|
2023-05-18 20:41:42 +00:00
|
|
|
fmt::format_to(output_iterator, "GRF ID {:08X}, checksum {}", BSWAP32(grfid), FormatArrayAsHex(*md5sum));
|
2010-10-16 21:20:46 +00:00
|
|
|
} else {
|
2023-05-09 21:10:38 +00:00
|
|
|
fmt::format_to(output_iterator, "GRF ID {:08X}", BSWAP32(grfid));
|
2010-10-16 21:20:46 +00:00
|
|
|
}
|
2008-06-03 18:35:58 +00:00
|
|
|
|
2019-04-10 21:07:06 +00:00
|
|
|
if (gc != nullptr) {
|
2023-05-09 21:10:38 +00:00
|
|
|
fmt::format_to(output_iterator, ", filename: {} (md5sum matches)", gc->filename);
|
2010-10-16 21:20:46 +00:00
|
|
|
} else {
|
2010-10-17 12:12:13 +00:00
|
|
|
gc = FindGRFConfig(grfid, FGCM_ANY);
|
2019-04-10 21:07:06 +00:00
|
|
|
if (gc != nullptr) {
|
2023-05-09 21:10:38 +00:00
|
|
|
fmt::format_to(output_iterator, ", filename: {} (matches GRFID only)", gc->filename);
|
2010-10-16 21:20:46 +00:00
|
|
|
} else {
|
2023-05-09 21:10:38 +00:00
|
|
|
fmt::format_to(output_iterator, ", unknown GRF");
|
2010-10-16 21:20:46 +00:00
|
|
|
}
|
|
|
|
}
|
2008-06-03 18:35:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Text messages for various logged actions */
|
2009-09-20 23:11:01 +00:00
|
|
|
static const char * const la_text[] = {
|
2008-06-03 18:35:58 +00:00
|
|
|
"new game started",
|
|
|
|
"game loaded",
|
|
|
|
"GRF config changed",
|
|
|
|
"cheat was used",
|
2009-02-08 12:25:13 +00:00
|
|
|
"settings changed",
|
2008-07-24 15:19:26 +00:00
|
|
|
"GRF bug triggered",
|
2009-03-30 00:21:43 +00:00
|
|
|
"emergency savegame",
|
2008-06-03 18:35:58 +00:00
|
|
|
};
|
|
|
|
|
2020-12-27 10:44:22 +00:00
|
|
|
static_assert(lengthof(la_text) == GLAT_END);
|
2008-06-03 18:35:58 +00:00
|
|
|
|
2009-09-19 09:51:14 +00:00
|
|
|
/**
|
|
|
|
* Prints active gamelog
|
|
|
|
* @param proc the procedure to draw with
|
|
|
|
*/
|
2023-04-29 11:11:45 +00:00
|
|
|
void Gamelog::Print(std::function<void(const std::string &)> proc)
|
2008-06-03 18:35:58 +00:00
|
|
|
{
|
2010-10-16 21:13:55 +00:00
|
|
|
GrfIDMapping grf_names;
|
2008-06-03 18:35:58 +00:00
|
|
|
|
|
|
|
proc("---- gamelog start ----");
|
|
|
|
|
2023-05-01 17:14:31 +00:00
|
|
|
for (const LoggedAction &la : this->data->action) {
|
2023-05-09 21:10:38 +00:00
|
|
|
assert(la.at < GLAT_END);
|
2008-06-03 18:35:58 +00:00
|
|
|
|
2023-04-29 11:11:45 +00:00
|
|
|
proc(fmt::format("Tick {}: {}", la.tick, la_text[la.at]));
|
2008-06-03 18:35:58 +00:00
|
|
|
|
2023-05-09 21:10:38 +00:00
|
|
|
for (auto &lc : la.change) {
|
2023-04-29 11:11:45 +00:00
|
|
|
std::string message;
|
2023-05-09 21:10:38 +00:00
|
|
|
auto output_iterator = std::back_inserter(message);
|
|
|
|
lc->FormatTo(output_iterator, grf_names, la.at);
|
2008-06-03 18:35:58 +00:00
|
|
|
|
2023-05-09 21:10:38 +00:00
|
|
|
proc(message);
|
|
|
|
}
|
|
|
|
}
|
2008-06-03 18:35:58 +00:00
|
|
|
|
2023-05-09 21:10:38 +00:00
|
|
|
proc("---- gamelog end ----");
|
|
|
|
}
|
2008-06-03 18:35:58 +00:00
|
|
|
|
|
|
|
|
2023-09-16 20:20:53 +00:00
|
|
|
/* virtual */ void LoggedChangeMode::FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &, GamelogActionType)
|
2023-05-09 21:10:38 +00:00
|
|
|
{
|
|
|
|
/* Changing landscape, or going from scenario editor to game or back. */
|
|
|
|
fmt::format_to(output_iterator, "New game mode: {} landscape: {}", this->mode, this->landscape);
|
|
|
|
}
|
2008-06-03 18:35:58 +00:00
|
|
|
|
2023-09-16 20:20:53 +00:00
|
|
|
/* virtual */ void LoggedChangeRevision::FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &, GamelogActionType)
|
2023-05-09 21:10:38 +00:00
|
|
|
{
|
|
|
|
/* The game was loaded in a diffferent version than before. */
|
|
|
|
fmt::format_to(output_iterator, "Revision text changed to {}, savegame version {}, ",
|
|
|
|
this->text, this->slver);
|
2008-06-03 18:35:58 +00:00
|
|
|
|
2023-05-09 21:10:38 +00:00
|
|
|
switch (this->modified) {
|
|
|
|
case 0: fmt::format_to(output_iterator, "not "); break;
|
|
|
|
case 1: fmt::format_to(output_iterator, "maybe "); break;
|
|
|
|
default: break;
|
|
|
|
}
|
2008-06-03 18:35:58 +00:00
|
|
|
|
2023-05-09 21:10:38 +00:00
|
|
|
fmt::format_to(output_iterator, "modified, _openttd_newgrf_version = 0x{:08x}", this->newgrf);
|
|
|
|
}
|
2008-06-03 18:35:58 +00:00
|
|
|
|
2023-09-16 20:20:53 +00:00
|
|
|
/* virtual */ void LoggedChangeOldVersion::FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &, GamelogActionType)
|
2023-05-09 21:10:38 +00:00
|
|
|
{
|
|
|
|
/* The game was loaded from before 0.7.0-beta1. */
|
|
|
|
fmt::format_to(output_iterator, "Conversion from ");
|
|
|
|
switch (this->type) {
|
|
|
|
default: NOT_REACHED();
|
|
|
|
case SGT_OTTD:
|
|
|
|
fmt::format_to(output_iterator, "OTTD savegame without gamelog: version {}, {}",
|
|
|
|
GB(this->version, 8, 16), GB(this->version, 0, 8));
|
|
|
|
break;
|
2008-06-03 18:35:58 +00:00
|
|
|
|
2023-05-09 21:10:38 +00:00
|
|
|
case SGT_TTO:
|
|
|
|
fmt::format_to(output_iterator, "TTO savegame");
|
|
|
|
break;
|
2008-06-03 18:35:58 +00:00
|
|
|
|
2023-05-09 21:10:38 +00:00
|
|
|
case SGT_TTD:
|
|
|
|
fmt::format_to(output_iterator, "TTD savegame");
|
|
|
|
break;
|
2008-07-24 15:19:26 +00:00
|
|
|
|
2023-05-09 21:10:38 +00:00
|
|
|
case SGT_TTDP1:
|
|
|
|
case SGT_TTDP2:
|
|
|
|
fmt::format_to(output_iterator, "TTDP savegame, {} format",
|
|
|
|
this->type == SGT_TTDP1 ? "old" : "new");
|
|
|
|
if (this->version != 0) {
|
|
|
|
fmt::format_to(output_iterator, ", TTDP version {}.{}.{}.{}",
|
|
|
|
GB(this->version, 24, 8), GB(this->version, 20, 4),
|
|
|
|
GB(this->version, 16, 4), GB(this->version, 0, 16));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2023-03-25 19:40:59 +00:00
|
|
|
|
2023-09-16 20:20:53 +00:00
|
|
|
/* virtual */ void LoggedChangeSettingChanged::FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &, GamelogActionType)
|
2023-05-09 21:10:38 +00:00
|
|
|
{
|
|
|
|
/* A setting with the SF_NO_NETWORK flag got changed; these settings usually affect NewGRFs, such as road side or wagon speed limits. */
|
|
|
|
fmt::format_to(output_iterator, "Setting changed: {} : {} -> {}", this->name, this->oldval, this->newval);
|
|
|
|
}
|
2009-03-30 00:21:43 +00:00
|
|
|
|
2023-09-16 20:20:53 +00:00
|
|
|
/* virtual */ void LoggedChangeGRFAdd::FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType)
|
2023-05-09 21:10:38 +00:00
|
|
|
{
|
|
|
|
/* A NewGRF got added to the game, either at the start of the game (never an issue), or later on when it could be an issue. */
|
2023-05-18 20:38:56 +00:00
|
|
|
const GRFConfig *gc = FindGRFConfig(this->grfid, FGCM_EXACT, &this->md5sum);
|
2023-05-09 21:10:38 +00:00
|
|
|
fmt::format_to(output_iterator, "Added NewGRF: ");
|
2023-05-18 20:38:56 +00:00
|
|
|
AddGrfInfo(output_iterator, this->grfid, &this->md5sum, gc);
|
2023-05-16 19:50:41 +00:00
|
|
|
auto gm = grf_names.find(this->grfid);
|
|
|
|
if (gm != grf_names.end() && !gm->second.was_missing) fmt::format_to(output_iterator, ". Gamelog inconsistency: GrfID was already added!");
|
2023-05-09 21:10:38 +00:00
|
|
|
grf_names[this->grfid] = gc;
|
|
|
|
}
|
2008-06-03 18:35:58 +00:00
|
|
|
|
2023-05-09 21:10:38 +00:00
|
|
|
/* virtual */ void LoggedChangeGRFRemoved::FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type)
|
|
|
|
{
|
|
|
|
/* A NewGRF got removed from the game, either manually or by it missing when loading the game. */
|
2023-05-16 19:50:41 +00:00
|
|
|
auto gm = grf_names.find(this->grfid);
|
2024-01-16 21:10:34 +00:00
|
|
|
if (action_type == GLAT_LOAD) {
|
|
|
|
fmt::format_to(output_iterator, "Missing NewGRF: ");
|
|
|
|
} else {
|
|
|
|
fmt::format_to(output_iterator, "Removed NewGRF: ");
|
|
|
|
}
|
2023-05-16 19:50:41 +00:00
|
|
|
AddGrfInfo(output_iterator, this->grfid, nullptr, gm != grf_names.end() ? gm->second.gc : nullptr);
|
|
|
|
if (gm == grf_names.end()) {
|
2023-05-09 21:10:38 +00:00
|
|
|
fmt::format_to(output_iterator, ". Gamelog inconsistency: GrfID was never added!");
|
|
|
|
} else {
|
|
|
|
if (action_type == GLAT_LOAD) {
|
|
|
|
/* Missing grfs on load are not removed from the configuration */
|
|
|
|
gm->second.was_missing = true;
|
|
|
|
} else {
|
2023-05-16 19:50:41 +00:00
|
|
|
grf_names.erase(gm);
|
2008-06-03 18:35:58 +00:00
|
|
|
}
|
|
|
|
}
|
2023-05-09 21:10:38 +00:00
|
|
|
}
|
2008-06-03 18:35:58 +00:00
|
|
|
|
2023-09-16 20:20:53 +00:00
|
|
|
/* virtual */ void LoggedChangeGRFChanged::FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType)
|
2023-05-09 21:10:38 +00:00
|
|
|
{
|
|
|
|
/* Another version of the same NewGRF got loaded. */
|
2023-05-18 20:38:56 +00:00
|
|
|
const GRFConfig *gc = FindGRFConfig(this->grfid, FGCM_EXACT, &this->md5sum);
|
2023-05-09 21:10:38 +00:00
|
|
|
fmt::format_to(output_iterator, "Compatible NewGRF loaded: ");
|
2023-05-18 20:38:56 +00:00
|
|
|
AddGrfInfo(output_iterator, this->grfid, &this->md5sum, gc);
|
2023-05-16 19:50:41 +00:00
|
|
|
if (grf_names.count(this->grfid) == 0) fmt::format_to(output_iterator, ". Gamelog inconsistency: GrfID was never added!");
|
2023-05-09 21:10:38 +00:00
|
|
|
grf_names[this->grfid] = gc;
|
|
|
|
}
|
|
|
|
|
2023-09-16 20:20:53 +00:00
|
|
|
/* virtual */ void LoggedChangeGRFParameterChanged::FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType)
|
2023-05-09 21:10:38 +00:00
|
|
|
{
|
|
|
|
/* A parameter of a NewGRF got changed after the game was started. */
|
2023-05-16 19:50:41 +00:00
|
|
|
auto gm = grf_names.find(this->grfid);
|
2023-05-09 21:10:38 +00:00
|
|
|
fmt::format_to(output_iterator, "GRF parameter changed: ");
|
2023-05-16 19:50:41 +00:00
|
|
|
AddGrfInfo(output_iterator, this->grfid, nullptr, gm != grf_names.end() ? gm->second.gc : nullptr);
|
|
|
|
if (gm == grf_names.end()) fmt::format_to(output_iterator, ". Gamelog inconsistency: GrfID was never added!");
|
2023-05-09 21:10:38 +00:00
|
|
|
}
|
|
|
|
|
2023-09-16 20:20:53 +00:00
|
|
|
/* virtual */ void LoggedChangeGRFMoved::FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType)
|
2023-05-09 21:10:38 +00:00
|
|
|
{
|
|
|
|
/* The order of NewGRFs got changed, which might cause some other NewGRFs to behave differently. */
|
2023-05-16 19:50:41 +00:00
|
|
|
auto gm = grf_names.find(this->grfid);
|
2023-05-09 21:10:38 +00:00
|
|
|
fmt::format_to(output_iterator, "GRF order changed: {:08X} moved {} places {}",
|
|
|
|
BSWAP32(this->grfid), abs(this->offset), this->offset >= 0 ? "down" : "up" );
|
2023-05-16 19:50:41 +00:00
|
|
|
AddGrfInfo(output_iterator, this->grfid, nullptr, gm != grf_names.end() ? gm->second.gc : nullptr);
|
|
|
|
if (gm == grf_names.end()) fmt::format_to(output_iterator, ". Gamelog inconsistency: GrfID was never added!");
|
2008-06-03 18:35:58 +00:00
|
|
|
}
|
|
|
|
|
2023-09-16 20:20:53 +00:00
|
|
|
/* virtual */ void LoggedChangeGRFBug::FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType)
|
2023-05-09 21:10:38 +00:00
|
|
|
{
|
|
|
|
/* A specific bug in a NewGRF, that could cause wide spread problems, has been noted during the execution of the game. */
|
2023-05-16 19:50:41 +00:00
|
|
|
auto gm = grf_names.find(this->grfid);
|
2023-05-09 21:10:38 +00:00
|
|
|
assert(this->bug == GBUG_VEH_LENGTH);
|
|
|
|
|
|
|
|
fmt::format_to(output_iterator, "Rail vehicle changes length outside a depot: GRF ID {:08X}, internal ID 0x{:X}", BSWAP32(this->grfid), this->data);
|
2023-05-16 19:50:41 +00:00
|
|
|
AddGrfInfo(output_iterator, this->grfid, nullptr, gm != grf_names.end() ? gm->second.gc : nullptr);
|
|
|
|
if (gm == grf_names.end()) fmt::format_to(output_iterator, ". Gamelog inconsistency: GrfID was never added!");
|
2023-05-09 21:10:38 +00:00
|
|
|
}
|
|
|
|
|
2023-09-16 20:20:53 +00:00
|
|
|
/* virtual */ void LoggedChangeEmergencySave::FormatTo(std::back_insert_iterator<std::string> &, GrfIDMapping &, GamelogActionType)
|
2023-05-09 21:10:38 +00:00
|
|
|
{
|
|
|
|
/* At one point the savegame was made during the handling of a game crash.
|
|
|
|
* The generic code already mentioned the emergency savegame, and there is no extra information to log. */
|
|
|
|
}
|
2008-06-03 18:35:58 +00:00
|
|
|
|
2011-05-02 17:42:12 +00:00
|
|
|
/** Print the gamelog data to the console. */
|
2023-05-01 17:14:31 +00:00
|
|
|
void Gamelog::PrintConsole()
|
2008-06-03 18:35:58 +00:00
|
|
|
{
|
2023-04-29 11:11:45 +00:00
|
|
|
this->Print([](const std::string &s) {
|
2023-01-27 21:40:30 +00:00
|
|
|
IConsolePrint(CC_WARNING, s);
|
|
|
|
});
|
2008-06-03 18:35:58 +00:00
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Prints gamelog to debug output. Code is executed even when
|
2008-07-18 12:11:46 +00:00
|
|
|
* there will be no output. It is called very seldom, so it
|
|
|
|
* doesn't matter that much. At least it gives more uniform code...
|
|
|
|
* @param level debug level we need to print stuff
|
|
|
|
*/
|
2023-05-01 17:14:31 +00:00
|
|
|
void Gamelog::PrintDebug(int level)
|
2008-06-03 18:35:58 +00:00
|
|
|
{
|
2023-04-29 11:11:45 +00:00
|
|
|
this->Print([level](const std::string &s) {
|
2023-01-27 21:40:30 +00:00
|
|
|
Debug(gamelog, level, "{}", s);
|
|
|
|
});
|
2008-06-03 18:35:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
2023-05-09 21:10:38 +00:00
|
|
|
* Allocates a new LoggedAction if needed, and add the change when action is active.
|
|
|
|
* @param change The actual change.
|
2008-06-03 18:35:58 +00:00
|
|
|
*/
|
2023-05-09 21:10:38 +00:00
|
|
|
void Gamelog::Change(std::unique_ptr<LoggedChange> &&change)
|
2008-06-03 18:35:58 +00:00
|
|
|
{
|
2023-05-01 17:14:31 +00:00
|
|
|
if (this->current_action == nullptr) {
|
2023-05-09 21:10:38 +00:00
|
|
|
if (this->action_type == GLAT_NONE) return;
|
2008-06-03 18:35:58 +00:00
|
|
|
|
2023-05-01 17:14:31 +00:00
|
|
|
this->current_action = &this->data->action.emplace_back();
|
|
|
|
this->current_action->at = this->action_type;
|
|
|
|
this->current_action->tick = TimerGameTick::counter;
|
2008-06-03 18:35:58 +00:00
|
|
|
}
|
|
|
|
|
2023-05-09 21:10:38 +00:00
|
|
|
this->current_action->change.push_back(std::move(change));
|
2008-06-03 18:35:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Logs a emergency savegame
|
2009-03-30 00:21:43 +00:00
|
|
|
*/
|
2023-05-01 17:14:31 +00:00
|
|
|
void Gamelog::Emergency()
|
2009-03-30 00:21:43 +00:00
|
|
|
{
|
2009-09-14 19:30:13 +00:00
|
|
|
/* Terminate any active action */
|
2023-05-01 17:14:31 +00:00
|
|
|
if (this->action_type != GLAT_NONE) this->StopAction();
|
|
|
|
this->StartAction(GLAT_EMERGENCY);
|
2023-05-09 21:10:38 +00:00
|
|
|
this->Change(std::make_unique<LoggedChangeEmergencySave>());
|
2023-05-01 17:14:31 +00:00
|
|
|
this->StopAction();
|
2009-03-30 00:21:43 +00:00
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Finds out if current game is a loaded emergency savegame.
|
2009-03-30 00:21:43 +00:00
|
|
|
*/
|
2023-05-01 17:14:31 +00:00
|
|
|
bool Gamelog::TestEmergency()
|
2009-03-30 00:21:43 +00:00
|
|
|
{
|
2023-05-01 17:14:31 +00:00
|
|
|
for (const LoggedAction &la : this->data->action) {
|
2023-05-09 21:10:38 +00:00
|
|
|
for (const auto &lc : la.change) {
|
|
|
|
if (lc->ct == GLCT_EMERGENCY) return true;
|
2009-03-30 00:21:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-01 17:14:31 +00:00
|
|
|
return false;
|
2009-03-30 00:21:43 +00:00
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Logs a change in game revision
|
2008-06-03 18:35:58 +00:00
|
|
|
*/
|
2023-05-01 17:14:31 +00:00
|
|
|
void Gamelog::Revision()
|
2008-06-03 18:35:58 +00:00
|
|
|
{
|
2023-05-01 17:14:31 +00:00
|
|
|
assert(this->action_type == GLAT_START || this->action_type == GLAT_LOAD);
|
2008-06-03 18:35:58 +00:00
|
|
|
|
2023-05-09 21:10:38 +00:00
|
|
|
this->Change(std::make_unique<LoggedChangeRevision>(
|
2023-06-06 17:30:37 +00:00
|
|
|
GetGamelogRevisionString(), _openttd_newgrf_version, SAVEGAME_VERSION, _openttd_revision_modified));
|
2008-06-03 18:35:58 +00:00
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Logs a change in game mode (scenario editor or game)
|
2008-06-03 18:35:58 +00:00
|
|
|
*/
|
2023-05-01 17:14:31 +00:00
|
|
|
void Gamelog::Mode()
|
2008-06-03 18:35:58 +00:00
|
|
|
{
|
2023-05-01 17:14:31 +00:00
|
|
|
assert(this->action_type == GLAT_START || this->action_type == GLAT_LOAD || this->action_type == GLAT_CHEAT);
|
2008-06-03 18:35:58 +00:00
|
|
|
|
2023-05-09 21:10:38 +00:00
|
|
|
this->Change(std::make_unique<LoggedChangeMode>(_game_mode, _settings_game.game_creation.landscape));
|
2008-06-03 18:35:58 +00:00
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Logs loading from savegame without gamelog
|
2008-06-03 18:35:58 +00:00
|
|
|
*/
|
2023-05-01 17:14:31 +00:00
|
|
|
void Gamelog::Oldver()
|
2008-06-03 18:35:58 +00:00
|
|
|
{
|
2023-05-01 17:14:31 +00:00
|
|
|
assert(this->action_type == GLAT_LOAD);
|
2008-06-03 18:35:58 +00:00
|
|
|
|
2023-05-09 21:10:38 +00:00
|
|
|
this->Change(std::make_unique<LoggedChangeOldVersion>(_savegame_type,
|
|
|
|
(_savegame_type == SGT_OTTD ? ((uint32_t)_sl_version << 8 | _sl_minor_version) : _ttdp_version)));
|
2008-06-03 18:35:58 +00:00
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Logs change in game settings. Only non-networksafe settings are logged
|
2009-02-08 12:25:13 +00:00
|
|
|
* @param name setting name
|
|
|
|
* @param oldval old setting value
|
|
|
|
* @param newval new setting value
|
2008-06-03 18:35:58 +00:00
|
|
|
*/
|
2023-05-08 17:01:06 +00:00
|
|
|
void Gamelog::Setting(const std::string &name, int32_t oldval, int32_t newval)
|
2008-06-03 18:35:58 +00:00
|
|
|
{
|
2023-05-01 17:14:31 +00:00
|
|
|
assert(this->action_type == GLAT_SETTING);
|
2008-06-03 18:35:58 +00:00
|
|
|
|
2023-05-09 21:10:38 +00:00
|
|
|
this->Change(std::make_unique<LoggedChangeSettingChanged>(name, oldval, newval));
|
2008-06-03 18:35:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Finds out if current revision is different than last revision stored in the savegame.
|
2008-06-03 18:35:58 +00:00
|
|
|
* Appends GLCT_REVISION when the revision string changed
|
|
|
|
*/
|
2023-05-01 17:14:31 +00:00
|
|
|
void Gamelog::TestRevision()
|
2008-06-03 18:35:58 +00:00
|
|
|
{
|
2023-05-09 21:10:38 +00:00
|
|
|
const LoggedChangeRevision *rev = nullptr;
|
2008-06-03 18:35:58 +00:00
|
|
|
|
2023-05-01 17:14:31 +00:00
|
|
|
for (const LoggedAction &la : this->data->action) {
|
2023-05-09 21:10:38 +00:00
|
|
|
for (const auto &lc : la.change) {
|
|
|
|
if (lc->ct == GLCT_REVISION) rev = static_cast<const LoggedChangeRevision *>(lc.get());
|
2008-06-03 18:35:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-09 21:10:38 +00:00
|
|
|
if (rev == nullptr || rev->text != GetGamelogRevisionString() ||
|
|
|
|
rev->modified != _openttd_revision_modified ||
|
|
|
|
rev->newgrf != _openttd_newgrf_version) {
|
2023-05-01 17:14:31 +00:00
|
|
|
this->Revision();
|
2008-06-03 18:35:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Finds last stored game mode or landscape.
|
2008-06-03 18:35:58 +00:00
|
|
|
* Any change is logged
|
|
|
|
*/
|
2023-05-01 17:14:31 +00:00
|
|
|
void Gamelog::TestMode()
|
2008-06-03 18:35:58 +00:00
|
|
|
{
|
2023-05-09 21:10:38 +00:00
|
|
|
const LoggedChangeMode *mode = nullptr;
|
2008-06-03 18:35:58 +00:00
|
|
|
|
2023-05-01 17:14:31 +00:00
|
|
|
for (const LoggedAction &la : this->data->action) {
|
2023-05-09 21:10:38 +00:00
|
|
|
for (const auto &lc : la.change) {
|
|
|
|
if (lc->ct == GLCT_MODE) mode = static_cast<const LoggedChangeMode *>(lc.get());
|
2008-06-03 18:35:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-09 21:10:38 +00:00
|
|
|
if (mode == nullptr || mode->mode != _game_mode || mode->landscape != _settings_game.game_creation.landscape) this->Mode();
|
2008-06-03 18:35:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Logs triggered GRF bug.
|
2008-07-24 15:19:26 +00:00
|
|
|
* @param grfid ID of problematic GRF
|
|
|
|
* @param bug type of bug, @see enum GRFBugs
|
|
|
|
* @param data additional data
|
|
|
|
*/
|
2023-05-08 17:01:06 +00:00
|
|
|
void Gamelog::GRFBug(uint32_t grfid, byte bug, uint64_t data)
|
2008-07-24 15:19:26 +00:00
|
|
|
{
|
2023-05-01 17:14:31 +00:00
|
|
|
assert(this->action_type == GLAT_GRFBUG);
|
2008-07-24 15:19:26 +00:00
|
|
|
|
2023-05-09 21:10:38 +00:00
|
|
|
this->Change(std::make_unique<LoggedChangeGRFBug>(data, grfid, bug));
|
2008-07-24 15:19:26 +00:00
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Logs GRF bug - rail vehicle has different length after reversing.
|
2008-07-24 15:19:26 +00:00
|
|
|
* Ensures this is logged only once for each GRF and engine type
|
|
|
|
* This check takes some time, but it is called pretty seldom, so it
|
|
|
|
* doesn't matter that much (ideally it shouldn't be called at all).
|
2009-09-19 09:51:14 +00:00
|
|
|
* @param grfid the broken NewGRF
|
|
|
|
* @param internal_id the internal ID of whatever's broken in the NewGRF
|
2008-07-24 15:19:26 +00:00
|
|
|
* @return true iff a unique record was done
|
|
|
|
*/
|
2023-05-08 17:01:06 +00:00
|
|
|
bool Gamelog::GRFBugReverse(uint32_t grfid, uint16_t internal_id)
|
2023-05-01 17:14:31 +00:00
|
|
|
{
|
|
|
|
for (const LoggedAction &la : this->data->action) {
|
2023-05-09 21:10:38 +00:00
|
|
|
for (const auto &lc : la.change) {
|
|
|
|
if (lc->ct == GLCT_GRFBUG) {
|
|
|
|
LoggedChangeGRFBug *bug = static_cast<LoggedChangeGRFBug *>(lc.get());
|
|
|
|
if (bug->grfid == grfid && bug->bug == GBUG_VEH_LENGTH && bug->data == internal_id) {
|
|
|
|
return false;
|
|
|
|
}
|
2008-07-24 15:19:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-01 17:14:31 +00:00
|
|
|
this->StartAction(GLAT_GRFBUG);
|
|
|
|
this->GRFBug(grfid, GBUG_VEH_LENGTH, internal_id);
|
|
|
|
this->StopAction();
|
2008-07-24 15:19:26 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Decides if GRF should be logged
|
2008-06-03 18:35:58 +00:00
|
|
|
* @param g grf to determine
|
|
|
|
* @return true iff GRF is not static and is loaded
|
|
|
|
*/
|
|
|
|
static inline bool IsLoggableGrfConfig(const GRFConfig *g)
|
|
|
|
{
|
|
|
|
return !HasBit(g->flags, GCF_STATIC) && g->status != GCS_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Logs removal of a GRF
|
2008-06-03 18:35:58 +00:00
|
|
|
* @param grfid ID of removed GRF
|
|
|
|
*/
|
2023-05-08 17:01:06 +00:00
|
|
|
void Gamelog::GRFRemove(uint32_t grfid)
|
2008-06-03 18:35:58 +00:00
|
|
|
{
|
2023-05-01 17:14:31 +00:00
|
|
|
assert(this->action_type == GLAT_LOAD || this->action_type == GLAT_GRF);
|
2008-06-03 18:35:58 +00:00
|
|
|
|
2023-05-09 21:10:38 +00:00
|
|
|
this->Change(std::make_unique<LoggedChangeGRFRemoved>(grfid));
|
2008-06-03 18:35:58 +00:00
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Logs adding of a GRF
|
2008-06-03 18:35:58 +00:00
|
|
|
* @param newg added GRF
|
|
|
|
*/
|
2023-05-01 17:14:31 +00:00
|
|
|
void Gamelog::GRFAdd(const GRFConfig *newg)
|
2008-06-03 18:35:58 +00:00
|
|
|
{
|
2023-05-01 17:14:31 +00:00
|
|
|
assert(this->action_type == GLAT_LOAD || this->action_type == GLAT_START || this->action_type == GLAT_GRF);
|
2008-06-03 18:35:58 +00:00
|
|
|
|
|
|
|
if (!IsLoggableGrfConfig(newg)) return;
|
|
|
|
|
2023-05-09 21:10:38 +00:00
|
|
|
this->Change(std::make_unique<LoggedChangeGRFAdd>(newg->ident));
|
2008-06-03 18:35:58 +00:00
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Logs loading compatible GRF
|
2008-06-03 18:35:58 +00:00
|
|
|
* (the same ID, but different MD5 hash)
|
|
|
|
* @param newg new (updated) GRF
|
|
|
|
*/
|
2023-05-01 17:14:31 +00:00
|
|
|
void Gamelog::GRFCompatible(const GRFIdentifier *newg)
|
2008-06-03 18:35:58 +00:00
|
|
|
{
|
2023-05-01 17:14:31 +00:00
|
|
|
assert(this->action_type == GLAT_LOAD || this->action_type == GLAT_GRF);
|
2008-06-03 18:35:58 +00:00
|
|
|
|
2023-05-09 21:10:38 +00:00
|
|
|
this->Change(std::make_unique<LoggedChangeGRFChanged>(*newg));
|
2008-06-03 18:35:58 +00:00
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Logs changing GRF order
|
2008-06-03 18:35:58 +00:00
|
|
|
* @param grfid GRF that is moved
|
|
|
|
* @param offset how far it is moved, positive = moved down
|
|
|
|
*/
|
2023-05-08 17:01:06 +00:00
|
|
|
void Gamelog::GRFMove(uint32_t grfid, int32_t offset)
|
2008-06-03 18:35:58 +00:00
|
|
|
{
|
2023-05-01 17:14:31 +00:00
|
|
|
assert(this->action_type == GLAT_GRF);
|
2008-06-03 18:35:58 +00:00
|
|
|
|
2023-05-09 21:10:38 +00:00
|
|
|
this->Change(std::make_unique<LoggedChangeGRFMoved>(grfid, offset));
|
2008-06-03 18:35:58 +00:00
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Logs change in GRF parameters.
|
2008-06-03 18:35:58 +00:00
|
|
|
* Details about parameters changed are not stored
|
|
|
|
* @param grfid ID of GRF to store
|
|
|
|
*/
|
2023-05-08 17:01:06 +00:00
|
|
|
void Gamelog::GRFParameters(uint32_t grfid)
|
2008-06-03 18:35:58 +00:00
|
|
|
{
|
2023-05-01 17:14:31 +00:00
|
|
|
assert(this->action_type == GLAT_GRF);
|
2008-06-03 18:35:58 +00:00
|
|
|
|
2023-05-09 21:10:38 +00:00
|
|
|
this->Change(std::make_unique<LoggedChangeGRFParameterChanged>(grfid));
|
2008-06-03 18:35:58 +00:00
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Logs adding of list of GRFs.
|
2008-06-03 18:35:58 +00:00
|
|
|
* Useful when old savegame is loaded or when new game is started
|
|
|
|
* @param newg head of GRF linked list
|
|
|
|
*/
|
2023-05-01 17:14:31 +00:00
|
|
|
void Gamelog::GRFAddList(const GRFConfig *newg)
|
2008-06-03 18:35:58 +00:00
|
|
|
{
|
2023-05-01 17:14:31 +00:00
|
|
|
assert(this->action_type == GLAT_START || this->action_type == GLAT_LOAD);
|
2008-06-03 18:35:58 +00:00
|
|
|
|
2019-04-10 21:07:06 +00:00
|
|
|
for (; newg != nullptr; newg = newg->next) {
|
2023-05-01 17:14:31 +00:00
|
|
|
this->GRFAdd(newg);
|
2008-06-03 18:35:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Generates GRFList
|
2008-06-03 18:35:58 +00:00
|
|
|
* @param grfc head of GRF linked list
|
|
|
|
*/
|
2023-01-20 16:00:18 +00:00
|
|
|
static std::vector<const GRFConfig *> GenerateGRFList(const GRFConfig *grfc)
|
2008-06-03 18:35:58 +00:00
|
|
|
{
|
2023-01-20 16:00:18 +00:00
|
|
|
std::vector<const GRFConfig *> list;
|
2019-04-10 21:07:06 +00:00
|
|
|
for (const GRFConfig *g = grfc; g != nullptr; g = g->next) {
|
2023-01-20 16:00:18 +00:00
|
|
|
if (IsLoggableGrfConfig(g)) list.push_back(g);
|
2008-06-03 18:35:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Compares two NewGRF lists and logs any change
|
2008-06-03 18:35:58 +00:00
|
|
|
* @param oldc original GRF list
|
|
|
|
* @param newc new GRF list
|
|
|
|
*/
|
2023-05-01 17:14:31 +00:00
|
|
|
void Gamelog::GRFUpdate(const GRFConfig *oldc, const GRFConfig *newc)
|
2008-06-03 18:35:58 +00:00
|
|
|
{
|
2023-01-20 16:00:18 +00:00
|
|
|
std::vector<const GRFConfig *> ol = GenerateGRFList(oldc);
|
|
|
|
std::vector<const GRFConfig *> nl = GenerateGRFList(newc);
|
2008-06-03 18:35:58 +00:00
|
|
|
|
|
|
|
uint o = 0, n = 0;
|
|
|
|
|
2023-01-20 16:00:18 +00:00
|
|
|
while (o < ol.size() && n < nl.size()) {
|
|
|
|
const GRFConfig *og = ol[o];
|
|
|
|
const GRFConfig *ng = nl[n];
|
2008-06-03 18:35:58 +00:00
|
|
|
|
2010-02-25 20:05:31 +00:00
|
|
|
if (og->ident.grfid != ng->ident.grfid) {
|
2008-06-03 18:35:58 +00:00
|
|
|
uint oi, ni;
|
2023-01-20 16:00:18 +00:00
|
|
|
for (oi = 0; oi < ol.size(); oi++) {
|
|
|
|
if (ol[oi]->ident.grfid == nl[n]->ident.grfid) break;
|
2008-06-03 18:35:58 +00:00
|
|
|
}
|
|
|
|
if (oi < o) {
|
|
|
|
/* GRF was moved, this change has been logged already */
|
|
|
|
n++;
|
|
|
|
continue;
|
|
|
|
}
|
2023-01-20 16:00:18 +00:00
|
|
|
if (oi == ol.size()) {
|
2008-06-03 18:35:58 +00:00
|
|
|
/* GRF couldn't be found in the OLD list, GRF was ADDED */
|
2023-01-20 16:00:18 +00:00
|
|
|
this->GRFAdd(nl[n++]);
|
2008-06-03 18:35:58 +00:00
|
|
|
continue;
|
|
|
|
}
|
2023-01-20 16:00:18 +00:00
|
|
|
for (ni = 0; ni < nl.size(); ni++) {
|
|
|
|
if (nl[ni]->ident.grfid == ol[o]->ident.grfid) break;
|
2008-06-03 18:35:58 +00:00
|
|
|
}
|
|
|
|
if (ni < n) {
|
|
|
|
/* GRF was moved, this change has been logged already */
|
|
|
|
o++;
|
|
|
|
continue;
|
|
|
|
}
|
2023-01-20 16:00:18 +00:00
|
|
|
if (ni == nl.size()) {
|
2008-06-03 18:35:58 +00:00
|
|
|
/* GRF couldn't be found in the NEW list, GRF was REMOVED */
|
2023-01-20 16:00:18 +00:00
|
|
|
this->GRFRemove(ol[o++]->ident.grfid);
|
2008-06-03 18:35:58 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* o < oi < ol->n
|
|
|
|
* n < ni < nl->n */
|
2023-01-20 16:00:18 +00:00
|
|
|
assert(ni > n && ni < nl.size());
|
|
|
|
assert(oi > o && oi < ol.size());
|
2008-06-03 18:35:58 +00:00
|
|
|
|
|
|
|
ni -= n; // number of GRFs it was moved downwards
|
|
|
|
oi -= o; // number of GRFs it was moved upwards
|
|
|
|
|
|
|
|
if (ni >= oi) { // prefer the one that is moved further
|
|
|
|
/* GRF was moved down */
|
2023-01-20 16:00:18 +00:00
|
|
|
this->GRFMove(ol[o++]->ident.grfid, ni);
|
2008-06-03 18:35:58 +00:00
|
|
|
} else {
|
2023-01-20 16:00:18 +00:00
|
|
|
this->GRFMove(nl[n++]->ident.grfid, -(int)oi);
|
2008-06-03 18:35:58 +00:00
|
|
|
}
|
|
|
|
} else {
|
2023-05-18 20:38:56 +00:00
|
|
|
if (og->ident.md5sum != ng->ident.md5sum) {
|
2008-06-03 18:35:58 +00:00
|
|
|
/* md5sum changed, probably loading 'compatible' GRF */
|
2023-01-20 16:00:18 +00:00
|
|
|
this->GRFCompatible(&nl[n]->ident);
|
2008-06-03 18:35:58 +00:00
|
|
|
}
|
|
|
|
|
2023-05-18 18:56:24 +00:00
|
|
|
if (og->num_params != ng->num_params || og->param == ng->param) {
|
2023-01-20 16:00:18 +00:00
|
|
|
this->GRFParameters(ol[o]->ident.grfid);
|
2008-06-03 18:35:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
o++;
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-20 16:00:18 +00:00
|
|
|
while (o < ol.size()) this->GRFRemove(ol[o++]->ident.grfid); // remaining GRFs were removed ...
|
|
|
|
while (n < nl.size()) this->GRFAdd (nl[n++]); // ... or added
|
2008-06-03 18:35:58 +00:00
|
|
|
}
|
2011-10-30 13:47:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get some basic information from the given gamelog.
|
2018-10-28 02:17:36 +00:00
|
|
|
* @param[out] last_ottd_rev OpenTTD NewGRF version from the binary that saved the savegame last.
|
|
|
|
* @param[out] ever_modified Max value of 'modified' from all binaries that ever saved this savegame.
|
|
|
|
* @param[out] removed_newgrfs Set to true if any NewGRFs have been removed.
|
2011-10-30 13:47:45 +00:00
|
|
|
*/
|
2023-05-08 17:01:06 +00:00
|
|
|
void Gamelog::Info(uint32_t *last_ottd_rev, byte *ever_modified, bool *removed_newgrfs)
|
2011-10-30 13:47:45 +00:00
|
|
|
{
|
2023-05-01 17:14:31 +00:00
|
|
|
for (const LoggedAction &la : this->data->action) {
|
2023-05-09 21:10:38 +00:00
|
|
|
for (const auto &lc : la.change) {
|
|
|
|
switch (lc->ct) {
|
2011-10-30 13:47:45 +00:00
|
|
|
default: break;
|
|
|
|
|
2023-05-09 21:10:38 +00:00
|
|
|
case GLCT_REVISION: {
|
|
|
|
const LoggedChangeRevision *rev = static_cast<const LoggedChangeRevision *>(lc.get());
|
|
|
|
*last_ottd_rev = rev->newgrf;
|
|
|
|
*ever_modified = std::max(*ever_modified, rev->modified);
|
2011-10-30 13:47:45 +00:00
|
|
|
break;
|
2023-05-09 21:10:38 +00:00
|
|
|
}
|
2011-10-30 13:47:45 +00:00
|
|
|
|
|
|
|
case GLCT_GRFREM:
|
|
|
|
*removed_newgrfs = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-05-01 17:14:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Try to find the overridden GRF identifier of the given GRF.
|
|
|
|
* @param c the GRF to get the 'previous' version of.
|
|
|
|
* @return the GRF identifier or \a c if none could be found.
|
|
|
|
*/
|
|
|
|
const GRFIdentifier *Gamelog::GetOverriddenIdentifier(const GRFConfig *c)
|
|
|
|
{
|
|
|
|
assert(c != nullptr);
|
|
|
|
const LoggedAction &la = this->data->action.back();
|
|
|
|
if (la.at != GLAT_LOAD) return &c->ident;
|
|
|
|
|
2023-05-09 21:10:38 +00:00
|
|
|
for (const auto &lc : la.change) {
|
|
|
|
if (lc->ct != GLCT_GRFCOMPAT) continue;
|
|
|
|
|
|
|
|
const LoggedChangeGRFChanged *grf = static_cast<const LoggedChangeGRFChanged *>(lc.get());
|
|
|
|
if (grf->grfid == c->ident.grfid) return grf;
|
2023-05-01 17:14:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &c->ident;
|
|
|
|
}
|