diff options
author | fonsinchen <fonsinchen@openttd.org> | 2014-05-01 14:48:44 +0000 |
---|---|---|
committer | fonsinchen <fonsinchen@openttd.org> | 2014-05-01 14:48:44 +0000 |
commit | c915d9fa55e8bb42b33c56b94c5a5e0ff446d7da (patch) | |
tree | d908c9f08f9ba22552bb21121936e5d279e00c4b /src | |
parent | 4ef537ba338c44a84b4defcce5aa24554edcde22 (diff) | |
download | openttd-c915d9fa55e8bb42b33c56b94c5a5e0ff446d7da.tar.xz |
(svn r26546) -Codechange: Make order wait_time, travel_time and max_speed private
Diffstat (limited to 'src')
-rw-r--r-- | src/economy.cpp | 2 | ||||
-rw-r--r-- | src/order_base.h | 30 | ||||
-rw-r--r-- | src/order_cmd.cpp | 10 | ||||
-rw-r--r-- | src/order_gui.cpp | 8 | ||||
-rw-r--r-- | src/roadveh_cmd.cpp | 2 | ||||
-rw-r--r-- | src/ship.h | 2 | ||||
-rw-r--r-- | src/ship_cmd.cpp | 2 | ||||
-rw-r--r-- | src/timetable_cmd.cpp | 40 | ||||
-rw-r--r-- | src/timetable_gui.cpp | 32 | ||||
-rw-r--r-- | src/train_cmd.cpp | 2 | ||||
-rw-r--r-- | src/vehicle.cpp | 6 |
11 files changed, 83 insertions, 53 deletions
diff --git a/src/economy.cpp b/src/economy.cpp index e3b3575b3..ea82ed84b 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -1675,7 +1675,7 @@ static void LoadUnloadVehicle(Vehicle *front) /* We loaded less cargo than possible for all cargo types and it's not full * load and we're not supposed to wait any longer: stop loading. */ if (!anything_unloaded && full_load_amount == 0 && reservation_left == 0 && !(front->current_order.GetLoadType() & OLFB_FULL_LOAD) && - front->current_order_time >= (uint)max(front->current_order.wait_time - front->lateness_counter, 0)) { + front->current_order_time >= (uint)max(front->current_order.GetWaitTime() - front->lateness_counter, 0)) { SetBit(front->vehicle_flags, VF_STOP_LOADING); } } else { diff --git a/src/order_base.h b/src/order_base.h index ff0813613..b1f83b1c5 100644 --- a/src/order_base.h +++ b/src/order_base.h @@ -43,13 +43,13 @@ private: CargoID refit_cargo; ///< Refit CargoID -public: - Order *next; ///< Pointer to next order. If NULL, end of list - uint16 wait_time; ///< How long in ticks to wait at the destination. uint16 travel_time; ///< How long in ticks the journey to this destination should take. uint16 max_speed; ///< How fast the vehicle may go on the way to the destination. +public: + Order *next; ///< Pointer to next order. If NULL, end of list + Order() : refit_cargo(CT_NO_REFIT), max_speed(UINT16_MAX) {} ~Order(); @@ -167,6 +167,30 @@ public: /** Set the value to base the skip on. */ inline void SetConditionValue(uint16 value) { SB(this->dest, 0, 11, value); } + /** Get the time in ticks a vehicle should wait at the destination. */ + inline uint16 GetWaitTime() const { return this->wait_time; } + /** Get the time in ticks a vehicle should take to reach the destination. */ + inline uint16 GetTravelTime() const { return this->travel_time; } + + /** + * Get the maxmimum speed in km-ish/h a vehicle is allowed to reach on the way to the + * destination. + * @return maximum speed. + */ + inline uint16 GetMaxSpeed() const { return this->max_speed; } + + /** Set the time in ticks a vehicle should wait at the destination. */ + inline void SetWaitTime(uint16 time) { this->wait_time = time; } + /** Set the time in ticks a vehicle should take to reach the destination. */ + inline void SetTravelTime(uint16 time) { this->travel_time = time; } + + /** + * Set the maxmimum speed in km-ish/h a vehicle is allowed to reach on the way to the + * destination. + * @param speed Speed to be set. + */ + inline void SetMaxSpeed(uint16 speed) { this->max_speed = speed; } + bool ShouldStopAtStation(const Vehicle *v, StationID station) const; bool CanLoadOrUnload() const; bool CanLeaveWithCargo(bool has_cargo) const; diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index e73f4f35f..1b74416da 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -301,7 +301,7 @@ void OrderList::Initialize(Order *chain, Vehicle *v) for (Order *o = this->first; o != NULL; o = o->next) { ++this->num_orders; if (!o->IsType(OT_IMPLICIT)) ++this->num_manual_orders; - this->timetable_duration += o->wait_time + o->travel_time; + this->timetable_duration += o->GetWaitTime() + o->GetTravelTime(); } for (Vehicle *u = this->first_shared->PreviousShared(); u != NULL; u = u->PreviousShared()) { @@ -476,7 +476,7 @@ void OrderList::InsertOrderAt(Order *new_order, int index) } ++this->num_orders; if (!new_order->IsType(OT_IMPLICIT)) ++this->num_manual_orders; - this->timetable_duration += new_order->wait_time + new_order->travel_time; + this->timetable_duration += new_order->GetWaitTime() + new_order->GetTravelTime(); /* We can visit oil rigs and buoys that are not our own. They will be shown in * the list of stations. So, we need to invalidate that window if needed. */ @@ -508,7 +508,7 @@ void OrderList::DeleteOrderAt(int index) } --this->num_orders; if (!to_remove->IsType(OT_IMPLICIT)) --this->num_manual_orders; - this->timetable_duration -= (to_remove->wait_time + to_remove->travel_time); + this->timetable_duration -= (to_remove->GetWaitTime() + to_remove->GetTravelTime()); delete to_remove; } @@ -609,7 +609,7 @@ void OrderList::DebugCheckSanity() const for (const Order *o = this->first; o != NULL; o = o->next) { ++check_num_orders; if (!o->IsType(OT_IMPLICIT)) ++check_num_manual_orders; - check_timetable_duration += o->wait_time + o->travel_time; + check_timetable_duration += o->GetWaitTime() + o->GetTravelTime(); } assert(this->num_orders == check_num_orders); assert(this->num_manual_orders == check_num_manual_orders); @@ -2081,7 +2081,7 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth, bool UpdateVehicleTimetable(v, false); v->cur_implicit_order_index = v->cur_real_order_index = next_order; v->UpdateRealOrderIndex(); - v->current_order_time += v->GetOrder(v->cur_real_order_index)->travel_time; + v->current_order_time += v->GetOrder(v->cur_real_order_index)->GetTravelTime(); /* Disable creation of implicit orders. * When inserting them we do not know that we would have to make the conditional orders point to them. */ diff --git a/src/order_gui.cpp b/src/order_gui.cpp index ac248f878..d5e5c5a2d 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -266,9 +266,9 @@ void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int if (timetable) { SetDParam(3, STR_EMPTY); - if (order->wait_time > 0) { + if (order->GetWaitTime() > 0) { SetDParam(5, STR_TIMETABLE_STAY_FOR); - SetTimetableParams(6, 7, order->wait_time); + SetTimetableParams(6, 7, order->GetWaitTime()); } } else { SetDParam(3, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) ? STR_EMPTY : _station_load_types[order->IsRefit()][unload][load]); @@ -334,9 +334,9 @@ void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int SetDParam(4, value); } - if (timetable && order->wait_time > 0) { + if (timetable && order->GetWaitTime() > 0) { SetDParam(5, STR_TIMETABLE_AND_TRAVEL_FOR); - SetTimetableParams(6, 7, order->wait_time); + SetTimetableParams(6, 7, order->GetWaitTime()); } else { SetDParam(5, STR_EMPTY); } diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index 88a31de73..b3310af10 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -460,7 +460,7 @@ inline int RoadVehicle::GetCurrentMaxSpeed() const } } - return min(max_speed, this->current_order.max_speed * 2); + return min(max_speed, this->current_order.GetMaxSpeed() * 2); } /** diff --git a/src/ship.h b/src/ship.h index 29f4439d4..18f04c8fa 100644 --- a/src/ship.h +++ b/src/ship.h @@ -37,7 +37,7 @@ struct Ship FINAL : public SpecializedVehicle<Ship, VEH_SHIP> { SpriteID GetImage(Direction direction, EngineImageType image_type) const; int GetDisplaySpeed() const { return this->cur_speed / 2; } int GetDisplayMaxSpeed() const { return this->vcache.cached_max_speed / 2; } - int GetCurrentMaxSpeed() const { return min(this->vcache.cached_max_speed, this->current_order.max_speed * 2); } + int GetCurrentMaxSpeed() const { return min(this->vcache.cached_max_speed, this->current_order.GetMaxSpeed() * 2); } Money GetRunningCost() const; bool IsInDepot() const { return this->state == TRACK_BIT_DEPOT; } bool Tick(); diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp index 210af2027..4fcda7c27 100644 --- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -378,7 +378,7 @@ static bool ShipAccelerate(Vehicle *v) byte t; spd = min(v->cur_speed + 1, v->vcache.cached_max_speed); - spd = min(spd, v->current_order.max_speed * 2); + spd = min(spd, v->current_order.GetMaxSpeed() * 2); /* updates statusbar only if speed have changed to save CPU time */ if (spd != v->cur_speed) { diff --git a/src/timetable_cmd.cpp b/src/timetable_cmd.cpp index 2e2150642..a0f797bea 100644 --- a/src/timetable_cmd.cpp +++ b/src/timetable_cmd.cpp @@ -36,17 +36,17 @@ static void ChangeTimetable(Vehicle *v, VehicleOrderID order_number, uint16 val, switch (mtf) { case MTF_WAIT_TIME: - delta = val - order->wait_time; - order->wait_time = val; + delta = val - order->GetWaitTime(); + order->SetWaitTime(val); break; case MTF_TRAVEL_TIME: - delta = val - order->travel_time; - order->travel_time = val; + delta = val - order->GetTravelTime(); + order->SetTravelTime(val); break; case MTF_TRAVEL_SPEED: - order->max_speed = val; + order->SetMaxSpeed(val); break; default: @@ -58,15 +58,15 @@ static void ChangeTimetable(Vehicle *v, VehicleOrderID order_number, uint16 val, if (v->cur_real_order_index == order_number && v->current_order.Equals(*order)) { switch (mtf) { case MTF_WAIT_TIME: - v->current_order.wait_time = val; + v->current_order.SetWaitTime(val); break; case MTF_TRAVEL_TIME: - v->current_order.travel_time = val; + v->current_order.SetTravelTime(val); break; case MTF_TRAVEL_SPEED: - v->current_order.max_speed = val; + v->current_order.SetMaxSpeed(val); break; default: @@ -107,9 +107,9 @@ CommandCost CmdChangeTimetable(TileIndex tile, DoCommandFlag flags, uint32 p1, u ModifyTimetableFlags mtf = Extract<ModifyTimetableFlags, 28, 2>(p1); if (mtf >= MTF_END) return CMD_ERROR; - int wait_time = order->wait_time; - int travel_time = order->travel_time; - int max_speed = order->max_speed; + int wait_time = order->GetWaitTime(); + int travel_time = order->GetTravelTime(); + int max_speed = order->GetMaxSpeed(); switch (mtf) { case MTF_WAIT_TIME: wait_time = GB(p2, 0, 16); @@ -128,7 +128,7 @@ CommandCost CmdChangeTimetable(TileIndex tile, DoCommandFlag flags, uint32 p1, u NOT_REACHED(); } - if (wait_time != order->wait_time) { + if (wait_time != order->GetWaitTime()) { switch (order->GetType()) { case OT_GOTO_STATION: if (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) return_cmd_error(STR_ERROR_TIMETABLE_NOT_STOPPING_HERE); @@ -141,13 +141,13 @@ CommandCost CmdChangeTimetable(TileIndex tile, DoCommandFlag flags, uint32 p1, u } } - if (travel_time != order->travel_time && order->IsType(OT_CONDITIONAL)) return CMD_ERROR; - if (max_speed != order->max_speed && (order->IsType(OT_CONDITIONAL) || v->type == VEH_AIRCRAFT)) return CMD_ERROR; + if (travel_time != order->GetTravelTime() && order->IsType(OT_CONDITIONAL)) return CMD_ERROR; + if (max_speed != order->GetMaxSpeed() && (order->IsType(OT_CONDITIONAL) || v->type == VEH_AIRCRAFT)) return CMD_ERROR; if (flags & DC_EXEC) { - if (wait_time != order->wait_time) ChangeTimetable(v, order_number, wait_time, MTF_WAIT_TIME); - if (travel_time != order->travel_time) ChangeTimetable(v, order_number, travel_time, MTF_TRAVEL_TIME); - if (max_speed != order->max_speed) ChangeTimetable(v, order_number, max_speed, MTF_TRAVEL_SPEED); + if (wait_time != order->GetWaitTime()) ChangeTimetable(v, order_number, wait_time, MTF_WAIT_TIME); + if (travel_time != order->GetTravelTime()) ChangeTimetable(v, order_number, travel_time, MTF_TRAVEL_TIME); + if (max_speed != order->GetMaxSpeed()) ChangeTimetable(v, order_number, max_speed, MTF_TRAVEL_SPEED); } return CommandCost(); @@ -347,7 +347,7 @@ CommandCost CmdAutofillTimetable(TileIndex tile, DoCommandFlag flags, uint32 p1, */ void UpdateVehicleTimetable(Vehicle *v, bool travelling) { - uint timetabled = travelling ? v->current_order.travel_time : v->current_order.wait_time; + uint timetabled = travelling ? v->current_order.GetTravelTime() : v->current_order.GetWaitTime(); uint time_taken = v->current_order_time; v->current_order_time = 0; @@ -383,14 +383,14 @@ void UpdateVehicleTimetable(Vehicle *v, bool travelling) if (HasBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE)) { if (travelling && !HasBit(v->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME)) { /* Need to clear that now as otherwise we are not able to reduce the wait time */ - v->current_order.wait_time = 0; + v->current_order.SetWaitTime(0); } if (just_started) return; /* Modify station waiting time only if our new value is larger (this is * always the case when we cleared the timetable). */ - if (!v->current_order.IsType(OT_CONDITIONAL) && (travelling || time_taken > v->current_order.wait_time)) { + if (!v->current_order.IsType(OT_CONDITIONAL) && (travelling || time_taken > v->current_order.GetWaitTime())) { /* Round the time taken up to the nearest day, as this will avoid * confusion for people who are timetabling in days, and can be * adjusted later by people who aren't. diff --git a/src/timetable_gui.cpp b/src/timetable_gui.cpp index b05c07211..42c7de33f 100644 --- a/src/timetable_gui.cpp +++ b/src/timetable_gui.cpp @@ -78,9 +78,12 @@ static bool CanDetermineTimeTaken(const Order *order, bool travelling) /* Current order is conditional */ if (order->IsType(OT_CONDITIONAL) || order->IsType(OT_IMPLICIT)) return false; /* No travel time and we have not already finished travelling */ - if (travelling && order->travel_time == 0) return false; + if (travelling && order->GetTravelTime() == 0) return false; /* No wait time but we are loading at this timetabled station */ - if (!travelling && order->wait_time == 0 && order->IsType(OT_GOTO_STATION) && !(order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION)) return false; + if (!travelling && order->GetWaitTime() == 0 && order->IsType(OT_GOTO_STATION) && + !(order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION)) { + return false; + } return true; } @@ -118,12 +121,12 @@ static void FillTimetableArrivalDepartureTable(const Vehicle *v, VehicleOrderID if (!order->IsType(OT_IMPLICIT)) { if (travelling || i != start) { if (!CanDetermineTimeTaken(order, true)) return; - sum += order->travel_time; + sum += order->GetTravelTime(); table[i].arrival = sum; } if (!CanDetermineTimeTaken(order, false)) return; - sum += order->wait_time; + sum += order->GetWaitTime(); table[i].departure = sum; } @@ -140,7 +143,7 @@ static void FillTimetableArrivalDepartureTable(const Vehicle *v, VehicleOrderID * travelling part of the first order. */ if (!travelling) { if (!CanDetermineTimeTaken(order, true)) return; - sum += order->travel_time; + sum += order->GetTravelTime(); table[i].arrival = sum; } } @@ -398,13 +401,16 @@ struct TimetableWindow : Window { } else if (order->IsType(OT_IMPLICIT)) { string = STR_TIMETABLE_NOT_TIMETABLEABLE; colour = ((i == selected) ? TC_SILVER : TC_GREY) | TC_NO_SHADE; - } else if (order->travel_time == 0) { - string = order->max_speed != UINT16_MAX ? STR_TIMETABLE_TRAVEL_NOT_TIMETABLED_SPEED : STR_TIMETABLE_TRAVEL_NOT_TIMETABLED; + } else if (order->GetTravelTime() == 0) { + string = order->GetMaxSpeed() != UINT16_MAX ? + STR_TIMETABLE_TRAVEL_NOT_TIMETABLED_SPEED : + STR_TIMETABLE_TRAVEL_NOT_TIMETABLED; } else { - SetTimetableParams(0, 1, order->travel_time); - string = order->max_speed != UINT16_MAX ? STR_TIMETABLE_TRAVEL_FOR_SPEED : STR_TIMETABLE_TRAVEL_FOR; + SetTimetableParams(0, 1, order->GetTravelTime()); + string = order->GetMaxSpeed() != UINT16_MAX ? + STR_TIMETABLE_TRAVEL_FOR_SPEED : STR_TIMETABLE_TRAVEL_FOR; } - SetDParam(2, order->max_speed); + SetDParam(2, order->GetMaxSpeed()); DrawString(rtl ? r.left + WD_FRAMERECT_LEFT : middle, rtl ? middle : r.right - WD_FRAMERECT_LEFT, y, string, colour); @@ -540,7 +546,7 @@ struct TimetableWindow : Window { StringID current = STR_EMPTY; if (order != NULL) { - uint time = (selected % 2 == 1) ? order->travel_time : order->wait_time; + uint time = (selected % 2 == 1) ? order->GetTravelTime() : order->GetWaitTime(); if (!_settings_client.gui.timetable_in_ticks) time /= DAY_TICKS; if (time != 0) { @@ -563,8 +569,8 @@ struct TimetableWindow : Window { StringID current = STR_EMPTY; const Order *order = v->GetOrder(real); if (order != NULL) { - if (order->max_speed != UINT16_MAX) { - SetDParam(0, ConvertKmhishSpeedToDisplaySpeed(order->max_speed)); + if (order->GetMaxSpeed() != UINT16_MAX) { + SetDParam(0, ConvertKmhishSpeedToDisplaySpeed(order->GetMaxSpeed())); current = STR_JUST_INT; } } diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 57d6ab30b..30ec1143d 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -432,7 +432,7 @@ int Train::GetCurrentMaxSpeed() const } } - max_speed = min(max_speed, this->current_order.max_speed); + max_speed = min(max_speed, this->current_order.GetMaxSpeed()); return min(max_speed, this->gcache.cached_max_track_speed); } diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 415b8e56a..cc781b48d 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -2137,7 +2137,7 @@ void Vehicle::HandleLoading(bool mode) { switch (this->current_order.GetType()) { case OT_LOADING: { - uint wait_time = max(this->current_order.wait_time - this->lateness_counter, 0); + uint wait_time = max(this->current_order.GetWaitTime() - this->lateness_counter, 0); /* Not the first call for this tick, or still loading */ if (mode || !HasBit(this->vehicle_flags, VF_LOADING_FINISHED) || this->current_order_time < wait_time) return; @@ -2375,9 +2375,9 @@ void Vehicle::ShowVisualEffect() const } max_speed = min(max_speed, t->gcache.cached_max_track_speed); - max_speed = min(max_speed, this->current_order.max_speed); + max_speed = min(max_speed, this->current_order.GetMaxSpeed()); } - if (this->type == VEH_ROAD || this->type == VEH_SHIP) max_speed = min(max_speed, this->current_order.max_speed * 2); + if (this->type == VEH_ROAD || this->type == VEH_SHIP) max_speed = min(max_speed, this->current_order.GetMaxSpeed() * 2); const Vehicle *v = this; |