Changeset - r12240:9443a1e602a7
[Not reviewed]
master
0 4 0
smatz - 15 years ago 2009-06-26 13:46:23
smatz@openttd.org
(svn r16665) -Codechange: replace GetTownByTile() by Town::GetByTile()
4 files changed with 26 insertions and 26 deletions:
0 comments (0 inline, 0 general)
src/newgrf_house.cpp
Show inline comments
 
@@ -366,13 +366,13 @@ static void DrawTileLayout(const TileInf
 
	const DrawTileSprites *dts = group->dts;
 
	const DrawTileSeqStruct *dtss;
 

	
 
	const HouseSpec *hs = GetHouseSpecs(house_id);
 
	SpriteID palette = hs->random_colour[TileHash2Bit(ti->x, ti->y)] + PALETTE_RECOLOUR_START;
 
	if (HasBit(hs->callback_mask, CBM_HOUSE_COLOUR)) {
 
		uint16 callback = GetHouseCallback(CBID_HOUSE_COLOUR, 0, 0, house_id, GetTownByTile(ti->tile), ti->tile);
 
		uint16 callback = GetHouseCallback(CBID_HOUSE_COLOUR, 0, 0, house_id, Town::GetByTile(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. */
 
			palette = HasBit(callback, 14) ? GB(callback, 0, 8) + SPR_2CCMAP_BASE : callback;
 
		}
 
	}
 

	
 
@@ -418,13 +418,13 @@ void DrawNewHouseTile(TileInfo *ti, Hous
 
	const HouseSpec *hs = GetHouseSpecs(house_id);
 
	const SpriteGroup *group;
 
	ResolverObject object;
 

	
 
	if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED);
 

	
 
	NewHouseResolver(&object, house_id, ti->tile, GetTownByTile(ti->tile));
 
	NewHouseResolver(&object, house_id, ti->tile, Town::GetByTile(ti->tile));
 

	
 
	group = SpriteGroup::Resolve(hs->spritegroup, &object);
 
	if (group == NULL || group->type != SGT_TILELAYOUT) {
 
		/* XXX: This is for debugging purposes really, and shouldn't stay. */
 
		DrawGroundSprite(SPR_SHADOW_CELL, PAL_NONE);
 
	} else {
 
@@ -440,13 +440,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_HOUSE_ANIMATION_SPEED)) {
 
		uint16 callback_res = GetHouseCallback(CBID_HOUSE_ANIMATION_SPEED, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile);
 
		uint16 callback_res = GetHouseCallback(CBID_HOUSE_ANIMATION_SPEED, 0, 0, GetHouseType(tile), Town::GetByTile(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
 
@@ -455,13 +455,13 @@ void AnimateNewHouseTile(TileIndex tile)
 

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

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

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

	
 
			switch (callback_res & 0xFF) {
 
				case 0xFF:
 
@@ -522,26 +522,26 @@ bool CanDeleteHouse(TileIndex tile)
 
	 * anyone using the scenario editor. */
 
	if (Company::IsValidHumanID(_current_company) || _current_company == OWNER_WATER || _current_company == OWNER_NONE) {
 
		return true;
 
	}
 

	
 
	if (HasBit(hs->callback_mask, CBM_HOUSE_DENY_DESTRUCTION)) {
 
		uint16 callback_res = GetHouseCallback(CBID_HOUSE_DENY_DESTRUCTION, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile);
 
		uint16 callback_res = GetHouseCallback(CBID_HOUSE_DENY_DESTRUCTION, 0, 0, GetHouseType(tile), Town::GetByTile(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_HOUSE_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, 0, GetHouseType(tile), GetTownByTile(tile), tile);
 
		uint16 callback_res = GetHouseCallback(CBID_HOUSE_ANIMATION_START_STOP, param, 0, GetHouseType(tile), Town::GetByTile(tile), tile);
 

	
 
		if (callback_res != CALLBACK_FAILED) ChangeHouseAnimationFrame(hs->grffile, tile, callback_res);
 
	}
 
}
 

	
 
bool NewHouseTileLoop(TileIndex tile)
 
@@ -572,15 +572,15 @@ 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, 0, GetHouseType(tile), GetTownByTile(tile), tile);
 
		uint16 callback_res = GetHouseCallback(CBID_HOUSE_DESTRUCTION, 0, 0, GetHouseType(tile), Town::GetByTile(tile), tile);
 
		if (callback_res != CALLBACK_FAILED && GB(callback_res, 0, 8) > 0) {
 
			ClearTownHouse(GetTownByTile(tile), tile);
 
			ClearTownHouse(Town::GetByTile(tile), tile);
 
			return false;
 
		}
 
	}
 

	
 
	SetHouseProcessingTime(tile, hs->processing_time);
 
	return true;
 
@@ -595,13 +595,13 @@ static void DoTriggerHouse(TileIndex til
 

	
 
	HouseID hid = GetHouseType(tile);
 
	HouseSpec *hs = GetHouseSpecs(hid);
 

	
 
	if (hs->spritegroup == NULL) return;
 

	
 
	NewHouseResolver(&object, hid, tile, GetTownByTile(tile));
 
	NewHouseResolver(&object, hid, tile, Town::GetByTile(tile));
 

	
 
	object.callback = CBID_RANDOM_TRIGGER;
 
	object.trigger = trigger;
 

	
 
	const SpriteGroup *group = SpriteGroup::Resolve(hs->spritegroup, &object);
 
	if (group == NULL) return;
src/saveload/town_sl.cpp
Show inline comments
 
@@ -39,13 +39,13 @@ void UpdateHousesAndTowns()
 
			/* The specs for this type of house are not available any more, so
 
			 * replace it with the substitute original house type. */
 
			house_id = _house_mngr.GetSubstituteID(house_id);
 
			SetHouseType(t, house_id);
 
		}
 

	
 
		town = GetTownByTile(t);
 
		town = Town::GetByTile(t);
 
		IncreaseBuildingCount(town, house_id);
 
		if (IsHouseCompleted(t)) town->population += GetHouseSpecs(house_id)->population;
 

	
 
		/* Increase the number of houses for every house, but only once. */
 
		if (GetHouseNorthPart(house_id) == 0) town->num_houses++;
 
	}
src/town.h
Show inline comments
 
@@ -132,19 +132,19 @@ struct Town : TownPool::PoolItem<&_town_
 
	inline uint16 MaxTownNoise() const
 
	{
 
		if (this->population == 0) return 0; // no population? no noise
 

	
 
		return ((this->population / _settings_game.economy.town_noise_population[_settings_game.difficulty.town_council_tolerance]) + 3);
 
	}
 

	
 
	static FORCEINLINE Town *GetByTile(TileIndex tile)
 
	{
 
		return Town::Get(GetTownIndex(tile));
 
	}
 
};
 

	
 
static inline Town *GetTownByTile(TileIndex tile)
 
{
 
	return Town::Get(GetTownIndex(tile));
 
}
 

	
 
uint32 GetWorldPopulation();
 

	
 
void UpdateTownVirtCoord(Town *t);
 
void UpdateAllTownVirtCoords();
 
void InitializeTown();
 
void ShowTownViewWindow(TownID town);
src/town_cmd.cpp
Show inline comments
 
@@ -77,13 +77,13 @@ Town::~Town()
 
	FOR_ALL_INDUSTRIES(i) if (i->town == this) delete i;
 

	
 
	/* Go through all tiles and delete those belonging to the town */
 
	for (TileIndex tile = 0; tile < MapSize(); ++tile) {
 
		switch (GetTileType(tile)) {
 
			case MP_HOUSE:
 
				if (GetTownByTile(tile) == this) DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
 
				if (Town::GetByTile(tile) == this) DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
 
				break;
 

	
 
			case MP_ROAD:
 
				/* Cached nearest town is updated later (after this town has been deleted) */
 
				if (HasTownOwnedRoad(tile) && GetTownIndex(tile) == this->index) {
 
					DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
 
@@ -377,20 +377,20 @@ static void MakeSingleHouseBigger(TileIn
 
	if (GetHouseConstructionTick(tile) != 0) return;
 

	
 
	const HouseSpec *hs = GetHouseSpecs(GetHouseType(tile));
 

	
 
	/* Check and/or  */
 
	if (HasBit(hs->callback_mask, CBM_HOUSE_CONSTRUCTION_STATE_CHANGE)) {
 
		uint16 callback_res = GetHouseCallback(CBID_HOUSE_CONSTRUCTION_STATE_CHANGE, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile);
 
		uint16 callback_res = GetHouseCallback(CBID_HOUSE_CONSTRUCTION_STATE_CHANGE, 0, 0, GetHouseType(tile), Town::GetByTile(tile), tile);
 
		if (callback_res != CALLBACK_FAILED) ChangeHouseAnimationFrame(hs->grffile, tile, callback_res);
 
	}
 

	
 
	if (IsHouseCompleted(tile)) {
 
		/* Now that construction is complete, we can add the population of the
 
		 * building to the town. */
 
		ChangePopulation(GetTownByTile(tile), hs->population);
 
		ChangePopulation(Town::GetByTile(tile), hs->population);
 
		ResetHouseAge(tile);
 
	}
 
	MarkTileDirtyByTile(tile);
 
}
 

	
 
/** Make the house advance in its construction stages until completion
 
@@ -432,13 +432,13 @@ static void TileLoop_Town(TileIndex tile
 
			house_id < NEW_HOUSE_OFFSET &&
 
			!LiftHasDestination(tile) &&
 
			Chance16(1, 2)) {
 
		AddAnimatedTile(tile);
 
	}
 

	
 
	Town *t = GetTownByTile(tile);
 
	Town *t = Town::GetByTile(tile);
 
	uint32 r = Random();
 

	
 
	if (HasBit(hs->callback_mask, CBM_HOUSE_PRODUCE_CARGO)) {
 
		for (uint i = 0; i < 256; i++) {
 
			uint16 callback = GetHouseCallback(CBID_HOUSE_PRODUCE_CARGO, i, r, house_id, t, tile);
 

	
 
@@ -513,13 +513,13 @@ static CommandCost ClearTile_Town(TileIn
 

	
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 
	cost.AddCost(hs->GetRemovalCost());
 

	
 
	int rating = hs->remove_rating_decrease;
 
	_cleared_town_rating += rating;
 
	Town *t = _cleared_town = GetTownByTile(tile);
 
	Town *t = _cleared_town = Town::GetByTile(tile);
 

	
 
	if (Company::IsValidID(_current_company)) {
 
		if (rating > t->ratings[_current_company] && !(flags & DC_NO_TEST_TOWN_RATING) && !_cheats.magic_bulldozer.value) {
 
			SetDParam(0, t->index);
 
			return_cmd_error(STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS);
 
		}
 
@@ -534,13 +534,13 @@ static CommandCost ClearTile_Town(TileIn
 
}
 

	
 
static void GetProducedCargo_Town(TileIndex tile, CargoID *b)
 
{
 
	HouseID house_id = GetHouseType(tile);
 
	const HouseSpec *hs = GetHouseSpecs(house_id);
 
	Town *t = GetTownByTile(tile);
 
	Town *t = Town::GetByTile(tile);
 

	
 
	if (HasBit(hs->callback_mask, CBM_HOUSE_PRODUCE_CARGO)) {
 
		for (uint i = 0; i < 256; i++) {
 
			uint16 callback = GetHouseCallback(CBID_HOUSE_PRODUCE_CARGO, i, 0, house_id, t, tile);
 

	
 
			if (callback == CALLBACK_FAILED || callback == CALLBACK_HOUSEPRODCARGO_END) break;
 
@@ -569,24 +569,24 @@ static void AddAcceptedCargo_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, 0, GetHouseType(tile), GetTownByTile(tile), tile);
 
		uint16 callback = GetHouseCallback(CBID_HOUSE_ACCEPT_CARGO, 0, 0, GetHouseType(tile), Town::GetByTile(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_HOUSE_CARGO_ACCEPTANCE)) {
 
		uint16 callback = GetHouseCallback(CBID_HOUSE_CARGO_ACCEPTANCE, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile);
 
		uint16 callback = GetHouseCallback(CBID_HOUSE_CARGO_ACCEPTANCE, 0, 0, GetHouseType(tile), Town::GetByTile(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 (_settings_game.game_creation.landscape != LT_TEMPERATE && HasBit(callback, 12)) {
 
				/* The 'S' bit indicates food instead of goods */
 
				ac[CT_FOOD] += GB(callback, 8, 4);
 
@@ -608,13 +608,13 @@ static void GetTileDesc_Town(TileIndex t
 
	const HouseID house = GetHouseType(tile);
 
	const HouseSpec *hs = GetHouseSpecs(house);
 
	bool house_completed = IsHouseCompleted(tile);
 

	
 
	td->str = hs->building_name;
 

	
 
	uint16 callback_res = GetHouseCallback(CBID_HOUSE_CUSTOM_NAME, house_completed ? 1 : 0, 0, house, GetTownByTile(tile), tile);
 
	uint16 callback_res = GetHouseCallback(CBID_HOUSE_CUSTOM_NAME, house_completed ? 1 : 0, 0, house, Town::GetByTile(tile), tile);
 
	if (callback_res != CALLBACK_FAILED) {
 
		StringID new_name = GetGRFStringID(hs->grffile->grfid, 0xD000 + callback_res);
 
		if (new_name != STR_NULL && new_name != STR_UNDEFINED) {
 
			td->str = new_name;
 
		}
 
	}
 
@@ -1211,13 +1211,13 @@ static int GrowTownAtRoad(Town *t, TileI
 
		 * and continue the search from there. */
 
		do target_dir = RandomDiagDir(); while (!(cur_rb & DiagDirToRoadBits(target_dir)));
 
		tile = TileAddByDiagDir(tile, target_dir);
 

	
 
		if (IsTileType(tile, MP_ROAD) && !IsRoadDepot(tile) && HasTileRoadType(tile, ROADTYPE_ROAD)) {
 
			/* Don't allow building over roads of other cities */
 
			if (IsRoadOwner(tile, ROADTYPE_ROAD, OWNER_TOWN) && GetTownByTile(tile) != t) {
 
			if (IsRoadOwner(tile, ROADTYPE_ROAD, OWNER_TOWN) && Town::GetByTile(tile) != t) {
 
				_grow_town_result = GROWTH_SUCCEED;
 
			} else if (IsRoadOwner(tile, ROADTYPE_ROAD, OWNER_NONE) && _game_mode == GM_EDITOR) {
 
				/* If we are in the SE, and this road-piece has no town owner yet, it just found an
 
				 * owner :) (happy happy happy road now) */
 
				SetRoadOwner(tile, ROADTYPE_ROAD, OWNER_TOWN);
 
				SetTownIndex(tile, t->index);
 
@@ -2712,13 +2712,13 @@ Town *ClosestTownFromTile(TileIndex tile
 

	
 
				return town;
 
			}
 
			/* FALL THROUGH */
 

	
 
		case MP_HOUSE:
 
			return GetTownByTile(tile);
 
			return Town::GetByTile(tile);
 

	
 
		default:
 
			return CalcClosestTownFromTile(tile, threshold);
 
	}
 
}
 

	
0 comments (0 inline, 0 general)