From 3813b3ca0951b5017a7d331d82899bee141ad4d0 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Wed, 22 Feb 2017 02:47:53 +0000 Subject: [PATCH] Dump infrastructure totals when mismatch detected in CheckCaches. --- src/company_base.h | 2 ++ src/company_cmd.cpp | 15 +++++++++++++++ src/openttd.cpp | 5 +++++ 3 files changed, 22 insertions(+) diff --git a/src/company_base.h b/src/company_base.h index 0017761216..847f40a8a7 100644 --- a/src/company_base.h +++ b/src/company_base.h @@ -43,6 +43,8 @@ struct CompanyInfrastructure { for (RailType rt = RAILTYPE_BEGIN; rt < RAILTYPE_END; rt++) total += this->rail[rt]; return total; } + + char *Dump(char *buffer, const char *last) const; }; typedef Pool CompanyPool; diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index b2a8c010a3..f5c0684850 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -1166,3 +1166,18 @@ int CompanyServiceInterval(const Company *c, VehicleType type) case VEH_SHIP: return vds->servint_ships; } } + +char *CompanyInfrastructure::Dump(char *buffer, const char *last) const +{ + for (RailType rt = RAILTYPE_BEGIN; rt != RAILTYPE_END; rt++) { + if (rail[rt]) buffer += seprintf(buffer, last, "Rail: %s: %u\n", GetStringPtr(GetRailTypeInfo(rt)->strings.name), rail[rt]); + } + buffer += seprintf(buffer, last, "Signal: %u\n", signal); + buffer += seprintf(buffer, last, "Road: %u\n", road[ROADTYPE_ROAD]); + buffer += seprintf(buffer, last, "Tram: %u\n", road[ROADTYPE_TRAM]); + buffer += seprintf(buffer, last, "Water: %u\n", water); + buffer += seprintf(buffer, last, "Station: %u\n", station); + buffer += seprintf(buffer, last, "Airport: %u\n", airport); + + return buffer; +} diff --git a/src/openttd.cpp b/src/openttd.cpp index 05ee7b4476..ce03275273 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -1317,6 +1317,11 @@ void CheckCaches(bool force_check) FOR_ALL_COMPANIES(c) { if (MemCmpT(old_infrastructure.Get(i), &c->infrastructure) != 0) { DEBUG(desync, 0, "infrastructure cache mismatch: company %i", (int)c->index); + char buffer[4096]; + old_infrastructure.Get(i)->Dump(buffer, lastof(buffer)); + DEBUG(desync, 0, "Previous:\n%s", buffer); + c->infrastructure.Dump(buffer, lastof(buffer)); + DEBUG(desync, 0, "Recalculated:\n%s", buffer); } i++; }