2009-08-21 22:21:05 +02: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/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 17:11:33 +02:00
|
|
|
/** @file engine_gui.cpp GUI to show engine related information. */
|
2007-02-23 19:55:07 +01:00
|
|
|
|
2004-08-09 19:04:08 +02:00
|
|
|
#include "stdafx.h"
|
2007-12-19 21:45:46 +01:00
|
|
|
#include "window_gui.h"
|
2008-04-29 23:31:29 +02:00
|
|
|
#include "engine_base.h"
|
2007-12-21 22:50:46 +01:00
|
|
|
#include "command_func.h"
|
2007-12-21 20:49:27 +01:00
|
|
|
#include "strings_func.h"
|
2008-05-27 14:24:23 +02:00
|
|
|
#include "engine_gui.h"
|
2008-06-20 09:23:00 +02:00
|
|
|
#include "articulated_vehicles.h"
|
2009-05-27 19:18:53 +02:00
|
|
|
#include "vehicle_func.h"
|
|
|
|
#include "company_func.h"
|
2008-08-24 23:31:24 +02:00
|
|
|
#include "rail.h"
|
2019-04-06 08:46:15 +02:00
|
|
|
#include "road.h"
|
2009-10-27 20:56:00 +01:00
|
|
|
#include "settings_type.h"
|
2014-09-28 11:02:11 +02:00
|
|
|
#include "train.h"
|
|
|
|
#include "roadveh.h"
|
|
|
|
#include "ship.h"
|
|
|
|
#include "aircraft.h"
|
2021-10-31 19:39:09 +01:00
|
|
|
#include "engine_cmd.h"
|
2022-12-05 18:57:27 +01:00
|
|
|
#include "zoom_func.h"
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2011-12-15 23:22:55 +01:00
|
|
|
#include "widgets/engine_widget.h"
|
|
|
|
|
2008-01-13 02:21:35 +01:00
|
|
|
#include "table/strings.h"
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2014-04-23 22:13:33 +02:00
|
|
|
#include "safeguards.h"
|
|
|
|
|
2010-08-01 21:22:34 +02:00
|
|
|
/**
|
|
|
|
* Return the category of an engine.
|
2009-08-30 19:54:11 +02:00
|
|
|
* @param engine Engine to examine.
|
|
|
|
* @return String describing the category ("road veh", "train". "airplane", or "ship") of the engine.
|
|
|
|
*/
|
2008-05-13 12:17:04 +02:00
|
|
|
StringID GetEngineCategoryName(EngineID engine)
|
2004-08-09 19:04:08 +02:00
|
|
|
{
|
2009-10-06 21:17:07 +02:00
|
|
|
const Engine *e = Engine::Get(engine);
|
|
|
|
switch (e->type) {
|
2007-03-03 23:03:15 +01:00
|
|
|
default: NOT_REACHED();
|
2019-04-06 08:46:15 +02:00
|
|
|
case VEH_ROAD:
|
|
|
|
return GetRoadTypeInfo(e->u.road.roadtype)->strings.new_engine;
|
2009-04-22 01:40:56 +02:00
|
|
|
case VEH_AIRCRAFT: return STR_ENGINE_PREVIEW_AIRCRAFT;
|
|
|
|
case VEH_SHIP: return STR_ENGINE_PREVIEW_SHIP;
|
2007-03-08 17:27:54 +01:00
|
|
|
case VEH_TRAIN:
|
2009-10-06 21:17:07 +02:00
|
|
|
return GetRailTypeInfo(e->u.rail.railtype)->strings.new_loco;
|
2004-11-19 20:13:32 +01:00
|
|
|
}
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
|
|
|
|
2024-01-15 23:49:24 +01:00
|
|
|
static constexpr NWidgetPart _nested_engine_preview_widgets[] = {
|
2009-03-28 14:35:07 +01:00
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-24 19:05:55 +01:00
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE),
|
|
|
|
NWidget(WWT_CAPTION, COLOUR_LIGHT_BLUE), SetDataTip(STR_ENGINE_PREVIEW_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
2009-03-28 14:35:07 +01:00
|
|
|
EndContainer(),
|
2009-11-24 22:13:36 +01:00
|
|
|
NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE),
|
2023-10-25 23:12:38 +02:00
|
|
|
NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_wide, 0), SetPadding(WidgetDimensions::unscaled.modalpopup),
|
|
|
|
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_EP_QUESTION), SetMinimalSize(300, 0), SetFill(1, 0),
|
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(85, WidgetDimensions::unscaled.hsep_wide, 85),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_EP_NO), SetDataTip(STR_QUIT_NO, STR_NULL), SetFill(1, 0),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_EP_YES), SetDataTip(STR_QUIT_YES, STR_NULL), SetFill(1, 0),
|
|
|
|
EndContainer(),
|
2009-03-28 14:35:07 +01:00
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2008-05-18 22:49:22 +02:00
|
|
|
struct EnginePreviewWindow : Window {
|
2014-09-28 11:21:51 +02:00
|
|
|
int vehicle_space; // The space to show the vehicle image
|
2009-11-08 20:22:45 +01:00
|
|
|
|
2013-05-26 21:23:42 +02:00
|
|
|
EnginePreviewWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
|
2008-05-18 22:49:22 +02:00
|
|
|
{
|
2013-05-26 21:23:42 +02:00
|
|
|
this->InitNested(window_number);
|
2012-12-09 17:54:23 +01:00
|
|
|
|
|
|
|
/* There is no way to recover the window; so disallow closure via DEL; unless SHIFT+DEL */
|
|
|
|
this->flags |= WF_STICKY;
|
2008-05-18 22:49:22 +02:00
|
|
|
}
|
2005-10-01 14:43:34 +02:00
|
|
|
|
2024-04-09 09:34:45 +02:00
|
|
|
void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
|
2009-11-08 20:22:45 +01:00
|
|
|
{
|
2011-12-16 17:27:45 +01:00
|
|
|
if (widget != WID_EP_QUESTION) return;
|
2009-11-08 20:22:45 +01:00
|
|
|
|
2014-09-28 11:02:11 +02:00
|
|
|
/* Get size of engine sprite, on loan from depot_gui.cpp */
|
2009-11-08 20:22:45 +01:00
|
|
|
EngineID engine = this->window_number;
|
2014-09-28 11:02:11 +02:00
|
|
|
EngineImageType image_type = EIT_PURCHASE;
|
|
|
|
uint x, y;
|
|
|
|
int x_offs, y_offs;
|
|
|
|
|
|
|
|
const Engine *e = Engine::Get(engine);
|
|
|
|
switch (e->type) {
|
|
|
|
default: NOT_REACHED();
|
|
|
|
case VEH_TRAIN: GetTrainSpriteSize( engine, x, y, x_offs, y_offs, image_type); break;
|
|
|
|
case VEH_ROAD: GetRoadVehSpriteSize( engine, x, y, x_offs, y_offs, image_type); break;
|
|
|
|
case VEH_SHIP: GetShipSpriteSize( engine, x, y, x_offs, y_offs, image_type); break;
|
|
|
|
case VEH_AIRCRAFT: GetAircraftSpriteSize(engine, x, y, x_offs, y_offs, image_type); break;
|
|
|
|
}
|
2022-12-05 18:57:27 +01:00
|
|
|
this->vehicle_space = std::max<int>(ScaleSpriteTrad(40), y - y_offs);
|
2014-09-28 11:02:11 +02:00
|
|
|
|
2024-04-09 09:34:45 +02:00
|
|
|
size.width = std::max(size.width, x + std::abs(x_offs));
|
2009-11-08 20:22:45 +01:00
|
|
|
SetDParam(0, GetEngineCategoryName(engine));
|
2024-04-09 09:34:45 +02:00
|
|
|
size.height = GetStringHeight(STR_ENGINE_PREVIEW_MESSAGE, size.width) + WidgetDimensions::scaled.vsep_wide + GetCharacterHeight(FS_NORMAL) + this->vehicle_space;
|
2009-11-08 20:22:45 +01:00
|
|
|
SetDParam(0, engine);
|
2024-04-09 09:34:45 +02:00
|
|
|
size.height += GetStringHeight(GetEngineInfoString(engine), size.width);
|
2009-11-08 20:22:45 +01:00
|
|
|
}
|
|
|
|
|
2023-12-29 20:11:59 +01:00
|
|
|
void DrawWidget(const Rect &r, WidgetID widget) const override
|
2009-11-08 20:22:45 +01:00
|
|
|
{
|
2011-12-16 17:27:45 +01:00
|
|
|
if (widget != WID_EP_QUESTION) return;
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2008-05-18 22:49:22 +02:00
|
|
|
EngineID engine = this->window_number;
|
2004-12-02 23:53:07 +01:00
|
|
|
SetDParam(0, GetEngineCategoryName(engine));
|
2022-09-23 10:36:22 +02:00
|
|
|
int y = DrawStringMultiLine(r, STR_ENGINE_PREVIEW_MESSAGE, TC_FROMSTRING, SA_HOR_CENTER | SA_TOP) + WidgetDimensions::scaled.vsep_wide;
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2023-01-22 22:06:48 +01:00
|
|
|
SetDParam(0, PackEngineNameDParam(engine, EngineNameContext::PreviewNews));
|
2022-10-15 19:06:55 +02:00
|
|
|
DrawString(r.left, r.right, y, STR_ENGINE_NAME, TC_BLACK, SA_HOR_CENTER);
|
2023-11-21 20:04:24 +01:00
|
|
|
y += GetCharacterHeight(FS_NORMAL);
|
2009-11-08 20:22:45 +01:00
|
|
|
|
2022-10-15 19:06:55 +02:00
|
|
|
DrawVehicleEngine(r.left, r.right, this->width >> 1, y + this->vehicle_space / 2, engine, GetEnginePalette(engine, _local_company), EIT_PREVIEW);
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2014-09-28 11:02:11 +02:00
|
|
|
y += this->vehicle_space;
|
2022-10-15 19:06:55 +02:00
|
|
|
DrawStringMultiLine(r.left, r.right, y, r.bottom, GetEngineInfoString(engine), TC_FROMSTRING, SA_CENTER);
|
2005-10-01 14:43:34 +02:00
|
|
|
}
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2023-12-29 20:11:59 +01:00
|
|
|
void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
|
2008-05-18 22:49:22 +02:00
|
|
|
{
|
|
|
|
switch (widget) {
|
2011-12-16 17:27:45 +01:00
|
|
|
case WID_EP_YES:
|
2021-11-05 23:55:23 +01:00
|
|
|
Command<CMD_WANT_ENGINE_PREVIEW>::Post(this->window_number);
|
2024-01-31 21:03:17 +01:00
|
|
|
[[fallthrough]];
|
2011-12-16 17:27:45 +01:00
|
|
|
case WID_EP_NO:
|
2021-05-15 23:12:25 +02:00
|
|
|
if (!_shift_pressed) this->Close();
|
2005-11-14 20:48:04 +01:00
|
|
|
break;
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
|
|
|
}
|
2012-12-09 17:55:21 +01:00
|
|
|
|
2023-09-16 22:20:53 +02:00
|
|
|
void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
|
2012-12-09 17:55:21 +01:00
|
|
|
{
|
|
|
|
if (!gui_scope) return;
|
|
|
|
|
|
|
|
EngineID engine = this->window_number;
|
2021-05-15 23:12:25 +02:00
|
|
|
if (Engine::Get(engine)->preview_company != _local_company) this->Close();
|
2012-12-09 17:55:21 +01:00
|
|
|
}
|
2008-05-18 22:49:22 +02:00
|
|
|
};
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2024-01-17 04:17:02 +01:00
|
|
|
static WindowDesc _engine_preview_desc(
|
2023-07-13 17:41:06 +02:00
|
|
|
WDP_CENTER, nullptr, 0, 0,
|
2007-02-01 16:49:12 +01:00
|
|
|
WC_ENGINE_PREVIEW, WC_NONE,
|
2009-11-24 18:28:29 +01:00
|
|
|
WDF_CONSTRUCTION,
|
2023-09-03 22:54:13 +02:00
|
|
|
std::begin(_nested_engine_preview_widgets), std::end(_nested_engine_preview_widgets)
|
2009-03-15 16:12:06 +01:00
|
|
|
);
|
2004-08-09 19:04:08 +02:00
|
|
|
|
|
|
|
|
2005-10-01 14:43:34 +02:00
|
|
|
void ShowEnginePreviewWindow(EngineID engine)
|
2004-08-09 19:04:08 +02:00
|
|
|
{
|
2008-05-18 22:49:22 +02:00
|
|
|
AllocateWindowDescFront<EnginePreviewWindow>(&_engine_preview_desc, engine);
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
|
|
|
|
2011-05-02 19:42:12 +02:00
|
|
|
/**
|
|
|
|
* Get the capacity of an engine with articulated parts.
|
|
|
|
* @param engine The engine to get the capacity of.
|
|
|
|
* @return The capacity.
|
|
|
|
*/
|
2009-10-06 21:52:38 +02:00
|
|
|
uint GetTotalCapacityOfArticulatedParts(EngineID engine)
|
2008-06-20 09:23:00 +02:00
|
|
|
{
|
2009-10-06 21:52:38 +02:00
|
|
|
CargoArray cap = GetCapacityOfArticulatedParts(engine);
|
2014-09-18 21:50:41 +02:00
|
|
|
return cap.GetSum<uint>();
|
2008-06-20 09:23:00 +02:00
|
|
|
}
|
|
|
|
|
2009-08-30 20:41:03 +02:00
|
|
|
static StringID GetTrainEngineInfoString(const Engine *e)
|
2005-07-01 16:05:44 +02:00
|
|
|
{
|
2024-01-26 22:02:27 +01:00
|
|
|
SetDParam(0, STR_ENGINE_PREVIEW_COST_WEIGHT);
|
|
|
|
SetDParam(1, e->GetCost());
|
|
|
|
SetDParam(2, e->GetDisplayWeight());
|
|
|
|
|
|
|
|
SetDParam(3, (_settings_game.vehicle.train_acceleration_model != AM_ORIGINAL && GetRailTypeInfo(e->u.rail.railtype)->acceleration_type != 2) ? STR_ENGINE_PREVIEW_SPEED_POWER_MAX_TE : STR_ENGINE_PREVIEW_SPEED_POWER);
|
|
|
|
SetDParam(4, PackVelocity(e->GetDisplayMaxSpeed(), e->type));
|
|
|
|
SetDParam(5, e->GetPower());
|
|
|
|
SetDParam(6, e->GetDisplayMaxTractiveEffort());
|
2005-07-01 16:05:44 +02:00
|
|
|
|
2024-01-26 22:02:27 +01:00
|
|
|
SetDParam(7, TimerGameEconomy::UsingWallclockUnits() ? STR_ENGINE_PREVIEW_RUNCOST_PERIOD : STR_ENGINE_PREVIEW_RUNCOST_YEAR);
|
|
|
|
SetDParam(8, e->GetRunningCost());
|
2005-07-01 16:05:44 +02:00
|
|
|
|
2024-01-26 22:02:27 +01:00
|
|
|
SetDParam(9, STR_ENGINE_PREVIEW_CAPACITY);
|
2009-10-06 21:52:38 +02:00
|
|
|
uint capacity = GetTotalCapacityOfArticulatedParts(e->index);
|
2024-01-26 22:02:27 +01:00
|
|
|
SetDParam(10, capacity != 0 ? e->GetDefaultCargoType() : INVALID_CARGO);
|
|
|
|
SetDParam(11, capacity);
|
|
|
|
|
|
|
|
return STR_ENGINE_PREVIEW_TEXT4;
|
2005-07-01 16:05:44 +02:00
|
|
|
}
|
|
|
|
|
2009-08-30 20:41:03 +02:00
|
|
|
static StringID GetAircraftEngineInfoString(const Engine *e)
|
2005-07-01 16:05:44 +02:00
|
|
|
{
|
2009-03-14 00:49:12 +01:00
|
|
|
CargoID cargo = e->GetDefaultCargoType();
|
2023-05-08 19:01:06 +02:00
|
|
|
uint16_t mail_capacity;
|
2009-10-31 18:48:09 +01:00
|
|
|
uint capacity = e->GetDisplayDefaultCapacity(&mail_capacity);
|
2023-05-08 19:01:06 +02:00
|
|
|
uint16_t range = e->GetRange();
|
2009-01-25 01:57:03 +01:00
|
|
|
|
2024-01-26 22:02:27 +01:00
|
|
|
SetDParam(0, STR_ENGINE_PREVIEW_COST_MAX_SPEED);
|
|
|
|
SetDParam(1, e->GetCost());
|
|
|
|
SetDParam(2, PackVelocity(e->GetDisplayMaxSpeed(), e->type));
|
|
|
|
|
|
|
|
SetDParam(3, range > 0 ? STR_ENGINE_PREVIEW_TYPE_RANGE : STR_ENGINE_PREVIEW_TYPE);
|
|
|
|
SetDParam(4, e->GetAircraftTypeText());
|
|
|
|
SetDParam(5, range);
|
|
|
|
|
|
|
|
SetDParam(7, TimerGameEconomy::UsingWallclockUnits() ? STR_ENGINE_PREVIEW_RUNCOST_PERIOD : STR_ENGINE_PREVIEW_RUNCOST_YEAR);
|
|
|
|
SetDParam(8, e->GetRunningCost());
|
|
|
|
|
|
|
|
SetDParam(9, mail_capacity > 0 ? STR_ENGINE_PREVIEW_CAPACITY_2 : STR_ENGINE_PREVIEW_CAPACITY);
|
|
|
|
SetDParam(10, cargo);
|
|
|
|
SetDParam(11, capacity);
|
2024-02-04 11:16:08 +01:00
|
|
|
SetDParam(12, GetCargoIDByLabel(CT_MAIL));
|
2024-01-26 22:02:27 +01:00
|
|
|
SetDParam(13, mail_capacity);
|
|
|
|
|
|
|
|
return STR_ENGINE_PREVIEW_TEXT4;
|
2005-07-01 16:05:44 +02:00
|
|
|
}
|
|
|
|
|
2009-08-30 20:41:03 +02:00
|
|
|
static StringID GetRoadVehEngineInfoString(const Engine *e)
|
2005-07-01 16:05:44 +02:00
|
|
|
{
|
2024-01-26 22:02:27 +01:00
|
|
|
SetDParam(7, TimerGameEconomy::UsingWallclockUnits() ? STR_ENGINE_PREVIEW_RUNCOST_PERIOD : STR_ENGINE_PREVIEW_RUNCOST_YEAR);
|
|
|
|
SetDParam(8, e->GetRunningCost());
|
|
|
|
|
|
|
|
SetDParam(9, STR_ENGINE_PREVIEW_CAPACITY);
|
|
|
|
uint capacity = GetTotalCapacityOfArticulatedParts(e->index);
|
|
|
|
SetDParam(10, capacity != 0 ? e->GetDefaultCargoType() : INVALID_CARGO);
|
|
|
|
SetDParam(11, capacity);
|
|
|
|
|
2010-03-06 13:59:28 +01:00
|
|
|
if (_settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL) {
|
2024-01-26 22:02:27 +01:00
|
|
|
SetDParam(0, STR_ENGINE_PREVIEW_COST_MAX_SPEED);
|
|
|
|
SetDParam(1, e->GetCost());
|
2023-04-08 18:26:13 +02:00
|
|
|
SetDParam(2, PackVelocity(e->GetDisplayMaxSpeed(), e->type));
|
2024-01-26 22:02:27 +01:00
|
|
|
|
|
|
|
return STR_ENGINE_PREVIEW_TEXT3;
|
|
|
|
} else {
|
|
|
|
SetDParam(0, STR_ENGINE_PREVIEW_COST_WEIGHT);
|
|
|
|
SetDParam(1, e->GetCost());
|
|
|
|
SetDParam(2, e->GetDisplayWeight());
|
|
|
|
|
|
|
|
SetDParam(3, STR_ENGINE_PREVIEW_SPEED_POWER_MAX_TE);
|
|
|
|
SetDParam(4, PackVelocity(e->GetDisplayMaxSpeed(), e->type));
|
|
|
|
SetDParam(5, e->GetPower());
|
|
|
|
SetDParam(6, e->GetDisplayMaxTractiveEffort());
|
|
|
|
|
|
|
|
return STR_ENGINE_PREVIEW_TEXT4;
|
2009-02-21 13:52:41 +01:00
|
|
|
}
|
2005-07-01 16:05:44 +02:00
|
|
|
}
|
|
|
|
|
2009-08-30 20:41:03 +02:00
|
|
|
static StringID GetShipEngineInfoString(const Engine *e)
|
2005-07-01 16:05:44 +02:00
|
|
|
{
|
2024-01-26 22:02:27 +01:00
|
|
|
SetDParam(0, STR_ENGINE_PREVIEW_COST_MAX_SPEED);
|
|
|
|
SetDParam(1, e->GetCost());
|
|
|
|
SetDParam(2, PackVelocity(e->GetDisplayMaxSpeed(), e->type));
|
|
|
|
|
|
|
|
SetDParam(7, TimerGameEconomy::UsingWallclockUnits() ? STR_ENGINE_PREVIEW_RUNCOST_PERIOD : STR_ENGINE_PREVIEW_RUNCOST_YEAR);
|
|
|
|
SetDParam(8, e->GetRunningCost());
|
|
|
|
|
|
|
|
SetDParam(9, STR_ENGINE_PREVIEW_CAPACITY);
|
|
|
|
SetDParam(10, e->GetDefaultCargoType());
|
|
|
|
SetDParam(11, e->GetDisplayDefaultCapacity());
|
|
|
|
|
|
|
|
return STR_ENGINE_PREVIEW_TEXT3;
|
2009-08-30 20:41:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a multi-line string with some technical data, describing the engine.
|
|
|
|
* @param engine Engine to describe.
|
|
|
|
* @return String describing the engine.
|
|
|
|
* @post \c DParam array is set up for printing the string.
|
|
|
|
*/
|
|
|
|
StringID GetEngineInfoString(EngineID engine)
|
|
|
|
{
|
|
|
|
const Engine *e = Engine::Get(engine);
|
|
|
|
|
|
|
|
switch (e->type) {
|
|
|
|
case VEH_TRAIN:
|
|
|
|
return GetTrainEngineInfoString(e);
|
|
|
|
|
|
|
|
case VEH_ROAD:
|
|
|
|
return GetRoadVehEngineInfoString(e);
|
|
|
|
|
|
|
|
case VEH_SHIP:
|
|
|
|
return GetShipEngineInfoString(e);
|
|
|
|
|
|
|
|
case VEH_AIRCRAFT:
|
|
|
|
return GetAircraftEngineInfoString(e);
|
|
|
|
|
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
2005-07-01 16:05:44 +02:00
|
|
|
}
|
|
|
|
|
2009-08-30 19:38:28 +02:00
|
|
|
/**
|
|
|
|
* Draw an engine.
|
2009-11-16 18:15:42 +01:00
|
|
|
* @param left Minimum horizontal position to use for drawing the engine
|
|
|
|
* @param right Maximum horizontal position to use for drawing the engine
|
|
|
|
* @param preferred_x Horizontal position to use for drawing the engine.
|
2009-08-30 19:38:28 +02:00
|
|
|
* @param y Vertical position to use for drawing the engine.
|
|
|
|
* @param engine Engine to draw.
|
2009-09-19 11:51:14 +02:00
|
|
|
* @param pal Palette to use for drawing.
|
2009-08-30 19:38:28 +02:00
|
|
|
*/
|
2011-11-01 17:51:47 +01:00
|
|
|
void DrawVehicleEngine(int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type)
|
2009-08-30 19:38:28 +02:00
|
|
|
{
|
|
|
|
const Engine *e = Engine::Get(engine);
|
|
|
|
|
|
|
|
switch (e->type) {
|
|
|
|
case VEH_TRAIN:
|
2011-11-01 17:51:47 +01:00
|
|
|
DrawTrainEngine(left, right, preferred_x, y, engine, pal, image_type);
|
2009-08-30 19:38:28 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VEH_ROAD:
|
2011-11-01 17:51:47 +01:00
|
|
|
DrawRoadVehEngine(left, right, preferred_x, y, engine, pal, image_type);
|
2009-08-30 19:38:28 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VEH_SHIP:
|
2011-11-01 17:51:47 +01:00
|
|
|
DrawShipEngine(left, right, preferred_x, y, engine, pal, image_type);
|
2009-08-30 19:38:28 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VEH_AIRCRAFT:
|
2011-11-01 17:51:47 +01:00
|
|
|
DrawAircraftEngine(left, right, preferred_x, y, engine, pal, image_type);
|
2009-08-30 19:38:28 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-01 21:22:34 +02:00
|
|
|
/**
|
|
|
|
* Sort all items using quick sort and given 'CompareItems' function
|
2008-05-27 14:24:23 +02:00
|
|
|
* @param el list to be sorted
|
|
|
|
* @param compare function for evaluation of the quicksort
|
|
|
|
*/
|
2023-05-14 10:17:44 +02:00
|
|
|
void EngList_Sort(GUIEngineList &el, EngList_SortTypeFunction compare)
|
2008-05-27 14:24:23 +02:00
|
|
|
{
|
2023-05-14 10:17:44 +02:00
|
|
|
if (el.size() < 2) return;
|
|
|
|
std::sort(el.begin(), el.end(), compare);
|
2008-05-27 14:24:23 +02:00
|
|
|
}
|
|
|
|
|
2010-08-01 21:22:34 +02:00
|
|
|
/**
|
|
|
|
* Sort selected range of items (on indices @ <begin, begin+num_items-1>)
|
2008-05-27 14:24:23 +02:00
|
|
|
* @param el list to be sorted
|
|
|
|
* @param compare function for evaluation of the quicksort
|
|
|
|
* @param begin start of sorting
|
|
|
|
* @param num_items count of items to be sorted
|
|
|
|
*/
|
2023-05-14 10:17:44 +02:00
|
|
|
void EngList_SortPartial(GUIEngineList &el, EngList_SortTypeFunction compare, size_t begin, size_t num_items)
|
2008-05-27 14:24:23 +02:00
|
|
|
{
|
2008-05-28 22:06:00 +02:00
|
|
|
if (num_items < 2) return;
|
2023-05-14 10:17:44 +02:00
|
|
|
assert(begin < el.size());
|
|
|
|
assert(begin + num_items <= el.size());
|
|
|
|
std::sort(el.begin() + begin, el.begin() + begin + num_items, compare);
|
2008-05-27 14:24:23 +02:00
|
|
|
}
|
|
|
|
|