2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +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/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file engine_gui.cpp GUI to show engine related information. */
|
2007-02-23 18:55:07 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2007-12-19 20:45:46 +00:00
|
|
|
#include "window_gui.h"
|
2008-04-29 21:31:29 +00:00
|
|
|
#include "engine_base.h"
|
2007-12-21 21:50:46 +00:00
|
|
|
#include "command_func.h"
|
2007-12-21 19:49:27 +00:00
|
|
|
#include "strings_func.h"
|
2008-05-27 12:24:23 +00:00
|
|
|
#include "engine_gui.h"
|
2008-06-20 07:23:00 +00:00
|
|
|
#include "articulated_vehicles.h"
|
2009-05-27 17:18:53 +00:00
|
|
|
#include "vehicle_func.h"
|
|
|
|
#include "company_func.h"
|
2008-08-24 21:31:24 +00:00
|
|
|
#include "rail.h"
|
2009-10-27 19:56:00 +00:00
|
|
|
#include "settings_type.h"
|
2014-09-28 09:02:11 +00:00
|
|
|
#include "train.h"
|
|
|
|
#include "roadveh.h"
|
|
|
|
#include "ship.h"
|
|
|
|
#include "aircraft.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2011-12-15 22:22:55 +00:00
|
|
|
#include "widgets/engine_widget.h"
|
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/strings.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2014-04-23 20:13:33 +00:00
|
|
|
#include "safeguards.h"
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Return the category of an engine.
|
2009-08-30 17:54:11 +00:00
|
|
|
* @param engine Engine to examine.
|
|
|
|
* @return String describing the category ("road veh", "train". "airplane", or "ship") of the engine.
|
|
|
|
*/
|
2008-05-13 10:17:04 +00:00
|
|
|
StringID GetEngineCategoryName(EngineID engine)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2009-10-06 19:17:07 +00:00
|
|
|
const Engine *e = Engine::Get(engine);
|
|
|
|
switch (e->type) {
|
2007-03-03 22:03:15 +00:00
|
|
|
default: NOT_REACHED();
|
2009-04-21 23:40:56 +00:00
|
|
|
case VEH_ROAD: return STR_ENGINE_PREVIEW_ROAD_VEHICLE;
|
|
|
|
case VEH_AIRCRAFT: return STR_ENGINE_PREVIEW_AIRCRAFT;
|
|
|
|
case VEH_SHIP: return STR_ENGINE_PREVIEW_SHIP;
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_TRAIN:
|
2009-10-06 19:17:07 +00:00
|
|
|
return GetRailTypeInfo(e->u.rail.railtype)->strings.new_loco;
|
2004-11-19 19:13:32 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2009-03-28 13:35:07 +00:00
|
|
|
static const NWidgetPart _nested_engine_preview_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-24 18:05:55 +00: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 13:35:07 +00:00
|
|
|
EndContainer(),
|
2009-11-24 21:13:36 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_EP_QUESTION), SetMinimalSize(300, 0), SetPadding(8, 8, 8, 8), SetFill(1, 0),
|
2009-11-08 19:22:45 +00:00
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(85, 10, 85),
|
2011-12-16 16:27:45 +00:00
|
|
|
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),
|
2009-03-28 13:35:07 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(0, 8),
|
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2008-05-18 20:49:22 +00:00
|
|
|
struct EnginePreviewWindow : Window {
|
2014-09-28 09:21:51 +00:00
|
|
|
int vehicle_space; // The space to show the vehicle image
|
2009-11-08 19:22:45 +00:00
|
|
|
|
2013-05-26 19:23:42 +00:00
|
|
|
EnginePreviewWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
|
2008-05-18 20:49:22 +00:00
|
|
|
{
|
2013-05-26 19:23:42 +00:00
|
|
|
this->InitNested(window_number);
|
2012-12-09 16:54:23 +00:00
|
|
|
|
|
|
|
/* There is no way to recover the window; so disallow closure via DEL; unless SHIFT+DEL */
|
|
|
|
this->flags |= WF_STICKY;
|
2008-05-18 20:49:22 +00:00
|
|
|
}
|
2005-10-01 12:43:34 +00:00
|
|
|
|
2009-11-22 18:28:14 +00:00
|
|
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
2009-11-08 19:22:45 +00:00
|
|
|
{
|
2011-12-16 16:27:45 +00:00
|
|
|
if (widget != WID_EP_QUESTION) return;
|
2009-11-08 19:22:45 +00:00
|
|
|
|
2014-09-28 09:02:11 +00:00
|
|
|
/* Get size of engine sprite, on loan from depot_gui.cpp */
|
2009-11-08 19:22:45 +00:00
|
|
|
EngineID engine = this->window_number;
|
2014-09-28 09:02:11 +00: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;
|
|
|
|
}
|
2014-09-28 09:21:51 +00:00
|
|
|
this->vehicle_space = max<int>(40, y - y_offs);
|
2014-09-28 09:02:11 +00:00
|
|
|
|
|
|
|
size->width = max(size->width, x - x_offs);
|
2009-11-08 19:22:45 +00:00
|
|
|
SetDParam(0, GetEngineCategoryName(engine));
|
2014-09-28 09:02:11 +00:00
|
|
|
size->height = GetStringHeight(STR_ENGINE_PREVIEW_MESSAGE, size->width) + WD_PAR_VSEP_WIDE + FONT_HEIGHT_NORMAL + this->vehicle_space;
|
2009-11-08 19:22:45 +00:00
|
|
|
SetDParam(0, engine);
|
|
|
|
size->height += GetStringHeight(GetEngineInfoString(engine), size->width);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void DrawWidget(const Rect &r, int widget) const
|
|
|
|
{
|
2011-12-16 16:27:45 +00:00
|
|
|
if (widget != WID_EP_QUESTION) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-18 20:49:22 +00:00
|
|
|
EngineID engine = this->window_number;
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, GetEngineCategoryName(engine));
|
2019-01-29 02:54:32 +00:00
|
|
|
int y = r.top + GetStringHeight(STR_ENGINE_PREVIEW_MESSAGE, r.right - r.left + 1);
|
2009-11-08 19:22:45 +00:00
|
|
|
y = DrawStringMultiLine(r.left, r.right, r.top, y, STR_ENGINE_PREVIEW_MESSAGE, TC_FROMSTRING, SA_CENTER) + WD_PAR_VSEP_WIDE;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-06-25 14:46:32 +00:00
|
|
|
SetDParam(0, engine);
|
2010-07-02 13:53:05 +00:00
|
|
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_ENGINE_NAME, TC_BLACK, SA_HOR_CENTER);
|
2009-11-08 19:22:45 +00:00
|
|
|
y += FONT_HEIGHT_NORMAL;
|
|
|
|
|
2014-09-28 09:02:11 +00:00
|
|
|
DrawVehicleEngine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, this->width >> 1, y + this->vehicle_space / 2, engine, GetEnginePalette(engine, _local_company), EIT_PREVIEW);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2014-09-28 09:02:11 +00:00
|
|
|
y += this->vehicle_space;
|
2009-11-08 19:22:45 +00:00
|
|
|
DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, r.bottom, GetEngineInfoString(engine), TC_FROMSTRING, SA_CENTER);
|
2005-10-01 12:43:34 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-01-30 18:34:48 +00:00
|
|
|
virtual void OnClick(Point pt, int widget, int click_count)
|
2008-05-18 20:49:22 +00:00
|
|
|
{
|
|
|
|
switch (widget) {
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_EP_YES:
|
2008-12-28 14:37:19 +00:00
|
|
|
DoCommandP(0, this->window_number, 0, CMD_WANT_ENGINE_PREVIEW);
|
2017-08-13 18:38:42 +00:00
|
|
|
FALLTHROUGH;
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_EP_NO:
|
2017-07-11 19:37:10 +00:00
|
|
|
if (!_shift_pressed) delete this;
|
2005-11-14 19:48:04 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
2012-12-09 16:55:21 +00:00
|
|
|
|
|
|
|
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
|
|
|
|
{
|
|
|
|
if (!gui_scope) return;
|
|
|
|
|
|
|
|
EngineID engine = this->window_number;
|
|
|
|
if (Engine::Get(engine)->preview_company != _local_company) delete this;
|
|
|
|
}
|
2008-05-18 20:49:22 +00:00
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2013-05-26 19:23:42 +00:00
|
|
|
static WindowDesc _engine_preview_desc(
|
2013-05-26 19:25:01 +00:00
|
|
|
WDP_CENTER, "engine_preview", 0, 0,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_ENGINE_PREVIEW, WC_NONE,
|
2009-11-24 17:28:29 +00:00
|
|
|
WDF_CONSTRUCTION,
|
2009-11-15 10:26:01 +00:00
|
|
|
_nested_engine_preview_widgets, lengthof(_nested_engine_preview_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
|
2005-10-01 12:43:34 +00:00
|
|
|
void ShowEnginePreviewWindow(EngineID engine)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-05-18 20:49:22 +00:00
|
|
|
AllocateWindowDescFront<EnginePreviewWindow>(&_engine_preview_desc, engine);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2011-05-02 17:42:12 +00: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 19:52:38 +00:00
|
|
|
uint GetTotalCapacityOfArticulatedParts(EngineID engine)
|
2008-06-20 07:23:00 +00:00
|
|
|
{
|
2009-10-06 19:52:38 +00:00
|
|
|
CargoArray cap = GetCapacityOfArticulatedParts(engine);
|
2014-09-18 19:50:41 +00:00
|
|
|
return cap.GetSum<uint>();
|
2008-06-20 07:23:00 +00:00
|
|
|
}
|
|
|
|
|
2009-08-30 18:41:03 +00:00
|
|
|
static StringID GetTrainEngineInfoString(const Engine *e)
|
2005-07-01 14:05:44 +00:00
|
|
|
{
|
2009-01-25 00:57:03 +00:00
|
|
|
SetDParam(0, e->GetCost());
|
2009-02-01 16:10:06 +00:00
|
|
|
SetDParam(2, e->GetDisplayMaxSpeed());
|
|
|
|
SetDParam(3, e->GetPower());
|
|
|
|
SetDParam(1, e->GetDisplayWeight());
|
2009-10-27 19:56:00 +00:00
|
|
|
SetDParam(7, e->GetDisplayMaxTractiveEffort());
|
2005-07-01 14:05:44 +00:00
|
|
|
|
2009-01-25 00:57:03 +00:00
|
|
|
SetDParam(4, e->GetRunningCost());
|
2005-07-01 14:05:44 +00:00
|
|
|
|
2009-10-06 19:52:38 +00:00
|
|
|
uint capacity = GetTotalCapacityOfArticulatedParts(e->index);
|
2008-06-20 07:23:00 +00:00
|
|
|
if (capacity != 0) {
|
2009-02-21 12:52:41 +00:00
|
|
|
SetDParam(5, e->GetDefaultCargoType());
|
2008-07-26 22:00:59 +00:00
|
|
|
SetDParam(6, capacity);
|
2005-10-23 13:04:44 +00:00
|
|
|
} else {
|
2006-10-20 19:48:25 +00:00
|
|
|
SetDParam(5, CT_INVALID);
|
2005-07-01 14:05:44 +00:00
|
|
|
}
|
2010-01-30 16:27:35 +00:00
|
|
|
return (_settings_game.vehicle.train_acceleration_model != AM_ORIGINAL && GetRailTypeInfo(e->u.rail.railtype)->acceleration_type != 2) ? STR_ENGINE_PREVIEW_COST_WEIGHT_SPEED_POWER_MAX_TE : STR_ENGINE_PREVIEW_COST_WEIGHT_SPEED_POWER;
|
2005-07-01 14:05:44 +00:00
|
|
|
}
|
|
|
|
|
2009-08-30 18:41:03 +00:00
|
|
|
static StringID GetAircraftEngineInfoString(const Engine *e)
|
2005-07-01 14:05:44 +00:00
|
|
|
{
|
2009-03-13 23:49:12 +00:00
|
|
|
CargoID cargo = e->GetDefaultCargoType();
|
2009-10-31 17:48:09 +00:00
|
|
|
uint16 mail_capacity;
|
|
|
|
uint capacity = e->GetDisplayDefaultCapacity(&mail_capacity);
|
2011-12-13 00:43:35 +00:00
|
|
|
uint16 range = e->GetRange();
|
2009-01-25 00:57:03 +00:00
|
|
|
|
2012-03-24 15:21:07 +00:00
|
|
|
uint i = 0;
|
|
|
|
SetDParam(i++, e->GetCost());
|
|
|
|
SetDParam(i++, e->GetDisplayMaxSpeed());
|
2017-03-18 20:48:54 +00:00
|
|
|
SetDParam(i++, e->GetAircraftTypeText());
|
2012-03-24 15:21:07 +00:00
|
|
|
if (range > 0) SetDParam(i++, range);
|
|
|
|
SetDParam(i++, cargo);
|
|
|
|
SetDParam(i++, capacity);
|
2010-01-07 16:39:04 +00:00
|
|
|
|
2009-10-31 17:48:09 +00:00
|
|
|
if (mail_capacity > 0) {
|
2012-03-24 15:21:07 +00:00
|
|
|
SetDParam(i++, CT_MAIL);
|
|
|
|
SetDParam(i++, mail_capacity);
|
|
|
|
SetDParam(i++, e->GetRunningCost());
|
2017-03-18 20:48:54 +00:00
|
|
|
return range > 0 ? STR_ENGINE_PREVIEW_COST_MAX_SPEED_TYPE_RANGE_CAP_CAP_RUNCOST : STR_ENGINE_PREVIEW_COST_MAX_SPEED_TYPE_CAP_CAP_RUNCOST;
|
2009-03-13 23:49:12 +00:00
|
|
|
} else {
|
2012-03-24 15:21:07 +00:00
|
|
|
SetDParam(i++, e->GetRunningCost());
|
2017-03-18 20:48:54 +00:00
|
|
|
return range > 0 ? STR_ENGINE_PREVIEW_COST_MAX_SPEED_TYPE_RANGE_CAP_RUNCOST : STR_ENGINE_PREVIEW_COST_MAX_SPEED_TYPE_CAP_RUNCOST;
|
2009-03-13 23:49:12 +00:00
|
|
|
}
|
2005-07-01 14:05:44 +00:00
|
|
|
}
|
|
|
|
|
2009-08-30 18:41:03 +00:00
|
|
|
static StringID GetRoadVehEngineInfoString(const Engine *e)
|
2005-07-01 14:05:44 +00:00
|
|
|
{
|
2010-03-06 12:59:28 +00:00
|
|
|
if (_settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL) {
|
|
|
|
SetDParam(0, e->GetCost());
|
|
|
|
SetDParam(1, e->GetDisplayMaxSpeed());
|
|
|
|
uint capacity = GetTotalCapacityOfArticulatedParts(e->index);
|
|
|
|
if (capacity != 0) {
|
|
|
|
SetDParam(2, e->GetDefaultCargoType());
|
|
|
|
SetDParam(3, capacity);
|
|
|
|
} else {
|
|
|
|
SetDParam(2, CT_INVALID);
|
|
|
|
}
|
|
|
|
SetDParam(4, e->GetRunningCost());
|
2017-03-18 20:47:48 +00:00
|
|
|
return STR_ENGINE_PREVIEW_COST_MAX_SPEED_CAP_RUNCOST;
|
2009-02-21 12:52:41 +00:00
|
|
|
} else {
|
2010-03-06 12:59:28 +00:00
|
|
|
SetDParam(0, e->GetCost());
|
|
|
|
SetDParam(2, e->GetDisplayMaxSpeed());
|
|
|
|
SetDParam(3, e->GetPower());
|
|
|
|
SetDParam(1, e->GetDisplayWeight());
|
|
|
|
SetDParam(7, e->GetDisplayMaxTractiveEffort());
|
|
|
|
|
|
|
|
SetDParam(4, e->GetRunningCost());
|
|
|
|
|
|
|
|
uint capacity = GetTotalCapacityOfArticulatedParts(e->index);
|
|
|
|
if (capacity != 0) {
|
|
|
|
SetDParam(5, e->GetDefaultCargoType());
|
|
|
|
SetDParam(6, capacity);
|
|
|
|
} else {
|
|
|
|
SetDParam(5, CT_INVALID);
|
|
|
|
}
|
|
|
|
return STR_ENGINE_PREVIEW_COST_WEIGHT_SPEED_POWER_MAX_TE;
|
2009-02-21 12:52:41 +00:00
|
|
|
}
|
2005-07-01 14:05:44 +00:00
|
|
|
}
|
|
|
|
|
2009-08-30 18:41:03 +00:00
|
|
|
static StringID GetShipEngineInfoString(const Engine *e)
|
2005-07-01 14:05:44 +00:00
|
|
|
{
|
2009-01-25 00:57:03 +00:00
|
|
|
SetDParam(0, e->GetCost());
|
2009-02-01 16:10:06 +00:00
|
|
|
SetDParam(1, e->GetDisplayMaxSpeed());
|
2009-02-21 12:52:41 +00:00
|
|
|
SetDParam(2, e->GetDefaultCargoType());
|
2009-03-18 19:32:13 +00:00
|
|
|
SetDParam(3, e->GetDisplayDefaultCapacity());
|
2009-01-25 00:57:03 +00:00
|
|
|
SetDParam(4, e->GetRunningCost());
|
2017-03-18 20:47:48 +00:00
|
|
|
return STR_ENGINE_PREVIEW_COST_MAX_SPEED_CAP_RUNCOST;
|
2009-08-30 18:41:03 +00: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 14:05:44 +00:00
|
|
|
}
|
|
|
|
|
2009-08-30 17:38:28 +00:00
|
|
|
/**
|
|
|
|
* Draw an engine.
|
2009-11-16 17:15:42 +00: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 17:38:28 +00:00
|
|
|
* @param y Vertical position to use for drawing the engine.
|
|
|
|
* @param engine Engine to draw.
|
2009-09-19 09:51:14 +00:00
|
|
|
* @param pal Palette to use for drawing.
|
2009-08-30 17:38:28 +00:00
|
|
|
*/
|
2011-11-01 16:51:47 +00:00
|
|
|
void DrawVehicleEngine(int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type)
|
2009-08-30 17:38:28 +00:00
|
|
|
{
|
|
|
|
const Engine *e = Engine::Get(engine);
|
|
|
|
|
|
|
|
switch (e->type) {
|
|
|
|
case VEH_TRAIN:
|
2011-11-01 16:51:47 +00:00
|
|
|
DrawTrainEngine(left, right, preferred_x, y, engine, pal, image_type);
|
2009-08-30 17:38:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VEH_ROAD:
|
2011-11-01 16:51:47 +00:00
|
|
|
DrawRoadVehEngine(left, right, preferred_x, y, engine, pal, image_type);
|
2009-08-30 17:38:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VEH_SHIP:
|
2011-11-01 16:51:47 +00:00
|
|
|
DrawShipEngine(left, right, preferred_x, y, engine, pal, image_type);
|
2009-08-30 17:38:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VEH_AIRCRAFT:
|
2011-11-01 16:51:47 +00:00
|
|
|
DrawAircraftEngine(left, right, preferred_x, y, engine, pal, image_type);
|
2009-08-30 17:38:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Sort all items using quick sort and given 'CompareItems' function
|
2008-05-27 12:24:23 +00:00
|
|
|
* @param el list to be sorted
|
|
|
|
* @param compare function for evaluation of the quicksort
|
|
|
|
*/
|
2008-05-28 17:29:27 +00:00
|
|
|
void EngList_Sort(GUIEngineList *el, EngList_SortTypeFunction compare)
|
2008-05-27 12:24:23 +00:00
|
|
|
{
|
2008-05-28 17:29:27 +00:00
|
|
|
uint size = el->Length();
|
2008-05-27 12:24:23 +00:00
|
|
|
/* out-of-bounds access at the next line for size == 0 (even with operator[] at some systems)
|
|
|
|
* generally, do not sort if there are less than 2 items */
|
|
|
|
if (size < 2) return;
|
2009-09-13 17:47:07 +00:00
|
|
|
QSortT(el->Begin(), size, compare);
|
2008-05-27 12:24:23 +00:00
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Sort selected range of items (on indices @ <begin, begin+num_items-1>)
|
2008-05-27 12:24:23 +00: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
|
|
|
|
*/
|
2008-05-28 17:29:27 +00:00
|
|
|
void EngList_SortPartial(GUIEngineList *el, EngList_SortTypeFunction compare, uint begin, uint num_items)
|
2008-05-27 12:24:23 +00:00
|
|
|
{
|
2008-05-28 20:06:00 +00:00
|
|
|
if (num_items < 2) return;
|
2008-05-28 17:29:27 +00:00
|
|
|
assert(begin < el->Length());
|
|
|
|
assert(begin + num_items <= el->Length());
|
2009-09-13 17:47:07 +00:00
|
|
|
QSortT(el->Get(begin), num_items, compare);
|
2008-05-27 12:24:23 +00:00
|
|
|
}
|
|
|
|
|