mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-02-10 08:17:05 +00:00
Codechange: Replace order related FOR_ALL with range-based for loops
This commit is contained in:
parent
41232f18c1
commit
9892d90b26
@ -102,8 +102,7 @@ void OrderBackup::DoRestore(Vehicle *v)
|
||||
{
|
||||
/* Don't use reset as that broadcasts over the network to reset the variable,
|
||||
* which is what we are doing at the moment. */
|
||||
OrderBackup *ob;
|
||||
FOR_ALL_ORDER_BACKUPS(ob) {
|
||||
for (OrderBackup *ob : OrderBackup::Iterate()) {
|
||||
if (ob->user == user) delete ob;
|
||||
}
|
||||
if (OrderBackup::CanAllocateItem()) {
|
||||
@ -119,8 +118,7 @@ void OrderBackup::DoRestore(Vehicle *v)
|
||||
*/
|
||||
/* static */ void OrderBackup::Restore(Vehicle *v, uint32 user)
|
||||
{
|
||||
OrderBackup *ob;
|
||||
FOR_ALL_ORDER_BACKUPS(ob) {
|
||||
for (OrderBackup *ob : OrderBackup::Iterate()) {
|
||||
if (v->tile != ob->tile || ob->user != user) continue;
|
||||
|
||||
ob->DoRestore(v);
|
||||
@ -136,8 +134,7 @@ void OrderBackup::DoRestore(Vehicle *v)
|
||||
*/
|
||||
/* static */ void OrderBackup::ResetOfUser(TileIndex tile, uint32 user)
|
||||
{
|
||||
OrderBackup *ob;
|
||||
FOR_ALL_ORDER_BACKUPS(ob) {
|
||||
for (OrderBackup *ob : OrderBackup::Iterate()) {
|
||||
if (ob->user == user && (ob->tile == tile || tile == INVALID_TILE)) delete ob;
|
||||
}
|
||||
}
|
||||
@ -169,9 +166,8 @@ CommandCost CmdClearOrderBackup(TileIndex tile, DoCommandFlag flags, uint32 p1,
|
||||
{
|
||||
assert(_network_server);
|
||||
|
||||
OrderBackup *ob;
|
||||
FOR_ALL_ORDER_BACKUPS(ob) {
|
||||
/* If it's not an backup of us, so ignore it. */
|
||||
for (OrderBackup *ob : OrderBackup::Iterate()) {
|
||||
/* If it's not a backup of us, ignore it. */
|
||||
if (ob->user != user) continue;
|
||||
|
||||
DoCommandP(0, 0, user, CMD_CLEAR_ORDER_BACKUP);
|
||||
@ -193,9 +189,8 @@ CommandCost CmdClearOrderBackup(TileIndex tile, DoCommandFlag flags, uint32 p1,
|
||||
* default is just plain and simple: 0. */
|
||||
uint32 user = _networking && !_network_server ? _network_own_client_id : CLIENT_ID_SERVER;
|
||||
|
||||
OrderBackup *ob;
|
||||
FOR_ALL_ORDER_BACKUPS(ob) {
|
||||
/* If it's not an backup of us, so ignore it. */
|
||||
for (OrderBackup *ob : OrderBackup::Iterate()) {
|
||||
/* If it's not a backup of us, ignore it. */
|
||||
if (ob->user != user) continue;
|
||||
/* If it's not for our chosen tile either, ignore it. */
|
||||
if (t != INVALID_TILE && t != ob->tile) continue;
|
||||
@ -219,8 +214,7 @@ CommandCost CmdClearOrderBackup(TileIndex tile, DoCommandFlag flags, uint32 p1,
|
||||
*/
|
||||
/* static */ void OrderBackup::ClearGroup(GroupID group)
|
||||
{
|
||||
OrderBackup *ob;
|
||||
FOR_ALL_ORDER_BACKUPS(ob) {
|
||||
for (OrderBackup *ob : OrderBackup::Iterate()) {
|
||||
if (ob->group == group) ob->group = DEFAULT_GROUP;
|
||||
}
|
||||
}
|
||||
@ -235,8 +229,7 @@ CommandCost CmdClearOrderBackup(TileIndex tile, DoCommandFlag flags, uint32 p1,
|
||||
/* static */ void OrderBackup::ClearVehicle(const Vehicle *v)
|
||||
{
|
||||
assert(v != nullptr);
|
||||
OrderBackup *ob;
|
||||
FOR_ALL_ORDER_BACKUPS(ob) {
|
||||
for (OrderBackup *ob : OrderBackup::Iterate()) {
|
||||
if (ob->clone == v) {
|
||||
/* Get another item in the shared list. */
|
||||
ob->clone = (v->FirstShared() == v) ? v->NextShared() : v->FirstShared();
|
||||
@ -256,8 +249,7 @@ CommandCost CmdClearOrderBackup(TileIndex tile, DoCommandFlag flags, uint32 p1,
|
||||
*/
|
||||
/* static */ void OrderBackup::RemoveOrder(OrderType type, DestinationID destination, bool hangar)
|
||||
{
|
||||
OrderBackup *ob;
|
||||
FOR_ALL_ORDER_BACKUPS(ob) {
|
||||
for (OrderBackup *ob : OrderBackup::Iterate()) {
|
||||
for (Order *order = ob->orders; order != nullptr; order = order->next) {
|
||||
OrderType ot = order->GetType();
|
||||
if (ot == OT_GOTO_DEPOT && (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) != 0) continue;
|
||||
|
@ -64,17 +64,4 @@ public:
|
||||
static void RemoveOrder(OrderType type, DestinationID destination, bool hangar);
|
||||
};
|
||||
|
||||
/**
|
||||
* Iterator over all order backups from a given ID.
|
||||
* @param var The variable to iterate with.
|
||||
* @param start The start of the iteration.
|
||||
*/
|
||||
#define FOR_ALL_ORDER_BACKUPS_FROM(var, start) FOR_ALL_ITEMS_FROM(OrderBackup, order_backup_index, var, start)
|
||||
|
||||
/**
|
||||
* Iterator over all order backups.
|
||||
* @param var The variable to iterate with.
|
||||
*/
|
||||
#define FOR_ALL_ORDER_BACKUPS(var) FOR_ALL_ORDER_BACKUPS_FROM(var, 0)
|
||||
|
||||
#endif /* ORDER_BACKUP_H */
|
||||
|
@ -390,14 +390,6 @@ public:
|
||||
void DebugCheckSanity() const;
|
||||
};
|
||||
|
||||
#define FOR_ALL_ORDERS_FROM(var, start) FOR_ALL_ITEMS_FROM(Order, order_index, var, start)
|
||||
#define FOR_ALL_ORDERS(var) FOR_ALL_ORDERS_FROM(var, 0)
|
||||
|
||||
|
||||
#define FOR_VEHICLE_ORDERS(v, order) for (order = (v->orders.list == nullptr) ? nullptr : v->orders.list->GetFirstOrder(); order != nullptr; order = order->next)
|
||||
|
||||
|
||||
#define FOR_ALL_ORDER_LISTS_FROM(var, start) FOR_ALL_ITEMS_FROM(OrderList, orderlist_index, var, start)
|
||||
#define FOR_ALL_ORDER_LISTS(var) FOR_ALL_ORDER_LISTS_FROM(var, 0)
|
||||
|
||||
#endif /* ORDER_BASE_H */
|
||||
|
@ -1451,10 +1451,9 @@ bool AfterLoadGame()
|
||||
|
||||
/* Setting no refit flags to all orders in savegames from before refit in orders were added */
|
||||
if (IsSavegameVersionBefore(SLV_36)) {
|
||||
Order *order;
|
||||
Vehicle *v;
|
||||
|
||||
FOR_ALL_ORDERS(order) {
|
||||
for (Order *order : Order::Iterate()) {
|
||||
order->SetRefit(CT_NO_REFIT);
|
||||
}
|
||||
|
||||
@ -1724,8 +1723,7 @@ bool AfterLoadGame()
|
||||
|
||||
if (IsSavegameVersionBefore(SLV_93)) {
|
||||
/* Rework of orders. */
|
||||
Order *order;
|
||||
FOR_ALL_ORDERS(order) order->ConvertFromOldSavegame();
|
||||
for (Order *order : Order::Iterate()) order->ConvertFromOldSavegame();
|
||||
|
||||
Vehicle *v;
|
||||
FOR_ALL_VEHICLES(v) {
|
||||
@ -1736,13 +1734,13 @@ bool AfterLoadGame()
|
||||
|
||||
v->current_order.ConvertFromOldSavegame();
|
||||
if (v->type == VEH_ROAD && v->IsPrimaryVehicle() && v->FirstShared() == v) {
|
||||
Order* order;
|
||||
FOR_VEHICLE_ORDERS(v, order) order->SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
|
||||
}
|
||||
}
|
||||
} else if (IsSavegameVersionBefore(SLV_94)) {
|
||||
/* Unload and transfer are now mutual exclusive. */
|
||||
Order *order;
|
||||
FOR_ALL_ORDERS(order) {
|
||||
for (Order *order : Order::Iterate()) {
|
||||
if ((order->GetUnloadType() & (OUFB_UNLOAD | OUFB_TRANSFER)) == (OUFB_UNLOAD | OUFB_TRANSFER)) {
|
||||
order->SetUnloadType(OUFB_TRANSFER);
|
||||
order->SetLoadType(OLFB_NO_LOAD);
|
||||
@ -2160,8 +2158,7 @@ bool AfterLoadGame()
|
||||
|
||||
/* Trains could now stop in a specific location. */
|
||||
if (IsSavegameVersionBefore(SLV_117)) {
|
||||
Order *o;
|
||||
FOR_ALL_ORDERS(o) {
|
||||
for (Order *o : Order::Iterate()) {
|
||||
if (o->IsType(OT_GOTO_STATION)) o->SetStopLocation(OSL_PLATFORM_FAR_END);
|
||||
}
|
||||
}
|
||||
@ -3014,8 +3011,7 @@ bool AfterLoadGame()
|
||||
#ifndef DEBUG_DUMP_COMMANDS
|
||||
/* Note: We cannot use CleanPool since that skips part of the destructor
|
||||
* and then leaks un-reachable Orders in the order pool. */
|
||||
OrderBackup *ob;
|
||||
FOR_ALL_ORDER_BACKUPS(ob) {
|
||||
for (OrderBackup *ob : OrderBackup::Iterate()) {
|
||||
delete ob;
|
||||
}
|
||||
#endif
|
||||
|
@ -123,9 +123,7 @@ const SaveLoad *GetOrderDescription()
|
||||
|
||||
static void Save_ORDR()
|
||||
{
|
||||
Order *order;
|
||||
|
||||
FOR_ALL_ORDERS(order) {
|
||||
for (Order *order : Order::Iterate()) {
|
||||
SlSetArrayIndex(order->index);
|
||||
SlObject(order, GetOrderDescription());
|
||||
}
|
||||
@ -166,8 +164,8 @@ static void Load_ORDR()
|
||||
}
|
||||
|
||||
/* Update all the next pointer */
|
||||
Order *o;
|
||||
FOR_ALL_ORDERS(o) {
|
||||
for (Order *o : Order::Iterate()) {
|
||||
size_t order_index = o->index;
|
||||
/* Delete invalid orders */
|
||||
if (o->IsType(OT_NOTHING)) {
|
||||
delete o;
|
||||
@ -197,9 +195,7 @@ static void Ptrs_ORDR()
|
||||
/* Orders from old savegames have pointers corrected in Load_ORDR */
|
||||
if (IsSavegameVersionBefore(SLV_5, 2)) return;
|
||||
|
||||
Order *o;
|
||||
|
||||
FOR_ALL_ORDERS(o) {
|
||||
for (Order *o : Order::Iterate()) {
|
||||
SlObject(o, GetOrderDescription());
|
||||
}
|
||||
}
|
||||
@ -216,9 +212,7 @@ const SaveLoad *GetOrderListDescription()
|
||||
|
||||
static void Save_ORDL()
|
||||
{
|
||||
OrderList *list;
|
||||
|
||||
FOR_ALL_ORDER_LISTS(list) {
|
||||
for (OrderList *list : OrderList::Iterate()) {
|
||||
SlSetArrayIndex(list->index);
|
||||
SlObject(list, GetOrderListDescription());
|
||||
}
|
||||
@ -238,9 +232,7 @@ static void Load_ORDL()
|
||||
|
||||
static void Ptrs_ORDL()
|
||||
{
|
||||
OrderList *list;
|
||||
|
||||
FOR_ALL_ORDER_LISTS(list) {
|
||||
for (OrderList *list : OrderList::Iterate()) {
|
||||
SlObject(list, GetOrderListDescription());
|
||||
}
|
||||
}
|
||||
@ -277,8 +269,7 @@ static void Save_BKOR()
|
||||
* normal games this information isn't needed. */
|
||||
if (!_networking || !_network_server) return;
|
||||
|
||||
OrderBackup *ob;
|
||||
FOR_ALL_ORDER_BACKUPS(ob) {
|
||||
for (OrderBackup *ob : OrderBackup::Iterate()) {
|
||||
SlSetArrayIndex(ob->index);
|
||||
SlObject(ob, GetOrderBackupDescription());
|
||||
}
|
||||
@ -297,8 +288,7 @@ void Load_BKOR()
|
||||
|
||||
static void Ptrs_BKOR()
|
||||
{
|
||||
OrderBackup *ob;
|
||||
FOR_ALL_ORDER_BACKUPS(ob) {
|
||||
for (OrderBackup *ob : OrderBackup::Iterate()) {
|
||||
SlObject(ob, GetOrderBackupDescription());
|
||||
}
|
||||
}
|
||||
|
@ -40,8 +40,7 @@ static void UpdateWaypointOrder(Order *o)
|
||||
void MoveBuoysToWaypoints()
|
||||
{
|
||||
/* Buoy orders become waypoint orders */
|
||||
OrderList *ol;
|
||||
FOR_ALL_ORDER_LISTS(ol) {
|
||||
for (OrderList *ol : OrderList::Iterate()) {
|
||||
VehicleType vt = ol->GetFirstSharedVehicle()->type;
|
||||
if (vt != VEH_SHIP && vt != VEH_TRAIN) continue;
|
||||
|
||||
|
@ -130,8 +130,7 @@ void MoveWaypointsToBaseStations()
|
||||
}
|
||||
|
||||
/* Update the orders of vehicles */
|
||||
OrderList *ol;
|
||||
FOR_ALL_ORDER_LISTS(ol) {
|
||||
for (OrderList *ol : OrderList::Iterate()) {
|
||||
if (ol->GetFirstSharedVehicle()->type != VEH_TRAIN) continue;
|
||||
|
||||
for (Order *o = ol->GetFirstOrder(); o != nullptr; o = o->next) UpdateWaypointOrder(o);
|
||||
|
@ -3664,9 +3664,8 @@ void DeleteStaleLinks(Station *from)
|
||||
if (auto_distributed) {
|
||||
/* Have all vehicles refresh their next hops before deciding to
|
||||
* remove the node. */
|
||||
OrderList *l;
|
||||
std::vector<Vehicle *> vehicles;
|
||||
FOR_ALL_ORDER_LISTS(l) {
|
||||
for (OrderList *l : OrderList::Iterate()) {
|
||||
bool found_from = false;
|
||||
bool found_to = false;
|
||||
for (Order *order = l->GetFirstOrder(); order != nullptr; order = order->next) {
|
||||
|
Loading…
Reference in New Issue
Block a user