Changeset - r6642:888871715086
[Not reviewed]
master
0 3 0
peter1138 - 17 years ago 2007-05-19 09:13:08
peter1138@openttd.org
(svn r9873) -Codechange: Add missing second callback parameter for houses
3 files changed with 13 insertions and 13 deletions:
0 comments (0 inline, 0 general)
src/newgrf_house.cpp
Show inline comments
 
@@ -291,21 +291,21 @@ static void NewHouseResolver(ResolverObj
 
	res->callback_param2 = 0;
 
	res->last_value      = 0;
 
	res->trigger         = 0;
 
	res->reseed          = 0;
 
}
 

	
 
uint16 GetHouseCallback(uint16 callback, uint32 param1, HouseID house_id, Town *town, TileIndex tile)
 
uint16 GetHouseCallback(uint16 callback, uint32 param1, uint32 param2, HouseID house_id, Town *town, TileIndex tile)
 
{
 
	ResolverObject object;
 
	const SpriteGroup *group;
 

	
 
	NewHouseResolver(&object, house_id, tile, town);
 
	object.callback = callback;
 
	object.callback_param1 = param1;
 
	object.callback_param2 = 0;
 
	object.callback_param2 = param2;
 

	
 
	group = Resolve(GetHouseSpecs(house_id)->spritegroup, &object);
 
	if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED;
 

	
 
	return group->g.callback.result;
 
}
 
