diff --git a/src/economy.cpp b/src/economy.cpp index 376e7da82d..fb4fc6dcc8 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -1242,31 +1242,26 @@ Money CargoPayment::PayTransfer(const CargoPacket *cp, uint count) /** * Returns the load type of a vehicle. - * In case of cargo type order, the load type returned depends of the cargo carriable by the vehicle. + * In case of cargo type order, the load type returned depends on the cargo carriable by the vehicle. * @pre v != NULL * @param v A pointer to a vehicle. * @return the load type of this vehicle. */ static OrderLoadFlags GetLoadType(const Vehicle *v) { - const Vehicle *front = v->First(); - OrderLoadFlags olf = front->current_order.GetLoadType(); - if (olf == OLFB_CARGO_TYPE_LOAD) olf = front->current_order.GetLoadType(v->cargo_type); - return olf; + return v->First()->current_order.GetCargoLoadType(v->cargo_type); } /** * Returns the unload type of a vehicle. - * In case of cargo type order, the unload type returned depends of the cargo carriable be the vehicle. + * In case of cargo type order, the unload type returned depends on the cargo carriable by the vehicle. + * @pre v != NULL * @param v A pointer to a vehicle. * @return The unload type of this vehicle. */ static OrderUnloadFlags GetUnloadType(const Vehicle *v) { - const Vehicle *front = v->First(); - OrderUnloadFlags ouf = front->current_order.GetUnloadType(); - if (ouf == OUFB_CARGO_TYPE_UNLOAD) ouf = front->current_order.GetUnloadType(v->cargo_type); - return ouf; + return v->First()->current_order.GetCargoUnloadType(v->cargo_type); } /** @@ -1477,7 +1472,7 @@ struct FinalizeRefitAction */ bool operator()(Vehicle *v) { - if (this->do_reserve || (cargo_type_loading == NULL || (cargo_type_loading->current_order.GetLoadType(v->cargo_type) & OLFB_FULL_LOAD))) { + if (this->do_reserve || (cargo_type_loading == NULL || (cargo_type_loading->current_order.GetCargoLoadTypeRaw(v->cargo_type) & OLFB_FULL_LOAD))) { this->st->goods[v->cargo_type].cargo.Reserve(v->cargo_cap - v->cargo.RemainingCount(), &v->cargo, st->xy, this->next_station); } @@ -1560,7 +1555,7 @@ struct ReserveCargoAction { bool operator()(Vehicle *v) { - if (cargo_type_loading != NULL && !(cargo_type_loading->current_order.GetLoadType(v->cargo_type) & OLFB_FULL_LOAD)) return true; + if (cargo_type_loading != NULL && !(cargo_type_loading->current_order.GetCargoLoadTypeRaw(v->cargo_type) & OLFB_FULL_LOAD)) return true; if (v->cargo_cap > v->cargo.RemainingCount()) { st->goods[v->cargo_type].cargo.Reserve(v->cargo_cap - v->cargo.RemainingCount(), &v->cargo, st->xy, *next_station); @@ -1599,7 +1594,7 @@ static void ReserveConsist(Station *st, Vehicle *u, CargoArray *consist_capleft, IterateVehicleParts(v, ReserveCargoAction(st, next_station, cargo_type_loading ? u : NULL)); } if (consist_capleft == NULL || v->cargo_cap == 0) continue; - if (cargo_type_loading && !(u->current_order.GetLoadType(v->cargo_type) & OLFB_FULL_LOAD)) continue; + if (cargo_type_loading && !(u->current_order.GetCargoLoadTypeRaw(v->cargo_type) & OLFB_FULL_LOAD)) continue; (*consist_capleft)[v->cargo_type] += v->cargo_cap - v->cargo.RemainingCount(); } } @@ -1866,7 +1861,7 @@ static void LoadUnloadVehicle(Vehicle *front) bool has_full_load_order = front->current_order.GetLoadType() & OLFB_FULL_LOAD; if (front->current_order.GetLoadType() == OLFB_CARGO_TYPE_LOAD) { for (Vehicle *v = front; v != NULL; v = v->Next()) { - if (front->current_order.GetLoadType(v->cargo_type) & OLFB_FULL_LOAD) { + if (front->current_order.GetCargoLoadTypeRaw(v->cargo_type) & OLFB_FULL_LOAD) { has_full_load_order = true; break; } diff --git a/src/order_base.h b/src/order_base.h index 93351dd7c8..ff0a003c13 100644 --- a/src/order_base.h +++ b/src/order_base.h @@ -136,12 +136,25 @@ public: * @param cargo_id The cargo type index. * @return The load type for this cargo. */ - inline OrderLoadFlags GetLoadType(CargoID cargo_id) const + inline OrderLoadFlags GetCargoLoadTypeRaw(CargoID cargo_id) const { assert(cargo_id < NUM_CARGO); return (OrderLoadFlags) GB(this->cargo_type_flags[cargo_id], 4, 4); } + /** + * How must the consist be loaded for this type of cargo? + * @param cargo_id The cargo type index. + * @return The load type for this cargo. + */ + inline OrderLoadFlags GetCargoLoadType(CargoID cargo_id) const + { + assert(cargo_id < NUM_CARGO); + OrderLoadFlags olf = this->GetLoadType(); + if (olf == OLFB_CARGO_TYPE_LOAD) olf = this->GetCargoLoadTypeRaw(cargo_id); + return olf; + } + /** How must the consist be unloaded? */ inline OrderUnloadFlags GetUnloadType() const { return (OrderUnloadFlags)GB(this->flags, 0, 4); } @@ -151,12 +164,25 @@ public: * @param cargo_id The cargo type index. * @return The unload type for this cargo. */ - inline OrderUnloadFlags GetUnloadType(CargoID cargo_id) const + inline OrderUnloadFlags GetCargoUnloadTypeRaw(CargoID cargo_id) const { assert(cargo_id < NUM_CARGO); return (OrderUnloadFlags) GB(this->cargo_type_flags[cargo_id], 0, 4); } + /** + * How must the consist be unloaded for this type of cargo? + * @param cargo_id The cargo type index. + * @return The unload type for this cargo. + */ + inline OrderUnloadFlags GetCargoUnloadType(CargoID cargo_id) const + { + assert(cargo_id < NUM_CARGO); + OrderUnloadFlags ouf = this->GetUnloadType(); + if (ouf == OUFB_CARGO_TYPE_UNLOAD) ouf = this->GetCargoUnloadTypeRaw(cargo_id); + return ouf; + } + /** At which stations must we stop? */ inline OrderNonStopFlags GetNonStopType() const { return (OrderNonStopFlags)GB(this->type, 6, 2); } /** Where must we stop at the platform? */ diff --git a/src/order_gui.cpp b/src/order_gui.cpp index c43b41ae40..21914689fe 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -106,7 +106,7 @@ private: for (int i = 0; i < _sorted_standard_cargo_specs_size; i++) { const CargoSpec *cs = _sorted_cargo_specs[i]; CargoID cargo_id = GetCargoIDByBitnum(cs->bitnum); - uint8 order_type = (this->variant == CTOWV_LOAD) ? (uint8) order->GetLoadType(cargo_id) : (uint8) order->GetUnloadType(cargo_id); + uint8 order_type = (this->variant == CTOWV_LOAD) ? (uint8) order->GetCargoLoadTypeRaw(cargo_id) : (uint8) order->GetCargoUnloadTypeRaw(cargo_id); this->GetWidget(WID_CTO_CARGO_DROPDOWN_FIRST + i)->SetDataTip(this->cargo_type_order_dropdown[order_type], tooltip); } this->set_to_all_dropdown_sel = 0; @@ -121,7 +121,7 @@ private: uint8 GetOrderActionTypeForCargo(CargoID cargo_id) { const Order *order = this->vehicle->GetOrder(this->order_id); - return (this->variant == CTOWV_LOAD) ? (uint8) order->GetLoadType(cargo_id) : (uint8) order->GetUnloadType(cargo_id); + return (this->variant == CTOWV_LOAD) ? (uint8) order->GetCargoLoadTypeRaw(cargo_id) : (uint8) order->GetCargoUnloadTypeRaw(cargo_id); } public: