Refactor Link Refresher cargo mask handling.
Add some separate helper functions. Move cargo checks out of LinkRefresher::Run.
This commit is contained in:
@@ -217,6 +217,20 @@ public:
|
||||
return ouf;
|
||||
}
|
||||
|
||||
template <typename F> uint32 FilterLoadUnloadTypeCargoMask(F filter_func, uint32 cargo_mask = ~0)
|
||||
{
|
||||
if ((this->GetLoadType() == OLFB_CARGO_TYPE_LOAD) || (this->GetUnloadType() == OUFB_CARGO_TYPE_UNLOAD)) {
|
||||
CargoID cargo;
|
||||
uint32 output_mask = cargo_mask;
|
||||
FOR_EACH_SET_BIT(cargo, cargo_mask) {
|
||||
if (!filter_func(this, cargo)) ClrBit(output_mask, cargo);
|
||||
}
|
||||
return output_mask;
|
||||
} else {
|
||||
return filter_func(this, FindFirstBit(cargo_mask)) ? cargo_mask : 0;
|
||||
}
|
||||
}
|
||||
|
||||
/** At which stations must we stop? */
|
||||
inline OrderNonStopFlags GetNonStopType() const { return (OrderNonStopFlags)GB(this->type, 6, 2); }
|
||||
/** Where must we stop at the platform? */
|
||||
@@ -389,6 +403,16 @@ public:
|
||||
void FillNextStoppingStation(const Vehicle *v, const OrderList *o, const Order *first = NULL, uint hops = 0);
|
||||
};
|
||||
|
||||
template <typename F> uint32 FilterCargoMask(F filter_func, uint32 cargo_mask = ~0)
|
||||
{
|
||||
CargoID cargo;
|
||||
uint32 output_mask = cargo_mask;
|
||||
FOR_EACH_SET_BIT(cargo, cargo_mask) {
|
||||
if (!filter_func(cargo)) ClrBit(output_mask, cargo);
|
||||
}
|
||||
return output_mask;
|
||||
}
|
||||
|
||||
template <typename T, typename F> T CargoMaskValueFilter(uint32 &cargo_mask, F filter_func)
|
||||
{
|
||||
CargoID first_cargo_id = FindFirstBit(cargo_mask);
|
||||
|
Reference in New Issue
Block a user