2016-02-17 19:45:07 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file scope_info.cpp Scope info debug functions. */
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "scope_info.h"
|
|
|
|
#include "string_func.h"
|
|
|
|
#include "strings_func.h"
|
|
|
|
#include "company_base.h"
|
|
|
|
#include "vehicle_base.h"
|
2018-05-31 17:36:12 +00:00
|
|
|
#include "station_base.h"
|
|
|
|
#include "waypoint_base.h"
|
2018-07-26 17:52:47 +00:00
|
|
|
#include "map_func.h"
|
2020-04-27 16:21:11 +00:00
|
|
|
#include "window_func.h"
|
|
|
|
#include "window_gui.h"
|
2016-02-17 19:45:07 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
|
|
|
|
#include "safeguards.h"
|
|
|
|
|
|
|
|
#ifdef USE_SCOPE_INFO
|
|
|
|
|
|
|
|
std::vector<std::function<int(char *, const char *)>> _scope_stack;
|
|
|
|
|
|
|
|
int WriteScopeLog(char *buf, const char *last)
|
|
|
|
{
|
|
|
|
char *b = buf;
|
|
|
|
if (!_scope_stack.empty()) {
|
|
|
|
b += seprintf(b, last, "Within context:");
|
|
|
|
int depth = 0;
|
|
|
|
for (auto it = _scope_stack.rbegin(); it != _scope_stack.rend(); ++it, depth++) {
|
|
|
|
b += seprintf(b, last, "\n %2d: ", depth);
|
|
|
|
b += (*it)(b, last);
|
|
|
|
}
|
|
|
|
b += seprintf(b, last, "\n\n");
|
|
|
|
}
|
|
|
|
return b - buf;
|
|
|
|
}
|
|
|
|
|
2018-07-25 07:13:15 +00:00
|
|
|
#endif
|
|
|
|
|
2016-02-17 19:45:07 +00:00
|
|
|
// helper functions
|
2016-02-25 00:20:31 +00:00
|
|
|
const char *scope_dumper::CompanyInfo(int company_id)
|
2016-02-17 19:45:07 +00:00
|
|
|
{
|
2016-02-25 00:20:31 +00:00
|
|
|
char *b = this->buffer;
|
|
|
|
const char *last = lastof(this->buffer);
|
|
|
|
b += seprintf(b, last, "%d (", company_id);
|
2016-02-17 19:45:07 +00:00
|
|
|
SetDParam(0, company_id);
|
2016-02-25 00:20:31 +00:00
|
|
|
b = GetString(b, STR_COMPANY_NAME, last);
|
|
|
|
b += seprintf(b, last, ")");
|
|
|
|
return buffer;
|
2016-02-17 19:45:07 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 00:20:31 +00:00
|
|
|
const char *scope_dumper::VehicleInfo(const Vehicle *v)
|
2016-02-17 19:45:07 +00:00
|
|
|
{
|
2016-02-25 00:20:31 +00:00
|
|
|
char *b = this->buffer;
|
|
|
|
const char *last = lastof(this->buffer);
|
2018-01-29 00:14:55 +00:00
|
|
|
auto dump_flags = [&](const Vehicle *u) {
|
2020-07-09 16:40:00 +00:00
|
|
|
b = u->DumpVehicleFlags(b, last, true);
|
2018-01-29 00:14:55 +00:00
|
|
|
};
|
2016-02-17 19:45:07 +00:00
|
|
|
if (v) {
|
2016-02-25 00:20:31 +00:00
|
|
|
b += seprintf(b, last, "veh: %u: (", v->index);
|
2016-02-25 19:21:06 +00:00
|
|
|
if (Vehicle::GetIfValid(v->index) != v) {
|
|
|
|
b += seprintf(b, last, "INVALID PTR: %p)", v);
|
|
|
|
return this->buffer;
|
|
|
|
}
|
2019-02-15 21:05:30 +00:00
|
|
|
switch (v->type) {
|
|
|
|
case VEH_EFFECT:
|
|
|
|
b += seprintf(b, last, "Effect Vehicle: subtype: %u", v->subtype);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VEH_DISASTER:
|
|
|
|
b += seprintf(b, last, "Disaster Vehicle: subtype: %u", v->subtype);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
SetDParam(0, v->index);
|
|
|
|
b = GetString(b, STR_VEHICLE_NAME, last);
|
|
|
|
break;
|
|
|
|
}
|
2021-02-01 17:30:41 +00:00
|
|
|
if (v->type < VEH_COMPANY_END) {
|
|
|
|
const char veh_type_chars[] = "TRSA";
|
|
|
|
b += seprintf(b, last, ", (%c%u)", veh_type_chars[v->type], v->unitnumber);
|
|
|
|
}
|
2018-01-29 00:14:55 +00:00
|
|
|
b += seprintf(b, last, ", c:%d, ", (int) v->owner);
|
|
|
|
dump_flags(v);
|
2016-02-17 19:45:07 +00:00
|
|
|
if (v->First() && v->First() != v) {
|
2017-06-21 20:10:22 +00:00
|
|
|
b += seprintf(b, last, ", front: %u: (", v->First()->index);
|
2016-02-25 19:21:06 +00:00
|
|
|
if (Vehicle::GetIfValid(v->First()->index) != v->First()) {
|
|
|
|
b += seprintf(b, last, "INVALID PTR: %p)", v->First());
|
|
|
|
return this->buffer;
|
|
|
|
}
|
2016-02-17 19:45:07 +00:00
|
|
|
SetDParam(0, v->First()->index);
|
2016-02-25 00:20:31 +00:00
|
|
|
b = GetString(b, STR_VEHICLE_NAME, last);
|
2018-01-29 00:14:55 +00:00
|
|
|
b += seprintf(b, last, ", ");
|
|
|
|
dump_flags(v->First());
|
2017-06-21 20:10:22 +00:00
|
|
|
b += seprintf(b, last, ")");
|
2016-02-17 19:45:07 +00:00
|
|
|
}
|
2016-02-25 00:20:31 +00:00
|
|
|
b += seprintf(b, last, ")");
|
2016-02-17 19:45:07 +00:00
|
|
|
} else {
|
2019-04-11 17:14:13 +00:00
|
|
|
b += seprintf(b, last, "veh: nullptr");
|
2016-02-17 19:45:07 +00:00
|
|
|
}
|
2016-02-25 00:20:31 +00:00
|
|
|
return this->buffer;
|
2016-02-17 19:45:07 +00:00
|
|
|
}
|
|
|
|
|
2018-05-31 17:36:12 +00:00
|
|
|
const char *scope_dumper::StationInfo(const BaseStation *st)
|
|
|
|
{
|
|
|
|
char *b = this->buffer;
|
|
|
|
const char *last = lastof(this->buffer);
|
|
|
|
|
|
|
|
if (st) {
|
|
|
|
const bool waypoint = Waypoint::IsExpected(st);
|
2018-05-31 17:37:08 +00:00
|
|
|
b += seprintf(b, last, "%s: %u: (", waypoint ? "waypoint" : "station", st->index);
|
|
|
|
SetDParam(0, st->index);
|
2018-05-31 17:36:12 +00:00
|
|
|
b = GetString(b, waypoint ? STR_WAYPOINT_NAME : STR_STATION_NAME, last);
|
|
|
|
b += seprintf(b, last, ", c:%d, facil: ", (int) st->owner);
|
|
|
|
auto dump_facil = [&](char c, StationFacility flag) {
|
|
|
|
if (st->facilities & flag) b += seprintf(b, last, "%c", c);
|
|
|
|
};
|
|
|
|
dump_facil('R', FACIL_TRAIN);
|
|
|
|
dump_facil('T', FACIL_TRUCK_STOP);
|
|
|
|
dump_facil('B', FACIL_BUS_STOP);
|
|
|
|
dump_facil('A', FACIL_AIRPORT);
|
|
|
|
dump_facil('D', FACIL_DOCK);
|
|
|
|
dump_facil('W', FACIL_WAYPOINT);
|
2018-05-31 17:37:08 +00:00
|
|
|
b += seprintf(b, last, ")");
|
2018-05-31 17:36:12 +00:00
|
|
|
} else {
|
2019-04-11 17:14:13 +00:00
|
|
|
b += seprintf(b, last, "station/waypoint: nullptr");
|
2018-05-31 17:36:12 +00:00
|
|
|
}
|
|
|
|
return this->buffer;
|
|
|
|
}
|
2018-07-26 17:52:47 +00:00
|
|
|
|
|
|
|
const char *scope_dumper::TileInfo(TileIndex tile)
|
|
|
|
{
|
2018-12-20 12:53:59 +00:00
|
|
|
DumpTileInfo(this->buffer, lastof(this->buffer), tile);
|
|
|
|
return this->buffer;
|
2018-07-26 17:52:47 +00:00
|
|
|
}
|
2020-04-27 16:21:11 +00:00
|
|
|
|
|
|
|
const char *scope_dumper::WindowInfo(const Window *w)
|
|
|
|
{
|
|
|
|
DumpWindowInfo(this->buffer, lastof(this->buffer), w);
|
|
|
|
return this->buffer;
|
|
|
|
}
|