summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2009-08-06 17:02:49 +0000
committersmatz <smatz@openttd.org>2009-08-06 17:02:49 +0000
commit88a2d688da29b6beb822c5671927d0543104755f (patch)
tree881761645cdedc2003f05cac8a3897d1f40fe744 /src
parent0ab39b52d088d7290b051777c4e808897dc02523 (diff)
downloadopenttd-88a2d688da29b6beb822c5671927d0543104755f.tar.xz
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
Diffstat (limited to 'src')
-rw-r--r--src/date.cpp25
-rw-r--r--src/vehicle.cpp39
-rw-r--r--src/vehicle_base.h2
3 files changed, 31 insertions, 35 deletions
diff --git a/src/date.cpp b/src/date.cpp
index b9c47bfa2..287cddb7f 100644
--- a/src/date.cpp
+++ b/src/date.cpp
@@ -262,37 +262,16 @@ static void OnNewDay()
}
/**
- * Runs the day_proc for every DAY_TICKS vehicle starting at daytick.
- */
-static void RunVehicleDayProc(uint daytick)
-{
- for (size_t i = daytick; i < Vehicle::GetPoolSize(); i += DAY_TICKS) {
- Vehicle *v = Vehicle::Get(i);
-
- if (v != NULL) {
- /* Call the 32-day callback if needed */
- CheckVehicle32Day(v);
- v->OnNewDay();
- }
- }
-}
-
-/**
* Increases the tick counter, increases date and possibly calls
* procedures that have to be called daily, monthly or yearly.
*/
void IncreaseDate()
{
- if (_game_mode == GM_MENU) {
- _tick_counter++;
- return;
- }
-
- RunVehicleDayProc(_date_fract);
-
/* increase day, and check if a new day is there? */
_tick_counter++;
+ if (_game_mode == GM_MENU) return;
+
_date_fract++;
if (_date_fract < DAY_TICKS) return;
_date_fract = 0;
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 11f75d17e..b00e4bb88 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -559,12 +559,41 @@ void VehicleEnteredDepotThisTick(Vehicle *v)
v->vehstatus |= VS_STOPPED;
}
+/**
+ * Increases the day counter for all vehicles and calls 1-day and 32-day handlers.
+ * Each tick, it processes vehicles with "index % DAY_TICKS == _date_fract",
+ * so each day, all vehicles are processes in DAY_TICKS steps.
+ */
+static void RunVehicleDayProc()
+{
+ if (_game_mode != GM_NORMAL) return;
+
+ /* Run the day_proc for every DAY_TICKS vehicle starting at _date_fract. */
+ for (size_t i = _date_fract; i < Vehicle::GetPoolSize(); i += DAY_TICKS) {
+ Vehicle *v = Vehicle::Get(i);
+ if (v == NULL) continue;
+
+ /* Call the 32-day callback if needed */
+ if ((v->day_counter & 0x1F) == 0) {
+ uint16 callback = GetVehicleCallback(CBID_VEHICLE_32DAY_CALLBACK, 0, 0, v->engine_type, v);
+ if (callback == CALLBACK_FAILED) return;
+ if (HasBit(callback, 0)) TriggerVehicle(v, VEHICLE_TRIGGER_CALLBACK_32); // Trigger vehicle trigger 10
+ if (HasBit(callback, 1)) v->colourmap = PAL_NONE;
+ }
+
+ /* This is called once per day for each vehicle, but not in the first tick of the day */
+ v->OnNewDay();
+ }
+}
+
void CallVehicleTicks()
{
_vehicles_to_autoreplace.Clear();
_age_cargo_skip_counter = (_age_cargo_skip_counter == 0) ? 184 : (_age_cargo_skip_counter - 1);
+ RunVehicleDayProc();
+
Station *st;
FOR_ALL_STATIONS(st) LoadUnloadStation(st);
@@ -801,16 +830,6 @@ Vehicle *CheckClickOnVehicle(const ViewPort *vp, int x, int y)
return found;
}
-void CheckVehicle32Day(Vehicle *v)
-{
- if ((v->day_counter & 0x1F) != 0) return;
-
- uint16 callback = GetVehicleCallback(CBID_VEHICLE_32DAY_CALLBACK, 0, 0, v->engine_type, v);
- if (callback == CALLBACK_FAILED) return;
- if (HasBit(callback, 0)) TriggerVehicle(v, VEHICLE_TRIGGER_CALLBACK_32); // Trigger vehicle trigger 10
- if (HasBit(callback, 1)) v->colourmap = PAL_NONE; // Update colourmap via callback 2D
-}
-
void DecreaseVehicleValue(Vehicle *v)
{
v->value -= v->value >> 8;
diff --git a/src/vehicle_base.h b/src/vehicle_base.h
index 80f7c0581..751137889 100644
--- a/src/vehicle_base.h
+++ b/src/vehicle_base.h
@@ -676,8 +676,6 @@ struct FreeUnitIDGenerator {
~FreeUnitIDGenerator() { free(this->cache); }
};
-void CheckVehicle32Day(Vehicle *v);
-
static const int32 INVALID_COORD = 0x7fffffff;
#endif /* VEHICLE_BASE_H */