Codechange: use string/fmt instead of printf for grfmsg

pull/544/head
Rubidium 1 year ago committed by rubidium42
parent dfe52da1ea
commit 7088f5b7c7

File diff suppressed because it is too large Load Diff

@ -201,7 +201,8 @@ void ReloadNewGRFData(); // in saveload/afterload.cpp
void ResetNewGRFData();
void ResetPersistentNewGRFData();
void CDECL grfmsg(int severity, const char *str, ...) WARN_FORMAT(2, 3);
void GrfMsgI(int severity, const std::string &msg);
#define GrfMsg(severity, format_string, ...) GrfMsgI(severity, fmt::format(FMT_STRING(format_string), ## __VA_ARGS__))
bool GetGlobalVariable(byte param, uint32 *value, const GRFFile *grffile);

@ -176,7 +176,7 @@ void AirportOverrideManager::SetEntitySpec(AirportSpec *as)
byte airport_id = this->AddEntityID(as->grf_prop.local_id, as->grf_prop.grffile->grfid, as->grf_prop.subst_id);
if (airport_id == this->invalid_id) {
grfmsg(1, "Airport.SetEntitySpec: Too many airports allocated. Ignoring.");
GrfMsg(1, "Airport.SetEntitySpec: Too many airports allocated. Ignoring.");
return;
}

@ -69,7 +69,7 @@ void AirportTileOverrideManager::SetEntitySpec(const AirportTileSpec *airpts)
StationGfx airpt_id = this->AddEntityID(airpts->grf_prop.local_id, airpts->grf_prop.grffile->grfid, airpts->grf_prop.subst_id);
if (airpt_id == this->invalid_id) {
grfmsg(1, "AirportTile.SetEntitySpec: Too many airport tiles allocated. Ignoring.");
GrfMsg(1, "AirportTile.SetEntitySpec: Too many airport tiles allocated. Ignoring.");
return;
}

@ -63,7 +63,7 @@ DEFINE_NEWGRF_CLASS_METHOD(Tid)::Allocate(uint32 global_id)
}
}
grfmsg(2, "ClassAllocate: already allocated %d classes, using default", Tmax);
GrfMsg(2, "ClassAllocate: already allocated {} classes, using default", Tmax);
return (Tid)0;
}

@ -160,7 +160,7 @@ void HouseOverrideManager::SetEntitySpec(const HouseSpec *hs)
HouseID house_id = this->AddEntityID(hs->grf_prop.local_id, hs->grf_prop.grffile->grfid, hs->grf_prop.subst_id);
if (house_id == this->invalid_id) {
grfmsg(1, "House.SetEntitySpec: Too many houses allocated. Ignoring.");
GrfMsg(1, "House.SetEntitySpec: Too many houses allocated. Ignoring.");
return;
}
@ -254,7 +254,7 @@ void IndustryOverrideManager::SetEntitySpec(IndustrySpec *inds)
}
if (ind_id == this->invalid_id) {
grfmsg(1, "Industry.SetEntitySpec: Too many industries allocated. Ignoring.");
GrfMsg(1, "Industry.SetEntitySpec: Too many industries allocated. Ignoring.");
return;
}
@ -269,7 +269,7 @@ void IndustryTileOverrideManager::SetEntitySpec(const IndustryTileSpec *its)
IndustryGfx indt_id = this->AddEntityID(its->grf_prop.local_id, its->grf_prop.grffile->grfid, its->grf_prop.subst_id);
if (indt_id == this->invalid_id) {
grfmsg(1, "IndustryTile.SetEntitySpec: Too many industry tiles allocated. Ignoring.");
GrfMsg(1, "IndustryTile.SetEntitySpec: Too many industry tiles allocated. Ignoring.");
return;
}
@ -308,7 +308,7 @@ void ObjectOverrideManager::SetEntitySpec(ObjectSpec *spec)
}
if (type == this->invalid_id) {
grfmsg(1, "Object.SetEntitySpec: Too many objects allocated. Ignoring.");
GrfMsg(1, "Object.SetEntitySpec: Too many objects allocated. Ignoring.");
return;
}

@ -55,7 +55,7 @@ void SetCustomEngineSprites(EngineID engine, byte cargo, const SpriteGroup *grou
assert(cargo < lengthof(e->grf_prop.spritegroup));
if (e->grf_prop.spritegroup[cargo] != nullptr) {
grfmsg(6, "SetCustomEngineSprites: engine %d cargo %d already has group -- replacing", engine, cargo);
GrfMsg(6, "SetCustomEngineSprites: engine {} cargo {} already has group -- replacing", engine, cargo);
}
e->grf_prop.spritegroup[cargo] = group;
}

