Change name of Order cargo-typed get load/unload type accessors.

Move helper functions to get cargo-specific type in cargo-specific
mode, into Order class.
pull/155/head
Jonathan G Rennison 8 years ago
parent 7178ef22e5
commit ed99dd2583

@ -1242,31 +1242,26 @@ Money CargoPayment::PayTransfer(const CargoPacket *cp, uint count)
/** /**
* Returns the load type of a vehicle. * 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 * @pre v != NULL
* @param v A pointer to a vehicle. * @param v A pointer to a vehicle.
* @return the load type of this vehicle. * @return the load type of this vehicle.
*/ */
static OrderLoadFlags GetLoadType(const Vehicle *v) static OrderLoadFlags GetLoadType(const Vehicle *v)
{ {
const Vehicle *front = v->First(); return v->First()->current_order.GetCargoLoadType(v->cargo_type);
OrderLoadFlags olf = front->current_order.GetLoadType();
if (olf == OLFB_CARGO_TYPE_LOAD) olf = front->current_order.GetLoadType(v->cargo_type);
return olf;
} }
/** /**
* Returns the unload type of a vehicle. * 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. * @param v A pointer to a vehicle.
* @return The unload type of this vehicle. * @return The unload type of this vehicle.
*/ */
static OrderUnloadFlags GetUnloadType(const Vehicle *v) static OrderUnloadFlags GetUnloadType(const Vehicle *v)
{ {
const Vehicle *front = v->First(); return v->First()->current_order.GetCargoUnloadType(v->cargo_type);
OrderUnloadFlags ouf = front->current_order.GetUnloadType();
if (ouf == OUFB_CARGO_TYPE_UNLOAD) ouf = front->current_order.GetUnloadType(v->cargo_type);
return ouf;
} }
/** /**
@ -1477,7 +1472,7 @@ struct FinalizeRefitAction
*/ */
bool operator()(Vehicle *v) 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(), this->st->goods[v->cargo_type].cargo.Reserve(v->cargo_cap - v->cargo.RemainingCount(),
&v->cargo, st->xy, this->next_station); &v->cargo, st->xy, this->next_station);
} }
@ -1560,7 +1555,7 @@ struct ReserveCargoAction {
bool operator()(Vehicle *v) 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()) { if (v->cargo_cap > v->cargo.RemainingCount()) {
st->goods[v->cargo_type].cargo.Reserve(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); &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)); IterateVehicleParts(v, ReserveCargoAction(st, next_station, cargo_type_loading ? u : NULL));
} }
if (consist_capleft == NULL || v->cargo_cap == 0) continue; 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(); (*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; bool has_full_load_order = front->current_order.GetLoadType() & OLFB_FULL_LOAD;
if (front->current_order.GetLoadType() == OLFB_CARGO_TYPE_LOAD) { if (front->current_order.GetLoadType() == OLFB_CARGO_TYPE_LOAD) {
for (Vehicle *v = front; v != NULL; v = v->Next()) { 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; has_full_load_order = true;
break; break;
} }

@ -136,12 +136,25 @@ public:
* @param cargo_id The cargo type index. * @param cargo_id The cargo type index.
* @return The load type for this cargo. * @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); assert(cargo_id < NUM_CARGO);
return (OrderLoadFlags) GB(this->cargo_type_flags[cargo_id], 4, 4); 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? */ /** How must the consist be unloaded? */
inline OrderUnloadFlags GetUnloadType() const { return (OrderUnloadFlags)GB(this->flags, 0, 4); } inline OrderUnloadFlags GetUnloadType() const { return (OrderUnloadFlags)GB(this->flags, 0, 4); }
@ -151,12 +164,25 @@ public:
* @param cargo_id The cargo type index. * @param cargo_id The cargo type index.
* @return The unload type for this cargo. * @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); assert(cargo_id < NUM_CARGO);
return (OrderUnloadFlags) GB(this->cargo_type_flags[cargo_id], 0, 4); 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? */ /** At which stations must we stop? */
inline OrderNonStopFlags GetNonStopType() const { return (OrderNonStopFlags)GB(this->type, 6, 2); } inline OrderNonStopFlags GetNonStopType() const { return (OrderNonStopFlags)GB(this->type, 6, 2); }
/** Where must we stop at the platform? */ /** Where must we stop at the platform? */

@ -106,7 +106,7 @@ private:
for (int i = 0; i < _sorted_standard_cargo_specs_size; i++) { for (int i = 0; i < _sorted_standard_cargo_specs_size; i++) {
const CargoSpec *cs = _sorted_cargo_specs[i]; const CargoSpec *cs = _sorted_cargo_specs[i];
CargoID cargo_id = GetCargoIDByBitnum(cs->bitnum); 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<NWidgetCore>(WID_CTO_CARGO_DROPDOWN_FIRST + i)->SetDataTip(this->cargo_type_order_dropdown[order_type], tooltip); this->GetWidget<NWidgetCore>(WID_CTO_CARGO_DROPDOWN_FIRST + i)->SetDataTip(this->cargo_type_order_dropdown[order_type], tooltip);
} }
this->set_to_all_dropdown_sel = 0; this->set_to_all_dropdown_sel = 0;
@ -121,7 +121,7 @@ private:
uint8 GetOrderActionTypeForCargo(CargoID cargo_id) uint8 GetOrderActionTypeForCargo(CargoID cargo_id)
{ {
const Order *order = this->vehicle->GetOrder(this->order_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: public:

Loading…
Cancel
Save