Files
@ r28486:aff297ed5a05
Branch filter:
Location: cpp/openttd-patchpack/source/src/engine_gui.cpp - annotation
r28486:aff297ed5a05
11.6 KiB
text/x-c
Codechange: Allow constexpr NWidgetPart construction.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r9111:983de9c5a848 r6125:eb40461cb765 r5584:545d748cc681 r8107:82461791b7a2 r9070:e059c65164f3 r8116:df67d3c5e4fd r8114:866ed489ed98 r9380:6b24883f64de r9567:b3592d86e408 r12037:7b4fedf64d47 r12037:7b4fedf64d47 r10000:91824eb4383b r23698:1872cc5b7dd7 r13372:236fb191f6c2 r21788:4129b833084f r21788:4129b833084f r21788:4129b833084f r21788:4129b833084f r26103:316b73a1be08 r26630:4bf0be997769 r5584:545d748cc681 r18670:f122c356353c r18670:f122c356353c r8264:d493cb51fe8a r5584:545d748cc681 r21383:942c32fb8b0e r21383:942c32fb8b0e r15610:623a23fb6560 r15610:623a23fb6560 r12827:19af93950884 r12827:19af93950884 r12827:19af93950884 r9199:7d9724de3af0 r5584:545d748cc681 r13208:40382e8abf19 r13208:40382e8abf19 r6209:f315c4c30b43 r23698:1872cc5b7dd7 r23698:1872cc5b7dd7 r11725:57bc99fdc1bc r11725:57bc99fdc1bc r6259:e2dba394134b r13208:40382e8abf19 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r11512:4e2f95d920fb r11512:4e2f95d920fb r13742:180ad925befc r13742:180ad925befc r11512:4e2f95d920fb r13745:49505a0400d8 r28043:6d63424774d6 r28043:6d63424774d6 r28043:6d63424774d6 r28043:6d63424774d6 r28043:6d63424774d6 r28043:6d63424774d6 r11512:4e2f95d920fb r11512:4e2f95d920fb r11512:4e2f95d920fb r11512:4e2f95d920fb r9302:115cfeb49cd5 r21789:7b1fbdc6dee7 r13490:0caa306cf3f9 r20280:ca1fc41725ff r9302:115cfeb49cd5 r20280:ca1fc41725ff r19854:d39ea9da77bb r19854:d39ea9da77bb r19854:d39ea9da77bb r9302:115cfeb49cd5 r5584:545d748cc681 r28353:bfc4ab63f376 r13490:0caa306cf3f9 r18673:e5a4490b411b r5584:545d748cc681 r21788:4129b833084f r9302:115cfeb49cd5 r21788:4129b833084f r21788:4129b833084f r21788:4129b833084f r21788:4129b833084f r21788:4129b833084f r21788:4129b833084f r21788:4129b833084f r21788:4129b833084f r21788:4129b833084f r21788:4129b833084f r21788:4129b833084f r21788:4129b833084f r26630:4bf0be997769 r21788:4129b833084f r24597:afde5721a3b6 r5584:545d748cc681 r28167:b14ea36d49e5 r13490:0caa306cf3f9 r13490:0caa306cf3f9 r13490:0caa306cf3f9 r13490:0caa306cf3f9 r28353:bfc4ab63f376 r13490:0caa306cf3f9 r18673:e5a4490b411b r13490:0caa306cf3f9 r13490:0caa306cf3f9 r13490:0caa306cf3f9 r26575:d5725bf82346 r5584:545d748cc681 r26839:2bed12525c08 r26547:eb935ee4e933 r28167:b14ea36d49e5 r5584:545d748cc681 r26547:eb935ee4e933 r13490:0caa306cf3f9 r21788:4129b833084f r26547:eb935ee4e933 r5584:545d748cc681 r5584:545d748cc681 r28353:bfc4ab63f376 r9302:115cfeb49cd5 r9302:115cfeb49cd5 r18673:e5a4490b411b r26111:5721922c714f r22672:3473f7daf422 r18673:e5a4490b411b r25564:c875d92c537a r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r19856:877797b48845 r27942:f7389062d120 r19856:877797b48845 r19856:877797b48845 r19856:877797b48845 r19856:877797b48845 r25564:c875d92c537a r19856:877797b48845 r9302:115cfeb49cd5 r5584:545d748cc681 r28078:5e5d6c0447b1 r27724:fe6470f73b2e r5893:6c4fd9987e0f r13739:747ed1f003e3 r27861:6269475166e0 r11368:058349c3a02c r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r9302:115cfeb49cd5 r5584:545d748cc681 r5584:545d748cc681 r17630:7d818445376d r17630:7d818445376d r17630:7d818445376d r17630:7d818445376d r17630:7d818445376d r13211:4ba95564ba64 r9567:b3592d86e408 r13211:4ba95564ba64 r21705:f9ca7c863088 r9567:b3592d86e408 r9567:b3592d86e408 r12828:1411e13c41d0 r5584:545d748cc681 r10927:eb69eaf0227d r27050:d85c65824c1e r10967:2c98940d6c64 r10967:2c98940d6c64 r13372:236fb191f6c2 r5584:545d748cc681 r10927:eb69eaf0227d r5584:545d748cc681 r13211:4ba95564ba64 r9567:b3592d86e408 r11188:143f3c64befd r9720:6d491d07d0a8 r5584:545d748cc681 r28422:76582babb47f r5584:545d748cc681 r14396:0e22f6ee524f r5584:545d748cc681 r5584:545d748cc681 r12828:1411e13c41d0 r5584:545d748cc681 r11350:df593340eca2 r27737:728d55b97775 r13407:428d181f586b r27737:728d55b97775 r11350:df593340eca2 r19170:2bf34ee1afd6 r19170:2bf34ee1afd6 r27050:d85c65824c1e r22591:6e3880e55298 r19170:2bf34ee1afd6 r19170:2bf34ee1afd6 r19170:2bf34ee1afd6 r14191:bc6b1902e177 r13407:428d181f586b r19170:2bf34ee1afd6 r19170:2bf34ee1afd6 r19170:2bf34ee1afd6 r22591:6e3880e55298 r11350:df593340eca2 r19170:2bf34ee1afd6 r22591:6e3880e55298 r11350:df593340eca2 r5584:545d748cc681 r5584:545d748cc681 r12828:1411e13c41d0 r5584:545d748cc681 r14749:107a1d25efe3 r14749:107a1d25efe3 r27050:d85c65824c1e r14749:107a1d25efe3 r14749:107a1d25efe3 r14749:107a1d25efe3 r14749:107a1d25efe3 r14749:107a1d25efe3 r28422:76582babb47f r14749:107a1d25efe3 r14749:107a1d25efe3 r22589:85fa73a4e73f r11188:143f3c64befd r14749:107a1d25efe3 r27050:d85c65824c1e r14749:107a1d25efe3 r14749:107a1d25efe3 r14749:107a1d25efe3 r14749:107a1d25efe3 r14749:107a1d25efe3 r14749:107a1d25efe3 r14749:107a1d25efe3 r14749:107a1d25efe3 r14749:107a1d25efe3 r14749:107a1d25efe3 r14749:107a1d25efe3 r28422:76582babb47f r14749:107a1d25efe3 r14749:107a1d25efe3 r11188:143f3c64befd r5584:545d748cc681 r5584:545d748cc681 r12828:1411e13c41d0 r5584:545d748cc681 r10927:eb69eaf0227d r27050:d85c65824c1e r11188:143f3c64befd r11403:ba31da6812eb r10927:eb69eaf0227d r22589:85fa73a4e73f r12828:1411e13c41d0 r12828:1411e13c41d0 r12828:1411e13c41d0 r12828:1411e13c41d0 r12828:1411e13c41d0 r12828:1411e13c41d0 r12828:1411e13c41d0 r12828:1411e13c41d0 r12828:1411e13c41d0 r12828:1411e13c41d0 r12828:1411e13c41d0 r12828:1411e13c41d0 r12828:1411e13c41d0 r12828:1411e13c41d0 r12828:1411e13c41d0 r12828:1411e13c41d0 r12828:1411e13c41d0 r12828:1411e13c41d0 r12828:1411e13c41d0 r12828:1411e13c41d0 r12828:1411e13c41d0 r12828:1411e13c41d0 r12828:1411e13c41d0 r12828:1411e13c41d0 r12828:1411e13c41d0 r12828:1411e13c41d0 r12828:1411e13c41d0 r12828:1411e13c41d0 r5584:545d748cc681 r5584:545d748cc681 r12825:b76c82800d1a r12825:b76c82800d1a r13587:9ee7798ce808 r13587:9ee7798ce808 r13587:9ee7798ce808 r12825:b76c82800d1a r12825:b76c82800d1a r13060:e57594b0ca84 r12825:b76c82800d1a r18234:0d83ef81cba4 r12825:b76c82800d1a r12825:b76c82800d1a r12825:b76c82800d1a r12825:b76c82800d1a r12825:b76c82800d1a r18234:0d83ef81cba4 r12825:b76c82800d1a r12825:b76c82800d1a r12825:b76c82800d1a r18234:0d83ef81cba4 r12825:b76c82800d1a r12825:b76c82800d1a r12825:b76c82800d1a r18234:0d83ef81cba4 r12825:b76c82800d1a r12825:b76c82800d1a r12825:b76c82800d1a r18234:0d83ef81cba4 r12825:b76c82800d1a r12825:b76c82800d1a r12825:b76c82800d1a r12825:b76c82800d1a r12825:b76c82800d1a r12825:b76c82800d1a r15610:623a23fb6560 r15610:623a23fb6560 r9380:6b24883f64de r9380:6b24883f64de r9380:6b24883f64de r27345:e0cbea665b9c r9380:6b24883f64de r27345:e0cbea665b9c r27345:e0cbea665b9c r9380:6b24883f64de r9380:6b24883f64de r15610:623a23fb6560 r15610:623a23fb6560 r9380:6b24883f64de r9380:6b24883f64de r9380:6b24883f64de r9380:6b24883f64de r9380:6b24883f64de r27345:e0cbea665b9c r9380:6b24883f64de r9404:f74e13f5c66e r27345:e0cbea665b9c r27345:e0cbea665b9c r27345:e0cbea665b9c r9380:6b24883f64de r9380:6b24883f64de | /*
* 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 engine_gui.cpp GUI to show engine related information. */
#include "stdafx.h"
#include "window_gui.h"
#include "engine_base.h"
#include "command_func.h"
#include "strings_func.h"
#include "engine_gui.h"
#include "articulated_vehicles.h"
#include "vehicle_func.h"
#include "company_func.h"
#include "rail.h"
#include "road.h"
#include "settings_type.h"
#include "train.h"
#include "roadveh.h"
#include "ship.h"
#include "aircraft.h"
#include "engine_cmd.h"
#include "zoom_func.h"
#include "widgets/engine_widget.h"
#include "table/strings.h"
#include "safeguards.h"
/**
* Return the category of an engine.
* @param engine Engine to examine.
* @return String describing the category ("road veh", "train". "airplane", or "ship") of the engine.
*/
StringID GetEngineCategoryName(EngineID engine)
{
const Engine *e = Engine::Get(engine);
switch (e->type) {
default: NOT_REACHED();
case VEH_ROAD:
return GetRoadTypeInfo(e->u.road.roadtype)->strings.new_engine;
case VEH_AIRCRAFT: return STR_ENGINE_PREVIEW_AIRCRAFT;
case VEH_SHIP: return STR_ENGINE_PREVIEW_SHIP;
case VEH_TRAIN:
return GetRailTypeInfo(e->u.rail.railtype)->strings.new_loco;
}
}
static const NWidgetPart _nested_engine_preview_widgets[] = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE),
NWidget(WWT_CAPTION, COLOUR_LIGHT_BLUE), SetDataTip(STR_ENGINE_PREVIEW_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE),
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(),
EndContainer(),
EndContainer(),
};
struct EnginePreviewWindow : Window {
int vehicle_space; // The space to show the vehicle image
EnginePreviewWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
{
this->InitNested(window_number);
/* There is no way to recover the window; so disallow closure via DEL; unless SHIFT+DEL */
this->flags |= WF_STICKY;
}
void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
{
if (widget != WID_EP_QUESTION) return;
/* Get size of engine sprite, on loan from depot_gui.cpp */
EngineID engine = this->window_number;
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;
}
this->vehicle_space = std::max<int>(ScaleSpriteTrad(40), y - y_offs);
size->width = std::max(size->width, x - x_offs);
SetDParam(0, GetEngineCategoryName(engine));
size->height = GetStringHeight(STR_ENGINE_PREVIEW_MESSAGE, size->width) + WidgetDimensions::scaled.vsep_wide + GetCharacterHeight(FS_NORMAL) + this->vehicle_space;
SetDParam(0, engine);
size->height += GetStringHeight(GetEngineInfoString(engine), size->width);
}
void DrawWidget(const Rect &r, WidgetID widget) const override
{
if (widget != WID_EP_QUESTION) return;
EngineID engine = this->window_number;
SetDParam(0, GetEngineCategoryName(engine));
int y = DrawStringMultiLine(r, STR_ENGINE_PREVIEW_MESSAGE, TC_FROMSTRING, SA_HOR_CENTER | SA_TOP) + WidgetDimensions::scaled.vsep_wide;
SetDParam(0, PackEngineNameDParam(engine, EngineNameContext::PreviewNews));
DrawString(r.left, r.right, y, STR_ENGINE_NAME, TC_BLACK, SA_HOR_CENTER);
y += GetCharacterHeight(FS_NORMAL);
DrawVehicleEngine(r.left, r.right, this->width >> 1, y + this->vehicle_space / 2, engine, GetEnginePalette(engine, _local_company), EIT_PREVIEW);
y += this->vehicle_space;
DrawStringMultiLine(r.left, r.right, y, r.bottom, GetEngineInfoString(engine), TC_FROMSTRING, SA_CENTER);
}
void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
{
switch (widget) {
case WID_EP_YES:
Command<CMD_WANT_ENGINE_PREVIEW>::Post(this->window_number);
FALLTHROUGH;
case WID_EP_NO:
if (!_shift_pressed) this->Close();
break;
}
}
void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
{
if (!gui_scope) return;
EngineID engine = this->window_number;
if (Engine::Get(engine)->preview_company != _local_company) this->Close();
}
};
static WindowDesc _engine_preview_desc(__FILE__, __LINE__,
WDP_CENTER, nullptr, 0, 0,
WC_ENGINE_PREVIEW, WC_NONE,
WDF_CONSTRUCTION,
std::begin(_nested_engine_preview_widgets), std::end(_nested_engine_preview_widgets)
);
void ShowEnginePreviewWindow(EngineID engine)
{
AllocateWindowDescFront<EnginePreviewWindow>(&_engine_preview_desc, engine);
}
/**
* Get the capacity of an engine with articulated parts.
* @param engine The engine to get the capacity of.
* @return The capacity.
*/
uint GetTotalCapacityOfArticulatedParts(EngineID engine)
{
CargoArray cap = GetCapacityOfArticulatedParts(engine);
return cap.GetSum<uint>();
}
static StringID GetTrainEngineInfoString(const Engine *e)
{
SetDParam(0, e->GetCost());
SetDParam(2, PackVelocity(e->GetDisplayMaxSpeed(), e->type));
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, INVALID_CARGO);
}
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;
}
static StringID GetAircraftEngineInfoString(const Engine *e)
{
CargoID cargo = e->GetDefaultCargoType();
uint16_t mail_capacity;
uint capacity = e->GetDisplayDefaultCapacity(&mail_capacity);
uint16_t range = e->GetRange();
uint i = 0;
SetDParam(i++, e->GetCost());
SetDParam(i++, PackVelocity(e->GetDisplayMaxSpeed(), e->type));
SetDParam(i++, e->GetAircraftTypeText());
if (range > 0) SetDParam(i++, range);
SetDParam(i++, cargo);
SetDParam(i++, capacity);
if (mail_capacity > 0) {
SetDParam(i++, CT_MAIL);
SetDParam(i++, mail_capacity);
SetDParam(i++, e->GetRunningCost());
return range > 0 ? STR_ENGINE_PREVIEW_COST_MAX_SPEED_TYPE_RANGE_CAP_CAP_RUNCOST : STR_ENGINE_PREVIEW_COST_MAX_SPEED_TYPE_CAP_CAP_RUNCOST;
} else {
SetDParam(i++, e->GetRunningCost());
return range > 0 ? STR_ENGINE_PREVIEW_COST_MAX_SPEED_TYPE_RANGE_CAP_RUNCOST : STR_ENGINE_PREVIEW_COST_MAX_SPEED_TYPE_CAP_RUNCOST;
}
}
static StringID GetRoadVehEngineInfoString(const Engine *e)
{
if (_settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL) {
SetDParam(0, e->GetCost());
SetDParam(1, PackVelocity(e->GetDisplayMaxSpeed(), e->type));
uint capacity = GetTotalCapacityOfArticulatedParts(e->index);
if (capacity != 0) {
SetDParam(2, e->GetDefaultCargoType());
SetDParam(3, capacity);
} else {
SetDParam(2, INVALID_CARGO);
}
SetDParam(4, e->GetRunningCost());
return STR_ENGINE_PREVIEW_COST_MAX_SPEED_CAP_RUNCOST;
} else {
SetDParam(0, e->GetCost());
SetDParam(2, PackVelocity(e->GetDisplayMaxSpeed(), e->type));
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, INVALID_CARGO);
}
return STR_ENGINE_PREVIEW_COST_WEIGHT_SPEED_POWER_MAX_TE;
}
}
static StringID GetShipEngineInfoString(const Engine *e)
{
SetDParam(0, e->GetCost());
SetDParam(1, PackVelocity(e->GetDisplayMaxSpeed(), e->type));
SetDParam(2, e->GetDefaultCargoType());
SetDParam(3, e->GetDisplayDefaultCapacity());
SetDParam(4, e->GetRunningCost());
return STR_ENGINE_PREVIEW_COST_MAX_SPEED_CAP_RUNCOST;
}
/**
* 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();
}
}
/**
* Draw an engine.
* @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.
* @param y Vertical position to use for drawing the engine.
* @param engine Engine to draw.
* @param pal Palette to use for drawing.
*/
void DrawVehicleEngine(int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type)
{
const Engine *e = Engine::Get(engine);
switch (e->type) {
case VEH_TRAIN:
DrawTrainEngine(left, right, preferred_x, y, engine, pal, image_type);
break;
case VEH_ROAD:
DrawRoadVehEngine(left, right, preferred_x, y, engine, pal, image_type);
break;
case VEH_SHIP:
DrawShipEngine(left, right, preferred_x, y, engine, pal, image_type);
break;
case VEH_AIRCRAFT:
DrawAircraftEngine(left, right, preferred_x, y, engine, pal, image_type);
break;
default: NOT_REACHED();
}
}
/**
* Sort all items using quick sort and given 'CompareItems' function
* @param el list to be sorted
* @param compare function for evaluation of the quicksort
*/
void EngList_Sort(GUIEngineList &el, EngList_SortTypeFunction compare)
{
if (el.size() < 2) return;
std::sort(el.begin(), el.end(), compare);
}
/**
* Sort selected range of items (on indices @ <begin, begin+num_items-1>)
* @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
*/
void EngList_SortPartial(GUIEngineList &el, EngList_SortTypeFunction compare, size_t begin, size_t num_items)
{
if (num_items < 2) return;
assert(begin < el.size());
assert(begin + num_items <= el.size());
std::sort(el.begin() + begin, el.begin() + begin + num_items, compare);
}
|