(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.

This commit is contained in:
Darkvater 2005-05-11 16:17:03 +00:00
parent aa4f2d2db2
commit 729066e407
10 changed files with 121 additions and 108 deletions

View File

@ -5,6 +5,7 @@
#include "map.h" #include "map.h"
#include "tile.h" #include "tile.h"
#include "vehicle.h" #include "vehicle.h"
#include "depot.h"
#include "engine.h" #include "engine.h"
#include "command.h" #include "command.h"
#include "station.h" #include "station.h"
@ -86,7 +87,7 @@ static bool HaveHangarInOrderList(Vehicle *v)
} }
#endif #endif
int GetAircraftImage(Vehicle *v, byte direction) int GetAircraftImage(const Vehicle *v, byte direction)
{ {
int spritenum = v->spritenum; int spritenum = v->spritenum;
@ -475,21 +476,24 @@ int32 CmdSendAircraftToHangar(int x, int y, uint32 flags, uint32 p1, uint32 p2)
return 0; return 0;
} }
// p1 = vehicle /** Change the service interval for aircraft.
// p2 = new service int * @param x,y unused
* @param p1 vehicle ID that is being service-interval-changed
* @param p2 new service interval
*/
int32 CmdChangeAircraftServiceInt(int x, int y, uint32 flags, uint32 p1, uint32 p2) int32 CmdChangeAircraftServiceInt(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{ {
Vehicle *v; Vehicle *v;
uint16 serv_int = GetServiceIntervalClamped(p2); /* Double check the service interval from the user-input */
if (!IsVehicleIndex(p1)) return CMD_ERROR; if (serv_int != p2 || !IsVehicleIndex(p1)) return CMD_ERROR;
v = GetVehicle(p1); v = GetVehicle(p1);
if (v->type != VEH_Aircraft || !CheckOwnership(v->owner)) if (v->type != VEH_Aircraft || !CheckOwnership(v->owner)) return CMD_ERROR;
return CMD_ERROR;
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
v->service_interval = (uint16)p2; v->service_interval = serv_int;
InvalidateWindowWidget(WC_VEHICLE_DETAILS, v->index, 7); InvalidateWindowWidget(WC_VEHICLE_DETAILS, v->index, 7);
} }

View File

@ -36,7 +36,7 @@ void Set_DPARAM_Aircraft_Build_Window(uint16 engine_number)
} }
static void DrawAircraftImage(Vehicle *v, int x, int y, VehicleID selection) static void DrawAircraftImage(const Vehicle *v, int x, int y, VehicleID selection)
{ {
int image = GetAircraftImage(v, 6); int image = GetAircraftImage(v, 6);
uint32 ormod = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner)); uint32 ormod = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner));
@ -378,11 +378,10 @@ static void ShowAircraftRefitWindow(Vehicle *v)
static void AircraftDetailsWndProc(Window *w, WindowEvent *e) static void AircraftDetailsWndProc(Window *w, WindowEvent *e)
{ {
int mod; switch (e->event) {
Vehicle *v = GetVehicle(w->window_number), *u; case WE_PAINT: {
const Vehicle *v = GetVehicle(w->window_number);
switch(e->event) {
case WE_PAINT:
w->disabled_state = v->owner == _local_player ? 0 : (1 << 2); w->disabled_state = v->owner == _local_player ? 0 : (1 << 2);
if (!_patches.servint_aircraft) // disable service-scroller when interval is set to disabled if (!_patches.servint_aircraft) // disable service-scroller when interval is set to disabled
w->disabled_state |= (1 << 5) | (1 << 6); w->disabled_state |= (1 << 5) | (1 << 6);
@ -440,6 +439,7 @@ static void AircraftDetailsWndProc(Window *w, WindowEvent *e)
DrawAircraftImage(v, 3, 57, INVALID_VEHICLE); DrawAircraftImage(v, 3, 57, INVALID_VEHICLE);
{ {
const Vehicle *u;
int y = 57; int y = 57;
do { do {
@ -471,34 +471,32 @@ static void AircraftDetailsWndProc(Window *w, WindowEvent *e)
} }
} while ( (v=v->next) != NULL); } while ( (v=v->next) != NULL);
} }
break; } break;
case WE_CLICK: case WE_CLICK: {
switch(e->click.widget) { int mod;
const Vehicle *v;
switch (e->click.widget) {
case 2: /* rename */ case 2: /* rename */
v = GetVehicle(w->window_number);
SetDParam(0, v->unitnumber); SetDParam(0, v->unitnumber);
ShowQueryString(v->string_id, STR_A030_NAME_AIRCRAFT, 31, 150, w->window_class, w->window_number); ShowQueryString(v->string_id, STR_A030_NAME_AIRCRAFT, 31, 150, w->window_class, w->window_number);
break; break;
case 5: /* increase int */ case 5: /* increase int */
mod = _ctrl_pressed? 5 : 10; mod = _ctrl_pressed? 5 : 10;
goto change_int; goto do_change_service_int;
case 6: /* decrease int */ case 6: /* decrease int */
mod = _ctrl_pressed?- 5 : -10; mod = _ctrl_pressed?- 5 : -10;
change_int: do_change_service_int:
mod += v->service_interval; v = GetVehicle(w->window_number);
/* %-based service interval max 5%-90% mod = GetServiceIntervalClamped(mod + v->service_interval);
day-based service interval max 30-800 days */ if (mod == v->service_interval) return;
mod = _patches.servint_ispercent ? clamp(mod, MIN_SERVINT_PERCENT, MAX_SERVINT_PERCENT) : clamp(mod, MIN_SERVINT_DAYS, MAX_SERVINT_DAYS+1);
if (mod == v->service_interval)
return;
DoCommandP(v->tile, v->index, mod, NULL, DoCommandP(v->tile, v->index, mod, NULL, CMD_CHANGE_AIRCRAFT_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING));
CMD_CHANGE_AIRCRAFT_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING));
break; break;
} }
break; } break;
case WE_4: case WE_4:
if (FindWindowById(WC_VEHICLE_VIEW, w->window_number) == NULL) if (FindWindowById(WC_VEHICLE_VIEW, w->window_number) == NULL)

