Changeset - r3390:04cda83c4278
[Not reviewed]
master
0 3 0
peter1138 - 19 years ago 2006-03-31 10:14:25
peter1138@openttd.org
(svn r4198) - NewGRF: Rename GetCallBackResult() to GetVehicleCallback(), as other types will exist later, and use separate parameters instead of bitshifting.
3 files changed with 14 insertions and 13 deletions:
0 comments (0 inline, 0 general)
newgrf_engine.c
Show inline comments
 
@@ -473,24 +473,25 @@ bool UsesWagonOverride(const Vehicle* v)
 
{
 
	assert(v->type == VEH_Train);
 
	return GetWagonOverrideSpriteSet(v->engine_type, v->u.rail.first_engine) != NULL;
 
}
 

	
 
/**
 
 * Evaluates a newgrf callback
 
 * @param callback_info info about which callback to evaluate
 
 *  (bit 0-7)  = CallBack id of the callback to use, see CallBackId enum
 
 *  (bit 8-15) = Other info some callbacks need to have, callback specific, see CallBackId enum, not used yet
 
 * @param engine Engine type of the vehicle to evaluate the callback for
 
 * @param vehicle The vehicle to evaluate the callback for, NULL if it doesnt exist (yet)
 
 * Evaluate a newgrf callback for vehicles
 
 * @param callback The callback to evalute
 
 * @param param1   First parameter of the callback
 
 * @param param2   Second parameter of the callback
 
 * @param engine   Engine type of the vehicle to evaluate the callback for
 
 * @param vehicle  The vehicle to evaluate the callback for, or NULL if it doesnt exist yet
 
 * @return The value the callback returned, or CALLBACK_FAILED if it failed
 
 */
 
uint16 GetCallBackResult(uint16 callback_info, EngineID engine, const Vehicle *v)
 
uint16 GetVehicleCallback(byte callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v)
 
