2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
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"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "gui.h"
|
2007-12-19 20:45:46 +00:00
|
|
|
#include "window_gui.h"
|
2008-01-09 09:45:45 +00:00
|
|
|
#include "gfx_func.h"
|
2008-03-31 00:17:39 +00:00
|
|
|
#include "engine_func.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"
|
|
|
|
#include "economy_func.h"
|
2008-03-28 08:53:36 +00:00
|
|
|
#include "news_func.h"
|
2005-07-21 22:15:02 +00:00
|
|
|
#include "variables.h"
|
2006-02-03 12:55:21 +00:00
|
|
|
#include "newgrf_engine.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"
|
2008-08-24 21:31:24 +00:00
|
|
|
#include "rail.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
#include "table/sprites.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-13 10:17:04 +00:00
|
|
|
StringID GetEngineCategoryName(EngineID engine)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-03-03 22:03:15 +00:00
|
|
|
switch (GetEngine(engine)->type) {
|
|
|
|
default: NOT_REACHED();
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_ROAD: return STR_8103_ROAD_VEHICLE;
|
|
|
|
case VEH_AIRCRAFT: return STR_8104_AIRCRAFT;
|
|
|
|
case VEH_SHIP: return STR_8105_SHIP;
|
|
|
|
case VEH_TRAIN:
|
2008-08-24 21:31:24 +00:00
|
|
|
return GetRailTypeInfo(RailVehInfo(engine)->railtype)->strings.new_loco;
|
2004-11-19 19:13:32 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const Widget _engine_preview_widgets[] = {
|
2008-07-30 16:13:58 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_LIGHT_BLUE, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, COLOUR_LIGHT_BLUE, 11, 299, 0, 13, STR_8100_MESSAGE_FROM_VEHICLE_MANUFACTURE, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, COLOUR_LIGHT_BLUE, 0, 299, 14, 191, 0x0, STR_NULL},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_LIGHT_BLUE, 85, 144, 172, 183, STR_00C9_NO, STR_NULL},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_LIGHT_BLUE, 155, 214, 172, 183, STR_00C8_YES, STR_NULL},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
typedef void DrawEngineProc(int x, int y, EngineID engine, SpriteID pal);
|
2005-10-01 12:43:34 +00:00
|
|
|
typedef void DrawEngineInfoProc(EngineID, int x, int y, int maxw);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
struct DrawEngineInfo {
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawEngineProc *engine_proc;
|
|
|
|
DrawEngineInfoProc *info_proc;
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-10-01 12:43:34 +00:00
|
|
|
static void DrawTrainEngineInfo(EngineID engine, int x, int y, int maxw);
|
|
|
|
static void DrawRoadVehEngineInfo(EngineID engine, int x, int y, int maxw);
|
|
|
|
static void DrawShipEngineInfo(EngineID engine, int x, int y, int maxw);
|
|
|
|
static void DrawAircraftEngineInfo(EngineID engine, int x, int y, int maxw);
|
2005-07-01 14:05:44 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
static const DrawEngineInfo _draw_engine_list[4] = {
|
2007-03-03 22:03:15 +00:00
|
|
|
{ DrawTrainEngine, DrawTrainEngineInfo },
|
|
|
|
{ DrawRoadVehEngine, DrawRoadVehEngineInfo },
|
|
|
|
{ DrawShipEngine, DrawShipEngineInfo },
|
|
|
|
{ DrawAircraftEngine, DrawAircraftEngineInfo },
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2008-05-18 20:49:22 +00:00
|
|
|
struct EnginePreviewWindow : Window {
|
|
|
|
EnginePreviewWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
|
|
|
|
{
|
2008-05-23 23:02:13 +00:00
|
|
|
this->FindWindowPlacementAndResize(desc);
|
2008-05-18 20:49:22 +00:00
|
|
|
}
|
2005-10-01 12:43:34 +00:00
|
|
|
|
2008-05-18 20:49:22 +00:00
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
|
|
|
this->DrawWidgets();
|
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));
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawStringMultiCenter(150, 44, STR_8101_WE_HAVE_JUST_DESIGNED_A, 296);
|
|
|
|
|
2007-06-25 14:46:32 +00:00
|
|
|
SetDParam(0, engine);
|
2008-05-18 20:49:22 +00:00
|
|
|
DrawStringCentered(this->width >> 1, 80, STR_ENGINE_NAME, TC_BLACK);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-18 20:49:22 +00:00
|
|
|
const DrawEngineInfo *dei = &_draw_engine_list[GetEngine(engine)->type];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-18 20:49:22 +00:00
|
|
|
int width = this->width;
|
2004-08-09 17:04:08 +00:00
|
|
|
dei->engine_proc(width >> 1, 100, engine, 0);
|
|
|
|
dei->info_proc(engine, width >> 1, 130, width - 52);
|
2005-10-01 12:43:34 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-18 20:49:22 +00:00
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
|
{
|
|
|
|
switch (widget) {
|
2005-11-14 19:48:04 +00:00
|
|
|
case 4:
|
2008-12-28 14:37:19 +00:00
|
|
|
DoCommandP(0, this->window_number, 0, CMD_WANT_ENGINE_PREVIEW);
|
2006-11-18 17:04:44 +00:00
|
|
|
/* Fallthrough */
|
|
|
|
case 3:
|
2008-05-18 20:49:22 +00:00
|
|
|
delete this;
|
2005-11-14 19:48:04 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
2008-05-18 20:49:22 +00:00
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
static const WindowDesc _engine_preview_desc = {
|
2007-07-27 12:49:04 +00:00
|
|
|
WDP_CENTER, WDP_CENTER, 300, 192, 300, 192,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_ENGINE_PREVIEW, WC_NONE,
|
2004-08-09 17:04:08 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
|
|
|
|
_engine_preview_widgets,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-06-20 07:23:00 +00:00
|
|
|
static uint GetTotalCapacityOfArticulatedParts(EngineID engine, VehicleType type)
|
|
|
|
{
|
|
|
|
uint total = 0;
|
|
|
|
|
|
|
|
uint16 *cap = GetCapacityOfArticulatedParts(engine, type);
|
|
|
|
for (uint c = 0; c < NUM_CARGO; c++) {
|
|
|
|
total += cap[c];
|
|
|
|
}
|
|
|
|
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
2005-10-01 12:43:34 +00:00
|
|
|
static void DrawTrainEngineInfo(EngineID engine, int x, int y, int maxw)
|
2005-07-01 14:05:44 +00:00
|
|
|
{
|
|
|
|
const RailVehicleInfo *rvi = RailVehInfo(engine);
|
2007-10-20 14:51:09 +00:00
|
|
|
int multihead = (rvi->railveh_type == RAILVEH_MULTIHEAD) ? 1 : 0;
|
2005-07-01 14:05:44 +00:00
|
|
|
|
2008-08-15 17:54:43 +00:00
|
|
|
SetDParam(0, (_price.build_railvehicle >> 3) * GetEngineProperty(engine, 0x17, rvi->cost_factor) >> 5);
|
2008-06-20 07:23:00 +00:00
|
|
|
SetDParam(2, GetEngineProperty(engine, 0x09, rvi->max_speed) * 10 / 16);
|
2008-07-26 22:00:59 +00:00
|
|
|
SetDParam(3, GetEngineProperty(engine, 0x0B, rvi->power));
|
2008-06-20 07:23:00 +00:00
|
|
|
SetDParam(1, GetEngineProperty(engine, 0x16, rvi->weight) << multihead);
|
2005-07-01 14:05:44 +00:00
|
|
|
|
2008-07-26 22:00:59 +00:00
|
|
|
SetDParam(4, GetEngineProperty(engine, 0x0D, rvi->running_cost) * GetPriceByIndex(rvi->running_cost_class) >> 8);
|
2005-07-01 14:05:44 +00:00
|
|
|
|
2008-06-20 07:23:00 +00:00
|
|
|
uint capacity = GetTotalCapacityOfArticulatedParts(engine, VEH_TRAIN);
|
|
|
|
if (capacity != 0) {
|
2006-10-20 11:53:29 +00:00
|
|
|
SetDParam(5, rvi->cargo_type);
|
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
|
|
|
}
|
2006-03-31 17:40:31 +00:00
|
|
|
DrawStringMultiCenter(x, y, STR_VEHICLE_INFO_COST_WEIGHT_SPEED_POWER, maxw);
|
2005-07-01 14:05:44 +00:00
|
|
|
}
|
|
|
|
|
2005-10-01 12:43:34 +00:00
|
|
|
static void DrawAircraftEngineInfo(EngineID engine, int x, int y, int maxw)
|
2005-07-01 14:05:44 +00:00
|
|
|
{
|
|
|
|
const AircraftVehicleInfo *avi = AircraftVehInfo(engine);
|
2008-08-15 17:54:43 +00:00
|
|
|
SetDParam(0, (_price.aircraft_base >> 3) * GetEngineProperty(engine, 0x0B, avi->cost_factor) >> 5);
|
2007-03-18 10:37:22 +00:00
|
|
|
SetDParam(1, avi->max_speed * 10 / 16);
|
2005-07-01 14:05:44 +00:00
|
|
|
SetDParam(2, avi->passenger_capacity);
|
|
|
|
SetDParam(3, avi->mail_capacity);
|
2008-06-20 07:23:00 +00:00
|
|
|
SetDParam(4, GetEngineProperty(engine, 0x0E, avi->running_cost) * _price.aircraft_running >> 8);
|
2005-07-01 14:05:44 +00:00
|
|
|
|
|
|
|
DrawStringMultiCenter(x, y, STR_A02E_COST_MAX_SPEED_CAPACITY, maxw);
|
|
|
|
}
|
|
|
|
|
2005-10-01 12:43:34 +00:00
|
|
|
static void DrawRoadVehEngineInfo(EngineID engine, int x, int y, int maxw)
|
2005-07-01 14:05:44 +00:00
|
|
|
{
|
|
|
|
const RoadVehicleInfo *rvi = RoadVehInfo(engine);
|
|
|
|
|
2008-08-15 17:54:43 +00:00
|
|
|
SetDParam(0, (_price.roadveh_base >> 3) * GetEngineProperty(engine, 0x11, rvi->cost_factor) >> 5);
|
2007-02-04 05:53:09 +00:00
|
|
|
SetDParam(1, rvi->max_speed * 10 / 32);
|
2008-02-21 19:09:10 +00:00
|
|
|
SetDParam(2, rvi->running_cost * GetPriceByIndex(rvi->running_cost_class) >> 8);
|
2006-10-20 11:53:29 +00:00
|
|
|
SetDParam(3, rvi->cargo_type);
|
2008-06-20 07:23:00 +00:00
|
|
|
SetDParam(4, GetTotalCapacityOfArticulatedParts(engine, VEH_ROAD));
|
2005-07-01 14:05:44 +00:00
|
|
|
|
|
|
|
DrawStringMultiCenter(x, y, STR_902A_COST_SPEED_RUNNING_COST, maxw);
|
|
|
|
}
|
|
|
|
|
2005-10-01 12:43:34 +00:00
|
|
|
static void DrawShipEngineInfo(EngineID engine, int x, int y, int maxw)
|
2005-07-01 14:05:44 +00:00
|
|
|
{
|
|
|
|
const ShipVehicleInfo *svi = ShipVehInfo(engine);
|
2008-08-15 17:54:43 +00:00
|
|
|
SetDParam(0, GetEngineProperty(engine, 0x0A, svi->cost_factor) * (_price.ship_base >> 3) >> 5);
|
2008-06-20 07:23:00 +00:00
|
|
|
SetDParam(1, GetEngineProperty(engine, 0x0B, svi->max_speed) * 10 / 32);
|
2006-10-20 11:53:29 +00:00
|
|
|
SetDParam(2, svi->cargo_type);
|
2008-06-20 07:23:00 +00:00
|
|
|
SetDParam(3, GetEngineProperty(engine, 0x0D, svi->capacity));
|
|
|
|
SetDParam(4, GetEngineProperty(engine, 0x0F, svi->running_cost) * _price.ship_running >> 8);
|
2005-07-01 14:05:44 +00:00
|
|
|
DrawStringMultiCenter(x, y, STR_982E_COST_MAX_SPEED_CAPACITY, maxw);
|
|
|
|
}
|
|
|
|
|
2008-03-28 08:53:36 +00:00
|
|
|
void DrawNewsNewVehicleAvail(Window *w, const NewsItem *ni)
|
2007-03-03 22:03:15 +00:00
|
|
|
{
|
2008-05-13 10:17:04 +00:00
|
|
|
EngineID engine = ni->data_a;
|
2007-03-03 22:03:15 +00:00
|
|
|
const DrawEngineInfo *dei = &_draw_engine_list[GetEngine(engine)->type];
|
|
|
|
|
|
|
|
SetDParam(0, GetEngineCategoryName(engine));
|
|
|
|
DrawStringMultiCenter(w->width >> 1, 20, STR_NEW_VEHICLE_NOW_AVAILABLE, w->width - 2);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
GfxFillRect(25, 56, w->width - 25, w->height - 2, 10);
|
|
|
|
|
2007-06-25 14:46:32 +00:00
|
|
|
SetDParam(0, engine);
|
2007-03-03 22:03:15 +00:00
|
|
|
DrawStringMultiCenter(w->width >> 1, 57, STR_NEW_VEHICLE_TYPE, w->width - 2);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-03 22:03:15 +00:00
|
|
|
dei->engine_proc(w->width >> 1, 88, engine, 0);
|
2008-06-28 15:44:24 +00:00
|
|
|
GfxFillRect(25, 56, w->width - 56, 112, PALETTE_TO_STRUCT_GREY, FILLRECT_RECOLOR);
|
2007-03-03 22:03:15 +00:00
|
|
|
dei->info_proc(engine, w->width >> 1, 129, w->width - 52);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2008-05-27 12:24:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
/** Sort all items using qsort() and given 'CompareItems' function
|
|
|
|
* @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;
|
2008-05-28 17:29:27 +00:00
|
|
|
qsort(el->Begin(), size, sizeof(*el->Begin()), compare); // MorphOS doesn't know vector::at(int) ...
|
2008-05-27 12:24:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** 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
|
|
|
|
*/
|
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());
|
|
|
|
qsort(el->Get(begin), num_items, sizeof(*el->Begin()), compare);
|
2008-05-27 12:24:23 +00:00
|
|
|
}
|
|
|
|
|