10
depot.h
View File

@ -41,6 +41,16 @@ static inline bool IsDepotIndex(uint index)
#define MIN_SERVINT_DAYS 30 #define MIN_SERVINT_DAYS 30
#define MAX_SERVINT_DAYS 800 #define MAX_SERVINT_DAYS 800
/** Get the service interval domain.
* Get the new proposed service interval for the vehicle is indeed, clamped
* within the given bounds. @see MIN_SERVINT_PERCENT ,etc.
* @param index proposed service interval
*/
static inline uint16 GetServiceIntervalClamped(uint index)
{
return (_patches.servint_ispercent) ? clamp(index, MIN_SERVINT_PERCENT, MAX_SERVINT_PERCENT) : clamp(index, MIN_SERVINT_DAYS, MAX_SERVINT_DAYS);
}
VARDEF TileIndex _last_built_train_depot_tile; VARDEF TileIndex _last_built_train_depot_tile;
VARDEF TileIndex _last_built_road_depot_tile; VARDEF TileIndex _last_built_road_depot_tile;
VARDEF TileIndex _last_built_aircraft_depot_tile; VARDEF TileIndex _last_built_aircraft_depot_tile;

View File

@ -58,7 +58,7 @@ static const uint16 _road_pf_table_3[4] = {
0x910, 0x1600, 0x2005, 0x2A 0x910, 0x1600, 0x2005, 0x2A
}; };
int GetRoadVehImage(Vehicle *v, byte direction) int GetRoadVehImage(const Vehicle *v, byte direction)
{ {
int img = v->spritenum; int img = v->spritenum;
int image; int image;
@ -405,19 +405,24 @@ int32 CmdTurnRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2)
return 0; return 0;
} }
/** Change the service interval for road vehicles.
* @param x,y unused
* @param p1 vehicle ID that is being service-interval-changed
* @param p2 new service interval
*/
int32 CmdChangeRoadVehServiceInt(int x, int y, uint32 flags, uint32 p1, uint32 p2) int32 CmdChangeRoadVehServiceInt(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{ {
Vehicle *v; Vehicle *v;
uint16 serv_int = GetServiceIntervalClamped(p2); /* Double check the service interval from the user-input */
if (!IsVehicleIndex(p1)) return CMD_ERROR; if (serv_int != p2 || !IsVehicleIndex(p1)) return CMD_ERROR;
v = GetVehicle(p1); v = GetVehicle(p1);
if (v->type != VEH_Road || !CheckOwnership(v->owner)) if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR;
return CMD_ERROR;
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
v->service_interval = (uint16)p2; v->service_interval = serv_int;
InvalidateWindowWidget(WC_VEHICLE_DETAILS, v->index, 7); InvalidateWindowWidget(WC_VEHICLE_DETAILS, v->index, 7);
} }

View File

@ -33,7 +33,7 @@ void Set_DPARAM_Road_Veh_Build_Window(uint16 engine_number)
SetDParam(5, ymd.year + 1920); SetDParam(5, ymd.year + 1920);
} }
static void DrawRoadVehImage(Vehicle *v, int x, int y, VehicleID selection) static void DrawRoadVehImage(const Vehicle *v, int x, int y, VehicleID selection)
{ {
int image = GetRoadVehImage(v, 6); int image = GetRoadVehImage(v, 6);
uint32 ormod = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner)); uint32 ormod = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner));
@ -47,12 +47,11 @@ static void DrawRoadVehImage(Vehicle *v, int x, int y, VehicleID selection)
static void RoadVehDetailsWndProc(Window *w, WindowEvent *e) static void RoadVehDetailsWndProc(Window *w, WindowEvent *e)
{ {
Vehicle *v = GetVehicle(w->window_number); switch (e->event) {
StringID str; case WE_PAINT: {
int mod; const Vehicle *v = GetVehicle(w->window_number);
StringID str;
switch(e->event) {
case WE_PAINT:
w->disabled_state = v->owner == _local_player ? 0 : (1 << 2); w->disabled_state = v->owner == _local_player ? 0 : (1 << 2);
if (!_patches.servint_roadveh) // disable service-scroller when interval is set to disabled if (!_patches.servint_roadveh) // disable service-scroller when interval is set to disabled
w->disabled_state |= (1 << 5) | (1 << 6); w->disabled_state |= (1 << 5) | (1 << 6);
@ -126,33 +125,33 @@ static void RoadVehDetailsWndProc(Window *w, WindowEvent *e)
str = STR_8813_FROM; str = STR_8813_FROM;
} }
DrawString(34, 78, str, 0); DrawString(34, 78, str, 0);
break; } break;
case WE_CLICK: case WE_CLICK: {
switch(e->click.widget) { int mod;
const Vehicle *v;
switch (e->click.widget) {
case 2: /* rename */ case 2: /* rename */
v = GetVehicle(w->window_number);
SetDParam(0, v->unitnumber); SetDParam(0, v->unitnumber);
ShowQueryString(v->string_id, STR_902C_NAME_ROAD_VEHICLE, 31, 150, w->window_class, w->window_number); ShowQueryString(v->string_id, STR_902C_NAME_ROAD_VEHICLE, 31, 150, w->window_class, w->window_number);
break; break;
case 5: /* increase int */ case 5: /* increase int */
mod = _ctrl_pressed? 5 : 10; mod = _ctrl_pressed? 5 : 10;
goto change_int; goto do_change_service_int;
case 6: /* decrease int */ case 6: /* decrease int */
mod = _ctrl_pressed? -5 : -10; mod = _ctrl_pressed? -5 : -10;
change_int: do_change_service_int:
mod += v->service_interval; v = GetVehicle(w->window_number);
/* %-based service interval max 5%-90% mod = GetServiceIntervalClamped(mod + v->service_interval);
day-based service interval max 30-800 days */ if (mod == v->service_interval) return;
mod = _patches.servint_ispercent ? clamp(mod, MIN_SERVINT_PERCENT, MAX_SERVINT_PERCENT) : clamp(mod, MIN_SERVINT_DAYS, MAX_SERVINT_DAYS+1);
if (mod == v->service_interval)
return;
DoCommandP(v->tile, v->index, mod, NULL, CMD_CHANGE_ROADVEH_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING)); DoCommandP(v->tile, v->index, mod, NULL, CMD_CHANGE_ROADVEH_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING));
break; break;
} }
break; } break;
case WE_4: case WE_4:
if (FindWindowById(WC_VEHICLE_VIEW, w->window_number) == NULL) if (FindWindowById(WC_VEHICLE_VIEW, w->window_number) == NULL)

