Changeset - r3983:b2c269b85722
[Not reviewed]
master
0 3 0
tron - 18 years ago 2006-06-08 18:31:54
tron@openttd.org
(svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
3 files changed with 31 insertions and 20 deletions:
0 comments (0 inline, 0 general)
openttd.c
Show inline comments
 
@@ -1201,40 +1201,40 @@ bool AfterLoadGame(void)
 

	
 
	DoZoomInOutWindow(ZOOM_NONE, w); // update button status
 
	MarkWholeScreenDirty();
 

	
 
	// In 5.1, Oilrigs have been moved (again)
 
	if (CheckSavegameVersionOldStyle(5, 1)) UpdateOilRig();
 

	
 
	/* In version 6.1 we put the town index in the map-array. To do this, we need
 
	 *  to use m2 (16bit big), so we need to clean m2, and that is where this is
 
	 *  all about ;) */
 
	if (CheckSavegameVersionOldStyle(6, 1)) {
 
		BEGIN_TILE_LOOP(tile, MapSizeX(), MapSizeY(), 0) {
 
			if (IsTileType(tile, MP_HOUSE)) {
 
			switch (GetTileType(tile)) {
 
				case MP_HOUSE:
 
				_m[tile].m4 = _m[tile].m2;
 
				//XXX magic
 
				SetTileType(tile, MP_VOID);
 
				_m[tile].m2 = ClosestTownFromTile(tile,(uint)-1)->index;
 
				SetTileType(tile, MP_HOUSE);
 
			} else if (IsTileType(tile, MP_STREET)) {
 
				//XXX magic
 
					SetTownIndex(tile, CalcClosestTownFromTile(tile, (uint)-1)->index);
 
					break;
 

	
 
				case MP_STREET:
 
				_m[tile].m4 |= (_m[tile].m2 << 4);
 
				if (IsTileOwner(tile, OWNER_TOWN)) {
 
					SetTileType(tile, MP_VOID);
 
					_m[tile].m2 = ClosestTownFromTile(tile,(uint)-1)->index;
 
					SetTileType(tile, MP_STREET);
 
						SetTownIndex(tile, CalcClosestTownFromTile(tile, (uint)-1)->index);
 
				} else {
 
					SetTownIndex(tile, 0);
 
				}
 
					break;
 

	
 
				default: break;
 
			}
 
		} END_TILE_LOOP(tile, MapSizeX(), MapSizeY(), 0);
 
	}
 

	
 
	/* From version 9.0, we update the max passengers of a town (was sometimes negative
 
	 *  before that. */
 
	if (CheckSavegameVersion(9)) {
 
		Town *t;
 
		FOR_ALL_TOWNS(t) UpdateTownMaxPass(t);
 
	}
 

	
 
	/* From version 16.0, we included autorenew on engines, which are now saved, but
town_cmd.c
Show inline comments
 
@@ -1730,49 +1730,57 @@ bool CheckIfAuthorityAllows(TileIndex ti
 
		return true;
 

	
 
	if (t->ratings[_current_player] > -200)
 
		return true;
 

	
 
	_error_message = STR_2009_LOCAL_AUTHORITY_REFUSES;
 
	SetDParam(0, t->index);
 

	
 
	return false;
 
}
 

	
 

	
 
Town *ClosestTownFromTile(TileIndex tile, uint threshold)
 
Town* CalcClosestTownFromTile(TileIndex tile, uint threshold)
 
{
 
	Town *t;
 
	uint dist, best = threshold;
 
	Town *best_town = NULL;
 

	
 
	if (IsTileType(tile, MP_HOUSE) || (
 
				IsTileType(tile, MP_STREET) &&
 
				(IsLevelCrossing(tile) ? GetCrossingRoadOwner(tile) : GetTileOwner(tile)) == OWNER_TOWN
 
			))
 
		return GetTownByTile(tile);
 

	
 
	FOR_ALL_TOWNS(t) {
 
		if (t->xy != 0) {
 
			dist = DistanceManhattan(tile, t->xy);
 
			if (dist < best) {
 
				best = dist;
 
				best_town = t;
 
			}
 
		}
 
	}
 

	
 
	return best_town;
 
}
 

	
 

	
 
Town *ClosestTownFromTile(TileIndex tile, uint threshold)
 
{
 
	if (IsTileType(tile, MP_HOUSE) || (
 
				IsTileType(tile, MP_STREET) &&
 
				(IsLevelCrossing(tile) ? GetCrossingRoadOwner(tile) : GetTileOwner(tile)) == OWNER_TOWN
 
			)) {
 
		return GetTownByTile(tile);
 
	} else {
 
		return CalcClosestTownFromTile(tile, threshold);
 
	}
 
}
 

	
 

	
 
void ChangeTownRating(Town *t, int add, int max)
 
{
 
	int rating;
 

	
 
	//	if magic_bulldozer cheat is active, town doesn't penaltize for removing stuff
 
	if (t == NULL ||
 
			_current_player >= MAX_PLAYERS ||
 
			(_cheats.magic_bulldozer.value && add < 0)) {
 
		return;
 
	}
 

	
 
	SETBIT(t->have_ratings, _current_player);
town_map.h
Show inline comments
 
@@ -11,32 +11,31 @@ static inline int GetHouseType(TileIndex
 
{
 
	assert(IsTileType(t, MP_HOUSE));
 
	return _m[t].m4;
 
}
 

	
 
static inline TownID GetTownIndex(TileIndex t)
 
{
 
	assert(IsTileType(t, MP_HOUSE) || IsTileType(t, MP_STREET)); // XXX incomplete
 
	return _m[t].m2;
 
}
 

	
 
/**
 
 * Set the town index for a street tile.
 
 * Set the town index for a road or house tile.
 
 * @param tile the tile
 
 * @param index the index of the town
 
 * @pre IsTileType(tile, MP_STREET)
 
 */
 
static inline void SetTownIndex(TileIndex t, TownID index)
 
{
 
	assert(IsTileType(t, MP_STREET));
 
	assert(IsTileType(t, MP_STREET) || IsTileType(t, MP_HOUSE));
 
	_m[t].m2 = index;
 
}
 

	
 
static inline bool LiftHasDestination(TileIndex t)
 
{
 
	return HASBIT(_m[t].m5, 7);
 
}
 

	
 
static inline void SetLiftDestination(TileIndex t, byte dest)
 
{
 
	SB(_m[t].m5, 0, 6, dest);
 
	SETBIT(_m[t].m1, 7); /* Start moving */
 
@@ -72,24 +71,28 @@ static inline byte GetLiftPosition(TileI
 
}
 

	
 
static inline void SetLiftPosition(TileIndex t, byte pos)
 
{
 
	SB(_m[t].m1, 0, 7, pos);
 
}
 

	
 
static inline Town* GetTownByTile(TileIndex t)
 
{
 
	return GetTown(GetTownIndex(t));
 
}
 

	
 

	
 
Town* CalcClosestTownFromTile(TileIndex tile, uint threshold);
 

	
 

	
 
static inline void MakeHouseTile(TileIndex t, TownID tid, byte counter, byte stage, byte type)
 
{
 
	assert(IsTileType(t, MP_CLEAR));
 

	
 
	SetTileType(t, MP_HOUSE);
 
	_m[t].m1 = 0;
 
	_m[t].m2 = tid;
 
	SB(_m[t].m3, 6, 2, stage);
 
	_m[t].m4 = type;
 
	SB(_m[t].m5, 0, 2, counter);
 

	
 
	MarkTileDirtyByTile(t);
0 comments (0 inline, 0 general)