equal
deleted
inserted
replaced
38 #include "date.h" |
38 #include "date.h" |
39 #include "newgrf_callbacks.h" |
39 #include "newgrf_callbacks.h" |
40 #include "newgrf_engine.h" |
40 #include "newgrf_engine.h" |
41 #include "newgrf_sound.h" |
41 #include "newgrf_sound.h" |
42 #include "helpers.hpp" |
42 #include "helpers.hpp" |
|
43 #include "group.h" |
43 #include "economy.h" |
44 #include "economy.h" |
44 |
45 |
45 #define INVALID_COORD (-0x8000) |
46 #define INVALID_COORD (-0x8000) |
46 #define GEN_HASH(x, y) ((GB((y), 6, 6) << 6) + GB((x), 7, 6)) |
47 #define GEN_HASH(x, y) ((GB((y), 6, 6) << 6) + GB((x), 7, 6)) |
47 |
48 |
109 { |
110 { |
110 if (v->vehstatus & VS_CRASHED) |
111 if (v->vehstatus & VS_CRASHED) |
111 return false; // Crashed vehicles don't need service anymore |
112 return false; // Crashed vehicles don't need service anymore |
112 |
113 |
113 if (_patches.no_servicing_if_no_breakdowns && _opt.diff.vehicle_breakdowns == 0) { |
114 if (_patches.no_servicing_if_no_breakdowns && _opt.diff.vehicle_breakdowns == 0) { |
114 return EngineHasReplacementForPlayer(GetPlayer(v->owner), v->engine_type); /* Vehicles set for autoreplacing needs to go to a depot even if breakdowns are turned off */ |
115 return EngineHasReplacementForPlayer(GetPlayer(v->owner), v->engine_type, v->group_id); /* Vehicles set for autoreplacing needs to go to a depot even if breakdowns are turned off */ |
115 } |
116 } |
116 |
117 |
117 return _patches.servint_ispercent ? |
118 return _patches.servint_ispercent ? |
118 (v->reliability < GetEngine(v->engine_type)->reliability * (100 - v->service_interval) / 100) : |
119 (v->reliability < GetEngine(v->engine_type)->reliability * (100 - v->service_interval) / 100) : |
119 (v->date_of_last_service + v->service_interval < _date); |
120 (v->date_of_last_service + v->service_interval < _date); |
282 v->string_id = 0; |
283 v->string_id = 0; |
283 v->next_shared = NULL; |
284 v->next_shared = NULL; |
284 v->prev_shared = NULL; |
285 v->prev_shared = NULL; |
285 v->depot_list = NULL; |
286 v->depot_list = NULL; |
286 v->random_bits = 0; |
287 v->random_bits = 0; |
|
288 v->group_id = DEFAULT_GROUP; |
|
289 |
287 return v; |
290 return v; |
288 } |
291 } |
289 |
292 |
290 /** |
293 /** |
291 * Get a value for a vehicle's random_bits. |
294 * Get a value for a vehicle's random_bits. |
578 } |
581 } |
579 |
582 |
580 if (IsEngineCountable(v)) { |
583 if (IsEngineCountable(v)) { |
581 GetPlayer(v->owner)->num_engines[v->engine_type]--; |
584 GetPlayer(v->owner)->num_engines[v->engine_type]--; |
582 if (v->owner == _local_player) InvalidateAutoreplaceWindow(v->engine_type); |
585 if (v->owner == _local_player) InvalidateAutoreplaceWindow(v->engine_type); |
|
586 |
|
587 if (!IsDefaultGroupID(v->group_id) && IsValidGroupID(v->group_id)) GetGroup(v->group_id)->num_engines[v->engine_type]--; |
583 } |
588 } |
584 |
589 |
585 DeleteVehicleNews(v->index, INVALID_STRING_ID); |
590 DeleteVehicleNews(v->index, INVALID_STRING_ID); |
586 |
591 |
587 DeleteName(v->string_id); |
592 DeleteName(v->string_id); |
1819 if (flags & DC_EXEC && v_front->type == VEH_TRAIN) { |
1824 if (flags & DC_EXEC && v_front->type == VEH_TRAIN) { |
1820 /* for trains this needs to be the front engine due to the callback function */ |
1825 /* for trains this needs to be the front engine due to the callback function */ |
1821 _new_vehicle_id = w_front->index; |
1826 _new_vehicle_id = w_front->index; |
1822 } |
1827 } |
1823 |
1828 |
|
1829 if (flags & DC_EXEC) { |
|
1830 /* Cloned vehicles belong to the same group */ |
|
1831 DoCommand(0, v_front->group_id, w_front->index, flags, CMD_ADD_VEHICLE_GROUP); |
|
1832 } |
|
1833 |
|
1834 |
1824 /* Take care of refitting. */ |
1835 /* Take care of refitting. */ |
1825 w = w_front; |
1836 w = w_front; |
1826 v = v_front; |
1837 v = v_front; |
1827 |
1838 |
1828 /* Both building and refitting are influenced by newgrf callbacks, which |
1839 /* Both building and refitting are influenced by newgrf callbacks, which |
1971 <ul> |
1982 <ul> |
1972 <li>VLW_STATION_LIST: index of station to generate a list for</li> |
1983 <li>VLW_STATION_LIST: index of station to generate a list for</li> |
1973 <li>VLW_SHARED_ORDERS: index of order to generate a list for<li> |
1984 <li>VLW_SHARED_ORDERS: index of order to generate a list for<li> |
1974 <li>VLW_STANDARD: not used<li> |
1985 <li>VLW_STANDARD: not used<li> |
1975 <li>VLW_DEPOT_LIST: TileIndex of the depot/hangar to make the list for</li> |
1986 <li>VLW_DEPOT_LIST: TileIndex of the depot/hangar to make the list for</li> |
|
1987 <li>VLW_GROUP_LIST: index of group to generate a list for</li> |
1976 </ul> |
1988 </ul> |
1977 * @param window_type tells what kind of window the list is for. Use the VLW flags in vehicle_gui.h |
1989 * @param window_type tells what kind of window the list is for. Use the VLW flags in vehicle_gui.h |
1978 * @return the number of vehicles added to the list |
1990 * @return the number of vehicles added to the list |
1979 */ |
1991 */ |
1980 uint GenerateVehicleSortList(const Vehicle ***sort_list, uint16 *length_of_array, VehicleType type, PlayerID owner, uint32 index, uint16 window_type) |
1992 uint GenerateVehicleSortList(const Vehicle ***sort_list, uint16 *length_of_array, VehicleType type, PlayerID owner, uint32 index, uint16 window_type) |
2048 } |
2060 } |
2049 } |
2061 } |
2050 } |
2062 } |
2051 break; |
2063 break; |
2052 } |
2064 } |
|
2065 |
|
2066 case VLW_GROUP_LIST: |
|
2067 FOR_ALL_VEHICLES(v) { |
|
2068 if (v->type == type && ( |
|
2069 (type == VEH_TRAIN && IsFrontEngine(v)) || |
|
2070 (type != VEH_TRAIN && v->subtype <= subtype) |
|
2071 ) && v->owner == owner && v->group_id == index) { |
|
2072 if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, GetNumVehicles() / 4); |
|
2073 |
|
2074 (*sort_list)[n++] = v; |
|
2075 } |
|
2076 } |
|
2077 break; |
2053 |
2078 |
2054 default: NOT_REACHED(); break; |
2079 default: NOT_REACHED(); break; |
2055 } |
2080 } |
2056 |
2081 |
2057 if ((n + 100) < *length_of_array) { |
2082 if ((n + 100) < *length_of_array) { |
2665 SLE_VAR(Vehicle, waiting_triggers, SLE_UINT8), |
2690 SLE_VAR(Vehicle, waiting_triggers, SLE_UINT8), |
2666 |
2691 |
2667 SLE_REF(Vehicle, next_shared, REF_VEHICLE), |
2692 SLE_REF(Vehicle, next_shared, REF_VEHICLE), |
2668 SLE_REF(Vehicle, prev_shared, REF_VEHICLE), |
2693 SLE_REF(Vehicle, prev_shared, REF_VEHICLE), |
2669 |
2694 |
|
2695 SLE_CONDVAR(Vehicle, group_id, SLE_UINT16, 60, SL_MAX_VERSION), |
|
2696 |
2670 /* reserve extra space in savegame here. (currently 10 bytes) */ |
2697 /* reserve extra space in savegame here. (currently 10 bytes) */ |
2671 SLE_CONDNULL(10, 2, SL_MAX_VERSION), |
2698 SLE_CONDNULL(10, 2, SL_MAX_VERSION), |
2672 |
2699 |
2673 SLE_END() |
2700 SLE_END() |
2674 }; |
2701 }; |
2863 /* Convert the current_order.type (which is a mix of type and flags, because |
2890 /* Convert the current_order.type (which is a mix of type and flags, because |
2864 * in those versions, they both were 4 bits big) to type and flags */ |
2891 * in those versions, they both were 4 bits big) to type and flags */ |
2865 v->current_order.flags = (v->current_order.type & 0xF0) >> 4; |
2892 v->current_order.flags = (v->current_order.type & 0xF0) >> 4; |
2866 v->current_order.type.m_val &= 0x0F; |
2893 v->current_order.type.m_val &= 0x0F; |
2867 } |
2894 } |
|
2895 |
|
2896 /* Advanced vehicle lists got added */ |
|
2897 if (CheckSavegameVersion(60)) v->group_id = DEFAULT_GROUP; |
2868 } |
2898 } |
2869 |
2899 |
2870 /* Check for shared order-lists (we now use pointers for that) */ |
2900 /* Check for shared order-lists (we now use pointers for that) */ |
2871 if (CheckSavegameVersionOldStyle(5, 2)) { |
2901 if (CheckSavegameVersionOldStyle(5, 2)) { |
2872 FOR_ALL_VEHICLES(v) { |
2902 FOR_ALL_VEHICLES(v) { |