View File

@ -51,7 +51,7 @@ void DrawShipEngineInfo(int engine, int x, int y, int maxw)
DrawStringMultiCenter(x, y, STR_982E_COST_MAX_SPEED_CAPACITY, maxw); DrawStringMultiCenter(x, y, STR_982E_COST_MAX_SPEED_CAPACITY, maxw);
} }
int GetShipImage(Vehicle *v, byte direction) int GetShipImage(const Vehicle *v, byte direction)
{ {
int spritenum = v->spritenum; int spritenum = v->spritenum;
@ -1032,19 +1032,24 @@ int32 CmdSendShipToDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2)
return 0; return 0;
} }
/** Change the service interval for ships.
* @param x,y unused
* @param p1 vehicle ID that is being service-interval-changed
* @param p2 new service interval
*/
int32 CmdChangeShipServiceInt(int x, int y, uint32 flags, uint32 p1, uint32 p2) int32 CmdChangeShipServiceInt(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{ {
Vehicle *v; Vehicle *v;
uint16 serv_int = GetServiceIntervalClamped(p2); /* Double check the service interval from the user-input */
if (!IsVehicleIndex(p1)) return CMD_ERROR; if (serv_int != p2 || !IsVehicleIndex(p1)) return CMD_ERROR;
v = GetVehicle(p1); v = GetVehicle(p1);
if (v->type != VEH_Ship || !CheckOwnership(v->owner)) if (v->type != VEH_Ship || !CheckOwnership(v->owner)) return CMD_ERROR;
return CMD_ERROR;
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
v->service_interval = (uint16)p2; v->service_interval = serv_int;
InvalidateWindowWidget(WC_VEHICLE_DETAILS, v->index, 7); InvalidateWindowWidget(WC_VEHICLE_DETAILS, v->index, 7);
} }

View File

@ -34,8 +34,16 @@ void Set_DPARAM_Ship_Build_Window(uint16 engine_number)
SetDParam(6, ymd.year + 1920); SetDParam(6, ymd.year + 1920);
} }
static void DrawShipImage(Vehicle *v, int x, int y, VehicleID selection); static void DrawShipImage(const Vehicle *v, int x, int y, VehicleID selection)
{
int image = GetShipImage(v, 6);
uint32 ormod = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner));
DrawSprite(image | ormod, x+32, y+10);
if (v->index == selection) {
DrawFrameRect(x-5, y-1, x+67, y+21, 15, 0x10);
}
}
const byte _ship_refit_types[4][16] = { const byte _ship_refit_types[4][16] = {
{CT_MAIL, CT_COAL, CT_LIVESTOCK, CT_GOODS, CT_GRAIN, CT_WOOD, CT_IRON_ORE, CT_STEEL, CT_VALUABLES, 255}, {CT_MAIL, CT_COAL, CT_LIVESTOCK, CT_GOODS, CT_GRAIN, CT_WOOD, CT_IRON_ORE, CT_STEEL, CT_VALUABLES, 255},
@ -168,12 +176,11 @@ static void ShowShipRefitWindow(Vehicle *v)
static void ShipDetailsWndProc(Window *w, WindowEvent *e) static void ShipDetailsWndProc(Window *w, WindowEvent *e)
{ {
Vehicle *v = GetVehicle(w->window_number); switch (e->event) {
StringID str; case WE_PAINT: {
int mod; const Vehicle *v = GetVehicle(w->window_number);
StringID str;
switch(e->event) {
case WE_PAINT:
w->disabled_state = v->owner == _local_player ? 0 : (1 << 2); w->disabled_state = v->owner == _local_player ? 0 : (1 << 2);
if (!_patches.servint_ships) // disable service-scroller when interval is set to disabled if (!_patches.servint_ships) // disable service-scroller when interval is set to disabled
w->disabled_state |= (1 << 5) | (1 << 6); w->disabled_state |= (1 << 5) | (1 << 6);
@ -247,32 +254,32 @@ static void ShipDetailsWndProc(Window *w, WindowEvent *e)
str = STR_8813_FROM; str = STR_8813_FROM;
} }
DrawString(74, 78, str, 0); DrawString(74, 78, str, 0);
break; } break;
case WE_CLICK: case WE_CLICK: {
switch(e->click.widget) { int mod;
const Vehicle *v;
switch (e->click.widget) {
case 2: /* rename */ case 2: /* rename */
v = GetVehicle(w->window_number);
SetDParam(0, v->unitnumber); SetDParam(0, v->unitnumber);
ShowQueryString(v->string_id, STR_9831_NAME_SHIP, 31, 150, w->window_class, w->window_number); ShowQueryString(v->string_id, STR_9831_NAME_SHIP, 31, 150, w->window_class, w->window_number);
break; break;
case 5: /* increase int */ case 5: /* increase int */
mod = _ctrl_pressed? 5 : 10; mod = _ctrl_pressed? 5 : 10;
goto change_int; goto do_change_service_int;
case 6: /* decrease int */ case 6: /* decrease int */
mod = _ctrl_pressed?- 5 : -10; mod = _ctrl_pressed?- 5 : -10;
change_int: do_change_service_int:
mod += v->service_interval; v = GetVehicle(w->window_number);
/* %-based service interval max 5%-90% mod = GetServiceIntervalClamped(mod + v->service_interval);
day-based service interval max 30-800 days */ if (mod == v->service_interval) return;
mod = _patches.servint_ispercent ? clamp(mod, MIN_SERVINT_PERCENT, MAX_SERVINT_PERCENT) : clamp(mod, MIN_SERVINT_DAYS, MAX_SERVINT_DAYS+1);
if (mod == v->service_interval)
return;
DoCommandP(v->tile, v->index, mod, NULL, CMD_CHANGE_SHIP_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING)); DoCommandP(v->tile, v->index, mod, NULL, CMD_CHANGE_SHIP_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING));
break; break;
} }
break; } break;
case WE_4: case WE_4:
if (FindWindowById(WC_VEHICLE_VIEW, w->window_number) == NULL) if (FindWindowById(WC_VEHICLE_VIEW, w->window_number) == NULL)
@ -622,18 +629,6 @@ void ShowShipViewWindow(Vehicle *v)
} }
} }
static void DrawShipImage(Vehicle *v, int x, int y, VehicleID selection)
{
int image = GetShipImage(v, 6);
uint32 ormod = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner));
DrawSprite(image | ormod, x+32, y+10);
if (v->index == selection) {
DrawFrameRect(x-5, y-1, x+67, y+21, 15, 0x10);
}
}
static void DrawShipDepotWindow(Window *w) static void DrawShipDepotWindow(Window *w)
{ {
uint tile; uint tile;

View File

@ -1481,20 +1481,21 @@ int32 CmdTrainGotoDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2)
/** Change the service interval for trains. /** Change the service interval for trains.
* @param x,y unused * @param x,y unused
* @param p1 vehicle ID that is being service-interval-changed * @param p1 vehicle ID that is being service-interval-changed
* @param p2 new service interval (0 - 65536) * @param p2 new service interval
*/ */
int32 CmdChangeTrainServiceInt(int x, int y, uint32 flags, uint32 p1, uint32 p2) int32 CmdChangeTrainServiceInt(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{ {
Vehicle *v; Vehicle *v;
uint16 serv_int = GetServiceIntervalClamped(p2); /* Double check the service interval from the user-input */
if (!IsVehicleIndex(p1)) return CMD_ERROR; if (serv_int != p2 || !IsVehicleIndex(p1)) return CMD_ERROR;
v = GetVehicle(p1); v = GetVehicle(p1);
if (v->type != VEH_Train || !CheckOwnership(v->owner)) return CMD_ERROR; if (v->type != VEH_Train || !CheckOwnership(v->owner)) return CMD_ERROR;
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
v->service_interval = (uint16)p2; v->service_interval = serv_int;
InvalidateWindowWidget(WC_VEHICLE_DETAILS, v->index, 8); InvalidateWindowWidget(WC_VEHICLE_DETAILS, v->index, 8);
} }
@ -3134,7 +3135,7 @@ static void CheckIfTrainNeedsService(Vehicle *v)
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
} }
int32 GetTrainRunningCost(Vehicle *v) int32 GetTrainRunningCost(const Vehicle *v)
{ {
int32 cost = 0; int32 cost = 0;

View File

@ -280,7 +280,7 @@ static void ShowBuildTrainWindow(uint tile)
} }
} }
static void DrawTrainImage(Vehicle *v, int x, int y, int count, int skip, VehicleID selection) static void DrawTrainImage(const Vehicle *v, int x, int y, int count, int skip, VehicleID selection)
{ {
do { do {
if (--skip < 0) { if (--skip < 0) {
@ -980,7 +980,7 @@ void ShowTrainViewWindow(Vehicle *v)
} }
} }
static void TrainDetailsCargoTab(Vehicle *v, int x, int y) static void TrainDetailsCargoTab(const Vehicle *v, int x, int y)
{ {
int num; int num;
StringID str; StringID str;
@ -998,7 +998,7 @@ static void TrainDetailsCargoTab(Vehicle *v, int x, int y)
} }
} }
static void TrainDetailsInfoTab(Vehicle *v, int x, int y) static void TrainDetailsInfoTab(const Vehicle *v, int x, int y)
{ {
const RailVehicleInfo *rvi = RailVehInfo(v->engine_type); const RailVehicleInfo *rvi = RailVehInfo(v->engine_type);
@ -1014,7 +1014,7 @@ static void TrainDetailsInfoTab(Vehicle *v, int x, int y)
} }
} }
static void TrainDetailsCapacityTab(Vehicle *v, int x, int y) static void TrainDetailsCapacityTab(const Vehicle *v, int x, int y)
{ {
if (v->cargo_cap != 0) { if (v->cargo_cap != 0) {
SetDParam(1, v->cargo_cap); SetDParam(1, v->cargo_cap);
@ -1023,7 +1023,7 @@ static void TrainDetailsCapacityTab(Vehicle *v, int x, int y)
} }
} }
typedef void TrainDetailsDrawerProc(Vehicle *v, int x, int y); typedef void TrainDetailsDrawerProc(const Vehicle *v, int x, int y);
static TrainDetailsDrawerProc * const _train_details_drawer_proc[3] = { static TrainDetailsDrawerProc * const _train_details_drawer_proc[3] = {
TrainDetailsCargoTab, TrainDetailsCargoTab,
@ -1033,7 +1033,7 @@ static TrainDetailsDrawerProc * const _train_details_drawer_proc[3] = {
static void DrawTrainDetailsWindow(Window *w) static void DrawTrainDetailsWindow(Window *w)
{ {
Vehicle *v, *u; const Vehicle *v, *u;
uint16 tot_cargo[NUM_CARGO][2]; // count total cargo ([0]-actual cargo, [1]-total cargo) uint16 tot_cargo[NUM_CARGO][2]; // count total cargo ([0]-actual cargo, [1]-total cargo)
int max_speed = 0xFFFF; int max_speed = 0xFFFF;
int i,num,x,y,sel; int i,num,x,y,sel;
@ -1151,14 +1151,14 @@ static void DrawTrainDetailsWindow(Window *w)
static void TrainDetailsWndProc(Window *w, WindowEvent *e) static void TrainDetailsWndProc(Window *w, WindowEvent *e)
{ {
switch(e->event) { switch (e->event) {
case WE_PAINT: case WE_PAINT:
DrawTrainDetailsWindow(w); DrawTrainDetailsWindow(w);
break; break;
case WE_CLICK: { case WE_CLICK: {
int mod; int mod;
Vehicle *v; const Vehicle *v;
switch(e->click.widget) { switch (e->click.widget) {
case 2: /* name train */ case 2: /* name train */
v = GetVehicle(w->window_number); v = GetVehicle(w->window_number);
SetDParam(0, v->unitnumber); SetDParam(0, v->unitnumber);
@ -1172,13 +1172,9 @@ static void TrainDetailsWndProc(Window *w, WindowEvent *e)
mod = _ctrl_pressed? -5 : -10; mod = _ctrl_pressed? -5 : -10;
do_change_service_int: do_change_service_int:
v = GetVehicle(w->window_number); v = GetVehicle(w->window_number);
mod += v->service_interval;
/* %-based service interval max 5%-90% mod = GetServiceIntervalClamped(mod + v->service_interval);
day-based service interval max 30-800 days */ if (mod == v->service_interval) return;
mod = _patches.servint_ispercent ? clamp(mod, MIN_SERVINT_PERCENT, MAX_SERVINT_PERCENT) : clamp(mod, MIN_SERVINT_DAYS, MAX_SERVINT_DAYS+1);
if (mod == v->service_interval)
return;
DoCommandP(v->tile, v->index, mod, NULL, CMD_CHANGE_TRAIN_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING)); DoCommandP(v->tile, v->index, mod, NULL, CMD_CHANGE_TRAIN_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING));
break; break;

View File

@ -271,9 +271,9 @@ void AddRearEngineToMultiheadedTrain(Vehicle *v, Vehicle *u, bool building) ;
/* train_cmd.h */ /* train_cmd.h */
int GetTrainImage(const Vehicle *v, byte direction); int GetTrainImage(const Vehicle *v, byte direction);
int GetAircraftImage(Vehicle *v, byte direction); int GetAircraftImage(const Vehicle *v, byte direction);
int GetRoadVehImage(Vehicle *v, byte direction); int GetRoadVehImage(const Vehicle *v, byte direction);
int GetShipImage(Vehicle *v, byte direction); int GetShipImage(const Vehicle *v, byte direction);
Vehicle *CreateEffectVehicle(int x, int y, int z, EffectVehicle type); Vehicle *CreateEffectVehicle(int x, int y, int z, EffectVehicle type);
Vehicle *CreateEffectVehicleAbove(int x, int y, int z, EffectVehicle type); Vehicle *CreateEffectVehicleAbove(int x, int y, int z, EffectVehicle type);
@ -307,7 +307,7 @@ UnitID GetFreeUnitNumber(byte type);
int LoadUnloadVehicle(Vehicle *v); int LoadUnloadVehicle(Vehicle *v);
void UpdateTrainAcceleration(Vehicle *v); void UpdateTrainAcceleration(Vehicle *v);
int32 GetTrainRunningCost(Vehicle *v); int32 GetTrainRunningCost(const Vehicle *v);
int CheckTrainStoppedInDepot(const Vehicle *v); int CheckTrainStoppedInDepot(const Vehicle *v);