Changeset - r15928:b5d464e405a1
[Not reviewed]
master
0 1 0
rubidium - 14 years ago 2010-08-26 16:56:06
rubidium@openttd.org
(svn r20626) -Codechange: pass AirportTileSpec to the airport tile callback
1 file changed with 14 insertions and 17 deletions:
0 comments (0 inline, 0 general)
src/newgrf_airporttiles.cpp
Show inline comments
 
@@ -222,13 +222,13 @@ static uint32 AirportTileGetRandomBits(c
 
{
 
	const Station *st = object->u.airport.st;
 
	const TileIndex tile = object->u.airport.tile;
 
	return (st == NULL ? 0 : st->random_bits) | (tile == INVALID_TILE ? 0 : GetStationTileRandomBits(tile) << 16);
 
}
 

	
 
static void AirportTileResolver(ResolverObject *res, StationGfx gfx, TileIndex tile, Station *st)
 
static void AirportTileResolver(ResolverObject *res, const AirportTileSpec *ats, TileIndex tile, const Station *st)
 
{
 
	res->GetRandomBits = AirportTileGetRandomBits;
 
	res->GetTriggers   = NULL;
 
	res->SetTriggers   = NULL;
 
	res->GetVariable   = AirportTileGetVariable;
 
	res->ResolveReal   = AirportTileResolveReal;
 
@@ -244,27 +244,26 @@ static void AirportTileResolver(Resolver
 
	res->callback_param2 = 0;
 
	res->last_value      = 0;
 
	res->trigger         = 0;
 
	res->reseed          = 0;
 
	res->count           = 0;
 

	
 
	const AirportTileSpec *ats = AirportTileSpec::Get(gfx);
 
	res->grffile         = ats->grf_prop.grffile;
 
}
 

	
 
uint16 GetAirportTileCallback(CallbackID callback, uint32 param1, uint32 param2, StationGfx gfx_id, Station *st, TileIndex tile)
 
uint16 GetAirportTileCallback(CallbackID callback, uint32 param1, uint32 param2, const AirportTileSpec *ats, const Station *st, TileIndex tile)
 
{
 
	ResolverObject object;
 
	const SpriteGroup *group;
 

	
 
	AirportTileResolver(&object, gfx_id, tile, st);
 
	AirportTileResolver(&object, ats, tile, st);
 
	object.callback = callback;
 
	object.callback_param1 = param1;
 
	object.callback_param2 = param2;
 

	
 
	group = SpriteGroup::Resolve(AirportTileSpec::Get(gfx_id)->grf_prop.spritegroup[0], &object);
 
	group = SpriteGroup::Resolve(ats->grf_prop.spritegroup[0], &object);
 
	if (group == NULL) return CALLBACK_FAILED;
 

	
 
	return group->GetCallbackResult();
 
}
 

	
 
static void AirportDrawTileLayout(const TileInfo *ti, const TileLayoutSpriteGroup *group, byte colour, StationGfx gfx)
 
@@ -291,20 +290,20 @@ bool DrawNewAirportTile(TileInfo *ti, St
 
	ResolverObject object;
 

	
 
	if (ti->tileh != SLOPE_FLAT) {
 
		bool draw_old_one = true;
 
		if (HasBit(airts->callback_mask, CBM_AIRT_DRAW_FOUNDATIONS)) {
 
			/* Called to determine the type (if any) of foundation to draw */
 
			uint32 callback_res = GetAirportTileCallback(CBID_AIRPTILE_DRAW_FOUNDATIONS, 0, 0, gfx, st, ti->tile);
 
			uint32 callback_res = GetAirportTileCallback(CBID_AIRPTILE_DRAW_FOUNDATIONS, 0, 0, airts, st, ti->tile);
 
			draw_old_one = (callback_res != 0);
 
		}
 

	
 
		if (draw_old_one) DrawFoundation(ti, FOUNDATION_LEVELED);
 
	}
 

	
 
	AirportTileResolver(&object, gfx, ti->tile, st);
 
	AirportTileResolver(&object, airts, ti->tile, st);
 

	
 
	group = SpriteGroup::Resolve(airts->grf_prop.spritegroup[0], &object);
 
	if (group == NULL || group->type != SGT_TILELAYOUT) {
 
		return false;
 
	}
 

	
 
@@ -313,18 +312,17 @@ bool DrawNewAirportTile(TileInfo *ti, St
 
	return true;
 
}
 

	
 
void AnimateAirportTile(TileIndex tile)
 
{
 
	Station *st = Station::GetByTile(tile);
 
	StationGfx gfx = GetAirportGfx(tile);
 
	const AirportTileSpec *ats = AirportTileSpec::Get(gfx);
 
	const AirportTileSpec *ats = AirportTileSpec::GetByTile(tile);
 
	uint8 animation_speed = ats->animation.speed;
 

	
 
	if (HasBit(ats->callback_mask, CBM_AIRT_ANIM_SPEED)) {
 
		uint16 callback_res = GetAirportTileCallback(CBID_AIRPTILE_ANIMATION_SPEED, 0, 0, gfx, st, tile);
 
		uint16 callback_res = GetAirportTileCallback(CBID_AIRPTILE_ANIMATION_SPEED, 0, 0, ats, st, tile);
 
		if (callback_res != CALLBACK_FAILED) animation_speed = Clamp(callback_res & 0xFF, 0, 16);
 
	}
 

	
 
	/* An animation speed of 2 means the animation frame changes 4 ticks, and
 
	 * increasing this value by one doubles the wait. 0 is the minimum value
 
	 * allowed for animation_speed, which corresponds to 30ms, and 16 is the
 
@@ -333,13 +331,13 @@ void AnimateAirportTile(TileIndex tile)
 

	
 
	bool frame_set_by_callback = false;
 
	uint8 frame      = GetAnimationFrame(tile);
 
	uint16 num_frames = ats->animation.frames;
 

	
 
	if (HasBit(ats->callback_mask, CBM_AIRT_ANIM_NEXT_FRAME)) {
 
		uint16 callback_res = GetAirportTileCallback(CBID_AIRPTILE_ANIM_NEXT_FRAME, HasBit(ats->animation_special_flags, 0) ? Random() : 0, 0, gfx, st, tile);
 
		uint16 callback_res = GetAirportTileCallback(CBID_AIRPTILE_ANIM_NEXT_FRAME, HasBit(ats->animation_special_flags, 0) ? Random() : 0, 0, ats, st, tile);
 

	
 
		if (callback_res != CALLBACK_FAILED) {
 
			frame_set_by_callback = true;
 

	
 
			switch (callback_res & 0xFF) {
 
				case 0xFF:
 
@@ -373,15 +371,15 @@ void AnimateAirportTile(TileIndex tile)
 
	}
 

	
 
	SetAnimationFrame(tile, frame);
 
	MarkTileDirtyByTile(tile);
 
}
 

	
 
static void ChangeAirportTileAnimationFrame(const AirportTileSpec *ats, TileIndex tile, AirpAnimationTrigger trigger, StationGfx gfx, Station *st)
 
static void ChangeAirportTileAnimationFrame(const AirportTileSpec *ats, TileIndex tile, AirpAnimationTrigger trigger, Station *st)
 
{
 
	uint16 callback_res = GetAirportTileCallback(CBID_AIRPTILE_ANIM_START_STOP, Random(), trigger, gfx, st, tile);
 
	uint16 callback_res = GetAirportTileCallback(CBID_AIRPTILE_ANIM_START_STOP, Random(), trigger, ats, st, tile);
 
	if (callback_res == CALLBACK_FAILED) return;
 

	
 
	switch (callback_res & 0xFF) {
 
		case 0xFD: /* Do nothing. */         break;
 
		case 0xFE: AddAnimatedTile(tile);    break;
 
		case 0xFF: DeleteAnimatedTile(tile); break;
 
@@ -395,18 +393,17 @@ static void ChangeAirportTileAnimationFr
 
	 * result are not empty, it is a sound effect. */
 
	if (GB(callback_res, 8, 7) != 0) PlayTileSound(ats->grf_prop.grffile, GB(callback_res, 8, 7), tile);
 
}
 

	
 
void AirportTileAnimationTrigger(Station *st, TileIndex tile, AirpAnimationTrigger trigger, CargoID cargo_type)
 
{
 
	StationGfx gfx = GetAirportGfx(tile);
 
	const AirportTileSpec *ats = AirportTileSpec::Get(gfx);
 
	const AirportTileSpec *ats = AirportTileSpec::GetByTile(tile);
 

	
 
	if (!HasBit(ats->animation.triggers, trigger)) return;
 

	
 
	ChangeAirportTileAnimationFrame(ats, tile, trigger, gfx, st);
 
	ChangeAirportTileAnimationFrame(ats, tile, trigger, st);
 
	return;
 
}
 

	
 
void AirportAnimationTrigger(Station *st, AirpAnimationTrigger trigger, CargoID cargo_type)
 
{
 
	if (st->airport.tile == INVALID_TILE) return;
 
@@ -420,8 +417,8 @@ void AirportAnimationTrigger(Station *st
 
 * Resolve an airport tile's spec and such so we can get a variable.
 
 * @param ro    The resolver object to fill.
 
 * @param index The airport tile to get the data from.
 
 */
 
void GetAirportTileTypeResolver(ResolverObject *ro, uint index)
 
{
 
	AirportTileResolver(ro, GetAirportGfx(index), index, Station::GetByTile(index));
 
	AirportTileResolver(ro, AirportTileSpec::GetByTile(index), index, Station::GetByTile(index));
 
}
0 comments (0 inline, 0 general)