2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2005-02-05 15:58:59 +00:00
|
|
|
#include "debug.h"
|
2005-07-22 07:02:20 +00:00
|
|
|
#include "functions.h"
|
2006-06-18 15:28:29 +00:00
|
|
|
#include "rail_map.h"
|
2005-06-06 22:44:11 +00:00
|
|
|
#include "table/sprites.h"
|
2004-11-25 10:47:30 +00:00
|
|
|
#include "table/strings.h"
|
2004-12-15 22:18:54 +00:00
|
|
|
#include "map.h"
|
2006-11-30 16:03:12 +00:00
|
|
|
#include "engine.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "window.h"
|
|
|
|
#include "gui.h"
|
|
|
|
#include "gfx.h"
|
|
|
|
#include "vehicle.h"
|
|
|
|
#include "viewport.h"
|
|
|
|
#include "station.h"
|
|
|
|
#include "command.h"
|
|
|
|
#include "player.h"
|
2004-12-10 18:16:08 +00:00
|
|
|
#include "vehicle_gui.h"
|
2005-02-06 10:18:47 +00:00
|
|
|
#include "depot.h"
|
2005-11-18 23:41:03 +00:00
|
|
|
#include "train.h"
|
2006-02-03 12:55:21 +00:00
|
|
|
#include "newgrf_engine.h"
|
2006-08-14 14:21:15 +00:00
|
|
|
#include "date.h"
|
2006-10-07 22:58:25 +00:00
|
|
|
#include "strings.h"
|
2004-11-14 23:36:19 +00:00
|
|
|
|
2006-12-07 13:00:41 +00:00
|
|
|
enum BuildTrainWidgets {
|
2006-10-07 09:02:48 +00:00
|
|
|
BUILD_TRAIN_WIDGET_CLOSEBOX = 0,
|
|
|
|
BUILD_TRAIN_WIDGET_CAPTION,
|
2006-11-30 16:03:12 +00:00
|
|
|
BUILD_TRAIN_WIDGET_SORT_ASCENDING_DESCENDING,
|
2006-10-07 22:58:25 +00:00
|
|
|
BUILD_TRAIN_WIDGET_SORT_TEXT,
|
|
|
|
BUILD_TRAIN_WIDGET_SORT_DROPDOWN,
|
2006-10-07 09:02:48 +00:00
|
|
|
BUILD_TRAIN_WIDGET_LIST,
|
|
|
|
BUILD_TRAIN_WIDGET_SCROLLBAR,
|
|
|
|
BUILD_TRAIN_WIDGET_PANEL,
|
|
|
|
BUILD_TRAIN_WIDGET_BUILD,
|
|
|
|
BUILD_TRAIN_WIDGET_RENAME,
|
|
|
|
BUILD_TRAIN_WIDGET_RESIZE,
|
2006-12-07 13:00:41 +00:00
|
|
|
};
|
2006-10-07 09:02:48 +00:00
|
|
|
|
2006-10-07 13:58:08 +00:00
|
|
|
static const Widget _new_rail_vehicle_widgets[] = {
|
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 227, 0, 13, STR_JUST_STRING, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
2006-10-07 22:58:25 +00:00
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 80, 14, 25, STR_SORT_BY, STR_SORT_ORDER_TIP},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 81, 215, 14, 25, 0x0, STR_SORT_CRITERIA_TIP},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 216, 227, 14, 25, STR_0225, STR_SORT_CRITERIA_TIP},
|
|
|
|
{ WWT_MATRIX, RESIZE_BOTTOM, 14, 0, 215, 26, 137, 0x801, STR_8843_TRAIN_VEHICLE_SELECTION},
|
|
|
|
{ WWT_SCROLLBAR, RESIZE_BOTTOM, 14, 216, 227, 26, 137, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
2006-10-23 21:25:30 +00:00
|
|
|
{ WWT_PANEL, RESIZE_TB, 14, 0, 227, 138, 239, 0x0, STR_NULL},
|
2006-11-30 16:03:12 +00:00
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 107, 240, 251, STR_881F_BUILD_VEHICLE, STR_8844_BUILD_THE_HIGHLIGHTED_TRAIN},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 108, 215, 240, 251, STR_8820_RENAME, STR_8845_RENAME_TRAIN_VEHICLE_TYPE},
|
|
|
|
{ WWT_RESIZEBOX, RESIZE_TB, 14, 216, 227, 240, 251, 0x0, STR_RESIZE_BUTTON},
|
2006-10-07 13:58:08 +00:00
|
|
|
{ WIDGETS_END},
|
|
|
|
};
|
|
|
|
|
2006-11-30 16:03:12 +00:00
|
|
|
static bool _internal_sort_order; // false = ascending, true = descending
|
2006-10-07 22:58:25 +00:00
|
|
|
static byte _last_sort_criteria = 0;
|
|
|
|
static bool _last_sort_order = false;
|
|
|
|
|
2006-11-30 21:37:06 +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;
|
|
|
|
}
|
|
|
|
|
2006-11-30 16:03:12 +00:00
|
|
|
static int CDECL TrainEnginesThenWagonsSorter(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
EngineID va = *(const EngineID*)a;
|
|
|
|
EngineID vb = *(const EngineID*)b;
|
|
|
|
int val_a = ((RailVehInfo(va)->flags & RVI_WAGON) != 0) ? 1 : 0;
|
|
|
|
int val_b = ((RailVehInfo(vb)->flags & RVI_WAGON) != 0) ? 1 : 0;
|
|
|
|
int r = val_a - val_b;
|
2006-10-07 22:58:25 +00:00
|
|
|
|
2006-12-01 00:14:10 +00:00
|
|
|
/* Use EngineID to sort instead since we want consistent sorting */
|
|
|
|
if (r == 0) return TrainEngineNumberSorter(a, b);
|
|
|
|
|
2006-10-07 22:58:25 +00:00
|
|
|
return _internal_sort_order ? -r : r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int CDECL TrainEngineCostSorter(const void *a, const void *b)
|
|
|
|
{
|
2006-12-01 00:14:10 +00:00
|
|
|
int va = RailVehInfo(*(const EngineID*)a)->base_cost;
|
|
|
|
int vb = RailVehInfo(*(const EngineID*)b)->base_cost;
|
2006-10-07 22:58:25 +00:00
|
|
|
int r = va - vb;
|
|
|
|
|
|
|
|
return _internal_sort_order ? -r : r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int CDECL TrainEngineSpeedSorter(const void *a, const void *b)
|
|
|
|
{
|
2006-12-01 00:14:10 +00:00
|
|
|
int va = RailVehInfo(*(const EngineID*)a)->max_speed;
|
|
|
|
int vb = RailVehInfo(*(const EngineID*)b)->max_speed;
|
|
|
|
int r = va - vb;
|
2006-10-07 22:58:25 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2006-12-01 00:14:10 +00:00
|
|
|
int va = rvi_a->power << (rvi_a->flags & RVI_MULTIHEAD ? 1 : 0);
|
|
|
|
int vb = rvi_b->power << (rvi_b->flags & RVI_MULTIHEAD ? 1 : 0);
|
|
|
|
int r = va - vb;
|
2006-10-07 22:58:25 +00:00
|
|
|
|
|
|
|
return _internal_sort_order ? -r : r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int CDECL TrainEngineIntroDateSorter(const void *a, const void *b)
|
|
|
|
{
|
2006-12-01 00:14:10 +00:00
|
|
|
int va = GetEngine(*(const EngineID*)a)->intro_date;
|
|
|
|
int vb = GetEngine(*(const EngineID*)b)->intro_date;
|
|
|
|
int r = va - vb;
|
2006-10-07 22:58:25 +00:00
|
|
|
|
|
|
|
return _internal_sort_order ? -r : r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static EngineID _last_engine; // cached vehicle to hopefully speed up name-sorting
|
|
|
|
|
|
|
|
static char _bufcache[64]; // used together with _last_vehicle to hopefully speed up stringsorting
|
|
|
|
static int CDECL TrainEngineNameSorter(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const EngineID va = *(const EngineID*)a;
|
|
|
|
const EngineID vb = *(const EngineID*)b;
|
2006-10-12 15:38:37 +00:00
|
|
|
char buf1[64];
|
2006-10-07 22:58:25 +00:00
|
|
|
int r;
|
|
|
|
|
2006-10-21 23:31:34 +00:00
|
|
|
GetString(buf1, GetCustomEngineName(va), lastof(buf1));
|
2006-10-07 22:58:25 +00:00
|
|
|
|
|
|
|
if (vb != _last_engine) {
|
|
|
|
_last_engine = vb;
|
|
|
|
_bufcache[0] = '\0';
|
|
|
|
|
2006-10-21 23:31:34 +00:00
|
|
|
GetString(_bufcache, GetCustomEngineName(vb), lastof(_bufcache));
|
2006-10-07 22:58:25 +00:00
|
|
|
}
|
|
|
|
|
2006-10-12 15:39:33 +00:00
|
|
|
r = strcasecmp(buf1, _bufcache); // sort by name
|
2006-10-07 22:58:25 +00:00
|
|
|
|
2006-10-12 15:39:33 +00:00
|
|
|
return _internal_sort_order ? -r : r;
|
2006-10-07 22:58:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2006-12-01 00:14:10 +00:00
|
|
|
int va = rvi_a->running_cost_base * _price.running_rail[rvi_a->running_cost_class] * (rvi_a->flags & RVI_MULTIHEAD ? 2 : 1);
|
|
|
|
int vb = rvi_b->running_cost_base * _price.running_rail[rvi_b->running_cost_class] * (rvi_b->flags & RVI_MULTIHEAD ? 2 : 1);
|
|
|
|
int r = va - vb;
|
2006-10-07 22:58:25 +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. */
|
2006-12-01 00:14:10 +00:00
|
|
|
int va = (rvi_a->running_cost_base * _price.running_rail[rvi_a->running_cost_class]) / max(1, rvi_a->power);
|
|
|
|
int vb = (rvi_b->running_cost_base * _price.running_rail[rvi_b->running_cost_class]) / max(1, rvi_b->power);
|
|
|
|
int r = vb - va;
|
2006-10-07 22:58:25 +00:00
|
|
|
|
|
|
|
return _internal_sort_order ? -r : r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int CDECL TrainEngineReliabilitySorter(const void *a, const void *b)
|
|
|
|
{
|
2006-12-01 00:14:10 +00:00
|
|
|
int va = GetEngine(*(const EngineID*)a)->reliability;
|
|
|
|
int vb = GetEngine(*(const EngineID*)b)->reliability;
|
|
|
|
int r = va - vb;
|
2006-10-07 22:58:25 +00:00
|
|
|
|
|
|
|
return _internal_sort_order ? -r : r;
|
|
|
|
}
|
|
|
|
|
2006-11-30 16:03:12 +00:00
|
|
|
static EngList_SortTypeFunction * const _engine_sorter[] = {
|
2006-10-07 22:58:25 +00:00
|
|
|
&TrainEngineNumberSorter,
|
|
|
|
&TrainEngineCostSorter,
|
|
|
|
&TrainEngineSpeedSorter,
|
|
|
|
&TrainEnginePowerSorter,
|
|
|
|
&TrainEngineIntroDateSorter,
|
|
|
|
&TrainEngineNameSorter,
|
|
|
|
&TrainEngineRunningCostSorter,
|
|
|
|
&TrainEnginePowerVsRunningCostSorter,
|
|
|
|
&TrainEngineReliabilitySorter,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const StringID _engine_sort_listing[] = {
|
|
|
|
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,
|
|
|
|
INVALID_STRING_ID
|
|
|
|
};
|
2006-10-07 09:02:48 +00:00
|
|
|
|
2005-06-05 23:01:10 +00:00
|
|
|
/**
|
|
|
|
* Draw the purchase info details of train engine at a given location.
|
|
|
|
* @param x,y location where to draw the info
|
|
|
|
* @param engine_number the engine of which to draw the info of
|
|
|
|
*/
|
2006-10-23 18:45:43 +00:00
|
|
|
void DrawTrainEnginePurchaseInfo(int x, int y, uint w, EngineID engine_number)
|
2005-01-02 17:23:04 +00:00
|
|
|
{
|
|
|
|
const RailVehicleInfo *rvi = RailVehInfo(engine_number);
|
2006-07-26 03:33:12 +00:00
|
|
|
const Engine *e = GetEngine(engine_number);
|
2005-01-02 17:23:04 +00:00
|
|
|
int multihead = (rvi->flags&RVI_MULTIHEAD?1:0);
|
|
|
|
YearMonthDay ymd;
|
2006-08-15 16:49:48 +00:00
|
|
|
ConvertDateToYMD(e->intro_date, &ymd);
|
2005-01-02 17:23:04 +00:00
|
|
|
|
2005-06-05 23:01:10 +00:00
|
|
|
/* Purchase Cost - Engine weight */
|
2005-01-02 17:23:04 +00:00
|
|
|
SetDParam(0, rvi->base_cost * (_price.build_railvehicle >> 3) >> 5);
|
|
|
|
SetDParam(1, rvi->weight << multihead);
|
2005-06-05 23:01:10 +00:00
|
|
|
DrawString(x,y, STR_PURCHASE_INFO_COST_WEIGHT, 0);
|
|
|
|
y += 10;
|
|
|
|
|
|
|
|
/* Max speed - Engine power */
|
2006-04-08 12:04:23 +00:00
|
|
|
SetDParam(0, rvi->max_speed);
|
2005-06-05 23:01:10 +00:00
|
|
|
SetDParam(1, rvi->power << multihead);
|
|
|
|
DrawString(x,y, STR_PURCHASE_INFO_SPEED_POWER, 0);
|
|
|
|
y += 10;
|
|
|
|
|
|
|
|
/* Running cost */
|
2006-01-07 16:47:59 +00:00
|
|
|
SetDParam(0, (rvi->running_cost_base * _price.running_rail[rvi->running_cost_class] >> 8) << multihead);
|
2005-06-05 23:01:10 +00:00
|
|
|
DrawString(x,y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
|
|
|
|
y += 10;
|
|
|
|
|
2005-06-06 00:19:24 +00:00
|
|
|
/* 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);
|
|
|
|
DrawString(x,y, STR_PURCHASE_INFO_PWAGPOWER_PWAGWEIGHT, 0);
|
|
|
|
y += 10;
|
|
|
|
};
|
|
|
|
|
2005-06-05 23:01:10 +00:00
|
|
|
/* Cargo type + capacity, or N/A */
|
2006-10-20 19:48:25 +00:00
|
|
|
if (rvi->capacity == 0) {
|
|
|
|
SetDParam(0, CT_INVALID);
|
|
|
|
SetDParam(2, STR_EMPTY);
|
|
|
|
} else {
|
2006-10-20 11:53:29 +00:00
|
|
|
SetDParam(0, rvi->cargo_type);
|
2006-10-05 11:26:59 +00:00
|
|
|
SetDParam(1, (rvi->capacity * (CountArticulatedParts(engine_number) + 1)) << multihead);
|
2005-06-05 23:01:10 +00:00
|
|
|
SetDParam(2, STR_9842_REFITTABLE);
|
2005-01-02 17:23:04 +00:00
|
|
|
}
|
2005-06-05 23:01:10 +00:00
|
|
|
DrawString(x,y, STR_PURCHASE_INFO_CAPACITY, 0);
|
|
|
|
y += 10;
|
|
|
|
|
|
|
|
/* Design date - Life length */
|
2006-08-16 11:39:55 +00:00
|
|
|
SetDParam(0, ymd.year);
|
2005-06-05 23:01:10 +00:00
|
|
|
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-04-23 22:35:37 +00:00
|
|
|
|
|
|
|
/* Additional text from NewGRF */
|
2006-10-23 18:45:43 +00:00
|
|
|
y += ShowAdditionalText(x, y, w, engine_number);
|
2006-10-24 07:10:37 +00:00
|
|
|
if (rvi->capacity > 0) y += ShowRefitOptionsList(x, y, w, engine_number);
|
2005-01-02 17:23:04 +00:00
|
|
|
}
|
|
|
|
|
2005-06-05 23:01:10 +00:00
|
|
|
/**
|
|
|
|
* Draw the purchase info details of a train wagon at a given location.
|
|
|
|
* @param x,y location where to draw the info
|
|
|
|
* @param engine_number the engine of which to draw the info of
|
|
|
|
*/
|
2006-10-23 18:45:43 +00:00
|
|
|
void DrawTrainWagonPurchaseInfo(int x, int y, uint w, EngineID engine_number)
|
2005-01-02 17:23:04 +00:00
|
|
|
{
|
|
|
|
const RailVehicleInfo *rvi = RailVehInfo(engine_number);
|
2006-03-31 12:59:43 +00:00
|
|
|
bool refittable = (EngInfo(engine_number)->refit_mask != 0);
|
2005-06-05 23:01:10 +00:00
|
|
|
|
|
|
|
/* Purchase cost */
|
|
|
|
SetDParam(0, (rvi->base_cost * _price.build_railwagon) >> 8);
|
|
|
|
DrawString(x, y, STR_PURCHASE_INFO_COST, 0);
|
|
|
|
y += 10;
|
|
|
|
|
|
|
|
/* Wagon weight - (including cargo) */
|
|
|
|
SetDParam(0, rvi->weight);
|
|
|
|
SetDParam(1, (_cargoc.weights[rvi->cargo_type] * rvi->capacity >> 4) + rvi->weight);
|
|
|
|
DrawString(x, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT, 0);
|
|
|
|
y += 10;
|
|
|
|
|
2006-04-28 19:56:18 +00:00
|
|
|
/* Cargo type + capacity, or N/A */
|
2006-10-20 19:48:25 +00:00
|
|
|
if (rvi->capacity == 0) {
|
|
|
|
SetDParam(0, CT_INVALID);
|
|
|
|
SetDParam(2, STR_EMPTY);
|
|
|
|
} else {
|
2006-10-20 11:53:29 +00:00
|
|
|
SetDParam(0, rvi->cargo_type);
|
2006-10-05 11:26:59 +00:00
|
|
|
SetDParam(1, rvi->capacity * (CountArticulatedParts(engine_number) + 1));
|
2006-04-28 19:56:18 +00:00
|
|
|
SetDParam(2, refittable ? STR_9842_REFITTABLE : STR_EMPTY);
|
|
|
|
}
|
2005-06-05 23:01:10 +00:00
|
|
|
DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0);
|
|
|
|
y += 10;
|
2005-09-22 10:31:09 +00:00
|
|
|
|
|
|
|
/* Wagon speed limit, displayed if above zero */
|
2005-09-24 13:56:39 +00:00
|
|
|
if (rvi->max_speed > 0 && _patches.wagon_speed_limits) {
|
2006-04-08 12:04:23 +00:00
|
|
|
SetDParam(0, rvi->max_speed);
|
2005-09-22 10:31:09 +00:00
|
|
|
DrawString(x,y, STR_PURCHASE_INFO_SPEED, 0);
|
|
|
|
y += 10;
|
|
|
|
}
|
2006-04-23 22:35:37 +00:00
|
|
|
|
|
|
|
/* Additional text from NewGRF */
|
2006-10-23 18:45:43 +00:00
|
|
|
y += ShowAdditionalText(x, y, w, engine_number);
|
2006-10-23 21:39:15 +00:00
|
|
|
y += ShowRefitOptionsList(x, y, w, engine_number);
|
2005-01-02 17:23:04 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
void CcBuildWagon(bool success, TileIndex tile, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-07-26 03:33:12 +00:00
|
|
|
Vehicle *v, *found;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-06-27 21:25:53 +00:00
|
|
|
if (!success) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// find a locomotive in the depot.
|
|
|
|
found = NULL;
|
|
|
|
FOR_ALL_VEHICLES(v) {
|
2005-11-18 23:41:03 +00:00
|
|
|
if (v->type == VEH_Train && IsFrontEngine(v) &&
|
2004-08-09 17:04:08 +00:00
|
|
|
v->tile == tile &&
|
|
|
|
v->u.rail.track == 0x80) {
|
2006-06-27 21:25:53 +00:00
|
|
|
if (found != NULL) return; // must be exactly one.
|
2004-08-09 17:04:08 +00:00
|
|
|
found = v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we found a loco,
|
|
|
|
if (found != NULL) {
|
|
|
|
found = GetLastVehicleInChain(found);
|
|
|
|
// put the new wagon at the end of the loco.
|
2006-06-04 09:28:33 +00:00
|
|
|
DoCommandP(0, _new_vehicle_id | (found->index << 16), 0, NULL, CMD_MOVE_RAIL_VEHICLE);
|
2004-12-10 18:16:08 +00:00
|
|
|
RebuildVehicleLists();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
void CcBuildLoco(bool success, TileIndex tile, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-07-26 03:33:12 +00:00
|
|
|
const Vehicle *v;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (!success) return;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2006-06-04 09:28:33 +00:00
|
|
|
v = GetVehicle(_new_vehicle_id);
|
2004-08-09 17:04:08 +00:00
|
|
|
if (tile == _backup_orders_tile) {
|
|
|
|
_backup_orders_tile = 0;
|
|
|
|
RestoreVehicleOrders(v, _backup_orders_data);
|
|
|
|
}
|
|
|
|
ShowTrainViewWindow(v);
|
|
|
|
}
|
|
|
|
|
2006-05-21 16:18:58 +00:00
|
|
|
void CcCloneTrain(bool success, TileIndex tile, uint32 p1, uint32 p2)
|
2005-07-31 13:08:08 +00:00
|
|
|
{
|
2006-06-04 09:28:33 +00:00
|
|
|
if (success) ShowTrainViewWindow(GetVehicle(_new_vehicle_id));
|
2005-07-31 13:08:08 +00:00
|
|
|
}
|
2006-10-07 13:58:08 +00:00
|
|
|
|
2006-11-30 16:03:12 +00:00
|
|
|
static void engine_drawing_loop(const EngineList *engines, int x, int *y, EngineID sel, EngineID position, int16 show_max)
|
2006-10-07 13:58:08 +00:00
|
|
|
{
|
2006-11-30 16:03:12 +00:00
|
|
|
int count = min(EngList_Count(engines), show_max);
|
|
|
|
for (; position < count; *y += 14, position++) {
|
|
|
|
EngineID id = (*engines)[position];
|
|
|
|
DrawString(x + 59, *y + 2, GetCustomEngineName(id), sel == id ? 0xC : 0x10);
|
|
|
|
DrawTrainEngine(x + 29, *y + 6, id, GetEnginePalette(id, _local_player));
|
|
|
|
}
|
2006-10-07 13:58:08 +00:00
|
|
|
}
|
2005-07-31 13:08:08 +00:00
|
|
|
|
2006-11-30 16:03:12 +00:00
|
|
|
static void GenerateBuildList(Window *w)
|
2004-11-29 19:26:24 +00:00
|
|
|
{
|
2006-12-01 00:26:42 +00:00
|
|
|
EngineID eid, sel_id;
|
2006-11-30 16:03:12 +00:00
|
|
|
int num_engines = 0;
|
2006-11-30 18:16:08 +00:00
|
|
|
int num_wagons = 0;
|
2006-11-30 16:03:12 +00:00
|
|
|
buildvehicle_d *bv = &WP(w, buildvehicle_d);
|
2004-11-29 19:26:24 +00:00
|
|
|
|
2006-12-01 00:14:10 +00:00
|
|
|
bv->filter.railtype = (w->window_number == 0) ? RAILTYPE_END : GetRailType(w->window_number);
|
2006-10-07 13:58:08 +00:00
|
|
|
|
2006-11-30 16:03:12 +00:00
|
|
|
EngList_RemoveAll(&bv->eng_list);
|
2006-12-01 00:14:10 +00:00
|
|
|
|
2006-12-01 00:26:42 +00:00
|
|
|
/* Make list of all available train engines and wagons.
|
|
|
|
* 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 */
|
|
|
|
for (sel_id = INVALID_ENGINE, eid = 0; eid < NUM_TRAIN_ENGINES; eid++) {
|
2006-12-01 00:14:10 +00:00
|
|
|
const Engine *e = GetEngine(eid);
|
|
|
|
const RailVehicleInfo *rvi = RailVehInfo(eid);
|
2004-11-29 19:26:24 +00:00
|
|
|
|
2006-11-30 16:03:12 +00:00
|
|
|
if (bv->filter.railtype != RAILTYPE_END && !HasPowerOnRail(e->railtype, bv->filter.railtype)) continue;
|
2006-12-03 15:48:21 +00:00
|
|
|
if (!IsEngineBuildable(eid, VEH_Train, _local_player)) continue;
|
2006-10-07 13:58:08 +00:00
|
|
|
|
2006-12-01 00:14:10 +00:00
|
|
|
EngList_Add(&bv->eng_list, eid);
|
2006-11-30 18:16:08 +00:00
|
|
|
if ((rvi->flags & RVI_WAGON) == 0) {
|
|
|
|
num_engines++;
|
|
|
|
} else {
|
|
|
|
num_wagons++;
|
|
|
|
}
|
2006-12-01 00:26:42 +00:00
|
|
|
|
|
|
|
if (eid == bv->sel_engine) sel_id = eid;
|
2006-10-07 13:58:08 +00:00
|
|
|
}
|
2006-11-30 18:16:08 +00:00
|
|
|
|
2006-12-01 00:26:42 +00:00
|
|
|
bv->sel_engine = sel_id;
|
|
|
|
|
2006-11-30 21:37:06 +00:00
|
|
|
// make engines first, and then wagons, sorted by ListPositionOfEngine()
|
2006-11-30 16:03:12 +00:00
|
|
|
_internal_sort_order = false;
|
|
|
|
EngList_Sort(&bv->eng_list, TrainEnginesThenWagonsSorter);
|
2006-11-30 18:16:08 +00:00
|
|
|
|
2006-11-30 16:03:12 +00:00
|
|
|
// and then sort engines
|
2006-12-01 00:14:10 +00:00
|
|
|
_internal_sort_order = bv->descending_sort_order;
|
2006-11-30 16:03:12 +00:00
|
|
|
EngList_SortPartial(&bv->eng_list, _engine_sorter[bv->sort_criteria], 0, num_engines);
|
2006-11-30 18:16:08 +00:00
|
|
|
|
|
|
|
// and finally sort wagons
|
|
|
|
EngList_SortPartial(&bv->eng_list, _engine_sorter[bv->sort_criteria], num_engines, num_wagons);
|
2006-10-07 22:58:25 +00:00
|
|
|
}
|
|
|
|
|
2006-10-07 13:58:08 +00:00
|
|
|
static void DrawTrainBuildWindow(Window *w)
|
|
|
|
{
|
2006-12-01 00:14:10 +00:00
|
|
|
const buildvehicle_d *bv = &WP(w, buildvehicle_d);
|
2006-10-07 13:58:08 +00:00
|
|
|
int x = 1;
|
2006-10-07 22:58:25 +00:00
|
|
|
int y = 27;
|
2006-11-30 16:03:12 +00:00
|
|
|
EngineID selected_id = bv->sel_engine;
|
2006-10-07 13:58:08 +00:00
|
|
|
int max = w->vscroll.pos + w->vscroll.cap;
|
|
|
|
|
|
|
|
SetWindowWidgetDisabledState(w, BUILD_TRAIN_WIDGET_BUILD, w->window_number == 0); // Disable unless we got a depot to build in
|
2006-11-30 16:03:12 +00:00
|
|
|
|
2006-12-01 00:26:42 +00:00
|
|
|
SetVScrollCount(w, EngList_Count(&bv->eng_list));
|
2006-11-30 16:03:12 +00:00
|
|
|
SetDParam(0, bv->filter.railtype + STR_881C_NEW_RAIL_VEHICLES);
|
2006-10-07 13:58:08 +00:00
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
|
|
|
/* Draw the engines */
|
2006-11-30 16:03:12 +00:00
|
|
|
engine_drawing_loop(&bv->eng_list, x, &y, selected_id, w->vscroll.pos, max);
|
2006-10-07 13:58:08 +00:00
|
|
|
|
|
|
|
if (selected_id != INVALID_ENGINE) {
|
|
|
|
const RailVehicleInfo *rvi = RailVehInfo(selected_id);
|
2006-10-23 18:45:43 +00:00
|
|
|
const Widget *wi = &w->widget[BUILD_TRAIN_WIDGET_PANEL];
|
2006-10-07 13:58:08 +00:00
|
|
|
|
|
|
|
if (rvi->flags & RVI_WAGON) {
|
2006-10-23 18:45:43 +00:00
|
|
|
DrawTrainWagonPurchaseInfo(2, wi->top + 1, wi->right - wi->left - 2, selected_id);
|
2006-10-07 13:58:08 +00:00
|
|
|
} else {
|
2006-10-23 18:45:43 +00:00
|
|
|
DrawTrainEnginePurchaseInfo(2, wi->top + 1, wi->right - wi->left - 2, selected_id);
|
2004-11-29 19:26:24 +00:00
|
|
|
}
|
|
|
|
}
|
2006-11-30 16:03:12 +00:00
|
|
|
DrawString(85, 15, _engine_sort_listing[bv->sort_criteria], 0x10);
|
|
|
|
DoDrawString(bv->descending_sort_order ? DOWNARROW : UPARROW, 69, 15, 0x10);
|
2004-11-29 19:26:24 +00:00
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
static void NewRailVehicleWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2006-12-01 00:14:10 +00:00
|
|
|
buildvehicle_d *bv = &WP(w, buildvehicle_d);
|
2006-02-01 07:36:15 +00:00
|
|
|
switch (e->event) {
|
2006-10-07 13:58:08 +00:00
|
|
|
case WE_CREATE:
|
2006-11-30 16:03:12 +00:00
|
|
|
EngList_Create(&bv->eng_list);
|
|
|
|
bv->sel_engine = INVALID_ENGINE;
|
|
|
|
bv->sort_criteria = _last_sort_criteria;
|
|
|
|
bv->descending_sort_order = _last_sort_order;
|
2006-11-30 18:23:25 +00:00
|
|
|
GenerateBuildList(w);
|
2006-12-01 00:26:42 +00:00
|
|
|
/* Select the first engine in the list as default when opening the window */
|
|
|
|
if (EngList_Count(&bv->eng_list) > 0) bv->sel_engine = bv->eng_list[0];
|
2006-10-07 14:30:13 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_INVALIDATE_DATA:
|
2006-11-30 18:23:25 +00:00
|
|
|
GenerateBuildList(w);
|
2006-10-07 13:58:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_DESTROY:
|
2006-11-30 16:03:12 +00:00
|
|
|
EngList_Destroy(&bv->eng_list);
|
2006-10-07 13:58:08 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-07 13:58:08 +00:00
|
|
|
case WE_PAINT:
|
|
|
|
DrawTrainBuildWindow(w);
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-07 09:02:48 +00:00
|
|
|
case WE_CLICK: {
|
|
|
|
switch (e->we.click.widget) {
|
2006-11-30 16:03:12 +00:00
|
|
|
case BUILD_TRAIN_WIDGET_SORT_ASCENDING_DESCENDING:
|
2006-12-01 00:14:10 +00:00
|
|
|
bv->descending_sort_order ^= true;
|
|
|
|
_last_sort_order = bv->descending_sort_order;
|
2006-11-30 18:23:25 +00:00
|
|
|
GenerateBuildList(w);
|
2006-10-07 22:58:25 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BUILD_TRAIN_WIDGET_SORT_TEXT: case BUILD_TRAIN_WIDGET_SORT_DROPDOWN:/* Select sorting criteria dropdown menu */
|
2006-11-30 16:03:12 +00:00
|
|
|
ShowDropDownMenu(w, _engine_sort_listing, bv->sort_criteria, BUILD_TRAIN_WIDGET_SORT_DROPDOWN, 0, 0);
|
2006-10-07 22:58:25 +00:00
|
|
|
return;
|
|
|
|
|
2006-10-07 09:02:48 +00:00
|
|
|
case BUILD_TRAIN_WIDGET_LIST: {
|
2006-10-07 22:58:25 +00:00
|
|
|
uint i = ((e->we.click.pt.y - 26) / 14) + w->vscroll.pos;
|
2006-11-30 16:03:12 +00:00
|
|
|
uint num_items = EngList_Count(&bv->eng_list);
|
|
|
|
bv->sel_engine = (i < num_items) ? bv->eng_list[i] : INVALID_ENGINE;
|
2006-10-07 13:58:08 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
2006-11-30 16:03:12 +00:00
|
|
|
}
|
2006-10-07 13:58:08 +00:00
|
|
|
|
2006-10-07 09:02:48 +00:00
|
|
|
case BUILD_TRAIN_WIDGET_BUILD: {
|
2006-11-30 16:03:12 +00:00
|
|
|
EngineID sel_eng = bv->sel_engine;
|
2006-10-07 09:02:48 +00:00
|
|
|
if (sel_eng != INVALID_ENGINE)
|
|
|
|
DoCommandP(w->window_number, sel_eng, 0, (RailVehInfo(sel_eng)->flags & RVI_WAGON) ? CcBuildWagon : CcBuildLoco, CMD_BUILD_RAIL_VEHICLE | CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE));
|
2006-11-30 16:03:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-10-07 09:02:48 +00:00
|
|
|
|
|
|
|
case BUILD_TRAIN_WIDGET_RENAME: {
|
2006-11-30 16:03:12 +00:00
|
|
|
EngineID sel_eng = bv->sel_engine;
|
2006-10-07 09:02:48 +00:00
|
|
|
if (sel_eng != INVALID_ENGINE) {
|
2006-11-30 16:03:12 +00:00
|
|
|
bv->rename_engine = sel_eng;
|
|
|
|
ShowQueryString(GetCustomEngineName(sel_eng), STR_886A_RENAME_TRAIN_VEHICLE_TYPE, 31, 160, w->window_class, w->window_number, CS_ALPHANUMERAL);
|
2006-10-07 09:02:48 +00:00
|
|
|
}
|
2006-11-30 16:03:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2006-11-30 16:03:12 +00:00
|
|
|
}
|
|
|
|
break;
|
2006-10-07 09:02:48 +00:00
|
|
|
|
|
|
|
case WE_ON_EDIT_TEXT: {
|
|
|
|
if (e->we.edittext.str[0] != '\0') {
|
|
|
|
_cmd_text = e->we.edittext.str;
|
2006-11-30 16:03:12 +00:00
|
|
|
DoCommandP(0, bv->rename_engine, 0, NULL, CMD_RENAME_ENGINE | CMD_MSG(STR_886B_CAN_T_RENAME_TRAIN_VEHICLE));
|
2005-01-10 14:24:40 +00:00
|
|
|
}
|
2006-11-30 16:03:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2006-10-07 22:58:25 +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) {
|
2006-12-01 00:14:10 +00:00
|
|
|
bv->sort_criteria = _last_sort_criteria = e->we.dropdown.index;
|
2006-11-30 18:23:25 +00:00
|
|
|
GenerateBuildList(w);
|
|
|
|
SetWindowDirty(w);
|
2006-10-07 22:58:25 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2006-10-07 09:02:48 +00:00
|
|
|
case WE_RESIZE: {
|
|
|
|
if (e->we.sizing.diff.y == 0) break;
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2006-10-07 09:02:48 +00:00
|
|
|
w->vscroll.cap += e->we.sizing.diff.y / 14;
|
|
|
|
w->widget[BUILD_TRAIN_WIDGET_LIST].data = (w->vscroll.cap << 8) + 1;
|
2006-11-30 16:03:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
static const WindowDesc _new_rail_vehicle_desc = {
|
2006-11-30 16:03:12 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 228, 252,
|
2004-08-09 17:04:08 +00:00
|
|
|
WC_BUILD_VEHICLE,0,
|
2005-01-03 19:45:18 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
|
2004-08-09 17:04:08 +00:00
|
|
|
_new_rail_vehicle_widgets,
|
|
|
|
NewRailVehicleWndProc
|
|
|
|
};
|
|
|
|
|
2006-08-29 17:41:13 +00:00
|
|
|
void ShowBuildTrainWindow(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
|
|
|
|
DeleteWindowById(WC_BUILD_VEHICLE, tile);
|
|
|
|
|
2006-11-18 16:47:02 +00:00
|
|
|
w = AllocateWindowDescFront(&_new_rail_vehicle_desc, tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
w->vscroll.cap = 8;
|
2006-10-07 09:02:48 +00:00
|
|
|
w->widget[BUILD_TRAIN_WIDGET_LIST].data = (w->vscroll.cap << 8) + 1;
|
2005-01-03 19:45:18 +00:00
|
|
|
|
|
|
|
w->resize.step_height = 14;
|
2006-06-10 08:37:41 +00:00
|
|
|
w->resize.height = w->height - 14 * 4; // Minimum of 4 vehicles in the display
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (tile != 0) {
|
2005-06-04 11:56:32 +00:00
|
|
|
w->caption_color = GetTileOwner(tile);
|
2006-11-30 16:03:12 +00:00
|
|
|
WP(w,buildvehicle_d).filter.railtype = GetRailType(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
|
|
|
w->caption_color = _local_player;
|
2006-11-30 16:03:12 +00:00
|
|
|
WP(w,buildvehicle_d).filter.railtype = RAILTYPE_END;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-04 07:38:26 +00:00
|
|
|
/**
|
|
|
|
* Get the number of pixels for the given wagon length.
|
|
|
|
* @param len Length measured in 1/8ths of a standard wagon.
|
|
|
|
* @return Number of pixels across.
|
|
|
|
*/
|
2006-09-26 16:47:51 +00:00
|
|
|
int WagonLengthToPixels(int len) {
|
2006-05-14 20:58:12 +00:00
|
|
|
return (len * _traininfo_vehicle_width) / 8;
|
2005-11-04 07:38:26 +00:00
|
|
|
}
|
|
|
|
|
2006-08-29 17:41:13 +00:00
|
|
|
void DrawTrainImage(const Vehicle *v, int x, int y, int count, int skip, VehicleID selection)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-05-30 21:19:46 +00:00
|
|
|
DrawPixelInfo tmp_dpi, *old_dpi;
|
|
|
|
int dx = -(skip * 8) / _traininfo_vehicle_width;
|
2006-06-20 07:07:28 +00:00
|
|
|
/* Position of highlight box */
|
|
|
|
int highlight_l = 0;
|
|
|
|
int highlight_r = 0;
|
2006-05-30 21:19:46 +00:00
|
|
|
|
2006-08-28 07:33:51 +00:00
|
|
|
if (!FillDrawPixelInfo(&tmp_dpi, x - 2, y - 1, count + 1, 14)) return;
|
2006-05-30 21:19:46 +00:00
|
|
|
|
|
|
|
count = (count * 8) / _traininfo_vehicle_width;
|
|
|
|
|
|
|
|
old_dpi = _cur_dpi;
|
|
|
|
_cur_dpi = &tmp_dpi;
|
2005-06-06 22:44:11 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
do {
|
2006-05-30 21:19:46 +00:00
|
|
|
int width = v->u.rail.cached_veh_length;
|
2005-06-06 22:44:11 +00:00
|
|
|
|
2006-05-30 21:19:46 +00:00
|
|
|
if (dx + width > 0) {
|
|
|
|
if (dx <= count) {
|
2006-02-20 21:49:31 +00:00
|
|
|
PalSpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
|
2006-06-20 07:07:28 +00:00
|
|
|
DrawSprite(GetTrainImage(v, DIR_W) | pal, 16 + WagonLengthToPixels(dx), 7 + (is_custom_sprite(RailVehInfo(v->engine_type)->image_index) ? _traininfo_vehicle_pitch : 0));
|
|
|
|
if (v->index == selection) {
|
|
|
|
/* Set the highlight position */
|
|
|
|
highlight_l = WagonLengthToPixels(dx) + 1;
|
|
|
|
highlight_r = WagonLengthToPixels(dx + width) + 1;
|
|
|
|
}
|
2005-06-06 22:44:11 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2006-05-30 21:19:46 +00:00
|
|
|
dx += width;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-11-04 07:38:26 +00:00
|
|
|
v = v->next;
|
2006-05-30 21:19:46 +00:00
|
|
|
} while (dx < count && v != NULL);
|
|
|
|
|
2006-06-20 07:07:28 +00:00
|
|
|
if (highlight_l != highlight_r) {
|
|
|
|
/* Draw the highlight. Now done after drawing all the engines, as
|
|
|
|
* the next engine after the highlight could overlap it. */
|
|
|
|
DrawFrameRect(highlight_l, 0, highlight_r, 13, 15, FR_BORDERONLY);
|
|
|
|
}
|
|
|
|
|
2006-05-30 21:19:46 +00:00
|
|
|
_cur_dpi = old_dpi;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-08-03 13:07:29 +00:00
|
|
|
static const Widget _train_view_widgets[] = {
|
2006-10-24 13:20:54 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW },
|
|
|
|
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 237, 0, 13, STR_882E, STR_018C_WINDOW_TITLE_DRAG_THIS },
|
|
|
|
{ WWT_STICKYBOX, RESIZE_LR, 14, 238, 249, 0, 13, 0x0, STR_STICKY_BUTTON },
|
|
|
|
{ WWT_PANEL, RESIZE_RB, 14, 0, 231, 14, 121, 0x0, STR_NULL },
|
2006-10-24 16:27:18 +00:00
|
|
|
{ WWT_INSET, RESIZE_RB, 14, 2, 229, 16, 119, 0x0, STR_NULL },
|
2006-10-24 14:15:17 +00:00
|
|
|
{ WWT_PUSHBTN, RESIZE_RTB, 14, 0, 237, 122, 133, 0x0, STR_8846_CURRENT_TRAIN_ACTION_CLICK },
|
2006-10-24 13:20:54 +00:00
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 14, 31, SPR_CENTRE_VIEW_VEHICLE, STR_8848_CENTER_MAIN_VIEW_ON_TRAIN },
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 32, 49, SPR_SEND_TRAIN_TODEPOT, STR_8849_SEND_TRAIN_TO_DEPOT },
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 50, 67, SPR_IGNORE_SIGNALS, STR_884A_FORCE_TRAIN_TO_PROCEED },
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 68, 85, SPR_FORCE_VEHICLE_TURN, STR_884B_REVERSE_DIRECTION_OF_TRAIN },
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 86, 103, SPR_SHOW_ORDERS, STR_8847_SHOW_TRAIN_S_ORDERS },
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 104, 121, SPR_SHOW_VEHICLE_DETAILS,STR_884C_SHOW_TRAIN_DETAILS },
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 68, 85, SPR_REFIT_VEHICLE, STR_RAIL_REFIT_VEHICLE_TO_CARRY },
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 32, 49, SPR_CLONE_TRAIN, STR_CLONE_TRAIN_INFO },
|
|
|
|
{ WWT_PANEL, RESIZE_LRB, 14, 232, 249, 122, 121, 0x0, STR_NULL },
|
|
|
|
{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 238, 249, 122, 133, 0x0, STR_NULL },
|
2005-03-11 13:17:39 +00:00
|
|
|
{ WIDGETS_END }
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2006-07-26 03:33:12 +00:00
|
|
|
static void ShowTrainDetailsWindow(const Vehicle *v);
|
2005-10-28 20:04:54 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
static void TrainViewWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2005-05-14 12:36:16 +00:00
|
|
|
switch (e->event) {
|
2004-08-09 17:04:08 +00:00
|
|
|
case WE_PAINT: {
|
2005-05-14 12:36:16 +00:00
|
|
|
const Vehicle *v, *u;
|
2004-08-09 17:04:08 +00:00
|
|
|
StringID str;
|
2006-10-03 02:08:15 +00:00
|
|
|
bool is_localplayer;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-06 22:31:58 +00:00
|
|
|
v = GetVehicle(w->window_number);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2006-10-03 02:08:15 +00:00
|
|
|
is_localplayer = v->owner == _local_player;
|
|
|
|
SetWindowWidgetDisabledState(w, 7, !is_localplayer);
|
|
|
|
SetWindowWidgetDisabledState(w, 8, !is_localplayer);
|
|
|
|
SetWindowWidgetDisabledState(w, 9, !is_localplayer);
|
|
|
|
SetWindowWidgetDisabledState(w, 13, !is_localplayer);
|
2005-02-20 07:47:42 +00:00
|
|
|
|
2006-10-17 17:10:39 +00:00
|
|
|
/* Disable cargo refit button, until we know we can enable it below. */
|
|
|
|
DisableWindowWidget(w, 12);
|
|
|
|
|
2006-10-03 02:08:15 +00:00
|
|
|
if (is_localplayer) {
|
2006-01-21 22:09:25 +00:00
|
|
|
/* See if any vehicle can be refitted */
|
|
|
|
for (u = v; u != NULL; u = u->next) {
|
2006-03-31 12:59:43 +00:00
|
|
|
if (EngInfo(u->engine_type)->refit_mask != 0 ||
|
2006-01-21 22:09:25 +00:00
|
|
|
(!(RailVehInfo(v->engine_type)->flags & RVI_WAGON) && v->cargo_cap != 0)) {
|
2006-10-03 02:08:15 +00:00
|
|
|
EnableWindowWidget(w, 12);
|
2006-01-21 22:09:25 +00:00
|
|
|
/* We have a refittable carriage, bail out */
|
|
|
|
break;
|
|
|
|
}
|
2005-02-20 07:47:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
/* draw widgets & caption */
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, v->string_id);
|
2005-08-01 16:31:19 +00:00
|
|
|
SetDParam(1, v->unitnumber);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
|
|
|
if (v->u.rail.crash_anim_pos != 0) {
|
|
|
|
str = STR_8863_CRASHED;
|
|
|
|
} else if (v->breakdown_ctr == 1) {
|
|
|
|
str = STR_885C_BROKEN_DOWN;
|
|
|
|
} else if (v->vehstatus & VS_STOPPED) {
|
|
|
|
if (v->u.rail.last_speed == 0) {
|
2006-08-12 10:41:29 +00:00
|
|
|
if (v->u.rail.cached_power == 0) {
|
|
|
|
str = STR_TRAIN_NO_POWER;
|
|
|
|
} else {
|
|
|
|
str = STR_8861_STOPPED;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2006-04-08 12:04:23 +00:00
|
|
|
SetDParam(0, v->u.rail.last_speed);
|
2004-08-09 17:04:08 +00:00
|
|
|
str = STR_TRAIN_STOPPING + _patches.vehicle_speed;
|
|
|
|
}
|
|
|
|
} else {
|
2004-12-05 12:43:04 +00:00
|
|
|
switch (v->current_order.type) {
|
2004-08-09 17:04:08 +00:00
|
|
|
case OT_GOTO_STATION: {
|
|
|
|
str = STR_HEADING_FOR_STATION + _patches.vehicle_speed;
|
2006-09-03 08:25:27 +00:00
|
|
|
SetDParam(0, v->current_order.dest);
|
2006-04-08 12:04:23 +00:00
|
|
|
SetDParam(1, v->u.rail.last_speed);
|
2004-08-09 17:04:08 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case OT_GOTO_DEPOT: {
|
2006-09-03 08:25:27 +00:00
|
|
|
Depot *dep = GetDepot(v->current_order.dest);
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, dep->town_index);
|
2006-09-22 23:13:12 +00:00
|
|
|
if (HASBIT(v->current_order.flags, OFB_HALT_IN_DEPOT) && !HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS)) {
|
2006-08-27 09:28:52 +00:00
|
|
|
str = STR_HEADING_FOR_TRAIN_DEPOT + _patches.vehicle_speed;
|
|
|
|
} else {
|
|
|
|
str = STR_HEADING_FOR_TRAIN_DEPOT_SERVICE + _patches.vehicle_speed;
|
|
|
|
}
|
2006-04-08 12:04:23 +00:00
|
|
|
SetDParam(1, v->u.rail.last_speed);
|
2004-08-09 17:04:08 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case OT_LOADING:
|
|
|
|
case OT_LEAVESTATION:
|
|
|
|
str = STR_882F_LOADING_UNLOADING;
|
|
|
|
break;
|
|
|
|
|
2004-11-14 13:07:07 +00:00
|
|
|
case OT_GOTO_WAYPOINT: {
|
2006-09-03 08:25:27 +00:00
|
|
|
SetDParam(0, v->current_order.dest);
|
2004-11-14 13:07:07 +00:00
|
|
|
str = STR_HEADING_FOR_WAYPOINT + _patches.vehicle_speed;
|
2006-04-08 12:04:23 +00:00
|
|
|
SetDParam(1, v->u.rail.last_speed);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
default:
|
|
|
|
if (v->num_orders == 0) {
|
|
|
|
str = STR_NO_ORDERS + _patches.vehicle_speed;
|
2006-04-08 12:04:23 +00:00
|
|
|
SetDParam(0, v->u.rail.last_speed);
|
2006-06-27 21:25:53 +00:00
|
|
|
} else {
|
2004-08-09 17:04:08 +00:00
|
|
|
str = STR_EMPTY;
|
2006-06-27 21:25:53 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-17 17:15:33 +00:00
|
|
|
/* draw the flag plus orders */
|
2005-10-15 11:06:54 +00:00
|
|
|
DrawSprite(v->vehstatus & VS_STOPPED ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, 2, w->widget[5].top + 1);
|
2005-07-17 19:23:18 +00:00
|
|
|
DrawStringCenteredTruncated(w->widget[5].left + 8, w->widget[5].right, w->widget[5].top + 1, str, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawWindowViewport(w);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case WE_CLICK: {
|
2006-09-23 02:39:24 +00:00
|
|
|
int wid = e->we.click.widget;
|
2005-01-06 22:31:58 +00:00
|
|
|
Vehicle *v = GetVehicle(w->window_number);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-01 07:36:15 +00:00
|
|
|
switch (wid) {
|
2004-12-21 23:27:58 +00:00
|
|
|
case 5: /* start/stop train */
|
2004-09-10 19:02:27 +00:00
|
|
|
DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_TRAIN | CMD_MSG(STR_883B_CAN_T_STOP_START_TRAIN));
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
2006-08-28 18:53:03 +00:00
|
|
|
case 6: /* center main view */
|
2004-08-09 17:04:08 +00:00
|
|
|
ScrollMainWindowTo(v->x_pos, v->y_pos);
|
|
|
|
break;
|
2006-08-28 18:53:03 +00:00
|
|
|
case 7: /* goto depot */
|
2004-12-12 15:43:55 +00:00
|
|
|
/* TrainGotoDepot has a nice randomizer in the pathfinder, which causes desyncs... */
|
2006-09-01 10:24:15 +00:00
|
|
|
DoCommandP(v->tile, v->index, _ctrl_pressed ? DEPOT_SERVICE : 0, NULL, CMD_SEND_TRAIN_TO_DEPOT | CMD_NO_TEST_IF_IN_NETWORK | CMD_MSG(STR_8830_CAN_T_SEND_TRAIN_TO_DEPOT));
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
2004-12-21 23:27:58 +00:00
|
|
|
case 8: /* force proceed */
|
2004-09-10 19:02:27 +00:00
|
|
|
DoCommandP(v->tile, v->index, 0, NULL, CMD_FORCE_TRAIN_PROCEED | CMD_MSG(STR_8862_CAN_T_MAKE_TRAIN_PASS_SIGNAL));
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
2004-12-21 23:27:58 +00:00
|
|
|
case 9: /* reverse direction */
|
2004-09-10 19:02:27 +00:00
|
|
|
DoCommandP(v->tile, v->index, 0, NULL, CMD_REVERSE_TRAIN_DIRECTION | CMD_MSG(STR_8869_CAN_T_REVERSE_DIRECTION));
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
2004-12-21 23:27:58 +00:00
|
|
|
case 10: /* show train orders */
|
2004-08-09 17:04:08 +00:00
|
|
|
ShowOrdersWindow(v);
|
|
|
|
break;
|
2004-12-21 23:27:58 +00:00
|
|
|
case 11: /* show train details */
|
2004-08-09 17:04:08 +00:00
|
|
|
ShowTrainDetailsWindow(v);
|
|
|
|
break;
|
2004-12-21 23:27:58 +00:00
|
|
|
case 12:
|
2006-10-03 14:52:39 +00:00
|
|
|
ShowVehicleRefitWindow(v, INVALID_VEH_ORDER_ID);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
2005-07-31 13:08:08 +00:00
|
|
|
case 13:
|
|
|
|
DoCommandP(v->tile, v->index, _ctrl_pressed ? 1 : 0, NULL, CMD_CLONE_VEHICLE | CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE));
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
2005-03-11 13:17:39 +00:00
|
|
|
case WE_RESIZE:
|
2006-09-23 02:39:24 +00:00
|
|
|
w->viewport->width += e->we.sizing.diff.x;
|
|
|
|
w->viewport->height += e->we.sizing.diff.y;
|
|
|
|
w->viewport->virtual_width += e->we.sizing.diff.x;
|
|
|
|
w->viewport->virtual_height += e->we.sizing.diff.y;
|
2005-03-11 13:17:39 +00:00
|
|
|
break;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
case WE_DESTROY:
|
2004-11-06 09:24:28 +00:00
|
|
|
DeleteWindowById(WC_VEHICLE_REFIT, w->window_number);
|
2004-08-09 17:04:08 +00:00
|
|
|
DeleteWindowById(WC_VEHICLE_ORDERS, w->window_number);
|
|
|
|
DeleteWindowById(WC_VEHICLE_DETAILS, w->window_number);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_MOUSELOOP: {
|
2006-07-26 03:33:12 +00:00
|
|
|
const Vehicle *v = GetVehicle(w->window_number);
|
2006-10-02 00:28:31 +00:00
|
|
|
bool train_stopped = CheckTrainStoppedInDepot(v) >= 0;
|
|
|
|
|
|
|
|
/* Widget 7 (send to depot) must be hidden if the train is already stopped in hangar.
|
|
|
|
* Widget 13 (clone) should then be shown, since cloning is allowed only while in depot and stopped.
|
|
|
|
* This sytem allows to have two buttons, on top of each other.
|
|
|
|
* The same system applies to widget 9 and 12, reverse direction and refit*/
|
|
|
|
if (train_stopped != IsWindowWidgetHidden(w, 7) || train_stopped == IsWindowWidgetHidden(w, 13)) {
|
|
|
|
SetWindowWidgetHiddenState(w, 7, train_stopped); // send to depot
|
|
|
|
SetWindowWidgetHiddenState(w, 9, train_stopped); // reverse direction
|
|
|
|
SetWindowWidgetHiddenState(w, 12, !train_stopped); // refit
|
|
|
|
SetWindowWidgetHiddenState(w, 13, !train_stopped); // clone
|
2004-08-09 17:04:08 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const WindowDesc _train_view_desc = {
|
2006-11-10 19:24:14 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 250, 134,
|
2004-08-09 17:04:08 +00:00
|
|
|
WC_VEHICLE_VIEW,0,
|
2005-03-11 13:17:39 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
|
2004-08-09 17:04:08 +00:00
|
|
|
_train_view_widgets,
|
|
|
|
TrainViewWndProc
|
|
|
|
};
|
|
|
|
|
2006-07-26 03:33:12 +00:00
|
|
|
void ShowTrainViewWindow(const Vehicle *v)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-07-26 03:33:12 +00:00
|
|
|
Window *w = AllocateWindowDescFront(&_train_view_desc,v->index);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-10-28 20:04:54 +00:00
|
|
|
if (w != NULL) {
|
2004-08-09 17:04:08 +00:00
|
|
|
w->caption_color = v->owner;
|
|
|
|
AssignWindowViewport(w, 3, 17, 0xE2, 0x66, w->window_number | (1 << 31), 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-11 16:17:03 +00:00
|
|
|
static void TrainDetailsCargoTab(const Vehicle *v, int x, int y)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
if (v->cargo_cap != 0) {
|
2006-08-31 15:22:03 +00:00
|
|
|
uint num = v->cargo_count;
|
|
|
|
StringID str = STR_8812_EMPTY;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (num != 0) {
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, v->cargo_type);
|
|
|
|
SetDParam(1, num);
|
|
|
|
SetDParam(2, v->cargo_source);
|
2006-11-27 23:11:56 +00:00
|
|
|
SetDParam(3, _patches.freight_trains);
|
|
|
|
str = FreightWagonMult(v) > 1 ? STR_FROM_MULT : STR_8813_FROM;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
DrawString(x, y, str, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-11 16:17:03 +00:00
|
|
|
static void TrainDetailsInfoTab(const Vehicle *v, int x, int y)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-08-31 15:22:03 +00:00
|
|
|
if (RailVehInfo(v->engine_type)->flags & RVI_WAGON) {
|
|
|
|
SetDParam(0, GetCustomEngineName(v->engine_type));
|
|
|
|
SetDParam(1, v->value);
|
|
|
|
DrawString(x, y, STR_882D_VALUE, 0x10);
|
|
|
|
} else {
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, GetCustomEngineName(v->engine_type));
|
2006-08-20 19:05:28 +00:00
|
|
|
SetDParam(1, v->build_year);
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(2, v->value);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawString(x, y, STR_882C_BUILT_VALUE, 0x10);
|
2004-09-10 19:02:27 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-05-11 16:17:03 +00:00
|
|
|
static void TrainDetailsCapacityTab(const Vehicle *v, int x, int y)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
if (v->cargo_cap != 0) {
|
2006-10-20 11:53:29 +00:00
|
|
|
SetDParam(0, v->cargo_type);
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(1, v->cargo_cap);
|
2006-11-27 23:11:56 +00:00
|
|
|
SetDParam(2, _patches.freight_trains);
|
|
|
|
DrawString(x, y, FreightWagonMult(v) > 1 ? STR_CAPACITY_MULT : STR_013F_CAPACITY, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void DrawTrainDetailsWindow(Window *w)
|
|
|
|
{
|
|
|
|
byte det_tab = WP(w, traindetails_d).tab;
|
2006-11-30 16:03:12 +00:00
|
|
|
const Vehicle *v;
|
|
|
|
const Vehicle *u;
|
2006-08-31 15:22:03 +00:00
|
|
|
AcceptedCargo act_cargo;
|
|
|
|
AcceptedCargo max_cargo;
|
|
|
|
uint i;
|
|
|
|
int num;
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
int sel;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
num = 0;
|
2005-01-06 22:31:58 +00:00
|
|
|
u = v = GetVehicle(w->window_number);
|
2006-08-31 15:22:03 +00:00
|
|
|
if (det_tab == 3) { // Total cargo tab
|
|
|
|
for (i = 0; i < lengthof(act_cargo); i++) {
|
|
|
|
act_cargo[i] = 0;
|
|
|
|
max_cargo[i] = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-08-31 15:22:03 +00:00
|
|
|
do {
|
|
|
|
act_cargo[u->cargo_type] += u->cargo_count;
|
|
|
|
max_cargo[u->cargo_type] += u->cargo_cap;
|
2006-10-17 07:33:05 +00:00
|
|
|
} while ((u = u->next) != NULL);
|
2006-08-31 15:22:03 +00:00
|
|
|
|
|
|
|
/* Set scroll-amount seperately from counting, as to not compute num double
|
|
|
|
* for more carriages of the same type
|
|
|
|
*/
|
2004-08-09 17:04:08 +00:00
|
|
|
for (i = 0; i != NUM_CARGO; i++) {
|
2006-08-31 15:22:03 +00:00
|
|
|
if (max_cargo[i] > 0) num++; // only count carriages that the train has
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2006-08-28 18:53:03 +00:00
|
|
|
num++; // needs one more because first line is description string
|
2006-08-31 15:22:03 +00:00
|
|
|
} else {
|
|
|
|
do {
|
2006-10-17 07:33:05 +00:00
|
|
|
if (!IsArticulatedPart(u) || u->cargo_cap != 0) num++;
|
|
|
|
} while ((u = u->next) != NULL);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SetVScrollCount(w, num);
|
|
|
|
|
2006-10-03 02:08:15 +00:00
|
|
|
DisableWindowWidget(w, det_tab + 9);
|
|
|
|
SetWindowWidgetDisabledState(w, 2, v->owner != _local_player);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-03 02:08:15 +00:00
|
|
|
/* disable service-scroller when interval is set to disabled */
|
|
|
|
SetWindowWidgetDisabledState(w, 6, !_patches.servint_trains);
|
|
|
|
SetWindowWidgetDisabledState(w, 7, !_patches.servint_trains);
|
2004-09-04 13:06:09 +00:00
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, v->string_id);
|
|
|
|
SetDParam(1, v->unitnumber);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
2006-08-31 15:22:03 +00:00
|
|
|
SetDParam(1, v->age / 366);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
x = 2;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-07-31 22:28:49 +00:00
|
|
|
SetDParam(0, (v->age + 365 < v->max_age) ? STR_AGE : STR_AGE_RED);
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(2, v->max_age / 366);
|
|
|
|
SetDParam(3, GetTrainRunningCost(v) >> 8);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawString(x, 15, STR_885D_AGE_RUNNING_COST_YR, 0);
|
|
|
|
|
2006-04-08 12:04:23 +00:00
|
|
|
SetDParam(2, v->u.rail.cached_max_speed);
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(1, v->u.rail.cached_power);
|
|
|
|
SetDParam(0, v->u.rail.cached_weight);
|
2006-03-31 17:40:31 +00:00
|
|
|
DrawString(x, 25, STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, v->profit_this_year);
|
|
|
|
SetDParam(1, v->profit_last_year);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawString(x, 35, STR_885F_PROFIT_THIS_YEAR_LAST_YEAR, 0);
|
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, 100 * (v->reliability>>8) >> 8);
|
|
|
|
SetDParam(1, v->breakdowns_since_last_service);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawString(x, 45, STR_8860_RELIABILITY_BREAKDOWNS, 0);
|
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, v->service_interval);
|
|
|
|
SetDParam(1, v->date_of_last_service);
|
2006-02-02 08:03:10 +00:00
|
|
|
DrawString(x + 11, 57 + (w->vscroll.cap * 14), _patches.servint_ispercent ? STR_SERVICING_INTERVAL_PERCENT : STR_883C_SERVICING_INTERVAL_DAYS, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
y = 57;
|
|
|
|
sel = w->vscroll.pos;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// draw the first 3 details tabs
|
|
|
|
if (det_tab != 3) {
|
2006-01-06 09:50:43 +00:00
|
|
|
x = 1;
|
2006-02-01 07:36:15 +00:00
|
|
|
for (;;) {
|
2006-02-02 08:03:10 +00:00
|
|
|
if (--sel < 0 && sel >= -w->vscroll.cap) {
|
2005-11-05 16:07:26 +00:00
|
|
|
int dx = 0;
|
2006-08-31 15:22:03 +00:00
|
|
|
int px;
|
|
|
|
int py;
|
|
|
|
|
2005-11-05 16:07:26 +00:00
|
|
|
u = v;
|
|
|
|
do {
|
2006-05-14 20:38:09 +00:00
|
|
|
PalSpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
|
|
|
|
DrawSprite(GetTrainImage(u, DIR_W) | pal, x + 14 + WagonLengthToPixels(dx), y + 6 + (is_custom_sprite(RailVehInfo(u->engine_type)->image_index) ? _traininfo_vehicle_pitch : 0));
|
2005-11-05 16:07:26 +00:00
|
|
|
dx += u->u.rail.cached_veh_length;
|
|
|
|
u = u->next;
|
2006-10-17 07:33:05 +00:00
|
|
|
} while (u != NULL && IsArticulatedPart(u) && u->cargo_cap == 0);
|
2006-08-31 15:22:03 +00:00
|
|
|
|
|
|
|
px = x + WagonLengthToPixels(dx) + 2;
|
|
|
|
py = y + 2;
|
|
|
|
switch (det_tab) {
|
|
|
|
default: NOT_REACHED();
|
|
|
|
case 0: TrainDetailsCargoTab( v, px, py); break;
|
2006-10-17 07:33:05 +00:00
|
|
|
case 1:
|
|
|
|
// Only show name and value for the 'real' part
|
|
|
|
if (!IsArticulatedPart(v)) {
|
|
|
|
TrainDetailsInfoTab(v, px, py);
|
|
|
|
}
|
|
|
|
break;
|
2006-08-31 15:22:03 +00:00
|
|
|
case 2: TrainDetailsCapacityTab(v, px, py); break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
y += 14;
|
2006-10-17 07:33:05 +00:00
|
|
|
|
|
|
|
v = u;
|
|
|
|
} else {
|
|
|
|
// Move to the next line
|
|
|
|
do {
|
|
|
|
v = v->next;
|
|
|
|
} while (v != NULL && IsArticulatedPart(v) && v->cargo_cap == 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2006-08-31 15:22:03 +00:00
|
|
|
if (v == NULL) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2006-02-02 08:03:10 +00:00
|
|
|
} else {
|
|
|
|
// draw total cargo tab
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawString(x, y + 2, STR_013F_TOTAL_CAPACITY_TEXT, 0);
|
2006-02-02 08:03:10 +00:00
|
|
|
for (i = 0; i != NUM_CARGO; i++) {
|
2006-08-31 15:22:03 +00:00
|
|
|
if (max_cargo[i] > 0 && --sel < 0 && sel > -w->vscroll.cap) {
|
2004-08-09 17:04:08 +00:00
|
|
|
y += 14;
|
2006-08-31 15:22:03 +00:00
|
|
|
SetDParam(0, i); // {CARGO} #1
|
|
|
|
SetDParam(1, act_cargo[i]); // {CARGO} #2
|
|
|
|
SetDParam(2, i); // {SHORTCARGO} #1
|
|
|
|
SetDParam(3, max_cargo[i]); // {SHORTCARGO} #2
|
2006-11-27 23:11:56 +00:00
|
|
|
SetDParam(4, _patches.freight_trains);
|
|
|
|
DrawString(x, y + 2, FreightWagonMult(v) > 1 ? STR_TOTAL_CAPACITY_MULT : STR_013F_TOTAL_CAPACITY, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2006-02-02 08:03:10 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void TrainDetailsWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2005-05-11 16:17:03 +00:00
|
|
|
switch (e->event) {
|
2004-08-09 17:04:08 +00:00
|
|
|
case WE_PAINT:
|
|
|
|
DrawTrainDetailsWindow(w);
|
|
|
|
break;
|
|
|
|
case WE_CLICK: {
|
|
|
|
int mod;
|
2005-05-11 16:17:03 +00:00
|
|
|
const Vehicle *v;
|
2006-09-23 02:39:24 +00:00
|
|
|
switch (e->we.click.widget) {
|
2004-08-09 17:04:08 +00:00
|
|
|
case 2: /* name train */
|
2005-01-06 22:31:58 +00:00
|
|
|
v = GetVehicle(w->window_number);
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, v->unitnumber);
|
2006-08-19 09:31:22 +00:00
|
|
|
ShowQueryString(v->string_id, STR_8865_NAME_TRAIN, 31, 150, w->window_class, w->window_number, CS_ALPHANUMERAL);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
2006-08-28 18:53:03 +00:00
|
|
|
case 6: /* inc serv interval */
|
2004-09-04 13:06:09 +00:00
|
|
|
mod = _ctrl_pressed? 5 : 10;
|
2004-08-09 17:04:08 +00:00
|
|
|
goto do_change_service_int;
|
|
|
|
|
|
|
|
case 7: /* dec serv interval */
|
2004-09-04 13:06:09 +00:00
|
|
|
mod = _ctrl_pressed? -5 : -10;
|
2004-08-09 17:04:08 +00:00
|
|
|
do_change_service_int:
|
2005-01-06 22:31:58 +00:00
|
|
|
v = GetVehicle(w->window_number);
|
2004-09-04 13:06:09 +00:00
|
|
|
|
2005-05-11 16:17:03 +00:00
|
|
|
mod = GetServiceIntervalClamped(mod + v->service_interval);
|
|
|
|
if (mod == v->service_interval) return;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2006-01-05 21:35:54 +00:00
|
|
|
DoCommandP(v->tile, v->index, mod, NULL, CMD_CHANGE_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING));
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
/* details buttons*/
|
2006-08-28 18:53:03 +00:00
|
|
|
case 9: // Cargo
|
|
|
|
case 10: // Information
|
|
|
|
case 11: // Capacities
|
|
|
|
case 12: // Total cargo
|
2006-10-03 02:08:15 +00:00
|
|
|
EnableWindowWidget(w, 9);
|
|
|
|
EnableWindowWidget(w, 10);
|
|
|
|
EnableWindowWidget(w, 11);
|
|
|
|
EnableWindowWidget(w, 12);
|
|
|
|
EnableWindowWidget(w, e->we.click.widget);
|
2006-09-23 02:39:24 +00:00
|
|
|
WP(w,traindetails_d).tab = e->we.click.widget - 9;
|
2004-08-09 17:04:08 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
2005-10-22 06:39:32 +00:00
|
|
|
case WE_ON_EDIT_TEXT:
|
2006-09-23 02:39:24 +00:00
|
|
|
if (e->we.edittext.str[0] != '\0') {
|
|
|
|
_cmd_text = e->we.edittext.str;
|
2005-05-15 18:50:55 +00:00
|
|
|
DoCommandP(0, w->window_number, 0, NULL,
|
|
|
|
CMD_NAME_VEHICLE | CMD_MSG(STR_8866_CAN_T_NAME_TRAIN));
|
|
|
|
}
|
2005-10-22 06:39:32 +00:00
|
|
|
break;
|
2006-02-02 08:03:10 +00:00
|
|
|
|
|
|
|
case WE_RESIZE:
|
2006-09-23 02:39:24 +00:00
|
|
|
if (e->we.sizing.diff.y == 0) break;
|
2006-02-02 08:03:10 +00:00
|
|
|
|
2006-09-23 02:39:24 +00:00
|
|
|
w->vscroll.cap += e->we.sizing.diff.y / 14;
|
2006-09-04 15:44:28 +00:00
|
|
|
w->widget[4].data = (w->vscroll.cap << 8) + 1;
|
2006-02-02 08:03:10 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const Widget _train_details_widgets[] = {
|
2006-02-02 08:03:10 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 329, 0, 13, STR_8802_DETAILS, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 330, 369, 0, 13, STR_01AA_NAME, STR_8867_NAME_TRAIN},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 0, 369, 14, 55, 0x0, STR_NULL},
|
|
|
|
{ WWT_MATRIX, RESIZE_BOTTOM, 14, 0, 357, 56, 139, 0x601, STR_NULL},
|
|
|
|
{ WWT_SCROLLBAR, RESIZE_BOTTOM, 14, 358, 369, 56, 139, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 10, 140, 145, STR_0188, STR_884D_INCREASE_SERVICING_INTERVAL},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 10, 146, 151, STR_0189, STR_884E_DECREASE_SERVICING_INTERVAL},
|
|
|
|
{ WWT_PANEL, RESIZE_TB, 14, 11, 369, 140, 151, 0x0, STR_NULL},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 89, 152, 163, STR_013C_CARGO, STR_884F_SHOW_DETAILS_OF_CARGO_CARRIED},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 90, 178, 152, 163, STR_013D_INFORMATION, STR_8850_SHOW_DETAILS_OF_TRAIN_VEHICLES},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 179, 268, 152, 163, STR_013E_CAPACITIES, STR_8851_SHOW_CAPACITIES_OF_EACH},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 269, 357, 152, 163, STR_013E_TOTAL_CARGO, STR_8852_SHOW_TOTAL_CARGO},
|
|
|
|
{ WWT_RESIZEBOX, RESIZE_TB, 14, 358, 369, 152, 163, 0x0, STR_RESIZE_BUTTON},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static const WindowDesc _train_details_desc = {
|
2006-11-10 19:24:14 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 370, 164,
|
2004-08-09 17:04:08 +00:00
|
|
|
WC_VEHICLE_DETAILS,WC_VEHICLE_VIEW,
|
2006-02-02 08:03:10 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
|
2004-08-09 17:04:08 +00:00
|
|
|
_train_details_widgets,
|
|
|
|
TrainDetailsWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-07-26 03:33:12 +00:00
|
|
|
static void ShowTrainDetailsWindow(const Vehicle *v)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
VehicleID veh = v->index;
|
|
|
|
|
|
|
|
DeleteWindowById(WC_VEHICLE_ORDERS, veh);
|
|
|
|
DeleteWindowById(WC_VEHICLE_DETAILS, veh);
|
|
|
|
|
2006-11-11 09:47:44 +00:00
|
|
|
w = AllocateWindowDescFront(&_train_details_desc, veh);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
w->caption_color = v->owner;
|
|
|
|
w->vscroll.cap = 6;
|
2006-09-04 15:44:28 +00:00
|
|
|
w->widget[4].data = (w->vscroll.cap << 8) + 1;
|
2006-02-02 08:03:10 +00:00
|
|
|
|
|
|
|
w->resize.step_height = 14;
|
|
|
|
w->resize.height = w->height - 14 * 2; /* Minimum of 4 wagons in the display */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
WP(w,traindetails_d).tab = 0;
|
|
|
|
}
|