summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2013-02-14 17:04:01 +0000
committerrubidium <rubidium@openttd.org>2013-02-14 17:04:01 +0000
commitc77cd1f409698a5c3c0dc89f2cd1930b20b90554 (patch)
treed73eefa6aae84ccaec5d3657a03c692e4f5b2cac
parent328ed1cf94a5a18fad75ae7057202b5c05138765 (diff)
downloadopenttd-c77cd1f409698a5c3c0dc89f2cd1930b20b90554.tar.xz
(svn r24994) -Codechange: Replace access to service_interval with accessors (peter1138)
-rw-r--r--src/aircraft_cmd.cpp2
-rw-r--r--src/base_consist.h2
-rw-r--r--src/newgrf_engine.cpp4
-rw-r--r--src/roadveh_cmd.cpp2
-rw-r--r--src/saveload/order_sl.cpp2
-rw-r--r--src/saveload/vehicle_sl.cpp4
-rw-r--r--src/ship_cmd.cpp2
-rw-r--r--src/train_cmd.cpp2
-rw-r--r--src/vehicle.cpp4
-rw-r--r--src/vehicle_base.h3
-rw-r--r--src/vehicle_cmd.cpp2
-rw-r--r--src/vehicle_gui.cpp6
12 files changed, 19 insertions, 16 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index 7d55f59b7..af388c0ed 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -302,7 +302,7 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, const Engine *
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;
diff --git a/src/base_consist.h b/src/base_consist.h
index 5e45d354d..0ea13b3f2 100644
--- a/src/base_consist.h
+++ b/src/base_consist.h
@@ -24,7 +24,7 @@ struct BaseConsist {
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
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp
index fbc69013f..556958ef3 100644
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -733,8 +733,8 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
}
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:
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index bc3da850f..e58acee5a 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -289,7 +289,7 @@ CommandCost CmdBuildRoadVehicle(TileIndex tile, DoCommandFlag flags, const Engin
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;
diff --git a/src/saveload/order_sl.cpp b/src/saveload/order_sl.cpp
index c72d982ad..5b7fa535e 100644
--- a/src/saveload/order_sl.cpp
+++ b/src/saveload/order_sl.cpp
@@ -247,7 +247,7 @@ const SaveLoad *GetOrderBackupDescription()
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),
diff --git a/src/saveload/vehicle_sl.cpp b/src/saveload/vehicle_sl.cpp
index 416b0f0e9..c1e07bf3c 100644
--- a/src/saveload/vehicle_sl.cpp
+++ b/src/saveload/vehicle_sl.cpp
@@ -640,8 +640,8 @@ const SaveLoad *GetVehicleDescription(VehicleType vt)
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),
diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp
index 58a069fdc..1bc0dc999 100644
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -692,7 +692,7 @@ CommandCost CmdBuildShip(TileIndex tile, DoCommandFlag flags, const Engine *e, u
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;
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index c28bc13ac..a6fe72048 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -736,7 +736,7 @@ CommandCost CmdBuildRailVehicle(TileIndex tile, DoCommandFlag flags, const Engin
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;
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index c09650410..6c542b91e 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -112,8 +112,8 @@ bool Vehicle::NeedsServicing() const
/* 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;
}
diff --git a/src/vehicle_base.h b/src/vehicle_base.h
index ab06695e2..6dfea26b7 100644
--- a/src/vehicle_base.h
+++ b/src/vehicle_base.h
@@ -645,6 +645,9 @@ public:
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.
diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp
index f0a0428dd..be17c575e 100644
--- a/src/vehicle_cmd.cpp
+++ b/src/vehicle_cmd.cpp
@@ -1046,7 +1046,7 @@ CommandCost CmdChangeServiceInt(TileIndex tile, DoCommandFlag flags, uint32 p1,
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);
}
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index ec523e134..ecb31d2e0 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -1981,7 +1981,7 @@ struct VehicleDetailsWindow : Window {
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 @@ struct VehicleDetailsWindow : Window {
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;