summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorglx <glx@openttd.org>2007-10-28 16:00:51 +0000
committerglx <glx@openttd.org>2007-10-28 16:00:51 +0000
commit1256cbade375d9e9cb2168a6fd9b613d269e7371 (patch)
treeb7c461ee18715f538ddea7d5fc8c94cbe68d95f5 /src
parent4041d8108a4f5994c52af436b393faebdad3ae01 (diff)
downloadopenttd-1256cbade375d9e9cb2168a6fd9b613d269e7371.tar.xz
(svn r11353) -Codechange: add support for newgrf callback 32
Diffstat (limited to 'src')
-rw-r--r--src/date.cpp6
-rw-r--r--src/newgrf_callbacks.h2
-rw-r--r--src/newgrf_engine.cpp4
-rw-r--r--src/newgrf_engine.h2
-rw-r--r--src/vehicle.cpp9
-rw-r--r--src/vehicle.h1
6 files changed, 22 insertions, 2 deletions
diff --git a/src/date.cpp b/src/date.cpp
index 6080ab895..23354cde1 100644
--- a/src/date.cpp
+++ b/src/date.cpp
@@ -220,7 +220,11 @@ static void RunVehicleDayProc(uint daytick)
for (i = daytick; i < total; i += DAY_TICKS) {
Vehicle *v = GetVehicle(i);
- if (v->IsValid()) _on_new_vehicle_day_proc[v->type](v);
+ if (v->IsValid()) {
+ /* Call the 32-day callback if needed */
+ CheckVehicle32Day(v);
+ _on_new_vehicle_day_proc[v->type](v);
+ }
}
}
diff --git a/src/newgrf_callbacks.h b/src/newgrf_callbacks.h
index 417cfb02e..3dffdcf03 100644
--- a/src/newgrf_callbacks.h
+++ b/src/newgrf_callbacks.h
@@ -134,7 +134,7 @@ enum CallbackID {
CBID_VEHICLE_START_STOP_CHECK = 0x31,
/** Called for every vehicle every 32 days (not all on same date though). */
- CBID_VEHICLE_32DAY_CALLBACK = 0x32, // not implemented
+ CBID_VEHICLE_32DAY_CALLBACK = 0x32,
/** Called to play a special sound effect */
CBID_VEHICLE_SOUND_EFFECT = 0x33,
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp
index 76075f5cb..9a8c804b3 100644
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -1050,6 +1050,10 @@ static void DoTriggerVehicle(Vehicle *v, VehicleTrigger trigger, byte base_rando
assert(!first);
if (v->Next() != NULL) DoTriggerVehicle(v->Next(), VEHICLE_TRIGGER_ANY_NEW_CARGO, base_random_bits, false);
break;
+
+ case VEHICLE_TRIGGER_CALLBACK_32:
+ /* Do not do any recursion */
+ break;
}
}
diff --git a/src/newgrf_engine.h b/src/newgrf_engine.h
index 222f229ad..2ddeaa17c 100644
--- a/src/newgrf_engine.h
+++ b/src/newgrf_engine.h
@@ -49,6 +49,8 @@ enum VehicleTrigger {
VEHICLE_TRIGGER_EMPTY = 4,
/* Not triggered externally (called for the whole chain if we got NEW_CARGO) */
VEHICLE_TRIGGER_ANY_NEW_CARGO = 8,
+ /* Externally triggered for each vehicle in chain */
+ VEHICLE_TRIGGER_CALLBACK_32 = 10,
};
void TriggerVehicle(Vehicle *veh, VehicleTrigger trigger);
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 86151e48a..48f16b582 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -1398,6 +1398,15 @@ 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->colormap = PAL_NONE; // Update colormap via callback 2D
+}
void DecreaseVehicleValue(Vehicle *v)
{
diff --git a/src/vehicle.h b/src/vehicle.h
index dd946900c..00a457bb1 100644
--- a/src/vehicle.h
+++ b/src/vehicle.h
@@ -591,6 +591,7 @@ void InitializeTrains();
byte VehicleRandomBits();
void ResetVehiclePosHash();
void ResetVehicleColorMap();
+void CheckVehicle32Day(Vehicle *v);
bool CanRefitTo(EngineID engine_type, CargoID cid_to);
CargoID FindFirstRefittableCargo(EngineID engine_type);