From 20e6ab70e99918daea6c590d8ffd3292a0c4a134 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Schu=CC=88mann?= Date: Thu, 23 Apr 2026 18:10:34 +0200 Subject: [PATCH 1/8] Add TPrint method with compile-time-safe formatting using fmtlib --- EBase/Utility.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/EBase/Utility.h b/EBase/Utility.h index 33240b3..8257d97 100644 --- a/EBase/Utility.h +++ b/EBase/Utility.h @@ -54,6 +54,8 @@ #include #include +#include + #define IsAlpha(c) isalpha((unsigned char)(c)) #define IsAlNum(c) isalnum((unsigned char)(c)) #define IsDigit(c) isdigit((unsigned char)(c)) @@ -340,6 +342,17 @@ class COutput static void TWrite(const std::string& sID, const std::string& sTxt); static void TPrintf(const std::string& sID, const char* msg, ...); + + // Compile-time-safe formatted output via fmtlib. + // fmt::format_string validates the format string and argument types + // at compile time — wrong types or argument count are caught as errors, not + // as runtime crashes or silent truncation like TPrintf. + template + static void TPrint(const std::string& sID, fmt::format_string fmt, Args&&... args) + { + Target(sID)->Write(fmt::format(fmt, std::forward(args)...)); + } + static void CloseTargets(); static void SetTarget(const std::string& sID, COutput* poTrace); static void SetFilter(const std::string& sID, const std::string& sFilter); From 169d67677baaa6b47621627f2aa5f7455110466f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Schu=CC=88mann?= Date: Thu, 23 Apr 2026 18:10:57 +0200 Subject: [PATCH 2/8] Add optional secondary report statistics calculation in Zugvorlage --- Vorlage/Zugvorlage.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Vorlage/Zugvorlage.cpp b/Vorlage/Zugvorlage.cpp index 7b1bff9..b3286a2 100644 --- a/Vorlage/Zugvorlage.cpp +++ b/Vorlage/Zugvorlage.cpp @@ -811,7 +811,9 @@ void CVorlage::Vorlage(CReport& oReport, CReport* poRep2, bool bTime) m_poCurrentReport = &oReport; CMessage::SelectRenderer(oReport.MessageRenderer(), oReport.MessageRules()); oReport.CalculateStatistics(); - + if (poRep2) { + poRep2->CalculateStatistics(); + } m_nPlayer = oReport.Partei(); for (CReport::Einheiten::iterator ei = oReport.GEinheiten().begin(); ei != oReport.GEinheiten().end(); ei++) { if ((*ei).second->Partei() == m_nPlayer) { From 6cdbb10d46c83adaee6ce7fc3d96e261a3ce4b69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Schu=CC=88mann?= Date: Thu, 23 Apr 2026 20:01:12 +0200 Subject: [PATCH 3/8] Refactor COutput calls: replace `TPrintf` with `TPrint` or `TWrite` for modern formatting and clarity. --- Vorlage/Zugvorlage.cpp | 216 ++++++++++++++++++++--------------------- 1 file changed, 107 insertions(+), 109 deletions(-) diff --git a/Vorlage/Zugvorlage.cpp b/Vorlage/Zugvorlage.cpp index b3286a2..27e5e20 100644 --- a/Vorlage/Zugvorlage.cpp +++ b/Vorlage/Zugvorlage.cpp @@ -225,7 +225,7 @@ static void WrapOut(const std::string& sPfx, const std::string& sText, size_t nL if (sFirstPfx.empty()) sFPfx = sPfx; do { - COutput::TPrintf("vorlage", "%s%s\n", c ? sPfx.c_str() : sFPfx.c_str(), Wrap(sTxt, nLen - (c ? sPfx.size() : sFPfx.size())).c_str()); + COutput::TPrint("vorlage", "{}{}\n", c ? sPfx : sFPfx, Wrap(sTxt, nLen - (c ? sPfx.size() : sFPfx.size()))); c++; } while (!sTxt.empty()); } @@ -749,14 +749,14 @@ std::string CVorlage::MutateCRBlock(std::fstream& oIS, CBlockBase* poBlockObj, b if (custom) { if (oVal.getType() == VT_STRING) { std::string strVal = Escape(oVal.asString()); - COutput::TPrintf("vorlage", "\x22%s\x22;%s\n", (utf8 ? iso885915ToUtf8(strVal).c_str() : strVal.c_str()), sTagCR.c_str()); + COutput::TPrint("vorlage", "\"{}\";{}\n", utf8 ? iso885915ToUtf8(strVal) : strVal, sTagCR); } else { - COutput::TPrintf("vorlage", "%d;%s\n", oVal.asLong(), sTagCR.c_str()); + COutput::TPrint("vorlage", "{};{}\n", oVal.asLong(), sTagCR); } } else { - COutput::TPrintf("vorlage", "%s\n", sLine.c_str()); + COutput::TPrint("vorlage", "{}\n", sLine); } } @@ -771,10 +771,10 @@ std::string CVorlage::MutateCRBlock(std::fstream& oIS, CBlockBase* poBlockObj, b iso885915ToUtf8(sName); if (oValt.getType() == VT_STRING) { std::string strVal = Escape(oValt.asString()); - COutput::TPrintf("vorlage", "\x22%s\x22;%s\n", (utf8 ? iso885915ToUtf8(strVal).c_str() : strVal.c_str()), sName.substr(1).c_str()); + COutput::TPrint("vorlage", "\"{}\";{}\n", utf8 ? iso885915ToUtf8(strVal) : strVal, sName.substr(1)); } else { - COutput::TPrintf("vorlage", "%d;%s\n", oValt.asLong(), sName.substr(1).c_str()); + COutput::TPrint("vorlage", "{};{}\n", oValt.asLong(), sName.substr(1)); } } } @@ -826,10 +826,10 @@ void CVorlage::Vorlage(CReport& oReport, CReport* poRep2, bool bTime) } m_nUnits = nUnits; - COutput::TPrintf("vorlage", "%s %s %c%s%c\n", IsEqual(g_poCurrentReport->m_sSpiel, "eressea") ? "ERESSEA" : "PARTEI", itoan(oReport.Partei(), oReport.PNrBase()), 34, oReport.Passwort().c_str(), 34); + COutput::TPrint("vorlage", "{} {} \"{}\"\n", IsEqual(g_poCurrentReport->m_sSpiel, "eressea") ? "ERESSEA" : "PARTEI", itoan(oReport.Partei(), oReport.PNrBase()), oReport.Passwort()); if (IsEqual(g_poCurrentReport->m_sSpiel, "eressea") || IsEqual(g_poCurrentReport->m_sSpiel, "empiria") || IsEqual(g_poCurrentReport->m_sSpiel, "vinyambar i") || IsEqual(g_poCurrentReport->m_sSpiel, "vinyambar ii")) - COutput::TPrintf("vorlage", "\n ; ECHECK -l -w4 -r%d\n", oReport.Rekrutierungskosten()); - COutput::TPrintf("vorlage", "\n ; %s, (C) 1999-2026 by S.Schuemann\n ; [%s %s]\n", VERSIONINFO, __DATE__, __TIME__); + COutput::TPrint("vorlage", "\n ; ECHECK -l -w4 -r{}\n", oReport.Rekrutierungskosten()); + COutput::TPrint("vorlage", "\n ; {}, (C) 1999-2026 by S.Schuemann\n ; [{} {}]\n", VERSIONINFO, __DATE__, __TIME__); WrapOut(" ; ", g_sCmdOptions, (size_t)g_nLineSize, " ; "); if (poRep2 && oReport.Version() != poRep2->Version()) { std::ostringstream out; @@ -837,13 +837,13 @@ void CVorlage::Vorlage(CReport& oReport, CReport* poRep2, bool bTime) auto msg = out.str(); if (bTime) TRACEMSG(("%s\n", msg.c_str())); - COutput::TPrintf("vorlage", " ; %s\n", msg.c_str()); + COutput::TPrint("vorlage", " ; {}\n", msg); } if (oReport.Zeitalter() == 1) - COutput::TPrintf("vorlage", "\n ; Zugvorlage aus Report Runde %d (%s %d)\n", oReport.Runde(), pcJahr[(oReport.Runde()) % 12], (oReport.Runde() - 1) / 12 + 1); + COutput::TPrint("vorlage", "\n ; Zugvorlage aus Report Runde {} ({} {})\n", oReport.Runde(), pcJahr[(oReport.Runde()) % 12], (oReport.Runde() - 1) / 12 + 1); else - COutput::TPrintf("vorlage", "\n ; Zugvorlage aus Report Runde %d (%d. Woche, %s, %d)\n", oReport.Runde(), (oReport.Runde() - 184) % 3 + 1, pcJahr2[((oReport.Runde() - 184) / 3) % 9], (oReport.Runde() - 184) / 27 + 1); + COutput::TPrint("vorlage", "\n ; Zugvorlage aus Report Runde {} ({}. Woche, {}, {})\n", oReport.Runde(), (oReport.Runde() - 184) % 3 + 1, pcJahr2[((oReport.Runde() - 184) / 3) % 9], (oReport.Runde() - 184) / 27 + 1); CPartei::Ptr parteiInfo = oReport.GetLocalParteiInfo(oReport.Partei()); CPartei::Ptr lastParteiInfo; @@ -860,10 +860,10 @@ void CVorlage::Vorlage(CReport& oReport, CReport* poRep2, bool bTime) if (oReport.m_nPunkte > 0 && oReport.m_nPunkteschnitt > 0) { if (!poRep2) { if (maxHeroes > 0) - COutput::TPrintf("vorlage", " ; Personen: %d, Einheiten: %d, Helden: %d/%d\n", nPersons, nUnits, heroes, maxHeroes); + COutput::TPrint("vorlage", " ; Personen: {}, Einheiten: {}, Helden: {}/{}\n", nPersons, nUnits, heroes, maxHeroes); else - COutput::TPrintf("vorlage", " ; Personen: %d, Einheiten: %d\n", nPersons, nUnits); - COutput::TPrintf("vorlage", " ; Punkte: %d (%.2f%% des Durchschnitts)\n", oReport.m_nPunkte, (double)oReport.m_nPunkte * 100.0 / oReport.m_nPunkteschnitt); + COutput::TPrint("vorlage", " ; Personen: {}, Einheiten: {}\n", nPersons, nUnits); + COutput::TPrint("vorlage", " ; Punkte: {} ({:.2f}% des Durchschnitts)\n", oReport.m_nPunkte, (double)oReport.m_nPunkte * 100.0 / oReport.m_nPunkteschnitt); } else { int32_t nLastUnits = 0, nLastPersons = 0; @@ -883,15 +883,15 @@ void CVorlage::Vorlage(CReport& oReport, CReport* poRep2, bool bTime) if (lastParteiInfo) lastHeroes = lastParteiInfo->GetValue("heroes").asLong(); if (maxHeroes > 0) - COutput::TPrintf("vorlage", " ; Personen: %d (%+d), Einheiten: %d (%+d), Helden: %d/%d (%+d/%+d)\n", nPersons, nPersons - nLastPersons, nUnits, nUnits - nLastUnits, heroes, maxHeroes, heroes - lastHeroes, maxHeroes - lastMaxHeroes); + COutput::TPrint("vorlage", " ; Personen: {} ({:+}), Einheiten: {} ({:+}), Helden: {}/{} ({:+}/{:+})\n", nPersons, nPersons - nLastPersons, nUnits, nUnits - nLastUnits, heroes, maxHeroes, heroes - lastHeroes, maxHeroes - lastMaxHeroes); else - COutput::TPrintf("vorlage", " ; Personen: %d (%+d), Einheiten: %d (%+d)\n", nPersons, nPersons - nLastPersons, nUnits, nUnits - nLastUnits); + COutput::TPrint("vorlage", " ; Personen: {} ({:+}), Einheiten: {} ({:+})\n", nPersons, nPersons - nLastPersons, nUnits, nUnits - nLastUnits); if (poRep2->m_nPunkte) - COutput::TPrintf("vorlage", " ; Punkte: %d (%.2f%% des Durchschnitts, %+.2f%%)\n", oReport.m_nPunkte, (double)oReport.m_nPunkte * 100.0 / oReport.m_nPunkteschnitt, - (double)oReport.m_nPunkte * 100.0 / oReport.m_nPunkteschnitt - (double)poRep2->m_nPunkte * 100.0 / poRep2->m_nPunkteschnitt); + COutput::TPrint("vorlage", " ; Punkte: {} ({:.2f}% des Durchschnitts, {:+.2f}%)\n", oReport.m_nPunkte, (double)oReport.m_nPunkte * 100.0 / oReport.m_nPunkteschnitt, + (double)oReport.m_nPunkte * 100.0 / oReport.m_nPunkteschnitt - (double)poRep2->m_nPunkte * 100.0 / poRep2->m_nPunkteschnitt); else - COutput::TPrintf("vorlage", " ; Punkte: %d (%.2f%% des Durchschnitts)\n", oReport.m_nPunkte, (double)oReport.m_nPunkte * 100.0 / oReport.m_nPunkteschnitt); + COutput::TPrint("vorlage", " ; Punkte: {} ({:.2f}% des Durchschnitts)\n", oReport.m_nPunkte, (double)oReport.m_nPunkte * 100.0 / oReport.m_nPunkteschnitt); } } @@ -966,7 +966,7 @@ void CVorlage::Vorlage(CReport& oReport, CReport* poRep2, bool bTime) if (!m_coInitCmd.empty()) { for (int32_t i = 0; i < (int32_t)m_coInitCmd.size(); i++) { if (m_coInitCmd[i].empty()) { - COutput::TPrintf("vorlage", "\n"); + COutput::TWrite("vorlage", "\n"); } else { if (m_coInitCmd[i].asString()[0] == ';') @@ -976,17 +976,17 @@ void CVorlage::Vorlage(CReport& oReport, CReport* poRep2, bool bTime) } if (IsFlag(VF_SHOWHANDEL)) { - COutput::TPrintf("vorlage", "\n ; Wirtschaftsbilanz:\n"); - COutput::TPrintf("vorlage", " ; Gesamteinkommen:%9ld Silber\n", oReport.m_nEinkommen); - COutput::TPrintf("vorlage", " ; Gesamtausgaben: %9ld Silber %s\n", oReport.m_nAusgaben + nNeededFood /*Eater*10*/, oReport.Version() > 40 ? "" : "(z.Zt. ohne kostenpfl. Talente)"); + COutput::TWrite("vorlage", "\n ; Wirtschaftsbilanz:\n"); + COutput::TPrint("vorlage", " ; Gesamteinkommen:{:9} Silber\n", oReport.m_nEinkommen); + COutput::TPrint("vorlage", " ; Gesamtausgaben: {:9} Silber {}\n", oReport.m_nAusgaben + nNeededFood /*Eater*10*/, oReport.Version() > 40 ? "" : "(z.Zt. ohne kostenpfl. Talente)"); int64_t nVermoegen = 0; for (CKarte::RegionMap::const_iterator rmi = m_poKarte->Regions().begin(); rmi != m_poKarte->Regions().end(); rmi++) { nVermoegen += (*rmi).second->SilverOf(oReport.Partei()); } - COutput::TPrintf("vorlage", " ; Gesamtverm\xF6gen: %9ld Silber\n", nVermoegen); + COutput::TPrint("vorlage", " ; Gesamtverm\xF6gen: {:9} Silber\n", nVermoegen); if (oReport.m_cpoHPartner.size()) - COutput::TPrintf("vorlage", "\n ; Warenaustausch:\n"); + COutput::TWrite("vorlage", "\n ; Warenaustausch:\n"); for (CReport::Handelspartner::const_iterator rhi = oReport.m_cpoHPartner.begin(); rhi != oReport.m_cpoHPartner.end(); rhi++) { std::ostringstream out; @@ -1012,12 +1012,12 @@ void CVorlage::Vorlage(CReport& oReport, CReport* poRep2, bool bTime) std::stable_sort(cpoRegions.begin(), cpoRegions.end(), CRegionSorter(IsFlag(VF_SORTISLANDS))); if (IsFlag(VF_SHOWKOMPKARTE)) { - COutput::TPrintf("vorlage", "\n ; Uebersichtskarte:\n"); + COutput::TWrite("vorlage", "\n ; Uebersichtskarte:\n"); oReport.Karte()->DumpFullMap("vorlage", " ; "); } if (IsFlag(VF_SHOWWORLDKARTE)) { - COutput::TPrintf("vorlage", "\n ; Karte der bekannten Welt:\n"); + COutput::TWrite("vorlage", "\n ; Karte der bekannten Welt:\n"); oReport.Karte()->DumpWorldMap("vorlage", " ; "); } @@ -1039,12 +1039,12 @@ void CVorlage::Vorlage(CReport& oReport, CReport* poRep2, bool bTime) } } - COutput::TPrintf("vorlage", "\n NAECHSTER\n\n"); + COutput::TWrite("vorlage", "\n NAECHSTER\n\n"); if (!m_coExitCmd.empty()) { for (int32_t i = 0; i < (int32_t)m_coExitCmd.size(); i++) { if (m_coExitCmd[i].empty()) { - COutput::TPrintf("vorlage", "\n"); + COutput::TWrite("vorlage", "\n"); } else { if (m_coExitCmd[i].asString()[0] == ';') @@ -1091,15 +1091,15 @@ void CVorlage::Vorlage(CReport& oReport, CReport* poRep2, bool bTime) if (!bKonfiguration && sLine.length() > 15 && CRegExp::Match(sLine, "^(\"[^\"]*\"\\s*;\\s*(?i:Konfiguration)|[A-Z]+)")) { bKonfiguration = true; if (CRegExp::Match(sLine, "^\"[^\"]*\"\\s*;\\s*(?i:Konfiguration)")) { - COutput::TPrintf("vorlage", "\"Vorlage\";Konfiguration\n"); + COutput::TWrite("vorlage", "\"Vorlage\";Konfiguration\n"); } else { - COutput::TPrintf("vorlage", "\"Vorlage\";Konfiguration\n"); - COutput::TPrintf("vorlage", "%s\n", sLine.c_str()); + COutput::TWrite("vorlage", "\"Vorlage\";Konfiguration\n"); + COutput::TPrint("vorlage", "{}\n", sLine); } } else { - COutput::TPrintf("vorlage", "%s\n", sLine.c_str()); + COutput::TPrint("vorlage", "{}\n", sLine); } if (!strncmp(sLine.c_str(), "REGION ", 7)) { @@ -1154,7 +1154,7 @@ void CVorlage::Vorlage(CReport& oReport, CReport* poRep2, bool bTime) for (int32_t i = 0; i < (int32_t)poUnit->m_csKommandos.size(); i++) { std::string strVal = Escape(poUnit->m_csKommandos[i].asString(), true); if (!poUnit->m_csKommandos[i].empty()) - COutput::TPrintf("vorlage", "\x22%s\x22\n", (oReport.m_bUTF8 ? iso885915ToUtf8(strVal).c_str() : strVal.c_str())); + COutput::TPrint("vorlage", "\"{}\"\n", oReport.m_bUTF8 ? iso885915ToUtf8(strVal) : strVal); } } @@ -1173,11 +1173,11 @@ void CVorlage::Vorlage(CReport& oReport, CReport* poRep2, bool bTime) sCmd.erase(sCmd.size() - 1, 1); } std::string strVal = Escape(sCmd, true); - COutput::TPrintf("vorlage", "\x22%s\x22\n", (oReport.m_bUTF8 ? iso885915ToUtf8(strVal).c_str() : strVal.c_str())); + COutput::TPrint("vorlage", "\"{}\"\n", oReport.m_bUTF8 ? iso885915ToUtf8(strVal) : strVal); } if (poUnit->m_csMetaOut.empty() && (poUnit->m_csKommandos.empty() || IsFlag(VF_FULLCOMMANDOUTPUT))) { - COutput::TPrintf("vorlage", "\x22\x22\n"); + COutput::TWrite("vorlage", "\"\"\n"); } bGotLine = true; @@ -1310,17 +1310,17 @@ void CVorlage::Regionsvorlage(CRegion* poReg, CRegion* poReg2, CReport* poRep2) } if (!bRegHead) { if (IsFlag(VF_SHOWVERBOSEINFO)) { - COutput::TPrintf("vorlage", "\n; --------------------------------------------------------------\n\n"); + COutput::TWrite("vorlage", "\n; --------------------------------------------------------------\n\n"); } else { - COutput::TPrintf("vorlage", "\n"); + COutput::TWrite("vorlage", "\n"); } if (CMetaCommand::ProcExists("CreateRegionHeader")) { VKommandos coOutput; CMetaCommand::Call("CreateRegionHeader", coOutput); if (!coOutput.empty()) { for (size_t j = 0; j < coOutput.size(); j++) { - COutput::TPrintf("vorlage", " %s\n", coOutput[(int32_t)j].c_str()); + COutput::TPrint("vorlage", " {}\n", coOutput[(int32_t)j].c_str()); } } } @@ -1328,45 +1328,45 @@ void CVorlage::Regionsvorlage(CRegion* poReg, CRegion* poReg2, CReport* poRep2) if (IsEqual(g_poCurrentReport->m_sSpiel, "Verdanon")) { if (!IsFlag(VF_SHOWVERBOSEINFO)) { if (poReg->GetEZ()) { - COutput::TPrintf("vorlage", " ; %s (%d,%d,%d)\n", poReg->GetName().empty() ? poReg->GetRegionTypeName().c_str() : poReg->GetName().c_str(), poReg->GetEX(), poReg->GetEY(), poReg->GetEZ()); + COutput::TPrint("vorlage", " ; {} ({},{},{})\n", poReg->GetName().empty() ? poReg->GetRegionTypeName() : poReg->GetName(), poReg->GetEX(), poReg->GetEY(), poReg->GetEZ()); } else { - COutput::TPrintf("vorlage", " ; %s (%d,%d)\n", poReg->GetName().empty() ? poReg->GetRegionTypeName().c_str() : poReg->GetName().c_str(), poReg->GetEX(), poReg->GetEY()); + COutput::TPrint("vorlage", " ; {} ({},{})\n", poReg->GetName().empty() ? poReg->GetRegionTypeName() : poReg->GetName(), poReg->GetEX(), poReg->GetEY()); } } else if (poReg->GetBlock() == CRegion::enSPEZIALREGION) { - COutput::TPrintf("vorlage", " ; Astralebene (%s, %d Personen, %d$ Silber)\n", poReg->GetRegionTypeName().c_str(), poReg->PersonsOf(m_nPlayer, true), poReg->SilverOf(m_nPlayer)); + COutput::TPrint("vorlage", " ; Astralebene ({}, {} Personen, {}$ Silber)\n", poReg->GetRegionTypeName(), poReg->PersonsOf(m_nPlayer, true), poReg->SilverOf(m_nPlayer)); } else if (poReg->GetEZ()) { - COutput::TPrintf("vorlage", " ; %s (%d,%d,%d) (%s, %d Personen, %d$ Silber) %s\n", poReg->GetName().c_str(), poReg->GetEX(), poReg->GetEY(), poReg->GetEZ(), poReg->GetRegionTypeName().c_str(), poReg->PersonsOf(m_nPlayer, true), - poReg->SilverOf(m_nPlayer), sInsel.c_str()); + COutput::TPrint("vorlage", " ; {} ({},{},{}) ({}, {} Personen, {}$ Silber) {}\n", poReg->GetName(), poReg->GetEX(), poReg->GetEY(), poReg->GetEZ(), poReg->GetRegionTypeName(), poReg->PersonsOf(m_nPlayer, true), + poReg->SilverOf(m_nPlayer), sInsel); } else { - COutput::TPrintf("vorlage", " ; %s (%d,%d) (%s, %d Personen, %d$ Silber) %s\n", poReg->GetName().c_str(), poReg->GetEX(), poReg->GetEY(), poReg->GetRegionTypeName().c_str(), poReg->PersonsOf(m_nPlayer, true), - poReg->SilverOf(m_nPlayer), sInsel.c_str()); + COutput::TPrint("vorlage", " ; {} ({},{}) ({}, {} Personen, {}$ Silber) {}\n", poReg->GetName(), poReg->GetEX(), poReg->GetEY(), poReg->GetRegionTypeName(), poReg->PersonsOf(m_nPlayer, true), + poReg->SilverOf(m_nPlayer), sInsel); } } else { if (!IsFlag(VF_SHOWVERBOSEINFO)) { if (poReg->GetEZ()) { - COutput::TPrintf("vorlage", " REGION $d,%d,%d ; %s\n", poReg->GetEX(), poReg->GetEY(), poReg->GetEZ(), poReg->GetName().empty() ? poReg->GetRegionTypeName().c_str() : poReg->GetName().c_str()); + COutput::TPrint("vorlage", " REGION {},{},{} ; {}\n", poReg->GetEX(), poReg->GetEY(), poReg->GetEZ(), poReg->GetName().empty() ? poReg->GetRegionTypeName() : poReg->GetName()); } else { - COutput::TPrintf("vorlage", " REGION %d,%d ; %s\n", poReg->GetEX(), poReg->GetEY(), poReg->GetName().empty() ? poReg->GetRegionTypeName().c_str() : poReg->GetName().c_str()); + COutput::TPrint("vorlage", " REGION {},{} ; {}\n", poReg->GetEX(), poReg->GetEY(), poReg->GetName().empty() ? poReg->GetRegionTypeName() : poReg->GetName()); } } else if (poReg->GetBlock() == CRegion::enSPEZIALREGION) { - COutput::TPrintf("vorlage", " REGION; Astralebene (%s, %d Personen, %d$ Silber)\n", poReg->GetRegionTypeName().c_str(), poReg->PersonsOf(m_nPlayer, true), poReg->SilverOf(m_nPlayer)); + COutput::TPrint("vorlage", " REGION; Astralebene ({}, {} Personen, {}$ Silber)\n", poReg->GetRegionTypeName(), poReg->PersonsOf(m_nPlayer, true), poReg->SilverOf(m_nPlayer)); } else if (poReg->GetEZ()) { - COutput::TPrintf("vorlage", " REGION %d,%d,%d ; %s (%s, %d Personen, %d$ Silber) %s\n", poReg->GetEX(), poReg->GetEY(), poReg->GetEZ(), poReg->GetName().c_str(), poReg->GetRegionTypeName().c_str(), - poReg->PersonsOf(m_nPlayer, true), poReg->SilverOf(m_nPlayer), sInsel.c_str()); + COutput::TPrint("vorlage", " REGION {},{},{} ; {} ({}, {} Personen, {}$ Silber) {}\n", poReg->GetEX(), poReg->GetEY(), poReg->GetEZ(), poReg->GetName(), poReg->GetRegionTypeName(), + poReg->PersonsOf(m_nPlayer, true), poReg->SilverOf(m_nPlayer), sInsel); } else { - COutput::TPrintf("vorlage", " REGION %d,%d ; %s (%s, %d Personen, %d$ Silber) %s\n", poReg->GetEX(), poReg->GetEY(), poReg->GetName().c_str(), poReg->GetRegionTypeName().c_str(), poReg->PersonsOf(m_nPlayer, true), - poReg->SilverOf(m_nPlayer), sInsel.c_str()); + COutput::TPrint("vorlage", " REGION {},{} ; {} ({}, {} Personen, {}$ Silber) {}\n", poReg->GetEX(), poReg->GetEY(), poReg->GetName(), poReg->GetRegionTypeName(), poReg->PersonsOf(m_nPlayer, true), + poReg->SilverOf(m_nPlayer), sInsel); } - COutput::TPrintf("vorlage", " ; ECheck Lohn %d\n", poReg->GetLohn() ? poReg->GetLohn() : 10); + COutput::TPrint("vorlage", " ; ECheck Lohn {}\n", poReg->GetLohn() ? poReg->GetLohn() : 10); } if (poReg->GetBlock() != CRegion::enSPEZIALREGION && IsFlag(VF_SHOWMINIKARTE)) { static const std::set explicitResources{"Bauern", "Silber", "Unterhalt", "Rekruten", "Pferde", "Gewinn", "Pl. frei"}; @@ -1591,7 +1591,7 @@ void CVorlage::Regionsvorlage(CRegion* poReg, CRegion* poReg2, CReport* poRep2) if (IsFlag(VF_SHOWLUXUS) || IsFlag(VF_SHOWLPROD)) { static char Delta[32]; if (poReg->GetVerkauf() >= 0 && size_t(poReg->GetVerkauf()) < poReg->GetLuxusgueter().size()) { - COutput::TPrintf("vorlage", " ; Prod.: "); + COutput::TWrite("vorlage", " ; Prod.: "); if (bDiff) { snprintf(Delta, sizeof(Delta), "%+5ld", (poReg2->GetLuxusgueter().size() > size_t(poReg2->GetVerkauf())) ? poReg->GetLuxusgueter()[size_t(poReg->GetVerkauf())].second - poReg2->GetLuxusgueter()[size_t(poReg2->GetVerkauf())].second : 0); @@ -1599,18 +1599,18 @@ void CVorlage::Regionsvorlage(CRegion* poReg, CRegion* poReg2, CReport* poRep2) else { Delta[0] = 0; } - COutput::TPrintf("vorlage", "%-10s%4d%s max. handelbar: %d\n", (poReg->GetLuxusgueter()[size_t(poReg->GetVerkauf())].first + ":").c_str(), poReg->GetLuxusgueter()[size_t(poReg->GetVerkauf())].second, Delta, - poReg->GetBauern() / 100); + COutput::TPrint("vorlage", "{:<10}{:4}{} max. handelbar: {}\n", poReg->GetLuxusgueter()[size_t(poReg->GetVerkauf())].first + ":", poReg->GetLuxusgueter()[size_t(poReg->GetVerkauf())].second, Delta, + poReg->GetBauern() / 100); } } if (IsFlag(VF_SHOWMINIKARTE)) { if (poRQ->DeepGetValue("herb").asString().size() > 2) { - COutput::TPrintf("vorlage", " ; Kraut: %s\n", poRQ->DeepGetValue("herb").asString().c_str()); + COutput::TPrint("vorlage", " ; Kraut: {}\n", poRQ->DeepGetValue("herb").asString()); } } if (poReg->isVerorkt()) - COutput::TPrintf("vorlage", " ; Die Region ist verorkt!\n"); + COutput::TWrite("vorlage", " ; Die Region ist verorkt!\n"); if (poReg->GetVGrenzen() && !poReg->GetVGrenzen()->empty()) { std::ostringstream os; @@ -1640,7 +1640,7 @@ void CVorlage::Regionsvorlage(CRegion* poReg, CRegion* poReg2, CReport* poRep2) break; } os << " ; " << (*(poReg->GetVGrenzen()))[j] -> Typ() << " (" << (*(poReg->GetVGrenzen()))[j] -> Prozent() << "%) in " << sGrenze; - COutput::TPrintf("vorlage", "%s\n", getAndReset(os).c_str()); + COutput::TPrint("vorlage", "{}\n", getAndReset(os)); } } } @@ -1656,13 +1656,13 @@ void CVorlage::Regionsvorlage(CRegion* poReg, CRegion* poReg2, CReport* poRep2) } } if (poReg->GetEinkommen() > 0) { - COutput::TPrintf("vorlage", " ; Regionseinnahmen:%6d Silber\n", poReg->GetEinkommen()); + COutput::TPrint("vorlage", " ; Regionseinnahmen:{:6} Silber\n", poReg->GetEinkommen()); } if (poReg->GetAusgaben() > 0) { - COutput::TPrintf("vorlage", " ; Regionsausgaben: %6d Silber\n", poReg->GetAusgaben() + nKosten); + COutput::TPrint("vorlage", " ; Regionsausgaben: {:6} Silber\n", poReg->GetAusgaben() + nKosten); } else if (nKosten) { - COutput::TPrintf("vorlage", " ; Nahrungskosten: %6d Silber\n", nKosten); + COutput::TPrint("vorlage", " ; Nahrungskosten: {:6} Silber\n", nKosten); } } } @@ -1718,17 +1718,17 @@ void CVorlage::Regionsvorlage(CRegion* poReg, CRegion* poReg2, CReport* poRep2) } CRegion::Durchreisen::const_iterator di; for (di = poReg->GetDurchreisen().begin(); di != poReg->GetDurchreisen().end(); di++) { - COutput::TPrintf("vorlage", " ; Durchgereist: %s\n", (*di).c_str()); + COutput::TPrint("vorlage", " ; Durchgereist: {}\n", *di); } for (di = poReg->GetDurchschiffungen().begin(); di != poReg->GetDurchschiffungen().end(); di++) { - COutput::TPrintf("vorlage", " ; Durchgesegelt: %s\n", (*di).c_str()); + COutput::TPrint("vorlage", " ; Durchgesegelt: {}\n", *di); } } if (!poReg->GetKommandos().empty()) { for (int32_t j = 0; j < (int32_t)poReg->GetKommandos().size(); j++) { if (poReg->GetKommandos()[j].empty()) { - COutput::TPrintf("vorlage", "\n"); + COutput::TWrite("vorlage", "\n"); } else { if (poReg->GetKommandos()[j].asString()[0] == ';') { @@ -1738,7 +1738,7 @@ void CVorlage::Regionsvorlage(CRegion* poReg, CRegion* poReg2, CReport* poRep2) } } if (!IsFlag(VF_SHOWVERBOSEINFO)) { - COutput::TPrintf("vorlage", "\n"); + COutput::TWrite("vorlage", "\n"); } if (poReg->PersonsOf(m_nPlayer) - poReg->PersonsOf(m_nPlayer, true) > 0) { WrapOut(" ; ", std::string("In dieser Region sind Einheiten als (") + itoan(m_nPlayer, g_poCurrentReport->PNrBase()) + ") getarnt!", (size_t)g_nLineSize); @@ -1750,9 +1750,9 @@ void CVorlage::Regionsvorlage(CRegion* poReg, CRegion* poReg2, CReport* poRep2) if (!IsFlag(VF_SUPPRESSUNITS)) { if (IsFlag(VF_SORTBURGEN) && nOrt != poReg->GetVEinheiten()[i]->Aufenthaltsort()) { nOrt = poReg->GetVEinheiten()[i]->Aufenthaltsort(); - COutput::TPrintf("vorlage", "\n ; - - - - - - - - - - - -\n"); + COutput::TWrite("vorlage", "\n ; - - - - - - - - - - - -\n"); if (!nOrt) { - COutput::TPrintf("vorlage", " ; Auf freiem Feld:\n"); + COutput::TWrite("vorlage", " ; Auf freiem Feld:\n"); } else if (nOrt > 0x10000000) { if (poReg->GetShip(nOrt - 0x10000000)) { @@ -1786,13 +1786,13 @@ void CVorlage::Regionsvorlage(CRegion* poReg, CRegion* poReg2, CReport* poRep2) if (IsFlag(VF_SORTBURGEN)) { while (!coBauwerke.empty()) { - COutput::TPrintf("vorlage", "\n ; - - - - - - - - - - - -\n"); + COutput::TWrite("vorlage", "\n ; - - - - - - - - - - - -\n"); BauwerkAusgabe(*(coBauwerke.begin())); coBauwerke.erase(coBauwerke.begin()); } while (!coSchiffe.empty()) { - COutput::TPrintf("vorlage", "\n ; - - - - - - - - - - - -\n"); + COutput::TWrite("vorlage", "\n ; - - - - - - - - - - - -\n"); SchiffAusgabe(*(coSchiffe.begin())); coSchiffe.erase(coSchiffe.begin()); } @@ -1807,12 +1807,12 @@ void CVorlage::Regionsvorlage(CRegion* poReg, CRegion* poReg2, CReport* poRep2) poLU = poRep2 ? poRep2->SearchUnit(poHU->Nummer(), false) : 0; if ((!IsFlag(VF_SHOWUNITSNEW) || !poLU || (poLU && poLU->Region()->GetKey() != poHU->Region()->GetKey())) && (poHU->Partei() != m_nPlayer)) { if (!bHead) { - COutput::TPrintf("vorlage", "\n ; - - - - - - - - - - - -\n"); + COutput::TWrite("vorlage", "\n ; - - - - - - - - - - - -\n"); if (IsFlag(VF_SHOWUNITSNEW)) { - COutput::TPrintf("vorlage", " ; Neue fremde Einheiten:\n"); + COutput::TWrite("vorlage", " ; Neue fremde Einheiten:\n"); } else { - COutput::TPrintf("vorlage", " ; Fremde Einheiten:\n"); + COutput::TWrite("vorlage", " ; Fremde Einheiten:\n"); } bHead = true; } @@ -1826,10 +1826,8 @@ void CVorlage::Regionsvorlage(CRegion* poReg, CRegion* poReg2, CReport* poRep2) } if (bRegHead && IsFlag(VF_SHOWTRIBEOVERVIEW) && coPersonen.size() > 1) { - COutput::TPrintf("vorlage", "\n ; - - - - - - - - - - - -\n"); - COutput::TPrintf("vorlage", - " ; Partei\xFC" - "bersicht:\n"); + COutput::TWrite("vorlage", "\n ; - - - - - - - - - - - -\n"); + COutput::TWrite("vorlage", " ; Partei\xFC" "bersicht:\n"); std::string sPfx; if (poReg2 && IsFlag(VF_SHOWTDIFF)) { @@ -1847,7 +1845,7 @@ void CVorlage::Regionsvorlage(CRegion* poReg, CRegion* poReg2, CReport* poRep2) if ((*ppi).first != m_nPlayer) { std::map::iterator ppi2 = coPersonen2.find((*ppi).first); - COutput::TPrintf("vorlage", "\n"); + COutput::TWrite("vorlage", "\n"); out.str(""); out.clear(); @@ -1923,7 +1921,7 @@ void CVorlage::Regionsvorlage(CRegion* poReg, CRegion* poReg2, CReport* poRep2) if (bRegHead && !poReg->GetEndKommandos().empty()) { for (int32_t i = 0; i < (int32_t)poReg->GetEndKommandos().size(); i++) { if (poReg->GetEndKommandos()[i].empty()) { - COutput::TPrintf("vorlage", "\n"); + COutput::TWrite("vorlage", "\n"); } else { if (poReg->GetEndKommandos()[i].asString()[0] == ';') { @@ -1955,8 +1953,8 @@ void CVorlage::ShowInvisibles(CRegion* poReg, CRegion* poReg2, CReport* poRep2) const CRegion* pRH = (*edbi).second->Region(); if (pRH && pRH->GetKey() == poReg->GetKey()) { if (!bHead) { - COutput::TPrintf("vorlage", "\n ; - - - - - - - - - - - -\n"); - COutput::TPrintf("vorlage", " ; Unsichtbare oder getarnte fremde Einheiten:\n"); + COutput::TWrite("vorlage", "\n ; - - - - - - - - - - - -\n"); + COutput::TWrite("vorlage", " ; Unsichtbare oder getarnte fremde Einheiten:\n"); bHead = true; } FremdEinheiten((*ui).second, poRep2); @@ -1982,15 +1980,15 @@ void CVorlage::BauwerkAusgabe(CBauwerk* pBuilding, CRegion::VEinheiten* poVE) } int32_t nKap = CBlockBase::GetValue(CBuildingInfo::Lookup(pBuilding->XTyp()), "kapazitaet").asLong(); int32_t nCountUnits = CBlockBase::GetValue(CBuildingInfo::Lookup(pBuilding->XTyp()), "einheiten").asLong(); - COutput::TPrintf("vorlage", " ; In %s '%s' (%s) [%d/%d%s]:\n", pBuilding->XTyp().c_str(), pBuilding->Name().c_str(), itoan(pBuilding->Nummer(), g_poCurrentReport->BNrBase()), nCountUnits > 0 ? nUnits : nPers, nKap ? nKap : pBuilding->Groesse(), - nKap && nKap != pBuilding->Groesse() ? std::string("/" + std::to_string(pBuilding->Groesse())).c_str() : ""); + COutput::TPrint("vorlage", " ; In {} '{}' ({}) [{}/{}{}]:\n", pBuilding->XTyp(), pBuilding->Name(), itoan(pBuilding->Nummer(), g_poCurrentReport->BNrBase()), nCountUnits > 0 ? nUnits : nPers, nKap ? nKap : pBuilding->Groesse(), + nKap && nKap != pBuilding->Groesse() ? "/" + std::to_string(pBuilding->Groesse()) : ""); if (IsFlag(VF_SHOWBESCHREIBUNG) && !(pBuilding->Beschreibung().empty())) { WrapOut(" ; ", pBuilding->Beschreibung(), (size_t)g_nLineSize); } if (pBuilding->m_nBelagerer) { - COutput::TPrintf("vorlage", " ; Belagert von: %d\n", pBuilding->m_nBelagerer); + COutput::TPrint("vorlage", " ; Belagert von: {}\n", pBuilding->m_nBelagerer); } if (!pBuilding->m_coEffects.empty() && IsFlag(VF_SHOWVERBOSEINFO)) { for (size_t i = 0; i < pBuilding->m_coEffects.size(); i++) { @@ -2001,7 +1999,7 @@ void CVorlage::BauwerkAusgabe(CBauwerk* pBuilding, CRegion::VEinheiten* poVE) if (!pBuilding->GetKommandos().empty()) { for (int32_t i = 0; i < (int32_t)pBuilding->GetKommandos().size(); i++) { if (pBuilding->GetKommandos()[i].empty()) { - COutput::TPrintf("vorlage", "\n"); + COutput::TWrite("vorlage", "\n"); } else { if (pBuilding->GetKommandos()[i].asString()[0] == ';') { @@ -2018,12 +2016,12 @@ void CVorlage::SchiffAusgabe(CSchiff* pSchiff) std::string anzahl = count == 1 ? "" : ", Anzahl " + std::to_string(count) + ","; // static int dbgcount = 0; if (pSchiff->MaxHolz() && pSchiff->MaxHolz() * count != pSchiff->Holz()) { - COutput::TPrintf("vorlage", " ; An Bord von %s '%s' (%s)%s (%d/0) im Bau (%d/%d):\n", pSchiff->Typ().c_str(), pSchiff->Name().c_str(), itoan(pSchiff->Nummer(), g_poCurrentReport->BNrBase()), anzahl.c_str(), pSchiff->Ladung(), pSchiff->Holz(), - pSchiff->MaxHolz() * count); + COutput::TPrint("vorlage", " ; An Bord von {} '{}' ({}){} ({}/0) im Bau ({}/{}):\n", pSchiff->Typ(), pSchiff->Name(), itoan(pSchiff->Nummer(), g_poCurrentReport->BNrBase()), anzahl, pSchiff->Ladung(), pSchiff->Holz(), + pSchiff->MaxHolz() * count); } else { - COutput::TPrintf("vorlage", " ; An Bord von %s '%s' (%s)%s Kap: %dGE/%dGE(%d%%):\n", pSchiff->Typ().c_str(), pSchiff->Name().c_str(), itoan(pSchiff->Nummer(), g_poCurrentReport->BNrBase()), anzahl.c_str(), pSchiff->MaxLadung() - pSchiff->Ladung(), - pSchiff->MaxLadung(), pSchiff->Schaden()); + COutput::TPrint("vorlage", " ; An Bord von {} '{}' ({}){} Kap: {}GE/{}GE({}%):\n", pSchiff->Typ(), pSchiff->Name(), itoan(pSchiff->Nummer(), g_poCurrentReport->BNrBase()), anzahl, pSchiff->MaxLadung() - pSchiff->Ladung(), + pSchiff->MaxLadung(), pSchiff->Schaden()); } if (IsFlag(VF_SHOWBESCHREIBUNG) && !(pSchiff->Beschreibung().empty())) { WrapOut(" ; ", pSchiff->Beschreibung(), (size_t)g_nLineSize); @@ -2038,7 +2036,7 @@ void CVorlage::SchiffAusgabe(CSchiff* pSchiff) if (!pSchiff->GetKommandos().empty()) { for (int32_t i = 0; i < (int32_t)pSchiff->GetKommandos().size(); i++) { if (pSchiff->GetKommandos()[i].empty()) { - COutput::TPrintf("vorlage", "\n"); + COutput::TWrite("vorlage", "\n"); } else { if (pSchiff->GetKommandos()[i].asString()[0] == ';') { @@ -2156,38 +2154,38 @@ void CVorlage::Einheitenvorlage(CEinheit* poUnit, CReport* poRep2) CMetaCommand::Call("CreateUnitHeader", coOutput); if (!coOutput.empty()) { for (int32_t j = 0; j < (int32_t)coOutput.size(); j++) { - COutput::TPrintf("vorlage", " %s\n", coOutput[j].c_str()); + COutput::TPrint("vorlage", " {}\n", coOutput[j].c_str()); } } } else { // if( IsFlag( VF_BASE36 ) ) if (IsFlag(VF_SHOWVERBOSEINFO)) { - COutput::TPrintf("vorlage", "\n EINHEIT %s; %s [%d,%d$%s] %s%s%s%s%s%s\n", itoan(poUnit->m_nNummer, g_poCurrentReport->ENrBase()), poUnit->m_sName.c_str(), poUnit->m_nAnzahl, poUnit->m_nSilber, getAndReset(out).c_str(), - (!poUnit->WahrerTyp().empty()) ? (poUnit->Typ() + std::string(", ")).c_str() : "", poUnit->m_nParteitarnung ? "parteigetarnt, " : "", poUnit->m_nBewacht ? "bewacht, " : "", - poUnit->m_shp.empty() ? "" : std::string(poUnit->m_shp + ", ").c_str(), pcKampf, (poUnit->m_nHunger) ? ", hungert" : ""); + COutput::TPrint("vorlage", "\n EINHEIT {}; {} [{},{}${}] {}{}{}{}{}{}\n", itoan(poUnit->m_nNummer, g_poCurrentReport->ENrBase()), poUnit->m_sName, poUnit->m_nAnzahl, poUnit->m_nSilber, getAndReset(out), + !poUnit->WahrerTyp().empty() ? poUnit->Typ() + ", " : "", poUnit->m_nParteitarnung ? "parteigetarnt, " : "", poUnit->m_nBewacht ? "bewacht, " : "", + poUnit->m_shp.empty() ? std::string{} : poUnit->m_shp + ", ", pcKampf, poUnit->m_nHunger ? ", hungert" : ""); if (poUnit->m_nVerkleidung) { - COutput::TPrintf("vorlage", " ; Verkleidet als %s (%s)\n", poUnit->Region()->Map()->Report()->Parteiname(poUnit->m_nVerkleidung).substr(1).c_str(), itoan(poUnit->m_nVerkleidung, g_poCurrentReport->PNrBase())); + COutput::TPrint("vorlage", " ; Verkleidet als {} ({})\n", poUnit->Region()->Map()->Report()->Parteiname(poUnit->m_nVerkleidung).substr(1), itoan(poUnit->m_nVerkleidung, g_poCurrentReport->PNrBase())); } if (poUnit->m_nVerraeter) { - COutput::TPrintf("vorlage", " ; VERR\xC4TER!\n"); + COutput::TWrite("vorlage", " ; VERR\xC4TER!\n"); } // else // COutput::TPrintf( "vorlage", "\n EINHEIT %6d; %s [%d,%d$%s] %s%s%s%s%s%s\n", poUnit->m_nNummer, poUnit->m_sName.c_str(), poUnit->m_nAnzahl, poUnit->m_nSilber, Buff, (!poUnit->m_sWahrerTyp.empty())?poUnit->m_sTyp.c_str():"", // poUnit->m_nParteitarnung?"parteigetarnt, ":"", poUnit->m_nBewacht?"bewacht, ":"", poUnit->m_shp.empty()?"":std::string( poUnit->m_shp + ", " ).c_str(), pcKampf, (poUnit->m_nHunger)?", hungert":"" ); } else { - COutput::TPrintf("vorlage", " EINHEIT %s; %s [%d,%d$%s]\n", itoan(poUnit->m_nNummer, g_poCurrentReport->ENrBase()), poUnit->m_sName.c_str(), poUnit->m_nAnzahl, poUnit->m_nSilber, getAndReset(out).c_str()); + COutput::TPrint("vorlage", " EINHEIT {}; {} [{},{}${}]\n", itoan(poUnit->m_nNummer, g_poCurrentReport->ENrBase()), poUnit->m_sName, poUnit->m_nAnzahl, poUnit->m_nSilber, getAndReset(out)); } if (!poUnit->Gruppe().empty() && IsFlag(VF_SHOWVERBOSEINFO)) { WrapOut(" ; In Gruppe: ", poUnit->Gruppe(), (size_t)g_nLineSize); } if (poUnit->CBlockBase::GetValue("hero").asLong() && IsFlag(VF_SHOWVERBOSEINFO)) { - COutput::TPrintf("vorlage", " ; Heldenstatus!\n"); + COutput::TWrite("vorlage", " ; Heldenstatus!\n"); } if (poUnit->GetValue("unaided", "").asLong()) { - COutput::TPrintf("vorlage", " ; Bekommt im Kampf keine Hilfe!\n"); + COutput::TWrite("vorlage", " ; Bekommt im Kampf keine Hilfe!\n"); } if (IsFlag(VF_SHOWBESCHREIBUNG) && !(poUnit->Beschreibung().empty())) { @@ -2362,12 +2360,12 @@ void CVorlage::Einheitenvorlage(CEinheit* poUnit, CReport* poRep2) if (!IsFlag(VF_FULLCOMMANDOUTPUT)) { for (int32_t j = 0; j < (int32_t)poUnit->m_csKommandos.size(); j++) { if (poUnit->m_csMetaOut.empty() || IsFlag(VF_DONTKILLCOMMANDS)) { - COutput::TPrintf("vorlage", " %s\n", poUnit->m_csKommandos[j].c_str()); + COutput::TPrint("vorlage", " {}\n", poUnit->m_csKommandos[j].c_str()); } else { auto p = poUnit->m_csKommandos[j].asString().find_first_not_of(" \t"); if (poUnit->m_csKommandos[j].empty() || (p != std::string::npos && (poUnit->m_csKommandos[j].asString()[p] == '/' || poUnit->m_csKommandos[j].asString()[p] == ';'))) { - COutput::TPrintf("vorlage", " %s\n", poUnit->m_csKommandos[j].c_str()); + COutput::TPrint("vorlage", " {}\n", poUnit->m_csKommandos[j].c_str()); } else { poUnit->m_csKommandos[j] = Value(""); @@ -2381,7 +2379,7 @@ void CVorlage::Einheitenvorlage(CEinheit* poUnit, CReport* poRep2) WrapOut(" ; ", poUnit->m_csMetaOut[j].c_str(), (size_t)g_nLineSize, " "); } else if (!poUnit->m_csMetaOut[j].empty() && poUnit->m_csMetaOut[j].asString()[0] == '/') { - COutput::TPrintf("vorlage", " %s\n", poUnit->m_csMetaOut[j].c_str()); + COutput::TPrint("vorlage", " {}\n", poUnit->m_csMetaOut[j].c_str()); } else { std::string sLine = poUnit->m_csMetaOut[j].c_str(); @@ -2389,11 +2387,11 @@ void CVorlage::Einheitenvorlage(CEinheit* poUnit, CReport* poRep2) size_t nLSize = (size_t)g_nCommandLineSize - 4; while (sLine.length() > nLSize) { if (sLine[nLSize - 2] == ' ') { - COutput::TPrintf("vorlage", " %s%s\\\n", sPref.c_str(), sLine.substr(0, nLSize - 1).c_str()); + COutput::TPrint("vorlage", " {}{}\\\n", sPref, sLine.substr(0, nLSize - 1)); sLine.erase(0, nLSize - 1); } else { - COutput::TPrintf("vorlage", " %s%s\\\n", sPref.c_str(), sLine.substr(0, nLSize - 2).c_str()); + COutput::TPrint("vorlage", " {}{}\\\n", sPref, sLine.substr(0, nLSize - 2)); sLine.erase(0, nLSize - 2); } if (sPref.empty()) { @@ -2401,7 +2399,7 @@ void CVorlage::Einheitenvorlage(CEinheit* poUnit, CReport* poRep2) sPref = " "; } } - COutput::TPrintf("vorlage", " %s%s\n", sPref.c_str(), sLine.c_str()); + COutput::TPrint("vorlage", " {}{}\n", sPref, sLine); } // COutput::TPrintf( "vorlage", " %s\n", poUnit->m_csMetaOut[i].c_str() ); } @@ -2410,7 +2408,7 @@ void CVorlage::Einheitenvorlage(CEinheit* poUnit, CReport* poRep2) for (int32_t j = 0; j < (int32_t)poUnit->m_csKommandos.size(); j++) { auto p = poUnit->m_csKommandos[j].asString().find_first_not_of(" \t"); if (!poUnit->m_csKommandos[j].empty() && p != std::string::npos && poUnit->m_csKommandos[j].asString()[p] != '/') { - COutput::TPrintf("vorlage", " %s\n", poUnit->m_csKommandos[j].c_str()); + COutput::TPrint("vorlage", " {}\n", poUnit->m_csKommandos[j].c_str()); } } } @@ -2427,7 +2425,7 @@ void CVorlage::FremdEinheiten(CEinheit* poUnit, CReport* poRep2) poLU = poRep2 ? poRep2->SearchUnit(poUnit->Nummer(), false) : 0; if (!IsFlag(VF_SHOWUNITSNEW) || !poLU || (poLU && poLU->Region()->GetKey() != poHU->Region()->GetKey()) || (poLU && poHU->Partei() != poLU->Partei())) { - COutput::TPrintf("vorlage", "\n"); + COutput::TWrite("vorlage", "\n"); std::string sPName = g_poCurrentReport->m_coParteien[poUnit->m_nPartei]; if (sPName.empty()) { From 8c5cee42a218a7ca7b1e29b4c7e9241b684f2c1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Schu=CC=88mann?= Date: Thu, 23 Apr 2026 21:07:15 +0200 Subject: [PATCH 4/8] Refactor `CMessage` handling: replace `shared_ptr` with `unique_ptr` and raw pointers to simplify ownership and improve performance. --- EBase/Report.cpp | 97 +++++++++++++++++++++--------------------- EBase/Report.h | 40 +++++------------ EBase/Utility.cpp | 16 +++---- Vorlage/Metascript.cpp | 16 +++---- Vorlage/Zugvorlage.cpp | 4 +- 5 files changed, 78 insertions(+), 95 deletions(-) diff --git a/EBase/Report.cpp b/EBase/Report.cpp index 810a7eb..8a15a1b 100644 --- a/EBase/Report.cpp +++ b/EBase/Report.cpp @@ -2203,7 +2203,7 @@ void CReport::Import(const std::string& sFName) int32_t nUnit = -1; int nBuilding = -1; bool bDrop = false; - CMessage::Ptr pMsg(new CMessage(oRS, m_nRunde)); + auto pMsg = std::make_unique(oRS, m_nRunde); if (inBattle && pMsg->GetValue("region", Value("")).asString().empty()) { pMsg->SetValue("region", Value(battle_x)); pMsg->SetValue("region:1", Value(battle_y)); @@ -2297,7 +2297,7 @@ void CReport::Import(const std::string& sFName) z = pMsg->GetValue("region:2").asLong(); bRegion = true; } - m_cpoMessages.insert(std::make_pair(m_cpoMessages.size(), pMsg)); + m_cpoMessages.push_back(std::move(pMsg)); if (!bDrop && (nAmount || (nBuilding > 0 && ((m_nRunde < 227 && nType == 7835) || (m_nRunde == 227 && nType == -1376149197L) || (m_nRunde > 227 && nType == 761324692L))))) { if (nFrom == Partei()) nAmount = -nAmount; @@ -2537,9 +2537,9 @@ void CReport::Import(const std::string& sFName) } else if (oRS.GetType() == CReportStream::enBLOCK && (oRS.GetValue() == "REGION" || oRS.GetValue() == "DURCHREISEREGION" || oRS.GetValue() == "SPEZIALREGION")) { if (bFirstRegion) { - CMessage::Ptr pMsg(new CMessage(m_nRunde)); + auto pMsg = std::make_unique(m_nRunde); pMsg->SetValue("type", Value(-2)); - m_cpoMessages[m_cpoMessages.size()] = pMsg; + m_cpoMessages.push_back(std::move(pMsg)); bFirstRegion = false; } @@ -2550,12 +2550,12 @@ void CReport::Import(const std::string& sFName) battle_x = oRS.GetDat(0); battle_y = oRS.GetDat(1); battle_z = oRS.GetDat(2); - CMessage::Ptr pMsg(new CMessage(m_nRunde)); + auto pMsg = std::make_unique(m_nRunde); pMsg->SetValue("region", Value(battle_x)); pMsg->SetValue("region:1", Value(battle_y)); pMsg->SetValue("region:2", Value(battle_z)); pMsg->SetValue("type", Value(-1)); - m_cpoMessages[m_cpoMessages.size()] = pMsg; + m_cpoMessages.push_back(std::move(pMsg)); oRS.Next(); while (!oRS.EOS() && (oRS.GetType() != CReportStream::enBLOCK || oRS.GetValue() != "MESSAGE")) oRS.Next(); @@ -2599,72 +2599,72 @@ void CReport::Import(const std::string& sFName) SetMessageSection(-1, "battle"); SetMessageSection(-2, "dummy"); - for (Messages::const_iterator mi = m_cpoMessages.begin(); mi != m_cpoMessages.end(); mi++) { + for (const auto& mi : m_cpoMessages) { + CMessage* pMsg = mi.get(); bUsed = false; - // TRACEMSG(( "%s\n", ((CMessage*)((*mi).second.get()))->Render( this ).c_str() )); - en1 = (*mi).second->GetValue("unit", Value("")).asLong(); - en2 = (*mi).second->GetValue("target", Value("")).asLong(); - en3 = (*mi).second->GetValue("teacher", Value("")).asLong(); - en4 = (*mi).second->GetValue("student", Value("")).asLong(); + en1 = pMsg->GetValue("unit", Value("")).asLong(); + en2 = pMsg->GetValue("target", Value("")).asLong(); + en3 = pMsg->GetValue("teacher", Value("")).asLong(); + en4 = pMsg->GetValue("student", Value("")).asLong(); if (en1) { ui = m_cpoGEinheiten.find(en1); if (ui != m_cpoGEinheiten.end() && (*ui).second->Partei() == Partei()) { - (*ui).second->AddMessage((*mi).second); + (*ui).second->AddMessage(pMsg); bUsed = true; } } if (en2) { ui = m_cpoGEinheiten.find(en2); if (ui != m_cpoGEinheiten.end() && (*ui).second->Partei() == Partei()) { - (*ui).second->AddMessage((*mi).second); + (*ui).second->AddMessage(pMsg); bUsed = true; } } if (en3) { ui = m_cpoGEinheiten.find(en3); if (ui != m_cpoGEinheiten.end() && (*ui).second->Partei() == Partei()) { - (*ui).second->AddMessage((*mi).second); + (*ui).second->AddMessage(pMsg); bUsed = true; } } if (en4) { ui = m_cpoGEinheiten.find(en4); if (ui != m_cpoGEinheiten.end() && (*ui).second->Partei() == Partei()) { - (*ui).second->AddMessage((*mi).second); + (*ui).second->AddMessage(pMsg); bUsed = true; } } if (!bUsed) { - if (!(*mi).second->GetValue("region", Value("")).asString().empty()) { + if (!pMsg->GetValue("region", Value("")).asString().empty()) { int32_t x, y, z; - ((CMessage*)((*mi).second.get()))->GetCoords(/*(*mi).second->GetValue(*/ "region" /*, Value( "" ) ).asString()*/, x, y, z); + pMsg->GetCoords("region", x, y, z); CRegion* pReg = GetMap()->GetFromECords(x, y, z); if (pReg) { - pReg->AddMessage((*mi).second); + pReg->AddMessage(pMsg); bUsed = true; } } - if (!(*mi).second->GetValue("start", Value("")).asString().empty()) { + if (!pMsg->GetValue("start", Value("")).asString().empty()) { int32_t x, y, z; - ((CMessage*)((*mi).second.get()))->GetCoords(/*(*mi).second->GetValue(*/ "start" /*, Value( "" ) ).asString()*/, x, y, z); + pMsg->GetCoords("start", x, y, z); CRegion* pReg = GetMap()->GetFromECords(x, y, z); if (pReg) { - pReg->AddMessage((*mi).second); + pReg->AddMessage(pMsg); bUsed = true; } } - if (!(*mi).second->GetValue("end", Value("")).asString().empty()) { + if (!pMsg->GetValue("end", Value("")).asString().empty()) { int32_t x, y, z; - ((CMessage*)((*mi).second.get()))->GetCoords(/*(*mi).second->GetValue( */ "end" /*, Value( "" ) ).asString()*/, x, y, z); + pMsg->GetCoords("end", x, y, z); CRegion* pReg = GetMap()->GetFromECords(x, y, z); if (pReg) { - pReg->AddMessage((*mi).second); + pReg->AddMessage(pMsg); bUsed = true; } } } if (bUsed) { - (*mi).second->SetValue("_used", Value(1)); + pMsg->SetValue("_used", Value(1)); } } @@ -2821,52 +2821,53 @@ void CReport::CalculateStatistics() m_nEinkommen = m_nMsgEinkommen; m_nAusgaben = m_nMsgAusgaben; - for (Messages::const_iterator mi = m_cpoMessages.begin(); mi != m_cpoMessages.end(); mi++) { + for (const auto& mi : m_cpoMessages) { + const CMessage* pMsg = mi.get(); if (m_nRunde < 227) { - switch ((*mi).second->GetValue("type").asLong()) { + switch (pMsg->GetValue("type").asLong()) { case 581: - nP1 = PNrFromENr((*mi).second->GetValue("unit").asLong()); - nP2 = PNrFromENr((*mi).second->GetValue("target").asLong()); + nP1 = PNrFromENr(pMsg->GetValue("unit").asLong()); + nP2 = PNrFromENr(pMsg->GetValue("target").asLong()); if (nP1 != nP2) { if (nP1 == m_nPartei) - InsertHandel(nP2, -(*mi).second->GetValue("amount").asLong(), (*mi).second->GetValue("resource").asString()); + InsertHandel(nP2, -pMsg->GetValue("amount").asLong(), pMsg->GetValue("resource").asString()); else - InsertHandel(nP1, (*mi).second->GetValue("amount").asLong(), (*mi).second->GetValue("resource").asString()); + InsertHandel(nP1, pMsg->GetValue("amount").asLong(), pMsg->GetValue("resource").asString()); } break; case 9386: - nP1 = (*mi).second->GetValue("from").asLong(); - nP2 = (*mi).second->GetValue("to").asLong(); + nP1 = pMsg->GetValue("from").asLong(); + nP2 = pMsg->GetValue("to").asLong(); if (nP1 != nP2) { if (nP1 == m_nPartei) - InsertHandel(nP2, -(*mi).second->GetValue("amount").asLong(), (*mi).second->GetValue("resource", Value("Silber")).asString()); + InsertHandel(nP2, -pMsg->GetValue("amount").asLong(), pMsg->GetValue("resource", Value("Silber")).asString()); else - InsertHandel(nP1, (*mi).second->GetValue("amount").asLong(), (*mi).second->GetValue("resource", Value("Silber")).asString()); + InsertHandel(nP1, pMsg->GetValue("amount").asLong(), pMsg->GetValue("resource", Value("Silber")).asString()); } break; } } else if (m_nRunde >= 227) { - switch ((*mi).second->GetValue("type").asLong()) { + switch (pMsg->GetValue("type").asLong()) { case 5281483: case 1235024123: - nP1 = PNrFromENr((*mi).second->GetValue("unit").asLong()); - nP2 = PNrFromENr((*mi).second->GetValue("target").asLong()); + nP1 = PNrFromENr(pMsg->GetValue("unit").asLong()); + nP2 = PNrFromENr(pMsg->GetValue("target").asLong()); if (nP1 != nP2) { if (nP1 == m_nPartei) - InsertHandel(nP2, -(*mi).second->GetValue("amount").asLong(), (*mi).second->GetValue("resource").asString()); + InsertHandel(nP2, -pMsg->GetValue("amount").asLong(), pMsg->GetValue("resource").asString()); else - InsertHandel(nP1, (*mi).second->GetValue("amount").asLong(), (*mi).second->GetValue("resource").asString()); + InsertHandel(nP1, pMsg->GetValue("amount").asLong(), pMsg->GetValue("resource").asString()); } break; case 1682429624: - nP1 = (*mi).second->GetValue("from").asLong(); - nP2 = (*mi).second->GetValue("to").asLong(); + nP1 = pMsg->GetValue("from").asLong(); + nP2 = pMsg->GetValue("to").asLong(); if (nP1 != nP2) { if (nP1 == m_nPartei) - InsertHandel(nP2, -(*mi).second->GetValue("amount").asLong(), (*mi).second->GetValue("resource", Value("Silber")).asString()); + InsertHandel(nP2, -pMsg->GetValue("amount").asLong(), pMsg->GetValue("resource", Value("Silber")).asString()); else - InsertHandel(nP1, (*mi).second->GetValue("amount").asLong(), (*mi).second->GetValue("resource", Value("Silber")).asString()); + InsertHandel(nP1, pMsg->GetValue("amount").asLong(), pMsg->GetValue("resource", Value("Silber")).asString()); } break; } @@ -3624,9 +3625,9 @@ CRegion::CRegion(CReportStream& oRS, CKarte* poMap, int nRunde, int32_t nPos) oRS.Next(); } else if (oRS.GetValue() == "MESSAGE") { - CMessage::Ptr pMsg(new CMessage(oRS, m_nRunde)); - // m_cpoMessages.push_back( pMsg ); - Map()->Report()->AddMessage(pMsg); + auto pMsgOwned = std::make_unique(oRS, m_nRunde); + CMessage* pMsg = pMsgOwned.get(); + Map()->Report()->AddMessage(std::move(pMsgOwned)); if (IsEqual(Map()->Report()->m_sSpiel, "eressea") && pMsg->GetValue("type").asLong() == 1638122429) m_bVerorkt = true; pMsg->SetValue(std::string("localmsg"), Value(1)); diff --git a/EBase/Report.h b/EBase/Report.h index 3b5fae7..500b311 100644 --- a/EBase/Report.h +++ b/EBase/Report.h @@ -320,8 +320,6 @@ class CBuildingInfo : public CBlockBase class CMessage : public CBlockBase { public: - typedef std::shared_ptr Ptr; - enum RENDERER { NONE, ERESSEA1, ERESSEA2 }; CMessage(int32_t round); @@ -536,7 +534,7 @@ class CReport : public CBlockBase friend class CRegion; friend class CVorlage; - typedef std::map Messages; + using Messages = std::vector>; typedef std::pair Nachricht; typedef std::map Parteien; typedef std::map ParteiInfos; @@ -674,17 +672,11 @@ class CReport : public CBlockBase size_t NumMessage() const { return m_cpoMessages.size(); } - void AddMessage(CMessage::Ptr pMsg) { m_cpoMessages[m_cpoMessages.size()] = pMsg; } + void AddMessage(std::unique_ptr pMsg) { m_cpoMessages.push_back(std::move(pMsg)); } - CMessage::Ptr GetMessage(size_t nID) + CMessage* GetMessage(size_t nID) { - Messages::iterator mi = m_cpoMessages.find(nID); - if (mi != m_cpoMessages.end()) { - return (*mi).second; - } - else { - return CMessage::Ptr(); - } + return nID < m_cpoMessages.size() ? m_cpoMessages[nID].get() : nullptr; } size_t NumNachrichten() const { return m_csNachrichten.size(); } @@ -890,7 +882,7 @@ class DummyRegion : public CBlockBase typedef std::vector VResourcen; typedef std::vector Durchreisen; typedef std::list Botschaften; - typedef std::list Messages; + using Messages = std::vector; typedef std::pair Luxusgut; typedef std::vector Luxusgueter; typedef std::map Materialpool; @@ -973,7 +965,7 @@ class CRegion : public CBlockBase typedef std::vector VResourcen; typedef std::vector Durchreisen; typedef std::list Botschaften; - typedef std::list Messages; + using Messages = std::vector; typedef std::pair Luxusgut; typedef std::vector Luxusgueter; typedef std::map Materialpool; @@ -1165,23 +1157,13 @@ class CRegion : public CBlockBase void AddMessage(const std::string& sTxt) { m_coBotschaften.push_back(sTxt); } - void AddMessage(CMessage::Ptr pMsg) { m_cpoMessages.push_back(pMsg); } + void AddMessage(CMessage* pMsg) { m_cpoMessages.push_back(pMsg); } size_t NumMessage() const { return m_cpoMessages.size(); } - CMessage::Ptr GetMessage(int32_t nID) + CMessage* GetMessage(int32_t nID) { - Messages::iterator mi = m_cpoMessages.begin(); - while (mi != m_cpoMessages.end() && nID) { - nID--; - mi++; - } - if (mi != m_cpoMessages.end()) { - return (*mi); - } - else { - return CMessage::Ptr(); - } + return (nID >= 0 && size_t(nID) < m_cpoMessages.size()) ? m_cpoMessages[nID] : nullptr; } const Effects& GetEffects() const { return m_coEffects; } @@ -1550,7 +1532,7 @@ class CEinheit : public CBlockBase typedef std::vector Gegenstaende; typedef std::vector Botschaften; typedef std::vector Sprueche; - typedef std::list Messages; + using Messages = std::vector; typedef std::vector Kampfzauber; CEinheit(CReportStream& oRS, CRegion* poRegion); @@ -1632,7 +1614,7 @@ class CEinheit : public CBlockBase void AddMessage(std::string sMsg) { m_coBotschaften.push_back(sMsg); } - void AddMessage(CMessage::Ptr pMsg) { m_cpoMessages.push_back(pMsg); } + void AddMessage(CMessage* pMsg) { m_cpoMessages.push_back(pMsg); } void AddMaterialpool(CRegion::Materialpool& coPool, bool bSearchable); diff --git a/EBase/Utility.cpp b/EBase/Utility.cpp index a666725..3e05476 100644 --- a/EBase/Utility.cpp +++ b/EBase/Utility.cpp @@ -2083,7 +2083,7 @@ COutput::COutput(const std::string& sFileName, bool bFlushed) , m_hFile(0) , m_poRoute(0) { - std::map::const_iterator di = g_cpoDestinations.find(sFileName); + auto di = g_cpoDestinations.find(sFileName); if (di == g_cpoDestinations.end()) { m_hFile = fopen(sFileName.c_str(), "w"); if (m_hFile) { @@ -2215,7 +2215,7 @@ extern bool DoUserFunction(const std::string& sName, ArgumentList& coArgs, Value void COutput::FilterWrite(const char* pcTxt) { - std::map::iterator i = g_csFilter.find(m_sTargetName); + auto i = g_csFilter.find(m_sTargetName); if (i != g_csFilter.end()) { ArgumentList coArgs; Value oVal; @@ -2239,7 +2239,7 @@ void COutput::FilterWrite(const char* pcTxt) void COutput::Write(const char* pcTxt) { - std::map::iterator i = g_csFilter.find(m_sTargetName); + auto i = g_csFilter.find(m_sTargetName); if (i == g_csFilter.end()) { DoWrite(pcTxt); return; @@ -2293,7 +2293,7 @@ void COutput::TPrintf(const std::string& sID, const char* msg, ...) void COutput::CloseTargets() { - std::map::iterator ti = g_cpoTargets.begin(); + auto ti = g_cpoTargets.begin(); std::list cpoHelp; while (ti != g_cpoTargets.end()) { @@ -2305,7 +2305,7 @@ void COutput::CloseTargets() } } g_cpoTargets.clear(); - std::list::iterator hi = cpoHelp.begin(); + auto hi = cpoHelp.begin(); while (hi != cpoHelp.end()) { delete (*hi++); } @@ -2315,7 +2315,7 @@ void COutput::CloseTargets() void COutput::SetTarget(const std::string& sID, COutput* poTarget) { - std::map::iterator ti = g_cpoTargets.find(sID); + auto ti = g_cpoTargets.find(sID); poTarget->m_sTargetName = sID; if (ti == g_cpoTargets.end()) { @@ -2341,7 +2341,7 @@ void COutput::SetFilter(const std::string& sID, const std::string& sFilter) void COutput::RenameTarget(const std::string& sIDOld, const std::string& sIDNew) { - std::map::iterator ti = g_cpoTargets.find(sIDOld); + auto ti = g_cpoTargets.find(sIDOld); COutput* poTarget; if (ti != g_cpoTargets.end()) { poTarget = (*ti).second; @@ -2352,7 +2352,7 @@ void COutput::RenameTarget(const std::string& sIDOld, const std::string& sIDNew) COutput* COutput::Target(const std::string& sID) { - std::map::const_iterator ti = g_cpoTargets.find(sID); + auto ti = g_cpoTargets.find(sID); if (ti == g_cpoTargets.end()) { SetTarget(sID, new COutput(stderr)); ERRMSG(0, ("FEHLER: Der interne Ausgabekanal '%s' wurde nicht gefunden!", sID.c_str())); diff --git a/Vorlage/Metascript.cpp b/Vorlage/Metascript.cpp index 34b9ba6..427dc28 100644 --- a/Vorlage/Metascript.cpp +++ b/Vorlage/Metascript.cpp @@ -644,16 +644,16 @@ Value DoReport(CObjectPart* poPart) return oVal; } if (g_poCurrentReport->NumMessage()) { - CMessage::Ptr pMsg = g_poCurrentReport->GetMessage((size_t)pOP->index[0].asLong()); + CMessage* pMsg = g_poCurrentReport->GetMessage((size_t)pOP->index[0].asLong()); if (!pOP->next) { - return pMsg.get() ? Value(1) : Value(0); + return pMsg ? Value(1) : Value(0); } - if (!pMsg.get()) { + if (!pMsg) { oVal.error("Index von REPORT.MESSAGE[] korrupt"); return oVal; } if (IsEqual(pOP->next->label.c_str(), "rendered")) { - return Value(((CMessage*)(pMsg.get()))->Render(g_poCurrentReport)); + return Value(pMsg->Render(g_poCurrentReport)); } else if (IsEqual(pOP->next->label.c_str(), "section")) { return (*(g_poCurrentReport->MessageSections()))[pMsg->GetValue("type", Value(0)).asLong()]; @@ -1132,16 +1132,16 @@ Value _DoRegion(CObjectPart* poPart, CRegion* pReg, CRegion* pRegQ) return oVal; } if (pReg->NumMessage()) { - CMessage::Ptr pMsg = pReg->GetMessage(pOP->index[0].asLong()); + CMessage* pMsg = pReg->GetMessage(pOP->index[0].asLong()); if (!pOP->next) { - return pMsg.get() ? Value(1) : Value(0); + return pMsg ? Value(1) : Value(0); } - if (!pMsg.get()) { + if (!pMsg) { oVal.error("Index von REGION.MESSAGE[] korrupt"); return oVal; } if (IsEqual(pOP->next->label.c_str(), "rendered")) { - return Value(((CMessage*)(pMsg.get()))->Render(g_poCurrentReport)); + return Value(pMsg->Render(g_poCurrentReport)); } else if (IsEqual(pOP->next->label.c_str(), "section")) { return (*(g_poCurrentReport->MessageSections()))[pMsg->GetValue("type", Value(0)).asLong()]; diff --git a/Vorlage/Zugvorlage.cpp b/Vorlage/Zugvorlage.cpp index 27e5e20..061fe16 100644 --- a/Vorlage/Zugvorlage.cpp +++ b/Vorlage/Zugvorlage.cpp @@ -2249,8 +2249,8 @@ void CVorlage::Einheitenvorlage(CEinheit* poUnit, CReport* poRep2) WrapOut(" ; ", (*bi), (size_t)g_nLineSize, " ; "); // COutput::TPrintf( "vorlage", " ; %s\n", (*bi).c_str() ); } - for (CEinheit::Messages::const_iterator mi = poUnit->m_cpoMessages.begin(); mi != poUnit->m_cpoMessages.end(); mi++) { - WrapOut(" ; ", ((CMessage*)((*mi).get()))->Render(g_poCurrentReport), (size_t)g_nLineSize, " ; > "); + for (CMessage* mi : poUnit->m_cpoMessages) { + WrapOut(" ; ", mi->Render(g_poCurrentReport), (size_t)g_nLineSize, " ; > "); } } From dadb546dc129f688b7b0aacdd6427fac5a35a808 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Schu=CC=88mann?= Date: Fri, 24 Apr 2026 09:17:40 +0200 Subject: [PATCH 5/8] Refactored output calls to use `COutput::Target` for consistency and improved code maintainability. --- EBase/Utility.h | 9 +- Vorlage/Zugvorlage.cpp | 187 +++++++++++++++++++++-------------------- 2 files changed, 102 insertions(+), 94 deletions(-) diff --git a/EBase/Utility.h b/EBase/Utility.h index 8257d97..e7a4064 100644 --- a/EBase/Utility.h +++ b/EBase/Utility.h @@ -337,16 +337,17 @@ class COutput void Write(const char* pcTxt); void Write(const std::string& sTxt); void Printf(const char* msg, ...); + template + void Print(fmt::format_string fmt, Args&&... args) + { + Write(fmt::format(fmt, std::forward(args)...)); + } bool Disconnect(bool bSuicide = true); static void TWrite(const std::string& sID, const std::string& sTxt); static void TPrintf(const std::string& sID, const char* msg, ...); - // Compile-time-safe formatted output via fmtlib. - // fmt::format_string validates the format string and argument types - // at compile time — wrong types or argument count are caught as errors, not - // as runtime crashes or silent truncation like TPrintf. template static void TPrint(const std::string& sID, fmt::format_string fmt, Args&&... args) { diff --git a/Vorlage/Zugvorlage.cpp b/Vorlage/Zugvorlage.cpp index 061fe16..b7bd112 100644 --- a/Vorlage/Zugvorlage.cpp +++ b/Vorlage/Zugvorlage.cpp @@ -224,8 +224,9 @@ static void WrapOut(const std::string& sPfx, const std::string& sText, size_t nL int c = 0; if (sFirstPfx.empty()) sFPfx = sPfx; + auto target = COutput::Target("vorlage"); do { - COutput::TPrint("vorlage", "{}{}\n", c ? sPfx : sFPfx, Wrap(sTxt, nLen - (c ? sPfx.size() : sFPfx.size()))); + target->Print("{}{}\n", c ? sPfx : sFPfx, Wrap(sTxt, nLen - (c ? sPfx.size() : sFPfx.size()))); c++; } while (!sTxt.empty()); } @@ -826,10 +827,11 @@ void CVorlage::Vorlage(CReport& oReport, CReport* poRep2, bool bTime) } m_nUnits = nUnits; - COutput::TPrint("vorlage", "{} {} \"{}\"\n", IsEqual(g_poCurrentReport->m_sSpiel, "eressea") ? "ERESSEA" : "PARTEI", itoan(oReport.Partei(), oReport.PNrBase()), oReport.Passwort()); + auto* target = COutput::Target("vorlage"); + target->Print("{} {} \"{}\"\n", IsEqual(g_poCurrentReport->m_sSpiel, "eressea") ? "ERESSEA" : "PARTEI", itoan(oReport.Partei(), oReport.PNrBase()), oReport.Passwort()); if (IsEqual(g_poCurrentReport->m_sSpiel, "eressea") || IsEqual(g_poCurrentReport->m_sSpiel, "empiria") || IsEqual(g_poCurrentReport->m_sSpiel, "vinyambar i") || IsEqual(g_poCurrentReport->m_sSpiel, "vinyambar ii")) - COutput::TPrint("vorlage", "\n ; ECHECK -l -w4 -r{}\n", oReport.Rekrutierungskosten()); - COutput::TPrint("vorlage", "\n ; {}, (C) 1999-2026 by S.Schuemann\n ; [{} {}]\n", VERSIONINFO, __DATE__, __TIME__); + target->Print("\n ; ECHECK -l -w4 -r{}\n", oReport.Rekrutierungskosten()); + target->Print("\n ; {}, (C) 1999-2026 by S.Schuemann\n ; [{} {}]\n", VERSIONINFO, __DATE__, __TIME__); WrapOut(" ; ", g_sCmdOptions, (size_t)g_nLineSize, " ; "); if (poRep2 && oReport.Version() != poRep2->Version()) { std::ostringstream out; @@ -837,13 +839,13 @@ void CVorlage::Vorlage(CReport& oReport, CReport* poRep2, bool bTime) auto msg = out.str(); if (bTime) TRACEMSG(("%s\n", msg.c_str())); - COutput::TPrint("vorlage", " ; {}\n", msg); + target->Print(" ; {}\n", msg); } if (oReport.Zeitalter() == 1) - COutput::TPrint("vorlage", "\n ; Zugvorlage aus Report Runde {} ({} {})\n", oReport.Runde(), pcJahr[(oReport.Runde()) % 12], (oReport.Runde() - 1) / 12 + 1); + target->Print("\n ; Zugvorlage aus Report Runde {} ({} {})\n", oReport.Runde(), pcJahr[(oReport.Runde()) % 12], (oReport.Runde() - 1) / 12 + 1); else - COutput::TPrint("vorlage", "\n ; Zugvorlage aus Report Runde {} ({}. Woche, {}, {})\n", oReport.Runde(), (oReport.Runde() - 184) % 3 + 1, pcJahr2[((oReport.Runde() - 184) / 3) % 9], (oReport.Runde() - 184) / 27 + 1); + target->Print("\n ; Zugvorlage aus Report Runde {} ({}. Woche, {}, {})\n", oReport.Runde(), (oReport.Runde() - 184) % 3 + 1, pcJahr2[((oReport.Runde() - 184) / 3) % 9], (oReport.Runde() - 184) / 27 + 1); CPartei::Ptr parteiInfo = oReport.GetLocalParteiInfo(oReport.Partei()); CPartei::Ptr lastParteiInfo; @@ -860,10 +862,10 @@ void CVorlage::Vorlage(CReport& oReport, CReport* poRep2, bool bTime) if (oReport.m_nPunkte > 0 && oReport.m_nPunkteschnitt > 0) { if (!poRep2) { if (maxHeroes > 0) - COutput::TPrint("vorlage", " ; Personen: {}, Einheiten: {}, Helden: {}/{}\n", nPersons, nUnits, heroes, maxHeroes); + target->Print(" ; Personen: {}, Einheiten: {}, Helden: {}/{}\n", nPersons, nUnits, heroes, maxHeroes); else - COutput::TPrint("vorlage", " ; Personen: {}, Einheiten: {}\n", nPersons, nUnits); - COutput::TPrint("vorlage", " ; Punkte: {} ({:.2f}% des Durchschnitts)\n", oReport.m_nPunkte, (double)oReport.m_nPunkte * 100.0 / oReport.m_nPunkteschnitt); + target->Print(" ; Personen: {}, Einheiten: {}\n", nPersons, nUnits); + target->Print(" ; Punkte: {} ({:.2f}% des Durchschnitts)\n", oReport.m_nPunkte, (double)oReport.m_nPunkte * 100.0 / oReport.m_nPunkteschnitt); } else { int32_t nLastUnits = 0, nLastPersons = 0; @@ -883,15 +885,15 @@ void CVorlage::Vorlage(CReport& oReport, CReport* poRep2, bool bTime) if (lastParteiInfo) lastHeroes = lastParteiInfo->GetValue("heroes").asLong(); if (maxHeroes > 0) - COutput::TPrint("vorlage", " ; Personen: {} ({:+}), Einheiten: {} ({:+}), Helden: {}/{} ({:+}/{:+})\n", nPersons, nPersons - nLastPersons, nUnits, nUnits - nLastUnits, heroes, maxHeroes, heroes - lastHeroes, maxHeroes - lastMaxHeroes); + target->Print(" ; Personen: {} ({:+}), Einheiten: {} ({:+}), Helden: {}/{} ({:+}/{:+})\n", nPersons, nPersons - nLastPersons, nUnits, nUnits - nLastUnits, heroes, maxHeroes, heroes - lastHeroes, maxHeroes - lastMaxHeroes); else - COutput::TPrint("vorlage", " ; Personen: {} ({:+}), Einheiten: {} ({:+})\n", nPersons, nPersons - nLastPersons, nUnits, nUnits - nLastUnits); + target->Print(" ; Personen: {} ({:+}), Einheiten: {} ({:+})\n", nPersons, nPersons - nLastPersons, nUnits, nUnits - nLastUnits); if (poRep2->m_nPunkte) - COutput::TPrint("vorlage", " ; Punkte: {} ({:.2f}% des Durchschnitts, {:+.2f}%)\n", oReport.m_nPunkte, (double)oReport.m_nPunkte * 100.0 / oReport.m_nPunkteschnitt, + target->Print(" ; Punkte: {} ({:.2f}% des Durchschnitts, {:+.2f}%)\n", oReport.m_nPunkte, (double)oReport.m_nPunkte * 100.0 / oReport.m_nPunkteschnitt, (double)oReport.m_nPunkte * 100.0 / oReport.m_nPunkteschnitt - (double)poRep2->m_nPunkte * 100.0 / poRep2->m_nPunkteschnitt); else - COutput::TPrint("vorlage", " ; Punkte: {} ({:.2f}% des Durchschnitts)\n", oReport.m_nPunkte, (double)oReport.m_nPunkte * 100.0 / oReport.m_nPunkteschnitt); + target->Print(" ; Punkte: {} ({:.2f}% des Durchschnitts)\n", oReport.m_nPunkte, (double)oReport.m_nPunkte * 100.0 / oReport.m_nPunkteschnitt); } } @@ -966,7 +968,7 @@ void CVorlage::Vorlage(CReport& oReport, CReport* poRep2, bool bTime) if (!m_coInitCmd.empty()) { for (int32_t i = 0; i < (int32_t)m_coInitCmd.size(); i++) { if (m_coInitCmd[i].empty()) { - COutput::TWrite("vorlage", "\n"); + target->Write("\n"); } else { if (m_coInitCmd[i].asString()[0] == ';') @@ -976,17 +978,17 @@ void CVorlage::Vorlage(CReport& oReport, CReport* poRep2, bool bTime) } if (IsFlag(VF_SHOWHANDEL)) { - COutput::TWrite("vorlage", "\n ; Wirtschaftsbilanz:\n"); - COutput::TPrint("vorlage", " ; Gesamteinkommen:{:9} Silber\n", oReport.m_nEinkommen); - COutput::TPrint("vorlage", " ; Gesamtausgaben: {:9} Silber {}\n", oReport.m_nAusgaben + nNeededFood /*Eater*10*/, oReport.Version() > 40 ? "" : "(z.Zt. ohne kostenpfl. Talente)"); + target->Write("\n ; Wirtschaftsbilanz:\n"); + target->Print(" ; Gesamteinkommen:{:9} Silber\n", oReport.m_nEinkommen); + target->Print(" ; Gesamtausgaben: {:9} Silber {}\n", oReport.m_nAusgaben + nNeededFood /*Eater*10*/, oReport.Version() > 40 ? "" : "(z.Zt. ohne kostenpfl. Talente)"); int64_t nVermoegen = 0; for (CKarte::RegionMap::const_iterator rmi = m_poKarte->Regions().begin(); rmi != m_poKarte->Regions().end(); rmi++) { nVermoegen += (*rmi).second->SilverOf(oReport.Partei()); } - COutput::TPrint("vorlage", " ; Gesamtverm\xF6gen: {:9} Silber\n", nVermoegen); + target->Print(" ; Gesamtverm\xF6gen: {:9} Silber\n", nVermoegen); if (oReport.m_cpoHPartner.size()) - COutput::TWrite("vorlage", "\n ; Warenaustausch:\n"); + target->Write("\n ; Warenaustausch:\n"); for (CReport::Handelspartner::const_iterator rhi = oReport.m_cpoHPartner.begin(); rhi != oReport.m_cpoHPartner.end(); rhi++) { std::ostringstream out; @@ -1012,12 +1014,12 @@ void CVorlage::Vorlage(CReport& oReport, CReport* poRep2, bool bTime) std::stable_sort(cpoRegions.begin(), cpoRegions.end(), CRegionSorter(IsFlag(VF_SORTISLANDS))); if (IsFlag(VF_SHOWKOMPKARTE)) { - COutput::TWrite("vorlage", "\n ; Uebersichtskarte:\n"); + target->Write("\n ; Uebersichtskarte:\n"); oReport.Karte()->DumpFullMap("vorlage", " ; "); } if (IsFlag(VF_SHOWWORLDKARTE)) { - COutput::TWrite("vorlage", "\n ; Karte der bekannten Welt:\n"); + target->Write("\n ; Karte der bekannten Welt:\n"); oReport.Karte()->DumpWorldMap("vorlage", " ; "); } @@ -1039,12 +1041,12 @@ void CVorlage::Vorlage(CReport& oReport, CReport* poRep2, bool bTime) } } - COutput::TWrite("vorlage", "\n NAECHSTER\n\n"); + target->Write("\n NAECHSTER\n\n"); if (!m_coExitCmd.empty()) { for (int32_t i = 0; i < (int32_t)m_coExitCmd.size(); i++) { if (m_coExitCmd[i].empty()) { - COutput::TWrite("vorlage", "\n"); + target->Write("\n"); } else { if (m_coExitCmd[i].asString()[0] == ';') @@ -1091,15 +1093,15 @@ void CVorlage::Vorlage(CReport& oReport, CReport* poRep2, bool bTime) if (!bKonfiguration && sLine.length() > 15 && CRegExp::Match(sLine, "^(\"[^\"]*\"\\s*;\\s*(?i:Konfiguration)|[A-Z]+)")) { bKonfiguration = true; if (CRegExp::Match(sLine, "^\"[^\"]*\"\\s*;\\s*(?i:Konfiguration)")) { - COutput::TWrite("vorlage", "\"Vorlage\";Konfiguration\n"); + target->Write("\"Vorlage\";Konfiguration\n"); } else { - COutput::TWrite("vorlage", "\"Vorlage\";Konfiguration\n"); - COutput::TPrint("vorlage", "{}\n", sLine); + target->Write("\"Vorlage\";Konfiguration\n"); + target->Print("{}\n", sLine); } } else { - COutput::TPrint("vorlage", "{}\n", sLine); + target->Print("{}\n", sLine); } if (!strncmp(sLine.c_str(), "REGION ", 7)) { @@ -1154,7 +1156,7 @@ void CVorlage::Vorlage(CReport& oReport, CReport* poRep2, bool bTime) for (int32_t i = 0; i < (int32_t)poUnit->m_csKommandos.size(); i++) { std::string strVal = Escape(poUnit->m_csKommandos[i].asString(), true); if (!poUnit->m_csKommandos[i].empty()) - COutput::TPrint("vorlage", "\"{}\"\n", oReport.m_bUTF8 ? iso885915ToUtf8(strVal) : strVal); + target->Print("\"{}\"\n", oReport.m_bUTF8 ? iso885915ToUtf8(strVal) : strVal); } } @@ -1173,11 +1175,11 @@ void CVorlage::Vorlage(CReport& oReport, CReport* poRep2, bool bTime) sCmd.erase(sCmd.size() - 1, 1); } std::string strVal = Escape(sCmd, true); - COutput::TPrint("vorlage", "\"{}\"\n", oReport.m_bUTF8 ? iso885915ToUtf8(strVal) : strVal); + target->Print("\"{}\"\n", oReport.m_bUTF8 ? iso885915ToUtf8(strVal) : strVal); } if (poUnit->m_csMetaOut.empty() && (poUnit->m_csKommandos.empty() || IsFlag(VF_FULLCOMMANDOUTPUT))) { - COutput::TWrite("vorlage", "\"\"\n"); + target->Write("\"\"\n"); } bGotLine = true; @@ -1274,6 +1276,7 @@ void CVorlage::Regionsvorlage(CRegion* poReg, CRegion* poReg2, CReport* poRep2) CRegion::VEinheiten* poVE = &poReg->GetVEinheiten(); m_poCurrentRegion = poReg; g_poCurrentRegion = poReg; + auto* target = COutput::Target("vorlage"); if (poReg->GetVBauwerke()) { coBauwerke.insert(poReg->GetVBauwerke()->begin(), poReg->GetVBauwerke()->end()); @@ -1310,17 +1313,17 @@ void CVorlage::Regionsvorlage(CRegion* poReg, CRegion* poReg2, CReport* poRep2) } if (!bRegHead) { if (IsFlag(VF_SHOWVERBOSEINFO)) { - COutput::TWrite("vorlage", "\n; --------------------------------------------------------------\n\n"); + target->Write("\n; --------------------------------------------------------------\n\n"); } else { - COutput::TWrite("vorlage", "\n"); + target->Write("\n"); } if (CMetaCommand::ProcExists("CreateRegionHeader")) { VKommandos coOutput; CMetaCommand::Call("CreateRegionHeader", coOutput); if (!coOutput.empty()) { for (size_t j = 0; j < coOutput.size(); j++) { - COutput::TPrint("vorlage", " {}\n", coOutput[(int32_t)j].c_str()); + target->Print(" {}\n", coOutput[(int32_t)j].c_str()); } } } @@ -1328,45 +1331,45 @@ void CVorlage::Regionsvorlage(CRegion* poReg, CRegion* poReg2, CReport* poRep2) if (IsEqual(g_poCurrentReport->m_sSpiel, "Verdanon")) { if (!IsFlag(VF_SHOWVERBOSEINFO)) { if (poReg->GetEZ()) { - COutput::TPrint("vorlage", " ; {} ({},{},{})\n", poReg->GetName().empty() ? poReg->GetRegionTypeName() : poReg->GetName(), poReg->GetEX(), poReg->GetEY(), poReg->GetEZ()); + target->Print(" ; {} ({},{},{})\n", poReg->GetName().empty() ? poReg->GetRegionTypeName() : poReg->GetName(), poReg->GetEX(), poReg->GetEY(), poReg->GetEZ()); } else { - COutput::TPrint("vorlage", " ; {} ({},{})\n", poReg->GetName().empty() ? poReg->GetRegionTypeName() : poReg->GetName(), poReg->GetEX(), poReg->GetEY()); + target->Print(" ; {} ({},{})\n", poReg->GetName().empty() ? poReg->GetRegionTypeName() : poReg->GetName(), poReg->GetEX(), poReg->GetEY()); } } else if (poReg->GetBlock() == CRegion::enSPEZIALREGION) { - COutput::TPrint("vorlage", " ; Astralebene ({}, {} Personen, {}$ Silber)\n", poReg->GetRegionTypeName(), poReg->PersonsOf(m_nPlayer, true), poReg->SilverOf(m_nPlayer)); + target->Print(" ; Astralebene ({}, {} Personen, {}$ Silber)\n", poReg->GetRegionTypeName(), poReg->PersonsOf(m_nPlayer, true), poReg->SilverOf(m_nPlayer)); } else if (poReg->GetEZ()) { - COutput::TPrint("vorlage", " ; {} ({},{},{}) ({}, {} Personen, {}$ Silber) {}\n", poReg->GetName(), poReg->GetEX(), poReg->GetEY(), poReg->GetEZ(), poReg->GetRegionTypeName(), poReg->PersonsOf(m_nPlayer, true), + target->Print(" ; {} ({},{},{}) ({}, {} Personen, {}$ Silber) {}\n", poReg->GetName(), poReg->GetEX(), poReg->GetEY(), poReg->GetEZ(), poReg->GetRegionTypeName(), poReg->PersonsOf(m_nPlayer, true), poReg->SilverOf(m_nPlayer), sInsel); } else { - COutput::TPrint("vorlage", " ; {} ({},{}) ({}, {} Personen, {}$ Silber) {}\n", poReg->GetName(), poReg->GetEX(), poReg->GetEY(), poReg->GetRegionTypeName(), poReg->PersonsOf(m_nPlayer, true), + target->Print(" ; {} ({},{}) ({}, {} Personen, {}$ Silber) {}\n", poReg->GetName(), poReg->GetEX(), poReg->GetEY(), poReg->GetRegionTypeName(), poReg->PersonsOf(m_nPlayer, true), poReg->SilverOf(m_nPlayer), sInsel); } } else { if (!IsFlag(VF_SHOWVERBOSEINFO)) { if (poReg->GetEZ()) { - COutput::TPrint("vorlage", " REGION {},{},{} ; {}\n", poReg->GetEX(), poReg->GetEY(), poReg->GetEZ(), poReg->GetName().empty() ? poReg->GetRegionTypeName() : poReg->GetName()); + target->Print(" REGION {},{},{} ; {}\n", poReg->GetEX(), poReg->GetEY(), poReg->GetEZ(), poReg->GetName().empty() ? poReg->GetRegionTypeName() : poReg->GetName()); } else { - COutput::TPrint("vorlage", " REGION {},{} ; {}\n", poReg->GetEX(), poReg->GetEY(), poReg->GetName().empty() ? poReg->GetRegionTypeName() : poReg->GetName()); + target->Print(" REGION {},{} ; {}\n", poReg->GetEX(), poReg->GetEY(), poReg->GetName().empty() ? poReg->GetRegionTypeName() : poReg->GetName()); } } else if (poReg->GetBlock() == CRegion::enSPEZIALREGION) { - COutput::TPrint("vorlage", " REGION; Astralebene ({}, {} Personen, {}$ Silber)\n", poReg->GetRegionTypeName(), poReg->PersonsOf(m_nPlayer, true), poReg->SilverOf(m_nPlayer)); + target->Print(" REGION; Astralebene ({}, {} Personen, {}$ Silber)\n", poReg->GetRegionTypeName(), poReg->PersonsOf(m_nPlayer, true), poReg->SilverOf(m_nPlayer)); } else if (poReg->GetEZ()) { - COutput::TPrint("vorlage", " REGION {},{},{} ; {} ({}, {} Personen, {}$ Silber) {}\n", poReg->GetEX(), poReg->GetEY(), poReg->GetEZ(), poReg->GetName(), poReg->GetRegionTypeName(), + target->Print(" REGION {},{},{} ; {} ({}, {} Personen, {}$ Silber) {}\n", poReg->GetEX(), poReg->GetEY(), poReg->GetEZ(), poReg->GetName(), poReg->GetRegionTypeName(), poReg->PersonsOf(m_nPlayer, true), poReg->SilverOf(m_nPlayer), sInsel); } else { - COutput::TPrint("vorlage", " REGION {},{} ; {} ({}, {} Personen, {}$ Silber) {}\n", poReg->GetEX(), poReg->GetEY(), poReg->GetName(), poReg->GetRegionTypeName(), poReg->PersonsOf(m_nPlayer, true), + target->Print(" REGION {},{} ; {} ({}, {} Personen, {}$ Silber) {}\n", poReg->GetEX(), poReg->GetEY(), poReg->GetName(), poReg->GetRegionTypeName(), poReg->PersonsOf(m_nPlayer, true), poReg->SilverOf(m_nPlayer), sInsel); } - COutput::TPrint("vorlage", " ; ECheck Lohn {}\n", poReg->GetLohn() ? poReg->GetLohn() : 10); + target->Print(" ; ECheck Lohn {}\n", poReg->GetLohn() ? poReg->GetLohn() : 10); } if (poReg->GetBlock() != CRegion::enSPEZIALREGION && IsFlag(VF_SHOWMINIKARTE)) { static const std::set explicitResources{"Bauern", "Silber", "Unterhalt", "Rekruten", "Pferde", "Gewinn", "Pl. frei"}; @@ -1591,7 +1594,7 @@ void CVorlage::Regionsvorlage(CRegion* poReg, CRegion* poReg2, CReport* poRep2) if (IsFlag(VF_SHOWLUXUS) || IsFlag(VF_SHOWLPROD)) { static char Delta[32]; if (poReg->GetVerkauf() >= 0 && size_t(poReg->GetVerkauf()) < poReg->GetLuxusgueter().size()) { - COutput::TWrite("vorlage", " ; Prod.: "); + target->Write(" ; Prod.: "); if (bDiff) { snprintf(Delta, sizeof(Delta), "%+5ld", (poReg2->GetLuxusgueter().size() > size_t(poReg2->GetVerkauf())) ? poReg->GetLuxusgueter()[size_t(poReg->GetVerkauf())].second - poReg2->GetLuxusgueter()[size_t(poReg2->GetVerkauf())].second : 0); @@ -1599,18 +1602,18 @@ void CVorlage::Regionsvorlage(CRegion* poReg, CRegion* poReg2, CReport* poRep2) else { Delta[0] = 0; } - COutput::TPrint("vorlage", "{:<10}{:4}{} max. handelbar: {}\n", poReg->GetLuxusgueter()[size_t(poReg->GetVerkauf())].first + ":", poReg->GetLuxusgueter()[size_t(poReg->GetVerkauf())].second, Delta, + target->Print("{:<10}{:4}{} max. handelbar: {}\n", poReg->GetLuxusgueter()[size_t(poReg->GetVerkauf())].first + ":", poReg->GetLuxusgueter()[size_t(poReg->GetVerkauf())].second, Delta, poReg->GetBauern() / 100); } } if (IsFlag(VF_SHOWMINIKARTE)) { if (poRQ->DeepGetValue("herb").asString().size() > 2) { - COutput::TPrint("vorlage", " ; Kraut: {}\n", poRQ->DeepGetValue("herb").asString()); + target->Print(" ; Kraut: {}\n", poRQ->DeepGetValue("herb").asString()); } } if (poReg->isVerorkt()) - COutput::TWrite("vorlage", " ; Die Region ist verorkt!\n"); + target->Write(" ; Die Region ist verorkt!\n"); if (poReg->GetVGrenzen() && !poReg->GetVGrenzen()->empty()) { std::ostringstream os; @@ -1640,7 +1643,7 @@ void CVorlage::Regionsvorlage(CRegion* poReg, CRegion* poReg2, CReport* poRep2) break; } os << " ; " << (*(poReg->GetVGrenzen()))[j] -> Typ() << " (" << (*(poReg->GetVGrenzen()))[j] -> Prozent() << "%) in " << sGrenze; - COutput::TPrint("vorlage", "{}\n", getAndReset(os)); + target->Print("{}\n", getAndReset(os)); } } } @@ -1656,13 +1659,13 @@ void CVorlage::Regionsvorlage(CRegion* poReg, CRegion* poReg2, CReport* poRep2) } } if (poReg->GetEinkommen() > 0) { - COutput::TPrint("vorlage", " ; Regionseinnahmen:{:6} Silber\n", poReg->GetEinkommen()); + target->Print(" ; Regionseinnahmen:{:6} Silber\n", poReg->GetEinkommen()); } if (poReg->GetAusgaben() > 0) { - COutput::TPrint("vorlage", " ; Regionsausgaben: {:6} Silber\n", poReg->GetAusgaben() + nKosten); + target->Print(" ; Regionsausgaben: {:6} Silber\n", poReg->GetAusgaben() + nKosten); } else if (nKosten) { - COutput::TPrint("vorlage", " ; Nahrungskosten: {:6} Silber\n", nKosten); + target->Print(" ; Nahrungskosten: {:6} Silber\n", nKosten); } } } @@ -1718,17 +1721,17 @@ void CVorlage::Regionsvorlage(CRegion* poReg, CRegion* poReg2, CReport* poRep2) } CRegion::Durchreisen::const_iterator di; for (di = poReg->GetDurchreisen().begin(); di != poReg->GetDurchreisen().end(); di++) { - COutput::TPrint("vorlage", " ; Durchgereist: {}\n", *di); + target->Print(" ; Durchgereist: {}\n", *di); } for (di = poReg->GetDurchschiffungen().begin(); di != poReg->GetDurchschiffungen().end(); di++) { - COutput::TPrint("vorlage", " ; Durchgesegelt: {}\n", *di); + target->Print(" ; Durchgesegelt: {}\n", *di); } } if (!poReg->GetKommandos().empty()) { for (int32_t j = 0; j < (int32_t)poReg->GetKommandos().size(); j++) { if (poReg->GetKommandos()[j].empty()) { - COutput::TWrite("vorlage", "\n"); + target->Write("\n"); } else { if (poReg->GetKommandos()[j].asString()[0] == ';') { @@ -1738,7 +1741,7 @@ void CVorlage::Regionsvorlage(CRegion* poReg, CRegion* poReg2, CReport* poRep2) } } if (!IsFlag(VF_SHOWVERBOSEINFO)) { - COutput::TWrite("vorlage", "\n"); + target->Write("\n"); } if (poReg->PersonsOf(m_nPlayer) - poReg->PersonsOf(m_nPlayer, true) > 0) { WrapOut(" ; ", std::string("In dieser Region sind Einheiten als (") + itoan(m_nPlayer, g_poCurrentReport->PNrBase()) + ") getarnt!", (size_t)g_nLineSize); @@ -1750,9 +1753,9 @@ void CVorlage::Regionsvorlage(CRegion* poReg, CRegion* poReg2, CReport* poRep2) if (!IsFlag(VF_SUPPRESSUNITS)) { if (IsFlag(VF_SORTBURGEN) && nOrt != poReg->GetVEinheiten()[i]->Aufenthaltsort()) { nOrt = poReg->GetVEinheiten()[i]->Aufenthaltsort(); - COutput::TWrite("vorlage", "\n ; - - - - - - - - - - - -\n"); + target->Write("\n ; - - - - - - - - - - - -\n"); if (!nOrt) { - COutput::TWrite("vorlage", " ; Auf freiem Feld:\n"); + target->Write(" ; Auf freiem Feld:\n"); } else if (nOrt > 0x10000000) { if (poReg->GetShip(nOrt - 0x10000000)) { @@ -1786,13 +1789,13 @@ void CVorlage::Regionsvorlage(CRegion* poReg, CRegion* poReg2, CReport* poRep2) if (IsFlag(VF_SORTBURGEN)) { while (!coBauwerke.empty()) { - COutput::TWrite("vorlage", "\n ; - - - - - - - - - - - -\n"); + target->Write("\n ; - - - - - - - - - - - -\n"); BauwerkAusgabe(*(coBauwerke.begin())); coBauwerke.erase(coBauwerke.begin()); } while (!coSchiffe.empty()) { - COutput::TWrite("vorlage", "\n ; - - - - - - - - - - - -\n"); + target->Write("\n ; - - - - - - - - - - - -\n"); SchiffAusgabe(*(coSchiffe.begin())); coSchiffe.erase(coSchiffe.begin()); } @@ -1807,12 +1810,12 @@ void CVorlage::Regionsvorlage(CRegion* poReg, CRegion* poReg2, CReport* poRep2) poLU = poRep2 ? poRep2->SearchUnit(poHU->Nummer(), false) : 0; if ((!IsFlag(VF_SHOWUNITSNEW) || !poLU || (poLU && poLU->Region()->GetKey() != poHU->Region()->GetKey())) && (poHU->Partei() != m_nPlayer)) { if (!bHead) { - COutput::TWrite("vorlage", "\n ; - - - - - - - - - - - -\n"); + target->Write("\n ; - - - - - - - - - - - -\n"); if (IsFlag(VF_SHOWUNITSNEW)) { - COutput::TWrite("vorlage", " ; Neue fremde Einheiten:\n"); + target->Write(" ; Neue fremde Einheiten:\n"); } else { - COutput::TWrite("vorlage", " ; Fremde Einheiten:\n"); + target->Write(" ; Fremde Einheiten:\n"); } bHead = true; } @@ -1826,8 +1829,8 @@ void CVorlage::Regionsvorlage(CRegion* poReg, CRegion* poReg2, CReport* poRep2) } if (bRegHead && IsFlag(VF_SHOWTRIBEOVERVIEW) && coPersonen.size() > 1) { - COutput::TWrite("vorlage", "\n ; - - - - - - - - - - - -\n"); - COutput::TWrite("vorlage", " ; Partei\xFC" "bersicht:\n"); + target->Write("\n ; - - - - - - - - - - - -\n"); + target->Write(" ; Partei\xFC" "bersicht:\n"); std::string sPfx; if (poReg2 && IsFlag(VF_SHOWTDIFF)) { @@ -1845,7 +1848,7 @@ void CVorlage::Regionsvorlage(CRegion* poReg, CRegion* poReg2, CReport* poRep2) if ((*ppi).first != m_nPlayer) { std::map::iterator ppi2 = coPersonen2.find((*ppi).first); - COutput::TWrite("vorlage", "\n"); + target->Write("\n"); out.str(""); out.clear(); @@ -1921,7 +1924,7 @@ void CVorlage::Regionsvorlage(CRegion* poReg, CRegion* poReg2, CReport* poRep2) if (bRegHead && !poReg->GetEndKommandos().empty()) { for (int32_t i = 0; i < (int32_t)poReg->GetEndKommandos().size(); i++) { if (poReg->GetEndKommandos()[i].empty()) { - COutput::TWrite("vorlage", "\n"); + target->Write("\n"); } else { if (poReg->GetEndKommandos()[i].asString()[0] == ';') { @@ -1939,6 +1942,7 @@ void CVorlage::ShowInvisibles(CRegion* poReg, CRegion* poReg2, CReport* poRep2) CEinheit* poHU; bool bHead = false; + auto* target = COutput::Target("vorlage"); poUnits = &g_coREDB[poReg->GetKey()]; for (ui = poUnits->begin(); ui != poUnits->end(); ui++) { @@ -1953,8 +1957,8 @@ void CVorlage::ShowInvisibles(CRegion* poReg, CRegion* poReg2, CReport* poRep2) const CRegion* pRH = (*edbi).second->Region(); if (pRH && pRH->GetKey() == poReg->GetKey()) { if (!bHead) { - COutput::TWrite("vorlage", "\n ; - - - - - - - - - - - -\n"); - COutput::TWrite("vorlage", " ; Unsichtbare oder getarnte fremde Einheiten:\n"); + target->Write("\n ; - - - - - - - - - - - -\n"); + target->Write(" ; Unsichtbare oder getarnte fremde Einheiten:\n"); bHead = true; } FremdEinheiten((*ui).second, poRep2); @@ -1978,9 +1982,10 @@ void CVorlage::BauwerkAusgabe(CBauwerk* pBuilding, CRegion::VEinheiten* poVE) } } } + auto* target = COutput::Target("vorlage"); int32_t nKap = CBlockBase::GetValue(CBuildingInfo::Lookup(pBuilding->XTyp()), "kapazitaet").asLong(); int32_t nCountUnits = CBlockBase::GetValue(CBuildingInfo::Lookup(pBuilding->XTyp()), "einheiten").asLong(); - COutput::TPrint("vorlage", " ; In {} '{}' ({}) [{}/{}{}]:\n", pBuilding->XTyp(), pBuilding->Name(), itoan(pBuilding->Nummer(), g_poCurrentReport->BNrBase()), nCountUnits > 0 ? nUnits : nPers, nKap ? nKap : pBuilding->Groesse(), + target->Print(" ; In {} '{}' ({}) [{}/{}{}]:\n", pBuilding->XTyp(), pBuilding->Name(), itoan(pBuilding->Nummer(), g_poCurrentReport->BNrBase()), nCountUnits > 0 ? nUnits : nPers, nKap ? nKap : pBuilding->Groesse(), nKap && nKap != pBuilding->Groesse() ? "/" + std::to_string(pBuilding->Groesse()) : ""); if (IsFlag(VF_SHOWBESCHREIBUNG) && !(pBuilding->Beschreibung().empty())) { @@ -1988,7 +1993,7 @@ void CVorlage::BauwerkAusgabe(CBauwerk* pBuilding, CRegion::VEinheiten* poVE) } if (pBuilding->m_nBelagerer) { - COutput::TPrint("vorlage", " ; Belagert von: {}\n", pBuilding->m_nBelagerer); + target->Print(" ; Belagert von: {}\n", pBuilding->m_nBelagerer); } if (!pBuilding->m_coEffects.empty() && IsFlag(VF_SHOWVERBOSEINFO)) { for (size_t i = 0; i < pBuilding->m_coEffects.size(); i++) { @@ -1999,7 +2004,7 @@ void CVorlage::BauwerkAusgabe(CBauwerk* pBuilding, CRegion::VEinheiten* poVE) if (!pBuilding->GetKommandos().empty()) { for (int32_t i = 0; i < (int32_t)pBuilding->GetKommandos().size(); i++) { if (pBuilding->GetKommandos()[i].empty()) { - COutput::TWrite("vorlage", "\n"); + target->Write("\n"); } else { if (pBuilding->GetKommandos()[i].asString()[0] == ';') { @@ -2012,15 +2017,16 @@ void CVorlage::BauwerkAusgabe(CBauwerk* pBuilding, CRegion::VEinheiten* poVE) void CVorlage::SchiffAusgabe(CSchiff* pSchiff) { + auto* target = COutput::Target("vorlage"); int32_t count = pSchiff->Anzahl(); std::string anzahl = count == 1 ? "" : ", Anzahl " + std::to_string(count) + ","; // static int dbgcount = 0; if (pSchiff->MaxHolz() && pSchiff->MaxHolz() * count != pSchiff->Holz()) { - COutput::TPrint("vorlage", " ; An Bord von {} '{}' ({}){} ({}/0) im Bau ({}/{}):\n", pSchiff->Typ(), pSchiff->Name(), itoan(pSchiff->Nummer(), g_poCurrentReport->BNrBase()), anzahl, pSchiff->Ladung(), pSchiff->Holz(), + target->Print(" ; An Bord von {} '{}' ({}){} ({}/0) im Bau ({}/{}):\n", pSchiff->Typ(), pSchiff->Name(), itoan(pSchiff->Nummer(), g_poCurrentReport->BNrBase()), anzahl, pSchiff->Ladung(), pSchiff->Holz(), pSchiff->MaxHolz() * count); } else { - COutput::TPrint("vorlage", " ; An Bord von {} '{}' ({}){} Kap: {}GE/{}GE({}%):\n", pSchiff->Typ(), pSchiff->Name(), itoan(pSchiff->Nummer(), g_poCurrentReport->BNrBase()), anzahl, pSchiff->MaxLadung() - pSchiff->Ladung(), + target->Print(" ; An Bord von {} '{}' ({}){} Kap: {}GE/{}GE({}%):\n", pSchiff->Typ(), pSchiff->Name(), itoan(pSchiff->Nummer(), g_poCurrentReport->BNrBase()), anzahl, pSchiff->MaxLadung() - pSchiff->Ladung(), pSchiff->MaxLadung(), pSchiff->Schaden()); } if (IsFlag(VF_SHOWBESCHREIBUNG) && !(pSchiff->Beschreibung().empty())) { @@ -2036,7 +2042,7 @@ void CVorlage::SchiffAusgabe(CSchiff* pSchiff) if (!pSchiff->GetKommandos().empty()) { for (int32_t i = 0; i < (int32_t)pSchiff->GetKommandos().size(); i++) { if (pSchiff->GetKommandos()[i].empty()) { - COutput::TWrite("vorlage", "\n"); + target->Write("\n"); } else { if (pSchiff->GetKommandos()[i].asString()[0] == ';') { @@ -2057,6 +2063,7 @@ void CVorlage::Einheitenvorlage(CEinheit* poUnit, CReport* poRep2) bool bKommando = false; size_t i; + auto* target = COutput::Target("vorlage"); m_poCurrentUnit = poUnit; g_poCurrentUnit = poUnit; @@ -2154,38 +2161,38 @@ void CVorlage::Einheitenvorlage(CEinheit* poUnit, CReport* poRep2) CMetaCommand::Call("CreateUnitHeader", coOutput); if (!coOutput.empty()) { for (int32_t j = 0; j < (int32_t)coOutput.size(); j++) { - COutput::TPrint("vorlage", " {}\n", coOutput[j].c_str()); + target->Print(" {}\n", coOutput[j].c_str()); } } } else { // if( IsFlag( VF_BASE36 ) ) if (IsFlag(VF_SHOWVERBOSEINFO)) { - COutput::TPrint("vorlage", "\n EINHEIT {}; {} [{},{}${}] {}{}{}{}{}{}\n", itoan(poUnit->m_nNummer, g_poCurrentReport->ENrBase()), poUnit->m_sName, poUnit->m_nAnzahl, poUnit->m_nSilber, getAndReset(out), + target->Print("\n EINHEIT {}; {} [{},{}${}] {}{}{}{}{}{}\n", itoan(poUnit->m_nNummer, g_poCurrentReport->ENrBase()), poUnit->m_sName, poUnit->m_nAnzahl, poUnit->m_nSilber, getAndReset(out), !poUnit->WahrerTyp().empty() ? poUnit->Typ() + ", " : "", poUnit->m_nParteitarnung ? "parteigetarnt, " : "", poUnit->m_nBewacht ? "bewacht, " : "", poUnit->m_shp.empty() ? std::string{} : poUnit->m_shp + ", ", pcKampf, poUnit->m_nHunger ? ", hungert" : ""); if (poUnit->m_nVerkleidung) { - COutput::TPrint("vorlage", " ; Verkleidet als {} ({})\n", poUnit->Region()->Map()->Report()->Parteiname(poUnit->m_nVerkleidung).substr(1), itoan(poUnit->m_nVerkleidung, g_poCurrentReport->PNrBase())); + target->Print(" ; Verkleidet als {} ({})\n", poUnit->Region()->Map()->Report()->Parteiname(poUnit->m_nVerkleidung).substr(1), itoan(poUnit->m_nVerkleidung, g_poCurrentReport->PNrBase())); } if (poUnit->m_nVerraeter) { - COutput::TWrite("vorlage", " ; VERR\xC4TER!\n"); + target->Write(" ; VERR\xC4TER!\n"); } // else // COutput::TPrintf( "vorlage", "\n EINHEIT %6d; %s [%d,%d$%s] %s%s%s%s%s%s\n", poUnit->m_nNummer, poUnit->m_sName.c_str(), poUnit->m_nAnzahl, poUnit->m_nSilber, Buff, (!poUnit->m_sWahrerTyp.empty())?poUnit->m_sTyp.c_str():"", // poUnit->m_nParteitarnung?"parteigetarnt, ":"", poUnit->m_nBewacht?"bewacht, ":"", poUnit->m_shp.empty()?"":std::string( poUnit->m_shp + ", " ).c_str(), pcKampf, (poUnit->m_nHunger)?", hungert":"" ); } else { - COutput::TPrint("vorlage", " EINHEIT {}; {} [{},{}${}]\n", itoan(poUnit->m_nNummer, g_poCurrentReport->ENrBase()), poUnit->m_sName, poUnit->m_nAnzahl, poUnit->m_nSilber, getAndReset(out)); + target->Print(" EINHEIT {}; {} [{},{}${}]\n", itoan(poUnit->m_nNummer, g_poCurrentReport->ENrBase()), poUnit->m_sName, poUnit->m_nAnzahl, poUnit->m_nSilber, getAndReset(out)); } if (!poUnit->Gruppe().empty() && IsFlag(VF_SHOWVERBOSEINFO)) { WrapOut(" ; In Gruppe: ", poUnit->Gruppe(), (size_t)g_nLineSize); } if (poUnit->CBlockBase::GetValue("hero").asLong() && IsFlag(VF_SHOWVERBOSEINFO)) { - COutput::TWrite("vorlage", " ; Heldenstatus!\n"); + target->Write(" ; Heldenstatus!\n"); } if (poUnit->GetValue("unaided", "").asLong()) { - COutput::TWrite("vorlage", " ; Bekommt im Kampf keine Hilfe!\n"); + target->Write(" ; Bekommt im Kampf keine Hilfe!\n"); } if (IsFlag(VF_SHOWBESCHREIBUNG) && !(poUnit->Beschreibung().empty())) { @@ -2360,12 +2367,12 @@ void CVorlage::Einheitenvorlage(CEinheit* poUnit, CReport* poRep2) if (!IsFlag(VF_FULLCOMMANDOUTPUT)) { for (int32_t j = 0; j < (int32_t)poUnit->m_csKommandos.size(); j++) { if (poUnit->m_csMetaOut.empty() || IsFlag(VF_DONTKILLCOMMANDS)) { - COutput::TPrint("vorlage", " {}\n", poUnit->m_csKommandos[j].c_str()); + target->Print(" {}\n", poUnit->m_csKommandos[j].c_str()); } else { auto p = poUnit->m_csKommandos[j].asString().find_first_not_of(" \t"); if (poUnit->m_csKommandos[j].empty() || (p != std::string::npos && (poUnit->m_csKommandos[j].asString()[p] == '/' || poUnit->m_csKommandos[j].asString()[p] == ';'))) { - COutput::TPrint("vorlage", " {}\n", poUnit->m_csKommandos[j].c_str()); + target->Print(" {}\n", poUnit->m_csKommandos[j].c_str()); } else { poUnit->m_csKommandos[j] = Value(""); @@ -2379,7 +2386,7 @@ void CVorlage::Einheitenvorlage(CEinheit* poUnit, CReport* poRep2) WrapOut(" ; ", poUnit->m_csMetaOut[j].c_str(), (size_t)g_nLineSize, " "); } else if (!poUnit->m_csMetaOut[j].empty() && poUnit->m_csMetaOut[j].asString()[0] == '/') { - COutput::TPrint("vorlage", " {}\n", poUnit->m_csMetaOut[j].c_str()); + target->Print(" {}\n", poUnit->m_csMetaOut[j].c_str()); } else { std::string sLine = poUnit->m_csMetaOut[j].c_str(); @@ -2387,11 +2394,11 @@ void CVorlage::Einheitenvorlage(CEinheit* poUnit, CReport* poRep2) size_t nLSize = (size_t)g_nCommandLineSize - 4; while (sLine.length() > nLSize) { if (sLine[nLSize - 2] == ' ') { - COutput::TPrint("vorlage", " {}{}\\\n", sPref, sLine.substr(0, nLSize - 1)); + target->Print(" {}{}\\\n", sPref, sLine.substr(0, nLSize - 1)); sLine.erase(0, nLSize - 1); } else { - COutput::TPrint("vorlage", " {}{}\\\n", sPref, sLine.substr(0, nLSize - 2)); + target->Print(" {}{}\\\n", sPref, sLine.substr(0, nLSize - 2)); sLine.erase(0, nLSize - 2); } if (sPref.empty()) { @@ -2399,7 +2406,7 @@ void CVorlage::Einheitenvorlage(CEinheit* poUnit, CReport* poRep2) sPref = " "; } } - COutput::TPrint("vorlage", " {}{}\n", sPref, sLine); + target->Print(" {}{}\n", sPref, sLine); } // COutput::TPrintf( "vorlage", " %s\n", poUnit->m_csMetaOut[i].c_str() ); } @@ -2408,7 +2415,7 @@ void CVorlage::Einheitenvorlage(CEinheit* poUnit, CReport* poRep2) for (int32_t j = 0; j < (int32_t)poUnit->m_csKommandos.size(); j++) { auto p = poUnit->m_csKommandos[j].asString().find_first_not_of(" \t"); if (!poUnit->m_csKommandos[j].empty() && p != std::string::npos && poUnit->m_csKommandos[j].asString()[p] != '/') { - COutput::TPrint("vorlage", " {}\n", poUnit->m_csKommandos[j].c_str()); + target->Print(" {}\n", poUnit->m_csKommandos[j].c_str()); } } } From b2b31c660761db8620d9a07caef85a498e1e237c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Schu=CC=88mann?= Date: Sat, 25 Apr 2026 08:32:48 +0200 Subject: [PATCH 6/8] Replace `TPrintf` with modernized `TPrint`/`TWrite` throughout the codebase for cleaner output handling. Also implements #14. --- EBase/Report.cpp | 56 +++++++++++++++++++++--------------------- EBase/Utility.cpp | 10 ++++---- Vorlage/Metascript.cpp | 4 +-- Vorlage/Zugvorlage.cpp | 41 +++++++++++++++++++++++++------ 4 files changed, 68 insertions(+), 43 deletions(-) diff --git a/EBase/Report.cpp b/EBase/Report.cpp index 8a15a1b..73572a7 100644 --- a/EBase/Report.cpp +++ b/EBase/Report.cpp @@ -1850,32 +1850,32 @@ void CKarte::DumpMap(const std::string& sTarget, int nCX, int nCY, int nB, int n snprintf(fmt2, sizeof(fmt2), "%%%ds ", sy + 1); if (pcPref) - COutput::TPrintf(sTarget, "%s ", pcPref); - COutput::TPrintf(sTarget, " "); + COutput::TPrint(sTarget, "{} ", pcPref); + COutput::TWrite(sTarget, " "); if ((y & 1) ^ (nCY & 1)) - COutput::TPrintf(sTarget, " "); + COutput::TWrite(sTarget, " "); e = ((y & 1) ^ (nCY & 1)) ? 0 : 1; for (x = nCX - nB + h; x <= nCX + nB + h + e; x++) - COutput::TPrintf(sTarget, "%c ", (x - ((y > 0) ? y + 1 : y) / 2) < 0 ? '-' : ((x - ((y > 0) ? y + 1 : y) / 2) ? '+' : '|')); - COutput::TPrintf(sTarget, "\n"); + COutput::TPrint(sTarget, "{} ", (x - ((y > 0) ? y + 1 : y) / 2) < 0 ? '-' : ((x - ((y > 0) ? y + 1 : y) / 2) ? '+' : '|')); + COutput::TWrite(sTarget, "\n"); for (z = (int)pow((double)10, (double)sx); z > 0; z /= 10) { if (pcPref) - COutput::TPrintf(sTarget, "%s ", pcPref); + COutput::TPrint(sTarget, "{} ", pcPref); COutput::TPrintf(sTarget, fmt2, ""); if ((y & 1) ^ (nCY & 1)) - COutput::TPrintf(sTarget, " "); + COutput::TWrite(sTarget, " "); for (x = nCX - nB + h; x <= nCX + nB + h + e; x++) - COutput::TPrintf(sTarget, "%c ", ((abs(x - ((y > 0) ? y + 1 : y) / 2) / z) % 10) + '0'); - COutput::TPrintf(sTarget, "\n"); + COutput::TPrint(sTarget, "{} ", ((abs(x - ((y > 0) ? y + 1 : y) / 2) / z) % 10) + '0'); + COutput::TWrite(sTarget, "\n"); } for (--y; y >= nCY - nH; y--) { if (pcPref) - COutput::TPrintf(sTarget, "%s ", pcPref); + COutput::TPrint(sTarget, "{} ", pcPref); COutput::TPrintf(sTarget, fmt, y); if ((y & 1) ^ (nCY & 1)) - COutput::TPrintf(sTarget, " "); + COutput::TWrite(sTarget, " "); h = (y & 1) & !(nCY & 1); for (x = nCX - nB + h; x <= nCX + nB + h; x++) { c = GetFromDCords(x, y, 0, true)->GetRegionChar(); @@ -1884,12 +1884,12 @@ void CKarte::DumpMap(const std::string& sTarget, int nCX, int nCY, int nB, int n c = ' '; if (c == ' ' && !(y % 10)) c = '-'; - COutput::TPrintf(sTarget, "%c%c", c, o); + COutput::TPrint(sTarget, "{}{}", c, o); } if (!((y & 1) ^ (nCY & 1))) - COutput::TPrintf(sTarget, " "); + COutput::TWrite(sTarget, " "); COutput::TPrintf(sTarget, fmt, y); - COutput::TPrintf(sTarget, "\n"); + COutput::TWrite(sTarget, "\n"); } h = (y & 1) & !(nCY & 1); @@ -1898,24 +1898,24 @@ void CKarte::DumpMap(const std::string& sTarget, int nCX, int nCY, int nB, int n sx = (log10((double)abs(x1)) > log10((double)abs(x2))) ? (int)log10((double)abs(x1)) : (int)log10((double)abs(x2)); if (pcPref) - COutput::TPrintf(sTarget, "%s ", pcPref); - COutput::TPrintf(sTarget, " "); + COutput::TPrint(sTarget, "{} ", pcPref); + COutput::TWrite(sTarget, " "); if ((y & 1) ^ (nCY & 1)) - COutput::TPrintf(sTarget, " "); + COutput::TWrite(sTarget, " "); e = ((y & 1) ^ (nCY & 1)) ? 0 : 1; for (x = nCX - nB + h; x <= nCX + nB + h + e; x++) - COutput::TPrintf(sTarget, "%c ", (x - ((y > 0) ? y + 1 : y) / 2) < 0 ? '-' : ((x - ((y > 0) ? y + 1 : y) / 2) ? '+' : '|')); - COutput::TPrintf(sTarget, "\n"); + COutput::TPrint(sTarget, "{} ", (x - ((y > 0) ? y + 1 : y) / 2) < 0 ? '-' : ((x - ((y > 0) ? y + 1 : y) / 2) ? '+' : '|')); + COutput::TWrite(sTarget, "\n"); for (z = (int)pow((double)10, (double)sx); z > 0; z /= 10) { if (pcPref) - COutput::TPrintf(sTarget, "%s ", pcPref); + COutput::TPrint(sTarget, "{} ", pcPref); COutput::TPrintf(sTarget, fmt2, ""); if ((y & 1) ^ (nCY & 1)) - COutput::TPrintf(sTarget, " "); + COutput::TWrite(sTarget, " "); for (x = nCX - nB + h; x <= nCX + nB + h + e; x++) - COutput::TPrintf(sTarget, "%c ", ((abs(x - ((y > 0) ? y + 1 : y) / 2) / z) % 10) + '0'); - COutput::TPrintf(sTarget, "\n"); + COutput::TPrint(sTarget, "{} ", ((abs(x - ((y > 0) ? y + 1 : y) / 2) / z) % 10) + '0'); + COutput::TWrite(sTarget, "\n"); } } @@ -5171,20 +5171,20 @@ void CEinheit::Kapazitaeten(const std::string& sTarget) const double fKapReiten, fFKapReiten, fKapGehen, fFKapGehen; int32_t nRHO, nGHO; - COutput::TPrintf(sTarget, " ; Gew: %sGE", ToString(Gewicht()).c_str()); + COutput::TPrint(sTarget, " ; Gew: {}GE", ToString(Gewicht()).c_str()); CalcKapazitaeten(fKapReiten, fFKapReiten, nRHO, fKapGehen, fFKapGehen, nGHO); if (!nRHO && ((CEinheit*)this)->GetValue(std::string("Pferd"), std::string("")).asLong()) { - COutput::TPrintf(sTarget, " Reiten: %sGE/%sGE", ToString(fFKapReiten).c_str(), ToString(fKapReiten).c_str()); + COutput::TPrint(sTarget, " Reiten: {}GE/{}GE", ToString(fFKapReiten).c_str(), ToString(fKapReiten).c_str()); } if (nGHO) { - COutput::TPrintf(sTarget, " (%d Pferd%s zuviel!)", nGHO, (nGHO > 1) ? "e" : ""); + COutput::TPrint(sTarget, " ({} Pferd{} zuviel!)", nGHO, (nGHO > 1) ? "e" : ""); } else { - COutput::TPrintf(sTarget, " Gehen: %sGE/%sGE", ToString(fFKapGehen).c_str(), ToString(fKapGehen).c_str()); + COutput::TPrint(sTarget, " Gehen: {}GE/{}GE", ToString(fFKapGehen).c_str(), ToString(fKapGehen).c_str()); } - COutput::TPrintf(sTarget, "\n"); + COutput::TWrite(sTarget, "\n"); } double CEinheit::Gewicht() const diff --git a/EBase/Utility.cpp b/EBase/Utility.cpp index 3e05476..8e3076d 100644 --- a/EBase/Utility.cpp +++ b/EBase/Utility.cpp @@ -1781,24 +1781,24 @@ void COutputTable::Output(const std::string& sTarget, const std::string& sPfx) Format(); for (iT = m_coTable.begin(); iT != m_coTable.end(); iT++) { - COutput::TPrintf(sTarget, "%s", sPfx.c_str()); + COutput::TPrint(sTarget, "{}", sPfx.c_str()); bBorder = false; for (size_t c = 0; c < (*iT).size(); c++) { if (!strcmp((*iT)[c].second.c_str(), "|")) { - COutput::TPrintf(sTarget, "|"); + COutput::TWrite(sTarget, "|"); bBorder = true; } else { if (c && !bBorder) { - COutput::TPrintf(sTarget, " %s", (*iT)[c].second.c_str()); + COutput::TPrint(sTarget, " {}", (*iT)[c].second.c_str()); } else { - COutput::TPrintf(sTarget, "%s", (*iT)[c].second.c_str()); + COutput::TPrint(sTarget, "{}", (*iT)[c].second.c_str()); } bBorder = false; } } - COutput::TPrintf(sTarget, "\n"); + COutput::TWrite(sTarget, "\n"); } } diff --git a/Vorlage/Metascript.cpp b/Vorlage/Metascript.cpp index 427dc28..26c9688 100644 --- a/Vorlage/Metascript.cpp +++ b/Vorlage/Metascript.cpp @@ -4359,12 +4359,12 @@ void CMetaCommand::RunScript(CMCI& oMCI, Expression::Variables& oContext, std::s Parse(oMCI, oContext, coCmd); if (IsFlag(VF_PROGRESSINFO)) { g_bForceEOL = true; - COutput::TPrintf("console", "\r%s", oMCI.m_sArg.c_str()); + COutput::TPrint("console", "\r{}", oMCI.m_sArg.c_str()); } } else { if (IsFlag(VF_DEBUGMODE)) - COutput::TPrintf("debug", "%s\n", oMCI.m_sArg.c_str()); + COutput::TPrint("debug", "{}\n", oMCI.m_sArg.c_str()); } Parse(oMCI, oContext, coCmd); } diff --git a/Vorlage/Zugvorlage.cpp b/Vorlage/Zugvorlage.cpp index b7bd112..94d768e 100644 --- a/Vorlage/Zugvorlage.cpp +++ b/Vorlage/Zugvorlage.cpp @@ -793,7 +793,7 @@ void CVorlage::Vorlage(CReport& oReport, CReport* poRep2, bool bTime) // CRegion* poRQ = 0; // FILE* hHold = 0; clock_t nStart; - int32_t nUnits = 0, nPersons = 0, nNeededFood = 0; + int32_t nUnits = 0, nPersons = 0, nNeededFood = 0, nNeededFood2 = 0; int ic; if (IsFlag(VF_CROUTPUT) || IsFlag(VF_SUPPRESSTURNOUTPUT)) { @@ -825,6 +825,17 @@ void CVorlage::Vorlage(CReport& oReport, CReport* poRep2, bool bTime) } } } + if (poRep2) { + for (CReport::Einheiten::iterator ei = poRep2->GEinheiten().begin(); ei != poRep2->GEinheiten().end(); ei++) { + if ((*ei).second->Partei() == m_nPlayer) { + nUnits++; + nPersons += (*ei).second->Anzahl(); + if (0 != CRasse::Lookup((*ei).second->RealType()).GetValue(std::string("Unterhalt")).asLong()) { + nNeededFood2 += CRasse::Lookup((*ei).second->RealType()).GetValue(std::string("Unterhalt")).asLong() * (*ei).second->Anzahl(); + } + } + } + } m_nUnits = nUnits; auto* target = COutput::Target("vorlage"); @@ -979,21 +990,35 @@ void CVorlage::Vorlage(CReport& oReport, CReport* poRep2, bool bTime) if (IsFlag(VF_SHOWHANDEL)) { target->Write("\n ; Wirtschaftsbilanz:\n"); - target->Print(" ; Gesamteinkommen:{:9} Silber\n", oReport.m_nEinkommen); - target->Print(" ; Gesamtausgaben: {:9} Silber {}\n", oReport.m_nAusgaben + nNeededFood /*Eater*10*/, oReport.Version() > 40 ? "" : "(z.Zt. ohne kostenpfl. Talente)"); - int64_t nVermoegen = 0; - for (CKarte::RegionMap::const_iterator rmi = m_poKarte->Regions().begin(); rmi != m_poKarte->Regions().end(); rmi++) { + if (poRep2 && poRep2->m_nEinkommen > 0) + target->Print(" ; Gesamteinkommen:{:9} ({:+}) Silber\n", oReport.m_nEinkommen, oReport.m_nEinkommen - poRep2->m_nEinkommen); + else + target->Print(" ; Gesamteinkommen:{:9} Silber\n", oReport.m_nEinkommen); + if (poRep2 && poRep2->m_nAusgaben > 0) + target->Print(" ; Gesamtausgaben: {:9} ({:+}) Silber {}\n", oReport.m_nAusgaben + nNeededFood /*Eater*10*/, (oReport.m_nAusgaben + nNeededFood) - (poRep2->m_nAusgaben + nNeededFood2), oReport.Version() > 40 ? "" : "(z.Zt. ohne kostenpfl. Talente)"); + else + target->Print(" ; Gesamtausgaben: {:9} Silber {}\n", oReport.m_nAusgaben + nNeededFood /*Eater*10*/, oReport.Version() > 40 ? "" : "(z.Zt. ohne kostenpfl. Talente)"); + int64_t nVermoegen = 0, nVermoegen2 = 0; + for (auto rmi = m_poKarte->Regions().begin(); rmi != m_poKarte->Regions().end(); rmi++) { nVermoegen += (*rmi).second->SilverOf(oReport.Partei()); } - target->Print(" ; Gesamtverm\xF6gen: {:9} Silber\n", nVermoegen); + if (poRep2) { + for (auto rmi = poRep2->Karte()->Regions().begin(); rmi != poRep2->Karte()->Regions().end(); rmi++) { + nVermoegen2 += (*rmi).second->SilverOf(oReport.Partei()); + } + } + if (poRep2 && nVermoegen2 > 0) + target->Print(" ; Gesamtverm\xF6gen: {:9} ({:+}) Silber\n", nVermoegen, nVermoegen - nVermoegen2); + else + target->Print(" ; Gesamtverm\xF6gen: {:9} Silber\n", nVermoegen); if (oReport.m_cpoHPartner.size()) target->Write("\n ; Warenaustausch:\n"); - for (CReport::Handelspartner::const_iterator rhi = oReport.m_cpoHPartner.begin(); rhi != oReport.m_cpoHPartner.end(); rhi++) { + for (auto rhi = oReport.m_cpoHPartner.begin(); rhi != oReport.m_cpoHPartner.end(); rhi++) { std::ostringstream out; out << oReport.Parteiname((*rhi).first).c_str() + 1 << "(" << itoan((*rhi).first, oReport.PNrBase()) << "): "; - for (CParteihandel::Produkte::const_iterator ppi = (*rhi).second->m_coProdukte.begin(); ppi != (*rhi).second->m_coProdukte.end(); ppi++) { + for (auto ppi = (*rhi).second->m_coProdukte.begin(); ppi != (*rhi).second->m_coProdukte.end(); ppi++) { if (ppi != (*rhi).second->m_coProdukte.begin()) { out << ", "; } From 5c9bb88698eceaddcf2075c19fc073a4face89b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Schu=CC=88mann?= Date: Tue, 28 Apr 2026 06:37:51 +0200 Subject: [PATCH 7/8] Replace `snprintf`, `fprintf`, `printf`, and similar legacy formatting with `fmt::format` for better type safety and readability. --- EBase/Expression.cpp | 41 ++++++++----------------------- EBase/Report.cpp | 34 +++++++++++-------------- EBase/ReportStream.cpp | 3 --- EBase/Utility.cpp | 31 +++-------------------- EBase/Utility.h | 2 -- EBase/Value.cpp | 4 +-- EBase/Value.h | 2 +- Vorlage/CRNE.cpp | 6 ++--- Vorlage/Metascript.cpp | 33 ++++++------------------- Vorlage/Zugvorlage.cpp | 56 +++++++++++++++++++++--------------------- 10 files changed, 70 insertions(+), 142 deletions(-) diff --git a/EBase/Expression.cpp b/EBase/Expression.cpp index 848a396..4ac53e3 100644 --- a/EBase/Expression.cpp +++ b/EBase/Expression.cpp @@ -409,10 +409,7 @@ bool Expression::getValue(const char* name, Value* value) return true; } else { - char Buff[512]; - snprintf(Buff, sizeof(Buff), "Undeklarierte Variable '%s' verwendet.", name); - value->error(Buff); - // *value = Value( name ); + value->error(fmt::format("Undeklarierte Variable '{}' verwendet.", name)); return false; } } @@ -821,18 +818,14 @@ int Expression::parseAssignment(Value* r) poContainer->remove(poObject->index[0]); } else { - char Buff[512]; - snprintf(Buff, sizeof(Buff), "Falsche Indizierung im Behaelter '%s'.", poObject->label.c_str()); - r->error(Buff); + r->error(fmt::format("Falsche Indizierung im Behaelter '{}'.", poObject->label)); ERR(E_BADINDEX); } } else { Value oV; if (!setValue(sT.c_str(), &oV, _force)) { - char Buff[512]; - snprintf(Buff, sizeof(Buff), "Zuweisung an undefinierte Variable '%s'.", sT.c_str()); - r->error(Buff); + r->error(fmt::format("Zuweisung an undefinierte Variable '{}'.", sT)); ERR(E_UNKNOWN); } } @@ -842,9 +835,7 @@ int Expression::parseAssignment(Value* r) if (poContainer) { if (poObject->index.size() == 1) { if (!poContainer->setAt(poObject->index[0], *r)) { - char Buff[512]; - snprintf(Buff, sizeof(Buff), "Falsche Indizierung im Behaelter '%s'.", poObject->label.c_str()); - r->error(Buff); + r->error(fmt::format("Falsche Indizierung im Behaelter '{}'.", poObject->label)); ERR(E_BADINDEX); } } @@ -853,9 +844,7 @@ int Expression::parseAssignment(Value* r) *poContainer = *r; } else if (poObject->index.size()) { - char Buff[512]; - snprintf(Buff, sizeof(Buff), "Falsche Indizierung im Behaelter '%s'.", poObject->label.c_str()); - r->error(Buff); + r->error(fmt::format("Falsche Indizierung im Behaelter '{}'.", poObject->label)); ERR(E_BADINDEX); } else { @@ -889,16 +878,12 @@ int Expression::parseAssignment(Value* r) } } else if (sT[0] == '$' && (!poObject->index.empty() || poObject->next)) { - char Buff[512]; - snprintf(Buff, sizeof(Buff), "Zuweisung ueber Behaelter/Objekt-Zugriff an Variable '%s'.", sT.c_str()); - r->error(Buff); + r->error(fmt::format("Zuweisung ueber Behaelter/Objekt-Zugriff an Variable '{}'.", sT)); ERR(E_BADINDEX); } else if (sT[0] == '$') { if (!setValue(sT.c_str(), r, _force)) { - char Buff[512]; - snprintf(Buff, sizeof(Buff), "Zuweisung an undefinierte Variable '%s'.", sT.c_str()); - r->error(Buff); + r->error(fmt::format("Zuweisung an undefinierte Variable '{}'.", sT)); ERR(E_UNKNOWN); } } @@ -906,9 +891,7 @@ int Expression::parseAssignment(Value* r) oRef.self() = *r; } else { - char Buff[512]; - snprintf(Buff, sizeof(Buff), "Fehlerhafte Zuweisung, '%s' ist kein gueltiges Zuweisungsziel.", sT.c_str()); - r->error(Buff); + r->error(fmt::format("Fehlerhafte Zuweisung, '{}' ist kein gueltiges Zuweisungsziel.", sT)); ERR(E_SYNTAX); } return 1; @@ -1098,9 +1081,7 @@ void Expression::parsePrimary(Value* r, CReference* pRef) nextToken(); evalExpr(&oIdx); if (_token[0] != ')' || (oIdx.asLong() < 0 && oIdx.asLong() > poContainer->size())) { - char Buff[512]; - snprintf(Buff, sizeof(Buff), "Falsche Indizierung im Behaelter '%s'.", _object->label.c_str()); - r->error(Buff); + r->error(fmt::format("Falsche Indizierung im Behaelter '{}'.", _object->label)); ERR(E_SYNTAX); } *r = poContainer->getNth(oIdx.asLong()); @@ -1109,9 +1090,7 @@ void Expression::parsePrimary(Value* r, CReference* pRef) *r = *_container; } else { - char Buff[512]; - snprintf(Buff, sizeof(Buff), "Falsche Indizierung im Behaelter '%s'.", _object->label.c_str()); - r->error(Buff); + r->error(fmt::format("Falsche Indizierung im Behaelter '{}'.", _object->label)); ERR(E_SYNTAX); } nextToken(); diff --git a/EBase/Report.cpp b/EBase/Report.cpp index 73572a7..b847374 100644 --- a/EBase/Report.cpp +++ b/EBase/Report.cpp @@ -1079,31 +1079,29 @@ void CBlockBase::ReadConfigObjects(const std::string& sFile, const std::string& void CBlockBase::Dump(unsigned int lvl) { - char spc[16]; - snprintf(spc, sizeof(spc), "%%%ds", lvl * 2); - fprintf(stderr, spc, ""); - fprintf(stderr, "<%s", g_stringTable.i2s(m_nName).c_str()); + fmt::print(stderr, "{:{}}", "", lvl * 2); + fmt::print(stderr, "<{}", g_stringTable.i2s(m_nName)); if (m_oKey1.getType() != VT_EMPTY) { - fprintf(stderr, " k1=%c%s%c", 34, m_oKey1.asString().c_str(), 34); + fmt::print(stderr, " k1=\"{}\"", m_oKey1.asString()); if (m_oKey2.getType() != VT_EMPTY) { - fprintf(stderr, " k2=%c%s%c", 34, m_oKey2.asString().c_str(), 34); + fmt::print(stderr, " k2=\"{}\"", m_oKey2.asString()); if (m_oKey3.getType() != VT_EMPTY) { - fprintf(stderr, " k3=%c%s%c", 34, m_oKey3.asString().c_str(), 34); + fmt::print(stderr, " k3=\"{}\"", m_oKey3.asString()); } } } - fprintf(stderr, ">\n"); + fmt::print(stderr, ">\n"); for (NamedValues::iterator ai = m_coNamedValues.begin(); ai != m_coNamedValues.end(); ai++) { - fprintf(stderr, spc, ""); - fprintf(stderr, " <%s>%s\n", CStringDB::SID2Str((*ai).first).c_str(), (*ai).second.asString().c_str(), CStringDB::SID2Str((*ai).first).c_str()); + fmt::print(stderr, "{:{}}", "", lvl * 2); + fmt::print(stderr, " <{}>{}\n", CStringDB::SID2Str((*ai).first), (*ai).second.asString(), CStringDB::SID2Str((*ai).first)); } for (NamedSubblocks::iterator bi = m_coSubblocks.begin(); bi != m_coSubblocks.end(); bi++) { for (BlockGroup::iterator bgi = (*bi).second.begin(); bgi != (*bi).second.end(); bgi++) { (*bgi).second->Dump(lvl + 1); } } - fprintf(stderr, spc, ""); - fprintf(stderr, "\n", g_stringTable.i2s(m_nName).c_str()); + fmt::print(stderr, "{:{}}", "", lvl * 2); + fmt::print(stderr, "\n", g_stringTable.i2s(m_nName)); } ///////////////////////////////////////////////////////////////////// @@ -1830,7 +1828,6 @@ void CKarte::DumpMap(const std::string& sTarget, int nCX, int nCY, int nB, int n { int h, x, y, z; int x1, x2, sx, sy; - char fmt[16], fmt2[16]; char c, o; int e; nB >>= 1; @@ -1846,8 +1843,7 @@ void CKarte::DumpMap(const std::string& sTarget, int nCX, int nCY, int nB, int n sx = (log10((double)abs(x1)) > log10((double)abs(x2))) ? (int)log10((double)abs(x1)) : (int)log10((double)abs(x2)); sy = (log10((double)abs(y)) > log10((double)abs(nCY - nH))) ? (int)log10((double)abs(y)) : (int)log10((double)abs(nCY - nH)); sy++; - snprintf(fmt, sizeof(fmt), "%%+%dd ", sy + 1); - snprintf(fmt2, sizeof(fmt2), "%%%ds ", sy + 1); + int yLabelWidth = sy + 1; if (pcPref) COutput::TPrint(sTarget, "{} ", pcPref); @@ -1862,7 +1858,7 @@ void CKarte::DumpMap(const std::string& sTarget, int nCX, int nCY, int nB, int n for (z = (int)pow((double)10, (double)sx); z > 0; z /= 10) { if (pcPref) COutput::TPrint(sTarget, "{} ", pcPref); - COutput::TPrintf(sTarget, fmt2, ""); + COutput::TPrint(sTarget, "{:>{}} ", "", yLabelWidth); if ((y & 1) ^ (nCY & 1)) COutput::TWrite(sTarget, " "); for (x = nCX - nB + h; x <= nCX + nB + h + e; x++) @@ -1873,7 +1869,7 @@ void CKarte::DumpMap(const std::string& sTarget, int nCX, int nCY, int nB, int n for (--y; y >= nCY - nH; y--) { if (pcPref) COutput::TPrint(sTarget, "{} ", pcPref); - COutput::TPrintf(sTarget, fmt, y); + COutput::TPrint(sTarget, "{:+{}} ", y, yLabelWidth); if ((y & 1) ^ (nCY & 1)) COutput::TWrite(sTarget, " "); h = (y & 1) & !(nCY & 1); @@ -1888,7 +1884,7 @@ void CKarte::DumpMap(const std::string& sTarget, int nCX, int nCY, int nB, int n } if (!((y & 1) ^ (nCY & 1))) COutput::TWrite(sTarget, " "); - COutput::TPrintf(sTarget, fmt, y); + COutput::TPrint(sTarget, "{:+{}} ", y, yLabelWidth); COutput::TWrite(sTarget, "\n"); } @@ -1910,7 +1906,7 @@ void CKarte::DumpMap(const std::string& sTarget, int nCX, int nCY, int nB, int n for (z = (int)pow((double)10, (double)sx); z > 0; z /= 10) { if (pcPref) COutput::TPrint(sTarget, "{} ", pcPref); - COutput::TPrintf(sTarget, fmt2, ""); + COutput::TPrint(sTarget, "{:>{}} ", "", yLabelWidth); if ((y & 1) ^ (nCY & 1)) COutput::TWrite(sTarget, " "); for (x = nCX - nB + h; x <= nCX + nB + h + e; x++) diff --git a/EBase/ReportStream.cpp b/EBase/ReportStream.cpp index cd21087..d6a57eb 100644 --- a/EBase/ReportStream.cpp +++ b/EBase/ReportStream.cpp @@ -216,9 +216,6 @@ void CReportStream::PrepareLine() m_enType = enINTEGER; } else { - char Buff[256]; - snprintf(Buff, sizeof(Buff), "Systax error in line %ld!\n", m_nLineNumber); - // Message( Buff ); m_enType = enERROR; } if (m_enType != enERROR) { diff --git a/EBase/Utility.cpp b/EBase/Utility.cpp index 8e3076d..41483c6 100644 --- a/EBase/Utility.cpp +++ b/EBase/Utility.cpp @@ -1015,9 +1015,8 @@ int32_t Random(int32_t seed) nCount++; // nSeedStart = 0x42C123E6; // nCount = 0x15555E; - char pcSeed[1024]; - snprintf(pcSeed, sizeof(pcSeed), "%s, %ld, %ld", ctime(&nSeedStart), (long)nSeedStart, nCount); - nSeed = Hash((const unsigned char*)pcSeed, (uint32_t)strlen(pcSeed), 4711); + std::string sSeed = fmt::format("{}, {}, {}", ctime(&nSeedStart), (long)nSeedStart, nCount); + nSeed = Hash((const unsigned char*)sSeed.c_str(), (uint32_t)sSeed.size(), 4711); } TRACEMSG(("Random used, seed: 0x%lX\n", nSeed)); prng.seed((mt11213b_t::result_type)nSeed); @@ -1718,15 +1717,11 @@ COutputTable& COutputTable::Col(int32_t nNum, COutputTable::FORMAT enFormat) COutputTable& COutputTable::Col(double fNum, int nScale, COutputTable::FORMAT enFormat) { - char Fmt[16]; - char Buff[80]; m_nCol++; if (m_nCol > m_nMaxCols) { m_nMaxCols = m_nCol; } - snprintf(Fmt, sizeof(Fmt), "%%.%df", nScale < 10 ? nScale : 10); - snprintf(Buff, sizeof(Buff), Fmt, fNum); - m_pRow->push_back(TABENTRY(enFormat, std::string(Buff))); + m_pRow->push_back(TABENTRY(enFormat, fmt::format("{:.{}f}", fNum, nScale < 10 ? nScale : 10))); return *this; } @@ -2266,31 +2261,11 @@ void COutput::Write(const std::string& sTxt) Write(sTxt.c_str()); } -void COutput::Printf(const char* msg, ...) -{ - static char pcBuff[4096]; - va_list list; - va_start(list, msg); - _vsnprintf(pcBuff, 4095, msg, list); - pcBuff[4095] = 0; - Write(pcBuff); -} - void COutput::TWrite(const std::string& sID, const std::string& sTxt) { Target(sID)->Write(sTxt.c_str()); } -void COutput::TPrintf(const std::string& sID, const char* msg, ...) -{ - static char pcBuff[4096]; - va_list list; - va_start(list, msg); - _vsnprintf(pcBuff, 4095, msg, list); - pcBuff[4095] = 0; - Target(sID)->Write(pcBuff); -} - void COutput::CloseTargets() { auto ti = g_cpoTargets.begin(); diff --git a/EBase/Utility.h b/EBase/Utility.h index e7a4064..014b339 100644 --- a/EBase/Utility.h +++ b/EBase/Utility.h @@ -336,7 +336,6 @@ class COutput void Write(const char* pcTxt); void Write(const std::string& sTxt); - void Printf(const char* msg, ...); template void Print(fmt::format_string fmt, Args&&... args) { @@ -346,7 +345,6 @@ class COutput bool Disconnect(bool bSuicide = true); static void TWrite(const std::string& sID, const std::string& sTxt); - static void TPrintf(const std::string& sID, const char* msg, ...); template static void TPrint(const std::string& sID, fmt::format_string fmt, Args&&... args) diff --git a/EBase/Value.cpp b/EBase/Value.cpp index 35918e5..172fd5c 100644 --- a/EBase/Value.cpp +++ b/EBase/Value.cpp @@ -249,9 +249,9 @@ double Value::asReal() const noexcept return 0.0; } -void Value::error(const char* pcMsg) +void Value::error(std::string sMsg) { - self()._data = detail::ErrorState{pcMsg}; + self()._data = detail::ErrorState{std::move(sMsg)}; } std::string Value::asString(bool bForceLiteral) const diff --git a/EBase/Value.h b/EBase/Value.h index fff0248..b81d431 100644 --- a/EBase/Value.h +++ b/EBase/Value.h @@ -99,7 +99,7 @@ class Value bool isProtectedType() const { return cself()._protectType; } - void error(const char* pcMsg); + void error(string sMsg); int32_t asLong() const noexcept; double asReal() const noexcept; std::string asString(bool bForceLiteral = false) const; diff --git a/Vorlage/CRNE.cpp b/Vorlage/CRNE.cpp index 2ce96fa..043ca37 100644 --- a/Vorlage/CRNE.cpp +++ b/Vorlage/CRNE.cpp @@ -72,7 +72,7 @@ void CRNENode::AddToPool(const std::string& sName, const std::string& sRNE) void CRNENode::DumpRNEPool() { for (RNEPOOL::iterator i = m_cpoRNEPool.begin(); i != m_cpoRNEPool.end(); i++) { - printf("$%s = %s\n", (*i).first.c_str(), (*i).second->String().c_str()); + std::cout << "$" << (*i).first << " = " << (*i).second->String() << "\n"; } } @@ -282,11 +282,11 @@ int main( int argc, char* argv[] ) } catch(CRNEException e) { - puts("Error in expression!"); + std::cerr << "Error in expression!\n"; poRNE = 0; } if( poRNE ) - for( i=0 ; iGenAVal().c_str() ); + for( i=0 ; iGenAVal() << "\n"; } return 0; diff --git a/Vorlage/Metascript.cpp b/Vorlage/Metascript.cpp index 26c9688..d7e4836 100644 --- a/Vorlage/Metascript.cpp +++ b/Vorlage/Metascript.cpp @@ -80,7 +80,6 @@ #include "CRNE.h" -using namespace std; extern std::string GetConfigFileName(); extern FILE* g_hErr; @@ -3227,9 +3226,7 @@ bool DoUserFunction(const std::string& sName, ArgumentList& coArgs, Value* poVal sStackInfo = std::string("#func ") + sName; if (!pMC->IsFunction()) { - char Buff[256]; - snprintf(Buff, sizeof(Buff), "Die Prozedur '#proc %s' kann nicht als Funktion aufgerufen werden!", sName.c_str()); - poVal->error(std::string(Buff).c_str()); + poVal->error(fmt::format("Die Prozedur '#proc {}' kann nicht als Funktion aufgerufen werden!", sName)); return false; } @@ -3246,9 +3243,7 @@ bool DoUserFunction(const std::string& sName, ArgumentList& coArgs, Value* poVal // coRefs[argi-2] = m_pvRef; m_pvRef = 0; } else { - char Buff[256]; - snprintf(Buff, sizeof(Buff), "Ueberzaehliges Argument '%s' fuer Funktion '%s'!", coArgs[nTC].asString().c_str(), sName.c_str()); - poVal->error(std::string(Buff).c_str()); + poVal->error(fmt::format("Ueberzaehliges Argument '{}' fuer Funktion '{}'!", coArgs[nTC].asString().c_str(), sName)); return false; } nTC++; @@ -3274,9 +3269,7 @@ bool DoUserFunction(const std::string& sName, ArgumentList& coArgs, Value* poVal } #ifdef ROCK_SOLID_CATCH catch (...) { - char Buff[256]; - snprintf(Buff, sizeof(Buff), "Unerwartete Ausnahmebehandlung in Funktion '%s'!", sName.c_str()); - poVal->error(std::string(Buff).c_str()); + poVal->error(fmt::format("Unerwartete Ausnahmebehandlung in Funktion '{}'!", sName)); if (g_poStepOut == &oMCI) CMetaCommand::SetTrace(2); g_coCallStack.pop_back(); @@ -3308,9 +3301,7 @@ bool DoUserFunction(const std::string& sName, ArgumentList& coArgs, Value* poVal } else { if (argi - 1 < nPArgs) { - char Buff[256]; - snprintf(Buff, sizeof(Buff), "Zu wenig Argumente fuer Funktion '%s'!", sName.c_str()); - poVal->error(std::string(Buff).c_str()); + poVal->error(fmt::format("Zu wenig Argumente fuer Funktion '{}'!", sName)); return false; } } @@ -4095,7 +4086,6 @@ void CMetaCommand::RunScript(CMCI& oMCI, Expression::Variables& oContext, std::s int n; if (oMCI.m_nTC <= (int)Args()) { CReference* pRef; - char Buff[16]; size_t nPos = (size_t)oMCI.m_nTC; Parse(oMCI, oContext, coCmd); n = atoi(oMCI.m_sArg.c_str()); @@ -4115,8 +4105,7 @@ void CMetaCommand::RunScript(CMCI& oMCI, Expression::Variables& oContext, std::s } else { if (psCom) { - snprintf(Buff, sizeof(Buff), "%d", n < 0 ? 0 : n); - (*this)[nPos] = Buff; + (*this)[nPos] = std::to_string(n < 0 ? 0 : n); if (n <= 0 && nPos >= 2) (*this)[nPos - 2] = ";"; *psCom = AsString(); @@ -4132,7 +4121,6 @@ void CMetaCommand::RunScript(CMCI& oMCI, Expression::Variables& oContext, std::s int n; if (oMCI.m_nTC <= (int)Args()) { CReference* pRef; - char Buff[16]; size_t nPos = (size_t)oMCI.m_nTC; Parse(oMCI, oContext, coCmd); n = atoi(oMCI.m_sArg.c_str()); @@ -4153,8 +4141,7 @@ void CMetaCommand::RunScript(CMCI& oMCI, Expression::Variables& oContext, std::s } else { if (psCom) { - snprintf(Buff, sizeof(Buff), "%d", n); - (*this)[nPos] = Buff; + (*this)[nPos] = std::to_string(n); *psCom = AsString(); } else { @@ -4168,7 +4155,6 @@ void CMetaCommand::RunScript(CMCI& oMCI, Expression::Variables& oContext, std::s int n, m; if (oMCI.m_nTC <= (int)Args()) { CReference* pRef; - char Buff[16]; size_t nPos; Parse(oMCI, oContext, coCmd); m = atoi(oMCI.m_sArg.c_str()); @@ -4190,8 +4176,7 @@ void CMetaCommand::RunScript(CMCI& oMCI, Expression::Variables& oContext, std::s } else { if (psCom) { - snprintf(Buff, sizeof(Buff), "%d", n); - (*this)[nPos] = Buff; + (*this)[nPos] = std::to_string(n); *psCom = AsString(); } else { @@ -5456,9 +5441,7 @@ int32_t CScriptBase::AddProc(const CharacterMapper* pMapper, const std::string& i++; } - char Buff[8]; - snprintf(Buff, sizeof(Buff), "%d", bVArg ? -(i - 1) : i - 1); - (*pMC)[0] = Buff; + (*pMC)[0] = fmt::format("{}", bVArg ? -(i - 1) : i - 1); if (pMC->Args() >= 2) { COMMANDBASE::iterator cbi = m_cpoSubs.find((*pMC)[1]); diff --git a/Vorlage/Zugvorlage.cpp b/Vorlage/Zugvorlage.cpp index 94d768e..ee41029 100644 --- a/Vorlage/Zugvorlage.cpp +++ b/Vorlage/Zugvorlage.cpp @@ -475,7 +475,7 @@ void CVorlage::Islandize(CKarte::IslandQueue& cpoQueue, RegionDB& coRDB) #define PIPRINT \ g_bForceEOL = true; \ - COutput::Target("console")->Printf + COutput::Target("console")->Print void CVorlage::RunMetacommands(CReport& oReport) { @@ -484,7 +484,7 @@ void CVorlage::RunMetacommands(CReport& oReport) CEinheit* poUnit = nullptr; int32_t nUnitCnt = 0; bool bDoneReg = false; - char pcPass[16]; + std::string pcPass; // Expression::clearAllVars(); m_nPlayer = oReport.Partei(); @@ -493,14 +493,14 @@ void CVorlage::RunMetacommands(CReport& oReport) g_poKarte = m_poKarte; if (g_nMinPasses) - snprintf(pcPass, sizeof(pcPass), "Pass %ld: ", g_nPassNum); + pcPass = fmt::format("Pass {}: ", g_nPassNum); else - pcPass[0] = 0; + pcPass.clear(); if (IsFlag(VF_PROGRESSINFO)) { if (g_nPassNum <= 1) TRACEMSG(("\n")); - PIPRINT("\r%sEinheiten: %3d%% - OnInit", pcPass, nUnitCnt * 100 / m_nUnits); + PIPRINT("\r{}Einheiten: {:3}% - OnInit", pcPass, nUnitCnt * 100 / m_nUnits); } Value vCurrentMeta(-1); Expression::setGlobal("$CURRENTMETA", &vCurrentMeta); @@ -529,10 +529,10 @@ void CVorlage::RunMetacommands(CReport& oReport) if (IsFlag(VF_RUNALLVISIBLEREGIONS)) { if (IsFlag(VF_PROGRESSINFO)) { if (poReg->GetEZ()) { - PIPRINT("\r%sEinheiten: %3d%% - OnRegion(%d,%d,%d)", pcPass, nUnitCnt * 100 / m_nUnits, poReg->GetEX(), poReg->GetEY(), poReg->GetEZ()); + PIPRINT("\r{}Einheiten: {:3}% - OnRegion({},{},{})", pcPass, nUnitCnt * 100 / m_nUnits, poReg->GetEX(), poReg->GetEY(), poReg->GetEZ()); } else { - PIPRINT("\r%sEinheiten: %3d%% - OnRegion(%d,%d)", pcPass, nUnitCnt * 100 / m_nUnits, poReg->GetEX(), poReg->GetEY()); + PIPRINT("\r{}Einheiten: {:3}% - OnRegion({},{})", pcPass, nUnitCnt * 100 / m_nUnits, poReg->GetEX(), poReg->GetEY()); } } CMetaCommand::Call(std::string("OnRegion"), poReg->GetKommandos()); @@ -560,10 +560,10 @@ void CVorlage::RunMetacommands(CReport& oReport) if (!bDoneReg) { if (IsFlag(VF_PROGRESSINFO)) { if (poReg->GetEZ()) { - PIPRINT("\r%sEinheiten: %3d%% - OnRegion(%d,%d,%d)", pcPass, nUnitCnt * 100 / m_nUnits, poReg->GetEX(), poReg->GetEY(), poReg->GetEZ()); + PIPRINT("\r{}Einheiten: {:3}% - OnRegion({},{},{})", pcPass, nUnitCnt * 100 / m_nUnits, poReg->GetEX(), poReg->GetEY(), poReg->GetEZ()); } else { - PIPRINT("\r%sEinheiten: %3d%% - OnRegion(%d,%d)", pcPass, nUnitCnt * 100 / m_nUnits, poReg->GetEX(), poReg->GetEY()); + PIPRINT("\r{}Einheiten: {:3}% - OnRegion({},{})", pcPass, nUnitCnt * 100 / m_nUnits, poReg->GetEX(), poReg->GetEY()); } } CMetaCommand::Call(std::string("OnRegion"), poReg->GetKommandos()); @@ -592,14 +592,14 @@ void CVorlage::RunMetacommands(CReport& oReport) g_poCurrentUnit = poUnit; if (IsFlag(VF_PROGRESSINFO)) { - PIPRINT("\r%sEinheiten: %3d%% - OnUnit(%s) ", pcPass, nUnitCnt * 100 / m_nUnits, itoan(poUnit->m_nNummer, g_poCurrentReport->ENrBase())); + PIPRINT("\r{}Einheiten: {:3}% - OnUnit({}) ", pcPass, nUnitCnt * 100 / m_nUnits, itoan(poUnit->m_nNummer, g_poCurrentReport->ENrBase())); } CMetaCommand::Call(std::string("OnUnit"), poUnit->m_csMetaOut); if (Expression::getGlobal("$EXECINLINE").asLong()) { if (IsFlag(VF_PROGRESSINFO)) { - PIPRINT("\r%sEinheiten: %3d%% - [%s] ", pcPass, nUnitCnt * 100 / m_nUnits, itoan(poUnit->m_nNummer, g_poCurrentReport->ENrBase())); + PIPRINT("\r{}Einheiten: {:3}% - [{}] ", pcPass, nUnitCnt * 100 / m_nUnits, itoan(poUnit->m_nNummer, g_poCurrentReport->ENrBase())); } if (IsFlag(VF_PRIVATMETA)) { @@ -678,7 +678,7 @@ void CVorlage::RunMetacommands(CReport& oReport) } if (IsFlag(VF_PROGRESSINFO)) { - PIPRINT("\r%sEinheiten: %3d%% - EndUnit(%s) ", pcPass, nUnitCnt * 100 / m_nUnits, itoan(poUnit->m_nNummer, g_poCurrentReport->ENrBase())); + PIPRINT("\r{}Einheiten: {:3}% - EndUnit({}) ", pcPass, nUnitCnt * 100 / m_nUnits, itoan(poUnit->m_nNummer, g_poCurrentReport->ENrBase())); nUnitCnt++; } CMetaCommand::Call(std::string("EndUnit"), poUnit->m_csMetaOut); @@ -689,10 +689,10 @@ void CVorlage::RunMetacommands(CReport& oReport) if (bDoneReg) { if (IsFlag(VF_PROGRESSINFO)) { if (poReg->GetEZ()) { - PIPRINT("\r%sEinheiten: %3d%% - EndRegion(%d,%d,%d)", pcPass, nUnitCnt * 100 / m_nUnits, poReg->GetEX(), poReg->GetEY(), poReg->GetEZ()); + PIPRINT("\r{}Einheiten: {:3}% - EndRegion({},{},{})", pcPass, nUnitCnt * 100 / m_nUnits, poReg->GetEX(), poReg->GetEY(), poReg->GetEZ()); } else { - PIPRINT("\r%sEinheiten: %3d%% - EndRegion(%d,%d)", pcPass, nUnitCnt * 100 / m_nUnits, poReg->GetEX(), poReg->GetEY()); + PIPRINT("\r{}Einheiten: {:3}% - EndRegion({},{})", pcPass, nUnitCnt * 100 / m_nUnits, poReg->GetEX(), poReg->GetEY()); } } CMetaCommand::Call(std::string("EndRegion"), poReg->GetEndKommandos()); @@ -703,12 +703,12 @@ void CVorlage::RunMetacommands(CReport& oReport) } if (IsFlag(VF_PROGRESSINFO)) { - PIPRINT("\r%sEinheiten: %3d%% - OnExit", pcPass, nUnitCnt * 100 / m_nUnits); + PIPRINT("\r{}Einheiten: {:3}% - OnExit", pcPass, nUnitCnt * 100 / m_nUnits); } CMetaCommand::Call(std::string("OnExit"), m_coExitCmd); if (IsFlag(VF_PROGRESSINFO)) { - PIPRINT("\r%sEinheiten: %3d%% \n", pcPass, nUnitCnt * 100 / m_nUnits); + PIPRINT("\r{}Einheiten: {:3}% \n", pcPass, nUnitCnt * 100 / m_nUnits); } } @@ -828,8 +828,8 @@ void CVorlage::Vorlage(CReport& oReport, CReport* poRep2, bool bTime) if (poRep2) { for (CReport::Einheiten::iterator ei = poRep2->GEinheiten().begin(); ei != poRep2->GEinheiten().end(); ei++) { if ((*ei).second->Partei() == m_nPlayer) { - nUnits++; - nPersons += (*ei).second->Anzahl(); + //nUnits2++; + //nPersons2 += (*ei).second->Anzahl(); if (0 != CRasse::Lookup((*ei).second->RealType()).GetValue(std::string("Unterhalt")).asLong()) { nNeededFood2 += CRasse::Lookup((*ei).second->RealType()).GetValue(std::string("Unterhalt")).asLong() * (*ei).second->Anzahl(); } @@ -991,13 +991,13 @@ void CVorlage::Vorlage(CReport& oReport, CReport* poRep2, bool bTime) if (IsFlag(VF_SHOWHANDEL)) { target->Write("\n ; Wirtschaftsbilanz:\n"); if (poRep2 && poRep2->m_nEinkommen > 0) - target->Print(" ; Gesamteinkommen:{:9} ({:+}) Silber\n", oReport.m_nEinkommen, oReport.m_nEinkommen - poRep2->m_nEinkommen); + target->Print(" ; Gesamteinkommen:{:12} ({:+}) Silber\n", oReport.m_nEinkommen, oReport.m_nEinkommen - poRep2->m_nEinkommen); else - target->Print(" ; Gesamteinkommen:{:9} Silber\n", oReport.m_nEinkommen); + target->Print(" ; Gesamteinkommen:{:12} Silber\n", oReport.m_nEinkommen); if (poRep2 && poRep2->m_nAusgaben > 0) - target->Print(" ; Gesamtausgaben: {:9} ({:+}) Silber {}\n", oReport.m_nAusgaben + nNeededFood /*Eater*10*/, (oReport.m_nAusgaben + nNeededFood) - (poRep2->m_nAusgaben + nNeededFood2), oReport.Version() > 40 ? "" : "(z.Zt. ohne kostenpfl. Talente)"); + target->Print(" ; Gesamtausgaben: {:12} ({:+}) Silber {}\n", oReport.m_nAusgaben + nNeededFood /*Eater*10*/, (oReport.m_nAusgaben + nNeededFood) - (poRep2->m_nAusgaben + nNeededFood2), oReport.Version() > 40 ? "" : "(z.Zt. ohne kostenpfl. Talente)"); else - target->Print(" ; Gesamtausgaben: {:9} Silber {}\n", oReport.m_nAusgaben + nNeededFood /*Eater*10*/, oReport.Version() > 40 ? "" : "(z.Zt. ohne kostenpfl. Talente)"); + target->Print(" ; Gesamtausgaben: {:12} Silber {}\n", oReport.m_nAusgaben + nNeededFood /*Eater*10*/, oReport.Version() > 40 ? "" : "(z.Zt. ohne kostenpfl. Talente)"); int64_t nVermoegen = 0, nVermoegen2 = 0; for (auto rmi = m_poKarte->Regions().begin(); rmi != m_poKarte->Regions().end(); rmi++) { nVermoegen += (*rmi).second->SilverOf(oReport.Partei()); @@ -1008,9 +1008,9 @@ void CVorlage::Vorlage(CReport& oReport, CReport* poRep2, bool bTime) } } if (poRep2 && nVermoegen2 > 0) - target->Print(" ; Gesamtverm\xF6gen: {:9} ({:+}) Silber\n", nVermoegen, nVermoegen - nVermoegen2); + target->Print(" ; Gesamtverm\xF6gen: {:12} ({:+}) Silber\n", nVermoegen, nVermoegen - nVermoegen2); else - target->Print(" ; Gesamtverm\xF6gen: {:9} Silber\n", nVermoegen); + target->Print(" ; Gesamtverm\xF6gen: {:12} Silber\n", nVermoegen); if (oReport.m_cpoHPartner.size()) target->Write("\n ; Warenaustausch:\n"); @@ -1617,15 +1617,15 @@ void CVorlage::Regionsvorlage(CRegion* poReg, CRegion* poReg2, CReport* poRep2) OT.Output("vorlage", std::string(" ; ")); if (IsFlag(VF_SHOWLUXUS) || IsFlag(VF_SHOWLPROD)) { - static char Delta[32]; + static std::string Delta; if (poReg->GetVerkauf() >= 0 && size_t(poReg->GetVerkauf()) < poReg->GetLuxusgueter().size()) { target->Write(" ; Prod.: "); if (bDiff) { - snprintf(Delta, sizeof(Delta), "%+5ld", + Delta = fmt::format("{:+5}", (poReg2->GetLuxusgueter().size() > size_t(poReg2->GetVerkauf())) ? poReg->GetLuxusgueter()[size_t(poReg->GetVerkauf())].second - poReg2->GetLuxusgueter()[size_t(poReg2->GetVerkauf())].second : 0); } else { - Delta[0] = 0; + Delta.clear(); } target->Print("{:<10}{:4}{} max. handelbar: {}\n", poReg->GetLuxusgueter()[size_t(poReg->GetVerkauf())].first + ":", poReg->GetLuxusgueter()[size_t(poReg->GetVerkauf())].second, Delta, poReg->GetBauern() / 100); @@ -3540,7 +3540,7 @@ int main(int argc, char* argv[]) pTarget = COutput::Target("stderr"); } // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 - pTarget->Printf("\nAufruf: VORLAGE [Optionen] [CR-Datei1] { [CR-Datei2] {...} } { [> Vorlagendatei] }\n\n"); + pTarget->Write("\nAufruf: VORLAGE [Optionen] [CR-Datei1] { [CR-Datei2] {...} } { [> Vorlagendatei] }\n\n"); pTarget->Write(" -b Beschreibungen der Einheiten mit in die Vorlage uebernehmen\n"); pTarget->Write(" -cfg s Gibt den Basisnamen der Konfigurationsdatei an\n"); pTarget->Write(" --cfgpath p Pfad in dem die Konfig-Dateien gesucht werden\n"); From 13e51d83e5007f147b6b70ff08b9ce11ccba8038 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Schu=CC=88mann?= Date: Tue, 28 Apr 2026 08:55:14 +0200 Subject: [PATCH 8/8] Wrap long detail outputs for EINHEIT-lines. --- Vorlage/Zugvorlage.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Vorlage/Zugvorlage.cpp b/Vorlage/Zugvorlage.cpp index ee41029..419388e 100644 --- a/Vorlage/Zugvorlage.cpp +++ b/Vorlage/Zugvorlage.cpp @@ -2193,18 +2193,15 @@ void CVorlage::Einheitenvorlage(CEinheit* poUnit, CReport* poRep2) else { // if( IsFlag( VF_BASE36 ) ) if (IsFlag(VF_SHOWVERBOSEINFO)) { - target->Print("\n EINHEIT {}; {} [{},{}${}] {}{}{}{}{}{}\n", itoan(poUnit->m_nNummer, g_poCurrentReport->ENrBase()), poUnit->m_sName, poUnit->m_nAnzahl, poUnit->m_nSilber, getAndReset(out), + WrapOut(" ; ", fmt::format("EINHEIT {}; {} [{},{}${}] {}{}{}{}{}{}", itoan(poUnit->m_nNummer, g_poCurrentReport->ENrBase()), poUnit->m_sName, poUnit->m_nAnzahl, poUnit->m_nSilber, getAndReset(out), !poUnit->WahrerTyp().empty() ? poUnit->Typ() + ", " : "", poUnit->m_nParteitarnung ? "parteigetarnt, " : "", poUnit->m_nBewacht ? "bewacht, " : "", - poUnit->m_shp.empty() ? std::string{} : poUnit->m_shp + ", ", pcKampf, poUnit->m_nHunger ? ", hungert" : ""); + poUnit->m_shp.empty() ? std::string{} : poUnit->m_shp + ", ", pcKampf, poUnit->m_nHunger ? ", hungert" : ""), g_nLineSize, "\n "); if (poUnit->m_nVerkleidung) { target->Print(" ; Verkleidet als {} ({})\n", poUnit->Region()->Map()->Report()->Parteiname(poUnit->m_nVerkleidung).substr(1), itoan(poUnit->m_nVerkleidung, g_poCurrentReport->PNrBase())); } if (poUnit->m_nVerraeter) { target->Write(" ; VERR\xC4TER!\n"); } - // else - // COutput::TPrintf( "vorlage", "\n EINHEIT %6d; %s [%d,%d$%s] %s%s%s%s%s%s\n", poUnit->m_nNummer, poUnit->m_sName.c_str(), poUnit->m_nAnzahl, poUnit->m_nSilber, Buff, (!poUnit->m_sWahrerTyp.empty())?poUnit->m_sTyp.c_str():"", - // poUnit->m_nParteitarnung?"parteigetarnt, ":"", poUnit->m_nBewacht?"bewacht, ":"", poUnit->m_shp.empty()?"":std::string( poUnit->m_shp + ", " ).c_str(), pcKampf, (poUnit->m_nHunger)?", hungert":"" ); } else { target->Print(" EINHEIT {}; {} [{},{}${}]\n", itoan(poUnit->m_nNummer, g_poCurrentReport->ENrBase()), poUnit->m_sName, poUnit->m_nAnzahl, poUnit->m_nSilber, getAndReset(out));