@ -109,7 +109,7 @@ void ResetGenericCallbacks()
void AddGenericCallback(uint8 feature, const GRFFile *file, const SpriteGroup *group)
{
if (feature >= lengthof(_gcl)) {
grfmsg(5, "AddGenericCallback: Unsupported feature 0x%02X", feature);
GrfMsg(5, "AddGenericCallback: Unsupported feature {:#02X}", feature);
return;
}

@ -12,8 +12,8 @@
#include "company_func.h"
#include "debug.h"
#include "genworld.h"
#include "newgrf_class_func.h"
#include "newgrf_object.h"
#include "newgrf_class_func.h"
#include "newgrf_sound.h"
#include "object_base.h"
#include "object_map.h"

@ -137,7 +137,7 @@ struct UnmappedChoiceList {
if (this->strings.find(0) == this->strings.end()) {
/* In case of a (broken) NewGRF without a default,
* assume an empty string. */
grfmsg(1, "choice list misses default value");
GrfMsg(1, "choice list misses default value");
this->strings[0] = std::stringstream();
}
@ -211,7 +211,7 @@ struct UnmappedChoiceList {
int idx = (this->type == SCC_GENDER_LIST ? lm->GetReverseMapping(i, true) : i + 1);
const auto &str = this->strings[this->strings.find(idx) != this->strings.end() ? idx : 0].str();
size_t len = str.size() + 1;
if (len > 0xFF) grfmsg(1, "choice list string is too long");
if (len > 0xFF) GrfMsg(1, "choice list string is too long");
*d++ = GB(len, 0, 8);
}
@ -290,7 +290,7 @@ std::string TranslateTTDPatchCodes(uint32 grfid, uint8 language_id, bool allow_n
if (allow_newlines) {
*d++ = 0x0A;
} else {
grfmsg(1, "Detected newline in string that does not allow one");
GrfMsg(1, "Detected newline in string that does not allow one");
}
break;
case 0x0E: Utf8Encode(d, SCC_TINYFONT); break;
@ -392,12 +392,12 @@ std::string TranslateTTDPatchCodes(uint32 grfid, uint8 language_id, bool allow_n
if (str[0] == '\0') goto string_end;
if (mapping == nullptr) {
if (code == 0x10) src++; // Skip the index
grfmsg(1, "choice list %s marker found when not expected", code == 0x10 ? "next" : "default");
GrfMsg(1, "choice list {} marker found when not expected", code == 0x10 ? "next" : "default");
break;
} else {
int index = (code == 0x10 ? *src++ : 0);
if (mapping->strings.find(index) != mapping->strings.end()) {
grfmsg(1, "duplicate choice list string, ignoring");
GrfMsg(1, "duplicate choice list string, ignoring");
} else {
d = std::ostreambuf_iterator<char>(mapping->strings[index]);
}
@ -406,7 +406,7 @@ std::string TranslateTTDPatchCodes(uint32 grfid, uint8 language_id, bool allow_n
case 0x12:
if (mapping == nullptr) {
grfmsg(1, "choice list end marker found when not expected");
GrfMsg(1, "choice list end marker found when not expected");
} else {
/* Now we can start flushing everything and clean everything up. */
mapping->Flush(LanguageMap::GetLanguageMap(grfid, language_id), dest);
@ -422,7 +422,7 @@ std::string TranslateTTDPatchCodes(uint32 grfid, uint8 language_id, bool allow_n
case 0x15:
if (src[0] == '\0') goto string_end;
if (mapping != nullptr) {
grfmsg(1, "choice lists can't be stacked, it's going to get messy now...");
GrfMsg(1, "choice lists can't be stacked, it's going to get messy now...");
if (code != 0x14) src++;
} else {
static const StringControlCode mp[] = { SCC_GENDER_LIST, SCC_SWITCH_CASE, SCC_PLURAL_LIST };
@ -446,7 +446,7 @@ std::string TranslateTTDPatchCodes(uint32 grfid, uint8 language_id, bool allow_n
case 0x20: Utf8Encode(d, SCC_POP_COLOUR); break;
default:
grfmsg(1, "missing handler for extended format code");
GrfMsg(1, "missing handler for extended format code");
break;
}
break;
@ -477,7 +477,7 @@ std::string TranslateTTDPatchCodes(uint32 grfid, uint8 language_id, bool allow_n
string_end:
if (mapping != nullptr) {
grfmsg(1, "choice list was incomplete, the whole list is ignored");
GrfMsg(1, "choice list was incomplete, the whole list is ignored");
delete mapping;
}
@ -590,7 +590,7 @@ StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, bool ne
}
AddGRFTextToList(_grf_text[id].textholder, langid_to_add, newtext);
grfmsg(3, "Added 0x%X: grfid %08X string 0x%X lang 0x%X string '%s' (%X)", id, grfid, stringid, langid_to_add, newtext.c_str(), MakeStringID(TEXT_TAB_NEWGRF_START, id));
GrfMsg(3, "Added {:#X} grfid {:08X} string {:#X} lang {:#X} string '{}' ({:X})", id, grfid, stringid, langid_to_add, newtext.c_str(), MakeStringID(TEXT_TAB_NEWGRF_START, id));
return MakeStringID(TEXT_TAB_NEWGRF_START, id);
}

Loading…
Cancel
Save