Changeset - r27412:e80c11e22792
[Not reviewed]
master
0 2 0
Rubidium - 17 months ago 2023-05-19 12:35:10
rubidium@openttd.org
Codechange: use GetString + StrMakeValid to pass string without colours/font sizes to Debug
2 files changed with 5 insertions and 12 deletions:
0 comments (0 inline, 0 general)
src/newgrf_commons.cpp
Show inline comments
 
@@ -6,48 +6,49 @@
 
 */
 

	
 
/**
 
 * @file newgrf_commons.cpp Implementation of the class %OverrideManagerBase
 
 * and its descendance, present and future.
 
 */
 

	
 
#include "stdafx.h"
 
#include "debug.h"
 
#include "landscape.h"
 
#include "house.h"
 
#include "industrytype.h"
 
#include "newgrf_config.h"
 
#include "clear_map.h"
 
#include "station_map.h"
 
#include "tree_map.h"
 
#include "tunnelbridge_map.h"
 
#include "newgrf_object.h"
 
#include "genworld.h"
 
#include "newgrf_spritegroup.h"
 
#include "newgrf_text.h"
 
#include "company_base.h"
 
#include "error.h"
 
#include "strings_func.h"
 
#include "string_func.h"
 

	
 
#include "table/strings.h"
 

	
 
#include "safeguards.h"
 

	
 
/**
 
 * Constructor of generic class
 
 * @param offset end of original data for this entity. i.e: houses = 110
 
 * @param maximum of entities this manager can deal with. i.e: houses = 512
 
 * @param invalid is the ID used to identify an invalid entity id
 
 */
 
OverrideManagerBase::OverrideManagerBase(uint16 offset, uint16 maximum, uint16 invalid)
 
{
 
	this->max_offset = offset;
 
	this->max_entities = maximum;
 
	this->invalid_id = invalid;
 

	
 
	this->mappings.resize(this->max_entities);
 
	this->entity_overrides.resize(this->max_offset);
 
	std::fill(this->entity_overrides.begin(), this->entity_overrides.end(), this->invalid_id);
 
	this->grfid_overrides.resize(this->max_offset);
 
}
 

	
 
/**
 
@@ -487,58 +488,54 @@ CommandCost GetErrorMessageFromLocationC
 

	
 
	return res;
 
}
 

	
 
/**
 
 * Record that a NewGRF returned an unknown/invalid callback result.
 
 * Also show an error to the user.
 
 * @param grfid ID of the NewGRF causing the problem.
 
 * @param cbid Callback causing the problem.
 
 * @param cb_res Invalid result returned by the callback.
 
 */
 
void ErrorUnknownCallbackResult(uint32 grfid, uint16 cbid, uint16 cb_res)
 
{
 
	GRFConfig *grfconfig = GetGRFConfig(grfid);
 

	
 
	if (!HasBit(grfconfig->grf_bugs, GBUG_UNKNOWN_CB_RESULT)) {
 
		SetBit(grfconfig->grf_bugs, GBUG_UNKNOWN_CB_RESULT);
 
		SetDParamStr(0, grfconfig->GetName());
 
		SetDParam(1, cbid);
 
		SetDParam(2, cb_res);
 
		ShowErrorMessage(STR_NEWGRF_BUGGY, STR_NEWGRF_BUGGY_UNKNOWN_CALLBACK_RESULT, WL_CRITICAL);
 
	}
 

	
 
	/* debug output */
 
	char buffer[512];
 

	
 
	SetDParamStr(0, grfconfig->GetName());
 
	GetString(buffer, STR_NEWGRF_BUGGY, lastof(buffer));
 
	Debug(grf, 0, "{}", buffer + 3);
 
	Debug(grf, 0, "{}", StrMakeValid(GetString(STR_NEWGRF_BUGGY)));
 

	
 
	SetDParam(1, cbid);
 
	SetDParam(2, cb_res);
 
	GetString(buffer, STR_NEWGRF_BUGGY_UNKNOWN_CALLBACK_RESULT, lastof(buffer));
 
	Debug(grf, 0, "{}", buffer + 3);
 
	Debug(grf, 0, "{}", StrMakeValid(GetString(STR_NEWGRF_BUGGY_UNKNOWN_CALLBACK_RESULT)));
 
}
 

	
 
