Changeset - r156:dd00481b3251
[Not reviewed]
master
0 13 0
darkvater - 20 years ago 2004-09-04 13:06:09
darkvater@openttd.org
(svn r157) -Feature: [1009708] Percent-based service intervals. Send a vehicle to depot after it has lost X% of its reliability (mivlad)
13 files changed with 104 insertions and 33 deletions:
0 comments (0 inline, 0 general)
aircraft_cmd.c
Show inline comments
 
@@ -529,7 +529,7 @@ static void CheckIfAircraftNeedsService(
 
	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
 
 	}
 
 
 
 	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++;
 
 	}
 

	
aircraft_gui.c
Show inline comments
 
@@ -309,6 +309,9 @@ static void AircraftDetailsWndProc(Windo
 
	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(Windo
 
		{
 
			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(Windo
 
			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;
lang/english.txt
Show inline comments
 
@@ -1003,13 +1003,13 @@ STR_CONFIG_PATCHES_AI_BUILDS_SHIPS		:{LT
 

	
 
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
 
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	:{W
 
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
roadveh_cmd.c
Show inline comments
 
@@ -651,7 +651,7 @@ static void ProcessRoadVehOrder(Vehicle 
 
	}
 

	
 
	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(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)
roadveh_gui.c
Show inline comments
 
@@ -39,6 +39,9 @@ static void RoadVehDetailsWndProc(Window
 
	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
 
		{
 
			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
 
			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;
 
		}
settings.c
Show inline comments
 
@@ -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)},
settings_gui.c
Show inline comments
 
@@ -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_vehicle
 
	{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[] = {
ship_cmd.c
Show inline comments
 
@@ -88,7 +88,7 @@ static void CheckIfShipNeedsService(Vehi
 
	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++;
 
	}
 

	
ship_gui.c
Show inline comments
 
@@ -154,6 +154,9 @@ static void ShipDetailsWndProc(Window *w
 
	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
 
		{
 
			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
 
			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;
 
		}
train_cmd.c
Show inline comments
 
@@ -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(Veh
 
	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)
train_gui.c
Show inline comments
 
@@ -959,6 +959,9 @@ static void DrawTrainDetailsWindow(Windo
 
	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(Windo
 

	
 
	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 *
 
			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;
variables.h
Show inline comments
 
@@ -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
vehicle.h
Show inline comments
 
@@ -414,4 +414,10 @@ VARDEF BackuppedOrders _backup_orders_da
 

	
 
#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 */
0 comments (0 inline, 0 general)