From 85628544eeac566a70bf3f218bc078c096c65c50 Mon Sep 17 00:00:00 2001 From: darkvater Date: Sat, 4 Sep 2004 13:06:09 +0000 Subject: (svn r157) -Feature: [1009708] Percent-based service intervals. Send a vehicle to depot after it has lost X% of its reliability (mivlad) --- aircraft_cmd.c | 4 ++-- aircraft_gui.c | 16 ++++++++++++---- lang/english.txt | 11 +++++++---- roadveh_cmd.c | 4 ++-- roadveh_gui.c | 16 ++++++++++++---- settings.c | 1 + settings_gui.c | 37 +++++++++++++++++++++++++++++++++---- ship_cmd.c | 4 ++-- ship_gui.c | 16 ++++++++++++---- train_cmd.c | 4 ++-- train_gui.c | 17 ++++++++++++----- variables.h | 1 + vehicle.h | 6 ++++++ 13 files changed, 104 insertions(+), 33 deletions(-) diff --git a/aircraft_cmd.c b/aircraft_cmd.c index 3814e19ce..c842f0bee 100644 --- a/aircraft_cmd.c +++ b/aircraft_cmd.c @@ -529,7 +529,7 @@ static void CheckIfAircraftNeedsService(Vehicle *v) if (_patches.servint_aircraft == 0) return; - if (v->date_of_last_service + v->service_interval > _date) + if (SERVICE_INTERVAL) return; if (v->vehstatus & VS_STOPPED) @@ -1061,7 +1061,7 @@ static void ProcessAircraftOrder(Vehicle *v) } if ((v->next_order & (OT_MASK|OF_UNLOAD|OF_FULL_LOAD)) == (OT_GOTO_DEPOT|OF_UNLOAD|OF_FULL_LOAD) && - v->date_of_last_service+v->service_interval > _date) { + SERVICE_INTERVAL) { v->cur_order_index++; } diff --git a/aircraft_gui.c b/aircraft_gui.c index 7a13ec15a..450c612cd 100644 --- a/aircraft_gui.c +++ b/aircraft_gui.c @@ -309,6 +309,9 @@ static void AircraftDetailsWndProc(Window *w, WindowEvent *e) switch(e->event) { case WE_PAINT: w->disabled_state = v->owner == _local_player ? 0 : (1 << 2); + if (!_patches.servint_aircraft) // disable service-scroller when interval is set to disabled + w->disabled_state |= (1 << 5) | (1 << 6); + SET_DPARAM16(0, v->string_id); SET_DPARAM16(1, v->unitnumber); DrawWindowWidgets(w); @@ -356,7 +359,7 @@ static void AircraftDetailsWndProc(Window *w, WindowEvent *e) { SET_DPARAM16(0, v->service_interval); SET_DPARAM16(1, v->date_of_last_service); - DrawString(13, 103, STR_883C_SERVICING_INTERVAL_DAYS, 0); + DrawString(13, 103, _patches.servint_ispercent?STR_SERVICING_INTERVAL_PERCENT:STR_883C_SERVICING_INTERVAL_DAYS, 0); } DrawAircraftImage(v, 3, 57, INVALID_VEHICLE); @@ -403,14 +406,19 @@ static void AircraftDetailsWndProc(Window *w, WindowEvent *e) break; case 5: /* increase int */ - mod = 10; + mod = _ctrl_pressed? 5 : 10; goto change_int; case 6: /* decrease int */ - mod = -10; + mod = _ctrl_pressed?- 5 : -10; change_int: mod += v->service_interval; - if (!IS_INT_INSIDE(mod, 30, 800+1)) + + /* %-based service interval max 5%-90% + day-based service interval max 30-800 days */ + 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_AIRCRAFT_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING)); break; diff --git a/lang/english.txt b/lang/english.txt index 74fb6d45b..85369fc7a 100644 --- a/lang/english.txt +++ b/lang/english.txt @@ -1003,13 +1003,13 @@ STR_CONFIG_PATCHES_AI_BUILDS_SHIPS :{LTBLUE}Disable ships for computer: {ORANGE STR_CONFIG_PATCHES_AINEW_ACTIVE :{LTBLUE}Enable new AI (alpha): {ORANGE}{STRING} -STR_CONFIG_PATCHES_SERVINT_TRAINS :{LTBLUE}Default service interval for trains: {ORANGE}{STRING} days +STR_CONFIG_PATCHES_SERVINT_TRAINS :{LTBLUE}Default service interval for trains: {ORANGE}{STRING} days/% STR_CONFIG_PATCHES_SERVINT_TRAINS_DISABLED :{LTBLUE}Default service interval for trains: {ORANGE}disabled -STR_CONFIG_PATCHES_SERVINT_ROADVEH :{LTBLUE}Default service interval for road vehicles: {ORANGE}{STRING} days +STR_CONFIG_PATCHES_SERVINT_ROADVEH :{LTBLUE}Default service interval for road vehicles: {ORANGE}{STRING} days/% STR_CONFIG_PATCHES_SERVINT_ROADVEH_DISABLED :{LTBLUE}Default service interval for road vehicles: {ORANGE}disabled -STR_CONFIG_PATCHES_SERVINT_AIRCRAFT :{LTBLUE}Default service interval for aircraft: {ORANGE}{STRING} days +STR_CONFIG_PATCHES_SERVINT_AIRCRAFT :{LTBLUE}Default service interval for aircraft: {ORANGE}{STRING} days/% STR_CONFIG_PATCHES_SERVINT_AIRCRAFT_DISABLED :{LTBLUE}Default service interval for aircraft: {ORANGE}disabled -STR_CONFIG_PATCHES_SERVINT_SHIPS :{LTBLUE}Default service interval for ships: {ORANGE}{STRING} days +STR_CONFIG_PATCHES_SERVINT_SHIPS :{LTBLUE}Default service interval for ships: {ORANGE}{STRING} days/% STR_CONFIG_PATCHES_SERVINT_SHIPS_DISABLED :{LTBLUE}Default service interval for ships: {ORANGE}disabled STR_CONFIG_PATCHES_COLORED_NEWS_DATE :{LTBLUE}Coloured news appears in: {ORANGE}{STRING} @@ -1033,6 +1033,7 @@ STR_CONFIG_PATCHES_INT32 :{INT32} STR_CONFIG_PATCHES_CURRENCY :{CURRENCY} STR_CONFIG_PATCHES_QUERY_CAPT :{WHITE}Change setting value +STR_CONFIG_PATCHES_SERVICE_INTERVAL_INCOMPATIBLE :{WHITE}Some or all of the default service interval(s) below are incompatible with chosen setting! 5-90% and 30-800 days are valid STR_TEMPERATE_LANDSCAPE :temperate landscape STR_SUB_ARCTIC_LANDSCAPE :sub-arctic landscape @@ -1151,6 +1152,7 @@ STR_RAIL_REFIT_VEHICLE :{BLACK}Refit train STR_RAIL_SELECT_TYPE_OF_CARGO_FOR :{BLACK}Select type of cargo for train to carry STR_RAIL_REFIT_TO_CARRY_HIGHLIGHTED :{BLACK}Refit train to carry highlighted cargo type STR_RAIL_CAN_T_REFIT_VEHICLE :{WHITE}Can't refit train... +STR_CONFIG_PATCHES_SERVINT_ISPERCENT :{LTBLUE}Service intervals are in percents: {ORANGE}{STRING} TEMP_AI_IN_PROGRESS :{WHITE}Welcome to this new AI, in progress. You can expect problems. When you do, make a screenshot and post it at the forum. Enjoy! TEMP_AI_ACTIVATED :{WHITE}Warning: this new AI is still alpha! Currently, only trucks and busses work! @@ -2261,6 +2263,7 @@ STR_8839_CAN_T_SELL_RAILROAD_VEHICLE :{WHITE}Can't sell railway vehicle... STR_883A_UNABLE_TO_FIND_ROUTE_TO :{WHITE}Unable to find route to local depot STR_883B_CAN_T_STOP_START_TRAIN :{WHITE}Can't stop/start train... STR_883C_SERVICING_INTERVAL_DAYS :{BLACK}Servicing interval: {LTBLUE}{COMMA16}days{BLACK} Last service: {LTBLUE}{DATE_LONG} +STR_SERVICING_INTERVAL_PERCENT :{BLACK}Servicing interval: {LTBLUE}{COMMA16}%{BLACK} Last service: {LTBLUE}{DATE_LONG} STR_883D_TRAINS_CLICK_ON_TRAIN_FOR :{BLACK}Trains - click on train for information STR_883E_BUILD_NEW_TRAINS_REQUIRES :{BLACK}Build new trains (requires train depot) STR_883F_TRAINS_CLICK_ON_TRAIN_FOR :{BLACK}Trains - click on train for info., drag vehicle to add/remove from train diff --git a/roadveh_cmd.c b/roadveh_cmd.c index 0ddb23387..e3fec5681 100644 --- a/roadveh_cmd.c +++ b/roadveh_cmd.c @@ -651,7 +651,7 @@ static void ProcessRoadVehOrder(Vehicle *v) } if ((v->next_order & (OT_MASK|OF_UNLOAD|OF_FULL_LOAD)) == (OT_GOTO_DEPOT|OF_UNLOAD|OF_FULL_LOAD) && - v->date_of_last_service+v->service_interval > _date) { + SERVICE_INTERVAL ) { v->cur_order_index++; } @@ -1500,7 +1500,7 @@ static void CheckIfRoadVehNeedsService(Vehicle *v) if (_patches.servint_roadveh == 0) return; - if (v->date_of_last_service + v->service_interval > _date) + if (SERVICE_INTERVAL) return; if (v->vehstatus & VS_STOPPED) diff --git a/roadveh_gui.c b/roadveh_gui.c index 5dd4147a4..8c77b081c 100644 --- a/roadveh_gui.c +++ b/roadveh_gui.c @@ -39,6 +39,9 @@ static void RoadVehDetailsWndProc(Window *w, WindowEvent *e) switch(e->event) { case WE_PAINT: w->disabled_state = v->owner == _local_player ? 0 : (1 << 2); + if (!_patches.servint_roadveh) // disable service-scroller when interval is set to disabled + w->disabled_state |= (1 << 5) | (1 << 6); + SET_DPARAM16(0, v->string_id); SET_DPARAM16(1, v->unitnumber); DrawWindowWidgets(w); @@ -86,7 +89,7 @@ static void RoadVehDetailsWndProc(Window *w, WindowEvent *e) { SET_DPARAM16(0, v->service_interval); SET_DPARAM16(1, v->date_of_last_service); - DrawString(13, 90, STR_883C_SERVICING_INTERVAL_DAYS, 0); + DrawString(13, 90, _patches.servint_ispercent?STR_SERVICING_INTERVAL_PERCENT:STR_883C_SERVICING_INTERVAL_DAYS, 0); } DrawRoadVehImage(v, 3, 57, INVALID_VEHICLE); @@ -118,14 +121,19 @@ static void RoadVehDetailsWndProc(Window *w, WindowEvent *e) break; case 5: /* increase int */ - mod = 10; + mod = _ctrl_pressed? 5 : 10; goto change_int; case 6: /* decrease int */ - mod = -10; + mod = _ctrl_pressed? -5 : -10; change_int: mod += v->service_interval; - if (!IS_INT_INSIDE(mod, 30, 800+1)) + + /* %-based service interval max 5%-90% + day-based service interval max 30-800 days */ + 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)); break; } diff --git a/settings.c b/settings.c index 42e3a38dd..a8aedf1d8 100644 --- a/settings.c +++ b/settings.c @@ -835,6 +835,7 @@ static const SettingDesc patch_settings[] = { {"max_aircraft", SDT_UINT8, (void*)40,(void*)offsetof(Patches, max_aircraft)}, {"max_ships", SDT_UINT8, (void*)50,(void*)offsetof(Patches, max_ships)}, + {"servint_ispercent", SDT_BOOL, (void*)false,(void*)offsetof(Patches, servint_ispercent)}, {"servint_trains", SDT_UINT16, (void*)150,(void*)offsetof(Patches, servint_trains)}, {"servint_roadveh", SDT_UINT16, (void*)150,(void*)offsetof(Patches, servint_roadveh)}, {"servint_ships", SDT_UINT16, (void*)360,(void*)offsetof(Patches, servint_ships)}, diff --git a/settings_gui.c b/settings_gui.c index 8fdc80464..58dea0b8e 100644 --- a/settings_gui.c +++ b/settings_gui.c @@ -684,6 +684,34 @@ int32 InvisibleTreesActive(int32 p1) return 0; } +int32 InValidateDetailsWindow(int32 p1) +{ + InvalidateWindowClasses(WC_VEHICLE_DETAILS); + return 0; +} + +/* Check service intervals of vehicles, p1 is value of % or day based servicing */ +int32 CheckInterval(int32 p1) +{ + bool warning; + if (p1) { + warning = ( (IS_INT_INSIDE(_patches.servint_trains, 5, 90+1) || _patches.servint_trains == 0) && + (IS_INT_INSIDE(_patches.servint_roadveh, 5, 90+1) || _patches.servint_roadveh == 0) && + (IS_INT_INSIDE(_patches.servint_aircraft, 5, 90+1) || _patches.servint_aircraft == 0) && + (IS_INT_INSIDE(_patches.servint_ships, 5, 90+1) || _patches.servint_ships == 0) ); + } else { + warning = ( (IS_INT_INSIDE(_patches.servint_trains, 30, 800+1) || _patches.servint_trains == 0) && + (IS_INT_INSIDE(_patches.servint_roadveh, 30, 800+1) || _patches.servint_roadveh == 0) && + (IS_INT_INSIDE(_patches.servint_aircraft, 30, 800+1) || _patches.servint_aircraft == 0) && + (IS_INT_INSIDE(_patches.servint_ships, 30, 800+1) || _patches.servint_ships == 0) ); + } + + if (!warning) + ShowErrorMessage(-1, STR_CONFIG_PATCHES_SERVICE_INTERVAL_INCOMPATIBLE, 0, 0); + + return InValidateDetailsWindow(0); +} + typedef int32 PatchButtonClick(int32); typedef struct PatchEntry { @@ -754,10 +782,11 @@ static const PatchEntry _patches_vehicles[] = { {PE_UINT8, 0, STR_CONFIG_PATCHES_MAX_AIRCRAFT, &_patches.max_aircraft, 0, 240, 10}, {PE_UINT8, 0, STR_CONFIG_PATCHES_MAX_SHIPS, &_patches.max_ships, 0, 240, 10}, - {PE_UINT16, PF_0ISDIS, STR_CONFIG_PATCHES_SERVINT_TRAINS, &_patches.servint_trains, 30, 1200, 10}, - {PE_UINT16, PF_0ISDIS, STR_CONFIG_PATCHES_SERVINT_ROADVEH, &_patches.servint_roadveh, 30, 1200, 10}, - {PE_UINT16, PF_0ISDIS, STR_CONFIG_PATCHES_SERVINT_AIRCRAFT, &_patches.servint_aircraft, 30, 1200, 10}, - {PE_UINT16, PF_0ISDIS, STR_CONFIG_PATCHES_SERVINT_SHIPS, &_patches.servint_ships, 30, 1200, 10}, + {PE_BOOL, 0, STR_CONFIG_PATCHES_SERVINT_ISPERCENT, &_patches.servint_ispercent, 0, 0, 0, &CheckInterval}, + {PE_UINT16, PF_0ISDIS, STR_CONFIG_PATCHES_SERVINT_TRAINS, &_patches.servint_trains, 5, 800, 5, &InValidateDetailsWindow}, + {PE_UINT16, PF_0ISDIS, STR_CONFIG_PATCHES_SERVINT_ROADVEH, &_patches.servint_roadveh, 5, 800, 5, &InValidateDetailsWindow}, + {PE_UINT16, PF_0ISDIS, STR_CONFIG_PATCHES_SERVINT_AIRCRAFT, &_patches.servint_aircraft, 5, 800, 5, &InValidateDetailsWindow}, + {PE_UINT16, PF_0ISDIS, STR_CONFIG_PATCHES_SERVINT_SHIPS, &_patches.servint_ships, 5, 800, 5, &InValidateDetailsWindow}, }; static const PatchEntry _patches_stations[] = { diff --git a/ship_cmd.c b/ship_cmd.c index cc5127033..009f2f18b 100644 --- a/ship_cmd.c +++ b/ship_cmd.c @@ -88,7 +88,7 @@ static void CheckIfShipNeedsService(Vehicle *v) if (_patches.servint_ships == 0) return; - if (v->date_of_last_service + v->service_interval > _date) + if (SERVICE_INTERVAL) return; if (v->vehstatus & VS_STOPPED) @@ -206,7 +206,7 @@ static void ProcessShipOrder(Vehicle *v) } if ((v->next_order & (OT_MASK|OF_UNLOAD|OF_FULL_LOAD)) == (OT_GOTO_DEPOT|OF_UNLOAD|OF_FULL_LOAD) && - v->date_of_last_service+v->service_interval > _date) { + SERVICE_INTERVAL) { v->cur_order_index++; } diff --git a/ship_gui.c b/ship_gui.c index 8bf48c417..293132275 100644 --- a/ship_gui.c +++ b/ship_gui.c @@ -154,6 +154,9 @@ static void ShipDetailsWndProc(Window *w, WindowEvent *e) switch(e->event) { case WE_PAINT: w->disabled_state = v->owner == _local_player ? 0 : (1 << 2); + if (!_patches.servint_ships) // disable service-scroller when interval is set to disabled + w->disabled_state |= (1 << 5) | (1 << 6); + SET_DPARAM16(0, v->string_id); SET_DPARAM16(1, v->unitnumber); DrawWindowWidgets(w); @@ -201,7 +204,7 @@ static void ShipDetailsWndProc(Window *w, WindowEvent *e) { SET_DPARAM16(0, v->service_interval); SET_DPARAM16(1, v->date_of_last_service); - DrawString(13, 90, STR_883C_SERVICING_INTERVAL_DAYS, 0); + DrawString(13, 90, _patches.servint_ispercent?STR_SERVICING_INTERVAL_PERCENT:STR_883C_SERVICING_INTERVAL_DAYS, 0); } DrawShipImage(v, 3, 57, INVALID_VEHICLE); @@ -232,14 +235,19 @@ static void ShipDetailsWndProc(Window *w, WindowEvent *e) ShowQueryString(v->string_id, STR_9831_NAME_SHIP, 31, 150, w->window_class, w->window_number); break; case 5: /* increase int */ - mod = 10; + mod = _ctrl_pressed? 5 : 10; goto change_int; case 6: /* decrease int */ - mod = -10; + mod = _ctrl_pressed?- 5 : -10; change_int: mod += v->service_interval; - if (!IS_INT_INSIDE(mod, 30, 800+1)) + + /* %-based service interval max 5%-90% + day-based service interval max 30-800 days */ + 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)); break; } diff --git a/train_cmd.c b/train_cmd.c index 7f04b19b2..dd5bc6008 100644 --- a/train_cmd.c +++ b/train_cmd.c @@ -1549,7 +1549,7 @@ static bool ProcessTrainOrder(Vehicle *v) } if ((v->next_order & (OT_MASK|OF_UNLOAD|OF_FULL_LOAD)) == (OT_GOTO_DEPOT|OF_UNLOAD|OF_FULL_LOAD) && - v->date_of_last_service+v->service_interval > _date) { + SERVICE_INTERVAL) { v->cur_order_index++; } @@ -2541,7 +2541,7 @@ static void CheckIfTrainNeedsService(Vehicle *v) if (_patches.servint_trains == 0) return; - if (v->date_of_last_service + v->service_interval > _date) + if (SERVICE_INTERVAL) return; if (v->vehstatus & VS_STOPPED) diff --git a/train_gui.c b/train_gui.c index f2910404c..d11832ff8 100644 --- a/train_gui.c +++ b/train_gui.c @@ -959,6 +959,9 @@ static void DrawTrainDetailsWindow(Window *w) if (v->owner != _local_player) w->disabled_state |= (1 << 2); + if (!_patches.servint_trains) // disable service-scroller when interval is set to disabled + w->disabled_state |= (1 << 6) | (1 << 7); + SET_DPARAM16(0, v->string_id); SET_DPARAM16(1, v->unitnumber); DrawWindowWidgets(w); @@ -994,7 +997,7 @@ static void DrawTrainDetailsWindow(Window *w) SET_DPARAM16(0, v->service_interval); SET_DPARAM16(1, v->date_of_last_service); - DrawString(x + 11, 141, STR_883C_SERVICING_INTERVAL_DAYS, 0); + DrawString(x + 11, 141, _patches.servint_ispercent?STR_SERVICING_INTERVAL_PERCENT:STR_883C_SERVICING_INTERVAL_DAYS, 0); x = 1; y = 57; @@ -1045,16 +1048,20 @@ static void TrainDetailsWndProc(Window *w, WindowEvent *e) ShowQueryString(v->string_id, STR_8865_NAME_TRAIN, 31, 150, w->window_class, w->window_number); break; case 6: /* inc serv interval */ - mod = 10; + mod = _ctrl_pressed? 5 : 10; goto do_change_service_int; case 7: /* dec serv interval */ - mod = -10; + mod = _ctrl_pressed? -5 : -10; do_change_service_int: v = &_vehicles[w->window_number]; mod += v->service_interval; - if (!IS_INT_INSIDE(mod, 30, 800+1)) - return; + + /* %-based service interval max 5%-90% + day-based service interval max 30-800 days */ + 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)); break; diff --git a/variables.h b/variables.h index f26255263..7a6d33814 100644 --- a/variables.h +++ b/variables.h @@ -118,6 +118,7 @@ typedef struct Patches { byte max_aircraft; //max planes in game per player byte max_ships; //max ships in game per player + bool servint_ispercent; // service intervals are in percents uint16 servint_trains; // service interval for trains uint16 servint_roadveh; // service interval for road vehicles uint16 servint_aircraft;// service interval for aircraft diff --git a/vehicle.h b/vehicle.h index b970bb8ab..f45e1e035 100644 --- a/vehicle.h +++ b/vehicle.h @@ -414,4 +414,10 @@ VARDEF BackuppedOrders _backup_orders_data[1]; #define INVALID_VEHICLE 0xffff +#define SERVICE_INTERVAL (_patches.servint_ispercent ? (v->reliability > _engines[v->engine_type].reliability * (100 - v->service_interval) / 100) : (v->date_of_last_service + v->service_interval > _date)) +#define MIN_SERVINT_PERCENT 5 +#define MAX_SERVINT_PERCENT 90 +#define MIN_SERVINT_DAYS 30 +#define MAX_SERVINT_DAYS 800 + #endif /* VEHICLE_H */ -- cgit v1.2.3-54-g00ecf