Changeset - r7803:21a2033d0bf7
[Not reviewed]
master
0 6 0
glx - 17 years ago 2007-10-28 16:00:51
glx@openttd.org
(svn r11353) -Codechange: add support for newgrf callback 32
6 files changed with 22 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/date.cpp
Show inline comments
 
@@ -220,7 +220,11 @@ static void RunVehicleDayProc(uint dayti
 
	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);
 
		}
 
	}
 
}
 

	
src/newgrf_callbacks.h
Show inline comments
 
@@ -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,
src/newgrf_engine.cpp
Show inline comments
 
@@ -1050,6 +1050,10 @@ static void DoTriggerVehicle(Vehicle *v,
 
			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;
 
	}
 
}
 

	
src/newgrf_engine.h
Show inline comments
 
@@ -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);
 

	
src/vehicle.cpp
Show inline comments
 
@@ -1398,6 +1398,15 @@ Vehicle *CheckClickOnVehicle(const ViewP
 
	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)
 
{
src/vehicle.h
Show inline comments
 
@@ -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);
0 comments (0 inline, 0 general)