Mercurial > hg > openttd
changeset 20061:aad15ac081e0 draft
(svn r24994) -Codechange: Replace access to service_interval with accessors (peter1138)
author | rubidium <rubidium@openttd.org> |
---|---|
date | Thu, 14 Feb 2013 17:04:01 +0000 |
parents | 33e0e21382ef |
children | 7456d9748fcb |
files | src/aircraft_cmd.cpp src/base_consist.h src/newgrf_engine.cpp src/roadveh_cmd.cpp src/saveload/order_sl.cpp src/saveload/vehicle_sl.cpp src/ship_cmd.cpp src/train_cmd.cpp src/vehicle.cpp src/vehicle_base.h src/vehicle_cmd.cpp src/vehicle_gui.cpp |
diffstat | 12 files changed, 19 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -302,7 +302,7 @@ v->targetairport = GetStationIndex(tile); v->SetNext(u); - v->service_interval = Company::Get(_current_company)->settings.vehicle.servint_aircraft; + v->SetServiceInterval(Company::Get(_current_company)->settings.vehicle.servint_aircraft); v->date_of_last_service = _date; v->build_year = u->build_year = _cur_year;
--- a/src/base_consist.h +++ b/src/base_consist.h @@ -24,7 +24,7 @@ int32 lateness_counter; ///< How many ticks late (or early if negative) this vehicle is. Date timetable_start; ///< When the vehicle is supposed to start the timetable. - Date service_interval; ///< The interval for (automatic) servicing; either in days or %. + uint32 service_interval; ///< The interval for (automatic) servicing; either in days or %. VehicleOrderID cur_real_order_index;///< The index to the current real (non-implicit) order VehicleOrderID cur_implicit_order_index;///< The index to the current implicit order
--- a/src/newgrf_engine.cpp +++ b/src/newgrf_engine.cpp @@ -733,8 +733,8 @@ } case 0x12: return Clamp(v->date_of_last_service - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 0xFFFF); case 0x13: return GB(Clamp(v->date_of_last_service - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 0xFFFF), 8, 8); - case 0x14: return v->service_interval; - case 0x15: return GB(v->service_interval, 8, 8); + case 0x14: return v->GetServiceInterval(); + case 0x15: return GB(v->GetServiceInterval(), 8, 8); case 0x16: return v->last_station_visited; case 0x17: return v->tick_counter; case 0x18:
--- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -289,7 +289,7 @@ v->max_age = e->GetLifeLengthInDays(); _new_vehicle_id = v->index; - v->service_interval = Company::Get(v->owner)->settings.vehicle.servint_roadveh; + v->SetServiceInterval(Company::Get(v->owner)->settings.vehicle.servint_roadveh); v->date_of_last_service = _date; v->build_year = _cur_year;
--- a/src/saveload/order_sl.cpp +++ b/src/saveload/order_sl.cpp @@ -247,7 +247,7 @@ SLE_VAR(OrderBackup, user, SLE_UINT32), SLE_VAR(OrderBackup, tile, SLE_UINT32), SLE_VAR(OrderBackup, group, SLE_UINT16), - SLE_VAR(OrderBackup, service_interval, SLE_INT32), + SLE_VAR(OrderBackup, service_interval, SLE_UINT32), SLE_STR(OrderBackup, name, SLE_STR, 0), SLE_VAR(OrderBackup, clone, SLE_UINT16), SLE_VAR(OrderBackup, cur_real_order_index, SLE_UINT8),
--- a/src/saveload/vehicle_sl.cpp +++ b/src/saveload/vehicle_sl.cpp @@ -640,8 +640,8 @@ SLE_CONDVAR(Vehicle, max_age, SLE_INT32, 31, SL_MAX_VERSION), SLE_CONDVAR(Vehicle, date_of_last_service, SLE_FILE_U16 | SLE_VAR_I32, 0, 30), SLE_CONDVAR(Vehicle, date_of_last_service, SLE_INT32, 31, SL_MAX_VERSION), - SLE_CONDVAR(Vehicle, service_interval, SLE_FILE_U16 | SLE_VAR_I32, 0, 30), - SLE_CONDVAR(Vehicle, service_interval, SLE_INT32, 31, SL_MAX_VERSION), + SLE_CONDVAR(Vehicle, service_interval, SLE_FILE_U16 | SLE_VAR_U32, 0, 30), + SLE_CONDVAR(Vehicle, service_interval, SLE_UINT32, 31, SL_MAX_VERSION), SLE_VAR(Vehicle, reliability, SLE_UINT16), SLE_VAR(Vehicle, reliability_spd_dec, SLE_UINT16), SLE_VAR(Vehicle, breakdown_ctr, SLE_UINT8),
--- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -692,7 +692,7 @@ v->state = TRACK_BIT_DEPOT; - v->service_interval = Company::Get(_current_company)->settings.vehicle.servint_ships; + v->SetServiceInterval(Company::Get(_current_company)->settings.vehicle.servint_ships); v->date_of_last_service = _date; v->build_year = _cur_year; v->cur_image = SPR_IMG_QUERY;
--- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -736,7 +736,7 @@ v->railtype = rvi->railtype; _new_vehicle_id = v->index; - v->service_interval = Company::Get(_current_company)->settings.vehicle.servint_trains; + v->SetServiceInterval(Company::Get(_current_company)->settings.vehicle.servint_trains); v->date_of_last_service = _date; v->build_year = _cur_year; v->cur_image = SPR_IMG_QUERY;
--- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -112,8 +112,8 @@ /* Are we ready for the next service cycle? */ const Company *c = Company::Get(this->owner); if (c->settings.vehicle.servint_ispercent ? - (this->reliability >= this->GetEngine()->reliability * (100 - this->service_interval) / 100) : - (this->date_of_last_service + this->service_interval >= _date)) { + (this->reliability >= this->GetEngine()->reliability * (100 - this->GetServiceInterval()) / 100) : + (this->date_of_last_service + this->GetServiceInterval() >= _date)) { return false; }
--- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -645,6 +645,9 @@ void UpdateVisualEffect(bool allow_power_change = true); void ShowVisualEffect() const; + inline uint16 GetServiceInterval() const { return GB(this->service_interval, 0, 16); } + inline void SetServiceInterval(uint16 interval) { SB(this->service_interval, 0, 16, interval); } + private: /** * Advance cur_real_order_index to the next real order.
--- a/src/vehicle_cmd.cpp +++ b/src/vehicle_cmd.cpp @@ -1046,7 +1046,7 @@ if (serv_int != p2) return CMD_ERROR; if (flags & DC_EXEC) { - v->service_interval = serv_int; + v->SetServiceInterval(serv_int); SetWindowDirty(WC_VEHICLE_DETAILS, v->index); }
--- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -1981,7 +1981,7 @@ case WID_VD_SERVICING_INTERVAL: /* Draw service interval text */ - SetDParam(0, v->service_interval); + SetDParam(0, v->GetServiceInterval()); SetDParam(1, v->date_of_last_service); DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + (r.bottom - r.top + 1 - FONT_HEIGHT_NORMAL) / 2, Company::Get(v->owner)->settings.vehicle.servint_ispercent ? STR_VEHICLE_DETAILS_SERVICING_INTERVAL_PERCENT : STR_VEHICLE_DETAILS_SERVICING_INTERVAL_DAYS); @@ -2027,8 +2027,8 @@ const Vehicle *v = Vehicle::Get(this->window_number); mod = (widget == WID_VD_DECREASE_SERVICING_INTERVAL) ? -mod : mod; - mod = GetServiceIntervalClamped(mod + v->service_interval, v->owner); - if (mod == v->service_interval) return; + mod = GetServiceIntervalClamped(mod + v->GetServiceInterval(), v->owner); + if (mod == v->GetServiceInterval()) return; DoCommandP(v->tile, v->index, mod, CMD_CHANGE_SERVICE_INT | CMD_MSG(STR_ERROR_CAN_T_CHANGE_SERVICING)); break;