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
 
@@ -216,61 +216,60 @@ static uint32 AirportTileGetVariable(con
 

	
 
	*available = false;
 
	return UINT_MAX;
 
}
 

	
 
static uint32 AirportTileGetRandomBits(const ResolverObject *object)
 
{
 
	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;
 

	
 
	assert(st != NULL);
 
	res->psa                  = NULL;
 
	res->u.airport.airport_id = st->airport.type;
 
	res->u.airport.st         = st;
 
	res->u.airport.tile       = tile;
 

	
 
	res->callback        = CBID_NO_CALLBACK;
 
	res->callback_param1 = 0;
 
	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)
 
{
 
	const DrawTileSprites *dts = group->dts;
 

	
 
	SpriteID image = dts->ground.sprite;
 
	SpriteID pal   = dts->ground.pal;
 

	
 
@@ -285,67 +284,66 @@ static void AirportDrawTileLayout(const 
 
	DrawNewGRFTileSeq(ti, dts, TO_BUILDINGS, 0, GENERAL_SPRITE_COLOUR(colour));
 
}
 

	
 
bool DrawNewAirportTile(TileInfo *ti, Station *st, StationGfx gfx, const AirportTileSpec *airts)
 
{
 
	const SpriteGroup *group;
 
	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;
 
	}
 

	
 
	const TileLayoutSpriteGroup *tlgroup = (const TileLayoutSpriteGroup *)group;
 
	AirportDrawTileLayout(ti, tlgroup, Company::Get(st->owner)->colour, gfx);
 
	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
 
	 * maximum, corresponding to around 33 minutes. */
 
	if ((_tick_counter % (1 << animation_speed)) != 0) return;
 

	
 
	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:
 
					DeleteAnimatedTile(tile);
 
					break;
 
				case 0xFE:
 
					/* Carry on as normal. */
 
					frame_set_by_callback = false;
 
					break;
 
@@ -367,61 +365,60 @@ void AnimateAirportTile(TileIndex tile)
 
			/* This animation loops, so start again from the beginning */
 
			frame = 0;
 
		} else {
 
			/* This animation doesn't loop, so stay here */
 
			DeleteAnimatedTile(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;
 
		default:
 
			SetAnimationFrame(tile, callback_res & 0xFF);
 
			AddAnimatedTile(tile);
 
			break;
 
	}
 

	
 
	/* If the lower 7 bits of the upper byte of the callback
 
	 * 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;
 

	
 
	TILE_AREA_LOOP(tile, st->airport) {
 
		if (st->TileBelongsToAirport(tile)) AirportTileAnimationTrigger(st, tile, trigger, cargo_type);
 
	}
 
}
 

	
 
/**
 
 * 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)