@@ -330,13 +330,13 @@ void DrawTileLayout(const TileInfo *ti, 
 
			SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
 
			pal = PALETTE_TO_TRANSPARENT;
 
		} else if (HASBIT(image, PALETTE_MODIFIER_COLOR)) {
 
			if (pal == 0) {
 
				const HouseSpec *hs = GetHouseSpecs(house_id);
 
				if (HASBIT(hs->callback_mask, CBM_BUILDING_COLOUR)) {
 
					uint16 callback = GetHouseCallback(CBID_BUILDING_COLOUR, 0, house_id, GetTownByTile(ti->tile), ti->tile);
 
					uint16 callback = GetHouseCallback(CBID_BUILDING_COLOUR, 0, 0, house_id, GetTownByTile(ti->tile), ti->tile);
 
					if (callback != CALLBACK_FAILED) {
 
						/* If bit 14 is set, we should use a 2cc colour map, else use the callback value. */
 
						pal = HASBIT(callback, 14) ? GB(callback, 0, 8) + SPR_2CCMAP_BASE : callback;
 
					}
 
				} else {
 
					pal = hs->random_colour[OriginalTileRandomiser(ti->x, ti->y)] + PALETTE_RECOLOR_START;
 
@@ -385,13 +385,13 @@ void AnimateNewHouseTile(TileIndex tile)
 
{
 
	const HouseSpec *hs = GetHouseSpecs(GetHouseType(tile));
 
	byte animation_speed = hs->animation_speed;
 
	bool frame_set_by_callback = false;
 

	
 
	if (HASBIT(hs->callback_mask, CBM_ANIMATION_SPEED)) {
 
		uint16 callback_res = GetHouseCallback(CBID_HOUSE_ANIMATION_SPEED, 0, GetHouseType(tile), GetTownByTile(tile), tile);
 
		uint16 callback_res = GetHouseCallback(CBID_HOUSE_ANIMATION_SPEED, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile);
 
		if (callback_res != CALLBACK_FAILED) animation_speed = clamp(callback_res & 0xFF, 2, 16);
 
	}
 

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

	
 
	byte frame      = GetHouseAnimationFrame(tile);
 
	byte num_frames = GB(hs->animation_frames, 0, 7);
 

	
 
	if (HASBIT(hs->callback_mask, CBM_ANIMATION_NEXT_FRAME)) {
 
		uint32 param = (hs->extra_flags & CALLBACK_1A_RANDOM_BITS) ? Random() : 0;
 
		uint16 callback_res = GetHouseCallback(CBID_HOUSE_ANIMATION_NEXT_FRAME, param, GetHouseType(tile), GetTownByTile(tile), tile);
 
		uint16 callback_res = GetHouseCallback(CBID_HOUSE_ANIMATION_NEXT_FRAME, param, 0, GetHouseType(tile), GetTownByTile(tile), tile);
 

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

	
 
			switch (callback_res & 0xFF) {
 
				case 0xFF:
 
@@ -466,26 +466,26 @@ bool CanDeleteHouse(TileIndex tile)
 
	/* Human players are always allowed to remove buildings, as is water and
 
	 * anyone using the scenario editor. */
 
	if ((IsValidPlayer(_current_player) && IsHumanPlayer(_current_player))
 
			|| _current_player == OWNER_WATER || _current_player == OWNER_NONE) return true;
 

	
 
	if (HASBIT(hs->callback_mask, CBM_HOUSE_DENY_DESTRUCTION)) {
 
		uint16 callback_res = GetHouseCallback(CBID_HOUSE_DENY_DESTRUCTION, 0, GetHouseType(tile), GetTownByTile(tile), tile);
 
		uint16 callback_res = GetHouseCallback(CBID_HOUSE_DENY_DESTRUCTION, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile);
 
		return (callback_res == CALLBACK_FAILED || callback_res == 0);
 
	} else {
 
		return !(hs->extra_flags & BUILDING_IS_PROTECTED);
 
	}
 
}
 

	
 
static void AnimationControl(TileIndex tile, uint16 random_bits)
 
{
 
	const HouseSpec *hs = GetHouseSpecs(GetHouseType(tile));
 

	
 
	if (HASBIT(hs->callback_mask, CBM_ANIMATION_START_STOP)) {
 
		uint32 param = (hs->extra_flags & SYNCHRONISED_CALLBACK_1B) ? (GB(Random(), 0, 16) | random_bits << 16) : Random();
 
		uint16 callback_res = GetHouseCallback(CBID_HOUSE_ANIMATION_START_STOP, param, GetHouseType(tile), GetTownByTile(tile), tile);
 
		uint16 callback_res = GetHouseCallback(CBID_HOUSE_ANIMATION_START_STOP, param, 0, GetHouseType(tile), GetTownByTile(tile), tile);
 

	
 
		if (callback_res != CALLBACK_FAILED) ChangeHouseAnimationFrame(tile, callback_res);
 
	}
 
}
 

	
 
bool NewHouseTileLoop(TileIndex tile)
 
@@ -519,13 +519,13 @@ bool NewHouseTileLoop(TileIndex tile)
 
			AnimationControl(tile, 0);
 
		}
 
	}
 

	
 
	/* Check callback 21, which determines if a house should be destroyed. */
 
	if (HASBIT(hs->callback_mask, CBM_HOUSE_DESTRUCTION)) {
 
		uint16 callback_res = GetHouseCallback(CBID_HOUSE_DESTRUCTION, 0, GetHouseType(tile), GetTownByTile(tile), tile);
 
		uint16 callback_res = GetHouseCallback(CBID_HOUSE_DESTRUCTION, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile);
 
		if (callback_res != CALLBACK_FAILED && callback_res > 0) {
 
			ClearTownHouse(GetTownByTile(tile), tile);
 
			return false;
 
		}
 
	}
 

	
src/newgrf_house.h
Show inline comments
 
@@ -51,13 +51,13 @@ void DecreaseBuildingCount(Town *t, Hous
 
void AfterLoadCountBuildings();
 

	
 
void DrawNewHouseTile(TileInfo *ti, HouseID house_id);
 
void AnimateNewHouseTile(TileIndex tile);
 
void ChangeHouseAnimationFrame(TileIndex tile, uint16 callback_result);
 

	
 
uint16 GetHouseCallback(uint16 callback, uint32 param1, HouseID house_id, Town *town, TileIndex tile);
 
uint16 GetHouseCallback(uint16 callback, uint32 param1, uint32 param2, HouseID house_id, Town *town, TileIndex tile);
 

	
 
bool CanDeleteHouse(TileIndex tile);
 

	
 
bool NewHouseTileLoop(TileIndex tile);
 

	
 
#endif /* NEWGRF_HOUSE_H */
src/town_cmd.cpp
Show inline comments
 
@@ -341,13 +341,13 @@ static void MakeSingleHouseBigger(TileIn
 
	/* progress in construction stages */
 
	IncHouseConstructionTick(tile);
 
	if (GetHouseConstructionTick(tile) != 0) return;
 

	
 
	/* Check and/or  */
 
	if (HASBIT(GetHouseSpecs(GetHouseType(tile))->callback_mask, CBM_CONSTRUCTION_STATE_CHANGE)) {
 
		uint16 callback_res = GetHouseCallback(CBID_CONSTRUCTION_STATE_CHANGE, 0, GetHouseType(tile), GetTownByTile(tile), tile);
 
		uint16 callback_res = GetHouseCallback(CBID_CONSTRUCTION_STATE_CHANGE, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile);
 
		if (callback_res != CALLBACK_FAILED) ChangeHouseAnimationFrame(tile, callback_res);
 
	}
 

	
 
	if (IsHouseCompleted(tile)) {
 
		/* Now that construction is complete, we can add the population of the
 
		 * building to the town. */
 
@@ -487,24 +487,24 @@ static void GetAcceptedCargo_Town(TileIn
 
	for (uint8 i = 0; i < lengthof(accepts); i++) {
 
		accepts[i] = hs->accepts_cargo[i];
 
	}
 

	
 
	/* Check for custom accepted cargo types */
 
	if (HASBIT(hs->callback_mask, CBM_HOUSE_ACCEPT_CARGO)) {
 
		uint16 callback = GetHouseCallback(CBID_HOUSE_ACCEPT_CARGO, 0, GetHouseType(tile), GetTownByTile(tile), tile);
 
		uint16 callback = GetHouseCallback(CBID_HOUSE_ACCEPT_CARGO, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile);
 
		if (callback != CALLBACK_FAILED) {
 
			/* Replace accepted cargo types with translated values from callback */
 
			accepts[0] = GetCargoTranslation(GB(callback,  0, 5), hs->grffile);
 
			accepts[1] = GetCargoTranslation(GB(callback,  5, 5), hs->grffile);
 
			accepts[2] = GetCargoTranslation(GB(callback, 10, 5), hs->grffile);
 
		}
 
	}
 

	
 
	/* Check for custom cargo acceptance */
 
	if (HASBIT(hs->callback_mask, CBM_CARGO_ACCEPTANCE)) {
 
		uint16 callback = GetHouseCallback(CBID_HOUSE_CARGO_ACCEPTANCE, 0, GetHouseType(tile), GetTownByTile(tile), tile);
 
		uint16 callback = GetHouseCallback(CBID_HOUSE_CARGO_ACCEPTANCE, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile);
 
		if (callback != CALLBACK_FAILED) {
 
			if (accepts[0] != CT_INVALID) ac[accepts[0]] = GB(callback, 0, 4);
 
			if (accepts[1] != CT_INVALID) ac[accepts[1]] = GB(callback, 4, 4);
 
			if (_opt.landscape != LT_TEMPERATE && HASBIT(callback, 12)) {
 
				/* The 'S' bit indicates food instead of goods */
 
				ac[CT_FOOD] = GB(callback, 8, 4);
 
@@ -1660,13 +1660,13 @@ static void DoBuildTownHouse(Town *t, Ti
 
			if (_have_newhouses) {
 
				if (hs->override != 0) hs = GetHouseSpecs(hs->override);
 

	
 
				if ((hs->extra_flags & BUILDING_IS_HISTORICAL) && !_generating_world) continue;
 

	
 
				if (HASBIT(hs->callback_mask, CBM_HOUSE_ALLOW_CONSTRUCTION)) {
 
					uint16 callback_res = GetHouseCallback(CBID_HOUSE_ALLOW_CONSTRUCTION, 0, house, t, tile);
 
					uint16 callback_res = GetHouseCallback(CBID_HOUSE_ALLOW_CONSTRUCTION, 0, 0, house, t, tile);
 
					if (callback_res != CALLBACK_FAILED && callback_res == 0) continue;
 
				}
 
			}
 

	
 
			if (_cur_year < hs->min_date || _cur_year > hs->max_date) continue;
 

	
0 comments (0 inline, 0 general)