2006-10-10 15:02:38 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-02-23 11:50:43 +00:00
|
|
|
/** @file build_vehicle_gui.cpp */
|
|
|
|
|
2006-10-10 15:02:38 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "openttd.h"
|
2007-01-21 22:50:43 +00:00
|
|
|
#include "train.h"
|
2007-01-22 02:09:51 +00:00
|
|
|
#include "roadveh.h"
|
2007-01-22 00:26:46 +00:00
|
|
|
#include "ship.h"
|
2006-10-10 15:02:38 +00:00
|
|
|
#include "aircraft.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "functions.h"
|
|
|
|
#include "table/sprites.h"
|
|
|
|
#include "table/strings.h"
|
|
|
|
#include "window.h"
|
|
|
|
#include "gui.h"
|
|
|
|
#include "vehicle.h"
|
2007-06-01 11:41:02 +00:00
|
|
|
#include "articulated_vehicles.h"
|
2006-10-10 15:02:38 +00:00
|
|
|
#include "gfx.h"
|
|
|
|
#include "station.h"
|
|
|
|
#include "command.h"
|
|
|
|
#include "engine.h"
|
|
|
|
#include "player.h"
|
|
|
|
#include "depot.h"
|
|
|
|
#include "airport.h"
|
|
|
|
#include "vehicle_gui.h"
|
|
|
|
#include "newgrf_engine.h"
|
|
|
|
#include "date.h"
|
|
|
|
#include "strings.h"
|
2007-02-20 22:09:21 +00:00
|
|
|
#include "cargotype.h"
|
2007-05-19 09:40:18 +00:00
|
|
|
#include "group.h"
|
2007-05-25 08:13:01 +00:00
|
|
|
#include "road_map.h"
|
2006-10-10 15:02:38 +00:00
|
|
|
|
|
|
|
|
2006-12-07 13:00:41 +00:00
|
|
|
enum BuildVehicleWidgets {
|
2006-10-10 15:02:38 +00:00
|
|
|
BUILD_VEHICLE_WIDGET_CLOSEBOX = 0,
|
|
|
|
BUILD_VEHICLE_WIDGET_CAPTION,
|
|
|
|
BUILD_VEHICLE_WIDGET_SORT_ASSENDING_DESCENDING,
|
|
|
|
BUILD_VEHICLE_WIDGET_SORT_TEXT,
|
|
|
|
BUILD_VEHICLE_WIDGET_SORT_DROPDOWN,
|
|
|
|
BUILD_VEHICLE_WIDGET_LIST,
|
|
|
|
BUILD_VEHICLE_WIDGET_SCROLLBAR,
|
|
|
|
BUILD_VEHICLE_WIDGET_PANEL,
|
|
|
|
BUILD_VEHICLE_WIDGET_BUILD,
|
|
|
|
BUILD_VEHICLE_WIDGET_RENAME,
|
|
|
|
BUILD_VEHICLE_WIDGET_RESIZE,
|
2007-03-26 11:41:14 +00:00
|
|
|
BUILD_VEHICLE_WIDGET_END
|
2006-12-07 13:00:41 +00:00
|
|
|
};
|
2006-10-10 15:02:38 +00:00
|
|
|
|
|
|
|
static const Widget _build_vehicle_widgets[] = {
|
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW },
|
2007-03-26 12:28:44 +00:00
|
|
|
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 239, 0, 13, 0x0, STR_018C_WINDOW_TITLE_DRAG_THIS },
|
2006-10-10 15:02:38 +00:00
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 80, 14, 25, STR_SORT_BY, STR_SORT_ORDER_TIP},
|
2007-03-26 12:28:44 +00:00
|
|
|
{ WWT_PANEL, RESIZE_RIGHT, 14, 81, 227, 14, 25, 0x0, STR_SORT_CRITERIA_TIP},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_LR, 14, 228, 239, 14, 25, STR_0225, STR_SORT_CRITERIA_TIP},
|
|
|
|
{ WWT_MATRIX, RESIZE_RB, 14, 0, 227, 26, 121, 0x0, STR_NULL },
|
|
|
|
{ WWT_SCROLLBAR, RESIZE_LRB, 14, 228, 239, 26, 121, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST },
|
|
|
|
{ WWT_PANEL, RESIZE_RTB, 14, 0, 239, 122, 243, 0x0, STR_NULL },
|
2007-01-21 22:50:43 +00:00
|
|
|
|
2007-03-26 08:55:45 +00:00
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 114, 244, 255, 0x0, STR_NULL },
|
2007-03-26 12:28:44 +00:00
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_RTB, 14, 115, 227, 244, 255, 0x0, STR_NULL },
|
|
|
|
{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 228, 239, 244, 255, 0x0, STR_RESIZE_BUTTON },
|
2006-10-10 15:02:38 +00:00
|
|
|
{ WIDGETS_END},
|
|
|
|
};
|
|
|
|
|
2007-01-21 22:50:43 +00:00
|
|
|
/* Setup widget strings to fit the different types of vehicles */
|
2007-01-22 14:08:14 +00:00
|
|
|
static void SetupWindowStrings(Window *w, byte type)
|
2007-01-21 22:50:43 +00:00
|
|
|
{
|
|
|
|
switch (type) {
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_TRAIN:
|
2007-01-21 22:50:43 +00:00
|
|
|
w->widget[BUILD_VEHICLE_WIDGET_CAPTION].data = STR_JUST_STRING;
|
|
|
|
w->widget[BUILD_VEHICLE_WIDGET_LIST].tooltips = STR_8843_TRAIN_VEHICLE_SELECTION;
|
|
|
|
w->widget[BUILD_VEHICLE_WIDGET_BUILD].data = STR_881F_BUILD_VEHICLE;
|
|
|
|
w->widget[BUILD_VEHICLE_WIDGET_BUILD].tooltips = STR_8844_BUILD_THE_HIGHLIGHTED_TRAIN;
|
|
|
|
w->widget[BUILD_VEHICLE_WIDGET_RENAME].data = STR_8820_RENAME;
|
|
|
|
w->widget[BUILD_VEHICLE_WIDGET_RENAME].tooltips = STR_8845_RENAME_TRAIN_VEHICLE_TYPE;
|
|
|
|
break;
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_ROAD:
|
2007-01-22 02:09:51 +00:00
|
|
|
w->widget[BUILD_VEHICLE_WIDGET_CAPTION].data = STR_9006_NEW_ROAD_VEHICLES;
|
|
|
|
w->widget[BUILD_VEHICLE_WIDGET_LIST].tooltips = STR_9026_ROAD_VEHICLE_SELECTION;
|
|
|
|
w->widget[BUILD_VEHICLE_WIDGET_BUILD].data = STR_9007_BUILD_VEHICLE;
|
|
|
|
w->widget[BUILD_VEHICLE_WIDGET_BUILD].tooltips = STR_9027_BUILD_THE_HIGHLIGHTED_ROAD;
|
|
|
|
w->widget[BUILD_VEHICLE_WIDGET_RENAME].data = STR_9034_RENAME;
|
|
|
|
w->widget[BUILD_VEHICLE_WIDGET_RENAME].tooltips = STR_9035_RENAME_ROAD_VEHICLE_TYPE;
|
|
|
|
break;
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_SHIP:
|
2007-01-22 00:26:46 +00:00
|
|
|
w->widget[BUILD_VEHICLE_WIDGET_CAPTION].data = STR_9808_NEW_SHIPS;
|
|
|
|
w->widget[BUILD_VEHICLE_WIDGET_LIST].tooltips = STR_9825_SHIP_SELECTION_LIST_CLICK;
|
|
|
|
w->widget[BUILD_VEHICLE_WIDGET_BUILD].data = STR_9809_BUILD_SHIP;
|
|
|
|
w->widget[BUILD_VEHICLE_WIDGET_BUILD].tooltips = STR_9826_BUILD_THE_HIGHLIGHTED_SHIP;
|
|
|
|
w->widget[BUILD_VEHICLE_WIDGET_RENAME].data = STR_9836_RENAME;
|
|
|
|
w->widget[BUILD_VEHICLE_WIDGET_RENAME].tooltips = STR_9837_RENAME_SHIP_TYPE;
|
|
|
|
break;
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_AIRCRAFT:
|
2007-01-21 22:50:43 +00:00
|
|
|
w->widget[BUILD_VEHICLE_WIDGET_CAPTION].data = STR_A005_NEW_AIRCRAFT;
|
|
|
|
w->widget[BUILD_VEHICLE_WIDGET_LIST].tooltips = STR_A025_AIRCRAFT_SELECTION_LIST;
|
|
|
|
w->widget[BUILD_VEHICLE_WIDGET_BUILD].data = STR_A006_BUILD_AIRCRAFT;
|
|
|
|
w->widget[BUILD_VEHICLE_WIDGET_BUILD].tooltips = STR_A026_BUILD_THE_HIGHLIGHTED_AIRCRAFT;
|
|
|
|
w->widget[BUILD_VEHICLE_WIDGET_RENAME].data = STR_A037_RENAME;
|
|
|
|
w->widget[BUILD_VEHICLE_WIDGET_RENAME].tooltips = STR_A038_RENAME_AIRCRAFT_TYPE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-10 15:02:38 +00:00
|
|
|
static bool _internal_sort_order; // descending/ascending
|
2007-01-21 22:50:43 +00:00
|
|
|
|
2007-01-22 01:13:10 +00:00
|
|
|
static byte _last_sort_criteria[] = {0, 0, 0, 0};
|
|
|
|
static bool _last_sort_order[] = {false, false, false, false};
|
2006-10-10 15:02:38 +00:00
|
|
|
|
|
|
|
static int CDECL EngineNumberSorter(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const EngineID va = *(const EngineID*)a;
|
|
|
|
const EngineID vb = *(const EngineID*)b;
|
|
|
|
int r = va - vb;
|
|
|
|
|
|
|
|
return _internal_sort_order ? -r : r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int CDECL EngineIntroDateSorter(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const int va = GetEngine(*(const EngineID*)a)->intro_date;
|
|
|
|
const int vb = GetEngine(*(const EngineID*)b)->intro_date;
|
|
|
|
const int r = va - vb;
|
|
|
|
|
|
|
|
if (r == 0) {
|
|
|
|
/* Use EngineID to sort instead since we want consistent sorting */
|
|
|
|
return EngineNumberSorter(a, b);
|
|
|
|
}
|
|
|
|
return _internal_sort_order ? -r : r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int CDECL EngineNameSorter(const void *a, const void *b)
|
|
|
|
{
|
2006-10-10 15:46:03 +00:00
|
|
|
static EngineID last_engine[2] = { INVALID_ENGINE, INVALID_ENGINE };
|
|
|
|
static char last_name[2][64] = { "\0", "\0" };
|
|
|
|
|
2006-10-10 15:02:38 +00:00
|
|
|
const EngineID va = *(const EngineID*)a;
|
|
|
|
const EngineID vb = *(const EngineID*)b;
|
|
|
|
int r;
|
|
|
|
|
2006-10-10 15:46:03 +00:00
|
|
|
if (va != last_engine[0]) {
|
|
|
|
last_engine[0] = va;
|
2007-06-25 14:46:32 +00:00
|
|
|
SetDParam(0, va);
|
|
|
|
GetString(last_name[0], STR_ENGINE_NAME, lastof(last_name[0]));
|
2006-10-10 15:46:03 +00:00
|
|
|
}
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2006-10-10 15:46:03 +00:00
|
|
|
if (vb != last_engine[1]) {
|
|
|
|
last_engine[1] = vb;
|
2007-06-25 14:46:32 +00:00
|
|
|
SetDParam(0, vb);
|
|
|
|
GetString(last_name[1], STR_ENGINE_NAME, lastof(last_name[1]));
|
2006-10-10 15:02:38 +00:00
|
|
|
}
|
|
|
|
|
2006-10-10 15:46:03 +00:00
|
|
|
r = strcmp(last_name[0], last_name[1]); // sort by name
|
2006-10-10 15:02:38 +00:00
|
|
|
|
|
|
|
if (r == 0) {
|
|
|
|
/* Use EngineID to sort instead since we want consistent sorting */
|
|
|
|
return EngineNumberSorter(a, b);
|
|
|
|
}
|
2006-10-10 15:46:03 +00:00
|
|
|
return _internal_sort_order ? -r : r;
|
2006-10-10 15:02:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int CDECL EngineReliabilitySorter(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const int va = GetEngine(*(const EngineID*)a)->reliability;
|
|
|
|
const int vb = GetEngine(*(const EngineID*)b)->reliability;
|
|
|
|
const int r = va - vb;
|
|
|
|
|
|
|
|
if (r == 0) {
|
|
|
|
/* Use EngineID to sort instead since we want consistent sorting */
|
|
|
|
return EngineNumberSorter(a, b);
|
|
|
|
}
|
|
|
|
return _internal_sort_order ? -r : r;
|
|
|
|
}
|
|
|
|
|
2007-01-21 22:50:43 +00:00
|
|
|
/* Train sorting functions */
|
|
|
|
static int CDECL TrainEngineCostSorter(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
int va = RailVehInfo(*(const EngineID*)a)->base_cost;
|
|
|
|
int vb = RailVehInfo(*(const EngineID*)b)->base_cost;
|
|
|
|
int r = va - vb;
|
|
|
|
|
|
|
|
return _internal_sort_order ? -r : r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int CDECL TrainEngineSpeedSorter(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
int va = RailVehInfo(*(const EngineID*)a)->max_speed;
|
|
|
|
int vb = RailVehInfo(*(const EngineID*)b)->max_speed;
|
|
|
|
int r = va - vb;
|
|
|
|
|
|
|
|
return _internal_sort_order ? -r : r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int CDECL TrainEnginePowerSorter(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a);
|
|
|
|
const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b);
|
|
|
|
|
2007-01-30 11:53:35 +00:00
|
|
|
int va = rvi_a->power << (rvi_a->railveh_type == RAILVEH_MULTIHEAD ? 1 : 0);
|
|
|
|
int vb = rvi_b->power << (rvi_b->railveh_type == RAILVEH_MULTIHEAD ? 1 : 0);
|
2007-01-21 22:50:43 +00:00
|
|
|
int r = va - vb;
|
|
|
|
|
|
|
|
return _internal_sort_order ? -r : r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int CDECL TrainEngineRunningCostSorter(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a);
|
|
|
|
const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b);
|
|
|
|
|
2007-06-21 14:32:27 +00:00
|
|
|
Money va = rvi_a->running_cost_base * _price.running_rail[rvi_a->running_cost_class] * (rvi_a->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
|
|
|
|
Money vb = rvi_b->running_cost_base * _price.running_rail[rvi_b->running_cost_class] * (rvi_b->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
|
|
|
|
int r = ClampToI32(va - vb);
|
2007-01-21 22:50:43 +00:00
|
|
|
|
|
|
|
return _internal_sort_order ? -r : r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int CDECL TrainEnginePowerVsRunningCostSorter(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a);
|
|
|
|
const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b);
|
|
|
|
|
|
|
|
/* Here we are using a few tricks to get the right sort.
|
|
|
|
* We want power/running cost, but since we usually got higher running cost than power and we store the result in an int,
|
|
|
|
* we will actually calculate cunning cost/power (to make it more than 1).
|
|
|
|
* Because of this, the return value have to be reversed as well and we return b - a instead of a - b.
|
|
|
|
* Another thing is that both power and running costs should be doubled for multiheaded engines.
|
|
|
|
* Since it would be multipling with 2 in both numerator and denumerator, it will even themselves out and we skip checking for multiheaded. */
|
2007-06-21 14:32:27 +00:00
|
|
|
Money va = (rvi_a->running_cost_base * _price.running_rail[rvi_a->running_cost_class]) / max((uint16)1, rvi_a->power);
|
|
|
|
Money vb = (rvi_b->running_cost_base * _price.running_rail[rvi_b->running_cost_class]) / max((uint16)1, rvi_b->power);
|
|
|
|
int r = ClampToI32(vb - va);
|
2007-01-21 22:50:43 +00:00
|
|
|
|
|
|
|
return _internal_sort_order ? -r : r;
|
|
|
|
}
|
|
|
|
|
2007-02-15 17:51:39 +00:00
|
|
|
static int CDECL TrainEngineNumberSorter(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const EngineID va = *(const EngineID*)a;
|
|
|
|
const EngineID vb = *(const EngineID*)b;
|
|
|
|
int r = ListPositionOfEngine(va) - ListPositionOfEngine(vb);
|
|
|
|
|
|
|
|
return _internal_sort_order ? -r : r;
|
|
|
|
}
|
|
|
|
|
2007-06-02 15:41:37 +00:00
|
|
|
static int CDECL TrainEngineCapacitySorter(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
int va = RailVehInfo(*(const EngineID*)a)->capacity;
|
|
|
|
int vb = RailVehInfo(*(const EngineID*)b)->capacity;
|
|
|
|
int r = va - vb;
|
|
|
|
|
|
|
|
if (r == 0) {
|
|
|
|
/* Use EngineID to sort instead since we want consistent sorting */
|
|
|
|
return EngineNumberSorter(a, b);
|
|
|
|
}
|
|
|
|
return _internal_sort_order ? -r : r;
|
|
|
|
}
|
|
|
|
|
2007-01-21 22:50:43 +00:00
|
|
|
static int CDECL TrainEnginesThenWagonsSorter(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
EngineID va = *(const EngineID*)a;
|
|
|
|
EngineID vb = *(const EngineID*)b;
|
2007-01-30 17:19:58 +00:00
|
|
|
int val_a = (RailVehInfo(va)->railveh_type == RAILVEH_WAGON ? 1 : 0);
|
|
|
|
int val_b = (RailVehInfo(vb)->railveh_type == RAILVEH_WAGON ? 1 : 0);
|
2007-01-21 22:50:43 +00:00
|
|
|
int r = val_a - val_b;
|
|
|
|
|
|
|
|
/* Use EngineID to sort instead since we want consistent sorting */
|
|
|
|
if (r == 0) return EngineNumberSorter(a, b);
|
|
|
|
|
|
|
|
return _internal_sort_order ? -r : r;
|
|
|
|
}
|
|
|
|
|
2007-06-02 15:41:37 +00:00
|
|
|
static int CDECL RoadVehEngineCapacitySorter(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
int va = RoadVehInfo(*(const EngineID*)a)->capacity;
|
|
|
|
int vb = RoadVehInfo(*(const EngineID*)b)->capacity;
|
|
|
|
int r = va - vb;
|
|
|
|
|
|
|
|
if (r == 0) {
|
|
|
|
/* Use EngineID to sort instead since we want consistent sorting */
|
|
|
|
return EngineNumberSorter(a, b);
|
|
|
|
}
|
|
|
|
return _internal_sort_order ? -r : r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int CDECL ShipEngineCapacitySorter(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
int va = ShipVehInfo(*(const EngineID*)a)->capacity;
|
|
|
|
int vb = ShipVehInfo(*(const EngineID*)b)->capacity;
|
|
|
|
int r = va - vb;
|
|
|
|
|
|
|
|
if (r == 0) {
|
|
|
|
/* Use EngineID to sort instead since we want consistent sorting */
|
|
|
|
return EngineNumberSorter(a, b);
|
|
|
|
}
|
|
|
|
return _internal_sort_order ? -r : r;
|
|
|
|
}
|
|
|
|
|
2006-10-10 15:02:38 +00:00
|
|
|
/* Aircraft sorting functions */
|
|
|
|
|
|
|
|
static int CDECL AircraftEngineCostSorter(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const int va = AircraftVehInfo(*(const EngineID*)a)->base_cost;
|
|
|
|
const int vb = AircraftVehInfo(*(const EngineID*)b)->base_cost;
|
|
|
|
int r = va - vb;
|
|
|
|
|
|
|
|
return _internal_sort_order ? -r : r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int CDECL AircraftEngineSpeedSorter(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const int va = AircraftVehInfo(*(const EngineID*)a)->max_speed;
|
|
|
|
const int vb = AircraftVehInfo(*(const EngineID*)b)->max_speed;
|
|
|
|
const int r = va - vb;
|
|
|
|
|
|
|
|
if (r == 0) {
|
|
|
|
/* Use EngineID to sort instead since we want consistent sorting */
|
|
|
|
return EngineNumberSorter(a, b);
|
|
|
|
}
|
|
|
|
return _internal_sort_order ? -r : r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int CDECL AircraftEngineRunningCostSorter(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const int va = AircraftVehInfo(*(const EngineID*)a)->running_cost;
|
|
|
|
const int vb = AircraftVehInfo(*(const EngineID*)b)->running_cost;
|
|
|
|
const int r = va - vb;
|
|
|
|
|
|
|
|
if (r == 0) {
|
|
|
|
/* Use EngineID to sort instead since we want consistent sorting */
|
|
|
|
return EngineNumberSorter(a, b);
|
|
|
|
}
|
|
|
|
return _internal_sort_order ? -r : r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int CDECL AircraftEngineCargoSorter(const void *a, const void *b)
|
|
|
|
{
|
2007-06-02 15:47:38 +00:00
|
|
|
int va = AircraftVehInfo(*(const EngineID*)a)->passenger_capacity;
|
|
|
|
int vb = AircraftVehInfo(*(const EngineID*)b)->passenger_capacity;
|
|
|
|
int r = va - vb;
|
2006-10-10 15:02:38 +00:00
|
|
|
|
|
|
|
if (r == 0) {
|
2007-06-02 15:47:38 +00:00
|
|
|
/* The planes has the same passenger capacity. Check mail capacity instead */
|
|
|
|
va = AircraftVehInfo(*(const EngineID*)a)->mail_capacity;
|
|
|
|
vb = AircraftVehInfo(*(const EngineID*)b)->mail_capacity;
|
|
|
|
r = va - vb;
|
|
|
|
|
|
|
|
if (r == 0) {
|
|
|
|
/* Use EngineID to sort instead since we want consistent sorting */
|
|
|
|
return EngineNumberSorter(a, b);
|
|
|
|
}
|
2006-10-10 15:02:38 +00:00
|
|
|
}
|
|
|
|
return _internal_sort_order ? -r : r;
|
|
|
|
}
|
|
|
|
|
2007-06-02 15:41:37 +00:00
|
|
|
static EngList_SortTypeFunction * const _sorter[][10] = {{
|
2007-01-22 14:08:14 +00:00
|
|
|
/* Trains */
|
2007-02-15 17:51:39 +00:00
|
|
|
&TrainEngineNumberSorter,
|
2007-01-21 22:50:43 +00:00
|
|
|
&TrainEngineCostSorter,
|
|
|
|
&TrainEngineSpeedSorter,
|
|
|
|
&TrainEnginePowerSorter,
|
|
|
|
&EngineIntroDateSorter,
|
|
|
|
&EngineNameSorter,
|
|
|
|
&TrainEngineRunningCostSorter,
|
|
|
|
&TrainEnginePowerVsRunningCostSorter,
|
|
|
|
&EngineReliabilitySorter,
|
2007-06-02 15:41:37 +00:00
|
|
|
&TrainEngineCapacitySorter,
|
2007-04-18 22:10:36 +00:00
|
|
|
}, {
|
2007-01-22 14:08:14 +00:00
|
|
|
/* Road vehicles */
|
2007-01-22 01:35:53 +00:00
|
|
|
&EngineNumberSorter,
|
|
|
|
&EngineIntroDateSorter,
|
|
|
|
&EngineNameSorter,
|
|
|
|
&EngineReliabilitySorter,
|
2007-06-02 15:41:37 +00:00
|
|
|
&RoadVehEngineCapacitySorter,
|
2007-04-18 22:10:36 +00:00
|
|
|
}, {
|
2007-01-22 14:08:14 +00:00
|
|
|
/* Ships */
|
2007-01-22 01:35:53 +00:00
|
|
|
&EngineNumberSorter,
|
|
|
|
&EngineIntroDateSorter,
|
|
|
|
&EngineNameSorter,
|
|
|
|
&EngineReliabilitySorter,
|
2007-06-02 15:41:37 +00:00
|
|
|
&ShipEngineCapacitySorter,
|
2007-04-18 22:10:36 +00:00
|
|
|
}, {
|
2007-01-22 14:08:14 +00:00
|
|
|
/* Aircraft */
|
2007-01-22 01:35:53 +00:00
|
|
|
&EngineNumberSorter,
|
|
|
|
&AircraftEngineCostSorter,
|
|
|
|
&AircraftEngineSpeedSorter,
|
|
|
|
&EngineIntroDateSorter,
|
|
|
|
&EngineNameSorter,
|
|
|
|
&AircraftEngineRunningCostSorter,
|
|
|
|
&EngineReliabilitySorter,
|
|
|
|
&AircraftEngineCargoSorter,
|
|
|
|
}};
|
2007-01-21 22:50:43 +00:00
|
|
|
|
2007-06-02 15:41:37 +00:00
|
|
|
static const StringID _sort_listing[][11] = {{
|
2007-01-22 14:08:14 +00:00
|
|
|
/* Trains */
|
2007-01-21 22:50:43 +00:00
|
|
|
STR_ENGINE_SORT_ENGINE_ID,
|
|
|
|
STR_ENGINE_SORT_COST,
|
|
|
|
STR_SORT_BY_MAX_SPEED,
|
|
|
|
STR_ENGINE_SORT_POWER,
|
|
|
|
STR_ENGINE_SORT_INTRO_DATE,
|
|
|
|
STR_SORT_BY_DROPDOWN_NAME,
|
|
|
|
STR_ENGINE_SORT_RUNNING_COST,
|
|
|
|
STR_ENGINE_SORT_POWER_VS_RUNNING_COST,
|
|
|
|
STR_SORT_BY_RELIABILITY,
|
2007-06-02 15:41:37 +00:00
|
|
|
STR_ENGINE_SORT_CARGO_CAPACITY,
|
2007-01-21 22:50:43 +00:00
|
|
|
INVALID_STRING_ID
|
2007-04-18 22:10:36 +00:00
|
|
|
}, {
|
2007-01-22 14:08:14 +00:00
|
|
|
/* Road vehicles */
|
2007-01-22 00:26:46 +00:00
|
|
|
STR_ENGINE_SORT_ENGINE_ID,
|
|
|
|
STR_ENGINE_SORT_INTRO_DATE,
|
|
|
|
STR_SORT_BY_DROPDOWN_NAME,
|
|
|
|
STR_SORT_BY_RELIABILITY,
|
2007-06-02 15:41:37 +00:00
|
|
|
STR_ENGINE_SORT_CARGO_CAPACITY,
|
2007-01-22 00:26:46 +00:00
|
|
|
INVALID_STRING_ID
|
2007-04-18 22:10:36 +00:00
|
|
|
}, {
|
2007-01-22 14:08:14 +00:00
|
|
|
/* Ships */
|
2007-01-22 01:35:53 +00:00
|
|
|
STR_ENGINE_SORT_ENGINE_ID,
|
|
|
|
STR_ENGINE_SORT_INTRO_DATE,
|
|
|
|
STR_SORT_BY_DROPDOWN_NAME,
|
|
|
|
STR_SORT_BY_RELIABILITY,
|
2007-06-02 15:41:37 +00:00
|
|
|
STR_ENGINE_SORT_CARGO_CAPACITY,
|
2007-01-22 01:35:53 +00:00
|
|
|
INVALID_STRING_ID
|
2007-04-18 22:10:36 +00:00
|
|
|
}, {
|
2007-01-22 14:08:14 +00:00
|
|
|
/* Aircraft */
|
2006-10-10 15:02:38 +00:00
|
|
|
STR_ENGINE_SORT_ENGINE_ID,
|
|
|
|
STR_ENGINE_SORT_COST,
|
|
|
|
STR_SORT_BY_MAX_SPEED,
|
|
|
|
STR_ENGINE_SORT_INTRO_DATE,
|
|
|
|
STR_SORT_BY_DROPDOWN_NAME,
|
|
|
|
STR_ENGINE_SORT_RUNNING_COST,
|
|
|
|
STR_SORT_BY_RELIABILITY,
|
|
|
|
STR_ENGINE_SORT_CARGO_CAPACITY,
|
|
|
|
INVALID_STRING_ID
|
2007-01-22 01:35:53 +00:00
|
|
|
}};
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2007-01-21 22:50:43 +00:00
|
|
|
/* Draw rail wagon specific details */
|
2007-01-23 20:55:04 +00:00
|
|
|
static int DrawRailWagonPurchaseInfo(int x, int y, EngineID engine_number, const RailVehicleInfo *rvi)
|
2007-01-21 22:50:43 +00:00
|
|
|
{
|
|
|
|
/* Purchase cost */
|
2007-06-21 17:25:17 +00:00
|
|
|
SetDParam(0, (GetEngineProperty(engine_number, 0x17, rvi->base_cost) * _price.build_railwagon) >> 8);
|
2007-01-21 22:50:43 +00:00
|
|
|
DrawString(x, y, STR_PURCHASE_INFO_COST, 0);
|
|
|
|
y += 10;
|
|
|
|
|
|
|
|
/* Wagon weight - (including cargo) */
|
2007-05-07 16:38:21 +00:00
|
|
|
uint weight = GetEngineProperty(engine_number, 0x16, rvi->weight);
|
|
|
|
SetDParam(0, weight);
|
2007-05-12 07:05:34 +00:00
|
|
|
SetDParam(1, (GetCargo(rvi->cargo_type)->weight * GetEngineProperty(engine_number, 0x14, rvi->capacity) >> 4) + weight);
|
2007-01-21 22:50:43 +00:00
|
|
|
DrawString(x, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT, 0);
|
|
|
|
y += 10;
|
|
|
|
|
|
|
|
/* Wagon speed limit, displayed if above zero */
|
2007-05-07 16:38:21 +00:00
|
|
|
if (_patches.wagon_speed_limits) {
|
|
|
|
uint max_speed = GetEngineProperty(engine_number, 0x09, rvi->max_speed);
|
|
|
|
if (max_speed > 0) {
|
|
|
|
SetDParam(0, max_speed * 10 / 16);
|
|
|
|
DrawString(x, y, STR_PURCHASE_INFO_SPEED, 0);
|
|
|
|
y += 10;
|
|
|
|
}
|
2007-01-21 22:50:43 +00:00
|
|
|
}
|
|
|
|
return y;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw locomotive specific details */
|
2007-01-24 07:14:09 +00:00
|
|
|
static int DrawRailEnginePurchaseInfo(int x, int y, EngineID engine_number, const RailVehicleInfo *rvi)
|
2007-01-21 22:50:43 +00:00
|
|
|
{
|
2007-01-30 11:53:35 +00:00
|
|
|
int multihead = (rvi->railveh_type == RAILVEH_MULTIHEAD ? 1 : 0);
|
2007-05-07 16:38:21 +00:00
|
|
|
uint weight = GetEngineProperty(engine_number, 0x16, rvi->weight);
|
2007-01-21 22:50:43 +00:00
|
|
|
|
|
|
|
/* Purchase Cost - Engine weight */
|
2007-06-21 17:25:17 +00:00
|
|
|
SetDParam(0, GetEngineProperty(engine_number, 0x17, rvi->base_cost) * (_price.build_railvehicle >> 3) >> 5);
|
2007-05-07 16:38:21 +00:00
|
|
|
SetDParam(1, weight << multihead);
|
2007-04-18 22:10:36 +00:00
|
|
|
DrawString(x, y, STR_PURCHASE_INFO_COST_WEIGHT, 0);
|
2007-01-21 22:50:43 +00:00
|
|
|
y += 10;
|
|
|
|
|
|
|
|
/* Max speed - Engine power */
|
2007-05-07 16:38:21 +00:00
|
|
|
SetDParam(0, GetEngineProperty(engine_number, 0x09, rvi->max_speed) * 10 / 16);
|
|
|
|
SetDParam(1, GetEngineProperty(engine_number, 0x0B, rvi->power) << multihead);
|
2007-04-18 22:10:36 +00:00
|
|
|
DrawString(x, y, STR_PURCHASE_INFO_SPEED_POWER, 0);
|
2007-01-21 22:50:43 +00:00
|
|
|
y += 10;
|
|
|
|
|
|
|
|
/* Max tractive effort - not applicable if old acceleration or maglev */
|
2007-01-24 07:14:09 +00:00
|
|
|
if (_patches.realistic_acceleration && rvi->railtype != RAILTYPE_MAGLEV) {
|
2007-05-07 16:38:21 +00:00
|
|
|
SetDParam(0, ((weight << multihead) * 10 * GetEngineProperty(engine_number, 0x1F, rvi->tractive_effort)) / 256);
|
2007-01-21 22:50:43 +00:00
|
|
|
DrawString(x, y, STR_PURCHASE_INFO_MAX_TE, 0);
|
|
|
|
y += 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Running cost */
|
2007-06-21 17:25:17 +00:00
|
|
|
SetDParam(0, (GetEngineProperty(engine_number, 0x0D, rvi->running_cost_base) * _price.running_rail[rvi->running_cost_class] >> 8) << multihead);
|
2007-04-18 22:10:36 +00:00
|
|
|
DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
|
2007-01-21 22:50:43 +00:00
|
|
|
y += 10;
|
|
|
|
|
|
|
|
/* Powered wagons power - Powered wagons extra weight */
|
|
|
|
if (rvi->pow_wag_power != 0) {
|
|
|
|
SetDParam(0, rvi->pow_wag_power);
|
|
|
|
SetDParam(1, rvi->pow_wag_weight);
|
2007-04-18 22:10:36 +00:00
|
|
|
DrawString(x, y, STR_PURCHASE_INFO_PWAGPOWER_PWAGWEIGHT, 0);
|
2007-01-21 22:50:43 +00:00
|
|
|
y += 10;
|
|
|
|
};
|
|
|
|
|
|
|
|
return y;
|
|
|
|
}
|
|
|
|
|
2007-01-22 02:09:51 +00:00
|
|
|
/* Draw road vehicle specific details */
|
2007-01-23 20:55:04 +00:00
|
|
|
static int DrawRoadVehPurchaseInfo(int x, int y, EngineID engine_number, const RoadVehicleInfo *rvi)
|
2007-01-22 02:09:51 +00:00
|
|
|
{
|
|
|
|
bool refittable = (_engine_info[engine_number].refit_mask != 0);
|
|
|
|
|
|
|
|
/* Purchase cost - Max speed */
|
2007-06-21 17:25:17 +00:00
|
|
|
SetDParam(0, GetEngineProperty(engine_number, 0x11, rvi->base_cost) * (_price.roadveh_base >> 3) >> 5);
|
2007-01-30 21:10:04 +00:00
|
|
|
SetDParam(1, rvi->max_speed * 10 / 32);
|
2007-01-22 02:09:51 +00:00
|
|
|
DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, 0);
|
|
|
|
y += 10;
|
|
|
|
|
|
|
|
/* Running cost */
|
2007-06-21 17:25:17 +00:00
|
|
|
SetDParam(0, rvi->running_cost * _price.roadveh_running >> 8);
|
2007-01-22 02:09:51 +00:00
|
|
|
DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
|
|
|
|
y += 10;
|
|
|
|
|
|
|
|
/* Cargo type + capacity */
|
|
|
|
SetDParam(0, rvi->cargo_type);
|
2007-05-12 07:05:34 +00:00
|
|
|
SetDParam(1, GetEngineProperty(engine_number, 0x0F, rvi->capacity));
|
2007-01-22 02:09:51 +00:00
|
|
|
SetDParam(2, refittable ? STR_9842_REFITTABLE : STR_EMPTY);
|
|
|
|
DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0);
|
|
|
|
y += 10;
|
|
|
|
|
|
|
|
return y;
|
|
|
|
}
|
|
|
|
|
2007-01-22 00:26:46 +00:00
|
|
|
/* Draw ship specific details */
|
2007-01-23 20:55:04 +00:00
|
|
|
static int DrawShipPurchaseInfo(int x, int y, EngineID engine_number, const ShipVehicleInfo *svi)
|
2007-01-22 00:26:46 +00:00
|
|
|
{
|
|
|
|
/* Purchase cost - Max speed */
|
2007-06-21 17:25:17 +00:00
|
|
|
SetDParam(0, GetEngineProperty(engine_number, 0x0A, svi->base_cost) * (_price.ship_base >> 3) >> 5);
|
2007-05-07 16:38:21 +00:00
|
|
|
SetDParam(1, GetEngineProperty(engine_number, 0x0B, svi->max_speed) * 10 / 32);
|
2007-04-18 22:10:36 +00:00
|
|
|
DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, 0);
|
2007-01-22 00:26:46 +00:00
|
|
|
y += 10;
|
|
|
|
|
|
|
|
/* Cargo type + capacity */
|
|
|
|
SetDParam(0, svi->cargo_type);
|
2007-05-12 07:05:34 +00:00
|
|
|
SetDParam(1, GetEngineProperty(engine_number, 0x0D, svi->capacity));
|
2007-01-22 00:26:46 +00:00
|
|
|
SetDParam(2, svi->refittable ? STR_9842_REFITTABLE : STR_EMPTY);
|
2007-04-18 22:10:36 +00:00
|
|
|
DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0);
|
2007-01-22 00:26:46 +00:00
|
|
|
y += 10;
|
|
|
|
|
|
|
|
/* Running cost */
|
2007-06-21 17:25:17 +00:00
|
|
|
SetDParam(0, GetEngineProperty(engine_number, 0x0F, svi->running_cost) * _price.ship_running >> 8);
|
2007-04-18 22:10:36 +00:00
|
|
|
DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
|
2007-01-22 00:26:46 +00:00
|
|
|
y += 10;
|
|
|
|
|
|
|
|
return y;
|
|
|
|
}
|
|
|
|
|
2007-01-21 22:50:43 +00:00
|
|
|
/* Draw aircraft specific details */
|
2007-01-23 20:55:04 +00:00
|
|
|
static int DrawAircraftPurchaseInfo(int x, int y, EngineID engine_number, const AircraftVehicleInfo *avi)
|
2006-10-10 15:02:38 +00:00
|
|
|
{
|
|
|
|
CargoID cargo;
|
|
|
|
|
|
|
|
/* Purchase cost - Max speed */
|
2007-06-21 17:25:17 +00:00
|
|
|
SetDParam(0, GetEngineProperty(engine_number, 0x0B, avi->base_cost) * (_price.aircraft_base >> 3) >> 5);
|
2007-03-02 12:01:24 +00:00
|
|
|
SetDParam(1, avi->max_speed * 10 / 16);
|
2006-10-10 15:02:38 +00:00
|
|
|
DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, 0);
|
|
|
|
y += 10;
|
|
|
|
|
|
|
|
/* Cargo capacity */
|
|
|
|
cargo = FindFirstRefittableCargo(engine_number);
|
|
|
|
if (cargo == CT_INVALID || cargo == CT_PASSENGERS) {
|
|
|
|
SetDParam(0, avi->passenger_capacity);
|
|
|
|
SetDParam(1, avi->mail_capacity);
|
|
|
|
DrawString(x, y, STR_PURCHASE_INFO_AIRCRAFT_CAPACITY, 0);
|
|
|
|
} else {
|
|
|
|
/* Note, if the default capacity is selected by the refit capacity
|
|
|
|
* callback, then the capacity shown is likely to be incorrect. */
|
2006-10-20 11:53:29 +00:00
|
|
|
SetDParam(0, cargo);
|
2007-02-20 06:39:09 +00:00
|
|
|
SetDParam(1, AircraftDefaultCargoCapacity(cargo, avi));
|
2006-10-10 15:02:38 +00:00
|
|
|
SetDParam(2, STR_9842_REFITTABLE);
|
|
|
|
DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0);
|
|
|
|
}
|
|
|
|
y += 10;
|
|
|
|
|
|
|
|
/* Running cost */
|
2007-06-21 17:25:17 +00:00
|
|
|
SetDParam(0, GetEngineProperty(engine_number, 0x0E, avi->running_cost) * _price.aircraft_running >> 8);
|
2006-10-10 15:02:38 +00:00
|
|
|
DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
|
|
|
|
y += 10;
|
|
|
|
|
2007-01-21 22:50:43 +00:00
|
|
|
return y;
|
|
|
|
}
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2007-01-21 22:50:43 +00:00
|
|
|
/**
|
|
|
|
* Draw the purchase info details of a vehicle at a given location.
|
|
|
|
* @param x,y location where to draw the info
|
|
|
|
* @param w how wide are the text allowed to be (size of widget/window to Draw in)
|
|
|
|
* @param engine_number the engine of which to draw the info of
|
2007-03-26 11:41:14 +00:00
|
|
|
* @return y after drawing all the text
|
2007-01-21 22:50:43 +00:00
|
|
|
*/
|
2007-03-26 11:41:14 +00:00
|
|
|
int DrawVehiclePurchaseInfo(int x, int y, uint w, EngineID engine_number)
|
2007-01-21 22:50:43 +00:00
|
|
|
{
|
|
|
|
const Engine *e = GetEngine(engine_number);
|
|
|
|
YearMonthDay ymd;
|
|
|
|
ConvertDateToYMD(e->intro_date, &ymd);
|
2007-01-22 14:08:14 +00:00
|
|
|
bool refitable = false;
|
2007-01-21 22:50:43 +00:00
|
|
|
|
|
|
|
switch (e->type) {
|
2007-05-18 17:31:41 +00:00
|
|
|
default: NOT_REACHED();
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_TRAIN: {
|
2007-01-21 22:50:43 +00:00
|
|
|
const RailVehicleInfo *rvi = RailVehInfo(engine_number);
|
2007-05-12 07:05:34 +00:00
|
|
|
uint capacity = GetEngineProperty(engine_number, 0x14, rvi->capacity);
|
2007-01-21 22:50:43 +00:00
|
|
|
|
2007-05-12 07:05:34 +00:00
|
|
|
refitable = (EngInfo(engine_number)->refit_mask != 0) && (capacity > 0);
|
2007-01-23 21:24:26 +00:00
|
|
|
|
2007-01-30 11:53:35 +00:00
|
|
|
if (rvi->railveh_type == RAILVEH_WAGON) {
|
2007-01-23 20:55:04 +00:00
|
|
|
y = DrawRailWagonPurchaseInfo(x, y, engine_number, rvi);
|
2007-01-21 22:50:43 +00:00
|
|
|
} else {
|
2007-01-24 07:14:09 +00:00
|
|
|
y = DrawRailEnginePurchaseInfo(x, y, engine_number, rvi);
|
2007-01-21 22:50:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Cargo type + capacity, or N/A */
|
|
|
|
if (rvi->capacity == 0) {
|
|
|
|
SetDParam(0, CT_INVALID);
|
|
|
|
SetDParam(2, STR_EMPTY);
|
|
|
|
} else {
|
2007-01-30 11:53:35 +00:00
|
|
|
int multihead = (rvi->railveh_type == RAILVEH_MULTIHEAD ? 1 : 0);
|
2007-01-23 20:01:04 +00:00
|
|
|
|
2007-01-21 22:50:43 +00:00
|
|
|
SetDParam(0, rvi->cargo_type);
|
2007-05-12 07:05:34 +00:00
|
|
|
SetDParam(1, (capacity * (CountArticulatedParts(engine_number) + 1)) << multihead);
|
2007-01-23 21:24:26 +00:00
|
|
|
SetDParam(2, refitable ? STR_9842_REFITTABLE : STR_EMPTY);
|
2007-01-21 22:50:43 +00:00
|
|
|
}
|
2007-04-18 22:10:36 +00:00
|
|
|
DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0);
|
2007-01-21 22:50:43 +00:00
|
|
|
y += 10;
|
|
|
|
}
|
|
|
|
break;
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_ROAD:
|
2007-01-23 20:55:04 +00:00
|
|
|
y = DrawRoadVehPurchaseInfo(x, y, engine_number, RoadVehInfo(engine_number));
|
2007-01-22 14:08:14 +00:00
|
|
|
refitable = true;
|
2007-01-22 02:09:51 +00:00
|
|
|
break;
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_SHIP: {
|
2007-01-22 14:08:14 +00:00
|
|
|
const ShipVehicleInfo *svi = ShipVehInfo(engine_number);
|
2007-01-23 20:55:04 +00:00
|
|
|
y = DrawShipPurchaseInfo(x, y, engine_number, svi);
|
2007-01-22 14:08:14 +00:00
|
|
|
refitable = svi->refittable;
|
|
|
|
} break;
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_AIRCRAFT:
|
2007-01-23 20:55:04 +00:00
|
|
|
y = DrawAircraftPurchaseInfo(x, y, engine_number, AircraftVehInfo(engine_number));
|
2007-01-22 14:08:14 +00:00
|
|
|
refitable = true;
|
2007-01-21 22:50:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw details, that applies to all types except rail wagons */
|
2007-03-08 16:27:54 +00:00
|
|
|
if (e->type != VEH_TRAIN || RailVehInfo(engine_number)->railveh_type != RAILVEH_WAGON) {
|
2007-01-21 22:50:43 +00:00
|
|
|
/* Design date - Life length */
|
|
|
|
SetDParam(0, ymd.year);
|
|
|
|
SetDParam(1, e->lifelength);
|
|
|
|
DrawString(x, y, STR_PURCHASE_INFO_DESIGNED_LIFE, 0);
|
|
|
|
y += 10;
|
|
|
|
|
|
|
|
/* Reliability */
|
|
|
|
SetDParam(0, e->reliability * 100 >> 16);
|
|
|
|
DrawString(x, y, STR_PURCHASE_INFO_RELIABILITY, 0);
|
|
|
|
y += 10;
|
|
|
|
}
|
2006-10-10 15:02:38 +00:00
|
|
|
|
|
|
|
/* Additional text from NewGRF */
|
2006-10-23 18:45:43 +00:00
|
|
|
y += ShowAdditionalText(x, y, w, engine_number);
|
2007-01-22 14:08:14 +00:00
|
|
|
if (refitable) y += ShowRefitOptionsList(x, y, w, engine_number);
|
2007-03-26 11:41:14 +00:00
|
|
|
|
|
|
|
return y;
|
2006-10-10 15:02:38 +00:00
|
|
|
}
|
|
|
|
|
2007-01-21 22:50:43 +00:00
|
|
|
/* Figure out what train EngineIDs to put in the list */
|
|
|
|
static void GenerateBuildTrainList(Window *w)
|
|
|
|
{
|
|
|
|
EngineID eid, sel_id;
|
|
|
|
int num_engines = 0;
|
|
|
|
int num_wagons = 0;
|
|
|
|
buildvehicle_d *bv = &WP(w, buildvehicle_d);
|
|
|
|
|
2007-07-13 19:06:12 +00:00
|
|
|
bv->filter.railtype = (w->window_number <= VEH_END) ? RAILTYPE_END : GetRailType(w->window_number);
|
2007-01-21 22:50:43 +00:00
|
|
|
|
|
|
|
EngList_RemoveAll(&bv->eng_list);
|
|
|
|
|
|
|
|
/* Make list of all available train engines and wagons.
|
2007-02-23 11:50:43 +00:00
|
|
|
* Also check to see if the previously selected engine is still available,
|
|
|
|
* and if not, reset selection to INVALID_ENGINE. This could be the case
|
|
|
|
* when engines become obsolete and are removed */
|
2007-01-21 22:50:43 +00:00
|
|
|
for (sel_id = INVALID_ENGINE, eid = 0; eid < NUM_TRAIN_ENGINES; eid++) {
|
|
|
|
const RailVehicleInfo *rvi = RailVehInfo(eid);
|
|
|
|
|
2007-01-24 07:14:09 +00:00
|
|
|
if (bv->filter.railtype != RAILTYPE_END && !HasPowerOnRail(rvi->railtype, bv->filter.railtype)) continue;
|
2007-03-08 16:27:54 +00:00
|
|
|
if (!IsEngineBuildable(eid, VEH_TRAIN, _local_player)) continue;
|
2007-01-21 22:50:43 +00:00
|
|
|
|
|
|
|
EngList_Add(&bv->eng_list, eid);
|
2007-01-30 11:53:35 +00:00
|
|
|
if (rvi->railveh_type != RAILVEH_WAGON) {
|
2007-01-21 22:50:43 +00:00
|
|
|
num_engines++;
|
|
|
|
} else {
|
|
|
|
num_wagons++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eid == bv->sel_engine) sel_id = eid;
|
|
|
|
}
|
|
|
|
|
|
|
|
bv->sel_engine = sel_id;
|
|
|
|
|
2007-02-23 11:50:43 +00:00
|
|
|
/* make engines first, and then wagons, sorted by ListPositionOfEngine() */
|
2007-01-21 22:50:43 +00:00
|
|
|
_internal_sort_order = false;
|
|
|
|
EngList_Sort(&bv->eng_list, TrainEnginesThenWagonsSorter);
|
|
|
|
|
2007-02-23 11:50:43 +00:00
|
|
|
/* and then sort engines */
|
2007-01-21 22:50:43 +00:00
|
|
|
_internal_sort_order = bv->descending_sort_order;
|
2007-01-22 01:35:53 +00:00
|
|
|
EngList_SortPartial(&bv->eng_list, _sorter[0][bv->sort_criteria], 0, num_engines);
|
2007-01-21 22:50:43 +00:00
|
|
|
|
2007-02-23 11:50:43 +00:00
|
|
|
/* and finally sort wagons */
|
2007-01-22 01:35:53 +00:00
|
|
|
EngList_SortPartial(&bv->eng_list, _sorter[0][bv->sort_criteria], num_engines, num_wagons);
|
2007-01-21 22:50:43 +00:00
|
|
|
}
|
|
|
|
|
2007-01-22 02:09:51 +00:00
|
|
|
/* Figure out what road vehicle EngineIDs to put in the list */
|
|
|
|
static void GenerateBuildRoadVehList(Window *w)
|
|
|
|
{
|
|
|
|
EngineID eid, sel_id;
|
|
|
|
buildvehicle_d *bv = &WP(w, buildvehicle_d);
|
|
|
|
|
|
|
|
EngList_RemoveAll(&bv->eng_list);
|
|
|
|
|
|
|
|
sel_id = INVALID_ENGINE;
|
|
|
|
|
|
|
|
for (eid = ROAD_ENGINES_INDEX; eid < ROAD_ENGINES_INDEX + NUM_ROAD_ENGINES; eid++) {
|
2007-03-08 16:27:54 +00:00
|
|
|
if (!IsEngineBuildable(eid, VEH_ROAD, _local_player)) continue;
|
2007-05-25 08:13:01 +00:00
|
|
|
if (!HASBIT(bv->filter.roadtypes, HASBIT(EngInfo(eid)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD)) continue;
|
2007-01-22 02:09:51 +00:00
|
|
|
EngList_Add(&bv->eng_list, eid);
|
|
|
|
|
|
|
|
if (eid == bv->sel_engine) sel_id = eid;
|
|
|
|
}
|
|
|
|
bv->sel_engine = sel_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Figure out what ship EngineIDs to put in the list */
|
2007-01-22 00:26:46 +00:00
|
|
|
static void GenerateBuildShipList(Window *w)
|
|
|
|
{
|
|
|
|
EngineID eid, sel_id;
|
|
|
|
buildvehicle_d *bv = &WP(w, buildvehicle_d);
|
|
|
|
|
|
|
|
EngList_RemoveAll(&bv->eng_list);
|
|
|
|
|
|
|
|
sel_id = INVALID_ENGINE;
|
|
|
|
|
|
|
|
for (eid = SHIP_ENGINES_INDEX; eid < SHIP_ENGINES_INDEX + NUM_SHIP_ENGINES; eid++) {
|
2007-03-08 16:27:54 +00:00
|
|
|
if (!IsEngineBuildable(eid, VEH_SHIP, _local_player)) continue;
|
2007-01-22 00:26:46 +00:00
|
|
|
EngList_Add(&bv->eng_list, eid);
|
|
|
|
|
|
|
|
if (eid == bv->sel_engine) sel_id = eid;
|
|
|
|
}
|
|
|
|
bv->sel_engine = sel_id;
|
|
|
|
}
|
|
|
|
|
2007-01-21 22:50:43 +00:00
|
|
|
/* Figure out what aircraft EngineIDs to put in the list */
|
2006-11-30 16:03:12 +00:00
|
|
|
static void GenerateBuildAircraftList(Window *w)
|
2006-10-10 15:02:38 +00:00
|
|
|
{
|
2006-12-01 00:26:42 +00:00
|
|
|
EngineID eid, sel_id;
|
2006-11-30 16:03:12 +00:00
|
|
|
buildvehicle_d *bv = &WP(w, buildvehicle_d);
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2006-11-30 16:03:12 +00:00
|
|
|
EngList_RemoveAll(&bv->eng_list);
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2006-12-01 00:26:42 +00:00
|
|
|
/* Make list of all available planes.
|
|
|
|
* Also check to see if the previously selected plane is still available,
|
|
|
|
* and if not, reset selection to INVALID_ENGINE. This could be the case
|
|
|
|
* when planes become obsolete and are removed */
|
|
|
|
sel_id = INVALID_ENGINE;
|
2006-10-10 15:02:38 +00:00
|
|
|
for (eid = AIRCRAFT_ENGINES_INDEX; eid < AIRCRAFT_ENGINES_INDEX + NUM_AIRCRAFT_ENGINES; eid++) {
|
2007-03-08 16:27:54 +00:00
|
|
|
if (!IsEngineBuildable(eid, VEH_AIRCRAFT, _local_player)) continue;
|
2007-07-13 19:06:12 +00:00
|
|
|
/* First VEH_END window_numbers are fake to allow a window open for all different types at once */
|
|
|
|
if (w->window_number > VEH_END && !IsAircraftBuildableAtStation(eid, w->window_number)) continue;
|
2006-12-01 00:26:42 +00:00
|
|
|
|
2007-03-06 22:11:58 +00:00
|
|
|
EngList_Add(&bv->eng_list, eid);
|
|
|
|
if (eid == bv->sel_engine) sel_id = eid;
|
2006-10-10 15:02:38 +00:00
|
|
|
}
|
2006-12-01 00:26:42 +00:00
|
|
|
|
|
|
|
bv->sel_engine = sel_id;
|
2006-10-10 15:02:38 +00:00
|
|
|
}
|
|
|
|
|
2007-01-21 22:50:43 +00:00
|
|
|
/* Generate the list of vehicles */
|
2006-10-10 15:02:38 +00:00
|
|
|
static void GenerateBuildList(Window *w)
|
|
|
|
{
|
2006-11-30 16:03:12 +00:00
|
|
|
buildvehicle_d *bv = &WP(w, buildvehicle_d);
|
|
|
|
|
|
|
|
switch (bv->vehicle_type) {
|
2007-05-18 17:31:41 +00:00
|
|
|
default: NOT_REACHED();
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_TRAIN:
|
2007-01-21 22:50:43 +00:00
|
|
|
GenerateBuildTrainList(w);
|
2007-01-22 01:35:53 +00:00
|
|
|
return; // trains should not reach the last sorting
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_ROAD:
|
2007-01-22 02:09:51 +00:00
|
|
|
GenerateBuildRoadVehList(w);
|
|
|
|
break;
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_SHIP:
|
2007-01-22 00:26:46 +00:00
|
|
|
GenerateBuildShipList(w);
|
|
|
|
break;
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_AIRCRAFT:
|
2006-11-30 16:03:12 +00:00
|
|
|
GenerateBuildAircraftList(w);
|
2006-10-10 15:02:38 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-01-22 01:35:53 +00:00
|
|
|
_internal_sort_order = bv->descending_sort_order;
|
2007-02-07 19:10:19 +00:00
|
|
|
EngList_Sort(&bv->eng_list, _sorter[bv->vehicle_type][bv->sort_criteria]);
|
2006-10-10 15:02:38 +00:00
|
|
|
}
|
|
|
|
|
2007-01-22 23:23:30 +00:00
|
|
|
static void DrawVehicleEngine(byte type, int x, int y, EngineID engine, SpriteID pal)
|
|
|
|
{
|
|
|
|
switch (type) {
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_TRAIN: DrawTrainEngine( x, y, engine, pal); break;
|
|
|
|
case VEH_ROAD: DrawRoadVehEngine( x, y, engine, pal); break;
|
|
|
|
case VEH_SHIP: DrawShipEngine( x, y, engine, pal); break;
|
|
|
|
case VEH_AIRCRAFT: DrawAircraftEngine(x, y, engine, pal); break;
|
2007-01-22 23:23:30 +00:00
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Engine drawing loop
|
|
|
|
* @param type Type of vehicle (VEH_*)
|
|
|
|
* @param x,y Where should the list start
|
|
|
|
* @param eng_list What engines to draw
|
|
|
|
* @param min where to start in the list
|
2007-01-23 01:00:56 +00:00
|
|
|
* @param max where in the list to end
|
2007-01-22 23:23:30 +00:00
|
|
|
* @param selected_id what engine to highlight as selected, if any
|
2007-02-06 11:11:12 +00:00
|
|
|
* @param show_count Display the number of vehicles (used by autoreplace)
|
2007-01-22 23:23:30 +00:00
|
|
|
*/
|
2007-05-19 09:40:18 +00:00
|
|
|
void DrawEngineList(VehicleType type, int x, int y, const EngineList eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count, GroupID selected_group)
|
2007-01-22 23:23:30 +00:00
|
|
|
{
|
|
|
|
byte step_size = GetVehicleListHeight(type);
|
|
|
|
byte x_offset = 0;
|
|
|
|
byte y_offset = 0;
|
2007-02-06 11:11:12 +00:00
|
|
|
Player *p = GetPlayer(_local_player);
|
2007-01-22 23:23:30 +00:00
|
|
|
|
2007-01-23 01:00:56 +00:00
|
|
|
assert(max <= EngList_Count(&eng_list));
|
|
|
|
|
2007-01-22 23:23:30 +00:00
|
|
|
switch (type) {
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_TRAIN:
|
2007-01-22 23:23:30 +00:00
|
|
|
x++; // train and road vehicles use the same offset, except trains are one more pixel to the right
|
|
|
|
/* Fallthough */
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_ROAD:
|
2007-01-22 23:23:30 +00:00
|
|
|
x += 26;
|
|
|
|
x_offset = 30;
|
|
|
|
y += 2;
|
|
|
|
y_offset = 4;
|
|
|
|
break;
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_SHIP:
|
2007-01-22 23:23:30 +00:00
|
|
|
x += 35;
|
|
|
|
x_offset = 40;
|
|
|
|
y += 7;
|
|
|
|
y_offset = 3;
|
|
|
|
break;
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_AIRCRAFT:
|
2007-01-22 23:23:30 +00:00
|
|
|
x += 27;
|
|
|
|
x_offset = 33;
|
|
|
|
y += 7;
|
|
|
|
y_offset = 3;
|
|
|
|
break;
|
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; min < max; min++, y += step_size) {
|
|
|
|
const EngineID engine = eng_list[min];
|
2007-05-19 09:40:18 +00:00
|
|
|
const uint num_engines = IsDefaultGroupID(selected_group) ? p->num_engines[engine] : GetGroup(selected_group)->num_engines[engine];
|
2007-01-22 23:23:30 +00:00
|
|
|
|
2007-06-25 14:46:32 +00:00
|
|
|
SetDParam(0, engine);
|
|
|
|
DrawString(x + x_offset, y, STR_ENGINE_NAME, engine == selected_id ? 0xC : 0x10);
|
2007-05-19 09:40:18 +00:00
|
|
|
DrawVehicleEngine(type, x, y + y_offset, engine, (show_count && num_engines == 0) ? PALETTE_CRASH : GetEnginePalette(engine, _local_player));
|
2007-02-06 11:11:12 +00:00
|
|
|
if (show_count) {
|
2007-05-19 09:40:18 +00:00
|
|
|
SetDParam(0, num_engines);
|
2007-02-06 11:11:12 +00:00
|
|
|
DrawStringRightAligned(213, y + (GetVehicleListHeight(type) == 14 ? 3 : 8), STR_TINY_BLACK, 0);
|
|
|
|
}
|
2007-01-22 23:23:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-26 11:41:14 +00:00
|
|
|
static void ExpandPurchaseInfoWidget(Window *w, int expand_by)
|
|
|
|
{
|
|
|
|
Widget *wi = &w->widget[BUILD_VEHICLE_WIDGET_PANEL];
|
|
|
|
|
|
|
|
SetWindowDirty(w);
|
|
|
|
wi->bottom += expand_by;
|
|
|
|
|
|
|
|
for (uint i = BUILD_VEHICLE_WIDGET_BUILD; i < BUILD_VEHICLE_WIDGET_END; i++) {
|
|
|
|
wi = &w->widget[i];
|
|
|
|
wi->top += expand_by;
|
|
|
|
wi->bottom += expand_by;
|
|
|
|
}
|
|
|
|
|
|
|
|
w->height += expand_by;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
|
|
|
|
2007-01-21 22:50:43 +00:00
|
|
|
static void DrawBuildVehicleWindow(Window *w)
|
2006-10-10 15:02:38 +00:00
|
|
|
{
|
2006-12-01 00:26:42 +00:00
|
|
|
const buildvehicle_d *bv = &WP(w, buildvehicle_d);
|
2007-01-22 23:23:30 +00:00
|
|
|
uint max = min(w->vscroll.pos + w->vscroll.cap, EngList_Count(&bv->eng_list));
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2007-07-13 19:06:12 +00:00
|
|
|
SetWindowWidgetDisabledState(w, BUILD_VEHICLE_WIDGET_BUILD, w->window_number <= VEH_END);
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2006-12-01 00:28:15 +00:00
|
|
|
SetVScrollCount(w, EngList_Count(&bv->eng_list));
|
2007-01-21 22:50:43 +00:00
|
|
|
SetDParam(0, bv->filter.railtype + STR_881C_NEW_RAIL_VEHICLES); // This should only affect rail vehicles
|
2006-10-10 15:02:38 +00:00
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
2007-05-19 09:40:18 +00:00
|
|
|
DrawEngineList(bv->vehicle_type, 2, 27, bv->eng_list, w->vscroll.pos, max, bv->sel_engine, false, DEFAULT_GROUP);
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2007-01-22 23:23:30 +00:00
|
|
|
if (bv->sel_engine != INVALID_ENGINE) {
|
|
|
|
const Widget *wi = &w->widget[BUILD_VEHICLE_WIDGET_PANEL];
|
2007-03-26 11:41:14 +00:00
|
|
|
int text_end = DrawVehiclePurchaseInfo(2, wi->top + 1, wi->right - wi->left - 2, bv->sel_engine);
|
|
|
|
|
|
|
|
if (text_end > wi->bottom) ExpandPurchaseInfoWidget(w, text_end - wi->bottom);
|
2007-01-21 22:50:43 +00:00
|
|
|
}
|
2007-01-22 23:23:30 +00:00
|
|
|
|
2007-02-07 19:10:19 +00:00
|
|
|
DrawString(85, 15, _sort_listing[bv->vehicle_type][bv->sort_criteria], 0x10);
|
2007-01-22 01:35:53 +00:00
|
|
|
DoDrawString(bv->descending_sort_order ? DOWNARROW : UPARROW, 69, 15, 0x10);
|
2006-10-10 15:02:38 +00:00
|
|
|
}
|
|
|
|
|
2007-01-21 22:50:43 +00:00
|
|
|
static void BuildVehicleClickEvent(Window *w, WindowEvent *e)
|
2006-10-10 15:02:38 +00:00
|
|
|
{
|
2006-11-30 16:03:12 +00:00
|
|
|
buildvehicle_d *bv = &WP(w, buildvehicle_d);
|
2006-10-10 15:02:38 +00:00
|
|
|
|
|
|
|
switch (e->we.click.widget) {
|
|
|
|
case BUILD_VEHICLE_WIDGET_SORT_ASSENDING_DESCENDING:
|
2006-12-01 00:14:10 +00:00
|
|
|
bv->descending_sort_order ^= true;
|
2007-02-07 19:10:19 +00:00
|
|
|
_last_sort_order[bv->vehicle_type] = bv->descending_sort_order;
|
2007-01-21 23:13:46 +00:00
|
|
|
bv->regenerate_list = true;
|
2006-10-10 15:02:38 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BUILD_VEHICLE_WIDGET_LIST: {
|
2007-01-21 22:50:43 +00:00
|
|
|
uint i = (e->we.click.pt.y - 26) / GetVehicleListHeight(bv->vehicle_type) + w->vscroll.pos;
|
2006-12-01 00:28:15 +00:00
|
|
|
uint num_items = EngList_Count(&bv->eng_list);
|
|
|
|
bv->sel_engine = (i < num_items) ? bv->eng_list[i] : INVALID_ENGINE;
|
|
|
|
SetWindowDirty(w);
|
2006-11-30 16:03:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2007-01-21 22:50:43 +00:00
|
|
|
case BUILD_VEHICLE_WIDGET_SORT_TEXT: case BUILD_VEHICLE_WIDGET_SORT_DROPDOWN: // Select sorting criteria dropdown menu
|
2007-02-07 19:10:19 +00:00
|
|
|
ShowDropDownMenu(w, _sort_listing[bv->vehicle_type], bv->sort_criteria, BUILD_VEHICLE_WIDGET_SORT_DROPDOWN, 0, 0);
|
2007-01-22 01:35:53 +00:00
|
|
|
break;
|
2006-10-10 15:02:38 +00:00
|
|
|
|
|
|
|
case BUILD_VEHICLE_WIDGET_BUILD: {
|
2006-11-30 16:03:12 +00:00
|
|
|
EngineID sel_eng = bv->sel_engine;
|
2006-11-30 18:47:57 +00:00
|
|
|
if (sel_eng != INVALID_ENGINE) {
|
2007-01-21 22:50:43 +00:00
|
|
|
switch (bv->vehicle_type) {
|
2007-05-18 17:31:41 +00:00
|
|
|
default: NOT_REACHED();
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_TRAIN:
|
2007-01-30 11:53:35 +00:00
|
|
|
DoCommandP(w->window_number, sel_eng, 0, (RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) ? CcBuildWagon : CcBuildLoco,
|
2007-01-21 22:50:43 +00:00
|
|
|
CMD_BUILD_RAIL_VEHICLE | CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE));
|
|
|
|
break;
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_ROAD:
|
2007-01-22 02:09:51 +00:00
|
|
|
DoCommandP(w->window_number, sel_eng, 0, CcBuildRoadVeh, CMD_BUILD_ROAD_VEH | CMD_MSG(STR_9009_CAN_T_BUILD_ROAD_VEHICLE));
|
|
|
|
break;
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_SHIP:
|
2007-01-22 00:26:46 +00:00
|
|
|
DoCommandP(w->window_number, sel_eng, 0, CcBuildShip, CMD_BUILD_SHIP | CMD_MSG(STR_980D_CAN_T_BUILD_SHIP));
|
|
|
|
break;
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_AIRCRAFT:
|
2007-01-21 22:50:43 +00:00
|
|
|
DoCommandP(w->window_number, sel_eng, 0, CcBuildAircraft, CMD_BUILD_AIRCRAFT | CMD_MSG(STR_A008_CAN_T_BUILD_AIRCRAFT));
|
|
|
|
break;
|
|
|
|
}
|
2006-11-30 18:47:57 +00:00
|
|
|
}
|
2006-11-30 16:03:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-10-10 15:02:38 +00:00
|
|
|
|
|
|
|
case BUILD_VEHICLE_WIDGET_RENAME: {
|
2006-11-30 16:03:12 +00:00
|
|
|
EngineID sel_eng = bv->sel_engine;
|
2006-10-10 15:02:38 +00:00
|
|
|
if (sel_eng != INVALID_ENGINE) {
|
2007-01-21 22:50:43 +00:00
|
|
|
StringID str = STR_NULL;
|
|
|
|
|
2006-11-30 16:03:12 +00:00
|
|
|
bv->rename_engine = sel_eng;
|
2007-01-21 22:50:43 +00:00
|
|
|
switch (bv->vehicle_type) {
|
2007-05-18 17:31:41 +00:00
|
|
|
default: NOT_REACHED();
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_TRAIN: str = STR_886A_RENAME_TRAIN_VEHICLE_TYPE; break;
|
|
|
|
case VEH_ROAD: str = STR_9036_RENAME_ROAD_VEHICLE_TYPE; break;
|
|
|
|
case VEH_SHIP: str = STR_9838_RENAME_SHIP_TYPE; break;
|
|
|
|
case VEH_AIRCRAFT: str = STR_A039_RENAME_AIRCRAFT_TYPE; break;
|
2007-01-21 22:50:43 +00:00
|
|
|
}
|
2007-06-25 14:46:32 +00:00
|
|
|
SetDParam(0, sel_eng);
|
|
|
|
ShowQueryString(STR_ENGINE_NAME, str, 31, 160, w, CS_ALPHANUMERAL);
|
2006-10-10 15:02:38 +00:00
|
|
|
}
|
2006-11-30 16:03:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-10-10 15:02:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-21 22:50:43 +00:00
|
|
|
static void NewVehicleWndProc(Window *w, WindowEvent *e)
|
2006-10-10 15:02:38 +00:00
|
|
|
{
|
2006-11-30 16:03:12 +00:00
|
|
|
buildvehicle_d *bv = &WP(w, buildvehicle_d);
|
|
|
|
|
2006-10-10 15:02:38 +00:00
|
|
|
switch (e->event) {
|
|
|
|
case WE_INVALIDATE_DATA:
|
2007-01-21 23:13:46 +00:00
|
|
|
bv->regenerate_list = true;
|
|
|
|
SetWindowDirty(w);
|
2006-10-10 15:02:38 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_DESTROY:
|
2006-11-30 16:03:12 +00:00
|
|
|
EngList_Destroy(&bv->eng_list);
|
2006-10-10 15:02:38 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_PAINT:
|
2007-01-21 23:13:46 +00:00
|
|
|
if (bv->regenerate_list) {
|
|
|
|
bv->regenerate_list = false;
|
|
|
|
GenerateBuildList(w);
|
|
|
|
}
|
2007-01-21 22:50:43 +00:00
|
|
|
DrawBuildVehicleWindow(w);
|
2006-10-10 15:02:38 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_CLICK:
|
2007-01-21 22:50:43 +00:00
|
|
|
BuildVehicleClickEvent(w, e);
|
2006-10-10 15:02:38 +00:00
|
|
|
break;
|
|
|
|
|
2007-06-22 10:57:53 +00:00
|
|
|
case WE_DOUBLE_CLICK:
|
|
|
|
if (e->we.click.widget == BUILD_VEHICLE_WIDGET_LIST) {
|
|
|
|
/* When double clicking, we want to buy a vehicle */
|
|
|
|
e->we.click.widget = BUILD_VEHICLE_WIDGET_BUILD;
|
|
|
|
BuildVehicleClickEvent(w, e);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2006-10-10 15:02:38 +00:00
|
|
|
case WE_ON_EDIT_TEXT: {
|
|
|
|
if (e->we.edittext.str[0] != '\0') {
|
2007-01-21 22:50:43 +00:00
|
|
|
StringID str = STR_NULL;
|
2006-10-10 15:02:38 +00:00
|
|
|
_cmd_text = e->we.edittext.str;
|
2007-01-21 22:50:43 +00:00
|
|
|
switch (bv->vehicle_type) {
|
2007-05-18 17:31:41 +00:00
|
|
|
default: NOT_REACHED();
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_TRAIN: str = STR_886B_CAN_T_RENAME_TRAIN_VEHICLE; break;
|
|
|
|
case VEH_ROAD: str = STR_9037_CAN_T_RENAME_ROAD_VEHICLE; break;
|
|
|
|
case VEH_SHIP: str = STR_9839_CAN_T_RENAME_SHIP_TYPE; break;
|
|
|
|
case VEH_AIRCRAFT: str = STR_A03A_CAN_T_RENAME_AIRCRAFT_TYPE; break;
|
2007-01-21 22:50:43 +00:00
|
|
|
}
|
|
|
|
DoCommandP(0, bv->rename_engine, 0, NULL, CMD_RENAME_ENGINE | CMD_MSG(str));
|
2006-10-10 15:02:38 +00:00
|
|
|
}
|
2006-11-30 16:03:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2007-02-23 11:50:43 +00:00
|
|
|
case WE_DROPDOWN_SELECT: // we have selected a dropdown item in the list
|
2006-11-30 16:03:12 +00:00
|
|
|
if (bv->sort_criteria != e->we.dropdown.index) {
|
2007-01-21 22:50:43 +00:00
|
|
|
bv->sort_criteria = e->we.dropdown.index;
|
2007-02-07 19:10:19 +00:00
|
|
|
_last_sort_criteria[bv->vehicle_type] = bv->sort_criteria;
|
2007-01-21 23:13:46 +00:00
|
|
|
bv->regenerate_list = true;
|
2006-10-10 15:02:38 +00:00
|
|
|
}
|
|
|
|
SetWindowDirty(w);
|
2006-11-30 18:47:57 +00:00
|
|
|
break;
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2006-11-30 18:47:57 +00:00
|
|
|
case WE_RESIZE:
|
2007-01-24 14:32:20 +00:00
|
|
|
if (e->we.sizing.diff.x != 0) ResizeButtons(w, BUILD_VEHICLE_WIDGET_BUILD, BUILD_VEHICLE_WIDGET_RENAME);
|
2007-01-21 22:50:43 +00:00
|
|
|
if (e->we.sizing.diff.y == 0) break;
|
|
|
|
|
2007-02-15 20:58:45 +00:00
|
|
|
w->vscroll.cap += e->we.sizing.diff.y / (int)GetVehicleListHeight(bv->vehicle_type);
|
2006-11-30 18:47:57 +00:00
|
|
|
w->widget[BUILD_VEHICLE_WIDGET_LIST].data = (w->vscroll.cap << 8) + 1;
|
|
|
|
break;
|
2006-10-10 15:02:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const WindowDesc _build_vehicle_desc = {
|
2007-03-26 12:28:44 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 240, 256,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_BUILD_VEHICLE, WC_NONE,
|
2006-10-10 15:02:38 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
|
|
|
|
_build_vehicle_widgets,
|
2007-01-21 22:50:43 +00:00
|
|
|
NewVehicleWndProc
|
2006-10-10 15:02:38 +00:00
|
|
|
};
|
|
|
|
|
2007-05-18 17:31:41 +00:00
|
|
|
void ShowBuildVehicleWindow(TileIndex tile, VehicleType type)
|
2006-10-10 15:02:38 +00:00
|
|
|
{
|
2006-11-30 16:03:12 +00:00
|
|
|
buildvehicle_d *bv;
|
2006-10-10 15:02:38 +00:00
|
|
|
Window *w;
|
2007-07-13 14:51:55 +00:00
|
|
|
/* We want to be able to open both Available Train as Available Ships,
|
|
|
|
* so if tile == 0 (Available XXX Window), use 'type' as unique number.
|
|
|
|
* As it always is a low value, it won't collide with any real tile
|
|
|
|
* number. */
|
|
|
|
uint num = (tile == 0) ? (int)type : tile;
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2007-01-21 22:50:43 +00:00
|
|
|
assert(IsPlayerBuildableVehicleType(type));
|
|
|
|
|
2007-07-13 14:51:55 +00:00
|
|
|
DeleteWindowById(WC_BUILD_VEHICLE, num);
|
2007-01-21 22:50:43 +00:00
|
|
|
|
2007-07-13 14:51:55 +00:00
|
|
|
w = AllocateWindowDescFront(&_build_vehicle_desc, num);
|
2007-01-21 22:50:43 +00:00
|
|
|
|
2006-10-10 15:02:38 +00:00
|
|
|
if (w == NULL) return;
|
|
|
|
|
2006-12-01 00:14:10 +00:00
|
|
|
w->caption_color = (tile != 0) ? GetTileOwner(tile) : _local_player;
|
2006-11-30 16:03:12 +00:00
|
|
|
w->resize.step_height = GetVehicleListHeight(type);
|
2007-01-21 22:50:43 +00:00
|
|
|
w->vscroll.cap = w->resize.step_height == 24 ? 4 : 8;
|
2006-11-30 16:03:12 +00:00
|
|
|
w->widget[BUILD_VEHICLE_WIDGET_LIST].data = (w->vscroll.cap << 8) + 1;
|
|
|
|
|
|
|
|
bv = &WP(w, buildvehicle_d);
|
|
|
|
EngList_Create(&bv->eng_list);
|
2007-01-21 23:13:46 +00:00
|
|
|
bv->sel_engine = INVALID_ENGINE;
|
2006-11-30 16:03:12 +00:00
|
|
|
|
2007-01-21 23:13:46 +00:00
|
|
|
bv->vehicle_type = type;
|
|
|
|
bv->regenerate_list = false;
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2007-02-07 19:10:19 +00:00
|
|
|
bv->sort_criteria = _last_sort_criteria[type];
|
|
|
|
bv->descending_sort_order = _last_sort_order[type];
|
2007-01-22 01:13:10 +00:00
|
|
|
|
2006-10-10 15:02:38 +00:00
|
|
|
switch (type) {
|
2007-05-18 17:31:41 +00:00
|
|
|
default: NOT_REACHED();
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_TRAIN:
|
2007-04-18 22:10:36 +00:00
|
|
|
WP(w, buildvehicle_d).filter.railtype = (tile == 0) ? RAILTYPE_END : GetRailType(tile);
|
2007-01-21 22:50:43 +00:00
|
|
|
ResizeWindow(w, 0, 16);
|
|
|
|
break;
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_ROAD:
|
2007-05-25 08:13:01 +00:00
|
|
|
WP(w, buildvehicle_d).filter.roadtypes = (tile == 0) ? ROADTYPES_ALL : GetRoadTypes(tile);
|
2007-03-26 12:28:44 +00:00
|
|
|
ResizeWindow(w, 0, 16);
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_SHIP:
|
2007-01-22 00:26:46 +00:00
|
|
|
break;
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_AIRCRAFT:
|
2007-02-15 20:16:33 +00:00
|
|
|
bv->filter.flags =
|
2007-02-16 09:38:43 +00:00
|
|
|
tile == 0 ? AirportFTAClass::ALL : GetStationByTile(tile)->Airport()->flags;
|
2006-11-30 16:03:12 +00:00
|
|
|
break;
|
2006-10-10 15:02:38 +00:00
|
|
|
}
|
2007-01-21 22:50:43 +00:00
|
|
|
SetupWindowStrings(w, type);
|
2007-01-24 14:32:20 +00:00
|
|
|
ResizeButtons(w, BUILD_VEHICLE_WIDGET_BUILD, BUILD_VEHICLE_WIDGET_RENAME);
|
2007-01-21 22:50:43 +00:00
|
|
|
|
|
|
|
w->resize.width = w->width;
|
|
|
|
w->resize.height = w->height;
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2007-01-21 23:13:46 +00:00
|
|
|
GenerateBuildList(w); // generate the list, since we need it in the next line
|
2007-01-21 22:50:43 +00:00
|
|
|
/* Select the first engine in the list as default when opening the window */
|
2006-12-01 00:26:42 +00:00
|
|
|
if (EngList_Count(&bv->eng_list) > 0) bv->sel_engine = bv->eng_list[0];
|
2006-10-10 15:02:38 +00:00
|
|
|
}
|