mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-19 15:25:39 +00:00
6c3e5642f8
# Conflicts: # cmake/CompileFlags.cmake # src/crashlog.cpp # src/fileio.cpp # src/fileio_func.h # src/fios_gui.cpp # src/ini_load.cpp # src/ini_type.h # src/lang/english.txt # src/lang/german.txt # src/lang/korean.txt # src/network/network_client.cpp # src/order_base.h # src/order_cmd.cpp # src/os/windows/win32.cpp # src/road_cmd.cpp # src/saveload/saveload.cpp # src/saveload/saveload.h # src/settings.cpp # src/station_cmd.cpp # src/stdafx.h # src/table/settings.ini # src/tree_cmd.cpp # src/tree_gui.cpp # src/vehicle_base.h # src/video/cocoa/cocoa_v.mm # src/video/cocoa/event.mm # src/video/cocoa/wnd_quartz.mm # src/viewport.cpp # src/widgets/tree_widget.h
78 lines
3.0 KiB
C++
78 lines
3.0 KiB
C++
/*
|
|
* This file is part of OpenTTD.
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
/** @file order_cmd.h Functions related to order commands. */
|
|
|
|
#ifndef ORDER_CMD_H
|
|
#define ORDER_CMD_H
|
|
|
|
#include "order_base.h"
|
|
#include "order_func.h"
|
|
#include "vehicle_base.h"
|
|
|
|
void UpdateOrderDestinationRefcount(const Order *order, VehicleType type, Owner owner, int delta);
|
|
|
|
inline void RegisterOrderDestination(const Order *order, VehicleType type, Owner owner)
|
|
{
|
|
if (_order_destination_refcount_map_valid) UpdateOrderDestinationRefcount(order, type, owner, 1);
|
|
}
|
|
|
|
inline void UnregisterOrderDestination(const Order *order, VehicleType type, Owner owner)
|
|
{
|
|
if (_order_destination_refcount_map_valid) UpdateOrderDestinationRefcount(order, type, owner, -1);
|
|
}
|
|
|
|
/**
|
|
* Removes all orders from a vehicle for which order_predicate returns true.
|
|
* Handles timetable updating, removing implicit orders correctly, etc.
|
|
* @param v The vehicle.
|
|
* @param order_predicate Functor with signature: bool (const Order *)
|
|
*/
|
|
template <typename F> void RemoveVehicleOrdersIf(Vehicle * const v, F order_predicate) {
|
|
/* Clear the order from the order-list */
|
|
int id = -1;
|
|
for(Order *order = v->GetFirstOrder(); order != nullptr; order = order->next) {
|
|
id++;
|
|
restart:
|
|
|
|
if (order_predicate(const_cast<const Order *>(order))) {
|
|
/* We want to clear implicit orders, but we don't want to make them
|
|
* dummy orders. They should just vanish. Also check the actual order
|
|
* type as ot is currently OT_GOTO_STATION. */
|
|
if (order->IsType(OT_IMPLICIT)) {
|
|
order = order->next; // DeleteOrder() invalidates current order
|
|
DeleteOrder(v, id);
|
|
if (order != nullptr) goto restart;
|
|
break;
|
|
}
|
|
|
|
UnregisterOrderDestination(order, v->type, v->owner);
|
|
|
|
/* Clear wait time */
|
|
if (!order->IsType(OT_CONDITIONAL)) v->orders.list->UpdateTotalDuration(-order->GetWaitTime());
|
|
if (order->IsWaitTimetabled()) {
|
|
if (!order->IsType(OT_CONDITIONAL)) v->orders.list->UpdateTimetableDuration(-order->GetTimetabledWait());
|
|
order->SetWaitTimetabled(false);
|
|
}
|
|
order->SetWaitTime(0);
|
|
|
|
/* Clear order, preserving travel time */
|
|
bool travel_timetabled = order->IsTravelTimetabled();
|
|
order->MakeDummy();
|
|
order->SetTravelTimetabled(travel_timetabled);
|
|
|
|
for (const Vehicle *w = v->FirstShared(); w != nullptr; w = w->NextShared()) {
|
|
/* In GUI, simulate by removing the order and adding it back */
|
|
InvalidateVehicleOrder(w, id | (INVALID_VEH_ORDER_ID << 16));
|
|
InvalidateVehicleOrder(w, (INVALID_VEH_ORDER_ID << 16) | id);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#endif /* ORDER_CMD_H */
|