summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/aircraft_cmd.cpp8
-rw-r--r--src/economy.cpp10
-rw-r--r--src/newgrf_engine.cpp4
-rw-r--r--src/roadveh_cmd.cpp2
-rw-r--r--src/saveload/oldloader_sl.cpp2
-rw-r--r--src/saveload/vehicle_sl.cpp2
-rw-r--r--src/train_cmd.cpp34
-rw-r--r--src/vehicle.cpp2
-rw-r--r--src/vehicle_base.h9
9 files changed, 40 insertions, 33 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index 99faffa8e..df8b91b25 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -325,7 +325,7 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
v->name = NULL;
// v->next_order_param = v->next_order = 0;
-// v->load_unload_time_rem = 0;
+// v->time_counter = 0;
// v->progress = 0;
v->last_station_visited = INVALID_STATION;
// v->destination_coords = 0;
@@ -1048,7 +1048,7 @@ static bool AircraftController(Aircraft *v)
count = UpdateAircraftSpeed(v, speed_limit, hard_limit);
if (count == 0) return false;
- if (v->load_unload_time_rem != 0) v->load_unload_time_rem--;
+ if (v->time_counter != 0) v->time_counter--;
do {
@@ -1072,13 +1072,13 @@ static bool AircraftController(Aircraft *v)
Direction newdir = GetDirectionTowards(v, x + amd->x, y + amd->y);
if (newdir != v->direction) {
if (amd->flag & AMED_SLOWTURN && v->number_consecutive_turns < 8) {
- if (v->load_unload_time_rem == 0 || newdir == v->last_direction) {
+ if (v->time_counter == 0 || newdir == v->last_direction) {
if (newdir == v->last_direction) {
v->number_consecutive_turns = 0;
} else {
v->number_consecutive_turns++;
}
- v->load_unload_time_rem = 2 * _settings_game.vehicle.plane_speed;
+ v->time_counter = 2 * _settings_game.vehicle.plane_speed;
v->last_direction = v->direction;
v->direction = newdir;
}
diff --git a/src/economy.cpp b/src/economy.cpp
index 77dd93109..c5b3666f5 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -1069,7 +1069,7 @@ void PrepareUnload(Vehicle *front_v)
ClrBit(front_v->vehicle_flags, VF_LOADING_FINISHED);
/* Start unloading in at the first possible moment */
- front_v->load_unload_time_rem = 1;
+ front_v->time_counter = 1;
if ((front_v->current_order.GetUnloadType() & OUFB_NO_UNLOAD) == 0) {
for (Vehicle *v = front_v; v != NULL; v = v->Next()) {
@@ -1095,10 +1095,10 @@ static void LoadUnloadVehicle(Vehicle *v, int *cargo_left)
{
assert(v->current_order.IsType(OT_LOADING));
- assert(v->load_unload_time_rem != 0);
+ assert(v->time_counter != 0);
/* We have not waited enough time till the next round of loading/unloading */
- if (--v->load_unload_time_rem != 0) {
+ if (--v->time_counter != 0) {
if (_settings_game.order.improved_load && (v->current_order.GetLoadType() & OLFB_FULL_LOAD)) {
/* 'Reserve' this cargo for this vehicle, because we were first. */
for (; v != NULL; v = v->Next()) {
@@ -1116,7 +1116,7 @@ static void LoadUnloadVehicle(Vehicle *v, int *cargo_left)
/* The train reversed in the station. Take the "easy" way
* out and let the train just leave as it always did. */
SetBit(v->vehicle_flags, VF_LOADING_FINISHED);
- v->load_unload_time_rem = 1;
+ v->time_counter = 1;
return;
}
@@ -1347,7 +1347,7 @@ static void LoadUnloadVehicle(Vehicle *v, int *cargo_left)
}
/* Always wait at least 1, otherwise we'll wait 'infinitively' long. */
- v->load_unload_time_rem = max(1, unloading_time);
+ v->time_counter = max(1, unloading_time);
if (completely_emptied) {
TriggerVehicle(v, VEHICLE_TRIGGER_EMPTY);
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp
index a59cccddf..e85449548 100644
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -709,8 +709,8 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
case 0x0B: return v->current_order.GetDestination();
case 0x0C: return v->GetNumOrders();
case 0x0D: return v->cur_order_index;
- case 0x10: return v->load_unload_time_rem;
- case 0x11: return GB(v->load_unload_time_rem, 8, 8);
+ case 0x10: return v->time_counter;
+ case 0x11: return GB(v->time_counter, 8, 8);
case 0x12: return max(v->date_of_last_service - DAYS_TILL_ORIGINAL_BASE_YEAR, 0);
case 0x13: return GB(max(v->date_of_last_service - DAYS_TILL_ORIGINAL_BASE_YEAR, 0), 8, 8);
case 0x14: return v->service_interval;
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index 14a968558..f48a09b38 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -245,7 +245,7 @@ CommandCost CmdBuildRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
v->value = cost.GetCost();
// v->day_counter = 0;
// v->next_order_param = v->next_order = 0;
-// v->load_unload_time_rem = 0;
+// v->time_counter = 0;
// v->progress = 0;
// v->overtaking = 0;
diff --git a/src/saveload/oldloader_sl.cpp b/src/saveload/oldloader_sl.cpp
index 5a50ac79a..ee9216cdc 100644
--- a/src/saveload/oldloader_sl.cpp
+++ b/src/saveload/oldloader_sl.cpp
@@ -1134,7 +1134,7 @@ static const OldChunks vehicle_chunk[] = {
OCL_NULL ( 1 ), ///< num_orders, now calculated
OCL_SVAR( OC_UINT8, Vehicle, cur_order_index ),
OCL_SVAR( OC_TILE, Vehicle, dest_tile ),
- OCL_SVAR( OC_UINT16, Vehicle, load_unload_time_rem ),
+ OCL_SVAR( OC_UINT16, Vehicle, time_counter ),
OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Vehicle, date_of_last_service ),
OCL_SVAR( OC_UINT16, Vehicle, service_interval ),
OCL_SVAR( OC_FILE_U8 | OC_VAR_U16, Vehicle, last_station_visited ),
diff --git a/src/saveload/vehicle_sl.cpp b/src/saveload/vehicle_sl.cpp
index f50266d25..b71d7058b 100644
--- a/src/saveload/vehicle_sl.cpp
+++ b/src/saveload/vehicle_sl.cpp
@@ -496,7 +496,7 @@ const SaveLoad *GetVehicleDescription(VehicleType vt)
SLE_CONDVAR(Vehicle, build_year, SLE_FILE_U8 | SLE_VAR_I32, 0, 30),
SLE_CONDVAR(Vehicle, build_year, SLE_INT32, 31, SL_MAX_VERSION),
- SLE_VAR(Vehicle, load_unload_time_rem, SLE_UINT16),
+ SLE_VAR(Vehicle, time_counter, SLE_UINT16),
SLEG_CONDVAR( _cargo_paid_for, SLE_UINT16, 45, SL_MAX_VERSION),
SLE_CONDVAR(Vehicle, vehicle_flags, SLE_UINT8, 40, SL_MAX_VERSION),
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 0c4a0805e..162f3ae12 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -1648,7 +1648,7 @@ static void MarkTrainAsStuck(Train *v)
/* When loading the vehicle is already stopped. No need to change that. */
if (v->current_order.IsType(OT_LOADING)) return;
- v->load_unload_time_rem = 0;
+ v->time_counter = 0;
/* Stop train */
v->cur_speed = 0;
@@ -1988,7 +1988,7 @@ static void ReverseTrainDirection(Train *v)
} else if (HasBit(v->flags, VRF_TRAIN_STUCK)) {
/* A train not inside a PBS block can't be stuck. */
ClrBit(v->flags, VRF_TRAIN_STUCK);
- v->load_unload_time_rem = 0;
+ v->time_counter = 0;
}
}
@@ -2445,12 +2445,12 @@ static bool CheckTrainStayInDepot(Train *v)
if (v->force_proceed == 0) {
/* force proceed was not pressed */
- if (++v->load_unload_time_rem < 37) {
+ if (++v->time_counter < 37) {
SetWindowClassesDirty(WC_TRAINS_LIST);
return true;
}
- v->load_unload_time_rem = 0;
+ v->time_counter = 0;
seg_state = _settings_game.pf.reserve_paths ? SIGSEG_PBS : UpdateSignalsOnSegment(v->tile, INVALID_DIAGDIR, v->owner);
if (seg_state == SIGSEG_FULL || HasDepotReservation(v->tile)) {
@@ -3196,7 +3196,7 @@ bool TryPathReserve(Train *v, bool mark_as_stuck, bool first_tile_okay)
}
if (HasBit(v->flags, VRF_TRAIN_STUCK)) {
- v->load_unload_time_rem = 0;
+ v->time_counter = 0;
SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
}
ClrBit(v->flags, VRF_TRAIN_STUCK);
@@ -3768,12 +3768,12 @@ static void TrainController(Train *v, Vehicle *nomove)
v->cur_speed = 0;
v->subspeed = 0;
v->progress = 255 - 100;
- if (_settings_game.pf.wait_oneway_signal == 255 || ++v->load_unload_time_rem < _settings_game.pf.wait_oneway_signal * 20) return;
+ if (_settings_game.pf.wait_oneway_signal == 255 || ++v->time_counter < _settings_game.pf.wait_oneway_signal * 20) return;
} else if (HasSignalOnTrackdir(gp.new_tile, i)) {
v->cur_speed = 0;
v->subspeed = 0;
v->progress = 255 - 10;
- if (_settings_game.pf.wait_twoway_signal == 255 || ++v->load_unload_time_rem < _settings_game.pf.wait_twoway_signal * 73) {
+ if (_settings_game.pf.wait_twoway_signal == 255 || ++v->time_counter < _settings_game.pf.wait_twoway_signal * 73) {
DiagDirection exitdir = TrackdirToExitdir(i);
TileIndex o_tile = TileAddByDiagDir(gp.new_tile, exitdir);
@@ -3787,7 +3787,7 @@ static void TrainController(Train *v, Vehicle *nomove)
/* If we would reverse but are currently in a PBS block and
* reversing of stuck trains is disabled, don't reverse. */
if (_settings_game.pf.wait_for_pbs_path == 255 && UpdateSignalsOnSegment(v->tile, enterdir, v->owner) == SIGSEG_PBS) {
- v->load_unload_time_rem = 0;
+ v->time_counter = 0;
return;
}
goto reverse_train_direction;
@@ -3881,7 +3881,7 @@ static void TrainController(Train *v, Vehicle *nomove)
}
if (v->IsFrontEngine()) {
- v->load_unload_time_rem = 0;
+ v->time_counter = 0;
/* If we are approching a crossing that is reserved, play the sound now. */
TileIndex crossing = TrainApproachingCrossingTile(v);
@@ -3973,7 +3973,7 @@ invalid_rail:
if (prev != NULL) error("Disconnecting train");
reverse_train_direction:
- v->load_unload_time_rem = 0;
+ v->time_counter = 0;
v->cur_speed = 0;
v->subspeed = 0;
ReverseTrainDirection(v);
@@ -4351,7 +4351,7 @@ static bool TrainLocoHandler(Train *v, bool mode)
bool valid_order = !v->current_order.IsType(OT_NOTHING) && v->current_order.GetType() != OT_CONDITIONAL;
if (ProcessOrders(v) && CheckReverseTrain(v)) {
- v->load_unload_time_rem = 0;
+ v->time_counter = 0;
v->cur_speed = 0;
v->subspeed = 0;
ReverseTrainDirection(v);
@@ -4373,17 +4373,17 @@ static bool TrainLocoHandler(Train *v, bool mode)
/* Handle stuck trains. */
if (!mode && HasBit(v->flags, VRF_TRAIN_STUCK)) {
- ++v->load_unload_time_rem;
+ ++v->time_counter;
/* Should we try reversing this tick if still stuck? */
- bool turn_around = v->load_unload_time_rem % (_settings_game.pf.wait_for_pbs_path * DAY_TICKS) == 0 && _settings_game.pf.wait_for_pbs_path < 255;
+ bool turn_around = v->time_counter % (_settings_game.pf.wait_for_pbs_path * DAY_TICKS) == 0 && _settings_game.pf.wait_for_pbs_path < 255;
- if (!turn_around && v->load_unload_time_rem % _settings_game.pf.path_backoff_interval != 0 && v->force_proceed == 0) return true;
+ if (!turn_around && v->time_counter % _settings_game.pf.path_backoff_interval != 0 && v->force_proceed == 0) return true;
if (!TryPathReserve(v)) {
/* Still stuck. */
if (turn_around) ReverseTrainDirection(v);
- if (HasBit(v->flags, VRF_TRAIN_STUCK) && v->load_unload_time_rem > 2 * _settings_game.pf.wait_for_pbs_path * DAY_TICKS) {
+ if (HasBit(v->flags, VRF_TRAIN_STUCK) && v->time_counter > 2 * _settings_game.pf.wait_for_pbs_path * DAY_TICKS) {
/* Show message to player. */
if (_settings_client.gui.lost_train_warn && v->owner == _local_company) {
SetDParam(0, v->index);
@@ -4393,12 +4393,12 @@ static bool TrainLocoHandler(Train *v, bool mode)
v->index
);
}
- v->load_unload_time_rem = 0;
+ v->time_counter = 0;
}
/* Exit if force proceed not pressed, else reset stuck flag anyway. */
if (v->force_proceed == 0) return true;
ClrBit(v->flags, VRF_TRAIN_STUCK);
- v->load_unload_time_rem = 0;
+ v->time_counter = 0;
SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
}
}
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index b0a92fad7..7596d4d7b 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -966,7 +966,7 @@ void VehicleEnterDepot(Vehicle *v)
if (_settings_client.gui.show_track_reservation) MarkTileDirtyByTile(t->tile);
UpdateSignalsOnSegment(t->tile, INVALID_DIAGDIR, t->owner);
- t->load_unload_time_rem = 0;
+ t->time_counter = 0;
ClrBit(t->flags, VRF_TOGGLE_REVERSE);
TrainConsistChanged(t, true);
break;
diff --git a/src/vehicle_base.h b/src/vehicle_base.h
index bf2629765..f733297eb 100644
--- a/src/vehicle_base.h
+++ b/src/vehicle_base.h
@@ -182,7 +182,14 @@ public:
} orders;
byte vehicle_flags; ///< Used for gradual loading and other miscellaneous things (@see VehicleFlags enum)
- uint16 load_unload_time_rem;
+
+ /**
+ * Multi purpose variable used as counter for:
+ * - loading/unloading: ticks to wait before starting next cycle.
+ * - aircraft: ticks between each turn to prevent > 45 degree turns.
+ * - trains: ticks waiting in front of a signal, ticks being stuck or a counter for forced proceeding through signals.
+ */
+ uint16 time_counter;
GroupID group_id; ///< Index of group Pool array