/**
 
 * Converts a callback result into a boolean.
 
 * For grf version < 8 the result is checked for zero or non-zero.
 
 * For grf version >= 8 the callback result must be 0 or 1.
 
 * @param grffile NewGRF returning the value.
 
 * @param cbid Callback returning the value.
 
 * @param cb_res Callback result.
 
 * @return Boolean value. True if cb_res != 0.
 
 */
 
bool ConvertBooleanCallback(const GRFFile *grffile, uint16 cbid, uint16 cb_res)
 
{
 
	assert(cb_res != CALLBACK_FAILED); // We do not know what to return
 

	
 
	if (grffile->grf_version < 8) return cb_res != 0;
 

	
 
	if (cb_res > 1) ErrorUnknownCallbackResult(grffile->grfid, cbid, cb_res);
 
	return cb_res != 0;
 
}
 

	
 
/**
 
 * Converts a callback result into a boolean.
 
 * For grf version < 8 the first 8 bit of the result are checked for zero or non-zero.
src/vehicle.cpp
Show inline comments
 
@@ -294,57 +294,53 @@ uint Vehicle::Crash(bool flooded)
 
 * Displays a "NewGrf Bug" error message for a engine, and pauses the game if not networking.
 
 * @param engine The engine that caused the problem
 
 * @param part1  Part 1 of the error message, taking the grfname as parameter 1
 
 * @param part2  Part 2 of the error message, taking the engine as parameter 2
 
 * @param bug_type Flag to check and set in grfconfig
 
 * @param critical Shall the "OpenTTD might crash"-message be shown when the player tries to unpause?
 
 */
 
void ShowNewGrfVehicleError(EngineID engine, StringID part1, StringID part2, GRFBugs bug_type, bool critical)
 
{
 
	const Engine *e = Engine::Get(engine);
 
	GRFConfig *grfconfig = GetGRFConfig(e->GetGRFID());
 

	
 
	/* Missing GRF. Nothing useful can be done in this situation. */
 
	if (grfconfig == nullptr) return;
 

	
 
	if (!HasBit(grfconfig->grf_bugs, bug_type)) {
 
		SetBit(grfconfig->grf_bugs, bug_type);
 
		SetDParamStr(0, grfconfig->GetName());
 
		SetDParam(1, engine);
 
		ShowErrorMessage(part1, part2, WL_CRITICAL);
 
		if (!_networking) Command<CMD_PAUSE>::Do(DC_EXEC, critical ? PM_PAUSED_ERROR : PM_PAUSED_NORMAL, true);
 
	}
 

	
 
	/* debug output */
 
	char buffer[512];
 

	
 
	SetDParamStr(0, grfconfig->GetName());
 
	GetString(buffer, part1, lastof(buffer));
 
	Debug(grf, 0, "{}", buffer + 3);
 
	Debug(grf, 0, "{}", StrMakeValid(GetString(part1)));
 

	
 
	SetDParam(1, engine);
 
	GetString(buffer, part2, lastof(buffer));
 
	Debug(grf, 0, "{}", buffer + 3);
 
	Debug(grf, 0, "{}", StrMakeValid(GetString(part2)));
 
}
 

	
 
/**
 
 * Logs a bug in GRF and shows a warning message if this
 
 * is for the first time this happened.
 
 * @param u first vehicle of chain
 
 */
 
void VehicleLengthChanged(const Vehicle *u)
 
{
 
	/* show a warning once for each engine in whole game and once for each GRF after each game load */
 
	const Engine *engine = u->GetEngine();
 
	uint32 grfid = engine->grf_prop.grffile->grfid;
 
	GRFConfig *grfconfig = GetGRFConfig(grfid);
 
	if (_gamelog.GRFBugReverse(grfid, engine->grf_prop.local_id) || !HasBit(grfconfig->grf_bugs, GBUG_VEH_LENGTH)) {
 
		ShowNewGrfVehicleError(u->engine_type, STR_NEWGRF_BROKEN, STR_NEWGRF_BROKEN_VEHICLE_LENGTH, GBUG_VEH_LENGTH, true);
 
	}
 
}
 

	
 
/**
 
 * Vehicle constructor.
 
 * @param type Type of the new vehicle.
 
 */
 
Vehicle::Vehicle(VehicleType type)
 
{
0 comments (0 inline, 0 general)