{
 
	const SpriteGroup *group;
 
	CargoID cargo = GC_DEFAULT;
 
	uint16 callback_info = callback | (param1 << 8); // XXX Temporary conversion between new and old format.
 

	
 
	if (v != NULL)
 
		cargo = _global_cargo_id[_opt.landscape][v->cargo_type];
 

	
 
	group = engine_custom_sprites[engine][cargo];
 

	
newgrf_engine.h
Show inline comments
 
@@ -15,13 +15,13 @@ VARDEF const CargoID _local_cargo_id_cty
 
VARDEF const uint32 cargo_classes[16];
 

	
 
void SetWagonOverrideSprites(EngineID engine, struct SpriteGroup *group, byte *train_id, int trains);
 
void SetCustomEngineSprites(EngineID engine, byte cargo, struct SpriteGroup *group);
 
// loaded is in percents, overriding_engine 0xffff is none
 
int GetCustomEngineSprite(EngineID engine, const Vehicle* v, Direction direction);
 
uint16 GetCallBackResult(uint16 callback_info, EngineID engine, const Vehicle *v);
 
uint16 GetVehicleCallback(byte callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v);
 
bool UsesWagonOverride(const Vehicle *v);
 
#define GetCustomVehicleSprite(v, direction) GetCustomEngineSprite(v->engine_type, v, direction)
 
#define GetCustomVehicleIcon(et, direction) GetCustomEngineSprite(et, NULL, direction)
 

	
 
typedef enum VehicleTrigger {
 
	VEHICLE_TRIGGER_NEW_CARGO = 1,
train_cmd.c
Show inline comments
 
@@ -161,13 +161,13 @@ void TrainConsistChanged(Vehicle* v)
 

	
 
		if (!IsArticulatedPart(u)) {
 
			// check if its a powered wagon
 
			CLRBIT(u->u.rail.flags, VRF_POWEREDWAGON);
 
			if ((rvi_v->pow_wag_power != 0) && (rvi_u->flags & RVI_WAGON) && UsesWagonOverride(u)) {
 
				if (HASBIT(rvi_u->callbackmask, CBM_WAGON_POWER)) {
 
					uint16 callback = GetCallBackResult(CBID_TRAIN_WAGON_POWER,  u->engine_type, u);
 
					uint16 callback = GetVehicleCallback(CBID_TRAIN_WAGON_POWER, 0, 0, u->engine_type, u);
 

	
 
					if (callback != CALLBACK_FAILED)
 
						u->u.rail.cached_vis_effect = callback;
 
				}
 

	
 
				if (u->u.rail.cached_vis_effect < 0x40) {
 
@@ -188,13 +188,13 @@ void TrainConsistChanged(Vehicle* v)
 
					max_speed = min(rvi_u->max_speed, max_speed);
 
		}
 

	
 
		// check the vehicle length (callback)
 
		veh_len = CALLBACK_FAILED;
 
		if (HASBIT(rvi_u->callbackmask, CBM_VEHICLE_LENGTH))
 
			veh_len = GetCallBackResult(CBID_TRAIN_VEHICLE_LENGTH,  u->engine_type, u);
 
			veh_len = GetVehicleCallback(CBID_TRAIN_VEHICLE_LENGTH, 0, 0, u->engine_type, u);
 
		if (veh_len == CALLBACK_FAILED)
 
			veh_len = rvi_u->shorten_factor;
 
		veh_len = clamp(veh_len, 0, u->next == NULL ? 7 : 5); // the clamp on vehicles not the last in chain is stricter, as too short wagons can break the 'follow next vehicle' code
 
		u->u.rail.cached_veh_length = 8 - veh_len;
 
		v->u.rail.cached_total_length += u->u.rail.cached_veh_length;
 

	
 
@@ -482,13 +482,13 @@ static uint CountArticulatedParts(const 
 
	uint16 callback;
 
	uint i;
 

	
 
	if (!HASBIT(rvi->callbackmask, CBM_ARTIC_ENGINE)) return 0;
 

	
 
	for (i = 1; i < 10; i++) {
 
		callback = GetCallBackResult(CBID_TRAIN_ARTIC_ENGINE + (i << 8), engine_type, NULL);
 
		callback = GetVehicleCallback(CBID_TRAIN_ARTIC_ENGINE, i, 0, engine_type, NULL);
 
		if (callback == CALLBACK_FAILED || callback == 0xFF) break;
 
	}
 

	
 
	return i - 1;
 
}
 

	
 
@@ -502,13 +502,13 @@ static void AddArticulatedParts(const Ra
 
	bool flip_image;
 
	uint i;
 

	
 
	if (!HASBIT(rvi->callbackmask, CBM_ARTIC_ENGINE)) return;
 

	
 
	for (i = 1; i < 10; i++) {
 
		callback = GetCallBackResult(CBID_TRAIN_ARTIC_ENGINE + (i << 8), v->engine_type, NULL);
 
		callback = GetVehicleCallback(CBID_TRAIN_ARTIC_ENGINE, i, 0, v->engine_type, NULL);
 
		if (callback == CALLBACK_FAILED || callback == 0xFF) return;
 

	
 
		u->next = vl[i];
 
		u = u->next;
 

	
 
		engine_type = GB(callback, 0, 7);
 
@@ -1734,13 +1734,13 @@ int32 CmdRefitRailVehicle(int x, int y, 
 
			uint16 amount = CALLBACK_FAILED;
 

	
 
			if (HASBIT(rvi->callbackmask, CBM_REFIT_CAPACITY)) {
 
				/* Check the 'refit capacity' callback */
 
				CargoID temp_cid = v->cargo_type;
 
				v->cargo_type = new_cid;
 
				amount = GetCallBackResult(CBID_VEHICLE_REFIT_CAPACITY, v->engine_type, v);
 
				amount = GetVehicleCallback(CBID_VEHICLE_REFIT_CAPACITY, 0, 0, v->engine_type, v);
 
				v->cargo_type = temp_cid;
 
			}
 

	
 
			if (amount == CALLBACK_FAILED) { // callback failed or not used, use default
 
				CargoID old_cid = rvi->cargo_type;
 
				/* normally, the capacity depends on the cargo type, a rail vehicle can
0 comments (0 inline, 0 general)