2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2004-09-06 18:15:13 +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"
|
2005-07-21 19:36:43 +00:00
|
|
|
#include "player.h"
|
2005-09-27 18:51:04 +00:00
|
|
|
#include "station.h"
|
2005-02-06 08:18:00 +00:00
|
|
|
#include "strings.h"
|
2005-02-13 11:18:02 +00:00
|
|
|
#include "table/sprites.h"
|
2004-11-25 10:47:30 +00:00
|
|
|
#include "table/strings.h"
|
2004-09-06 18:15:13 +00:00
|
|
|
#include "vehicle.h"
|
2004-12-10 18:16:08 +00:00
|
|
|
#include "window.h"
|
2005-01-02 17:23:04 +00:00
|
|
|
#include "engine.h"
|
|
|
|
#include "gui.h"
|
|
|
|
#include "command.h"
|
|
|
|
#include "gfx.h"
|
2005-07-21 22:15:02 +00:00
|
|
|
#include "variables.h"
|
|
|
|
#include "vehicle_gui.h"
|
2005-10-24 19:40:48 +00:00
|
|
|
#include "viewport.h"
|
2005-07-21 22:15:02 +00:00
|
|
|
|
|
|
|
Sorting _sorting;
|
|
|
|
|
|
|
|
static uint32 _internal_name_sorter_id; // internal StringID for default vehicle-names
|
|
|
|
static uint32 _last_vehicle_idx; // cached index to hopefully speed up name-sorting
|
|
|
|
static bool _internal_sort_order; // descending/ascending
|
2004-09-06 18:15:13 +00:00
|
|
|
|
2005-08-05 20:22:06 +00:00
|
|
|
static uint16 _player_num_engines[256];
|
2005-10-16 09:13:04 +00:00
|
|
|
static RailType _railtype_selected_in_replace_gui;
|
2005-08-05 20:22:06 +00:00
|
|
|
|
2005-09-26 13:38:12 +00:00
|
|
|
|
|
|
|
typedef int CDECL VehicleSortListingTypeFunction(const void*, const void*);
|
|
|
|
|
|
|
|
static VehicleSortListingTypeFunction VehicleUnsortedSorter;
|
|
|
|
static VehicleSortListingTypeFunction VehicleNumberSorter;
|
|
|
|
static VehicleSortListingTypeFunction VehicleNameSorter;
|
|
|
|
static VehicleSortListingTypeFunction VehicleAgeSorter;
|
|
|
|
static VehicleSortListingTypeFunction VehicleProfitThisYearSorter;
|
|
|
|
static VehicleSortListingTypeFunction VehicleProfitLastYearSorter;
|
|
|
|
static VehicleSortListingTypeFunction VehicleCargoSorter;
|
|
|
|
static VehicleSortListingTypeFunction VehicleReliabilitySorter;
|
|
|
|
static VehicleSortListingTypeFunction VehicleMaxSpeedSorter;
|
|
|
|
|
|
|
|
static VehicleSortListingTypeFunction* const _vehicle_sorter[] = {
|
2004-11-25 06:05:47 +00:00
|
|
|
&VehicleUnsortedSorter,
|
|
|
|
&VehicleNumberSorter,
|
|
|
|
&VehicleNameSorter,
|
|
|
|
&VehicleAgeSorter,
|
|
|
|
&VehicleProfitThisYearSorter,
|
|
|
|
&VehicleProfitLastYearSorter,
|
|
|
|
&VehicleCargoSorter,
|
|
|
|
&VehicleReliabilitySorter,
|
|
|
|
&VehicleMaxSpeedSorter
|
|
|
|
};
|
|
|
|
|
|
|
|
const StringID _vehicle_sort_listing[] = {
|
|
|
|
STR_SORT_BY_UNSORTED,
|
|
|
|
STR_SORT_BY_NUMBER,
|
|
|
|
STR_SORT_BY_DROPDOWN_NAME,
|
|
|
|
STR_SORT_BY_AGE,
|
|
|
|
STR_SORT_BY_PROFIT_THIS_YEAR,
|
|
|
|
STR_SORT_BY_PROFIT_LAST_YEAR,
|
|
|
|
STR_SORT_BY_TOTAL_CAPACITY_PER_CARGOTYPE,
|
|
|
|
STR_SORT_BY_RELIABILITY,
|
|
|
|
STR_SORT_BY_MAX_SPEED,
|
|
|
|
INVALID_STRING_ID
|
|
|
|
};
|
|
|
|
|
2005-09-26 13:38:12 +00:00
|
|
|
static const StringID _rail_types_list[] = {
|
2005-01-02 17:23:04 +00:00
|
|
|
STR_RAIL_VEHICLES,
|
|
|
|
STR_MONORAIL_VEHICLES,
|
|
|
|
STR_MAGLEV_VEHICLES,
|
|
|
|
INVALID_STRING_ID
|
|
|
|
};
|
|
|
|
|
2004-12-10 18:16:08 +00:00
|
|
|
void RebuildVehicleLists(void)
|
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
|
|
|
|
for (w = _windows; w != _last_window; ++w)
|
|
|
|
switch (w->window_class) {
|
2005-01-10 12:14:15 +00:00
|
|
|
case WC_TRAINS_LIST: case WC_ROADVEH_LIST:
|
|
|
|
case WC_SHIPS_LIST: case WC_AIRCRAFT_LIST:
|
|
|
|
WP(w, vehiclelist_d).flags |= VL_REBUILD;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
|
|
|
default: break;
|
2004-12-10 18:16:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResortVehicleLists(void)
|
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
|
|
|
|
for (w = _windows; w != _last_window; ++w)
|
|
|
|
switch (w->window_class) {
|
2005-01-10 12:14:15 +00:00
|
|
|
case WC_TRAINS_LIST: case WC_ROADVEH_LIST:
|
|
|
|
case WC_SHIPS_LIST: case WC_AIRCRAFT_LIST:
|
|
|
|
WP(w, vehiclelist_d).flags |= VL_RESORT;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
|
|
|
default: break;
|
2004-12-10 18:16:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-27 18:51:04 +00:00
|
|
|
void BuildVehicleList(vehiclelist_d* vl, int type, PlayerID owner, StationID station)
|
2004-12-10 18:16:08 +00:00
|
|
|
{
|
2005-01-19 19:15:03 +00:00
|
|
|
int subtype = (type != VEH_Aircraft) ? TS_Front_Engine : 2;
|
2004-12-10 18:16:08 +00:00
|
|
|
int n = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!(vl->flags & VL_REBUILD)) return;
|
|
|
|
|
2005-01-06 22:31:58 +00:00
|
|
|
/* Create array for sorting */
|
2005-02-04 13:23:29 +00:00
|
|
|
_vehicle_sort = realloc(_vehicle_sort, GetVehiclePoolSize() * sizeof(_vehicle_sort[0]));
|
2005-01-06 22:31:58 +00:00
|
|
|
if (_vehicle_sort == NULL)
|
|
|
|
error("Could not allocate memory for the vehicle-sorting-list");
|
|
|
|
|
2004-12-10 18:16:08 +00:00
|
|
|
DEBUG(misc, 1) ("Building vehicle list for player %d station %d...",
|
2005-01-03 19:45:18 +00:00
|
|
|
owner, station);
|
2004-12-10 18:16:08 +00:00
|
|
|
|
2005-09-27 18:51:04 +00:00
|
|
|
if (station != INVALID_STATION) {
|
2004-12-10 18:16:08 +00:00
|
|
|
const Vehicle *v;
|
|
|
|
FOR_ALL_VEHICLES(v) {
|
|
|
|
if (v->type == type && v->subtype <= subtype) {
|
2005-01-15 19:06:22 +00:00
|
|
|
const Order *order;
|
|
|
|
|
|
|
|
FOR_VEHICLE_ORDERS(v, order) {
|
|
|
|
if (order->type == OT_GOTO_STATION && order->station == station) {
|
2005-01-06 22:31:58 +00:00
|
|
|
_vehicle_sort[n].index = v->index;
|
|
|
|
_vehicle_sort[n].owner = v->owner;
|
2004-12-10 18:16:08 +00:00
|
|
|
++n;
|
|
|
|
break;
|
|
|
|
}
|
2005-01-15 19:06:22 +00:00
|
|
|
}
|
2004-12-10 18:16:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const Vehicle *v;
|
|
|
|
FOR_ALL_VEHICLES(v) {
|
|
|
|
if (v->type == type && v->subtype <= subtype && v->owner == owner) {
|
2005-01-06 22:31:58 +00:00
|
|
|
_vehicle_sort[n].index = v->index;
|
|
|
|
_vehicle_sort[n].owner = v->owner;
|
2004-12-10 18:16:08 +00:00
|
|
|
++n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-23 13:04:44 +00:00
|
|
|
free(vl->sort_list);
|
|
|
|
vl->sort_list = malloc(n * sizeof(vl->sort_list[0]));
|
|
|
|
if (n != 0 && vl->sort_list == NULL)
|
2005-01-06 22:31:58 +00:00
|
|
|
error("Could not allocate memory for the vehicle-sorting-list");
|
2004-12-10 18:16:08 +00:00
|
|
|
vl->list_length = n;
|
|
|
|
|
2005-10-23 13:04:44 +00:00
|
|
|
for (i = 0; i < n; ++i) vl->sort_list[i] = _vehicle_sort[i];
|
2004-12-10 18:16:08 +00:00
|
|
|
|
|
|
|
vl->flags &= ~VL_REBUILD;
|
|
|
|
vl->flags |= VL_RESORT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SortVehicleList(vehiclelist_d *vl)
|
|
|
|
{
|
|
|
|
if (!(vl->flags & VL_RESORT)) return;
|
|
|
|
|
|
|
|
_internal_sort_order = vl->flags & VL_DESC;
|
|
|
|
_internal_name_sorter_id = STR_SV_TRAIN_NAME;
|
|
|
|
_last_vehicle_idx = 0; // used for "cache" in namesorting
|
|
|
|
qsort(vl->sort_list, vl->list_length, sizeof(vl->sort_list[0]),
|
|
|
|
_vehicle_sorter[vl->sort_type]);
|
|
|
|
|
|
|
|
vl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
|
|
|
|
vl->flags &= ~VL_RESORT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-06 18:15:13 +00:00
|
|
|
/* General Vehicle GUI based procedures that are independent of vehicle types */
|
2005-01-22 20:23:18 +00:00
|
|
|
void InitializeVehiclesGuiList(void)
|
2004-09-06 18:15:13 +00:00
|
|
|
{
|
2005-10-16 07:58:15 +00:00
|
|
|
_railtype_selected_in_replace_gui = RAILTYPE_RAIL;
|
2004-09-06 18:15:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// draw the vehicle profit button in the vehicle list window.
|
2005-09-18 20:56:44 +00:00
|
|
|
void DrawVehicleProfitButton(const Vehicle *v, int x, int y)
|
2004-09-06 18:15:13 +00:00
|
|
|
{
|
|
|
|
uint32 ormod;
|
|
|
|
|
|
|
|
// draw profit-based colored icons
|
|
|
|
if(v->age <= 365 * 2)
|
2005-04-13 23:03:31 +00:00
|
|
|
ormod = PALETTE_TO_GREY;
|
2004-09-06 18:15:13 +00:00
|
|
|
else if(v->profit_last_year < 0)
|
2005-04-13 23:03:31 +00:00
|
|
|
ormod = PALETTE_TO_RED;
|
2004-09-06 18:15:13 +00:00
|
|
|
else if(v->profit_last_year < 10000)
|
2005-04-13 23:03:31 +00:00
|
|
|
ormod = PALETTE_TO_YELLOW;
|
2004-09-06 18:15:13 +00:00
|
|
|
else
|
2005-04-13 23:03:31 +00:00
|
|
|
ormod = PALETTE_TO_GREEN;
|
|
|
|
DrawSprite(SPR_BLOT | ormod, x, y);
|
2004-09-06 18:15:13 +00:00
|
|
|
}
|
|
|
|
|
2005-05-26 16:31:32 +00:00
|
|
|
/** Draw the list of available refit options for a consist.
|
2005-05-14 12:36:16 +00:00
|
|
|
* Draw the list and highlight the selected refit option (if any)
|
2005-05-26 16:31:32 +00:00
|
|
|
* @param *v first vehicle in consist to get the refit-options of
|
2005-05-14 12:36:16 +00:00
|
|
|
* @param sel selected refit cargo-type in the window
|
|
|
|
* @return the cargo type that is hightlighted, CT_INVALID if none
|
|
|
|
*/
|
|
|
|
CargoID DrawVehicleRefitWindow(const Vehicle *v, int sel)
|
|
|
|
{
|
|
|
|
uint32 cmask;
|
|
|
|
CargoID cid, cargo = CT_INVALID;
|
|
|
|
int y = 25;
|
2005-05-26 16:31:32 +00:00
|
|
|
const Vehicle* u;
|
2005-05-14 12:36:16 +00:00
|
|
|
#define show_cargo(ctype) { \
|
|
|
|
byte colour = 16; \
|
|
|
|
if (sel == 0) { \
|
|
|
|
cargo = ctype; \
|
|
|
|
colour = 12; \
|
|
|
|
} \
|
|
|
|
sel--; \
|
|
|
|
DrawString(6, y, _cargoc.names_s[ctype], colour); \
|
|
|
|
y += 10; \
|
|
|
|
}
|
|
|
|
|
2005-05-26 16:31:32 +00:00
|
|
|
/* Check if vehicle has custom refit or normal ones, and get its bitmasked value.
|
|
|
|
* If its a train, 'or' this with the refit masks of the wagons. Now just 'and'
|
|
|
|
* it with the bitmask of available cargo on the current landscape, and
|
|
|
|
* where the bits are set: those are available */
|
|
|
|
cmask = 0;
|
|
|
|
u = v;
|
|
|
|
do {
|
|
|
|
if (_engine_refit_masks[u->engine_type] != 0) { // newgrf custom refit mask
|
|
|
|
cmask |= _engine_refit_masks[u->engine_type];
|
|
|
|
} else if (u->cargo_cap != 0) {
|
|
|
|
// rail wagons cant be refitted by default
|
|
|
|
if (v->type != VEH_Train || !(RailVehInfo(u->engine_type)->flags & RVI_WAGON))
|
|
|
|
cmask |= _default_refitmasks[v->type - VEH_Train];
|
|
|
|
}
|
|
|
|
u = u->next;
|
|
|
|
} while (v->type == VEH_Train && u != NULL);
|
|
|
|
|
2005-05-14 12:36:16 +00:00
|
|
|
cmask &= _landscape_global_cargo_mask[_opt_ptr->landscape];
|
|
|
|
|
|
|
|
/* Check which cargo has been selected from the refit window and draw list */
|
|
|
|
for (cid = 0; cmask != 0; cmask >>= 1, cid++) {
|
|
|
|
if (HASBIT(cmask, 0)) // vehicle is refittable to this cargo
|
|
|
|
show_cargo(_local_cargo_id_ctype[cid]);
|
|
|
|
}
|
|
|
|
return cargo;
|
|
|
|
}
|
|
|
|
|
2004-09-06 18:15:13 +00:00
|
|
|
/************ Sorter functions *****************/
|
|
|
|
int CDECL GeneralOwnerSorter(const void *a, const void *b)
|
|
|
|
{
|
2004-09-06 21:20:01 +00:00
|
|
|
return (*(const SortStruct*)a).owner - (*(const SortStruct*)b).owner;
|
2004-09-06 18:15:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Variables you need to set before calling this function!
|
2004-09-06 21:20:01 +00:00
|
|
|
* 1. (byte)_internal_sort_type: sorting criteria to sort on
|
2004-09-06 18:15:13 +00:00
|
|
|
* 2. (bool)_internal_sort_order: sorting order, descending/ascending
|
2004-09-06 21:20:01 +00:00
|
|
|
* 3. (uint32)_internal_name_sorter_id: default StringID of the vehicle when no name is set. eg
|
|
|
|
* STR_SV_TRAIN_NAME for trains or STR_SV_AIRCRAFT_NAME for aircraft
|
2004-09-06 18:15:13 +00:00
|
|
|
*/
|
2005-09-26 13:38:12 +00:00
|
|
|
static int CDECL VehicleUnsortedSorter(const void *a, const void *b)
|
2004-09-06 21:20:01 +00:00
|
|
|
{
|
2005-02-04 20:40:04 +00:00
|
|
|
return ((const SortStruct*)a)->index - ((const SortStruct*)b)->index;
|
2004-09-06 21:20:01 +00:00
|
|
|
}
|
|
|
|
|
2004-09-14 14:19:53 +00:00
|
|
|
// if the sorting criteria had the same value, sort vehicle by unitnumber
|
|
|
|
#define VEHICLEUNITNUMBERSORTER(r, a, b) {if (r == 0) {r = a->unitnumber - b->unitnumber;}}
|
|
|
|
|
2005-09-26 13:38:12 +00:00
|
|
|
static int CDECL VehicleNumberSorter(const void *a, const void *b)
|
2004-09-06 21:20:01 +00:00
|
|
|
{
|
2005-01-06 22:31:58 +00:00
|
|
|
const Vehicle *va = GetVehicle((*(const SortStruct*)a).index);
|
|
|
|
const Vehicle *vb = GetVehicle((*(const SortStruct*)b).index);
|
2004-09-06 21:20:01 +00:00
|
|
|
int r = va->unitnumber - vb->unitnumber;
|
|
|
|
|
|
|
|
return (_internal_sort_order & 1) ? -r : r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char _bufcache[64]; // used together with _last_vehicle_idx to hopefully speed up stringsorting
|
2005-09-26 13:38:12 +00:00
|
|
|
static int CDECL VehicleNameSorter(const void *a, const void *b)
|
2004-09-06 18:15:13 +00:00
|
|
|
{
|
2004-09-06 21:47:12 +00:00
|
|
|
const SortStruct *cmp1 = (const SortStruct*)a;
|
|
|
|
const SortStruct *cmp2 = (const SortStruct*)b;
|
2005-01-06 22:31:58 +00:00
|
|
|
const Vehicle *va = GetVehicle(cmp1->index);
|
|
|
|
const Vehicle *vb = GetVehicle(cmp2->index);
|
2004-09-06 18:15:13 +00:00
|
|
|
char buf1[64] = "\0";
|
|
|
|
int r;
|
|
|
|
|
2004-09-06 21:20:01 +00:00
|
|
|
if (va->string_id != _internal_name_sorter_id) {
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, va->string_id);
|
2005-01-15 01:52:23 +00:00
|
|
|
GetString(buf1, STR_JUST_STRING);
|
2004-09-06 18:15:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( cmp2->index != _last_vehicle_idx) {
|
|
|
|
_last_vehicle_idx = cmp2->index;
|
|
|
|
_bufcache[0] = '\0';
|
2004-09-06 21:20:01 +00:00
|
|
|
if (vb->string_id != _internal_name_sorter_id) {
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, vb->string_id);
|
2005-01-15 01:52:23 +00:00
|
|
|
GetString(_bufcache, STR_JUST_STRING);
|
2004-09-06 18:15:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
r = strcmp(buf1, _bufcache); // sort by name
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-09-14 14:19:53 +00:00
|
|
|
VEHICLEUNITNUMBERSORTER(r, va, vb);
|
2004-09-06 21:20:01 +00:00
|
|
|
|
|
|
|
return (_internal_sort_order & 1) ? -r : r;
|
2004-09-06 18:15:13 +00:00
|
|
|
}
|
|
|
|
|
2005-09-26 13:38:12 +00:00
|
|
|
static int CDECL VehicleAgeSorter(const void *a, const void *b)
|
2004-09-06 18:15:13 +00:00
|
|
|
{
|
2005-01-06 22:31:58 +00:00
|
|
|
const Vehicle *va = GetVehicle((*(const SortStruct*)a).index);
|
|
|
|
const Vehicle *vb = GetVehicle((*(const SortStruct*)b).index);
|
2004-09-06 21:20:01 +00:00
|
|
|
int r = va->age - vb->age;
|
2004-09-06 18:15:13 +00:00
|
|
|
|
2004-09-14 14:19:53 +00:00
|
|
|
VEHICLEUNITNUMBERSORTER(r, va, vb);
|
2004-09-06 21:20:01 +00:00
|
|
|
|
|
|
|
return (_internal_sort_order & 1) ? -r : r;
|
|
|
|
}
|
|
|
|
|
2005-09-26 13:38:12 +00:00
|
|
|
static int CDECL VehicleProfitThisYearSorter(const void *a, const void *b)
|
2004-09-06 21:20:01 +00:00
|
|
|
{
|
2005-01-06 22:31:58 +00:00
|
|
|
const Vehicle *va = GetVehicle((*(const SortStruct*)a).index);
|
|
|
|
const Vehicle *vb = GetVehicle((*(const SortStruct*)b).index);
|
2004-09-06 21:20:01 +00:00
|
|
|
int r = va->profit_this_year - vb->profit_this_year;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-09-14 14:19:53 +00:00
|
|
|
VEHICLEUNITNUMBERSORTER(r, va, vb);
|
2004-09-06 21:20:01 +00:00
|
|
|
|
|
|
|
return (_internal_sort_order & 1) ? -r : r;
|
|
|
|
}
|
|
|
|
|
2005-09-26 13:38:12 +00:00
|
|
|
static int CDECL VehicleProfitLastYearSorter(const void *a, const void *b)
|
2004-09-06 21:20:01 +00:00
|
|
|
{
|
2005-01-06 22:31:58 +00:00
|
|
|
const Vehicle *va = GetVehicle((*(const SortStruct*)a).index);
|
|
|
|
const Vehicle *vb = GetVehicle((*(const SortStruct*)b).index);
|
2004-09-06 21:20:01 +00:00
|
|
|
int r = va->profit_last_year - vb->profit_last_year;
|
|
|
|
|
2004-09-14 14:19:53 +00:00
|
|
|
VEHICLEUNITNUMBERSORTER(r, va, vb);
|
2004-09-06 21:20:01 +00:00
|
|
|
|
|
|
|
return (_internal_sort_order & 1) ? -r : r;
|
|
|
|
}
|
|
|
|
|
2005-09-26 13:38:12 +00:00
|
|
|
static int CDECL VehicleCargoSorter(const void *a, const void *b)
|
2004-09-06 21:20:01 +00:00
|
|
|
{
|
2005-10-23 13:04:44 +00:00
|
|
|
const Vehicle* va = GetVehicle(((const SortStruct*)a)->index);
|
|
|
|
const Vehicle* vb = GetVehicle(((const SortStruct*)b)->index);
|
|
|
|
const Vehicle* v;
|
|
|
|
AcceptedCargo cargoa;
|
|
|
|
AcceptedCargo cargob;
|
2004-09-06 21:20:01 +00:00
|
|
|
int r = 0;
|
|
|
|
int i;
|
|
|
|
|
2005-10-23 13:04:44 +00:00
|
|
|
memset(cargoa, 0, sizeof(cargoa));
|
|
|
|
memset(cargob, 0, sizeof(cargob));
|
|
|
|
for (v = va; v != NULL; v = v->next) cargoa[v->cargo_type] += v->cargo_cap;
|
|
|
|
for (v = vb; v != NULL; v = v->next) cargob[v->cargo_type] += v->cargo_cap;
|
2004-09-06 21:20:01 +00:00
|
|
|
|
|
|
|
for (i = 0; i < NUM_CARGO; i++) {
|
2005-10-23 13:04:44 +00:00
|
|
|
r = cargoa[i] - cargob[i];
|
|
|
|
if (r != 0) break;
|
2004-09-06 18:15:13 +00:00
|
|
|
}
|
2004-09-06 21:20:01 +00:00
|
|
|
|
2004-12-11 11:00:54 +00:00
|
|
|
VEHICLEUNITNUMBERSORTER(r, va, vb);
|
|
|
|
|
2004-09-06 21:20:01 +00:00
|
|
|
return (_internal_sort_order & 1) ? -r : r;
|
|
|
|
}
|
|
|
|
|
2005-09-26 13:38:12 +00:00
|
|
|
static int CDECL VehicleReliabilitySorter(const void *a, const void *b)
|
2004-09-06 21:20:01 +00:00
|
|
|
{
|
2005-01-06 22:31:58 +00:00
|
|
|
const Vehicle *va = GetVehicle((*(const SortStruct*)a).index);
|
|
|
|
const Vehicle *vb = GetVehicle((*(const SortStruct*)b).index);
|
2004-09-06 21:20:01 +00:00
|
|
|
int r = va->reliability - vb->reliability;
|
|
|
|
|
2004-09-14 14:19:53 +00:00
|
|
|
VEHICLEUNITNUMBERSORTER(r, va, vb);
|
2004-09-06 21:20:01 +00:00
|
|
|
|
|
|
|
return (_internal_sort_order & 1) ? -r : r;
|
2004-09-06 18:15:13 +00:00
|
|
|
}
|
2004-09-06 21:20:01 +00:00
|
|
|
|
2005-09-26 13:38:12 +00:00
|
|
|
static int CDECL VehicleMaxSpeedSorter(const void *a, const void *b)
|
2004-09-06 21:20:01 +00:00
|
|
|
{
|
2005-01-06 22:31:58 +00:00
|
|
|
const Vehicle *va = GetVehicle((*(const SortStruct*)a).index);
|
|
|
|
const Vehicle *vb = GetVehicle((*(const SortStruct*)b).index);
|
2005-01-26 12:51:04 +00:00
|
|
|
int max_speed_a = 0xFFFF, max_speed_b = 0xFFFF;
|
|
|
|
int r;
|
|
|
|
const Vehicle *ua = va, *ub = vb;
|
|
|
|
|
2005-01-27 11:33:14 +00:00
|
|
|
if (va->type == VEH_Train && vb->type == VEH_Train) {
|
|
|
|
do {
|
|
|
|
if (RailVehInfo(ua->engine_type)->max_speed != 0)
|
|
|
|
max_speed_a = min(max_speed_a, RailVehInfo(ua->engine_type)->max_speed);
|
|
|
|
} while ((ua = ua->next) != NULL);
|
2005-01-26 12:51:04 +00:00
|
|
|
|
2005-01-27 11:33:14 +00:00
|
|
|
do {
|
|
|
|
if (RailVehInfo(ub->engine_type)->max_speed != 0)
|
|
|
|
max_speed_b = min(max_speed_b, RailVehInfo(ub->engine_type)->max_speed);
|
|
|
|
} while ((ub = ub->next) != NULL);
|
|
|
|
|
|
|
|
r = max_speed_a - max_speed_b;
|
|
|
|
} else {
|
|
|
|
r = va->max_speed - vb->max_speed;
|
|
|
|
}
|
2004-09-06 21:20:01 +00:00
|
|
|
|
2004-09-14 14:19:53 +00:00
|
|
|
VEHICLEUNITNUMBERSORTER(r, va, vb);
|
2004-09-06 21:20:01 +00:00
|
|
|
|
|
|
|
return (_internal_sort_order & 1) ? -r : r;
|
2004-09-10 19:02:27 +00:00
|
|
|
}
|
2005-01-02 17:23:04 +00:00
|
|
|
|
|
|
|
// this define is to match engine.c, but engine.c keeps it to itself
|
|
|
|
// ENGINE_AVAILABLE is used in ReplaceVehicleWndProc
|
2005-10-18 11:23:58 +00:00
|
|
|
#define ENGINE_AVAILABLE ((e->flags & 1 && HASBIT(info->climates, _opt.landscape)) || HASBIT(e->player_avail, _local_player))
|
2005-01-02 17:23:04 +00:00
|
|
|
|
|
|
|
/* if show_outdated is selected, it do not sort psudo engines properly but it draws all engines
|
2005-01-03 19:45:18 +00:00
|
|
|
* if used compined with show_cars set to false, it will work as intended. Replace window do it like that
|
2005-01-02 17:23:04 +00:00
|
|
|
* this was a big hack even before show_outdated was added. Stupid newgrf :p */
|
2005-10-16 09:13:04 +00:00
|
|
|
static void train_engine_drawing_loop(int *x, int *y, int *pos, int *sel, int *selected_id, RailType railtype,
|
2005-01-02 17:23:04 +00:00
|
|
|
uint8 lines_drawn, bool is_engine, bool show_cars, bool show_outdated)
|
|
|
|
{
|
2005-10-01 12:43:34 +00:00
|
|
|
EngineID i;
|
2005-01-02 17:23:04 +00:00
|
|
|
byte colour;
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
for (i = 0; i < NUM_TRAIN_ENGINES; i++) {
|
2005-06-07 18:13:49 +00:00
|
|
|
const Engine *e = GetEngine(i);
|
2005-01-02 17:23:04 +00:00
|
|
|
const RailVehicleInfo *rvi = RailVehInfo(i);
|
|
|
|
const EngineInfo *info = &_engine_info[i];
|
|
|
|
|
2005-01-23 22:01:51 +00:00
|
|
|
if ( _player_num_engines[i] == 0 && show_outdated ) continue;
|
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
if ( rvi->power == 0 && !(show_cars) ) // disables display of cars (works since they do not have power)
|
|
|
|
continue;
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
if (*sel == 0) *selected_id = i;
|
|
|
|
|
|
|
|
|
|
|
|
colour = *sel == 0 ? 0xC : 0x10;
|
|
|
|
if (!(ENGINE_AVAILABLE && show_outdated && RailVehInfo(i)->power && e->railtype == railtype)) {
|
|
|
|
if (e->railtype != railtype || !(rvi->flags & RVI_WAGON) != is_engine ||
|
|
|
|
!HASBIT(e->player_avail, _local_player))
|
|
|
|
continue;
|
2005-01-03 19:45:18 +00:00
|
|
|
} /*else {
|
2005-01-02 17:23:04 +00:00
|
|
|
// TODO find a nice red colour for vehicles being replaced
|
|
|
|
if ( _autoreplace_array[i] != i )
|
|
|
|
colour = *sel == 0 ? 0x44 : 0x45;
|
|
|
|
} */
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
if (IS_INT_INSIDE(--*pos, -lines_drawn, 0)) {
|
|
|
|
DrawString(*x + 59, *y + 2, GetCustomEngineName(i),
|
|
|
|
colour);
|
|
|
|
DrawTrainEngine(*x + 29, *y + 6, i,
|
|
|
|
SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)));
|
2005-01-23 22:01:51 +00:00
|
|
|
if ( show_outdated ) {
|
|
|
|
SetDParam(0, _player_num_engines[i]);
|
|
|
|
DrawStringRightAligned(213, *y+5, STR_TINY_BLACK, 0);
|
|
|
|
}
|
2005-01-02 17:23:04 +00:00
|
|
|
*y += 14;
|
|
|
|
}
|
|
|
|
--*sel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void SetupScrollStuffForReplaceWindow(Window *w)
|
|
|
|
{
|
2005-10-16 09:13:04 +00:00
|
|
|
RailType railtype;
|
2005-01-02 17:23:04 +00:00
|
|
|
int selected_id[2] = {-1,-1};
|
2005-01-06 15:57:26 +00:00
|
|
|
int sel[2];
|
2005-01-02 17:23:04 +00:00
|
|
|
int count = 0;
|
|
|
|
int count2 = 0;
|
2005-10-01 12:43:34 +00:00
|
|
|
EngineID engine_id;
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-01-06 15:57:26 +00:00
|
|
|
sel[0] = WP(w,replaceveh_d).sel_index[0];
|
|
|
|
sel[1] = WP(w,replaceveh_d).sel_index[1];
|
2005-01-06 18:45:28 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
switch (WP(w,replaceveh_d).vehicletype) {
|
|
|
|
case VEH_Train: {
|
2005-01-26 12:42:29 +00:00
|
|
|
railtype = _railtype_selected_in_replace_gui;
|
2005-01-03 21:01:37 +00:00
|
|
|
w->widget[13].color = _player_colors[_local_player]; // sets the colour of that art thing
|
|
|
|
w->widget[16].color = _player_colors[_local_player]; // sets the colour of that art thing
|
2005-01-02 17:23:04 +00:00
|
|
|
for (engine_id = 0; engine_id < NUM_TRAIN_ENGINES; engine_id++) {
|
2005-06-07 18:13:49 +00:00
|
|
|
const Engine *e = GetEngine(engine_id);
|
2005-01-02 17:23:04 +00:00
|
|
|
const EngineInfo *info = &_engine_info[engine_id];
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-01-23 22:01:51 +00:00
|
|
|
if (ENGINE_AVAILABLE && RailVehInfo(engine_id)->power && e->railtype == railtype ) {
|
|
|
|
if ( _player_num_engines[engine_id] ) {
|
|
|
|
if (sel[0]==0) selected_id[0] = engine_id;
|
2005-01-24 08:49:14 +00:00
|
|
|
count++;
|
2005-01-23 22:01:51 +00:00
|
|
|
sel[0]--;
|
|
|
|
}
|
2005-01-02 17:23:04 +00:00
|
|
|
if (HASBIT(e->player_avail, _local_player)) {
|
|
|
|
if (sel[1]==0) selected_id[1] = engine_id;
|
2005-01-23 22:01:51 +00:00
|
|
|
count2++;
|
|
|
|
sel[1]--;
|
2005-01-02 17:23:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-01-23 22:01:51 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-01-02 17:23:04 +00:00
|
|
|
case VEH_Road: {
|
|
|
|
int num = NUM_ROAD_ENGINES;
|
2005-06-07 18:13:49 +00:00
|
|
|
Engine *e = GetEngine(ROAD_ENGINES_INDEX);
|
2005-01-02 17:23:04 +00:00
|
|
|
byte cargo;
|
|
|
|
EngineInfo *info;
|
|
|
|
engine_id = ROAD_ENGINES_INDEX;
|
|
|
|
|
|
|
|
do {
|
|
|
|
info = &_engine_info[engine_id];
|
2005-01-23 22:01:51 +00:00
|
|
|
if (_player_num_engines[engine_id] ) {
|
2005-01-02 17:23:04 +00:00
|
|
|
if (sel[0]==0) selected_id[0] = engine_id;
|
|
|
|
count++;
|
2005-01-03 19:45:18 +00:00
|
|
|
sel[0]--;
|
2005-01-02 17:23:04 +00:00
|
|
|
}
|
|
|
|
} while (++engine_id,++e,--num);
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
if ( selected_id[0] != -1 ) { // only draw right array if we have anything in the left one
|
|
|
|
num = NUM_ROAD_ENGINES;
|
|
|
|
engine_id = ROAD_ENGINES_INDEX;
|
2005-06-07 18:13:49 +00:00
|
|
|
e = GetEngine(ROAD_ENGINES_INDEX);
|
2005-01-02 17:23:04 +00:00
|
|
|
cargo = RoadVehInfo(selected_id[0])->cargo_type;
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
do {
|
|
|
|
if ( cargo == RoadVehInfo(engine_id)->cargo_type && HASBIT(e->player_avail, _local_player)) {
|
|
|
|
count2++;
|
|
|
|
if (sel[1]==0) selected_id[1] = engine_id;
|
|
|
|
sel[1]--;
|
|
|
|
}
|
|
|
|
} while (++engine_id,++e,--num);
|
2005-01-03 19:45:18 +00:00
|
|
|
}
|
2005-01-02 17:23:04 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
case VEH_Ship: {
|
|
|
|
int num = NUM_SHIP_ENGINES;
|
2005-06-07 18:13:49 +00:00
|
|
|
Engine *e = GetEngine(SHIP_ENGINES_INDEX);
|
2005-01-03 19:45:18 +00:00
|
|
|
byte cargo, refittable;
|
2005-01-02 17:23:04 +00:00
|
|
|
EngineInfo *info;
|
|
|
|
engine_id = SHIP_ENGINES_INDEX;
|
|
|
|
|
|
|
|
do {
|
|
|
|
info = &_engine_info[engine_id];
|
2005-01-23 22:01:51 +00:00
|
|
|
if (_player_num_engines[engine_id] ) {
|
2005-01-02 17:23:04 +00:00
|
|
|
if ( sel[0] == 0 ) selected_id[0] = engine_id;
|
|
|
|
count++;
|
2005-01-03 19:45:18 +00:00
|
|
|
sel[0]--;
|
2005-01-02 17:23:04 +00:00
|
|
|
}
|
|
|
|
} while (++engine_id,++e,--num);
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
if ( selected_id[0] != -1 ) {
|
|
|
|
num = NUM_SHIP_ENGINES;
|
2005-06-07 18:13:49 +00:00
|
|
|
e = GetEngine(SHIP_ENGINES_INDEX);
|
2005-01-02 17:23:04 +00:00
|
|
|
engine_id = SHIP_ENGINES_INDEX;
|
|
|
|
cargo = ShipVehInfo(selected_id[0])->cargo_type;
|
|
|
|
refittable = ShipVehInfo(selected_id[0])->refittable;
|
2005-01-03 19:45:18 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
if (HASBIT(e->player_avail, _local_player)
|
2005-01-02 17:23:04 +00:00
|
|
|
&& ( cargo == ShipVehInfo(engine_id)->cargo_type || refittable & ShipVehInfo(engine_id)->refittable)) {
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
if ( sel[1]==0) selected_id[1] = engine_id;
|
|
|
|
sel[1]--;
|
|
|
|
count2++;
|
|
|
|
}
|
|
|
|
} while (++engine_id,++e,--num);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
} //end of ship
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
case VEH_Aircraft:{
|
|
|
|
int num = NUM_AIRCRAFT_ENGINES;
|
2005-01-02 17:39:01 +00:00
|
|
|
byte subtype;
|
2005-06-07 18:13:49 +00:00
|
|
|
Engine *e = GetEngine(AIRCRAFT_ENGINES_INDEX);
|
2005-01-02 17:23:04 +00:00
|
|
|
EngineInfo *info;
|
|
|
|
engine_id = AIRCRAFT_ENGINES_INDEX;
|
|
|
|
|
|
|
|
do {
|
|
|
|
info = &_engine_info[engine_id];
|
2005-01-23 22:01:51 +00:00
|
|
|
if (_player_num_engines[engine_id]) {
|
2005-01-02 17:23:04 +00:00
|
|
|
count++;
|
|
|
|
if (sel[0]==0) selected_id[0] = engine_id;
|
|
|
|
sel[0]--;
|
|
|
|
}
|
|
|
|
} while (++engine_id,++e,--num);
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
if ( selected_id[0] != -1 ) {
|
|
|
|
num = NUM_AIRCRAFT_ENGINES;
|
2005-06-07 18:13:49 +00:00
|
|
|
e = GetEngine(AIRCRAFT_ENGINES_INDEX);
|
2005-01-02 17:23:04 +00:00
|
|
|
subtype = AircraftVehInfo(selected_id[0])->subtype;
|
|
|
|
engine_id = AIRCRAFT_ENGINES_INDEX;
|
|
|
|
do {
|
|
|
|
if (HASBIT(e->player_avail, _local_player)) {
|
2005-01-26 18:18:00 +00:00
|
|
|
if (HASBIT(subtype, 0) == HASBIT(AircraftVehInfo(engine_id)->subtype, 0)) {
|
2005-01-02 17:23:04 +00:00
|
|
|
count2++;
|
|
|
|
if (sel[1]==0) selected_id[1] = engine_id;
|
|
|
|
sel[1]--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (++engine_id,++e,--num);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// sets up the number of items in each list
|
|
|
|
SetVScrollCount(w, count);
|
|
|
|
SetVScroll2Count(w, count2);
|
|
|
|
WP(w,replaceveh_d).sel_engine[0] = selected_id[0];
|
|
|
|
WP(w,replaceveh_d).sel_engine[1] = selected_id[1];
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
WP(w,replaceveh_d).count[0] = count;
|
|
|
|
WP(w,replaceveh_d).count[1] = count2;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void DrawEngineArrayInReplaceWindow(Window *w, int x, int y, int x2, int y2, int pos, int pos2,
|
2005-01-03 19:45:18 +00:00
|
|
|
int sel1, int sel2, int selected_id1, int selected_id2)
|
2005-01-02 17:23:04 +00:00
|
|
|
{
|
2005-01-06 15:57:26 +00:00
|
|
|
int sel[2];
|
|
|
|
int selected_id[2];
|
|
|
|
|
|
|
|
sel[0] = sel1;
|
|
|
|
sel[1] = sel2;
|
2005-01-06 18:45:28 +00:00
|
|
|
|
2005-01-06 15:57:26 +00:00
|
|
|
selected_id[0] = selected_id1;
|
|
|
|
selected_id[1] = selected_id2;
|
2005-01-06 18:45:28 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
switch (WP(w,replaceveh_d).vehicletype) {
|
|
|
|
case VEH_Train: {
|
2005-10-16 09:13:04 +00:00
|
|
|
RailType railtype = _railtype_selected_in_replace_gui;
|
2005-06-07 01:21:56 +00:00
|
|
|
DrawString(157, 99 + (14 * w->vscroll.cap), _rail_types_list[railtype], 0x10);
|
2005-01-02 17:23:04 +00:00
|
|
|
/* draw sorting criteria string */
|
|
|
|
|
|
|
|
/* Ensure that custom engines which substituted wagons
|
|
|
|
* are sorted correctly.
|
|
|
|
* XXX - DO NOT EVER DO THIS EVER AGAIN! GRRR hacking in wagons as
|
|
|
|
* engines to get more types.. Stays here until we have our own format
|
|
|
|
* then it is exit!!! */
|
|
|
|
train_engine_drawing_loop(&x, &y, &pos, &sel[0], &selected_id[0], railtype, w->vscroll.cap, true, false, true); // True engines
|
|
|
|
train_engine_drawing_loop(&x2, &y2, &pos2, &sel[1], &selected_id[1], railtype, w->vscroll.cap, true, false, false); // True engines
|
|
|
|
train_engine_drawing_loop(&x2, &y2, &pos2, &sel[1], &selected_id[1], railtype, w->vscroll.cap, false, false, false); // Feeble wagons
|
|
|
|
break;
|
|
|
|
}
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
case VEH_Road: {
|
|
|
|
int num = NUM_ROAD_ENGINES;
|
2005-06-07 18:13:49 +00:00
|
|
|
Engine *e = GetEngine(ROAD_ENGINES_INDEX);
|
2005-10-01 12:43:34 +00:00
|
|
|
EngineID engine_id = ROAD_ENGINES_INDEX;
|
2005-01-02 17:23:04 +00:00
|
|
|
byte cargo;
|
|
|
|
EngineInfo *info;
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-01-02 22:28:56 +00:00
|
|
|
if ( selected_id[0] >= ROAD_ENGINES_INDEX && selected_id[0] <= SHIP_ENGINES_INDEX ) {
|
2005-01-03 19:45:18 +00:00
|
|
|
cargo = RoadVehInfo(selected_id[0])->cargo_type;
|
2005-01-02 17:23:04 +00:00
|
|
|
|
2005-01-02 22:28:56 +00:00
|
|
|
do {
|
|
|
|
info = &_engine_info[engine_id];
|
2005-01-23 22:01:51 +00:00
|
|
|
if (_player_num_engines[engine_id]) {
|
2005-01-02 22:28:56 +00:00
|
|
|
if (IS_INT_INSIDE(--pos, -w->vscroll.cap, 0)) {
|
|
|
|
DrawString(x+59, y+2, GetCustomEngineName(engine_id), sel[0]==0 ? 0xC : 0x10);
|
|
|
|
DrawRoadVehEngine(x+29, y+6, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)));
|
2005-01-23 22:01:51 +00:00
|
|
|
SetDParam(0, _player_num_engines[engine_id]);
|
|
|
|
DrawStringRightAligned(213, y+5, STR_TINY_BLACK, 0);
|
2005-01-02 22:28:56 +00:00
|
|
|
y += 14;
|
2005-01-02 17:23:04 +00:00
|
|
|
}
|
2005-01-23 22:01:51 +00:00
|
|
|
sel[0]--;
|
|
|
|
}
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-01-23 22:01:51 +00:00
|
|
|
if ( RoadVehInfo(engine_id)->cargo_type == cargo && HASBIT(e->player_avail, _local_player) ) {
|
|
|
|
if (IS_INT_INSIDE(--pos2, -w->vscroll.cap, 0) && RoadVehInfo(engine_id)->cargo_type == cargo) {
|
|
|
|
DrawString(x2+59, y2+2, GetCustomEngineName(engine_id), sel[1]==0 ? 0xC : 0x10);
|
|
|
|
DrawRoadVehEngine(x2+29, y2+6, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)));
|
|
|
|
y2 += 14;
|
2005-01-02 22:28:56 +00:00
|
|
|
}
|
2005-01-23 22:01:51 +00:00
|
|
|
sel[1]--;
|
2005-01-02 17:23:04 +00:00
|
|
|
}
|
2005-01-02 22:28:56 +00:00
|
|
|
} while (++engine_id, ++e,--num);
|
|
|
|
}
|
2005-01-02 17:23:04 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
case VEH_Ship: {
|
|
|
|
int num = NUM_SHIP_ENGINES;
|
2005-06-07 18:13:49 +00:00
|
|
|
Engine *e = GetEngine(SHIP_ENGINES_INDEX);
|
2005-10-01 12:43:34 +00:00
|
|
|
EngineID engine_id = SHIP_ENGINES_INDEX;
|
2005-01-03 19:45:18 +00:00
|
|
|
byte cargo, refittable;
|
2005-01-02 17:23:04 +00:00
|
|
|
EngineInfo *info;
|
|
|
|
|
|
|
|
if ( selected_id[0] != -1 ) {
|
|
|
|
cargo = ShipVehInfo(selected_id[0])->cargo_type;
|
|
|
|
refittable = ShipVehInfo(selected_id[0])->refittable;
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-01-02 22:28:56 +00:00
|
|
|
do {
|
|
|
|
info = &_engine_info[engine_id];
|
2005-01-23 22:01:51 +00:00
|
|
|
if (_player_num_engines[engine_id]) {
|
2005-01-02 22:28:56 +00:00
|
|
|
if (IS_INT_INSIDE(--pos, -w->vscroll.cap, 0)) {
|
|
|
|
DrawString(x+75, y+7, GetCustomEngineName(engine_id), sel[0]==0 ? 0xC : 0x10);
|
|
|
|
DrawShipEngine(x+35, y+10, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)));
|
2005-01-23 22:01:51 +00:00
|
|
|
SetDParam(0, _player_num_engines[engine_id]);
|
|
|
|
DrawStringRightAligned(213, y+15, STR_TINY_BLACK, 0);
|
2005-01-02 22:28:56 +00:00
|
|
|
y += 24;
|
|
|
|
}
|
2005-01-23 22:01:51 +00:00
|
|
|
sel[0]--;
|
|
|
|
}
|
|
|
|
if ( selected_id[0] != -1 ) {
|
|
|
|
if (HASBIT(e->player_avail, _local_player) && ( cargo == ShipVehInfo(engine_id)->cargo_type || refittable & ShipVehInfo(engine_id)->refittable)) {
|
|
|
|
if (IS_INT_INSIDE(--pos2, -w->vscroll.cap, 0)) {
|
|
|
|
DrawString(x2+75, y2+7, GetCustomEngineName(engine_id), sel[1]==0 ? 0xC : 0x10);
|
|
|
|
DrawShipEngine(x2+35, y2+10, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)));
|
|
|
|
y2 += 24;
|
2005-01-02 17:23:04 +00:00
|
|
|
}
|
2005-01-23 22:01:51 +00:00
|
|
|
sel[1]--;
|
2005-01-02 17:23:04 +00:00
|
|
|
}
|
|
|
|
}
|
2005-01-02 22:28:56 +00:00
|
|
|
} while (++engine_id, ++e,--num);
|
|
|
|
}
|
|
|
|
break;
|
2005-01-02 17:23:04 +00:00
|
|
|
} //end of ship
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
case VEH_Aircraft: {
|
|
|
|
if ( selected_id[0] != -1 ) {
|
|
|
|
int num = NUM_AIRCRAFT_ENGINES;
|
2005-06-07 18:13:49 +00:00
|
|
|
Engine *e = GetEngine(AIRCRAFT_ENGINES_INDEX);
|
2005-10-01 12:43:34 +00:00
|
|
|
EngineID engine_id = AIRCRAFT_ENGINES_INDEX;
|
2005-01-02 17:23:04 +00:00
|
|
|
byte subtype = AircraftVehInfo(selected_id[0])->subtype;
|
|
|
|
EngineInfo *info;
|
|
|
|
|
|
|
|
do {
|
|
|
|
info = &_engine_info[engine_id];
|
2005-01-23 22:01:51 +00:00
|
|
|
if (_player_num_engines[engine_id]) {
|
2005-01-02 17:23:04 +00:00
|
|
|
if (sel[0]==0) selected_id[0] = engine_id;
|
|
|
|
if (IS_INT_INSIDE(--pos, -w->vscroll.cap, 0)) {
|
|
|
|
DrawString(x+62, y+7, GetCustomEngineName(engine_id), sel[0]==0 ? 0xC : 0x10);
|
|
|
|
DrawAircraftEngine(x+29, y+10, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)));
|
2005-01-23 22:01:51 +00:00
|
|
|
SetDParam(0, _player_num_engines[engine_id]);
|
|
|
|
DrawStringRightAligned(213, y+15, STR_TINY_BLACK, 0);
|
2005-01-02 17:23:04 +00:00
|
|
|
y += 24;
|
|
|
|
}
|
2005-01-23 22:01:51 +00:00
|
|
|
sel[0]--;
|
|
|
|
}
|
2005-01-26 18:18:00 +00:00
|
|
|
if ( (HASBIT(subtype, 0) == HASBIT(AircraftVehInfo(engine_id)->subtype, 0))
|
2005-01-23 22:01:51 +00:00
|
|
|
&& HASBIT(e->player_avail, _local_player) ) {
|
|
|
|
if (sel[1]==0) selected_id[1] = engine_id;
|
|
|
|
if (IS_INT_INSIDE(--pos2, -w->vscroll.cap, 0)) {
|
|
|
|
DrawString(x2+62, y2+7, GetCustomEngineName(engine_id), sel[1]==0 ? 0xC : 0x10);
|
|
|
|
DrawAircraftEngine(x2+29, y2+10, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)));
|
|
|
|
y2 += 24;
|
2005-01-02 17:23:04 +00:00
|
|
|
}
|
2005-01-23 22:01:51 +00:00
|
|
|
sel[1]--;
|
2005-01-02 17:23:04 +00:00
|
|
|
}
|
|
|
|
} while (++engine_id, ++e,--num);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
} // end of aircraft
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
static void ReplaceVehicleWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2005-08-29 22:27:22 +00:00
|
|
|
static const StringID _vehicle_type_names[4] = {STR_019F_TRAIN, STR_019C_ROAD_VEHICLE, STR_019E_SHIP,STR_019D_AIRCRAFT};
|
|
|
|
|
|
|
|
switch (e->event) {
|
|
|
|
case WE_PAINT: {
|
|
|
|
const Player *p = GetPlayer(_local_player);
|
2005-01-02 17:23:04 +00:00
|
|
|
int pos = w->vscroll.pos;
|
|
|
|
int selected_id[2] = {-1,-1};
|
|
|
|
int x = 1;
|
|
|
|
int y = 15;
|
|
|
|
int pos2 = w->vscroll2.pos;
|
|
|
|
int x2 = 1 + 228;
|
|
|
|
int y2 = 15;
|
2005-01-06 15:57:26 +00:00
|
|
|
int sel[2];
|
|
|
|
sel[0] = WP(w,replaceveh_d).sel_index[0];
|
|
|
|
sel[1] = WP(w,replaceveh_d).sel_index[1];
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-01-23 22:01:51 +00:00
|
|
|
{
|
|
|
|
uint i;
|
|
|
|
const Vehicle *vehicle;
|
|
|
|
|
|
|
|
for (i = 0; i < lengthof(_player_num_engines); i++) {
|
|
|
|
_player_num_engines[i] = 0;
|
|
|
|
}
|
|
|
|
FOR_ALL_VEHICLES(vehicle) {
|
|
|
|
if ( vehicle->owner == _local_player ) {
|
|
|
|
if (vehicle->type == VEH_Aircraft && vehicle->subtype > 2) continue;
|
|
|
|
|
|
|
|
// do not count the vehicles, that contains only 0 in all var
|
|
|
|
if (vehicle->engine_type == 0 && vehicle->spritenum == 0 ) continue;
|
|
|
|
|
2005-06-07 18:13:49 +00:00
|
|
|
if (vehicle->type != GetEngine(vehicle->engine_type)->type) continue;
|
2005-01-23 22:01:51 +00:00
|
|
|
|
|
|
|
_player_num_engines[vehicle->engine_type]++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
SetupScrollStuffForReplaceWindow(w);
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
selected_id[0] = WP(w,replaceveh_d).sel_engine[0];
|
|
|
|
selected_id[1] = WP(w,replaceveh_d).sel_engine[1];
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
// sets the selected left item to the top one if it's greater than the number of vehicles in the left side
|
|
|
|
|
|
|
|
if ( WP(w,replaceveh_d).count[0] <= sel[0] ) {
|
|
|
|
if (WP(w,replaceveh_d).count[0]) {
|
|
|
|
sel[0] = 0;
|
|
|
|
WP(w,replaceveh_d).sel_index[0] = 0;
|
|
|
|
w->vscroll.pos = 0;
|
|
|
|
// now we go back to set selected_id[1] properly
|
|
|
|
SetWindowDirty(w);
|
|
|
|
return;
|
|
|
|
} else { //there are no vehicles in the left window
|
|
|
|
selected_id[1] = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( WP(w,replaceveh_d).count[1] <= sel[1] ) {
|
|
|
|
if (WP(w,replaceveh_d).count[1]) {
|
|
|
|
sel[1] = 0;
|
|
|
|
WP(w,replaceveh_d).sel_index[1] = 0;
|
|
|
|
w->vscroll2.pos = 0;
|
|
|
|
// now we go back to set selected_id[1] properly
|
|
|
|
SetWindowDirty(w);
|
|
|
|
return;
|
|
|
|
} else { //there are no vehicles in the right window
|
|
|
|
selected_id[1] = -1;
|
|
|
|
}
|
|
|
|
}
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-10-25 19:52:25 +00:00
|
|
|
// Disable the "Start Replacing" button if:
|
|
|
|
// Either list is empty
|
|
|
|
// or Both lists have the same vehicle selected
|
|
|
|
// or The right list (new replacement) has the existing replacement vehicle selected
|
|
|
|
if (selected_id[0] == -1 || selected_id[1] == -1 ||
|
|
|
|
selected_id[0] == selected_id[1] ||
|
|
|
|
p->engine_replacement[selected_id[0]] == selected_id[1])
|
2005-01-02 17:23:04 +00:00
|
|
|
SETBIT(w->disabled_state, 4);
|
|
|
|
else
|
|
|
|
CLRBIT(w->disabled_state, 4);
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-10-25 19:52:25 +00:00
|
|
|
// Disable the "Stop Replacing" button if:
|
|
|
|
// The left list (existing vehicle) is empty
|
|
|
|
// or The selected vehicle has no replacement set up
|
|
|
|
if (selected_id[0] == -1 ||
|
|
|
|
p->engine_replacement[selected_id[0]] == INVALID_ENGINE)
|
2005-01-02 17:23:04 +00:00
|
|
|
SETBIT(w->disabled_state, 6);
|
|
|
|
else
|
|
|
|
CLRBIT(w->disabled_state, 6);
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
// now the actual drawing of the window itself takes place
|
2005-08-29 22:27:22 +00:00
|
|
|
SetDParam(0, _vehicle_type_names[WP(w, replaceveh_d).vehicletype - VEH_Train]);
|
2005-01-02 17:23:04 +00:00
|
|
|
DrawWindowWidgets(w);
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
// sets up the string for the vehicle that is being replaced to
|
|
|
|
if ( selected_id[0] != -1 ) {
|
2005-08-06 16:07:22 +00:00
|
|
|
if (p->engine_replacement[selected_id[0]] == INVALID_ENGINE)
|
2005-01-02 17:23:04 +00:00
|
|
|
SetDParam(0, STR_NOT_REPLACING);
|
|
|
|
else
|
2005-08-06 16:07:22 +00:00
|
|
|
SetDParam(0, GetCustomEngineName(p->engine_replacement[selected_id[0]]));
|
2005-01-02 17:23:04 +00:00
|
|
|
} else {
|
|
|
|
SetDParam(0, STR_NOT_REPLACING_VEHICLE_SELECTED);
|
|
|
|
}
|
2005-01-03 19:45:18 +00:00
|
|
|
|
|
|
|
|
2005-08-29 22:27:22 +00:00
|
|
|
DrawString(145, (w->resize.step_height == 24 ? 67 : 87 ) + ( w->resize.step_height * w->vscroll.cap), STR_02BD, 0x10);
|
2005-01-02 17:23:04 +00:00
|
|
|
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
/* now we draw the two arrays according to what we just counted */
|
|
|
|
DrawEngineArrayInReplaceWindow(w, x, y, x2, y2, pos, pos2, sel[0], sel[1], selected_id[0], selected_id[1]);
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
WP(w,replaceveh_d).sel_engine[0] = selected_id[0];
|
|
|
|
WP(w,replaceveh_d).sel_engine[1] = selected_id[1];
|
|
|
|
/* now we draw the info about the vehicles we selected */
|
|
|
|
switch (WP(w,replaceveh_d).vehicletype) {
|
|
|
|
case VEH_Train: {
|
|
|
|
byte i = 0;
|
|
|
|
int offset = 0;
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
for ( i = 0 ; i < 2 ; i++) {
|
|
|
|
if ( i )
|
|
|
|
offset = 228;
|
|
|
|
if (selected_id[i] != -1) {
|
|
|
|
if (!(RailVehInfo(selected_id[i])->flags & RVI_WAGON)) {
|
|
|
|
/* it's an engine */
|
2005-06-05 23:01:10 +00:00
|
|
|
DrawTrainEnginePurchaseInfo(2 + offset, 15 + (14 * w->vscroll.cap), selected_id[i]);
|
2005-01-02 17:23:04 +00:00
|
|
|
} else {
|
|
|
|
/* it's a wagon. Train cars are not replaced with the current GUI, but this code is ready for newgrf if anybody adds that*/
|
2005-06-05 23:01:10 +00:00
|
|
|
DrawTrainWagonPurchaseInfo(2 + offset, 15 + (14 * w->vscroll.cap), selected_id[i]);
|
2005-01-02 17:23:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
} //end if case VEH_Train
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
case VEH_Road: {
|
|
|
|
if (selected_id[0] != -1) {
|
2005-06-05 23:01:10 +00:00
|
|
|
DrawRoadVehPurchaseInfo(2, 15 + (14 * w->vscroll.cap), selected_id[0]);
|
2005-01-02 17:23:04 +00:00
|
|
|
if (selected_id[1] != -1) {
|
2005-06-05 23:01:10 +00:00
|
|
|
DrawRoadVehPurchaseInfo(2 + 228, 15 + (14 * w->vscroll.cap), selected_id[1]);
|
2005-01-02 17:23:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
} // end of VEH_Road
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
case VEH_Ship: {
|
|
|
|
if (selected_id[0] != -1) {
|
2005-06-05 23:01:10 +00:00
|
|
|
DrawShipPurchaseInfo(2, 15 + (24 * w->vscroll.cap), selected_id[0]);
|
2005-01-02 17:23:04 +00:00
|
|
|
if (selected_id[1] != -1) {
|
2005-06-05 23:01:10 +00:00
|
|
|
DrawShipPurchaseInfo(2 + 228, 15 + (24 * w->vscroll.cap), selected_id[1]);
|
2005-01-02 17:23:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2005-01-03 19:45:18 +00:00
|
|
|
} // end of VEH_Ship
|
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
case VEH_Aircraft: {
|
|
|
|
if (selected_id[0] != -1) {
|
2005-06-05 23:01:10 +00:00
|
|
|
DrawAircraftPurchaseInfo(2, 15 + (24 * w->vscroll.cap), selected_id[0]);
|
2005-01-02 17:23:04 +00:00
|
|
|
if (selected_id[1] != -1) {
|
2005-06-05 23:01:10 +00:00
|
|
|
DrawAircraftPurchaseInfo(2 + 228, 15 + (24 * w->vscroll.cap), selected_id[1]);
|
2005-01-02 17:23:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
} // end of VEH_Aircraft
|
|
|
|
}
|
2005-03-08 21:47:22 +00:00
|
|
|
} break; // end of paint
|
2005-01-02 17:23:04 +00:00
|
|
|
|
|
|
|
case WE_CLICK: {
|
2005-08-29 22:27:22 +00:00
|
|
|
// these 3 variables is used if any of the lists is clicked
|
|
|
|
uint16 click_scroll_pos = w->vscroll2.pos;
|
|
|
|
uint16 click_scroll_cap = w->vscroll2.cap;
|
|
|
|
byte click_side = 1;
|
|
|
|
|
|
|
|
switch (e->click.widget) {
|
2005-07-27 10:11:45 +00:00
|
|
|
case 14: case 15: { /* Select sorting criteria dropdown menu */
|
2005-09-23 07:44:03 +00:00
|
|
|
ShowDropDownMenu(w, _rail_types_list, _railtype_selected_in_replace_gui, 15, 0, ~GetPlayer(_local_player)->avail_railtypes);
|
2005-01-03 20:52:09 +00:00
|
|
|
break;
|
2005-01-02 17:23:04 +00:00
|
|
|
}
|
2005-08-06 16:07:22 +00:00
|
|
|
case 4: { /* Start replacing */
|
|
|
|
EngineID veh_from = WP(w, replaceveh_d).sel_engine[0];
|
|
|
|
EngineID veh_to = WP(w, replaceveh_d).sel_engine[1];
|
|
|
|
DoCommandP(0, 3, veh_from + (veh_to << 16), NULL, CMD_REPLACE_VEHICLE);
|
2005-01-02 17:23:04 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
|
|
|
}
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-08-06 16:07:22 +00:00
|
|
|
case 6: { /* Stop replacing */
|
|
|
|
EngineID veh_from = WP(w, replaceveh_d).sel_engine[0];
|
|
|
|
DoCommandP(0, 3, veh_from + (INVALID_ENGINE << 16), NULL, CMD_REPLACE_VEHICLE);
|
2005-01-02 17:23:04 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
|
|
|
}
|
2005-01-03 19:45:18 +00:00
|
|
|
|
|
|
|
case 7:
|
2005-01-02 17:23:04 +00:00
|
|
|
// sets up that the left one was clicked. The default values are for the right one (9)
|
|
|
|
// this way, the code for 9 handles both sides
|
|
|
|
click_scroll_pos = w->vscroll.pos;
|
|
|
|
click_scroll_cap = w->vscroll.cap;
|
|
|
|
click_side = 0;
|
|
|
|
case 9: {
|
2005-01-03 20:52:09 +00:00
|
|
|
uint i = (e->click.pt.y - 14) / w->resize.step_height;
|
2005-01-02 17:23:04 +00:00
|
|
|
if (i < click_scroll_cap) {
|
|
|
|
WP(w,replaceveh_d).sel_index[click_side] = i + click_scroll_pos;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case WE_DROPDOWN_SELECT: { /* we have selected a dropdown item in the list */
|
2005-01-26 12:42:29 +00:00
|
|
|
_railtype_selected_in_replace_gui = e->dropdown.index;
|
2005-01-02 17:23:04 +00:00
|
|
|
SetWindowDirty(w);
|
2005-01-03 19:45:18 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case WE_RESIZE: {
|
|
|
|
w->vscroll.cap += e->sizing.diff.y / (int)w->resize.step_height;
|
|
|
|
w->vscroll2.cap += e->sizing.diff.y / (int)w->resize.step_height;
|
|
|
|
|
|
|
|
w->widget[7].unkA = (w->vscroll.cap << 8) + 1;
|
|
|
|
w->widget[9].unkA = (w->vscroll2.cap << 8) + 1;
|
|
|
|
} break;
|
2005-01-02 17:23:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const Widget _replace_rail_vehicle_widgets[] = {
|
2005-03-08 23:20:47 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
2005-01-03 20:52:09 +00:00
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 443, 0, 13, STR_REPLACE_VEHICLES_WHITE, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
2005-08-29 22:27:22 +00:00
|
|
|
{ WWT_STICKYBOX, RESIZE_NONE, 14, 444, 455, 0, 13, STR_NULL, STR_STICKY_BUTTON},
|
|
|
|
{ WWT_PANEL, RESIZE_TB, 14, 0, 227, 126, 197, STR_NULL, STR_NULL},
|
2005-06-07 01:21:56 +00:00
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 138, 210, 221, STR_REPLACE_VEHICLES_START, STR_REPLACE_HELP_START_BUTTON},
|
2005-08-29 22:27:22 +00:00
|
|
|
{ WWT_PANEL, RESIZE_TB, 14, 139, 316, 198, 209, STR_NULL, STR_REPLACE_HELP_REPLACE_INFO_TAB},
|
2005-06-07 01:21:56 +00:00
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 306, 443, 210, 221, STR_REPLACE_VEHICLES_STOP, STR_REPLACE_HELP_STOP_BUTTON},
|
2005-03-08 23:20:47 +00:00
|
|
|
{ WWT_MATRIX, RESIZE_BOTTOM, 14, 0, 215, 14, 125, 0x801, STR_REPLACE_HELP_LEFT_ARRAY},
|
2005-08-29 22:27:22 +00:00
|
|
|
{ WWT_SCROLLBAR, RESIZE_BOTTOM, 14, 216, 227, 14, 125, STR_NULL, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
2005-03-08 23:20:47 +00:00
|
|
|
{ WWT_MATRIX, RESIZE_BOTTOM, 14, 228, 443, 14, 125, 0x801, STR_REPLACE_HELP_RIGHT_ARRAY},
|
2005-08-29 22:27:22 +00:00
|
|
|
{ WWT_SCROLL2BAR, RESIZE_BOTTOM, 14, 444, 455, 14, 125, STR_NULL, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
|
|
|
{ WWT_PANEL, RESIZE_TB, 14, 228, 455, 126, 197, STR_NULL, STR_NULL},
|
2005-01-03 20:52:09 +00:00
|
|
|
// train specific stuff
|
2005-08-29 22:27:22 +00:00
|
|
|
{ WWT_PANEL, RESIZE_TB, 14, 0, 138, 198, 209, STR_NULL, STR_NULL},
|
|
|
|
{ WWT_PANEL, RESIZE_TB, 14, 139, 153, 210, 221, STR_NULL, STR_NULL},
|
|
|
|
{ WWT_PANEL, RESIZE_TB, 14, 154, 277, 210, 221, STR_NULL, STR_REPLACE_HELP_RAILTYPE},
|
2005-06-07 01:21:56 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_TB, 14, 278, 289, 210, 221, STR_0225, STR_REPLACE_HELP_RAILTYPE},
|
2005-08-29 22:27:22 +00:00
|
|
|
{ WWT_PANEL, RESIZE_TB, 14, 290, 305, 210, 221, STR_NULL, STR_NULL},
|
|
|
|
{ WWT_PANEL, RESIZE_TB, 14, 317, 455, 198, 209, STR_NULL, STR_NULL},
|
2005-01-03 20:52:09 +00:00
|
|
|
// end of train specific stuff
|
2005-08-29 22:27:22 +00:00
|
|
|
{ WWT_RESIZEBOX, RESIZE_TB, 14, 444, 455, 210, 221, STR_NULL, STR_RESIZE_BUTTON},
|
2005-01-02 17:23:04 +00:00
|
|
|
{ WIDGETS_END},
|
|
|
|
};
|
|
|
|
|
|
|
|
static const Widget _replace_road_vehicle_widgets[] = {
|
2005-03-08 23:20:47 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 443, 0, 13, STR_REPLACE_VEHICLES_WHITE, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
2005-08-29 22:27:22 +00:00
|
|
|
{ WWT_STICKYBOX, RESIZE_NONE, 14, 444, 455, 0, 13, STR_NULL, STR_STICKY_BUTTON},
|
|
|
|
{ WWT_PANEL, RESIZE_TB, 14, 0, 227, 126, 197, STR_NULL, STR_NULL},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 138, 198, 209, STR_REPLACE_VEHICLES_START, STR_REPLACE_HELP_START_BUTTON},
|
|
|
|
{ WWT_PANEL, RESIZE_TB, 14, 139, 305, 198, 209, STR_NULL, STR_REPLACE_HELP_REPLACE_INFO_TAB},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 306, 443, 198, 209, STR_REPLACE_VEHICLES_STOP, STR_REPLACE_HELP_STOP_BUTTON},
|
2005-03-08 23:20:47 +00:00
|
|
|
{ WWT_MATRIX, RESIZE_BOTTOM, 14, 0, 215, 14, 125, 0x801, STR_REPLACE_HELP_LEFT_ARRAY},
|
2005-08-29 22:27:22 +00:00
|
|
|
{ WWT_SCROLLBAR, RESIZE_BOTTOM, 14, 216, 227, 14, 125, STR_NULL, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
2005-03-08 23:20:47 +00:00
|
|
|
{ WWT_MATRIX, RESIZE_BOTTOM, 14, 228, 443, 14, 125, 0x801, STR_REPLACE_HELP_RIGHT_ARRAY},
|
2005-08-29 22:27:22 +00:00
|
|
|
{ WWT_SCROLL2BAR, RESIZE_BOTTOM, 14, 444, 455, 14, 125, STR_NULL, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
|
|
|
{ WWT_PANEL, RESIZE_TB, 14, 228, 455, 126, 197, STR_NULL, STR_NULL},
|
|
|
|
{ WWT_RESIZEBOX, RESIZE_TB, 14, 444, 455, 198, 209, STR_NULL, STR_RESIZE_BUTTON},
|
2005-01-02 17:23:04 +00:00
|
|
|
{ WIDGETS_END},
|
|
|
|
};
|
|
|
|
|
|
|
|
static const Widget _replace_ship_aircraft_vehicle_widgets[] = {
|
2005-03-08 23:20:47 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 443, 0, 13, STR_REPLACE_VEHICLES_WHITE, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
2005-08-29 22:27:22 +00:00
|
|
|
{ WWT_STICKYBOX, RESIZE_NONE, 14, 444, 455, 0, 13, STR_NULL, STR_STICKY_BUTTON},
|
|
|
|
{ WWT_PANEL, RESIZE_TB, 14, 0, 227, 110, 161, STR_NULL, STR_NULL},
|
2005-03-08 23:20:47 +00:00
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 138, 162, 173, STR_REPLACE_VEHICLES_START, STR_REPLACE_HELP_START_BUTTON},
|
2005-08-29 22:27:22 +00:00
|
|
|
{ WWT_PANEL, RESIZE_TB, 14, 139, 305, 162, 173, STR_NULL, STR_REPLACE_HELP_REPLACE_INFO_TAB},
|
2005-03-08 23:20:47 +00:00
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 306, 443, 162, 173, STR_REPLACE_VEHICLES_STOP, STR_REPLACE_HELP_STOP_BUTTON},
|
|
|
|
{ WWT_MATRIX, RESIZE_BOTTOM, 14, 0, 215, 14, 109, 0x401, STR_REPLACE_HELP_LEFT_ARRAY},
|
2005-08-29 22:27:22 +00:00
|
|
|
{ WWT_SCROLLBAR, RESIZE_BOTTOM, 14, 216, 227, 14, 109, STR_NULL, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
2005-03-08 23:20:47 +00:00
|
|
|
{ WWT_MATRIX, RESIZE_BOTTOM, 14, 228, 443, 14, 109, 0x401, STR_REPLACE_HELP_RIGHT_ARRAY},
|
2005-08-29 22:27:22 +00:00
|
|
|
{ WWT_SCROLL2BAR, RESIZE_BOTTOM, 14, 444, 455, 14, 109, STR_NULL, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
|
|
|
{ WWT_PANEL, RESIZE_TB, 14, 228, 455, 110, 161, STR_NULL, STR_NULL},
|
|
|
|
{ WWT_RESIZEBOX, RESIZE_TB, 14, 444, 455, 162, 173, STR_NULL, STR_RESIZE_BUTTON},
|
2005-01-02 17:23:04 +00:00
|
|
|
{ WIDGETS_END},
|
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _replace_rail_vehicle_desc = {
|
2005-06-07 01:21:56 +00:00
|
|
|
-1, -1, 456, 222,
|
2005-01-02 17:23:04 +00:00
|
|
|
WC_REPLACE_VEHICLE,0,
|
2005-01-03 19:45:18 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
|
2005-01-02 17:23:04 +00:00
|
|
|
_replace_rail_vehicle_widgets,
|
|
|
|
ReplaceVehicleWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _replace_road_vehicle_desc = {
|
2005-08-29 22:27:22 +00:00
|
|
|
-1, -1, 456, 210,
|
2005-01-02 17:23:04 +00:00
|
|
|
WC_REPLACE_VEHICLE,0,
|
2005-01-03 19:45:18 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
|
2005-01-02 17:23:04 +00:00
|
|
|
_replace_road_vehicle_widgets,
|
|
|
|
ReplaceVehicleWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _replace_ship_aircraft_vehicle_desc = {
|
|
|
|
-1, -1, 456, 174,
|
|
|
|
WC_REPLACE_VEHICLE,0,
|
2005-01-03 19:45:18 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
|
2005-01-02 17:23:04 +00:00
|
|
|
_replace_ship_aircraft_vehicle_widgets,
|
|
|
|
ReplaceVehicleWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void ShowReplaceVehicleWindow(byte vehicletype)
|
|
|
|
{
|
|
|
|
Window *w;
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-10-23 13:04:44 +00:00
|
|
|
DeleteWindowById(WC_REPLACE_VEHICLE, vehicletype);
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
switch (vehicletype) {
|
|
|
|
case VEH_Train:
|
|
|
|
w = AllocateWindowDescFront(&_replace_rail_vehicle_desc, vehicletype);
|
|
|
|
w->vscroll.cap = 8;
|
2005-01-03 19:45:18 +00:00
|
|
|
w->resize.step_height = 14;
|
2005-01-02 17:23:04 +00:00
|
|
|
break;
|
|
|
|
case VEH_Road:
|
|
|
|
w = AllocateWindowDescFront(&_replace_road_vehicle_desc, vehicletype);
|
|
|
|
w->vscroll.cap = 8;
|
2005-01-03 19:45:18 +00:00
|
|
|
w->resize.step_height = 14;
|
2005-01-02 17:23:04 +00:00
|
|
|
break;
|
2005-10-23 13:04:44 +00:00
|
|
|
case VEH_Ship:
|
|
|
|
case VEH_Aircraft:
|
2005-01-02 17:23:04 +00:00
|
|
|
w = AllocateWindowDescFront(&_replace_ship_aircraft_vehicle_desc, vehicletype);
|
|
|
|
w->vscroll.cap = 4;
|
2005-01-03 19:45:18 +00:00
|
|
|
w->resize.step_height = 24;
|
2005-01-02 17:23:04 +00:00
|
|
|
break;
|
2005-01-02 22:28:56 +00:00
|
|
|
default: return;
|
2005-01-02 17:23:04 +00:00
|
|
|
}
|
2005-01-03 20:52:09 +00:00
|
|
|
w->caption_color = _local_player;
|
2005-01-02 17:23:04 +00:00
|
|
|
WP(w,replaceveh_d).vehicletype = vehicletype;
|
|
|
|
w->vscroll2.cap = w->vscroll.cap; // these two are always the same
|
|
|
|
}
|
2005-01-31 11:03:23 +00:00
|
|
|
|
|
|
|
void InitializeGUI(void)
|
|
|
|
{
|
|
|
|
memset(&_sorting, 0, sizeof(_sorting));
|
|
|
|
}
|
2005-10-24 19:40:48 +00:00
|
|
|
|
|
|
|
/** Assigns an already open vehicle window to a new vehicle.
|
|
|
|
* Assigns an already open vehicle window to a new vehicle. If the vehicle got any sub window open (orders and so on) it will change owner too
|
|
|
|
* @param *from_v the current owner of the window
|
|
|
|
* @param *to_v the new owner of the window
|
|
|
|
*/
|
|
|
|
void ChangeVehicleViewWindow(const Vehicle *from_v, const Vehicle *to_v)
|
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
|
|
|
|
w = FindWindowById(WC_VEHICLE_VIEW, from_v->index);
|
|
|
|
|
|
|
|
if (w != NULL) {
|
|
|
|
w->window_number = to_v->index;
|
2005-10-24 20:12:39 +00:00
|
|
|
WP(w, vp_d).follow_vehicle = to_v->index; // tell the viewport to follow the new vehicle
|
2005-10-24 19:40:48 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
|
|
|
|
w = FindWindowById(WC_VEHICLE_ORDERS, from_v->index);
|
|
|
|
|
|
|
|
if (w != NULL) {
|
|
|
|
w->window_number = to_v->index;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
w = FindWindowById(WC_VEHICLE_REFIT, from_v->index);
|
|
|
|
|
|
|
|
if (w != NULL) {
|
|
|
|
w->window_number = to_v->index;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
w = FindWindowById(WC_VEHICLE_DETAILS, from_v->index);
|
|
|
|
|
|
|
|
if (w != NULL) {
|
|
|
|
w->window_number = to_v->index;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|