src/vehicle_gui.cpp
branchNewGRF_ports
changeset 10991 d8811e327d12
parent 10731 67db0d431d5e
child 10994 cd9968b6f96b
equal deleted inserted replaced
10731:67db0d431d5e 10991:d8811e327d12
    34 #include "string_func.h"
    34 #include "string_func.h"
    35 #include "settings_type.h"
    35 #include "settings_type.h"
    36 #include "widgets/dropdown_func.h"
    36 #include "widgets/dropdown_func.h"
    37 #include "order_func.h"
    37 #include "order_func.h"
    38 #include "timetable.h"
    38 #include "timetable.h"
       
    39 #include "vehiclelist.h"
    39 
    40 
    40 #include "table/sprites.h"
    41 #include "table/sprites.h"
    41 #include "table/strings.h"
    42 #include "table/strings.h"
    42 
    43 
    43 Sorting _sorting;
    44 Sorting _sorting;
   108 
   109 
   109 	/* invalidate cached values for name sorter - vehicle names could change */
   110 	/* invalidate cached values for name sorter - vehicle names could change */
   110 	_last_vehicle[0] = _last_vehicle[1] = NULL;
   111 	_last_vehicle[0] = _last_vehicle[1] = NULL;
   111 
   112 
   112 	_internal_sort_order = (vl->vehicles.flags & VL_DESC) != 0;
   113 	_internal_sort_order = (vl->vehicles.flags & VL_DESC) != 0;
   113 	qsort((void*)vl->vehicles.Begin(), vl->vehicles.Length(), sizeof(vl->vehicles.Begin()),
   114 	qsort((void*)vl->vehicles.Begin(), vl->vehicles.Length(), sizeof(*vl->vehicles.Begin()),
   114 		_vehicle_sorter[vl->vehicles.sort_type]);
   115 		_vehicle_sorter[vl->vehicles.sort_type]);
   115 
   116 
   116 	vl->vehicles.resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
   117 	vl->vehicles.resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
   117 	vl->vehicles.flags &= ~VL_RESORT;
   118 	vl->vehicles.flags &= ~VL_RESORT;
   118 }
   119 }
   119 
   120 
   120 void DepotSortList(VehicleList *list)
   121 void DepotSortList(VehicleList *list)
   121 {
   122 {
   122 	_internal_sort_order = 0;
   123 	_internal_sort_order = 0;
   123 	if (list->Length() < 2) return;
   124 	if (list->Length() < 2) return;
   124 	qsort((void*)list->Begin(), list->Length(), sizeof(list->Begin()), _vehicle_sorter[0]);
   125 	qsort((void*)list->Begin(), list->Length(), sizeof(*list->Begin()), _vehicle_sorter[0]);
   125 }
   126 }
   126 
   127 
   127 /** draw the vehicle profit button in the vehicle list window. */
   128 /** draw the vehicle profit button in the vehicle list window. */
   128 void DrawVehicleProfitButton(const Vehicle *v, int x, int y)
   129 void DrawVehicleProfitButton(const Vehicle *v, int x, int y)
   129 {
   130 {
  1215 	}
  1216 	}
  1216 }
  1217 }
  1217 
  1218 
  1218 void ShowVehicleListWindow(PlayerID player, VehicleType vehicle_type)
  1219 void ShowVehicleListWindow(PlayerID player, VehicleType vehicle_type)
  1219 {
  1220 {
  1220 	/* If _settings.gui.advanced_vehicle_list > 1, display the Advanced list
  1221 	/* If _settings_client.gui.advanced_vehicle_list > 1, display the Advanced list
  1221 	 * if _settings.gui.advanced_vehicle_list == 1, display Advanced list only for local player
  1222 	 * if _settings_client.gui.advanced_vehicle_list == 1, display Advanced list only for local player
  1222 	 * if _ctrl_pressed, do the opposite action (Advanced list x Normal list)
  1223 	 * if _ctrl_pressed, do the opposite action (Advanced list x Normal list)
  1223 	 */
  1224 	 */
  1224 
  1225 
  1225 	if ((_settings.gui.advanced_vehicle_list > (uint)(player != _local_player)) != _ctrl_pressed) {
  1226 	if ((_settings_client.gui.advanced_vehicle_list > (uint)(player != _local_player)) != _ctrl_pressed) {
  1226 		ShowPlayerGroup(player, vehicle_type);
  1227 		ShowPlayerGroup(player, vehicle_type);
  1227 	} else {
  1228 	} else {
  1228 		ShowVehicleListWindowLocal(player, VLW_STANDARD, vehicle_type, 0);
  1229 		ShowVehicleListWindowLocal(player, VLW_STANDARD, vehicle_type, 0);
  1229 	}
  1230 	}
  1230 }
  1231 }
  1406 	/** Checks whether service interval is enabled for the vehicle. */
  1407 	/** Checks whether service interval is enabled for the vehicle. */
  1407 	static bool IsVehicleServiceIntervalEnabled(const VehicleType vehicle_type)
  1408 	static bool IsVehicleServiceIntervalEnabled(const VehicleType vehicle_type)
  1408 	{
  1409 	{
  1409 		switch (vehicle_type) {
  1410 		switch (vehicle_type) {
  1410 			default: NOT_REACHED();
  1411 			default: NOT_REACHED();
  1411 			case VEH_TRAIN:    return _settings.vehicle.servint_trains   != 0; break;
  1412 			case VEH_TRAIN:    return _settings_game.vehicle.servint_trains   != 0; break;
  1412 			case VEH_ROAD:     return _settings.vehicle.servint_roadveh  != 0; break;
  1413 			case VEH_ROAD:     return _settings_game.vehicle.servint_roadveh  != 0; break;
  1413 			case VEH_SHIP:     return _settings.vehicle.servint_ships    != 0; break;
  1414 			case VEH_SHIP:     return _settings_game.vehicle.servint_ships    != 0; break;
  1414 			case VEH_AIRCRAFT: return _settings.vehicle.servint_aircraft != 0; break;
  1415 			case VEH_AIRCRAFT: return _settings_game.vehicle.servint_aircraft != 0; break;
  1415 		}
  1416 		}
  1416 		return false; // kill a compiler warning
  1417 		return false; // kill a compiler warning
  1417 	}
  1418 	}
  1418 
  1419 
  1419 	/**
  1420 	/**
  1481 			case VEH_TRAIN:
  1482 			case VEH_TRAIN:
  1482 				SetDParam(2, v->GetDisplayMaxSpeed());
  1483 				SetDParam(2, v->GetDisplayMaxSpeed());
  1483 				SetDParam(1, v->u.rail.cached_power);
  1484 				SetDParam(1, v->u.rail.cached_power);
  1484 				SetDParam(0, v->u.rail.cached_weight);
  1485 				SetDParam(0, v->u.rail.cached_weight);
  1485 				SetDParam(3, v->u.rail.cached_max_te / 1000);
  1486 				SetDParam(3, v->u.rail.cached_max_te / 1000);
  1486 				DrawString(2, 25, (_settings.vehicle.realistic_acceleration && v->u.rail.railtype != RAILTYPE_MAGLEV) ?
  1487 				DrawString(2, 25, (_settings_game.vehicle.realistic_acceleration && v->u.rail.railtype != RAILTYPE_MAGLEV) ?
  1487 					STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE :
  1488 					STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE :
  1488 					STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED, TC_FROMSTRING);
  1489 					STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED, TC_FROMSTRING);
  1489 				break;
  1490 				break;
  1490 
  1491 
  1491 			case VEH_ROAD:
  1492 			case VEH_ROAD:
  1509 		DrawString(2, 45, _vehicle_translation_table[VST_VEHICLE_RELIABILITY_BREAKDOWNS][v->type], TC_FROMSTRING);
  1510 		DrawString(2, 45, _vehicle_translation_table[VST_VEHICLE_RELIABILITY_BREAKDOWNS][v->type], TC_FROMSTRING);
  1510 
  1511 
  1511 		/* Draw service interval text */
  1512 		/* Draw service interval text */
  1512 		SetDParam(0, v->service_interval);
  1513 		SetDParam(0, v->service_interval);
  1513 		SetDParam(1, v->date_of_last_service);
  1514 		SetDParam(1, v->date_of_last_service);
  1514 		DrawString(13, this->height - (v->type != VEH_TRAIN ? 11 : 23), _settings.vehicle.servint_ispercent ? STR_SERVICING_INTERVAL_PERCENT : STR_883C_SERVICING_INTERVAL_DAYS, TC_FROMSTRING);
  1515 		DrawString(13, this->height - (v->type != VEH_TRAIN ? 11 : 23), _settings_game.vehicle.servint_ispercent ? STR_SERVICING_INTERVAL_PERCENT : STR_883C_SERVICING_INTERVAL_DAYS, TC_FROMSTRING);
  1515 
  1516 
  1516 		switch (v->type) {
  1517 		switch (v->type) {
  1517 			case VEH_TRAIN:
  1518 			case VEH_TRAIN:
  1518 				DrawVehicleDetails(v, 2, 57, this->vscroll.pos, this->vscroll.cap, det_tab);
  1519 				DrawVehicleDetails(v, 2, 57, this->vscroll.pos, this->vscroll.cap, det_tab);
  1519 				break;
  1520 				break;
  1948 					} else {
  1949 					} else {
  1949 						str = STR_8861_STOPPED;
  1950 						str = STR_8861_STOPPED;
  1950 					}
  1951 					}
  1951 				} else {
  1952 				} else {
  1952 					SetDParam(0, v->GetDisplaySpeed());
  1953 					SetDParam(0, v->GetDisplaySpeed());
  1953 					str = STR_TRAIN_STOPPING + _settings.gui.vehicle_speed;
  1954 					str = STR_TRAIN_STOPPING + _settings_client.gui.vehicle_speed;
  1954 				}
  1955 				}
  1955 			} else { // no train
  1956 			} else { // no train
  1956 				str = STR_8861_STOPPED;
  1957 				str = STR_8861_STOPPED;
  1957 			}
  1958 			}
  1958 		} else { // vehicle is in a "normal" state, show current order
  1959 		} else { // vehicle is in a "normal" state, show current order
  1959 			switch (v->current_order.GetType()) {
  1960 			switch (v->current_order.GetType()) {
  1960 				case OT_GOTO_STATION: {
  1961 				case OT_GOTO_STATION: {
  1961 					SetDParam(0, v->current_order.GetDestination());
  1962 					SetDParam(0, v->current_order.GetDestination());
  1962 					SetDParam(1, v->GetDisplaySpeed());
  1963 					SetDParam(1, v->GetDisplaySpeed());
  1963 					str = STR_HEADING_FOR_STATION + _settings.gui.vehicle_speed;
  1964 					str = STR_HEADING_FOR_STATION + _settings_client.gui.vehicle_speed;
  1964 				} break;
  1965 				} break;
  1965 
  1966 
  1966 				case OT_GOTO_DEPOT: {
  1967 				case OT_GOTO_DEPOT: {
  1967 					if (v->type == VEH_AIRCRAFT) {
  1968 					if (v->type == VEH_AIRCRAFT) {
  1968 						/* Aircrafts always go to a station, even if you say depot */
  1969 						/* Aircrafts always go to a station, even if you say depot */
  1972 						Depot *depot = GetDepot(v->current_order.GetDestination());
  1973 						Depot *depot = GetDepot(v->current_order.GetDestination());
  1973 						SetDParam(0, depot->town_index);
  1974 						SetDParam(0, depot->town_index);
  1974 						SetDParam(1, v->GetDisplaySpeed());
  1975 						SetDParam(1, v->GetDisplaySpeed());
  1975 					}
  1976 					}
  1976 					if ((v->current_order.GetDepotActionType() & ODATFB_HALT) && !(v->current_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS)) {
  1977 					if ((v->current_order.GetDepotActionType() & ODATFB_HALT) && !(v->current_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS)) {
  1977 						str = _heading_for_depot_strings[v->type] + _settings.gui.vehicle_speed;
  1978 						str = _heading_for_depot_strings[v->type] + _settings_client.gui.vehicle_speed;
  1978 					} else {
  1979 					} else {
  1979 						str = _heading_for_depot_service_strings[v->type] + _settings.gui.vehicle_speed;
  1980 						str = _heading_for_depot_service_strings[v->type] + _settings_client.gui.vehicle_speed;
  1980 					}
  1981 					}
  1981 				} break;
  1982 				} break;
  1982 
  1983 
  1983 				case OT_LOADING:
  1984 				case OT_LOADING:
  1984 					str = STR_882F_LOADING_UNLOADING;
  1985 					str = STR_882F_LOADING_UNLOADING;
  1985 					break;
  1986 					break;
  1986 
  1987 
  1987 				case OT_GOTO_WAYPOINT: {
  1988 				case OT_GOTO_WAYPOINT: {
  1988 					assert(v->type == VEH_TRAIN);
  1989 					assert(v->type == VEH_TRAIN);
  1989 					SetDParam(0, v->current_order.GetDestination());
  1990 					SetDParam(0, v->current_order.GetDestination());
  1990 					str = STR_HEADING_FOR_WAYPOINT + _settings.gui.vehicle_speed;
  1991 					str = STR_HEADING_FOR_WAYPOINT + _settings_client.gui.vehicle_speed;
  1991 					SetDParam(1, v->GetDisplaySpeed());
  1992 					SetDParam(1, v->GetDisplaySpeed());
  1992 					break;
  1993 					break;
  1993 				}
  1994 				}
  1994 
  1995 
  1995 				case OT_LEAVESTATION:
  1996 				case OT_LEAVESTATION:
  1999 					}
  2000 					}
  2000 					/* fall-through if aircraft. Does this even happen? */
  2001 					/* fall-through if aircraft. Does this even happen? */
  2001 
  2002 
  2002 				default:
  2003 				default:
  2003 					if (v->num_orders == 0) {
  2004 					if (v->num_orders == 0) {
  2004 						str = STR_NO_ORDERS + _settings.gui.vehicle_speed;
  2005 						str = STR_NO_ORDERS + _settings_client.gui.vehicle_speed;
  2005 						SetDParam(0, v->GetDisplaySpeed());
  2006 						SetDParam(0, v->GetDisplaySpeed());
  2006 					} else {
  2007 					} else {
  2007 						str = STR_EMPTY;
  2008 						str = STR_EMPTY;
  2008 					}
  2009 					}
  2009 					break;
  2010 					break;