MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / ChangeVehicleWindow

Function ChangeVehicleWindow

src/vehicle_gui.cpp:1566–1582  ·  view source on GitHub ↗

* Assign a vehicle window a new vehicle * @param window_class WindowClass to search for * @param from_index the old vehicle ID * @param to_index the new vehicle ID */

Source from the content-addressed store, hash-verified

1564 * @param to_index the new vehicle ID
1565 */
1566static inline void ChangeVehicleWindow(WindowClass window_class, VehicleID from_index, VehicleID to_index)
1567{
1568 Window *w = FindWindowById(window_class, from_index);
1569 if (w != nullptr) {
1570 /* Update window_number */
1571 w->window_number = to_index;
1572 if (w->viewport != nullptr) w->viewport->follow_vehicle = to_index;
1573
1574 /* Update vehicle drag data */
1575 if (_thd.window_class == window_class && _thd.window_number == from_index) {
1576 _thd.window_number = to_index;
1577 }
1578
1579 /* Notify the window. */
1580 w->InvalidateData(VIWD_AUTOREPLACE, false);
1581 }
1582}
1583
1584/**
1585 * Report a change in vehicle IDs (due to autoreplace) to affected vehicle windows.

Callers 1

ChangeVehicleViewWindowFunction · 0.85

Calls 2

FindWindowByIdFunction · 0.85
InvalidateDataMethod · 0.45

Tested by

no test coverage detected