Add debug console command to show cargo packet deferred payment stats

This commit is contained in:
Jonathan G Rennison 2018-01-28 17:26:35 +00:00
parent decc0f210c
commit 2c16800454
2 changed files with 40 additions and 0 deletions

View File

@ -18,6 +18,8 @@
#include "order_type.h" #include "order_type.h"
#include "company_func.h" #include "company_func.h"
#include "core/backup_type.hpp" #include "core/backup_type.hpp"
#include "string_func.h"
#include "strings_func.h"
#include "3rdparty/cpp-btree/btree_map.h" #include "3rdparty/cpp-btree/btree_map.h"
#include "safeguards.h" #include "safeguards.h"
@ -71,6 +73,29 @@ inline void IterateCargoPacketDeferredPayments(CargoPacketID index, bool erase_r
} }
} }
void DumpCargoPacketDeferredPaymentStats(char *buffer, const char *last)
{
Money payments[256][4] = {};
for (auto &it : _cargo_packet_deferred_payments) {
payments[GB(it.first, 24, 8)][GB(it.first, 22, 2)] += it.second;
}
for (uint i = 0; i < 256; i++) {
for (uint j = 0; j < 4; j++) {
if (payments[i][j] != 0) {
SetDParam(0, i);
buffer = GetString(buffer, STR_COMPANY_NAME, last);
buffer += seprintf(buffer, last, " (");
buffer = GetString(buffer, STR_REPLACE_VEHICLE_TRAIN + j, last);
buffer += seprintf(buffer, last, "): ");
SetDParam(0, payments[i][j]);
buffer = GetString(buffer, STR_JUST_CURRENCY_LONG, last);
buffer += seprintf(buffer, last, "\n");
}
}
}
buffer += seprintf(buffer, last, "Deferred payment count: %u\n", (uint) _cargo_packet_deferred_payments.size());
}
/** /**
* Create a new packet for savegame loading. * Create a new packet for savegame loading.
*/ */

View File

@ -1882,6 +1882,20 @@ DEF_CONSOLE_CMD(ConNewGRFReload)
return true; return true;
} }
DEF_CONSOLE_CMD(ConDumpCpdpStats)
{
if (argc == 0) {
IConsoleHelp("Dump cargo packet deferred payment stats.");
return true;
}
extern void DumpCargoPacketDeferredPaymentStats(char *buffer, const char *last);
char buffer[32768];
DumpCargoPacketDeferredPaymentStats(buffer, lastof(buffer));
PrintLineByLine(buffer);
return true;
}
#ifdef _DEBUG #ifdef _DEBUG
/****************** /******************
* debug commands * debug commands
@ -2025,6 +2039,7 @@ void IConsoleStdLibRegister()
#ifdef _DEBUG #ifdef _DEBUG
IConsoleDebugLibRegister(); IConsoleDebugLibRegister();
#endif #endif
IConsoleCmdRegister("dump_cpdp_stats", ConDumpCpdpStats);
/* NewGRF development stuff */ /* NewGRF development stuff */
IConsoleCmdRegister("reload_newgrfs", ConNewGRFReload, ConHookNewGRFDeveloperTool); IConsoleCmdRegister("reload_newgrfs", ConNewGRFReload, ConHookNewGRFDeveloperTool);