Changeset - r2049:7e26d55f0f4c
[Not reviewed]
master
0 44 0
tron - 19 years ago 2005-07-13 18:04:01
tron@openttd.org
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
44 files changed with 989 insertions and 826 deletions:
0 comments (0 inline, 0 general)
ai.c
Show inline comments
 
@@ -2182,7 +2182,7 @@ static bool AiRemoveTileAndGoForward(Pla
 
	TileIndex tilenew;
 

	
 
	if (IsTileType(tile, MP_TUNNELBRIDGE)) {
 
		if (!(_map5[tile] & 0x80)) {
 
		if (!(_m[tile].m5 & 0x80)) {
 
			// Clear the tunnel and continue at the other side of it.
 
			if (CmdFailed(DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR)) )
 
				return false;
 
@@ -2190,18 +2190,18 @@ static bool AiRemoveTileAndGoForward(Pla
 
			return true;
 
		}
 

	
 
		if (!(_map5[tile] & 0x40)) {
 
		if (!(_m[tile].m5 & 0x40)) {
 

	
 
			// Check if the bridge points in the right direction.
 
			// This is not really needed the first place AiRemoveTileAndGoForward is called.
 
			if ((_map5[tile]&1) != (p->ai.cur_dir_a&1))
 
			if ((_m[tile].m5&1) != (p->ai.cur_dir_a&1))
 
				return false;
 

	
 
			// Find other side of bridge.
 
			offs = TileOffsByDir(p->ai.cur_dir_a);
 
			do {
 
				tile = TILE_MASK(tile - offs);
 
			} while (_map5[tile] & 0x40);
 
			} while (_m[tile].m5 & 0x40);
 

	
 
			tilenew = TILE_MASK(tile - offs);
 
			// And clear the bridge.
 
@@ -2222,7 +2222,7 @@ static bool AiRemoveTileAndGoForward(Pla
 

	
 
	// Then remove and signals if there are any.
 
	if (IsTileType(tile, MP_RAILWAY) &&
 
			(_map5[tile]&0xC0) == 0x40) {
 
			(_m[tile].m5&0xC0) == 0x40) {
 
		DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_REMOVE_SIGNALS);
 
	}
 

	
 
@@ -2360,7 +2360,7 @@ static int AiGetStationIdByDef(TileIndex
 
{
 
	const AiDefaultBlockData *p = _default_rail_track_data[id]->data;
 
	while (p->mode != 1) p++;
 
	return _map2[TILE_ADD(tile, ToTileIndexDiff(p->tileoffs))];
 
	return _m[TILE_ADD(tile, ToTileIndexDiff(p->tileoffs))].m2;
 
}
 

	
 
static void AiStateBuildRailVeh(Player *p)
 
@@ -2546,12 +2546,12 @@ static int32 AiDoBuildDefaultRoadBlock(T
 

	
 
		if (p->mode == 2) {
 
			if (IsTileType(c, MP_STREET) &&
 
					(_map5[c]&0xF0)==0 &&
 
					(_map5[c]&p->attr)!=0) {
 
					(_m[c].m5&0xF0)==0 &&
 
					(_m[c].m5&p->attr)!=0) {
 
				roadflag |= 2;
 

	
 
				// all bits are already built?
 
				if ((_map5[c]&p->attr)==p->attr)
 
				if ((_m[c].m5&p->attr)==p->attr)
 
					continue;
 
			}
 

	
 
@@ -2592,7 +2592,7 @@ clear_town_stuff:;
 
			if (GetTileSlope(c, NULL) != 0)
 
				return CMD_ERROR;
 

	
 
			if (!(IsTileType(c, MP_STREET) && (_map5[c] & 0xF0) == 0)) {
 
			if (!(IsTileType(c, MP_STREET) && (_m[c].m5 & 0xF0) == 0)) {
 
				ret = DoCommandByTile(c, 0, 0, flag | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, CMD_LANDSCAPE_CLEAR);
 
				if (CmdFailed(ret)) return CMD_ERROR;
 
			}
 
@@ -2776,7 +2776,7 @@ static bool AiEnumFollowRoad(TileIndex t
 
		TileIndex tile2 = TILE_MASK(tile + TileOffsByDir(_dir_by_track[track]));
 

	
 
		if (IsTileType(tile2, MP_STREET) &&
 
				(_map5[tile2]&0xF0) == 0) {
 
				(_m[tile2].m5&0xF0) == 0) {
 
			a->best_dist = dist;
 
			a->best_tile = tile;
 
			a->best_track = track;
 
@@ -3161,7 +3161,7 @@ static int AiGetStationIdFromRoadBlock(T
 
{
 
	const AiDefaultBlockData *p = _road_default_block_data[id]->data;
 
	while (p->mode != 1) p++;
 
	return _map2[TILE_ADD(tile, ToTileIndexDiff(p->tileoffs))];
 
	return _m[TILE_ADD(tile, ToTileIndexDiff(p->tileoffs))].m2;
 
}
 

	
 
static void AiStateBuildRoadVehicles(Player *p)
 
@@ -3245,7 +3245,7 @@ static bool AiCheckIfHangar(Station *st)
 
	// HANGAR of airports
 
	// 0x20 - hangar large airport (32)
 
	// 0x41 - hangar small airport (65)
 
	return (_map5[tile] == 32 || _map5[tile] == 65);
 
	return (_m[tile].m5 == 32 || _m[tile].m5 == 65);
 
}
 

	
 
static void AiStateAirportStuff(Player *p)
 
@@ -3431,8 +3431,8 @@ static void AiStateBuildDefaultAirportBl
 
					!IsTileType(aib->use_tile, MP_STATION)
 
					) {
 

	
 
				_map_type_and_height[aib->use_tile] = 0xa1;
 
				_map5[aib->use_tile] = 0x80;
 
				_m[aib->use_tile].type_height = 0xa1;
 
				_m[aib->use_tile].m5 = 0x80;
 
				MarkTileDirtyByTile(aib->use_tile);
 
			}
 
#endif
 
@@ -3480,7 +3480,7 @@ static int AiGetStationIdFromAircraftBlo
 
{
 
	const AiDefaultBlockData *p = _airport_default_block_data[id];
 
	while (p->mode != 1) p++;
 
	return _map2[TILE_ADD(tile, ToTileIndexDiff(p->tileoffs))];
 
	return _m[TILE_ADD(tile, ToTileIndexDiff(p->tileoffs))].m2;
 
}
 

	
 
static void AiStateBuildAircraftVehicles(Player *p)
 
@@ -3646,7 +3646,7 @@ static void AiRemovePlayerRailOrRoad(Pla
 
	if (IsTileType(tile, MP_RAILWAY)) {
 
		if (!IsTileOwner(tile, _current_player)) return;
 

	
 
		m5 = _map5[tile];
 
		m5 = _m[tile].m5;
 
		if ((m5&~0x3) != 0xC0) {
 
is_rail_crossing:;
 
			m5 = GetRailTrackStatus(tile);
 
@@ -3708,7 +3708,7 @@ pos_3:
 
		if (IsLevelCrossing(tile))
 
			goto is_rail_crossing;
 

	
 
		if ( (_map5[tile]&0xF0) == 0x20) {
 
		if ( (_m[tile].m5&0xF0) == 0x20) {
 
			int dir;
 

	
 
			// Check if there are any stations around.
 
@@ -3728,7 +3728,7 @@ pos_3:
 
					IsTileOwner(tile + TileDiffXY(0, 1), _current_player))
 
						return;
 

	
 
			dir = _map5[tile] & 3;
 
			dir = _m[tile].m5 & 3;
 

	
 
			DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
 
			DoCommandByTile(
 
@@ -3741,12 +3741,12 @@ pos_3:
 
	} else if (IsTileType(tile, MP_TUNNELBRIDGE)) {
 
		byte b;
 

	
 
		if (!IsTileOwner(tile, _current_player) || (_map5[tile] & 0xC6) != 0x80)
 
		if (!IsTileOwner(tile, _current_player) || (_m[tile].m5 & 0xC6) != 0x80)
 
			return;
 

	
 
		m5 = 0;
 

	
 
		b = _map5[tile] & 0x21;
 
		b = _m[tile].m5 & 0x21;
 
		if (b == 0) goto pos_0;
 
		if (b == 1) goto pos_3;
 
		if (b == 0x20) goto pos_2;
ai_new.c
Show inline comments
 
@@ -589,7 +589,7 @@ static void AiNew_State_FindStation(Play
 
								new_tile = st->xy;
 
								// Cheap way to get the direction of the station...
 
								//  Bus stations save it as 0x47 .. 0x4A, so decrease it with 0x47, and tada!
 
								direction = _map5[st->xy] - 0x47;
 
								direction = _m[st->xy].m5 - 0x47;
 
								break;
 
							}
 
						}
 
@@ -761,11 +761,11 @@ static void AiNew_State_FindDepot(Player
 
		for (j = 0; j < 4; j++) {
 
			if (IsTileType(tile + TileOffsByDir(j), MP_STREET)) {
 
				// Its a street, test if it is a depot
 
				if (_map5[tile + TileOffsByDir(j)] & 0x20) {
 
				if (_m[tile + TileOffsByDir(j)].m5 & 0x20) {
 
					// We found a depot, is it ours? (TELL ME!!!)
 
					if (IsTileOwner(tile + TileOffsByDir(j), _current_player)) {
 
						// Now, is it pointing to the right direction.........
 
						if ((_map5[tile + TileOffsByDir(j)] & 3) == (j ^ 2)) {
 
						if ((_m[tile + TileOffsByDir(j)].m5 & 3) == (j ^ 2)) {
 
							// Yeah!!!
 
							p->ainew.depot_tile = tile + TileOffsByDir(j);
 
							p->ainew.depot_direction = j ^ 2; // Reverse direction
 
@@ -1061,7 +1061,7 @@ static void AiNew_State_BuildDepot(Playe
 
	int res = 0;
 
	assert(p->ainew.state == AI_STATE_BUILD_DEPOT);
 

	
 
	if (IsTileType(p->ainew.depot_tile, MP_STREET) && _map5[p->ainew.depot_tile] & 0x20) {
 
	if (IsTileType(p->ainew.depot_tile, MP_STREET) && _m[p->ainew.depot_tile].m5 & 0x20) {
 
		if (IsTileOwner(p->ainew.depot_tile, _current_player)) {
 
			// The depot is already builded!
 
			p->ainew.state = AI_STATE_BUILD_VEHICLE;
 
@@ -1151,7 +1151,7 @@ static void AiNew_State_GiveOrders(Playe
 
		idx = 0;
 
		order.type = OT_GOTO_STATION;
 
		order.flags = 0;
 
		order.station = _map2[p->ainew.from_tile];
 
		order.station = _m[p->ainew.from_tile].m2;
 
    if (p->ainew.tbt == AI_TRUCK && p->ainew.from_deliver)
 
			order.flags |= OF_FULL_LOAD;
 
		DoCommandByTile(0, p->ainew.veh_id + (idx << 16), PackOrder(&order), DC_EXEC, CMD_INSERT_ORDER);
 
@@ -1159,7 +1159,7 @@ static void AiNew_State_GiveOrders(Playe
 
		idx = 1;
 
		order.type = OT_GOTO_STATION;
 
		order.flags = 0;
 
		order.station = _map2[p->ainew.to_tile];
 
		order.station = _m[p->ainew.to_tile].m2;
 
    if (p->ainew.tbt == AI_TRUCK && p->ainew.to_deliver)
 
			order.flags |= OF_FULL_LOAD;
 
		DoCommandByTile(0, p->ainew.veh_id + (idx << 16), PackOrder(&order), DC_EXEC, CMD_INSERT_ORDER);
ai_pathfinder.c
Show inline comments
 
@@ -38,9 +38,9 @@ static bool IsRoad(TileIndex tile)
 
		(IsTileType(tile, MP_STREET) && !IsTileDepotType(tile, TRANSPORT_ROAD)) ||
 
		(IsTileType(tile, MP_TUNNELBRIDGE) && (
 
			// road tunnel?
 
			((_map5[tile] & 0x80) == 0 && (_map5[tile] & 0x4) == 0x4) ||
 
			((_m[tile].m5 & 0x80) == 0 && (_m[tile].m5 & 0x4) == 0x4) ||
 
			// road bridge?
 
			((_map5[tile] & 0x80) != 0 && (_map5[tile] & 0x2) == 0x2)
 
			((_m[tile].m5 & 0x80) != 0 && (_m[tile].m5 & 0x2) == 0x2)
 
		));
 
}
 

	
 
@@ -220,11 +220,11 @@ static void AyStar_AiPathFinder_GetNeigh
 
			if (!PathFinderInfo->rail_or_road && IsRoad(atile)) {
 
				if (IsTileType(atile, MP_TUNNELBRIDGE)) {
 
					// An existing bridge... let's test the direction ;)
 
					if ((_map5[atile] & 1U) != (i & 1)) continue;
 
					if ((_m[atile].m5 & 1U) != (i & 1)) continue;
 
					// This problem only is valid for tunnels:
 
					// When the last tile was not yet a tunnel, check if we enter from the right side..
 
					if ((_map5[atile] & 0x80) == 0) {
 
						if (i != (_map5[atile] & 3U)) continue;
 
					if ((_m[atile].m5 & 0x80) == 0) {
 
						if (i != (_m[atile].m5 & 3U)) continue;
 
					}
 
				}
 
			}
 
@@ -232,7 +232,7 @@ static void AyStar_AiPathFinder_GetNeigh
 
			if (!PathFinderInfo->rail_or_road && IsRoad(ctile)) {
 
				if (IsTileType(ctile, MP_TUNNELBRIDGE)) {
 
					// An existing bridge/tunnel... let's test the direction ;)
 
					if ((_map5[ctile] & 1U) != (i & 1)) continue;
 
					if ((_m[ctile].m5 & 1U) != (i & 1)) continue;
 
				}
 
			}
 

	
 
@@ -278,9 +278,9 @@ static void AyStar_AiPathFinder_GetNeigh
 
							dir = 0;
 
						} else {
 
							// It already has road.. check if we miss any bits!
 
							if ((_map5[ctile] & dir) != dir) {
 
							if ((_m[ctile].m5 & dir) != dir) {
 
								// We do miss some pieces :(
 
								dir &= ~_map5[ctile];
 
								dir &= ~_m[ctile].m5;
 
							} else {
 
								dir = 0;
 
							}
aircraft_cmd.c
Show inline comments
 
@@ -260,7 +260,7 @@ int32 CmdBuildAircraft(int x, int y, uin
 
			->layout for #th position of depot. Since layout must start with depots, it is simple
 
		*/
 
		{
 
			const Station* st = GetStation(_map2[tile]);
 
			const Station* st = GetStation(_m[tile].m2);
 
			const AirportFTAClass* Airport = GetAirport(st->airport_type);
 
			uint i;
 

	
 
@@ -277,7 +277,7 @@ int32 CmdBuildAircraft(int x, int y, uin
 

	
 
		v->u.air.state = HANGAR;
 
		v->u.air.previous_pos = v->u.air.pos;
 
		v->u.air.targetairport = _map2[tile];
 
		v->u.air.targetairport = _m[tile].m2;
 
		v->next = u;
 

	
 
		v->service_interval = _patches.servint_aircraft;
 
@@ -326,7 +326,7 @@ bool IsAircraftHangarTile(TileIndex tile
 
	// 0x20 - hangar large airport (32)
 
	// 0x41 - hangar small airport (65)
 
	return IsTileType(tile, MP_STATION) &&
 
				(_map5[tile] == 32 || _map5[tile] == 65 || _map5[tile] == 86);
 
				(_m[tile].m5 == 32 || _m[tile].m5 == 65 || _m[tile].m5 == 86);
 
}
 

	
 
static bool CheckStoppedInHangar(Vehicle *v)
aircraft_gui.c
Show inline comments
 
@@ -509,7 +509,7 @@ static void AircraftViewWndProc(Window *
 
			TileIndex tile = v->tile;
 

	
 
			if (IsTileType(tile, MP_STATION) &&
 
					(_map5[tile] == 32 || _map5[tile] == 65) &&
 
					(_m[tile].m5 == 32 || _m[tile].m5 == 65) &&
 
					v->vehstatus&VS_STOPPED)
 
						disabled = 0;
 
		}
 
@@ -646,7 +646,7 @@ static void DrawAircraftDepotWindow(Wind
 
	}
 
	SetVScrollCount(w, (num + w->hscroll.cap - 1) / w->hscroll.cap);
 

	
 
	SetDParam(0, _map2[tile]);
 
	SetDParam(0, _m[tile].m2);
 
	DrawWindowWidgets(w);
 

	
 
	x = 2;
clear_cmd.c
Show inline comments
 
@@ -110,7 +110,7 @@ static int TerraformProc(TerraformerStat
 

	
 
		// If we have a single diagonal track there, the other side of
 
		// tile can be terraformed.
 
		if ((_map5[tile]&~0x40) == _railway_modes[mode])
 
		if ((_m[tile].m5&~0x40) == _railway_modes[mode])
 
			return 0;
 
	}
 

	
 
@@ -390,7 +390,7 @@ int32 CmdPurchaseLandArea(int x, int y, 
 

	
 
	if (!EnsureNoVehicle(tile)) return CMD_ERROR;
 

	
 
	if (IsTileType(tile, MP_UNMOVABLE) && _map5[tile] == 3 &&
 
	if (IsTileType(tile, MP_UNMOVABLE) && _m[tile].m5 == 3 &&
 
			IsTileOwner(tile, _current_player))
 
		return_cmd_error(STR_5807_YOU_ALREADY_OWN_IT);
 

	
 
@@ -420,7 +420,7 @@ static int32 ClearTile_Clear(TileIndex t
 
			&_price.purchase_land,&_price.purchase_land,&_price.purchase_land,&_price.purchase_land,
 
			&_price.clear_2,&_price.clear_2,&_price.clear_2,&_price.clear_2,
 
	};
 
	const int32 *price = _clear_price_table[_map5[tile] & 0x1F];
 
	const int32 *price = _clear_price_table[_m[tile].m5 & 0x1F];
 

	
 
	if (flags & DC_EXEC)
 
		DoClearSquare(tile);
 
@@ -444,7 +444,7 @@ int32 CmdSellLandArea(int x, int y, uint
 

	
 
	tile = TileVirtXY(x, y);
 

	
 
	if (!IsTileType(tile, MP_UNMOVABLE) || _map5[tile] != 3) return CMD_ERROR;
 
	if (!IsTileType(tile, MP_UNMOVABLE) || _m[tile].m5 != 3) return CMD_ERROR;
 
	if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) return CMD_ERROR;
 

	
 

	
 
@@ -510,7 +510,7 @@ static void DrawTile_Clear(TileInfo *ti)
 
		break;
 

	
 
	case 3:
 
		DrawGroundSprite( _clear_land_sprites_1[_map3_lo[ti->tile]&0xF] + _tileh_to_sprite[ti->tileh]);
 
		DrawGroundSprite( _clear_land_sprites_1[_m[ti->tile].m3&0xF] + _tileh_to_sprite[ti->tileh]);
 
		break;
 

	
 
	case 4:
 
@@ -522,7 +522,7 @@ static void DrawTile_Clear(TileInfo *ti)
 
		break;
 
	}
 

	
 
	DrawClearLandFence(ti, _map3_hi[ti->tile] >> 2);
 
	DrawClearLandFence(ti, _m[ti->tile].m4 >> 2);
 
}
 

	
 
static uint GetSlopeZ_Clear(TileInfo *ti)
 
@@ -554,11 +554,11 @@ void TileLoopClearHelper(TileIndex tile)
 

	
 
	switch (GetTileType(tile)) {
 
		case MP_CLEAR:
 
			img_1 = img_by_map5[(_map5[tile] & 0x1C) >> 2];
 
			img_1 = img_by_map5[(_m[tile].m5 & 0x1C) >> 2];
 
			break;
 

	
 
		case MP_TREES:
 
			if ((_map2[tile] & 0x30) == 0x20)
 
			if ((_m[tile].m2 & 0x30) == 0x20)
 
				img_1 = 1;
 
			else
 
				img_1 = 0;
 
@@ -571,11 +571,11 @@ void TileLoopClearHelper(TileIndex tile)
 

	
 
	switch (GetTileType(TILE_ADDXY(tile, 1, 0))) {
 
		case MP_CLEAR:
 
			img_2 = img_by_map5[(_map5[TILE_ADDXY(tile, 1, 0)] & 0x1C) >> 2];
 
			img_2 = img_by_map5[(_m[TILE_ADDXY(tile, 1, 0)].m5 & 0x1C) >> 2];
 
			break;
 

	
 
		case MP_TREES:
 
			if ((_map2[TILE_ADDXY(tile, 1, 0)] & 0x30) == 0x20)
 
			if ((_m[TILE_ADDXY(tile, 1, 0)].m2 & 0x30) == 0x20)
 
				img_2 = 1;
 
			else
 
				img_2 = 0;
 
@@ -586,25 +586,25 @@ void TileLoopClearHelper(TileIndex tile)
 
			break;
 
	}
 

	
 
	if ((_map3_hi[tile] & 0xE0) == 0) {
 
	if ((_m[tile].m4 & 0xE0) == 0) {
 
		if ((img_1 & 2) != (img_2 & 2)) {
 
			_map3_hi[tile] |= 3 << 5;
 
			_m[tile].m4 |= 3 << 5;
 
			dirty = tile;
 
		}
 
	} else {
 
		if (img_1 == 1 && img_2 == 1) {
 
			_map3_hi[tile] &= ~(3 << 5);
 
			_m[tile].m4 &= ~(3 << 5);
 
			dirty = tile;
 
		}
 
	}
 

	
 
	switch (GetTileType(TILE_ADDXY(tile, 0, 1))) {
 
		case MP_CLEAR:
 
			img_2 = img_by_map5[(_map5[TILE_ADDXY(tile, 0, 1)] & 0x1C) >> 2];
 
			img_2 = img_by_map5[(_m[TILE_ADDXY(tile, 0, 1)].m5 & 0x1C) >> 2];
 
			break;
 

	
 
		case MP_TREES:
 
			if ((_map2[TILE_ADDXY(tile, 0, 1)] & 0x30) == 0x20)
 
			if ((_m[TILE_ADDXY(tile, 0, 1)].m2 & 0x30) == 0x20)
 
				img_2 = 1;
 
			else
 
				img_2 = 0;
 
@@ -615,14 +615,14 @@ void TileLoopClearHelper(TileIndex tile)
 
			break;
 
	}
 

	
 
	if ((_map3_hi[tile] & 0x1C) == 0) {
 
	if ((_m[tile].m4 & 0x1C) == 0) {
 
		if ((img_1 & 2) != (img_2 & 2)) {
 
			_map3_hi[tile] |= 3 << 2;
 
			_m[tile].m4 |= 3 << 2;
 
			dirty = tile;
 
		}
 
	} else {
 
		if (img_1 == 1 && img_2 == 1) {
 
			_map3_hi[tile] &= ~(3 << 2);
 
			_m[tile].m4 &= ~(3 << 2);
 
			dirty = tile;
 
		}
 
	}
 
@@ -641,8 +641,8 @@ static void TileLoopClearAlps(TileIndex 
 
	/* distance from snow line, in steps of 8 */
 
	k = GetTileZ(tile) - _opt.snow_line;
 

	
 
	m5 = _map5[tile] & 0x1C;
 
	tmp = _map5[tile] & 3;
 
	m5 = _m[tile].m5 & 0x1C;
 
	tmp = _m[tile].m5 & 3;
 

	
 
	if (k < -8) {
 
		/* snow_m2_down */
 
@@ -690,24 +690,24 @@ static void TileLoopClearAlps(TileIndex 
 
			return;
 
	}
 

	
 
	_map5[tile] = m5;
 
	_m[tile].m5 = m5;
 
	MarkTileDirtyByTile(tile);
 
}
 

	
 
static void TileLoopClearDesert(TileIndex tile)
 
{
 
 	if ( (_map5[tile] & 0x1C) == 0x14)
 
 	if ( (_m[tile].m5 & 0x1C) == 0x14)
 
		return;
 

	
 
	if (GetMapExtraBits(tile) == 1) {
 
		_map5[tile] = 0x17;
 
		_m[tile].m5 = 0x17;
 
	} else {
 
		if (GetMapExtraBits(tile + TileDiffXY( 1,  0)) != 1 &&
 
				GetMapExtraBits(tile + TileDiffXY(-1,  0)) != 1 &&
 
				GetMapExtraBits(tile + TileDiffXY( 0,  1)) != 1 &&
 
				GetMapExtraBits(tile + TileDiffXY( 0, -1)) != 1)
 
			return;
 
		_map5[tile] = 0x15;
 
		_m[tile].m5 = 0x15;
 
	}
 

	
 
	MarkTileDirtyByTile(tile);
 
@@ -725,7 +725,7 @@ static void TileLoop_Clear(TileIndex til
 
		TileLoopClearAlps(tile);
 
	}
 

	
 
	m5 = _map5[tile];
 
	m5 = _m[tile].m5;
 
	if ( (m5 & 0x1C) == 0x10 || (m5 & 0x1C) == 0x14)
 
		return;
 

	
 
@@ -737,7 +737,7 @@ static void TileLoop_Clear(TileIndex til
 
			m5 += 0x20;
 
			if (m5 >= 0x20) {
 
				// Didn't overflow
 
				_map5[tile] = m5;
 
				_m[tile].m5 = m5;
 
				return;
 
			}
 
			/* did overflow, so continue */
 
@@ -750,18 +750,18 @@ static void TileLoop_Clear(TileIndex til
 
		m5 += 0x20;
 
		if (m5 >= 0x20) {
 
			// Didn't overflow
 
			_map5[tile] = m5;
 
			_m[tile].m5 = m5;
 
			return;
 
		}
 
		/* overflowed */
 
		m3 = _map3_lo[tile] + 1;
 
		m3 = _m[tile].m3 + 1;
 
		assert( (m3 & 0xF) != 0);
 
		if ( (m3 & 0xF) >= 9) /* NOTE: will not work properly if m3&0xF == 0xF */
 
			m3 &= ~0xF;
 
		_map3_lo[tile] = m3;
 
		_m[tile].m3 = m3;
 
	}
 

	
 
	_map5[tile] = m5;
 
	_m[tile].m5 = m5;
 
	MarkTileDirtyByTile(tile);
 
}
 

	
 
@@ -776,7 +776,7 @@ void GenerateClearTile(void)
 
	do {
 
		tile = TILE_MASK(Random());
 
		if (IsTileType(tile, MP_CLEAR))
 
			_map5[tile] = (byte)((_map5[tile] & ~(3<<2)) | (1<<2));
 
			_m[tile].m5 = (byte)((_m[tile].m5 & ~(3<<2)) | (1<<2));
 
	} while (--i);
 

	
 
	/* add grey squares */
 
@@ -789,7 +789,7 @@ void GenerateClearTile(void)
 
			for(;;) {
 
				TileIndex tile_new;
 

	
 
				_map5[tile] = (byte)((_map5[tile] & ~(3<<2)) | (2<<2));
 
				_m[tile].m5 = (byte)((_m[tile].m5 & ~(3<<2)) | (2<<2));
 
				do {
 
					if (--j == 0) goto get_out;
 
					tile_new = tile + TileOffsByDir(Random() & 3);
 
@@ -827,9 +827,9 @@ static const StringID _clear_land_str[4+
 

	
 
static void GetTileDesc_Clear(TileIndex tile, TileDesc *td)
 
{
 
	int i = (_map5[tile]>>2) & 7;
 
	int i = (_m[tile].m5>>2) & 7;
 
	if (i == 0)
 
		i = (_map5[tile] & 3) + 8;
 
		i = (_m[tile].m5 & 3) + 8;
 
	td->str = _clear_land_str[i - 1];
 
	td->owner = GetTileOwner(tile);
 
}
depot.h
Show inline comments
 
@@ -72,13 +72,13 @@ static inline bool IsTileDepotType(TileI
 
	switch(type)
 
	{
 
		case TRANSPORT_RAIL:
 
			return IsTileType(tile, MP_RAILWAY) && (_map5[tile] & 0xFC) == 0xC0;
 
			return IsTileType(tile, MP_RAILWAY) && (_m[tile].m5 & 0xFC) == 0xC0;
 

	
 
		case TRANSPORT_ROAD:
 
			return IsTileType(tile, MP_STREET) && (_map5[tile] & 0xF0) == 0x20;
 
			return IsTileType(tile, MP_STREET) && (_m[tile].m5 & 0xF0) == 0x20;
 

	
 
		case TRANSPORT_WATER:
 
			return IsTileType(tile, MP_WATER) && (_map5[tile] & ~3) == 0x80;
 
			return IsTileType(tile, MP_WATER) && (_m[tile].m5 & ~3) == 0x80;
 

	
 
		default:
 
			assert(0);
 
@@ -98,10 +98,10 @@ static inline DiagDirection GetDepotDire
 
		case TRANSPORT_RAIL:
 
		case TRANSPORT_ROAD:
 
			/* Rail and road store a diagonal direction in bits 0 and 1 */
 
			return (DiagDirection)(_map5[tile] & 3);
 
			return (DiagDirection)(_m[tile].m5 & 3);
 
		case TRANSPORT_WATER:
 
			/* Water is stubborn, it stores the directions in a different order. */
 
			switch (_map5[tile] & 3) {
 
			switch (_m[tile].m5 & 3) {
 
				case 0: return DIAGDIR_NE;
 
				case 1: return DIAGDIR_SW;
 
				case 2: return DIAGDIR_NW;
disaster_cmd.c
Show inline comments
 
@@ -172,12 +172,12 @@ static void DisasterTick_Zeppeliner(Vehi
 

	
 
			if (IsValidTile(tile) &&
 
					IsTileType(tile, MP_STATION) &&
 
					IS_BYTE_INSIDE(_map5[tile], 8, 0x43) &&
 
					IS_BYTE_INSIDE(_m[tile].m5, 8, 0x43) &&
 
					IS_HUMAN_PLAYER(GetTileOwner(tile))) {
 
				v->current_order.station = 1;
 
				v->age = 0;
 

	
 
				SetDParam(0, _map2[tile]);
 
				SetDParam(0, _m[tile].m2);
 
				AddNewsItem(STR_B000_ZEPPELIN_DISASTER_AT,
 
					NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0),
 
					v->index,
 
@@ -197,9 +197,9 @@ static void DisasterTick_Zeppeliner(Vehi
 

	
 
		if (IsValidTile(tile) &&
 
				IsTileType(tile, MP_STATION) &&
 
				IS_BYTE_INSIDE(_map5[tile], 8, 0x43) &&
 
				IS_BYTE_INSIDE(_m[tile].m5, 8, 0x43) &&
 
				IS_HUMAN_PLAYER(GetTileOwner(tile))) {
 
			st = GetStation(_map2[tile]);
 
			st = GetStation(_m[tile].m2);
 
			CLRBITS(st->airport_flags, RUNWAY_IN_block);
 
		}
 

	
 
@@ -239,10 +239,10 @@ static void DisasterTick_Zeppeliner(Vehi
 
	tile = v->tile;/**/
 
	if (IsValidTile(tile) &&
 
			IsTileType(tile, MP_STATION) &&
 
			IS_BYTE_INSIDE(_map5[tile], 8, 0x43) &&
 
			IS_BYTE_INSIDE(_m[tile].m5, 8, 0x43) &&
 
			IS_HUMAN_PLAYER(GetTileOwner(tile))) {
 

	
 
		st = GetStation(_map2[tile]);
 
		st = GetStation(_m[tile].m2);
 
		SETBITS(st->airport_flags, RUNWAY_IN_block);
 
	}
 
}
 
@@ -332,8 +332,8 @@ static void DestructIndustry(Industry *i
 
	TileIndex tile;
 

	
 
	for (tile = 0; tile != MapSize(); tile++) {
 
		if (IsTileType(tile, MP_INDUSTRY) && _map2[tile] == i->index) {
 
			_map_owner[tile] = 0;
 
		if (IsTileType(tile, MP_INDUSTRY) && _m[tile].m2 == i->index) {
 
			_m[tile].owner = 0;
 
			MarkTileDirtyByTile(tile);
 
		}
 
	}
 
@@ -401,7 +401,7 @@ static void DisasterTick_2(Vehicle *v)
 
		if (!IsTileType(tile, MP_INDUSTRY))
 
			return;
 

	
 
		v->dest_tile = ind = _map2[tile];
 
		v->dest_tile = ind = _m[tile].m2;
 

	
 
		if (GetIndustry(ind)->type == IT_OIL_REFINERY) {
 
			v->current_order.station = 1;
 
@@ -472,7 +472,7 @@ static void DisasterTick_3(Vehicle *v)
 
		if (!IsTileType(tile, MP_INDUSTRY))
 
			return;
 

	
 
		v->dest_tile = ind = _map2[tile];
 
		v->dest_tile = ind = _m[tile].m2;
 

	
 
		if (GetIndustry(ind)->type == IT_FACTORY) {
 
			v->current_order.station = 1;
 
@@ -579,7 +579,7 @@ static void DisasterTick_4(Vehicle *v)
 
		tile_org = tile = TILE_MASK(Random());
 
		do {
 
			if (IsTileType(tile, MP_RAILWAY) &&
 
					(_map5[tile] & ~3) != 0xC0 && IS_HUMAN_PLAYER(GetTileOwner(tile)))
 
					(_m[tile].m5 & ~3) != 0xC0 && IS_HUMAN_PLAYER(GetTileOwner(tile)))
 
				break;
 
			tile = TILE_MASK(tile+1);
 
		} while (tile != tile_org);
economy.c
Show inline comments
 
@@ -59,13 +59,13 @@ void UpdatePlayerHouse(Player *p, uint s
 
	(val+= 4, true);
 

	
 
/* house is already big enough */
 
	if (val <= _map5[tile])
 
	if (val <= _m[tile].m5)
 
		return;
 

	
 
	_map5[tile + TileDiffXY(0, 0)] =   val;
 
	_map5[tile + TileDiffXY(0, 1)] = ++val;
 
	_map5[tile + TileDiffXY(1, 0)] = ++val;
 
	_map5[tile + TileDiffXY(1, 1)] = ++val;
 
	_m[tile + TileDiffXY(0, 0)].m5 =   val;
 
	_m[tile + TileDiffXY(0, 1)].m5 = ++val;
 
	_m[tile + TileDiffXY(1, 0)].m5 = ++val;
 
	_m[tile + TileDiffXY(1, 1)].m5 = ++val;
 

	
 
	MarkTileDirtyByTile(tile + TileDiffXY(0, 0));
 
	MarkTileDirtyByTile(tile + TileDiffXY(0, 1));
industry_cmd.c
Show inline comments
 
@@ -255,10 +255,10 @@ static void IndustryDrawTileProc1(TileIn
 
	const DrawIndustrySpec1Struct *d;
 
	uint32 image;
 

	
 
	if (!(_map_owner[ti->tile] & 0x80))
 
	if (!(_m[ti->tile].owner & 0x80))
 
		return;
 

	
 
	d = &_draw_industry_spec1[_map3_lo[ti->tile]];
 
	d = &_draw_industry_spec1[_m[ti->tile].m3];
 

	
 
	AddChildSpriteScreen(0x12A7 + d->image_1, d->x, 0);
 

	
 
@@ -274,8 +274,8 @@ static void IndustryDrawTileProc2(TileIn
 
{
 
	int x = 0;
 

	
 
	if (_map_owner[ti->tile] & 0x80) {
 
		x = _industry_anim_offs[_map3_lo[ti->tile]];
 
	if (_m[ti->tile].owner & 0x80) {
 
		x = _industry_anim_offs[_m[ti->tile].m3];
 
		if ( (byte)x == 0xFF)
 
			x = 0;
 
	}
 
@@ -286,9 +286,9 @@ static void IndustryDrawTileProc2(TileIn
 

	
 
static void IndustryDrawTileProc3(TileInfo *ti)
 
{
 
	if (_map_owner[ti->tile] & 0x80) {
 
	if (_m[ti->tile].owner & 0x80) {
 
		AddChildSpriteScreen(0x128B, 5,
 
			_industry_anim_offs_2[_map3_lo[ti->tile]]);
 
			_industry_anim_offs_2[_m[ti->tile].m3]);
 
	}
 
	AddChildSpriteScreen(4746, 3, 67);
 
}
 
@@ -297,7 +297,7 @@ static void IndustryDrawTileProc4(TileIn
 
{
 
	const DrawIndustrySpec4Struct *d;
 

	
 
	d = &_industry_anim_offs_3[_map3_lo[ti->tile]];
 
	d = &_industry_anim_offs_3[_m[ti->tile].m3];
 

	
 
	if (d->image_1 != 0xFF) {
 
		AddChildSpriteScreen(0x126F, 0x32 - d->image_1 * 2, 0x60 + d->image_1);
 
@@ -313,7 +313,7 @@ static void IndustryDrawTileProc4(TileIn
 

	
 
static void DrawCoalPlantSparkles(TileInfo *ti)
 
{
 
	int image = _map_owner[ti->tile];
 
	int image = _m[ti->tile].owner;
 
	if (image & 0x80) {
 
		image = (image >> 2) & 0x1F;
 
		if (image != 0 && image < 7) {
 
@@ -342,11 +342,11 @@ static void DrawTile_Industry(TileInfo *
 
	uint32 image, ormod;
 

	
 
	/* Pointer to industry */
 
	ind = GetIndustry(_map2[ti->tile]);
 
	ind = GetIndustry(_m[ti->tile].m2);
 
	ormod = (ind->color_map+0x307)<<16;
 

	
 
	/* Retrieve pointer to the draw industry tile struct */
 
	dits = &_industry_draw_tile_data[(ti->map5<<2) | (_map_owner[ti->tile]&3)];
 
	dits = &_industry_draw_tile_data[(ti->map5<<2) | (_m[ti->tile].owner&3)];
 

	
 
	image = dits->sprite_1;
 
	if (image&0x8000 && (image & 0xFFFF0000) == 0)
 
@@ -403,7 +403,7 @@ static uint GetSlopeTileh_Industry(TileI
 

	
 
static void GetAcceptedCargo_Industry(TileIndex tile, AcceptedCargo ac)
 
{
 
	int m5 = _map5[tile];
 
	int m5 = _m[tile].m5;
 
	int a;
 

	
 
	a = _industry_map5_accepts_1[m5];
 
@@ -418,11 +418,11 @@ static void GetAcceptedCargo_Industry(Ti
 

	
 
static void GetTileDesc_Industry(TileIndex tile, TileDesc *td)
 
{
 
	Industry *i = GetIndustry(_map2[tile]);
 
	Industry *i = GetIndustry(_m[tile].m2);
 

	
 
	td->owner = i->owner;
 
	td->str = STR_4802_COAL_MINE + i->type;
 
	if ((_map_owner[tile] & 0x80) == 0) {
 
	if ((_m[tile].owner & 0x80) == 0) {
 
		SetDParamX(td->dparam, 0, td->str);
 
		td->str = STR_2058_UNDER_CONSTRUCTION;
 
	}
 
@@ -430,7 +430,7 @@ static void GetTileDesc_Industry(TileInd
 

	
 
static int32 ClearTile_Industry(TileIndex tile, byte flags)
 
{
 
	Industry *i = GetIndustry(_map2[tile]);
 
	Industry *i = GetIndustry(_m[tile].m2);
 

	
 
	/*	* water can destroy industries
 
			* in editor you can bulldoze industries
 
@@ -466,7 +466,7 @@ static void TransportIndustryGoods(TileI
 
	uint cw, am;
 
	byte m5;
 

	
 
	i = GetIndustry(_map2[tile]);
 
	i = GetIndustry(_m[tile].m2);
 

	
 
	type = i->type;
 
	cw = min(i->cargo_waiting[0], 255);
 
@@ -480,9 +480,9 @@ static void TransportIndustryGoods(TileI
 

	
 
		am = MoveGoodsToStation(i->xy, i->width, i->height, i->produced_cargo[0], cw);
 
		i->last_mo_transported[0] += am;
 
		if (am != 0 && (m5 = _industry_produce_map5[_map5[tile]]) != 0xFF) {
 
			_map5[tile] = m5;
 
			_map_owner[tile] = 0x80;
 
		if (am != 0 && (m5 = _industry_produce_map5[_m[tile].m5]) != 0xFF) {
 
			_m[tile].m5 = m5;
 
			_m[tile].owner = 0x80;
 
			MarkTileDirtyByTile(tile);
 
		}
 
	}
 
@@ -506,10 +506,10 @@ static void AnimateTile_Industry(TileInd
 
{
 
	byte m,n;
 

	
 
	switch(_map5[tile]) {
 
	switch(_m[tile].m5) {
 
	case 174:
 
		if ((_tick_counter & 1) == 0) {
 
			m = _map3_lo[tile] + 1;
 
			m = _m[tile].m3 + 1;
 

	
 
			switch(m & 7) {
 
			case 2:	SndPlayTileFx(SND_2D_RIP_2, tile); break;
 
@@ -520,7 +520,7 @@ static void AnimateTile_Industry(TileInd
 
				m = 0;
 
				DeleteAnimatedTile(tile);
 
			}
 
			_map3_lo[tile] = m;
 
			_m[tile].m3 = m;
 

	
 
			MarkTileDirtyByTile(tile);
 
		}
 
@@ -528,7 +528,7 @@ static void AnimateTile_Industry(TileInd
 

	
 
	case 165:
 
		if ((_tick_counter & 3) == 0) {
 
			m = _map3_lo[tile];
 
			m = _m[tile].m3;
 

	
 
			if (_industry_anim_offs[m] == 0xFF) {
 
				SndPlayTileFx(SND_30_CARTOON_SOUND, tile);
 
@@ -538,7 +538,7 @@ static void AnimateTile_Industry(TileInd
 
				m = 0;
 
				DeleteAnimatedTile(tile);
 
			}
 
			_map3_lo[tile] = m;
 
			_m[tile].m3 = m;
 

	
 
			MarkTileDirtyByTile(tile);
 
		}
 
@@ -546,13 +546,13 @@ static void AnimateTile_Industry(TileInd
 

	
 
	case 162:
 
		if ((_tick_counter&1) == 0) {
 
			m = _map3_lo[tile];
 
			m = _m[tile].m3;
 

	
 
			if (++m >= 40) {
 
				m = 0;
 
				DeleteAnimatedTile(tile);
 
			}
 
			_map3_lo[tile] = m;
 
			_m[tile].m3 = m;
 

	
 
			MarkTileDirtyByTile(tile);
 
		}
 
@@ -561,12 +561,12 @@ static void AnimateTile_Industry(TileInd
 
	// Sparks on a coal plant
 
	case 10:
 
		if ((_tick_counter & 3) == 0) {
 
			m = _map_owner[tile];
 
			m = _m[tile].owner;
 
			if ((m & (31<<2)) == (6 << 2)) {
 
				_map_owner[tile] = m&~(31<<2);
 
				_m[tile].owner = m&~(31<<2);
 
				DeleteAnimatedTile(tile);
 
			} else {
 
				_map_owner[tile] = m + (1<<2);
 
				_m[tile].owner = m + (1<<2);
 
				MarkTileDirtyByTile(tile);
 
			}
 
		}
 
@@ -574,7 +574,7 @@ static void AnimateTile_Industry(TileInd
 

	
 
	case 143:
 
		if ((_tick_counter & 1) == 0) {
 
			m = _map3_lo[tile] + 1;
 
			m = _m[tile].m3 + 1;
 

	
 
			if (m == 1) {
 
				SndPlayTileFx(SND_2C_MACHINERY, tile);
 
@@ -584,11 +584,11 @@ static void AnimateTile_Industry(TileInd
 
				SndPlayTileFx(SND_2A_EXTRACT_AND_POP, tile);
 
			}
 

	
 
			if (m >= 50 && (m=0,++_map3_hi[tile] >= 8)) {
 
				_map3_hi[tile] = 0;
 
			if (m >= 50 && (m=0,++_m[tile].m4 >= 8)) {
 
				_m[tile].m4 = 0;
 
				DeleteAnimatedTile(tile);
 
			}
 
			_map3_lo[tile] = m;
 
			_m[tile].m3 = m;
 
			MarkTileDirtyByTile(tile);
 
		}
 
		break;
 
@@ -596,9 +596,9 @@ static void AnimateTile_Industry(TileInd
 
	case 148: case 149: case 150: case 151:
 
	case 152: case 153: case 154: case 155:
 
		if ((_tick_counter & 3) == 0) {
 
			m = _map5[tile]	+ 1;
 
			m = _m[tile].m5	+ 1;
 
			if (m == 155+1) m = 148;
 
			_map5[tile] = m;
 
			_m[tile].m5 = m;
 

	
 
			MarkTileDirtyByTile(tile);
 
		}
 
@@ -607,16 +607,16 @@ static void AnimateTile_Industry(TileInd
 
	case 30: case 31: case 32:
 
		if ((_tick_counter & 7) == 0) {
 
			bool b = CHANCE16(1,7);
 
			m = _map_owner[tile];
 
			m = _m[tile].owner;
 
			m = (m & 3) + 1;
 
			n = _map5[tile];
 
			n = _m[tile].m5;
 
			if (m == 4 && (m=0,++n) == 32+1 && (n=30,b)) {
 
				_map_owner[tile] = 0x83;
 
				_map5[tile] = 29;
 
				_m[tile].owner = 0x83;
 
				_m[tile].m5 = 29;
 
				DeleteAnimatedTile(tile);
 
			} else {
 
				_map5[tile] = n;
 
				_map_owner[tile] = (_map_owner[tile] & ~3) | m;
 
				_m[tile].m5 = n;
 
				_m[tile].owner = (_m[tile].owner & ~3) | m;
 
				MarkTileDirtyByTile(tile);
 
			}
 
		}
 
@@ -632,8 +632,8 @@ static void AnimateTile_Industry(TileInd
 

	
 
			if (state < 0x1A0) {
 
				if (state < 0x20 || state >= 0x180) {
 
					if (!	(_map_owner[tile] & 0x40)) {
 
						_map_owner[tile] |= 0x40;
 
					if (!	(_m[tile].owner & 0x40)) {
 
						_m[tile].owner |= 0x40;
 
						SndPlayTileFx(SND_0B_MINING_MACHINERY, tile);
 
					}
 
					if (state & 7)
 
@@ -642,9 +642,9 @@ static void AnimateTile_Industry(TileInd
 
					if (state & 3)
 
						return;
 
				}
 
				m = (_map_owner[tile] + 1) | 0x40;
 
				m = (_m[tile].owner + 1) | 0x40;
 
				if (m > 0xC2) m = 0xC0;
 
				_map_owner[tile] = m;
 
				_m[tile].owner = m;
 
				MarkTileDirtyByTile(tile);
 
			} else if (state >= 0x200 && state < 0x3A0) {
 
				int i;
 
@@ -652,9 +652,9 @@ static void AnimateTile_Industry(TileInd
 
				if (state & i)
 
					return;
 

	
 
				m = (_map_owner[tile] & 0xBF) - 1;
 
				m = (_m[tile].owner & 0xBF) - 1;
 
				if (m < 0x80) m = 0x82;
 
				_map_owner[tile] = m;
 
				_m[tile].owner = m;
 
				MarkTileDirtyByTile(tile);
 
			}
 
		} break;
 
@@ -673,33 +673,33 @@ static void MakeIndustryTileBigger(TileI
 
	byte b = (byte)((size + (1<<2)) & (3<<2));
 

	
 
	if (b != 0) {
 
		_map_owner[tile] = b | (size & 3);
 
		_m[tile].owner = b | (size & 3);
 
		return;
 
	}
 

	
 
	size = (size + 1) & 3;
 
	if (size == 3) size |= 0x80;
 
	_map_owner[tile] = size | b;
 
	_m[tile].owner = size | b;
 

	
 
	MarkTileDirtyByTile(tile);
 

	
 
	if (!(_map_owner[tile] & 0x80))
 
	if (!(_m[tile].owner & 0x80))
 
		return;
 

	
 
	switch(_map5[tile]) {
 
	switch(_m[tile].m5) {
 
	case 8:
 
		MakeIndustryTileBiggerCase8(tile);
 
		break;
 

	
 
	case 24:
 
		if (_map5[tile + TileDiffXY(0, 1)] == 24) BuildOilRig(tile);
 
		if (_m[tile + TileDiffXY(0, 1)].m5 == 24) BuildOilRig(tile);
 
		break;
 

	
 
	case 143:
 
	case 162:
 
	case 165:
 
		_map3_lo[tile] = 0;
 
		_map3_hi[tile] = 0;
 
		_m[tile].m3 = 0;
 
		_m[tile].m4 = 0;
 
		break;
 

	
 
	case 148: case 149: case 150: case 151:
 
@@ -740,8 +740,8 @@ static void TileLoop_Industry(TileIndex 
 
{
 
	byte n;
 

	
 
	if (!(_map_owner[tile] & 0x80)) {
 
		MakeIndustryTileBigger(tile, _map_owner[tile]);
 
	if (!(_m[tile].owner & 0x80)) {
 
		MakeIndustryTileBigger(tile, _m[tile].owner);
 
		return;
 
	}
 

	
 
@@ -750,18 +750,18 @@ static void TileLoop_Industry(TileIndex 
 

	
 
	TransportIndustryGoods(tile);
 

	
 
	n = _industry_map5_animation_next[_map5[tile]];
 
	n = _industry_map5_animation_next[_m[tile].m5];
 
	if (n != 255) {
 
		_map5[tile] = n;
 
		_map_owner[tile] = 0;
 
		_m[tile].m5 = n;
 
		_m[tile].owner = 0;
 
		MarkTileDirtyByTile(tile);
 
		return;
 
	}
 

	
 
#define SET_AND_ANIMATE(tile,a,b) { _map5[tile]=a; _map_owner[tile]=b; AddAnimatedTile(tile); }
 
#define SET_AND_UNANIMATE(tile,a,b) { _map5[tile]=a; _map_owner[tile]=b; DeleteAnimatedTile(tile); }
 
#define SET_AND_ANIMATE(tile,a,b) { _m[tile].m5=a; _m[tile].owner=b; AddAnimatedTile(tile); }
 
#define SET_AND_UNANIMATE(tile,a,b) { _m[tile].m5=a; _m[tile].owner=b; DeleteAnimatedTile(tile); }
 

	
 
	switch(_map5[tile]) {
 
	switch(_m[tile].m5) {
 
	case 0x18: // coast line at oilrigs
 
	case 0x19:
 
	case 0x1A:
 
@@ -818,11 +818,11 @@ static void TileLoop_Industry(TileIndex 
 

	
 

	
 
	case 143: {
 
			Industry *i = GetIndustry(_map2[tile]);
 
			Industry *i = GetIndustry(_m[tile].m2);
 
			if (i->was_cargo_delivered) {
 
				i->was_cargo_delivered = false;
 
				if ((_map3_hi[tile]|_map3_lo[tile]) != 0)
 
					_map3_hi[tile] = 0;
 
				if ((_m[tile].m4|_m[tile].m3) != 0)
 
					_m[tile].m4 = 0;
 
				AddAnimatedTile(tile);
 
			}
 
		}
 
@@ -847,7 +847,7 @@ static void TileLoop_Industry(TileIndex 
 

	
 
static void ClickTile_Industry(TileIndex tile)
 
{
 
	ShowIndustryViewWindow(_map2[tile]);
 
	ShowIndustryViewWindow(_m[tile].m2);
 
}
 

	
 
static uint32 GetTileTrackStatus_Industry(TileIndex tile, TransportType mode)
 
@@ -857,7 +857,7 @@ static uint32 GetTileTrackStatus_Industr
 

	
 
static void GetProducedCargo_Industry(TileIndex tile, byte *b)
 
{
 
	Industry *i = GetIndustry(_map2[tile]);
 
	Industry *i = GetIndustry(_m[tile].m2);
 
	b[0] = i->produced_cargo[0];
 
	b[1] = i->produced_cargo[1];
 
}
 
@@ -871,10 +871,10 @@ void DeleteIndustry(Industry *i)
 
{
 
	BEGIN_TILE_LOOP(tile_cur, i->width, i->height, i->xy);
 
		if (IsTileType(tile_cur, MP_INDUSTRY)) {
 
			if (_map2[tile_cur] == i->index) {
 
			if (_m[tile_cur].m2 == i->index) {
 
				DoClearSquare(tile_cur);
 
			}
 
		} else if (IsTileType(tile_cur, MP_STATION) && _map5[tile_cur] == 0x4B) {
 
		} else if (IsTileType(tile_cur, MP_STATION) && _m[tile_cur].m5 == 0x4B) {
 
			DeleteOilRig(tile_cur);
 
		}
 
	END_TILE_LOOP(tile_cur, i->width, i->height, i->xy);
 
@@ -892,7 +892,7 @@ static bool IsBadFarmFieldTile(TileIndex
 
{
 
	switch (GetTileType(tile)) {
 
		case MP_CLEAR: {
 
			byte m5 = _map5[tile] & 0x1C;
 
			byte m5 = _m[tile].m5 & 0x1C;
 
			return m5 == 0xC || m5 == 0x10;
 
		}
 

	
 
@@ -908,7 +908,7 @@ static bool IsBadFarmFieldTile2(TileInde
 
{
 
	switch (GetTileType(tile)) {
 
		case MP_CLEAR: {
 
			byte m5 = _map5[tile] & 0x1C;
 
			byte m5 = _m[tile].m5 & 0x1C;
 
			return m5 == 0x10;
 
		}
 

	
 
@@ -938,7 +938,7 @@ static void SetupFarmFieldFence(TileInde
 
				or <<= 3;
 
				and = (byte)~0xE0;
 
			}
 
			_map3_hi[tile] = (_map3_hi[tile] & and) | or;
 
			_m[tile].m4 = (_m[tile].m4 & and) | or;
 
		}
 

	
 
		tile += direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
 
@@ -1029,7 +1029,7 @@ static void ChopLumberMillTrees(Industry
 
	TileIndex tile = i->xy;
 
	int dir, a, j;
 

	
 
	if ((_map_owner[tile] & 0x80) == 0)
 
	if ((_m[tile].owner & 0x80) == 0)
 
		return;
 

	
 
	/* search outwards as a rectangular spiral */
 
@@ -1520,9 +1520,9 @@ static void DoCreateNewIndustry(Industry
 
			DoCommandByTile(cur_tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
 

	
 
			SetTileType(cur_tile, MP_INDUSTRY);
 
			_map5[cur_tile] = it->map5;
 
			_map2[cur_tile] = i->index;
 
			_map_owner[cur_tile] = _generating_world ? 0x1E : 0; /* maturity */
 
			_m[cur_tile].m5 = it->map5;
 
			_m[cur_tile].m2 = i->index;
 
			_m[cur_tile].owner = _generating_world ? 0x1E : 0; /* maturity */
 
		}
 
	} while ((++it)->ti.x != -0x80);
 

	
landscape.c
Show inline comments
 
@@ -52,7 +52,7 @@ void FindLandscapeHeightByTile(TileInfo 
 
	assert(tile < MapSize());
 

	
 
	ti->tile = tile;
 
	ti->map5 = _map5[tile];
 
	ti->map5 = _m[tile].m5;
 
	ti->type = GetTileType(tile);
 
	ti->tileh = GetTileSlope(tile, &ti->z);
 
}
 
@@ -359,29 +359,29 @@ void CDECL ModifyTile(TileIndex tile, ui
 
	if (flags & (MP_MAP2_CLEAR | MP_MAP2)) {
 
		int x = 0;
 
		if (flags & MP_MAP2) x = va_arg(va, int);
 
		_map2[tile] = x;
 
		_m[tile].m2 = x;
 
	}
 

	
 
	if (flags & (MP_MAP3LO_CLEAR | MP_MAP3LO)) {
 
		int x = 0;
 
		if (flags & MP_MAP3LO) x = va_arg(va, int);
 
		_map3_lo[tile] = x;
 
		_m[tile].m3 = x;
 
	}
 

	
 
	if (flags & (MP_MAP3HI_CLEAR | MP_MAP3HI)) {
 
		int x = 0;
 
		if (flags & MP_MAP3HI) x = va_arg(va, int);
 
		_map3_hi[tile] = x;
 
		_m[tile].m4 = x;
 
	}
 

	
 
	if (flags & (MP_MAPOWNER|MP_MAPOWNER_CURRENT)) {
 
		byte x = _current_player;
 
		if (flags & MP_MAPOWNER) x = va_arg(va, int);
 
		_map_owner[tile] = x;
 
		_m[tile].owner = x;
 
	}
 

	
 
	if (flags & MP_MAP5) {
 
		_map5[tile] = va_arg(va, int);
 
		_m[tile].m5 = va_arg(va, int);
 
	}
 

	
 
	va_end(va);
 
@@ -428,15 +428,17 @@ void InitializeLandscape(uint log_x, uin
 
	uint i;
 

	
 
	InitMap(log_x, log_y);
 

	
 
	map_size = MapSize();
 

	
 
	memset(_map_type_and_height, MP_CLEAR << 4, map_size);
 
	memset(_map_owner,              OWNER_NONE, map_size);
 
	memset(_map2,                            0, map_size * sizeof(_map2[0]));
 
	memset(_map3_lo,                         0, map_size);
 
	memset(_map3_hi,                         0, map_size);
 
	memset(_map5,                            3, map_size);
 
	memset(_map_extra_bits,                  0, map_size / 4);
 
	for (i = 0; i < map_size; i++) {
 
		_m[i].type_height = MP_CLEAR << 4;
 
		_m[i].owner       = OWNER_NONE;
 
		_m[i].m2          = 0;
 
		_m[i].m3          = 0;
 
		_m[i].m4          = 0;
 
		_m[i].m5          = 3;
 
		_m[i].extra       = 0;
 
	}
 

	
 
	// create void tiles at the border
 
	for (i = 0; i < MapMaxY(); ++i)
 
@@ -453,7 +455,7 @@ void ConvertGroundTilesIntoWaterTiles(vo
 
	for (tile = 0; tile < MapSize(); ++tile) {
 
		if (IsTileType(tile, MP_CLEAR) && GetTileSlope(tile, &h) == 0 && h == 0) {
 
			SetTileType(tile, MP_WATER);
 
			_map5[tile] = 0;
 
			_m[tile].m5 = 0;
 
			SetTileOwner(tile, OWNER_WATER);
 
		}
 
	}
 
@@ -471,7 +473,7 @@ static void GenerateTerrain(int type, in
 
	uint h;
 
	const Sprite* template;
 
	const byte *p;
 
	byte *tile;
 
	Tile* tile;
 
	byte direction;
 

	
 
	r = Random();
 
@@ -524,16 +526,16 @@ static void GenerateTerrain(int type, in
 
	if (y + h >= MapMaxY() - 1)
 
		return;
 

	
 
	tile = &_map_type_and_height[TileXY(x, y)];
 
	tile = &_m[TileXY(x, y)];
 

	
 
	switch (direction) {
 
		case 0:
 
			do {
 
				byte *tile_cur = tile;
 
				Tile* tile_cur = tile;
 
				uint w_cur;
 

	
 
				for (w_cur = w; w_cur != 0; --w_cur) {
 
					if (*p >= *tile_cur) *tile_cur = *p;
 
					if (*p >= tile_cur->type_height) tile_cur->type_height = *p;
 
					p++;
 
					tile_cur++;
 
				}
 
@@ -543,11 +545,11 @@ static void GenerateTerrain(int type, in
 

	
 
		case 1:
 
			do {
 
				byte *tile_cur = tile;
 
				Tile* tile_cur = tile;
 
				uint h_cur;
 

	
 
				for (h_cur = h; h_cur != 0; --h_cur) {
 
					if (*p >= *tile_cur) *tile_cur = *p;
 
					if (*p >= tile_cur->type_height) tile_cur->type_height = *p;
 
					p++;
 
					tile_cur += TileDiffXY(0, 1);
 
				}
 
@@ -558,11 +560,11 @@ static void GenerateTerrain(int type, in
 
		case 2:
 
			tile += TileDiffXY(w - 1, 0);
 
			do {
 
				byte *tile_cur = tile;
 
				Tile* tile_cur = tile;
 
				uint w_cur;
 

	
 
				for (w_cur = w; w_cur != 0; --w_cur) {
 
					if (*p >= *tile_cur) *tile_cur = *p;
 
					if (*p >= tile_cur->type_height) tile_cur->type_height = *p;
 
					p++;
 
					tile_cur--;
 
				}
 
@@ -573,11 +575,11 @@ static void GenerateTerrain(int type, in
 
		case 3:
 
			tile += TileDiffXY(0, h - 1);
 
			do {
 
				byte *tile_cur = tile;
 
				Tile* tile_cur = tile;
 
				uint h_cur;
 

	
 
				for (h_cur = h; h_cur != 0; --h_cur) {
 
					if (*p >= *tile_cur) *tile_cur = *p;
 
					if (*p >= tile_cur->type_height) tile_cur->type_height = *p;
 
					p++;
 
					tile_cur -= TileDiffXY(0, 1);
 
				}
 
@@ -613,7 +615,7 @@ static void CreateDesertOrRainForest(voi
 
		for (data = _make_desert_or_rainforest_data;
 
				data != endof(_make_desert_or_rainforest_data); ++data) {
 
			TileIndex t = TILE_MASK(tile + ToTileIndexDiff(*data));
 
			if (IsTileType(t, MP_CLEAR) && (_map5[t] & 0x1c) == 0x14) break;
 
			if (IsTileType(t, MP_CLEAR) && (_m[t].m5 & 0x1c) == 0x14) break;
 
		}
 
		if (data == endof(_make_desert_or_rainforest_data))
 
			SetMapExtraBits(tile, 2);
main_gui.c
Show inline comments
 
@@ -1209,7 +1209,7 @@ static void PlaceProc_RockyArea(TileInde
 
	if (!IsTileType(tile, MP_CLEAR) && !IsTileType(tile, MP_TREES))
 
		return;
 

	
 
	ModifyTile(tile, MP_SETTYPE(MP_CLEAR) | MP_MAP5, (_map5[tile] & ~0x1C) | 0xB);
 
	ModifyTile(tile, MP_SETTYPE(MP_CLEAR) | MP_MAP5, (_m[tile].m5 & ~0x1C) | 0xB);
 
	SndPlayTileFx(SND_1F_SPLAT, tile);
 
}
 

	
map.c
Show inline comments
 
@@ -7,13 +7,7 @@
 
uint _map_log_x;
 
uint _map_log_y;
 

	
 
byte   *_map_type_and_height = NULL;
 
byte   *_map_owner           = NULL;
 
uint16 *_map2                = NULL;
 
byte   *_map3_lo             = NULL;
 
byte   *_map3_hi             = NULL;
 
byte   *_map5                = NULL;
 
byte   *_map_extra_bits      = NULL;
 
Tile* _m = NULL;
 

	
 

	
 
void InitMap(uint log_x, uint log_y)
 
@@ -31,25 +25,11 @@ void InitMap(uint log_x, uint log_y)
 
	// XXX - MSVC6 workaround
 
	map_size = 1 << (log_x + log_y);
 

	
 
	_map_type_and_height =
 
		realloc(_map_type_and_height, map_size * sizeof(_map_type_and_height[0]));
 
	_map_owner = realloc(_map_owner, map_size * sizeof(_map_owner[0]));
 
	_map2      = realloc(_map2,      map_size * sizeof(_map2[0]));
 
	_map3_lo   = realloc(_map3_lo,   map_size * sizeof(_map3_lo[0]));
 
	_map3_hi   = realloc(_map3_hi,   map_size * sizeof(_map3_hi[0]));
 
	_map5      = realloc(_map5,      map_size * sizeof(_map5[0]));
 
	_map_extra_bits =
 
		realloc(_map_extra_bits, map_size * sizeof(_map_extra_bits[0]) / 4);
 
	free(_m);
 
	_m = malloc(map_size * sizeof(*_m));
 

	
 
	// XXX TODO handle memory shortage more gracefully
 
	if (_map_type_and_height == NULL ||
 
			_map_owner           == NULL ||
 
			_map2                == NULL ||
 
			_map3_lo             == NULL ||
 
			_map3_hi             == NULL ||
 
			_map5                == NULL ||
 
			_map_extra_bits      == NULL)
 
		error("Failed to allocate memory for the map");
 
	if (_m == NULL) error("Failed to allocate memory for the map");
 
}
 

	
 

	
map.h
Show inline comments
 
@@ -6,13 +6,17 @@
 
#define TILE_MASK(x) ((x) & ((1 << (MapLogX() + MapLogY())) - 1))
 
#define TILE_ASSERT(x) assert(TILE_MASK(x) == (x));
 

	
 
extern byte   *_map_type_and_height;
 
extern byte   *_map_owner;
 
extern uint16 *_map2;
 
extern byte   *_map3_lo;
 
extern byte   *_map3_hi;
 
extern byte   *_map5;
 
extern byte   *_map_extra_bits;
 
typedef struct Tile {
 
	byte type_height;
 
	byte owner;
 
	uint16 m2;
 
	byte m3;
 
	byte m4;
 
	byte m5;
 
	byte extra;
 
} Tile;
 

	
 
extern Tile* _m;
 

	
 
void InitMap(uint log_x, uint log_y);
 

	
misc.c
Show inline comments
 
@@ -842,14 +842,14 @@ static const SaveLoadGlobVarList _map_di
 
	{NULL, 0, 0, 0}
 
};
 

	
 
static void Save_MAPSIZE(void)
 
static void Save_MAPS(void)
 
{
 
	_map_dim_x = MapSizeX();
 
	_map_dim_y = MapSizeY();
 
	SlGlobList(_map_dimensions);
 
}
 

	
 
static void Load_MAPSIZE(void)
 
static void Load_MAPS(void)
 
{
 
	uint bits_x = 0;
 
	uint bits_y = 0;
 
@@ -862,44 +862,220 @@ static void Load_MAPSIZE(void)
 
	InitMap(bits_x, bits_y);
 
}
 

	
 
static void SaveLoad_MAPT(void)
 
static void Load_MAPT(void)
 
{
 
	uint size = MapSize();
 
	uint i;
 

	
 
	for (i = 0; i != size;) {
 
		byte buf[4096];
 
		uint j;
 

	
 
		SlArray(buf, lengthof(buf), SLE_UINT8);
 
		for (j = 0; j != lengthof(buf); j++) _m[i++].type_height = buf[j];
 
	}
 
}
 

	
 
static void Save_MAPT(void)
 
{
 
  SlArray(_map_type_and_height, MapSize(), SLE_UINT8);
 
	uint size = MapSize();
 
	uint i;
 

	
 
	SlSetLength(size);
 
	for (i = 0; i != size;) {
 
		byte buf[4096];
 
		uint j;
 

	
 
		for (j = 0; j != lengthof(buf); j++) buf[j] = _m[i++].type_height;
 
		SlArray(buf, lengthof(buf), SLE_UINT8);
 
	}
 
}
 

	
 
static void Load_MAPO(void)
 
{
 
	uint size = MapSize();
 
	uint i;
 

	
 
	for (i = 0; i != size;) {
 
		byte buf[4096];
 
		uint j;
 

	
 
		SlArray(buf, lengthof(buf), SLE_UINT8);
 
		for (j = 0; j != lengthof(buf); j++) _m[i++].owner = buf[j];
 
	}
 
}
 

	
 
static void SaveLoad_MAP2(void)
 
static void Save_MAPO(void)
 
{
 
	uint size = MapSize();
 
	uint i;
 

	
 
	SlSetLength(size);
 
	for (i = 0; i != size;) {
 
		byte buf[4096];
 
		uint j;
 

	
 
		for (j = 0; j != lengthof(buf); j++) buf[j] = _m[i++].owner;
 
		SlArray(buf, lengthof(buf), SLE_UINT8);
 
	}
 
}
 

	
 
static void Load_MAP2(void)
 
{
 
	if (_sl.version < 5) {
 
		/* In those versions the _map2 was 8 bits */
 
		SlArray(_map2, MapSize(), SLE_FILE_U8 | SLE_VAR_U16);
 
	} else {
 
		SlArray(_map2, MapSize(), SLE_UINT16);
 
	uint size = MapSize();
 
	uint i;
 

	
 
	for (i = 0; i != size;) {
 
		uint16 buf[4096];
 
		uint j;
 

	
 
		SlArray(buf, lengthof(buf),
 
			/* In those versions the m2 was 8 bits */
 
			_sl.version < 5 ? SLE_FILE_U8 | SLE_VAR_U16 : SLE_UINT16
 
		);
 
		for (j = 0; j != lengthof(buf); j++) _m[i++].m2 = buf[j];
 
	}
 
}
 

	
 
static void Save_MAP2(void)
 
{
 
	uint size = MapSize();
 
	uint i;
 

	
 
	SlSetLength(size * sizeof(_m[0].m2));
 
	for (i = 0; i != size;) {
 
		uint16 buf[4096];
 
		uint j;
 

	
 
		for (j = 0; j != lengthof(buf); j++) buf[j] = _m[i++].m2;
 
		SlArray(buf, lengthof(buf), SLE_UINT16);
 
	}
 
}
 

	
 
static void Load_MAP3(void)
 
{
 
	uint size = MapSize();
 
	uint i;
 

	
 
	for (i = 0; i != size;) {
 
		byte buf[4096];
 
		uint j;
 

	
 
		SlArray(buf, lengthof(buf), SLE_UINT8);
 
		for (j = 0; j != lengthof(buf); j++) _m[i++].m3 = buf[j];
 
	}
 
}
 

	
 
static void SaveLoad_M3LO(void)
 
static void Save_MAP3(void)
 
{
 
  SlArray(_map3_lo, MapSize(), SLE_UINT8);
 
	uint size = MapSize();
 
	uint i;
 

	
 
	SlSetLength(size);
 
	for (i = 0; i != size;) {
 
		byte buf[4096];
 
		uint j;
 

	
 
		for (j = 0; j != lengthof(buf); j++) buf[j] = _m[i++].m3;
 
		SlArray(buf, lengthof(buf), SLE_UINT8);
 
	}
 
}
 

	
 
static void SaveLoad_M3HI(void)
 
static void Load_MAP4(void)
 
{
 
  SlArray(_map3_hi, MapSize(), SLE_UINT8);
 
	uint size = MapSize();
 
	uint i;
 

	
 
	for (i = 0; i != size;) {
 
		byte buf[4096];
 
		uint j;
 

	
 
		SlArray(buf, lengthof(buf), SLE_UINT8);
 
		for (j = 0; j != lengthof(buf); j++) _m[i++].m4 = buf[j];
 
	}
 
}
 

	
 
static void Save_MAP4(void)
 
{
 
	uint size = MapSize();
 
	uint i;
 

	
 
	SlSetLength(size);
 
	for (i = 0; i != size;) {
 
		byte buf[4096];
 
		uint j;
 

	
 
		for (j = 0; j != lengthof(buf); j++) buf[j] = _m[i++].m4;
 
		SlArray(buf, lengthof(buf), SLE_UINT8);
 
	}
 
}
 

	
 
static void SaveLoad_MAPO(void)
 
static void Load_MAP5(void)
 
{
 
  SlArray(_map_owner, MapSize(), SLE_UINT8);
 
	uint size = MapSize();
 
	uint i;
 

	
 
	for (i = 0; i != size;) {
 
		byte buf[4096];
 
		uint j;
 

	
 
		SlArray(buf, lengthof(buf), SLE_UINT8);
 
		for (j = 0; j != lengthof(buf); j++) _m[i++].m5 = buf[j];
 
	}
 
}
 

	
 
static void Save_MAP5(void)
 
{
 
	uint size = MapSize();
 
	uint i;
 

	
 
	SlSetLength(size);
 
	for (i = 0; i != size;) {
 
		byte buf[4096];
 
		uint j;
 

	
 
		for (j = 0; j != lengthof(buf); j++) buf[j] = _m[i++].m5;
 
		SlArray(buf, lengthof(buf), SLE_UINT8);
 
	}
 
}
 

	
 
static void SaveLoad_MAP5(void)
 
static void Load_MAPE(void)
 
{
 
  SlArray(_map5, MapSize(), SLE_UINT8);
 
	uint size = MapSize();
 
	uint i;
 

	
 
	for (i = 0; i != size;) {
 
		uint8 buf[1024];
 
		uint j;
 

	
 
		SlArray(buf, lengthof(buf), SLE_UINT8);
 
		for (j = 0; j != lengthof(buf); j++) {
 
			_m[i++].extra = GB(buf[j], 0, 2);
 
			_m[i++].extra = GB(buf[j], 2, 2);
 
			_m[i++].extra = GB(buf[j], 4, 2);
 
			_m[i++].extra = GB(buf[j], 6, 2);
 
		}
 
	}
 
}
 

	
 
static void SaveLoad_MAPE(void)
 
static void Save_MAPE(void)
 
{
 
  SlArray(_map_extra_bits, MapSize() / 4, SLE_UINT8);
 
	uint size = MapSize();
 
	uint i;
 

	
 
	SlSetLength(size / 4);
 
	for (i = 0; i != size;) {
 
		uint8 buf[1024];
 
		uint j;
 

	
 
		for (j = 0; j != lengthof(buf); j++) {
 
			buf[j]  = _m[i++].extra << 0;
 
			buf[j] |= _m[i++].extra << 2;
 
			buf[j] |= _m[i++].extra << 4;
 
			buf[j] |= _m[i++].extra << 6;
 
		}
 
		SlArray(buf, lengthof(buf), SLE_UINT8);
 
	}
 
}
 

	
 

	
 
@@ -930,14 +1106,14 @@ static void Load_CHTS(void)
 

	
 

	
 
const ChunkHandler _misc_chunk_handlers[] = {
 
	{ 'MAPS', Save_MAPSIZE,  Load_MAPSIZE,  CH_RIFF },
 
	{ 'MAPT', SaveLoad_MAPT, SaveLoad_MAPT, CH_RIFF },
 
	{ 'MAP2', SaveLoad_MAP2, SaveLoad_MAP2, CH_RIFF },
 
	{ 'M3LO', SaveLoad_M3LO, SaveLoad_M3LO, CH_RIFF },
 
	{ 'M3HI', SaveLoad_M3HI, SaveLoad_M3HI, CH_RIFF },
 
	{ 'MAPO', SaveLoad_MAPO, SaveLoad_MAPO, CH_RIFF },
 
	{ 'MAP5', SaveLoad_MAP5, SaveLoad_MAP5, CH_RIFF },
 
	{ 'MAPE', SaveLoad_MAPE, SaveLoad_MAPE, CH_RIFF },
 
	{ 'MAPS', Save_MAPS, Load_MAPS, CH_RIFF },
 
	{ 'MAPT', Save_MAPT, Load_MAPT, CH_RIFF },
 
	{ 'MAPO', Save_MAPO, Load_MAPO, CH_RIFF },
 
	{ 'MAP2', Save_MAP2, Load_MAP2, CH_RIFF },
 
	{ 'M3LO', Save_MAP3, Load_MAP3, CH_RIFF },
 
	{ 'M3HI', Save_MAP4, Load_MAP4, CH_RIFF },
 
	{ 'MAP5', Save_MAP5, Load_MAP5, CH_RIFF },
 
	{ 'MAPE', Save_MAPE, Load_MAPE, CH_RIFF },
 

	
 
	{ 'NAME', Save_NAME, Load_NAME, CH_ARRAY},
 
	{ 'DATE', SaveLoad_DATE, SaveLoad_DATE, CH_RIFF},
misc_gui.c
Show inline comments
 
@@ -150,12 +150,12 @@ static void Place_LandInfo(TileIndex til
 
	#if defined(_DEBUG)
 
		DEBUG(misc, 0) ("TILE: %#x (%i,%i)", tile, TileX(tile), TileY(tile));
 
		DEBUG(misc, 0) ("TILE: %d ", tile);
 
		DEBUG(misc, 0) ("_map_type_and_height=%#x", _map_type_and_height[tile]);
 
		DEBUG(misc, 0) ("_map2=%#x", _map2[tile]);
 
		DEBUG(misc, 0) ("_map3_lo=%#x", _map3_lo[tile]);
 
		DEBUG(misc, 0) ("_map3_hi=%#x", _map3_hi[tile]);
 
		DEBUG(misc, 0) ("_map5=%#x", _map5[tile]);
 
		DEBUG(misc, 0) ("_map_owner=%#x", _map_owner[tile]);
 
		DEBUG(misc, 0) ("_type_height = %#x", _m[tile].type_height);
 
		DEBUG(misc, 0) ("m2           = %#x", _m[tile].m2);
 
		DEBUG(misc, 0) ("m3           = %#x", _m[tile].m3);
 
		DEBUG(misc, 0) ("m4           = %#x", _m[tile].m4);
 
		DEBUG(misc, 0) ("m5           = %#x", _m[tile].m5);
 
		DEBUG(misc, 0) ("owner        = %#x", _m[tile].owner);
 
	#endif
 
}
 

	
npf.c
Show inline comments
 
@@ -34,7 +34,7 @@ bool IsEndOfLine(TileIndex tile, Trackdi
 
	uint32 ts;
 

	
 
	// tunnel entrance?
 
	if (IsTileType(tile, MP_TUNNELBRIDGE) && (_map5[tile] & 0xF0)==0 && (_map5[tile] & 3) == exitdir)
 
	if (IsTileType(tile, MP_TUNNELBRIDGE) && (_m[tile].m5 & 0xF0)==0 && (_m[tile].m5 & 3) == exitdir)
 
		return false;
 

	
 
	// depot
 
@@ -271,7 +271,7 @@ static uint NPFTunnelCost(AyStarNode* cu
 
{
 
	DiagDirection exitdir = TrackdirToExitdir((Trackdir)current->direction);
 
	TileIndex tile = current->tile;
 
	if ( (DiagDirection)(_map5[tile] & 3) == ReverseDiagdir(exitdir)) {
 
	if ( (DiagDirection)(_m[tile].m5 & 3) == ReverseDiagdir(exitdir)) {
 
		/* We just popped out if this tunnel, since were
 
		 * facing the tunnel exit */
 
		FindLengthOfTunnelResult flotr;
 
@@ -323,13 +323,13 @@ static void NPFMarkTile(TileIndex tile)
 
				/* DEBUG: mark visited tiles by mowing the grass under them
 
				 * ;-) */
 
				if (!IsTileDepotType(tile, TRANSPORT_RAIL)) {
 
					_map2[tile] &= ~15; /* Clear bits 0-3 */
 
					_m[tile].m2 &= ~15; /* Clear bits 0-3 */
 
					MarkTileDirtyByTile(tile);
 
				}
 
				break;
 
			case MP_STREET:
 
				if (!IsTileDepotType(tile, TRANSPORT_ROAD)) {
 
					_map3_hi[tile] &= ~0x70; /* Clear bits 4-6 */
 
					_m[tile].m4 &= ~0x70; /* Clear bits 4-6 */
 
					MarkTileDirtyByTile(tile);
 
				}
 
				break;
 
@@ -367,7 +367,7 @@ static int32 NPFRoadPathCost(AyStar* as,
 
	/* Determine base length */
 
	switch (GetTileType(tile)) {
 
		case MP_TUNNELBRIDGE:
 
			if ((_map5[tile] & 0xF0)==0) {
 
			if ((_m[tile].m5 & 0xF0)==0) {
 
				cost = NPFTunnelCost(current);
 
				break;
 
			}
 
@@ -376,7 +376,7 @@ static int32 NPFRoadPathCost(AyStar* as,
 
		case MP_STREET:
 
			cost = NPF_TILE_LENGTH;
 
			/* Increase the cost for level crossings */
 
			if ((_map5[tile] & 0xF0) == 0x10)
 
			if ((_m[tile].m5 & 0xF0) == 0x10)
 
				cost += _patches.npf_crossing_penalty;
 
			break;
 
		default:
 
@@ -411,7 +411,7 @@ static int32 NPFRailPathCost(AyStar* as,
 
	/* Determine base length */
 
	switch (GetTileType(tile)) {
 
		case MP_TUNNELBRIDGE:
 
			if ((_map5[tile] & 0xF0)==0) {
 
			if ((_m[tile].m5 & 0xF0)==0) {
 
				cost = NPFTunnelCost(current);
 
				break;
 
			}
 
@@ -559,7 +559,7 @@ static int32 NPFFindStationOrTile(AyStar
 
	 * is correct */
 
	if (
 
		(fstd->station_index == -1 && tile == fstd->dest_coords) || /* We've found the tile, or */
 
		(IsTileType(tile, MP_STATION) && _map2[tile] == fstd->station_index) || /* the station */
 
		(IsTileType(tile, MP_STATION) && _m[tile].m2 == fstd->station_index) || /* the station */
 
		(NPFGetFlag(node, NPF_FLAG_PBS_TARGET_SEEN)) /* or, we've passed it already (for pbs) */
 
	) {
 
		NPFSetFlag(&current->path.node, NPF_FLAG_PBS_TARGET_SEEN, true);
 
@@ -618,18 +618,18 @@ static bool VehicleMayEnterTile(Owner ow
 
 * intensive owner check, instead we will just assume that if the vehicle
 
 * managed to get on the bridge, it is probably allowed to :-)
 
 */
 
			if ((_map5[tile] & 0xC6) == 0xC0 && (unsigned)(_map5[tile] & 0x1) == (enterdir & 0x1)) {
 
			if ((_m[tile].m5 & 0xC6) == 0xC0 && (unsigned)(_m[tile].m5 & 0x1) == (enterdir & 0x1)) {
 
				/* on the middle part of a railway bridge: find bridge ending */
 
				while (IsTileType(tile, MP_TUNNELBRIDGE) && !((_map5[tile] & 0xC6) == 0x80)) {
 
					tile += TileOffsByDir(_map5[tile] & 0x1);
 
				while (IsTileType(tile, MP_TUNNELBRIDGE) && !((_m[tile].m5 & 0xC6) == 0x80)) {
 
					tile += TileOffsByDir(_m[tile].m5 & 0x1);
 
				}
 
			}
 
			/* if we were on a railway middle part, we are now at a railway bridge ending */
 
#endif
 
			if (
 
				(_map5[tile] & 0xFC) == 0 /* railway tunnel */
 
				|| (_map5[tile] & 0xC6) == 0x80 /* railway bridge ending */
 
				|| ((_map5[tile] & 0xF8) == 0xE0 && ((unsigned)_map5[tile] & 0x1) != (enterdir & 0x1)) /* railway under bridge */
 
				(_m[tile].m5 & 0xFC) == 0 /* railway tunnel */
 
				|| (_m[tile].m5 & 0xC6) == 0x80 /* railway bridge ending */
 
				|| ((_m[tile].m5 & 0xF8) == 0xE0 && ((unsigned)_m[tile].m5 & 0x1) != (enterdir & 0x1)) /* railway under bridge */
 
				)
 
				return IsTileOwner(tile, owner);
 
			break;
 
@@ -663,7 +663,7 @@ static void NPFFollowTrack(AyStar* aysta
 
	aystar->EndNodeCheck(aystar, current);
 

	
 
	/* Find dest tile */
 
	if (IsTileType(src_tile, MP_TUNNELBRIDGE) && (_map5[src_tile] & 0xF0)==0 && (DiagDirection)(_map5[src_tile] & 3) == src_exitdir) {
 
	if (IsTileType(src_tile, MP_TUNNELBRIDGE) && (_m[src_tile].m5 & 0xF0)==0 && (DiagDirection)(_m[src_tile].m5 & 3) == src_exitdir) {
 
		/* This is a tunnel. We know this tunnel is our type,
 
		 * otherwise we wouldn't have got here. It is also facing us,
 
		 * so we should skip it's body */
 
@@ -708,7 +708,7 @@ static void NPFFollowTrack(AyStar* aysta
 
	/* I can't enter a tunnel entry/exit tile from a tile above the tunnel. Note
 
	 * that I can enter the tunnel from a tile below the tunnel entrance. This
 
	 * solves the problem of vehicles wanting to drive off a tunnel entrance */
 
	if (IsTileType(dst_tile, MP_TUNNELBRIDGE) && (_map5[dst_tile] & 0xF0) == 0 && GetTileZ(dst_tile) < GetTileZ(src_tile))
 
	if (IsTileType(dst_tile, MP_TUNNELBRIDGE) && (_m[dst_tile].m5 & 0xF0) == 0 && GetTileZ(dst_tile) < GetTileZ(src_tile))
 
		return;
 

	
 
	/* check correct rail type (mono, maglev, etc) */
oldloader.c
Show inline comments
 
@@ -367,7 +367,7 @@ static void FixOldStations(void)
 

	
 
	FOR_ALL_STATIONS(st) {
 
		/* Check if we need to swap width and height for the station */
 
		if (st->train_tile != 0 && _map5[st->train_tile] & 1) {
 
		if (st->train_tile != 0 && _m[st->train_tile].m5 & 1) {
 
			swap_byte(&st->trainst_w, &st->trainst_h);
 
		}
 

	
 
@@ -1399,17 +1399,21 @@ static bool LoadOldMapPart1(LoadgameStat
 
	uint i;
 

	
 
	for (i = 0; i < OLD_MAP_SIZE; i++) {
 
		_map_owner[i] = ReadByte(ls);
 
		_m[i].owner = ReadByte(ls);
 
	}
 
	for (i = 0; i < OLD_MAP_SIZE; i++) {
 
		_map2[i] = ReadByte(ls);
 
		_m[i].m2 = ReadByte(ls);
 
	}
 
	for (i = 0; i < OLD_MAP_SIZE; i++) {
 
		_old_map3[i * 2] = ReadByte(ls);
 
		_old_map3[i * 2 + 1] = ReadByte(ls);
 
	}
 
	for (i = 0; i < OLD_MAP_SIZE / 4; i++) {
 
		_map_extra_bits[i] = ReadByte(ls);
 
		byte b = ReadByte(ls);
 
		_m[i * 4 + 0].extra = GB(b, 0, 2);
 
		_m[i * 4 + 1].extra = GB(b, 2, 2);
 
		_m[i * 4 + 2].extra = GB(b, 4, 2);
 
		_m[i * 4 + 3].extra = GB(b, 6, 2);
 
	}
 

	
 
	return !ls->failed;
 
@@ -1419,10 +1423,10 @@ static bool LoadOldMapPart2(LoadgameStat
 
	uint i;
 

	
 
	for (i = 0; i < OLD_MAP_SIZE; i++) {
 
		_map_type_and_height[i] = ReadByte(ls);
 
		_m[i].type_height = ReadByte(ls);
 
	}
 
	for (i = 0; i < OLD_MAP_SIZE; i++) {
 
		_map5[i] = ReadByte(ls);
 
		_m[i].m5 = ReadByte(ls);
 
	}
 

	
 
	return !ls->failed;
 
@@ -1568,21 +1572,21 @@ static bool LoadOldMain(LoadgameState *l
 

	
 
	/* _old_map3 is changed in _map3_lo and _map3_hi */
 
	for (i = 0; i < OLD_MAP_SIZE; i++) {
 
		_map3_lo[i] = _old_map3[i * 2];
 
		_map3_hi[i] = _old_map3[i * 2 + 1];
 
		_m[i].m3 = _old_map3[i * 2];
 
		_m[i].m4 = _old_map3[i * 2 + 1];
 
	}
 

	
 
	for (i = 0; i < OLD_MAP_SIZE; i ++) {
 
		if (IsTileType(i, MP_RAILWAY)) {
 
			/* We save presignals different from TTDPatch, convert them */
 
			if ((_map5[i] & 0xC0) == 0x40) {
 
			if ((_m[i].m5 & 0xC0) == 0x40) {
 
				/* This byte is always zero in TTD for this type of tile */
 
				if (_map3_hi[i]) /* Convert the presignals to our own format */
 
					_map3_hi[i] = (_map3_hi[i] >> 1) & 7;
 
				if (_m[i].m4) /* Convert the presignals to our own format */
 
					_m[i].m4 = (_m[i].m4 >> 1) & 7;
 
			}
 
			/* TTDPatch stores PBS things in L6 and all elsewhere; so we'll just
 
			* clear it for ourselves and let OTTD's rebuild PBS itself */
 
			_map3_hi[i] &= 0xF; /* Only keep the lower four bits; upper four is PBS */
 
			_m[i].m4 &= 0xF; /* Only keep the lower four bits; upper four is PBS */
 
		}
 
	}
 

	
openttd.c
Show inline comments
 
@@ -1202,12 +1202,12 @@ static void ConvertTownOwner(void)
 

	
 
	for (tile = 0; tile != MapSize(); tile++) {
 
		if (IsTileType(tile, MP_STREET)) {
 
			if (IsLevelCrossing(tile) && _map3_lo[tile] & 0x80)
 
				_map3_lo[tile] = OWNER_TOWN;
 
			if (IsLevelCrossing(tile) && _m[tile].m3 & 0x80)
 
				_m[tile].m3 = OWNER_TOWN;
 

	
 
			if (_map_owner[tile] & 0x80) SetTileOwner(tile, OWNER_TOWN);
 
			if (_m[tile].owner & 0x80) SetTileOwner(tile, OWNER_TOWN);
 
		} else if (IsTileType(tile, MP_TUNNELBRIDGE)) {
 
			if (_map_owner[tile] & 0x80) SetTileOwner(tile, OWNER_TOWN);
 
			if (_m[tile].owner & 0x80) SetTileOwner(tile, OWNER_TOWN);
 
		}
 
	}
 
}
 
@@ -1401,20 +1401,20 @@ bool AfterLoadGame(uint version)
 
	if (version <= 0x600) {
 
		BEGIN_TILE_LOOP(tile, MapSizeX(), MapSizeY(), 0) {
 
			if (IsTileType(tile, MP_HOUSE)) {
 
				_map3_hi[tile] = _map2[tile];
 
				_m[tile].m4 = _m[tile].m2;
 
				//XXX magic
 
				SetTileType(tile, MP_VOID);
 
				_map2[tile] = ClosestTownFromTile(tile,(uint)-1)->index;
 
				_m[tile].m2 = ClosestTownFromTile(tile,(uint)-1)->index;
 
				SetTileType(tile, MP_HOUSE);
 
			} else if (IsTileType(tile, MP_STREET)) {
 
				//XXX magic
 
				_map3_hi[tile] |= (_map2[tile] << 4);
 
				_m[tile].m4 |= (_m[tile].m2 << 4);
 
				if (IsTileOwner(tile, OWNER_TOWN)) {
 
					SetTileType(tile, MP_VOID);
 
					_map2[tile] = ClosestTownFromTile(tile,(uint)-1)->index;
 
					_m[tile].m2 = ClosestTownFromTile(tile,(uint)-1)->index;
 
					SetTileType(tile, MP_STREET);
 
				} else {
 
					_map2[tile] = 0;
 
					_m[tile].m2 = 0;
 
				}
 
			}
 
		} END_TILE_LOOP(tile, MapSizeX(), MapSizeY(), 0);
 
@@ -1429,9 +1429,9 @@ bool AfterLoadGame(uint version)
 

	
 
	if (version < 0xF00) {
 
		BEGIN_TILE_LOOP(tile, MapSizeX(), MapSizeY(), 0) {
 
			if (IsTileType(tile, MP_RAILWAY) && HasSignals(tile) && HASBIT(_map3_hi[tile], 2)) {
 
				CLRBIT(_map3_hi[tile], 2);
 
				SETBIT(_map3_hi[tile], 3);
 
			if (IsTileType(tile, MP_RAILWAY) && HasSignals(tile) && HASBIT(_m[tile].m4, 2)) {
 
				CLRBIT(_m[tile].m4, 2);
 
				SETBIT(_m[tile].m4, 3);
 
			}
 
		} END_TILE_LOOP(tile, MapSizeX(), MapSizeY(), 0);
 
	}
order_gui.c
Show inline comments
 
@@ -194,7 +194,7 @@ static Order GetOrderCmdFromTile(Vehicle
 
		switch (GetTileType(tile)) {
 
		case MP_RAILWAY:
 
			if (v->type == VEH_Train && IsTileOwner(tile, _local_player)) {
 
				if ((_map5[tile]&0xFC)==0xC0) {
 
				if ((_m[tile].m5&0xFC)==0xC0) {
 
					order.type = OT_GOTO_DEPOT;
 
					order.flags = OF_PART_OF_ORDERS;
 
					order.station = GetDepotByTile(tile)->index;
 
@@ -204,7 +204,7 @@ static Order GetOrderCmdFromTile(Vehicle
 
			break;
 

	
 
		case MP_STREET:
 
			if ((_map5[tile] & 0xF0) == 0x20 && v->type == VEH_Road && IsTileOwner(tile, _local_player)) {
 
			if ((_m[tile].m5 & 0xF0) == 0x20 && v->type == VEH_Road && IsTileOwner(tile, _local_player)) {
 
				order.type = OT_GOTO_DEPOT;
 
				order.flags = OF_PART_OF_ORDERS;
 
				order.station = GetDepotByTile(tile)->index;
 
@@ -217,7 +217,7 @@ static Order GetOrderCmdFromTile(Vehicle
 
			if (IsAircraftHangarTile(tile) && IsTileOwner(tile, _local_player)) {
 
				order.type = OT_GOTO_DEPOT;
 
				order.flags = OF_PART_OF_ORDERS | OF_NON_STOP;	//XXX - whats the nonstop stuff doing here?
 
				order.station = _map2[tile];
 
				order.station = _m[tile].m2;
 
				return order;
 
			}
 
			break;
 
@@ -226,7 +226,7 @@ static Order GetOrderCmdFromTile(Vehicle
 
			if (v->type != VEH_Ship) break;
 
			if (IsTileDepotType(tile, TRANSPORT_WATER) &&
 
					IsTileOwner(tile, _local_player)) {
 
				switch (_map5[tile]) {
 
				switch (_m[tile].m5) {
 
					case 0x81: tile -= TileDiffXY(1, 0); break;
 
					case 0x83: tile -= TileDiffXY(0, 1); break;
 
				}
 
@@ -245,7 +245,7 @@ static Order GetOrderCmdFromTile(Vehicle
 
	if (IsTileType(tile, MP_RAILWAY) &&
 
			v->type == VEH_Train &&
 
			IsTileOwner(tile, _local_player) &&
 
			(_map5[tile] & 0xFE) == 0xC4) {
 
			(_m[tile].m5 & 0xFE) == 0xC4) {
 
		order.type = OT_GOTO_WAYPOINT;
 
		order.flags = 0;
 
		order.station = GetWaypointByTile(tile)->index;
 
@@ -253,7 +253,7 @@ static Order GetOrderCmdFromTile(Vehicle
 
	}
 

	
 
	if (IsTileType(tile, MP_STATION)) {
 
		st = GetStation(st_index = _map2[tile]);
 
		st = GetStation(st_index = _m[tile].m2);
 

	
 
		if (st->owner == _current_player || st->owner == OWNER_NONE) {
 
			byte facil;
pathfind.c
Show inline comments
 
@@ -142,7 +142,7 @@ static void TPFMode2(TrackPathFinder *tp
 
		if (IsTileType(tile, MP_RAILWAY) || IsTileType(tile, MP_STATION) || IsTileType(tile, MP_TUNNELBRIDGE)) {
 
			owner = GetTileOwner(tile);
 
			/* Check if we are on the middle of a bridge (has no owner) */
 
			if (IsTileType(tile, MP_TUNNELBRIDGE) && (_map5[tile] & 0xC0) == 0xC0)
 
			if (IsTileType(tile, MP_TUNNELBRIDGE) && (_m[tile].m5 & 0xC0) == 0xC0)
 
				owner = -1;
 
		}
 
	}
 
@@ -156,7 +156,7 @@ static void TPFMode2(TrackPathFinder *tp
 
	if (tpf->tracktype == TRANSPORT_RAIL) {
 
		if (IsTileType(tile, MP_RAILWAY) || IsTileType(tile, MP_STATION) || IsTileType(tile, MP_TUNNELBRIDGE))
 
			/* Check if we are on the middle of a bridge (has no owner) */
 
			if (!IsTileType(tile, MP_TUNNELBRIDGE) || (_map5[tile] & 0xC0) != 0xC0)
 
			if (!IsTileType(tile, MP_TUNNELBRIDGE) || (_m[tile].m5 & 0xC0) != 0xC0)
 
				if (owner != -1 && !IsTileOwner(tile, owner))
 
					return;
 
	}
 
@@ -240,9 +240,9 @@ FindLengthOfTunnelResult FindLengthOfTun
 
		tile = TileVirtXY(x, y);
 

	
 
		if (IsTileType(tile, MP_TUNNELBRIDGE) &&
 
				(_map5[tile] & 0xF0) == 0 &&					// tunnel entrance/exit
 
				//((_map5[tile]>>2)&3) == type &&		// rail/road-tunnel <-- This is not necesary to check, right?
 
				((_map5[tile] & 3)^2) == direction &&	// entrance towards: 0 = NE, 1 = SE, 2 = SW, 3 = NW
 
				(_m[tile].m5 & 0xF0) == 0 &&					// tunnel entrance/exit
 
				//((_m[tile].m5>>2)&3) == type &&		// rail/road-tunnel <-- This is not necesary to check, right?
 
				((_m[tile].m5 & 3)^2) == direction &&	// entrance towards: 0 = NE, 1 = SE, 2 = SW, 3 = NW
 
				GetSlopeZ(x+8, y+8) == z)
 
					break;
 
	}
 
@@ -290,8 +290,8 @@ static void TPFMode1(TrackPathFinder *tp
 
	RememberData rd;
 
	TileIndex tile_org = tile;
 

	
 
	if (IsTileType(tile, MP_TUNNELBRIDGE) && (_map5[tile] & 0xF0) == 0) {
 
		if ((_map5[tile] & 3) != direction || ((_map5[tile]>>2)&3) != tpf->tracktype)
 
	if (IsTileType(tile, MP_TUNNELBRIDGE) && (_m[tile].m5 & 0xF0) == 0) {
 
		if ((_m[tile].m5 & 3) != direction || ((_m[tile].m5>>2)&3) != tpf->tracktype)
 
			return;
 
		tile = SkipToEndOfTunnel(tpf, tile, direction);
 
	}
 
@@ -302,8 +302,8 @@ static void TPFMode1(TrackPathFinder *tp
 
		if (IsTileType(tile_org, MP_RAILWAY) || IsTileType(tile_org, MP_STATION) || IsTileType(tile_org, MP_TUNNELBRIDGE))
 
			if (IsTileType(tile, MP_RAILWAY) || IsTileType(tile, MP_STATION) || IsTileType(tile, MP_TUNNELBRIDGE))
 
				/* Check if we are on a bridge (middle parts don't have an owner */
 
				if (!IsTileType(tile, MP_TUNNELBRIDGE) || (_map5[tile] & 0xC0) != 0xC0)
 
					if (!IsTileType(tile_org, MP_TUNNELBRIDGE) || (_map5[tile_org] & 0xC0) != 0xC0)
 
				if (!IsTileType(tile, MP_TUNNELBRIDGE) || (_m[tile].m5 & 0xC0) != 0xC0)
 
					if (!IsTileType(tile_org, MP_TUNNELBRIDGE) || (_m[tile_org].m5 & 0xC0) != 0xC0)
 
						if (GetTileOwner(tile_org) != GetTileOwner(tile))
 
							return;
 
	}
 
@@ -651,11 +651,11 @@ static void NTPEnum(NewTrackPathFinder *
 
	si.state = 0;
 

	
 
restart:
 
	if (IsTileType(tile, MP_TUNNELBRIDGE) && (_map5[tile] & 0xF0) == 0) {
 
	if (IsTileType(tile, MP_TUNNELBRIDGE) && (_m[tile].m5 & 0xF0) == 0) {
 
		/* This is a tunnel tile */
 
		if ( (uint)(_map5[tile] & 3) != (direction ^ 2)) { /* ^ 2 is reversing the direction */
 
		if ( (uint)(_m[tile].m5 & 3) != (direction ^ 2)) { /* ^ 2 is reversing the direction */
 
			/* We are not just driving out of the tunnel */
 
			if ( (uint)(_map5[tile] & 3) != direction || ((_map5[tile]>>1)&6) != tpf->tracktype)
 
			if ( (uint)(_m[tile].m5 & 3) != direction || ((_m[tile].m5>>1)&6) != tpf->tracktype)
 
				/* We are not driving into the tunnel, or it
 
				 * is an invalid tunnel */
 
				goto stop_search;
 
@@ -689,7 +689,7 @@ restart:
 
		}
 

	
 
		// regular rail tile, determine the tracks that are actually reachable.
 
		bits = _map5[tile] & _bits_mask[direction];
 
		bits = _m[tile].m5 & _bits_mask[direction];
 
		if (bits == 0) goto stop_search; // no tracks there? stop searching.
 

	
 
		// intersection? then we need to branch the search space,
 
@@ -709,12 +709,12 @@ restart:
 
		if (HasSignals(tile)) {
 
			byte m3;
 

	
 
			m3 = _map3_lo[tile];
 
			m3 = _m[tile].m3;
 
			if (!(m3 & SignalAlongTrackdir(track))) {
 
				// if one way signal not pointing towards us, stop going in this direction.
 
				if (m3 & SignalAgainstTrackdir(track))
 
					goto stop_search;
 
			} else if (_map2[tile] & SignalAlongTrackdir(track)) {
 
			} else if (_m[tile].m2 & SignalAlongTrackdir(track)) {
 
				// green signal in our direction. either one way or two way.
 
				si.state |= 1;
 
			} else {
pbs.c
Show inline comments
 
@@ -50,32 +50,32 @@ void PBSReserveTrack(TileIndex tile, Tra
 
	assert(track <= 5);
 
	switch (GetTileType(tile)) {
 
		case MP_RAILWAY:
 
			if ((_map5[tile] & ~1) == 0xC4) {
 
			if ((_m[tile].m5 & ~1) == 0xC4) {
 
				// waypoint
 
				SETBIT(_map3_lo[tile], 6);
 
				SETBIT(_m[tile].m3, 6);
 
			} else {
 
				// normal rail track
 
				byte encrt = (_map3_hi[tile] & 0xF0) >> 4; // get current encoded info (see comments at top of file)
 
				byte encrt = (_m[tile].m4 & 0xF0) >> 4; // get current encoded info (see comments at top of file)
 

	
 
				if (encrt == 0) // nothing reserved before
 
					encrt = track + 1;
 
				else if (encrt == (track^1) + 1) // opposite track reserved before
 
					encrt |= 8;
 

	
 
				_map3_hi[tile] &= ~0xF0;
 
				_map3_hi[tile] |= encrt << 4;
 
				_m[tile].m4 &= ~0xF0;
 
				_m[tile].m4 |= encrt << 4;
 
			}
 
			break;
 
		case MP_TUNNELBRIDGE:
 
			_map3_hi[tile] |= (1 << track) & 3;
 
			_m[tile].m4 |= (1 << track) & 3;
 
			break;
 
		case MP_STATION:
 
			SETBIT(_map3_lo[tile], 6);
 
			SETBIT(_m[tile].m3, 6);
 
			break;
 
		case MP_STREET:
 
			// make sure it is a railroad crossing
 
			if (!IsLevelCrossing(tile)) return;
 
			SETBIT(_map5[tile], 0);
 
			SETBIT(_m[tile].m5, 0);
 
			break;
 
		default:
 
			return;
 
@@ -89,32 +89,32 @@ byte PBSTileReserved(TileIndex tile) {
 
	assert(IsValidTile(tile));
 
	switch (GetTileType(tile)) {
 
		case MP_RAILWAY:
 
			if ((_map5[tile] & ~1) == 0xC4) {
 
			if ((_m[tile].m5 & ~1) == 0xC4) {
 
				// waypoint
 
				// check if its reserved
 
				if (!HASBIT(_map3_lo[tile], 6)) return 0;
 
				if (!HASBIT(_m[tile].m3, 6)) return 0;
 
				// return the track for the correct direction
 
				return HASBIT(_map5[tile], 0) ? 2 : 1;
 
				return HASBIT(_m[tile].m5, 0) ? 2 : 1;
 
			} else {
 
				// normal track
 
				byte res = encrt_to_reserved[(_map3_hi[tile] & 0xF0) >> 4];
 
				byte res = encrt_to_reserved[(_m[tile].m4 & 0xF0) >> 4];
 
				assert(res != 0xFF);
 
				return res;
 
			};
 
		case MP_TUNNELBRIDGE:
 
			return (_map3_hi[tile] & 3);
 
			return (_m[tile].m4 & 3);
 
		case MP_STATION:
 
			// check if its reserved
 
			if (!HASBIT(_map3_lo[tile], 6)) return 0;
 
			if (!HASBIT(_m[tile].m3, 6)) return 0;
 
			// return the track for the correct direction
 
			return HASBIT(_map5[tile], 0) ? 2 : 1;
 
			return HASBIT(_m[tile].m5, 0) ? 2 : 1;
 
		case MP_STREET:
 
			// make sure its a railroad crossing
 
			if (!IsLevelCrossing(tile)) return 0;
 
			// check if its reserved
 
			if (!HASBIT(_map5[tile], 0)) return 0;
 
			if (!HASBIT(_m[tile].m5, 0)) return 0;
 
			// return the track for the correct direction
 
			return HASBIT(_map5[tile], 3) ? 1 : 2;
 
			return HASBIT(_m[tile].m5, 3) ? 1 : 2;
 
		default:
 
			return 0;
 
	};
 
@@ -124,24 +124,24 @@ uint16 PBSTileUnavail(TileIndex tile) {
 
	assert(IsValidTile(tile));
 
	switch (GetTileType(tile)) {
 
		case MP_RAILWAY:
 
			if ((_map5[tile] & ~1) == 0xC4) {
 
			if ((_m[tile].m5 & ~1) == 0xC4) {
 
				// waypoint
 
				return HASBIT(_map3_lo[tile], 6) ? TRACKDIR_BIT_MASK : 0;
 
				return HASBIT(_m[tile].m3, 6) ? TRACKDIR_BIT_MASK : 0;
 
			} else {
 
				// normal track
 
				uint16 res = encrt_to_unavail[(_map3_hi[tile] & 0xF0) >> 4];
 
				uint16 res = encrt_to_unavail[(_m[tile].m4 & 0xF0) >> 4];
 
				assert(res != 0xFFFF);
 
				return res;
 
			};
 
		case MP_TUNNELBRIDGE:
 
			return (_map3_hi[tile] & 3) | ((_map3_hi[tile] & 3) << 8);
 
			return (_m[tile].m4 & 3) | ((_m[tile].m4 & 3) << 8);
 
		case MP_STATION:
 
			return HASBIT(_map3_lo[tile], 6) ? TRACKDIR_BIT_MASK : 0;
 
			return HASBIT(_m[tile].m3, 6) ? TRACKDIR_BIT_MASK : 0;
 
		case MP_STREET:
 
			// make sure its a railroad crossing
 
			if (!IsLevelCrossing(tile)) return 0;
 
			// check if its reserved
 
			return (HASBIT(_map5[tile], 0)) ? TRACKDIR_BIT_MASK : 0;
 
			return (HASBIT(_m[tile].m5, 0)) ? TRACKDIR_BIT_MASK : 0;
 
		default:
 
			return 0;
 
	};
 
@@ -152,12 +152,12 @@ void PBSClearTrack(TileIndex tile, Track
 
	assert(track <= 5);
 
	switch (GetTileType(tile)) {
 
		case MP_RAILWAY:
 
			if ((_map5[tile] & ~1) == 0xC4) {
 
			if ((_m[tile].m5 & ~1) == 0xC4) {
 
				// waypoint
 
				CLRBIT(_map3_lo[tile], 6);
 
				CLRBIT(_m[tile].m3, 6);
 
			} else {
 
				// normal rail track
 
				byte encrt = (_map3_hi[tile] & 0xF0) >> 4;
 
				byte encrt = (_m[tile].m4 & 0xF0) >> 4;
 

	
 
				if (encrt == track + 1)
 
					encrt = 0;
 
@@ -166,20 +166,20 @@ void PBSClearTrack(TileIndex tile, Track
 
				else if (encrt == (track^1) + 1 + 8)
 
					encrt &= 7;
 

	
 
				_map3_hi[tile] &= ~0xF0;
 
				_map3_hi[tile] |= encrt << 4;
 
				_m[tile].m4 &= ~0xF0;
 
				_m[tile].m4 |= encrt << 4;
 
			}
 
			break;
 
		case MP_TUNNELBRIDGE:
 
			_map3_hi[tile] &= ~((1 << track) & 3);
 
			_m[tile].m4 &= ~((1 << track) & 3);
 
			break;
 
		case MP_STATION:
 
			CLRBIT(_map3_lo[tile], 6);
 
			CLRBIT(_m[tile].m3, 6);
 
			break;
 
		case MP_STREET:
 
			// make sure it is a railroad crossing
 
			if (!IsLevelCrossing(tile)) return;
 
			CLRBIT(_map5[tile], 0);
 
			CLRBIT(_m[tile].m5, 0);
 
			break;
 
		default:
 
			return;
 
@@ -197,7 +197,7 @@ void PBSClearPath(TileIndex tile, Trackd
 
	do {
 
		PBSClearTrack(tile, trackdir & 7);
 

	
 
		if (IsTileType(tile, MP_TUNNELBRIDGE) && (_map5[tile] & 0xF0)==0 && (unsigned)(_map5[tile] & 3) == TrackdirToExitdir(trackdir)) {
 
		if (IsTileType(tile, MP_TUNNELBRIDGE) && (_m[tile].m5 & 0xF0)==0 && (unsigned)(_m[tile].m5 & 3) == TrackdirToExitdir(trackdir)) {
 
			// this is a tunnel
 
			flotr = FindLengthOfTunnel(tile, TrackdirToExitdir(trackdir));
 

	
rail.c
Show inline comments
 
@@ -113,28 +113,28 @@ RailType GetTileRailType(TileIndex tile,
 
	switch (GetTileType(tile)) {
 
		case MP_RAILWAY:
 
			/* railway track */
 
			type = _map3_lo[tile] & RAILTYPE_MASK;
 
			type = _m[tile].m3 & RAILTYPE_MASK;
 
			break;
 
		case MP_STREET:
 
			/* rail/road crossing */
 
			if (IsLevelCrossing(tile))
 
				type = _map3_hi[tile] & RAILTYPE_MASK;
 
				type = _m[tile].m4 & RAILTYPE_MASK;
 
			break;
 
		case MP_STATION:
 
			if (IsTrainStationTile(tile))
 
				type = _map3_lo[tile] & RAILTYPE_MASK;
 
				type = _m[tile].m3 & RAILTYPE_MASK;
 
			break;
 
		case MP_TUNNELBRIDGE:
 
			/* railway tunnel */
 
			if ((_map5[tile] & 0xFC) == 0) type = _map3_lo[tile] & RAILTYPE_MASK;
 
			if ((_m[tile].m5 & 0xFC) == 0) type = _m[tile].m3 & RAILTYPE_MASK;
 
			/* railway bridge ending */
 
			if ((_map5[tile] & 0xC6) == 0x80) type = _map3_lo[tile] & RAILTYPE_MASK;
 
			if ((_m[tile].m5 & 0xC6) == 0x80) type = _m[tile].m3 & RAILTYPE_MASK;
 
			/* on railway bridge */
 
			if ((_map5[tile] & 0xC6) == 0xC0 && ((DiagDirection)(_map5[tile] & 0x1)) == (exitdir & 0x1))
 
				type = (_map3_lo[tile] >> 4) & RAILTYPE_MASK;
 
			if ((_m[tile].m5 & 0xC6) == 0xC0 && ((DiagDirection)(_m[tile].m5 & 0x1)) == (exitdir & 0x1))
 
				type = (_m[tile].m3 >> 4) & RAILTYPE_MASK;
 
			/* under bridge (any type) */
 
			if ((_map5[tile] & 0xC0) == 0xC0 && ((uint)_map5[tile] & 0x1) != (exitdir & 0x1))
 
				type = _map3_lo[tile] & RAILTYPE_MASK;
 
			if ((_m[tile].m5 & 0xC0) == 0xC0 && ((uint)_m[tile].m5 & 0x1) != (exitdir & 0x1))
 
				type = _m[tile].m3 & RAILTYPE_MASK;
 
			break;
 
		default:
 
			break;
rail.h
Show inline comments
 
@@ -38,7 +38,7 @@ typedef enum RailTileSubtypes {
 
} RailTileSubtype;
 

	
 
typedef enum SignalTypes {
 
	/* Stored in _map3_hi[0..1] for MP_RAILWAY */
 
	/* Stored in m4[0..1] for MP_RAILWAY */
 
  SIGTYPE_NORMAL  = 0,        // normal signal
 
  SIGTYPE_ENTRY   = 1,        // presignal block entry
 
  SIGTYPE_EXIT    = 2,        // presignal block exit
 
@@ -195,13 +195,13 @@ static inline byte SignalOnTrack(Track t
 
static inline RailTileType GetRailTileType(TileIndex tile)
 
{
 
	assert(IsTileType(tile, MP_RAILWAY));
 
	return (_map5[tile] & RAIL_TILE_TYPE_MASK);
 
	return (_m[tile].m5 & RAIL_TILE_TYPE_MASK);
 
}
 

	
 
/**
 
 * Returns the rail type of the given rail tile (ie rail, mono, maglev).
 
 */
 
static inline RailType GetRailType(TileIndex tile) { return (RailType)(_map3_lo[tile] & RAILTYPE_MASK); }
 
static inline RailType GetRailType(TileIndex tile) { return (RailType)(_m[tile].m3 & RAILTYPE_MASK); }
 

	
 
/**
 
 * Checks if a rail tile has signals.
 
@@ -218,7 +218,7 @@ static inline bool HasSignals(TileIndex 
 
static inline RailTileSubtype GetRailTileSubtype(TileIndex tile)
 
{
 
	assert(GetRailTileType(tile) == RAIL_TYPE_DEPOT_WAYPOINT);
 
	return (RailTileSubtype)(_map5[tile] & RAIL_SUBTYPE_MASK);
 
	return (RailTileSubtype)(_m[tile].m5 & RAIL_SUBTYPE_MASK);
 
}
 

	
 
/**
 
@@ -237,7 +237,7 @@ static inline bool IsPlainRailTile(TileI
 
static inline TrackBits GetTrackBits(TileIndex tile)
 
{
 
	assert(GetRailTileType(tile) == RAIL_TYPE_NORMAL || GetRailTileType(tile) == RAIL_TYPE_SIGNALS);
 
	return (TrackBits)(_map5[tile] & TRACK_BIT_MASK);
 
	return (TrackBits)(_m[tile].m5 & TRACK_BIT_MASK);
 
}
 

	
 
/**
 
@@ -399,7 +399,7 @@ static inline bool IsDiagonalTrackdir(Tr
 
static inline bool HasSignalOnTrack(TileIndex tile, Track track)
 
{
 
	assert(IsValidTrack(track));
 
	return ((GetRailTileType(tile) == RAIL_TYPE_SIGNALS) && ((_map3_lo[tile] & SignalOnTrack(track)) != 0));
 
	return ((GetRailTileType(tile) == RAIL_TYPE_SIGNALS) && ((_m[tile].m3 & SignalOnTrack(track)) != 0));
 
}
 

	
 
/**
 
@@ -412,7 +412,7 @@ static inline bool HasSignalOnTrack(Tile
 
static inline bool HasSignalOnTrackdir(TileIndex tile, Trackdir trackdir)
 
{
 
	assert (IsValidTrackdir(trackdir));
 
	return (GetRailTileType(tile) == RAIL_TYPE_SIGNALS) && (_map3_lo[tile] & SignalAlongTrackdir(trackdir));
 
	return (GetRailTileType(tile) == RAIL_TYPE_SIGNALS) && (_m[tile].m3 & SignalAlongTrackdir(trackdir));
 
}
 

	
 
/**
 
@@ -425,7 +425,7 @@ static inline SignalState GetSignalState
 
{
 
	assert(IsValidTrackdir(trackdir));
 
	assert(HasSignalOnTrack(tile, TrackdirToTrack(trackdir)));
 
	return ((_map2[tile] & SignalAlongTrackdir(trackdir))?SIGNAL_STATE_GREEN:SIGNAL_STATE_RED);
 
	return ((_m[tile].m2 & SignalAlongTrackdir(trackdir))?SIGNAL_STATE_GREEN:SIGNAL_STATE_RED);
 
}
 

	
 
/**
 
@@ -439,7 +439,7 @@ static inline SignalType GetSignalType(T
 
{
 
	assert(IsValidTrack(track));
 
	assert(GetRailTileType(tile) == RAIL_TYPE_SIGNALS);
 
	return (SignalType)(_map3_hi[tile] & SIGTYPE_MASK);
 
	return (SignalType)(_m[tile].m4 & SIGTYPE_MASK);
 
}
 

	
 
/**
 
@@ -454,7 +454,7 @@ static inline SignalType GetSignalType(T
 
static inline bool HasSemaphores(TileIndex tile, Track track)
 
{
 
	assert(IsValidTrack(track));
 
	return (_map3_hi[tile] & SIG_SEMAPHORE_MASK);
 
	return (_m[tile].m4 & SIG_SEMAPHORE_MASK);
 
}
 

	
 
/**
 
@@ -471,7 +471,7 @@ RailType GetTileRailType(TileIndex tile,
 
 */
 
static inline bool IsLevelCrossing(TileIndex tile)
 
{
 
	return (_map5[tile] & 0xF0) == 0x10;
 
	return (_m[tile].m5 & 0xF0) == 0x10;
 
}
 

	
 
/**
 
@@ -486,9 +486,9 @@ static inline TransportType GetCrossingT
 
	{
 
		/* When map5 bit 3 is set, the road runs in the y direction (DIAG2) */
 
		case TRACK_DIAG1:
 
			return (HASBIT(_map5[tile], 3) ? TRANSPORT_RAIL : TRANSPORT_ROAD);
 
			return (HASBIT(_m[tile].m5, 3) ? TRANSPORT_RAIL : TRANSPORT_ROAD);
 
		case TRACK_DIAG2:
 
			return (HASBIT(_map5[tile], 3) ? TRANSPORT_ROAD : TRANSPORT_RAIL);
 
			return (HASBIT(_m[tile].m5, 3) ? TRANSPORT_ROAD : TRANSPORT_RAIL);
 
		default:
 
			assert(0);
 
	}
rail_cmd.c
Show inline comments
 
@@ -269,7 +269,7 @@ int32 CmdBuildSingleRail(int x, int y, u
 

	
 
	tile = TileVirtXY(x, y);
 
	tileh = GetTileSlope(tile, NULL);
 
	m5 = _map5[tile];
 
	m5 = _m[tile].m5;
 
	trackbit = TrackToTrackBits(track);
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 
@@ -290,9 +290,9 @@ int32 CmdBuildSingleRail(int x, int y, u
 

	
 
					if (flags & DC_EXEC) {
 
						SetTileOwner(tile, _current_player);
 
						_map3_lo[tile] &= ~0x0F;
 
						_map3_lo[tile] |= p1;
 
						_map5[tile] = (m5 & 0xC7) | 0x20; // railroad under bridge
 
						_m[tile].m3 &= ~0x0F;
 
						_m[tile].m3 |= p1;
 
						_m[tile].m5 = (m5 & 0xC7) | 0x20; // railroad under bridge
 
					}
 
					break;
 

	
 
@@ -312,7 +312,7 @@ int32 CmdBuildSingleRail(int x, int y, u
 
			}
 
			if (m5 & RAIL_TYPE_SPECIAL ||
 
					!IsTileOwner(tile, _current_player) ||
 
					(_map3_lo[tile] & 0xFU) != p1) {
 
					(_m[tile].m3 & 0xFU) != p1) {
 
				// Get detailed error message
 
				return DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
			}
 
@@ -322,8 +322,8 @@ int32 CmdBuildSingleRail(int x, int y, u
 
			cost += ret;
 

	
 
			if (flags & DC_EXEC) {
 
				_map2[tile] &= ~RAIL_MAP2LO_GROUND_MASK; // Bare land
 
				_map5[tile] = m5 | trackbit;
 
				_m[tile].m2 &= ~RAIL_MAP2LO_GROUND_MASK; // Bare land
 
				_m[tile].m5 = m5 | trackbit;
 
			}
 
			break;
 

	
 
@@ -337,10 +337,10 @@ int32 CmdBuildSingleRail(int x, int y, u
 
						(track == TRACK_DIAG2 && m5 == 0x0A) // correct direction?
 
					)) {
 
				if (flags & DC_EXEC) {
 
					_map3_lo[tile] = GetTileOwner(tile);
 
					_m[tile].m3 = GetTileOwner(tile);
 
					SetTileOwner(tile, _current_player);
 
					_map3_hi[tile] = p1;
 
					_map5[tile] = 0x10 | (track == TRACK_DIAG1 ? 0x08 : 0x00); // level crossing
 
					_m[tile].m4 = p1;
 
					_m[tile].m5 = 0x10 | (track == TRACK_DIAG1 ? 0x08 : 0x00); // level crossing
 
				}
 
				break;
 
			}
 
@@ -361,9 +361,9 @@ int32 CmdBuildSingleRail(int x, int y, u
 
			if (flags & DC_EXEC) {
 
				SetTileType(tile, MP_RAILWAY);
 
				SetTileOwner(tile, _current_player);
 
				_map2[tile] = 0; // Bare land
 
				_map3_lo[tile] = p1; // No signals, rail type
 
				_map5[tile] = trackbit;
 
				_m[tile].m2 = 0; // Bare land
 
				_m[tile].m3 = p1; // No signals, rail type
 
				_m[tile].m5 = trackbit;
 
			}
 
			break;
 
	}
 
@@ -430,27 +430,27 @@ int32 CmdRemoveSingleRail(int x, int y, 
 
			if (!EnsureNoVehicleZ(tile, TilePixelHeight(tile)))
 
				return CMD_ERROR;
 

	
 
			if ((_map5[tile] & 0xF8) != 0xE0)
 
			if ((_m[tile].m5 & 0xF8) != 0xE0)
 
				return CMD_ERROR;
 

	
 
			if ( ((_map5[tile] & 1) ? 1 : 2) != trackbit )
 
			if ( ((_m[tile].m5 & 1) ? 1 : 2) != trackbit )
 
				return CMD_ERROR;
 

	
 
			if (!(flags & DC_EXEC))
 
				return _price.remove_rail;
 

	
 
		SetTileOwner(tile, OWNER_NONE);
 
			_map5[tile] = _map5[tile] & 0xC7;
 
			_m[tile].m5 = _m[tile].m5 & 0xC7;
 
			break;
 
		case MP_STREET:
 
			if (!(_map5[tile] & 0xF0))
 
			if (!(_m[tile].m5 & 0xF0))
 
				return CMD_ERROR;
 

	
 
			if (_map5[tile] & 0xE0)
 
			if (_m[tile].m5 & 0xE0)
 
				return CMD_ERROR;
 

	
 
			/* This is a crossing, let's check if the direction is correct */
 
			if (_map5[tile] & 8) {
 
			if (_m[tile].m5 & 8) {
 
				m5 = 5;
 
				if (track != TRACK_DIAG1)
 
					return CMD_ERROR;
 
@@ -463,9 +463,9 @@ int32 CmdRemoveSingleRail(int x, int y, 
 
			if (!(flags & DC_EXEC))
 
				return _price.remove_rail;
 

	
 
			_map5[tile] = m5;
 
			SetTileOwner(tile, _map3_lo[tile]);
 
			_map2[tile] = 0;
 
			_m[tile].m5 = m5;
 
			SetTileOwner(tile, _m[tile].m3);
 
			_m[tile].m2 = 0;
 
			break;
 
		case MP_RAILWAY:
 

	
 
@@ -484,7 +484,7 @@ int32 CmdRemoveSingleRail(int x, int y, 
 
				return cost;
 

	
 
			/* We remove the trackbit here. */
 
			_map5[tile] &= ~trackbit;
 
			_m[tile].m5 &= ~trackbit;
 

	
 
			if (GetTrackBits(tile)  == 0) {
 
				/* The tile has no tracks left, it is no longer a rail tile */
 
@@ -710,7 +710,7 @@ int32 CmdBuildSingleSignal(int x, int y,
 
	/* Protect against invalid signal copying */
 
	if (p2 != 0 && (p2 & SignalOnTrack(track)) == 0) return CMD_ERROR;
 

	
 
	m5 = _map5[tile];
 
	m5 = _m[tile].m5;
 

	
 
	/* You can only build signals on plain rail tiles, and the selected track must exist */
 
	if (!IsPlainRailTile(tile) || !HasTrack(tile, track)) return CMD_ERROR;
 
@@ -747,40 +747,40 @@ int32 CmdBuildSingleSignal(int x, int y,
 
	if (flags & DC_EXEC) {
 
		if (GetRailTileType(tile) != RAIL_TYPE_SIGNALS) {
 
			// there are no signals at all on this tile yet
 
			_map5[tile] |= RAIL_TYPE_SIGNALS; // change into signals
 
			_map2[tile] |= 0xF0;              // all signals are on
 
			_map3_lo[tile] &= ~0xF0;          // no signals built by default
 
			_map3_hi[tile] = semaphore ? 0x08 : 0;
 
			_m[tile].m5 |= RAIL_TYPE_SIGNALS; // change into signals
 
			_m[tile].m2 |= 0xF0;              // all signals are on
 
			_m[tile].m3 &= ~0xF0;          // no signals built by default
 
			_m[tile].m4 = semaphore ? 0x08 : 0;
 
		}
 

	
 
		if (p2 == 0) {
 
			if (!HasSignalOnTrack(tile, track)) {
 
				// build new signals
 
				_map3_lo[tile] |= SignalOnTrack(track);
 
				_m[tile].m3 |= SignalOnTrack(track);
 
			} else {
 
				if (pre_signal) {
 
					// cycle between normal -> pre -> exit -> combo -> pbs ->...
 
					byte type = ((GetSignalType(tile, track) + 1) % 5);
 
					_map3_hi[tile] &= ~0x07;
 
					_map3_hi[tile] |= type ;
 
					_m[tile].m4 &= ~0x07;
 
					_m[tile].m4 |= type ;
 
				} else {
 
					// cycle between two-way -> one-way -> one-way -> ...
 
					/* TODO: Rewrite switch into something more general */
 
					switch (track) {
 
						case TRACK_LOWER:
 
						case TRACK_RIGHT: {
 
							byte signal = (_map3_lo[tile] - 0x10) & 0x30;
 
							byte signal = (_m[tile].m3 - 0x10) & 0x30;
 
							if (signal == 0) signal = 0x30;
 
							_map3_lo[tile] &= ~0x30;
 
							_map3_lo[tile] |= signal;
 
							_m[tile].m3 &= ~0x30;
 
							_m[tile].m3 |= signal;
 
							break;
 
						}
 

	
 
						default: {
 
							byte signal = (_map3_lo[tile] - 0x40) & 0xC0;
 
							byte signal = (_m[tile].m3 - 0x40) & 0xC0;
 
							if (signal == 0) signal = 0xC0;
 
							_map3_lo[tile] &= ~0xC0;
 
							_map3_lo[tile] |= signal;
 
							_m[tile].m3 &= ~0xC0;
 
							_m[tile].m3 |= signal;
 
							break;
 
						}
 
					}
 
@@ -789,13 +789,13 @@ int32 CmdBuildSingleSignal(int x, int y,
 
		} else {
 
			/* If CmdBuildManySignals is called with copying signals, just copy the
 
			 * direction of the first signal given as parameter by CmdBuildManySignals */
 
			_map3_lo[tile] &= ~SignalOnTrack(track);
 
			_map3_lo[tile] |= p2 & SignalOnTrack(track);
 
			_m[tile].m3 &= ~SignalOnTrack(track);
 
			_m[tile].m3 |= p2 & SignalOnTrack(track);
 
			// convert between signal<->semaphores when dragging
 
			if (semaphore)
 
				SETBIT(_map3_hi[tile], 3);
 
				SETBIT(_m[tile].m4, 3);
 
			else
 
				CLRBIT(_map3_hi[tile], 3);
 
				CLRBIT(_m[tile].m4, 3);
 
		}
 

	
 
		MarkTileDirtyByTile(tile);
 
@@ -851,7 +851,7 @@ static int32 CmdSignalTrackHelper(int x,
 

	
 
	// copy the signal-style of the first rail-piece if existing
 
	if (GetRailTileType(tile) == RAIL_TYPE_SIGNALS && GetTrackBits(tile) != 0) { /* XXX: GetTrackBits check useless? */
 
		signals = _map3_lo[tile] & SignalOnTrack(track);
 
		signals = _m[tile].m3 & SignalOnTrack(track);
 
		if (signals == 0) signals = SignalOnTrack(track); /* Can this actually occur? */
 

	
 
		semaphores = (HasSemaphores(tile, track) ? 8 : 0); // copy signal/semaphores style (independent of CTRL)
 
@@ -926,13 +926,13 @@ int32 CmdRemoveSingleSignal(int x, int y
 

	
 
	/* Do it? */
 
	if (flags & DC_EXEC) {
 
		_map3_lo[tile] &= ~SignalOnTrack(track);
 
		_m[tile].m3 &= ~SignalOnTrack(track);
 

	
 
		/* removed last signal from tile? */
 
		if ((_map3_lo[tile] & 0xF0) == 0) {
 
			_map5[tile] &= ~RAIL_TYPE_SIGNALS;
 
			_map2[tile] &= ~0xF0;
 
			CLRBIT(_map3_hi[tile], 3); // remove any possible semaphores
 
		if ((_m[tile].m3 & 0xF0) == 0) {
 
			_m[tile].m5 &= ~RAIL_TYPE_SIGNALS;
 
			_m[tile].m2 &= ~0xF0;
 
			CLRBIT(_m[tile].m4, 3); // remove any possible semaphores
 
		}
 

	
 
		SetSignalsOnBothDir(tile, track);
 
@@ -965,7 +965,7 @@ static int32 DoConvertRail(TileIndex til
 

	
 
	// change type.
 
	if (exec) {
 
		_map3_lo[tile] = (_map3_lo[tile] & 0xF0) + totype;
 
		_m[tile].m3 = (_m[tile].m3 & 0xF0) + totype;
 
		MarkTileDirtyByTile(tile);
 
	}
 

	
 
@@ -1050,7 +1050,7 @@ static int32 ClearTile_Track(TileIndex t
 
	int32 ret;
 
	byte m5;
 

	
 
	m5 = _map5[tile];
 
	m5 = _m[tile].m5;
 

	
 
	if (flags & DC_AUTO) {
 
		if (m5 & RAIL_TYPE_SPECIAL)
 
@@ -1066,12 +1066,12 @@ static int32 ClearTile_Track(TileIndex t
 

	
 
	switch (GetRailTileType(tile)) {
 
		case RAIL_TYPE_SIGNALS:
 
			if (_map3_lo[tile] & _signals_table_both[0]) {
 
			if (_m[tile].m3 & _signals_table_both[0]) {
 
				ret = DoCommandByTile(tile, 0, 0, flags, CMD_REMOVE_SIGNALS);
 
				if (ret == CMD_ERROR) return CMD_ERROR;
 
				cost += ret;
 
			}
 
			if (_map3_lo[tile] & _signals_table_both[3]) {
 
			if (_m[tile].m3 & _signals_table_both[3]) {
 
				ret = DoCommandByTile(tile, 3, 0, flags, CMD_REMOVE_SIGNALS);
 
				if (ret == CMD_ERROR) return CMD_ERROR;
 
				cost += ret;
 
@@ -1184,7 +1184,7 @@ static void DrawSignalHelper(TileInfo *t
 
	uint v = _signal_position[(image_and_pos & 0xF) + (otherside ? 12 : 0)];
 
	uint x = ti->x | (v&0xF);
 
	uint y = ti->y | (v>>4);
 
	uint sprite = _signal_base_sprites[(_map3_hi[ti->tile] & 0xF) + (otherside ? 0x10 : 0)] + (image_and_pos>>4) + ((condition != 0) ? 1 : 0);
 
	uint sprite = _signal_base_sprites[(_m[ti->tile].m4 & 0xF) + (otherside ? 0x10 : 0)] + (image_and_pos>>4) + ((condition != 0) ? 1 : 0);
 
	AddSortableSpriteToDraw(sprite, x, y, 1, 1, 10, GetSlopeZ(x,y));
 
}
 

	
 
@@ -1419,7 +1419,7 @@ static void DrawTile_Track(TileInfo *ti)
 

	
 
	_drawtile_track_palette = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)));
 

	
 
	tracktype_offs = (_map3_lo[ti->tile] & 0xF) * TRACKTYPE_SPRITE_PITCH;
 
	tracktype_offs = (_m[ti->tile].m3 & 0xF) * TRACKTYPE_SPRITE_PITCH;
 

	
 
	m5 = (byte)ti->map5;
 
	if (!(m5 & RAIL_TYPE_SPECIAL)) {
 
@@ -1457,9 +1457,9 @@ static void DrawTile_Track(TileInfo *ti)
 
			if (ti->tileh != 0) image = _track_sloped_sprites[ti->tileh - 1] + TrackSet[TRACK_Y];
 
		}
 

	
 
		if ((_map2[ti->tile] & RAIL_MAP2LO_GROUND_MASK)==RAIL_GROUND_BROWN) {
 
		if ((_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK)==RAIL_GROUND_BROWN) {
 
			image = (image & 0xFFFF) | 0x3178000; // use a brown palette
 
		 } else if ((_map2[ti->tile] & RAIL_MAP2LO_GROUND_MASK)==RAIL_GROUND_ICE_DESERT) {
 
		 } else if ((_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK)==RAIL_GROUND_ICE_DESERT) {
 
			image += TrackSet[SNOW_OFFSET];
 
		}
 

	
 
@@ -1485,7 +1485,7 @@ static void DrawTile_Track(TileInfo *ti)
 
		}
 

	
 
		if (_display_opt & DO_FULL_DETAIL) {
 
			_detailed_track_proc[_map2[ti->tile] & RAIL_MAP2LO_GROUND_MASK](ti);
 
			_detailed_track_proc[_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK](ti);
 
		}
 

	
 
		/* draw signals also? */
 
@@ -1495,7 +1495,7 @@ static void DrawTile_Track(TileInfo *ti)
 
		{
 
			byte m23;
 

	
 
			m23 = (_map3_lo[ti->tile] >> 4) | (_map2[ti->tile] & 0xF0);
 
			m23 = (_m[ti->tile].m3 >> 4) | (_m[ti->tile].m2 & 0xF0);
 

	
 
#define HAS_SIGNAL(x) (m23 & (byte)(0x1 << (x)))
 
#define ISON_SIGNAL(x) (m23 & (byte)(0x10 << (x)))
 
@@ -1541,16 +1541,16 @@ static void DrawTile_Track(TileInfo *ti)
 

	
 
		if (ti->tileh != 0) { DrawFoundation(ti, ti->tileh); }
 

	
 
		if (IsRailWaypoint(m5) && _map3_lo[ti->tile] & 16) {
 
		if (IsRailWaypoint(m5) && _m[ti->tile].m3 & 16) {
 
			// look for customization
 
			StationSpec *stat = GetCustomStation(STAT_CLASS_WAYP, _map3_hi[ti->tile]);
 
			StationSpec *stat = GetCustomStation(STAT_CLASS_WAYP, _m[ti->tile].m4);
 

	
 
			if (stat) {
 
				DrawTileSeqStruct const *seq;
 
				// emulate station tile - open with building
 
				DrawTileSprites *cust = &stat->renderdata[2 + (m5 & 0x1)];
 
				uint32 relocation = GetCustomStationRelocation(stat, ComposeWaypointStation(ti->tile), 0);
 
				int railtype=(_map3_lo[ti->tile] & 0xF);
 
				int railtype=(_m[ti->tile].m3 & 0xF);
 

	
 
				/* We don't touch the 0x8000 bit. In all this
 
				 * waypoint code, it is used to indicate that
 
@@ -1583,7 +1583,7 @@ static void DrawTile_Track(TileInfo *ti)
 

	
 
		// adjust ground tile for desert
 
		// (don't adjust for arctic depots, because snow in depots looks weird)
 
		if ((_map2[ti->tile] & RAIL_MAP2LO_GROUND_MASK)==RAIL_GROUND_ICE_DESERT && (_opt.landscape == LT_DESERT || type>=4))
 
		if ((_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK)==RAIL_GROUND_ICE_DESERT && (_opt.landscape == LT_DESERT || type>=4))
 
		{
 
			if(image!=3981)
 
				image += 26; // tile with tracks
 
@@ -1673,7 +1673,7 @@ static bool SetSignalsEnumProc(TileIndex
 
	// the tile has signals?
 
	if (IsTileType(tile, MP_RAILWAY)) {
 
		if (HasSignalOnTrack(tile, TrackdirToTrack(track))) {
 
			if ((_map3_lo[tile] & _signals_table[track]) != 0) {
 
			if ((_m[tile].m3 & _signals_table[track]) != 0) {
 
				// yes, add the signal to the list of signals
 
				if (ssd->cur != NUM_SSD_ENTRY) {
 
					ssd->tile[ssd->cur] = tile; // remember the tile index
 
@@ -1685,7 +1685,7 @@ static bool SetSignalsEnumProc(TileIndex
 
				SETBIT(ssd->has_pbssignal, 2);
 

	
 
				// remember if this block has a presignal.
 
				ssd->has_presignal |= (_map3_hi[tile]&1);
 
				ssd->has_presignal |= (_m[tile].m4&1);
 
			}
 

	
 
			if (PBSIsPbsSignal(tile, ReverseTrackdir(track)) || PBSIsPbsSignal(tile, track)) {
 
@@ -1695,16 +1695,16 @@ static bool SetSignalsEnumProc(TileIndex
 
				ssd->has_pbssignal |= num;
 
			}
 

	
 
			if ((_map3_lo[tile] & _signals_table_both[track]) != 0) {
 
			if ((_m[tile].m3 & _signals_table_both[track]) != 0) {
 
				ssd->pbs_tile[ssd->pbs_cur] = tile; // remember the tile index
 
				ssd->pbs_cur++;
 
			}
 

	
 
			if (_map3_lo[tile]&_signals_table_other[track]) {
 
				if (_map3_hi[tile]&2) {
 
			if (_m[tile].m3&_signals_table_other[track]) {
 
				if (_m[tile].m4&2) {
 
					// this is an exit signal that points out from the segment
 
					ssd->presignal_exits++;
 
					if ((_map2[tile]&_signals_table_other[track]) != 0)
 
					if ((_m[tile].m2&_signals_table_other[track]) != 0)
 
						ssd->presignal_exits_free++;
 
				}
 
				if (PBSIsPbsSignal(tile, track))
 
@@ -1761,10 +1761,10 @@ bool SignalVehicleCheck(TileIndex tile, 
 
	 * is some kind of invisible black hole, and there is some special magic going
 
	 * on in there. This 'workaround' can be removed once the maprewrite is done.
 
	 */
 
	if (GetTileType(tile)==MP_TUNNELBRIDGE && ((_map5[tile] & 0xF0)==0)) {
 
	if (GetTileType(tile)==MP_TUNNELBRIDGE && ((_m[tile].m5 & 0xF0)==0)) {
 
		// It is a tunnel we're checking, we need to do some special stuff
 
		// because VehicleFromPos will not find the vihicle otherwise
 
		byte direction = _map5[tile] & 3;
 
		byte direction = _m[tile].m5 & 3;
 
		FindLengthOfTunnelResult flotr;
 
		flotr = FindLengthOfTunnel(tile, direction);
 
		dest.track = 1 << (direction & 1); // get the trackbit the vehicle would have if it has not entered the tunnel yet (ie is still visible)
 
@@ -1849,8 +1849,8 @@ static void ChangeSignalStates(SetSignal
 
	if (_patches.auto_pbs_placement && !(ssd->stop) && (ssd->has_pbssignal == 0xE) && !ssd->has_presignal && (ssd->presignal_exits == 0)) // 0xE means at least 2 pbs signals, and at least 1 entry and 1 exit, see comments ssd->has_pbssignal
 
	for(i=0; i!=ssd->pbs_cur; i++) {
 
		TileIndex tile = ssd->pbs_tile[i];
 
		_map3_hi[tile] &= ~0x07;
 
		_map3_hi[tile] |= 0x04;
 
		_m[tile].m4 &= ~0x07;
 
		_m[tile].m4 |= 0x04;
 
		MarkTileDirtyByTile(tile);
 
	};
 

	
 
@@ -1858,16 +1858,16 @@ static void ChangeSignalStates(SetSignal
 
	for(i=0; i!=ssd->cur; i++) {
 
		TileIndex tile = ssd->tile[i];
 
		byte bit = _signals_table[ssd->bit[i]];
 
		uint16 m2 = _map2[tile];
 
		uint16 m2 = _m[tile].m2;
 

	
 
		// presignals don't turn green if there is at least one presignal exit and none are free
 
		if (_map3_hi[tile] & 1) {
 
		if (_m[tile].m4 & 1) {
 
			int ex = ssd->presignal_exits, exfree = ssd->presignal_exits_free;
 

	
 
			// subtract for dual combo signals so they don't count themselves
 
			if (_map3_hi[tile]&2 && _map3_lo[tile]&_signals_table_other[ssd->bit[i]]) {
 
			if (_m[tile].m4&2 && _m[tile].m3&_signals_table_other[ssd->bit[i]]) {
 
				ex--;
 
				if ((_map2[tile]&_signals_table_other[ssd->bit[i]]) != 0) exfree--;
 
				if ((_m[tile].m2&_signals_table_other[ssd->bit[i]]) != 0) exfree--;
 
			}
 

	
 
			// if we have exits and none are free, make red.
 
@@ -1887,7 +1887,7 @@ make_red:
 
		}
 

	
 
		/* Update signals on the other side of this exit-combo signal; it changed. */
 
		if (_map3_hi[tile] & 2 ) {
 
		if (_m[tile].m4 & 2 ) {
 
			if (ssd->cur_stack != NUM_SSD_STACK) {
 
				ssd->next_tile[ssd->cur_stack] = tile;
 
				ssd->next_dir[ssd->cur_stack] = _dir_from_track[ssd->bit[i]];
 
@@ -1898,7 +1898,7 @@ make_red:
 
		}
 

	
 
		// it changed, so toggle it
 
		_map2[tile] = m2 ^ bit;
 
		_m[tile].m2 = m2 ^ bit;
 
		MarkTileDirtyByTile(tile);
 
	}
 
}
 
@@ -2010,7 +2010,7 @@ static void TileLoop_Track(TileIndex til
 
	uint16 m2;
 
	byte owner;
 

	
 
	m2 = _map2[tile] & 0xF;
 
	m2 = _m[tile].m2 & 0xF;
 

	
 
	/* special code for alps landscape */
 
	if (_opt.landscape == LT_HILLY) {
 
@@ -2030,14 +2030,14 @@ static void TileLoop_Track(TileIndex til
 
	}
 

	
 
	// Don't continue tile loop for depots
 
	if (_map5[tile] & RAIL_TYPE_SPECIAL)
 
	if (_m[tile].m5 & RAIL_TYPE_SPECIAL)
 
		return;
 

	
 
	a2 = RAIL_GROUND_GREEN;
 

	
 
	if (m2 != RAIL_GROUND_BROWN) { /* wait until bottom is green */
 
		/* determine direction of fence */
 
		rail = _map5[tile] & TRACK_BIT_MASK;
 
		rail = _m[tile].m5 & TRACK_BIT_MASK;
 

	
 
		if (rail == TRACK_BIT_UPPER) {
 
			a2 = RAIL_GROUND_FENCE_HORIZ1;
 
@@ -2053,28 +2053,28 @@ static void TileLoop_Track(TileIndex til
 
			if ( (!(rail&(TRACK_BIT_DIAG2|TRACK_BIT_UPPER|TRACK_BIT_LEFT)) && (rail&TRACK_BIT_DIAG1)) || rail==(TRACK_BIT_LOWER|TRACK_BIT_RIGHT)) {
 
				if (!IsTileType(tile + TileDiffXY(0, -1), MP_RAILWAY) ||
 
						!IsTileOwner(tile + TileDiffXY(0, -1), owner) ||
 
						(_map5[tile + TileDiffXY(0, -1)] == TRACK_BIT_UPPER || _map5[tile + TileDiffXY(0, -1)] == TRACK_BIT_LEFT))
 
						(_m[tile + TileDiffXY(0, -1)].m5 == TRACK_BIT_UPPER || _m[tile + TileDiffXY(0, -1)].m5 == TRACK_BIT_LEFT))
 
							a2 = RAIL_GROUND_FENCE_NW;
 
			}
 

	
 
			if ( (!(rail&(TRACK_BIT_DIAG2|TRACK_BIT_LOWER|TRACK_BIT_RIGHT)) && (rail&TRACK_BIT_DIAG1)) || rail==(TRACK_BIT_UPPER|TRACK_BIT_LEFT)) {
 
				if (!IsTileType(tile + TileDiffXY(0, 1), MP_RAILWAY) ||
 
						!IsTileOwner(tile + TileDiffXY(0, 1), owner) ||
 
						(_map5[tile + TileDiffXY(0, 1)] == TRACK_BIT_LOWER || _map5[tile + TileDiffXY(0, 1)] == TRACK_BIT_RIGHT))
 
						(_m[tile + TileDiffXY(0, 1)].m5 == TRACK_BIT_LOWER || _m[tile + TileDiffXY(0, 1)].m5 == TRACK_BIT_RIGHT))
 
							a2 = (a2 == RAIL_GROUND_FENCE_NW) ? RAIL_GROUND_FENCE_SENW : RAIL_GROUND_FENCE_SE;
 
			}
 

	
 
			if ( (!(rail&(TRACK_BIT_DIAG1|TRACK_BIT_UPPER|TRACK_BIT_RIGHT)) && (rail&TRACK_BIT_DIAG2)) || rail==(TRACK_BIT_LOWER|TRACK_BIT_LEFT)) {
 
				if (!IsTileType(tile + TileDiffXY(-1, 0), MP_RAILWAY) ||
 
						!IsTileOwner(tile + TileDiffXY(-1, 0), owner) ||
 
						(_map5[tile + TileDiffXY(-1, 0)] == TRACK_BIT_UPPER || _map5[tile + TileDiffXY(-1, 0)] == TRACK_BIT_RIGHT))
 
						(_m[tile + TileDiffXY(-1, 0)].m5 == TRACK_BIT_UPPER || _m[tile + TileDiffXY(-1, 0)].m5 == TRACK_BIT_RIGHT))
 
							a2 = RAIL_GROUND_FENCE_NE;
 
			}
 

	
 
			if ( (!(rail&(TRACK_BIT_DIAG1|TRACK_BIT_LOWER|TRACK_BIT_LEFT)) && (rail&TRACK_BIT_DIAG2)) || rail==(TRACK_BIT_UPPER|TRACK_BIT_RIGHT)) {
 
				if (!IsTileType(tile + TileDiffXY(1, 0), MP_RAILWAY) ||
 
						!IsTileOwner(tile + TileDiffXY(1, 0), owner) ||
 
						(_map5[tile + TileDiffXY(1, 0)] == TRACK_BIT_LOWER || _map5[tile + TileDiffXY(1, 0)] == TRACK_BIT_LEFT))
 
						(_m[tile + TileDiffXY(1, 0)].m5 == TRACK_BIT_LOWER || _m[tile + TileDiffXY(1, 0)].m5 == TRACK_BIT_LEFT))
 
							a2 = (a2 == RAIL_GROUND_FENCE_NE) ? RAIL_GROUND_FENCE_NESW : RAIL_GROUND_FENCE_SW;
 
			}
 
		}
 
@@ -2083,7 +2083,7 @@ static void TileLoop_Track(TileIndex til
 
modify_me:;
 
	/* tile changed? */
 
	if ( m2 != a2) {
 
		_map2[tile] = (_map2[tile] & ~RAIL_MAP2LO_GROUND_MASK) | a2;
 
		_m[tile].m2 = (_m[tile].m2 & ~RAIL_MAP2LO_GROUND_MASK) | a2;
 
		MarkTileDirtyByTile(tile);
 
	}
 
}
 
@@ -2098,7 +2098,7 @@ static uint32 GetTileTrackStatus_Track(T
 
	if (mode != TRANSPORT_RAIL)
 
		return 0;
 

	
 
	m5 = _map5[tile];
 
	m5 = _m[tile].m5;
 

	
 
	if (!(m5 & RAIL_TYPE_SPECIAL)) {
 
		ret = (m5 | (m5 << 8)) & 0x3F3F;
 
@@ -2109,8 +2109,8 @@ static uint32 GetTileTrackStatus_Track(T
 
		} else {
 
			/* has_signals */
 

	
 
			a = _map3_lo[tile];
 
			b = _map2[tile];
 
			a = _m[tile].m3;
 
			b = _m[tile].m2;
 

	
 
			b &= a;
 

	
 
@@ -2139,7 +2139,7 @@ static void ClickTile_Track(TileIndex ti
 
{
 
	if (IsTileDepotType(tile, TRANSPORT_RAIL))
 
		ShowTrainDepotWindow(tile);
 
	else if (IsRailWaypoint(_map5[tile]))
 
	else if (IsRailWaypoint(_m[tile].m5))
 
		ShowRenameWaypointWindow(GetWaypointByTile(tile));
 

	
 
}
 
@@ -2162,13 +2162,13 @@ static void GetTileDesc_Track(TileIndex 
 
				STR_NULL, STR_NULL
 
			};
 

	
 
			td->str = signal_type[_map3_hi[tile] & 0x7];
 
			td->str = signal_type[_m[tile].m4 & 0x7];
 
			break;
 
		}
 

	
 
		case RAIL_TYPE_DEPOT_WAYPOINT:
 
		default:
 
			td->str = ((_map5[tile] & RAIL_SUBTYPE_MASK) == RAIL_SUBTYPE_DEPOT) ?
 
			td->str = ((_m[tile].m5 & RAIL_SUBTYPE_MASK) == RAIL_SUBTYPE_DEPOT) ?
 
				STR_1023_RAILROAD_TRAIN_DEPOT : STR_LANDINFO_WAYPOINT;
 
			break;
 
	}
rail_gui.c
Show inline comments
 
@@ -79,7 +79,7 @@ static void PlaceRail_AutoRail(TileIndex
 

	
 
static void PlaceExtraDepotRail(TileIndex tile, uint16 extra)
 
{
 
	byte b = _map5[tile];
 
	byte b = _m[tile].m5;
 

	
 
	if (b & 0xC0 || !(b & (extra >> 8)))
 
		return;
road_cmd.c
Show inline comments
 
@@ -31,7 +31,7 @@ static bool HasTileRoadAt(TileIndex tile
 

	
 
	switch (GetTileType(tile)) {
 
	case MP_STREET:
 
		b = _map5[tile];
 
		b = _m[tile].m5;
 

	
 
		if ((b & 0xF0) == 0) {
 
		} else if (IsLevelCrossing(tile)) {
 
@@ -43,7 +43,7 @@ static bool HasTileRoadAt(TileIndex tile
 
		break;
 

	
 
	case MP_STATION:
 
		b = _map5[tile];
 
		b = _m[tile].m5;
 
		if (!IS_BYTE_INSIDE(b, 0x43, 0x43+8))
 
			return false;
 
		return ((~(b - 0x43) & 3) == i);
 
@@ -81,7 +81,7 @@ static bool CheckAllowRemoveRoad(TileInd
 

	
 
	// A railway crossing has the road owner in the map3_lo byte.
 
	if (IsTileType(tile, MP_STREET) && IsLevelCrossing(tile)) {
 
		owner = _map3_lo[tile];
 
		owner = _m[tile].m3;
 
	} else {
 
		owner = GetTileOwner(tile);
 
	}
 
@@ -157,7 +157,7 @@ int32 CmdRemoveRoad(int x, int y, uint32
 
	// owner for railraod crossing is stored somewhere else
 
	// XXX - Fix this so for a given tiletype the owner of the type is in the same variable
 
	if (IsTileType(tile, MP_STREET) && IsLevelCrossing(tile)) {
 
		owner = _map3_lo[tile];
 
		owner = _m[tile].m3;
 
	} else
 
		owner = GetTileOwner(tile);
 

	
 
@@ -165,7 +165,7 @@ int32 CmdRemoveRoad(int x, int y, uint32
 
		if (IsTileType(tile, MP_TUNNELBRIDGE)) { // index of town is not saved for bridge (no space)
 
			t = ClosestTownFromTile(tile, _patches.dist_local_authority);
 
		} else
 
			t = GetTown(_map2[tile]);
 
			t = GetTown(_m[tile].m2);
 
	} else
 
		t = NULL;
 

	
 
@@ -196,7 +196,7 @@ int32 CmdRemoveRoad(int x, int y, uint32
 

	
 
		if (flags & DC_EXEC) {
 
			ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM);
 
			_map5[tile] = ti.map5 & 0xC7;
 
			_m[tile].m5 = ti.map5 & 0xC7;
 
			SetTileOwner(tile, OWNER_NONE);
 
			MarkTileDirtyByTile(tile);
 
		}
 
@@ -228,8 +228,8 @@ int32 CmdRemoveRoad(int x, int y, uint32
 
			if (flags & DC_EXEC) {
 
				ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM);
 

	
 
				_map5[tile] ^= c;
 
				if ((_map5[tile]&0xF) == 0)
 
				_m[tile].m5 ^= c;
 
				if ((_m[tile].m5&0xF) == 0)
 
					DoClearSquare(tile);
 
				else
 
					MarkTileDirtyByTile(tile);
 
@@ -255,7 +255,7 @@ int32 CmdRemoveRoad(int x, int y, uint32
 
				ModifyTile(tile,
 
					MP_SETTYPE(MP_RAILWAY) |
 
					MP_MAP2_CLEAR | MP_MAP3LO | MP_MAP3HI_CLEAR | MP_MAP5,
 
					_map3_hi[tile] & 0xF, /* map3_lo */
 
					_m[tile].m4 & 0xF, /* map3_lo */
 
					c											/* map5 */
 
				);
 
				if (pbs_track != 0)
 
@@ -408,7 +408,7 @@ int32 CmdBuildRoad(int x, int y, uint32 
 
				MP_MAP2 | MP_MAP3LO | MP_MAP3HI | MP_MAP5,
 
				p2,
 
				_current_player, /* map3_lo */
 
				_map3_lo[tile] & 0xF, /* map3_hi */
 
				_m[tile].m3 & 0xF, /* map3_hi */
 
				m5 /* map5 */
 
			);
 
			if (pbs_track != 0)
 
@@ -476,12 +476,12 @@ do_clear:;
 
	if (flags & DC_EXEC) {
 
		if (ti.type != MP_STREET) {
 
			SetTileType(tile, MP_STREET);
 
			_map5[tile] = 0;
 
			_map2[tile] = p2;
 
			_m[tile].m5 = 0;
 
			_m[tile].m2 = p2;
 
			SetTileOwner(tile, _current_player);
 
		}
 

	
 
		_map5[tile] |= (byte)pieces;
 
		_m[tile].m5 |= (byte)pieces;
 

	
 
		MarkTileDirtyByTile(tile);
 
	}
 
@@ -497,11 +497,11 @@ int32 DoConvertStreetRail(TileIndex tile
 
	if (!CheckTileOwnership(tile) || !EnsureNoVehicle(tile)) return CMD_ERROR;
 

	
 
	// tile is already of requested type?
 
	if ( (uint)(_map3_hi[tile] & 0xF) == totype) return CMD_ERROR;
 
	if ( (uint)(_m[tile].m4 & 0xF) == totype) return CMD_ERROR;
 

	
 
	if (exec) {
 
		// change type.
 
		_map3_hi[tile] = (_map3_hi[tile] & 0xF0) + totype;
 
		_m[tile].m4 = (_m[tile].m4 & 0xF0) + totype;
 
		MarkTileDirtyByTile(tile);
 
	}
 

	
 
@@ -688,7 +688,7 @@ static int32 RemoveRoadDepot(TileIndex t
 
static int32 ClearTile_Road(TileIndex tile, byte flags)
 
{
 
	int32 ret;
 
	byte m5 = _map5[tile];
 
	byte m5 = _m[tile].m5;
 

	
 
	if ( (m5 & 0xF0) == 0) {
 
		byte b = m5 & 0xF;
 
@@ -783,11 +783,11 @@ static void DrawTile_Road(TileInfo *ti)
 
			image = _road_tile_sprites_1[ti->map5 & 0xF];
 
		}
 

	
 
		m2 = (_map3_hi[ti->tile] & 0x70) >> 4;
 
		m2 = (_m[ti->tile].m4 & 0x70) >> 4;
 

	
 
		if (m2 == 0) image |= 0x3178000;
 

	
 
		if (_map3_hi[ti->tile] & 0x80) {
 
		if (_m[ti->tile].m4 & 0x80) {
 
			image += 19;
 
		} else if (m2 > 1 && m2 != 6) {
 
			image -= 19; /* pavement along the road? */
 
@@ -826,15 +826,15 @@ static void DrawTile_Road(TileInfo *ti)
 
		if ( (ti->map5 & 4) != 0)
 
			image += 2;
 

	
 
		if ( _map3_hi[ti->tile] & 0x80) {
 
		if ( _m[ti->tile].m4 & 0x80) {
 
			image += 8;
 
		} else {
 
			m2 = (_map3_hi[ti->tile] & 0x70) >> 4;
 
			m2 = (_m[ti->tile].m4 & 0x70) >> 4;
 
			if (m2 == 0) image |= 0x3178000;
 
			if (m2 > 1) image += 4;
 
		}
 

	
 
		DrawGroundSprite(image + (_map3_hi[ti->tile] & 0xF) * 12);
 
		DrawGroundSprite(image + (_m[ti->tile].m4 & 0xF) * 12);
 

	
 
		if (_debug_pbs_level >= 1) {
 
			byte pbs = PBSTileReserved(ti->tile);
 
@@ -985,22 +985,22 @@ static void TileLoop_Road(TileIndex tile
 

	
 
	if (_opt.landscape == LT_HILLY) {
 
		// Fix snow style if the road is above the snowline
 
		if ((_map3_hi[tile] & 0x80) != ((GetTileZ(tile) > _opt.snow_line) ? 0x80 : 0x00)) {
 
			_map3_hi[tile] ^= 0x80;
 
		if ((_m[tile].m4 & 0x80) != ((GetTileZ(tile) > _opt.snow_line) ? 0x80 : 0x00)) {
 
			_m[tile].m4 ^= 0x80;
 
			MarkTileDirtyByTile(tile);
 
		}
 
	} else if (_opt.landscape == LT_DESERT) {
 
		// Fix desert style
 
		if (GetMapExtraBits(tile) == 1 && !(_map3_hi[tile] & 0x80)) {
 
			_map3_hi[tile] |= 0x80;
 
		if (GetMapExtraBits(tile) == 1 && !(_m[tile].m4 & 0x80)) {
 
			_m[tile].m4 |= 0x80;
 
			MarkTileDirtyByTile(tile);
 
		}
 
	}
 

	
 
	if (_map5[tile] & 0xE0)
 
	if (_m[tile].m5 & 0xE0)
 
		return;
 

	
 
	if (((_map3_hi[tile] & 0x70) >> 4) < 6) {
 
	if (((_m[tile].m4 & 0x70) >> 4) < 6) {
 
		t = ClosestTownFromTile(tile, (uint)-1);
 

	
 
		grp = 0;
 
@@ -1010,9 +1010,9 @@ static void TileLoop_Road(TileIndex tile
 
			// Show an animation to indicate road work
 
			if (t->road_build_months != 0 &&
 
					!(DistanceManhattan(t->xy, tile) >= 8 && grp == 0) &&
 
					(_map5[tile]==5 || _map5[tile]==10)) {
 
					(_m[tile].m5==5 || _m[tile].m5==10)) {
 
				if (GetTileSlope(tile, NULL) == 0 && EnsureNoVehicle(tile) && CHANCE16(1,20)) {
 
					_map3_hi[tile] |= ((((_map3_hi[tile] & 0x70) >> 4 ) <=  2) ? 7 : 6) << 4;
 
					_m[tile].m4 |= ((((_m[tile].m4 & 0x70) >> 4 ) <=  2) ? 7 : 6) << 4;
 

	
 
					SndPlayTileFx(SND_21_JACKHAMMER, tile);
 
					CreateEffectVehicleAbove(
 
@@ -1028,7 +1028,7 @@ static void TileLoop_Road(TileIndex tile
 

	
 
		{
 
			const byte *p = (_opt.landscape == LT_CANDY) ? _town_road_types_2[grp] : _town_road_types[grp];
 
			byte b = (_map3_hi[tile] & 0x70) >> 4;
 
			byte b = (_m[tile].m4 & 0x70) >> 4;
 

	
 
			if (b == p[0])
 
				return;
 
@@ -1040,23 +1040,23 @@ static void TileLoop_Road(TileIndex tile
 
			} else {
 
				b = 0;
 
			}
 
			_map3_hi[tile] = (_map3_hi[tile] & ~0x70) | (b << 4);
 
			_m[tile].m4 = (_m[tile].m4 & ~0x70) | (b << 4);
 
			MarkTileDirtyByTile(tile);
 
		}
 
	} else {
 
		// Handle road work
 
		//XXX undocumented
 

	
 
		byte b = _map3_hi[tile];
 
		byte b = _m[tile].m4;
 
		//roadworks take place only
 
		//keep roadworks running for 16 loops
 
		//lower 4 bits of map3_hi store the counter now
 
		if ((b & 0xF) != 0xF) {
 
			_map3_hi[tile] = b + 1;
 
			_m[tile].m4 = b + 1;
 
			return;
 
		}
 
		//roadworks finished
 
		_map3_hi[tile] = ((((b& 0x70) >> 4)== 6) ? 1 : 2) << 4;
 
		_m[tile].m4 = ((((b& 0x70) >> 4)== 6) ? 1 : 2) << 4;
 
		MarkTileDirtyByTile(tile);
 
	}
 
}
 
@@ -1065,7 +1065,7 @@ void ShowRoadDepotWindow(TileIndex tile)
 

	
 
static void ClickTile_Road(TileIndex tile)
 
{
 
	if ((_map5[tile] & 0xF0) == 0x20) {
 
	if ((_m[tile].m5 & 0xF0) == 0x20) {
 
		ShowRoadDepotWindow(tile);
 
	}
 
}
 
@@ -1079,12 +1079,12 @@ static uint32 GetTileTrackStatus_Road(Ti
 
	if (mode == TRANSPORT_RAIL) {
 
		if (!IsLevelCrossing(tile))
 
			return 0;
 
		return _map5[tile] & 8 ? 0x101 : 0x202;
 
		return _m[tile].m5 & 8 ? 0x101 : 0x202;
 
	} else if  (mode == TRANSPORT_ROAD) {
 
		byte b = _map5[tile];
 
		byte b = _m[tile].m5;
 
		if ((b & 0xF0) == 0) {
 
			/* Ordinary road */
 
			if (!_road_special_gettrackstatus && ((_map3_hi[tile]&0x70) >> 4) >= 6)
 
			if (!_road_special_gettrackstatus && ((_m[tile].m4&0x70) >> 4) >= 6)
 
				return 0;
 
			return _road_trackbits[b&0xF] * 0x101;
 
		} else if (IsLevelCrossing(tile)) {
 
@@ -1117,9 +1117,9 @@ static const StringID _road_tile_strings
 

	
 
static void GetTileDesc_Road(TileIndex tile, TileDesc *td)
 
{
 
	int i = (_map5[tile] >> 4);
 
	int i = (_m[tile].m5 >> 4);
 
	if (i == 0)
 
		i = ((_map3_hi[tile] & 0x70) >> 4) + 3;
 
		i = ((_m[tile].m4 & 0x70) >> 4) + 3;
 
	td->str = _road_tile_strings[i - 1];
 
	td->owner = GetTileOwner(tile);
 
}
 
@@ -1131,15 +1131,15 @@ static const byte _roadveh_enter_depot_u
 
static uint32 VehicleEnter_Road(Vehicle *v, TileIndex tile, int x, int y)
 
{
 
	if (IsLevelCrossing(tile)) {
 
		if (v->type == VEH_Train && (_map5[tile] & 4) == 0) {
 
		if (v->type == VEH_Train && (_m[tile].m5 & 4) == 0) {
 
			/* train crossing a road */
 
			SndPlayVehicleFx(SND_0E_LEVEL_CROSSING, v);
 
			_map5[tile] |= 4;
 
			_m[tile].m5 |= 4;
 
			MarkTileDirtyByTile(tile);
 
		}
 
	} else if ((_map5[tile]&0xF0) ==  0x20){
 
	} else if ((_m[tile].m5&0xF0) ==  0x20){
 
		if (v->type == VEH_Road && v->u.road.frame == 11) {
 
			if (_roadveh_enter_depot_unk0[_map5[tile]&3] == v->u.road.state) {
 
			if (_roadveh_enter_depot_unk0[_m[tile].m5&3] == v->u.road.state) {
 
				RoadVehEnterDepot(v);
 
				return 4;
 
			}
 
@@ -1152,7 +1152,7 @@ static void VehicleLeave_Road(Vehicle *v
 
{
 
	if (IsLevelCrossing(tile) && v->type == VEH_Train && v->next == NULL) {
 
		// Turn off level crossing lights
 
		_map5[tile] &= ~4;
 
		_m[tile].m5 &= ~4;
 
		MarkTileDirtyByTile(tile);
 
	}
 
}
 
@@ -1162,8 +1162,8 @@ static void ChangeTileOwner_Road(TileInd
 
	byte b;
 

	
 
	// road/rail crossing where the road is owned by the current player?
 
	if (old_player == _map3_lo[tile] && IsLevelCrossing(tile)) {
 
		_map3_lo[tile] = (new_player == 0xFF) ? OWNER_NONE : new_player;
 
	if (old_player == _m[tile].m3 && IsLevelCrossing(tile)) {
 
		_m[tile].m3 = (new_player == 0xFF) ? OWNER_NONE : new_player;
 
	}
 

	
 
	if (!IsTileOwner(tile, old_player)) return;
 
@@ -1171,14 +1171,14 @@ static void ChangeTileOwner_Road(TileInd
 
	if (new_player != 255) {
 
		SetTileOwner(tile, new_player);
 
	}	else {
 
		b = _map5[tile]&0xF0;
 
		b = _m[tile].m5&0xF0;
 
		if (b == 0) {
 
			SetTileOwner(tile, OWNER_NONE);
 
		} else if (IsLevelCrossing(tile)) {
 
			_map5[tile] = (_map5[tile]&8) ? 0x5 : 0xA;
 
			SetTileOwner(tile, _map3_lo[tile]);
 
			_map3_lo[tile] = 0;
 
			_map3_hi[tile] &= 0x80;
 
			_m[tile].m5 = (_m[tile].m5&8) ? 0x5 : 0xA;
 
			SetTileOwner(tile, _m[tile].m3);
 
			_m[tile].m3 = 0;
 
			_m[tile].m4 &= 0x80;
 
		} else {
 
			DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
 
		}
road_gui.c
Show inline comments
 
@@ -69,7 +69,7 @@ static void BuildRoadOutsideStation(Tile
 
	static const byte _roadbits_by_dir[4] = {2,1,8,4};
 
	tile += TileOffsByDir(direction);
 
	// if there is a roadpiece just outside of the station entrance, build a connecting route
 
	if (IsTileType(tile, MP_STREET) && !(_map5[tile] & 0x20)) {
 
	if (IsTileType(tile, MP_STREET) && !(_m[tile].m5 & 0x20)) {
 
		DoCommandP(tile, _roadbits_by_dir[direction], 0, NULL, CMD_BUILD_ROAD);
 
	}
 
}
roadveh_cmd.c
Show inline comments
 
@@ -281,7 +281,7 @@ static bool EnumRoadSignalFindDepot(Tile
 
	tile += TileOffsByDir(_road_pf_directions[track]);
 

	
 
	if (IsTileType(tile, MP_STREET) &&
 
			(_map5[tile] & 0xF0) == 0x20 &&
 
			(_m[tile].m5 & 0xF0) == 0x20 &&
 
			IsTileOwner(tile, rfdd->owner)) {
 

	
 
		if (length < rfdd->best_length) {
 
@@ -1029,14 +1029,14 @@ static int RoadFindPathToDest(Vehicle *v
 
	}
 

	
 
	if (IsTileType(tile, MP_STREET)) {
 
		if ((_map5[tile]&0xF0) == 0x20 && IsTileOwner(tile, v->owner))
 
		if ((_m[tile].m5&0xF0) == 0x20 && IsTileOwner(tile, v->owner))
 
			/* Road crossing */
 
			bitmask |= _road_veh_fp_ax_or[_map5[tile]&3];
 
			bitmask |= _road_veh_fp_ax_or[_m[tile].m5&3];
 
	} else if (IsTileType(tile, MP_STATION)) {
 
		if (IsTileOwner(tile, OWNER_NONE) || IsTileOwner(tile, v->owner)) {
 
			/* Our station */
 
			Station *st = GetStation(_map2[tile]);
 
			byte val = _map5[tile];
 
			Station *st = GetStation(_m[tile].m2);
 
			byte val = _m[tile].m5;
 
			if (v->cargo_type != CT_PASSENGERS) {
 
				if (IS_BYTE_INSIDE(val, 0x43, 0x47) && (_patches.roadveh_queue || st->truck_stops->status&3))
 
					bitmask |= _road_veh_fp_ax_or[(val-0x43)&3];
 
@@ -1101,12 +1101,12 @@ static int RoadFindPathToDest(Vehicle *v
 
		}
 
	} else {
 
		if (IsTileType(desttile, MP_STREET)) {
 
			m5 = _map5[desttile];
 
			m5 = _m[desttile].m5;
 
			if ((m5&0xF0) == 0x20)
 
				/* We are heading for a Depot */
 
				goto do_it;
 
		} else if (IsTileType(desttile, MP_STATION)) {
 
			m5 = _map5[desttile];
 
			m5 = _m[desttile].m5;
 
			if (IS_BYTE_INSIDE(m5, 0x43, 0x4B)) {
 
				/* We are heading for a station */
 
				m5 -= 0x43;
 
@@ -1230,7 +1230,7 @@ static void RoadVehController(Vehicle *v
 

	
 
		v->cur_speed = 0;
 

	
 
		dir = _map5[v->tile]&3;
 
		dir = _m[v->tile].m5&3;
 
		v->direction = dir*2+1;
 

	
 
		rd2 = _roadveh_data_2[dir];
 
@@ -1279,7 +1279,7 @@ static void RoadVehController(Vehicle *v
 
		}
 

	
 
		if (IsTileType(gp.new_tile, MP_TUNNELBRIDGE) &&
 
				(_map5[gp.new_tile]&0xF0) == 0 &&
 
				(_m[gp.new_tile].m5&0xF0) == 0 &&
 
				(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y)&4)) {
 

	
 
			//new_dir = RoadGetNewDirection(v, gp.x, gp.y)
 
@@ -1340,7 +1340,7 @@ again:
 

	
 
		if (IS_BYTE_INSIDE(v->u.road.state, 0x20, 0x30) && IsTileType(v->tile, MP_STATION)) {
 
			if ((tmp&7) >= 6) { v->cur_speed = 0; return; }
 
			if (IS_BYTE_INSIDE(_map5[v->tile], 0x43, 0x4B)) {
 
			if (IS_BYTE_INSIDE(_m[v->tile].m5, 0x43, 0x4B)) {
 
				RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile));
 
				byte *b = &rs->status;
 

	
 
@@ -1435,7 +1435,7 @@ again:
 
		RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile));
 
		byte *b = &rs->status;
 

	
 
		st = GetStation(_map2[v->tile]);
 
		st = GetStation(_m[v->tile].m2);
 

	
 
		if (v->current_order.type != OT_LEAVESTATION &&
 
				v->current_order.type != OT_GOTO_DEPOT) {
 
@@ -1443,7 +1443,7 @@ again:
 

	
 
			*b &= ~0x80;
 

	
 
			v->last_station_visited = _map2[v->tile];
 
			v->last_station_visited = _m[v->tile].m2;
 

	
 
			RoadVehArrivesAt(v, st);
 

	
ship_cmd.c
Show inline comments
 
@@ -249,7 +249,7 @@ static void ProcessShipOrder(Vehicle *v)
 

	
 
		st = GetStation(order->station);
 
		if (st->dock_tile != 0) {
 
			v->dest_tile = TILE_ADD(st->dock_tile, ToTileIndexDiff(_dock_offs[_map5[st->dock_tile]-0x4B]));
 
			v->dest_tile = TILE_ADD(st->dock_tile, ToTileIndexDiff(_dock_offs[_m[st->dock_tile].m5-0x4B]));
 
		}
 
	} else if (order->type == OT_GOTO_DEPOT) {
 
		v->dest_tile = GetDepot(order->station)->xy;
 
@@ -341,7 +341,7 @@ static void CheckShipLeaveDepot(Vehicle 
 
		return;
 

	
 
	tile = v->tile;
 
	d = (_map5[tile]&2) ? 1 : 0;
 
	d = (_m[tile].m5&2) ? 1 : 0;
 

	
 
	// Check first side
 
	if (_ship_sometracks[d] & GetTileShipTrackStatus(TILE_ADD(tile, ToTileIndexDiff(_ship_leave_depot_offs[d])))) {
smallmap_gui.c
Show inline comments
 
@@ -345,7 +345,7 @@ static inline TileType GetEffectiveTileT
 
	TileType t = GetTileType(tile);
 

	
 
	if (t == MP_TUNNELBRIDGE) {
 
		t = _map5[tile];
 
		t = _m[tile].m5;
 
		if ((t & 0x80) == 0) t >>= 1;
 
		if ((t & 6) == 0) {
 
			t = MP_RAILWAY;
 
@@ -421,7 +421,7 @@ static inline uint32 GetSmallMapIndustri
 
	TileType t = GetEffectiveTileType(tile);
 

	
 
	if (t == MP_INDUSTRY) {
 
		byte color = _industry_smallmap_colors[_map5[tile]];
 
		byte color = _industry_smallmap_colors[_m[tile].m5];
 
		return color + (color << 8) + (color << 16) + (color << 24);
 
	}
 

	
 
@@ -440,7 +440,7 @@ static inline uint32 GetSmallMapRoutesPi
 
	uint32 bits;
 

	
 
	if (t == MP_STATION) {
 
		byte m5 = _map5[tile];
 
		byte m5 = _m[tile].m5;
 
		(bits = MKCOLOR(0x56565656), m5 < 8) ||			//   8 - railroad station (green)
 
		(bits = MKCOLOR(0xB8B8B8B8), m5 < 0x43) ||	//  67 - airport (red)
 
		(bits = MKCOLOR(0xC2C2C2C2), m5 < 0x47) ||	//  71 - truck loading bay (orange)
 
@@ -479,17 +479,17 @@ static inline uint32 GetSmallMapVegetati
 

	
 
	switch (t) {
 
		case MP_CLEAR:
 
			i = (_map5[tile] & 0x1F) - 4;
 
			i = (_m[tile].m5 & 0x1F) - 4;
 
			if (i >= 0) i >>= 2;
 
			bits = _vegetation_clear_bits[i + 4];
 
			break;
 

	
 
		case MP_INDUSTRY:
 
			bits = IS_BYTE_INSIDE(_map5[tile], 0x10, 0x12) ? MKCOLOR(0xD0D0D0D0) : MKCOLOR(0xB5B5B5B5);
 
			bits = IS_BYTE_INSIDE(_m[tile].m5, 0x10, 0x12) ? MKCOLOR(0xD0D0D0D0) : MKCOLOR(0xB5B5B5B5);
 
			break;
 

	
 
		case MP_TREES:
 
			if ((_map2[tile] & 0x30) == 0x20)
 
			if ((_m[tile].m2 & 0x30) == 0x20)
 
				bits = (_opt.landscape == LT_HILLY) ? MKCOLOR(0x98575798) : MKCOLOR(0xC25757C2);
 
			else
 
				bits = MKCOLOR(0x54575754);
station.h
Show inline comments
 
@@ -270,7 +270,7 @@ int GetCustomStationsCount(StationClass 
 
RoadStop * GetRoadStopByTile(TileIndex tile, RoadStopType type);
 
static inline int GetRoadStopType(TileIndex tile)
 
{
 
	return (_map5[tile] < 0x47) ? RS_TRUCK : RS_BUS;
 
	return (_m[tile].m5 < 0x47) ? RS_TRUCK : RS_BUS;
 
}
 

	
 
uint GetNumRoadStops(const Station *st, RoadStopType type);
 
@@ -280,7 +280,7 @@ void ClearSlot(Vehicle *v, RoadStop *rs)
 

	
 
static inline bool IsTrainStationTile(TileIndex tile)
 
{
 
	return IsTileType(tile, MP_STATION) && IS_BYTE_INSIDE(_map5[tile], 0, 8);
 
	return IsTileType(tile, MP_STATION) && IS_BYTE_INSIDE(_m[tile].m5, 0, 8);
 
}
 

	
 
static inline bool IsCompatibleTrainStationTile(TileIndex tile, TileIndex ref)
 
@@ -288,12 +288,12 @@ static inline bool IsCompatibleTrainStat
 
	assert(IsTrainStationTile(ref));
 
	return
 
		IsTrainStationTile(tile) &&
 
		(_map3_lo[tile] & 0x0F) == (_map3_lo[ref] & 0x0F) && // same rail type?
 
		(_map5[tile] & 0x01) == (_map5[ref] & 0x01); // same direction?
 
		(_m[tile].m3 & 0x0F) == (_m[ref].m3 & 0x0F) && // same rail type?
 
		(_m[tile].m5 & 0x01) == (_m[ref].m5 & 0x01); // same direction?
 
}
 

	
 
static inline bool IsRoadStationTile(TileIndex tile) {
 
	return IsTileType(tile, MP_STATION) && IS_BYTE_INSIDE(_map5[tile], 0x43, 0x4B);
 
	return IsTileType(tile, MP_STATION) && IS_BYTE_INSIDE(_m[tile].m5, 0x43, 0x4B);
 
}
 

	
 
/**
 
@@ -310,7 +310,7 @@ static inline bool IsBuoy(const Station*
 
}
 

	
 
static inline bool IsBuoyTile(TileIndex tile) {
 
	return IsTileType(tile, MP_STATION) && _map5[tile] == 0x52;
 
	return IsTileType(tile, MP_STATION) && _m[tile].m5 == 0x52;
 
}
 

	
 
/* Get's the direction the station exit points towards. Ie, returns 0 for a
 
@@ -318,7 +318,7 @@ static inline bool IsBuoyTile(TileIndex 
 
static inline byte GetRoadStationDir(TileIndex tile)
 
{
 
	assert(IsRoadStationTile(tile));
 
	return (_map5[tile] - 0x43) & 3;
 
	return (_m[tile].m5 - 0x43) & 3;
 
}
 

	
 
#endif /* STATION_H */
station_cmd.c
Show inline comments
 
@@ -104,7 +104,7 @@ RoadStop * GetPrimaryRoadStop(const Stat
 

	
 
RoadStop * GetRoadStopByTile(TileIndex tile, RoadStopType type)
 
{
 
	const Station *st = GetStation(_map2[tile]);
 
	const Station *st = GetStation(_m[tile].m2);
 
	RoadStop *rs;
 

	
 
	for ( rs = GetPrimaryRoadStop(st, type); rs->xy != tile; rs = rs->next)
 
@@ -179,7 +179,7 @@ static Station *GetStationAround(TileInd
 
	BEGIN_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TileDiffXY(1, 1))
 
		if (IsTileType(tile_cur, MP_STATION)) {
 
			int t;
 
			t = _map2[tile_cur];
 
			t = _m[tile_cur].m2;
 
			{
 
				Station *st = GetStation(t);
 
				// you cannot take control of an oilrig!!
 
@@ -233,7 +233,7 @@ static bool CheckStationSpreadOut(Statio
 
	uint t;
 

	
 
	for (i = 0; i != MapSize(); i++) {
 
		if (IsTileType(i, MP_STATION) && _map2[i] == station_index) {
 
		if (IsTileType(i, MP_STATION) && _m[i].m2 == station_index) {
 
			t = TileX(i);
 
			if (t < x1) x1 = t;
 
			if (t > x2) x2 = t;
 
@@ -293,7 +293,7 @@ static int CountMapSquareAround(TileInde
 
	for (p = _count_square_table; p != endof(_count_square_table); ++p) {
 
		tile = TILE_MASK(tile + ToTileIndexDiff(*p));
 

	
 
		if (IsTileType(tile, type) && _map5[tile] >= min && _map5[tile] <= max)
 
		if (IsTileType(tile, type) && _m[tile].m5 >= min && _m[tile].m5 <= max)
 
			num++;
 
	}
 

	
 
@@ -797,11 +797,11 @@ int32 CheckFlatLandBelow(TileIndex tile,
 
		// so station points to -1 if we can build on any station. or it points to a station if we're only allowed to build
 
		// on exactly that station.
 
		if (station != NULL && IsTileType(tile_cur, MP_STATION)) {
 
			if (_map5[tile_cur] >= 8) {
 
			if (_m[tile_cur].m5 >= 8) {
 
				_error_message = ClearTile_Station(tile_cur, DC_AUTO); // get error message
 
				return CMD_ERROR;
 
			} else {
 
				int st = _map2[tile_cur];
 
				int st = _m[tile_cur].m2;
 
				if (*station == -1)
 
					*station = st;
 
				else if (*station != st) {
 
@@ -835,7 +835,7 @@ static bool CanExpandRailroadStation(Sta
 
		tile = TileXY(x, y);
 
	} else {
 
		// check so the direction is the same
 
		if ((_map5[st->train_tile] & 1) != direction) {
 
		if ((_m[st->train_tile].m5 & 1) != direction) {
 
			_error_message = STR_306D_NONUNIFORM_STATIONS_DISALLOWED;
 
			return false;
 
		}
 
@@ -1076,7 +1076,7 @@ int32 CmdBuildRailroadStation(int x, int
 

	
 
static bool TileBelongsToRailStation(Station *st, TileIndex tile)
 
{
 
	return IsTileType(tile, MP_STATION) && _map2[tile] == st->index && _map5[tile] < 8;
 
	return IsTileType(tile, MP_STATION) && _m[tile].m2 == st->index && _m[tile].m5 < 8;
 
}
 

	
 
static void MakeRailwayStationAreaSmaller(Station *st)
 
@@ -1150,8 +1150,8 @@ int32 CmdRemoveFromRailroadStation(int x
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	// make sure the specified tile belongs to the current player, and that it is a railroad station.
 
	if (!IsTileType(tile, MP_STATION) || _map5[tile] >= 8 || !_patches.nonuniform_stations) return CMD_ERROR;
 
	st = GetStation(_map2[tile]);
 
	if (!IsTileType(tile, MP_STATION) || _m[tile].m5 >= 8 || !_patches.nonuniform_stations) return CMD_ERROR;
 
	st = GetStation(_m[tile].m2);
 
	if (_current_player != OWNER_WATER && (!CheckOwnership(st->owner) || !EnsureNoVehicle(tile))) return CMD_ERROR;
 

	
 
	// if we reached here, it means we can actually delete it. do that.
 
@@ -1180,16 +1180,16 @@ uint GetStationPlatforms(Station *st, Ti
 
	assert(TileBelongsToRailStation(st, tile));
 

	
 
	len = 0;
 
	dir = _map5[tile]&1;
 
	dir = _m[tile].m5&1;
 
	delta = dir ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
 

	
 
	// find starting tile..
 
	t = tile;
 
	do { t -= delta; len++; } while (TileBelongsToRailStation(st, t) && (_map5[t]&1) == dir);
 
	do { t -= delta; len++; } while (TileBelongsToRailStation(st, t) && (_m[t].m5&1) == dir);
 

	
 
	// find ending tile
 
	t = tile;
 
	do { t += delta; len++; }while (TileBelongsToRailStation(st, t) && (_map5[t]&1) == dir);
 
	do { t += delta; len++; }while (TileBelongsToRailStation(st, t) && (_m[t].m5&1) == dir);
 

	
 
	return len - 1;
 
}
 
@@ -1411,18 +1411,18 @@ static int32 RemoveRailroadStation(Stati
 

	
 
int32 DoConvertStationRail(TileIndex tile, uint totype, bool exec)
 
{
 
	const Station *st = GetStation(_map2[tile]);
 
	const Station *st = GetStation(_m[tile].m2);
 
	if (!CheckOwnership(st->owner) || !EnsureNoVehicle(tile)) return CMD_ERROR;
 

	
 
	// tile is not a railroad station?
 
	if (_map5[tile] >= 8) return CMD_ERROR;
 
	if (_m[tile].m5 >= 8) return CMD_ERROR;
 

	
 
	// tile is already of requested type?
 
	if ( (uint)(_map3_lo[tile] & 0xF) == totype) return CMD_ERROR;
 
	if ( (uint)(_m[tile].m3 & 0xF) == totype) return CMD_ERROR;
 

	
 
	if (exec) {
 
		// change type.
 
		_map3_lo[tile] = (_map3_lo[tile] & 0xF0) + totype;
 
		_m[tile].m3 = (_m[tile].m3 & 0xF0) + totype;
 
		MarkTileDirtyByTile(tile);
 
	}
 

	
 
@@ -1547,7 +1547,7 @@ int32 CmdBuildRoadStop(int x, int y, uin
 
			MP_SETTYPE(MP_STATION) | MP_MAPOWNER_CURRENT |
 
			MP_MAP2 | MP_MAP5 | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR,
 
			st->index,                       /* map2 parameter */
 
			/* XXX - Truck stops have 0x43 _map5[] value + direction
 
			/* XXX - Truck stops have 0x43 _m[].m5 value + direction
 
			 * XXX - Bus stops have a _map5 value of 0x47 + direction */
 
			((type) ? 0x43 : 0x47) + p1 /* map5 parameter */
 
		);
 
@@ -1564,7 +1564,7 @@ static int32 RemoveRoadStop(Station *st,
 
{
 
	RoadStop **primary_stop;
 
	RoadStop *cur_stop;
 
	bool is_truck = _map5[tile] < 0x47;
 
	bool is_truck = _m[tile].m5 < 0x47;
 

	
 
	if (_current_player != OWNER_WATER && !CheckOwnership(st->owner))
 
		return CMD_ERROR;
 
@@ -2085,7 +2085,7 @@ static int32 RemoveDock(Station *st, uin
 
		return CMD_ERROR;
 

	
 
	tile1 = st->dock_tile;
 
	tile2 = tile1 + TileOffsByDir(_map5[tile1] - 0x4C);
 
	tile2 = tile1 + TileOffsByDir(_m[tile1].m5 - 0x4C);
 

	
 
	if (!EnsureNoVehicle(tile1))
 
		return CMD_ERROR;
 
@@ -2120,7 +2120,7 @@ static void DrawTile_Station(TileInfo *t
 
	uint32 image;
 
	const DrawTileSeqStruct *dtss;
 
	const DrawTileSprites *t = NULL;
 
	byte railtype = _map3_lo[ti->tile] & 0xF;
 
	byte railtype = _m[ti->tile].m3 & 0xF;
 
	int type_offset;
 
	uint32 relocation = 0;
 

	
 
@@ -2135,14 +2135,14 @@ static void DrawTile_Station(TileInfo *t
 
	if (ti->tileh != 0 && (ti->map5 < 0x4C || ti->map5 > 0x51))
 
		DrawFoundation(ti, ti->tileh);
 

	
 
	if (_map3_lo[ti->tile] & 0x10) {
 
	if (_m[ti->tile].m3 & 0x10) {
 
		// look for customization
 
		StationSpec *statspec = GetCustomStation(STAT_CLASS_DFLT, _map3_hi[ti->tile]);
 
		StationSpec *statspec = GetCustomStation(STAT_CLASS_DFLT, _m[ti->tile].m4);
 

	
 
		//debug("Cust-o-mized %p", statspec);
 

	
 
		if (statspec != NULL) {
 
			Station *st = GetStation(_map2[ti->tile]);
 
			Station *st = GetStation(_m[ti->tile].m2);
 

	
 
			relocation = GetCustomStationRelocation(statspec, st, 0);
 
			//debug("Relocation %d", relocation);
 
@@ -2239,9 +2239,9 @@ static void GetTileDesc_Station(TileInde
 
	StringID str;
 

	
 
	td->owner = GetTileOwner(tile);
 
	td->build_date = GetStation(_map2[tile])->build_date;
 

	
 
	m5 = _map5[tile];
 
	td->build_date = GetStation(_m[tile].m2)->build_date;
 

	
 
	m5 = _m[tile].m5;
 
	(str=STR_305E_RAILROAD_STATION, m5 < 8) ||
 
	(str=STR_305F_AIRCRAFT_HANGAR, m5==32 || m5==45) || // hangars
 
	(str=STR_3060_AIRPORT, m5 < 0x43 || (m5 >= 83 && m5 <= 114)) ||
 
@@ -2256,7 +2256,7 @@ static void GetTileDesc_Station(TileInde
 

	
 
static uint32 GetTileTrackStatus_Station(TileIndex tile, TransportType mode)
 
{
 
	uint i = _map5[tile];
 
	uint i = _m[tile].m5;
 
	uint j = 0;
 

	
 
	switch (mode) {
 
@@ -2290,15 +2290,15 @@ static void TileLoop_Station(TileIndex t
 
  // 0x66 - radar metropolitan airport (102)
 
  // 0x5A - radar international airport (90)
 
  // 0x3A - flag small airport (58)
 
	if (_map5[tile] == 39 || _map5[tile] == 58 || _map5[tile] == 90 || _map5[tile] == 102)
 
	if (_m[tile].m5 == 39 || _m[tile].m5 == 58 || _m[tile].m5 == 90 || _m[tile].m5 == 102)
 
		AddAnimatedTile(tile);
 

	
 
	// treat a bouy tile as water.
 
	else if (_map5[tile] == 0x52)
 
	else if (_m[tile].m5 == 0x52)
 
		TileLoop_Water(tile);
 

	
 
	// treat a oilrig (the station part) as water
 
	else if (_map5[tile] == 0x4B)
 
	else if (_m[tile].m5 == 0x4B)
 
		TileLoop_Water(tile);
 

	
 
}
 
@@ -2306,7 +2306,7 @@ static void TileLoop_Station(TileIndex t
 

	
 
static void AnimateTile_Station(TileIndex tile)
 
{
 
	byte m5 = _map5[tile];
 
	byte m5 = _m[tile].m5;
 
	//FIXME -- AnimateTile_Station -> not nice code, lots of things double
 
  // again hardcoded...was a quick hack
 

	
 
@@ -2318,7 +2318,7 @@ static void AnimateTile_Station(TileInde
 
		if (++m5 == 50+1)
 
			m5 = 39;
 

	
 
		_map5[tile] = m5;
 
		_m[tile].m5 = m5;
 
		MarkTileDirtyByTile(tile);
 
  //added - begin
 
	} else if (m5 >= 90 && m5 <= 113) { // turning radar with ground under it (different fences) (90 - 101 | 102 - 113)
 
@@ -2330,7 +2330,7 @@ static void AnimateTile_Station(TileInde
 
		if (m5 == 101+1) {m5 = 90;}  // radar with fences in south
 
		else if (m5 == 113+1) {m5 = 102;} // radar with fences in north
 

	
 
		_map5[tile] = m5;
 
		_m[tile].m5 = m5;
 
		MarkTileDirtyByTile(tile);
 
	//added - end
 
	} else if (m5 >= 0x3A && m5 <= 0x3D) {  // windsack (58 - 61)
 
@@ -2340,7 +2340,7 @@ static void AnimateTile_Station(TileInde
 
		if (++m5 == 0x3D+1)
 
			m5 = 0x3A;
 

	
 
		_map5[tile] = m5;
 
		_m[tile].m5 = m5;
 
		MarkTileDirtyByTile(tile);
 
	}
 
}
 
@@ -2349,10 +2349,10 @@ static void ClickTile_Station(TileIndex 
 
{
 
  // 0x20 - hangar large airport (32)
 
  // 0x41 - hangar small airport (65)
 
	if (_map5[tile] == 32 || _map5[tile] == 65) {
 
	if (_m[tile].m5 == 32 || _m[tile].m5 == 65) {
 
		ShowAircraftDepotWindow(tile);
 
	} else {
 
		ShowStationViewWindow(_map2[tile]);
 
		ShowStationViewWindow(_m[tile].m2);
 
	}
 
}
 

	
 
@@ -2367,10 +2367,10 @@ static uint32 VehicleEnter_Station(Vehic
 
	uint16 spd;
 

	
 
	if (v->type == VEH_Train) {
 
		if (IS_BYTE_INSIDE(_map5[tile], 0, 8) && v->subtype == TS_Front_Engine &&
 
		if (IS_BYTE_INSIDE(_m[tile].m5, 0, 8) && v->subtype == TS_Front_Engine &&
 
				!IsCompatibleTrainStationTile(tile + TileOffsByDir(v->direction >> 1), tile)) {
 

	
 
			station_id = _map2[tile];
 
			station_id = _m[tile].m2;
 
			if ((!(v->current_order.flags & OF_NON_STOP) && !_patches.new_nonstop) ||
 
					(v->current_order.type == OT_GOTO_STATION && v->current_order.station == station_id)) {
 

	
 
@@ -2399,7 +2399,7 @@ static uint32 VehicleEnter_Station(Vehic
 
		}
 
	} else if (v->type == VEH_Road) {
 
		if (v->u.road.state < 16 && (v->u.road.state&4)==0 && v->u.road.frame==0) {
 
			byte m5 = _map5[tile];
 
			byte m5 = _m[tile].m5;
 
			byte *b, bb,state;
 

	
 
			if (IS_BYTE_INSIDE(m5, 0x43, 0x4B)) {
 
@@ -2747,7 +2747,7 @@ uint MoveGoodsToStation(TileIndex tile, 
 
	BEGIN_TILE_LOOP(cur_tile, w, h, tile - TileDiffXY(max_rad, max_rad))
 
		cur_tile = TILE_MASK(cur_tile);
 
		if (IsTileType(cur_tile, MP_STATION)) {
 
			st_index = _map2[cur_tile];
 
			st_index = _m[cur_tile].m2;
 
			for(i=0; i!=8; i++)	{
 
				if (around[i] == INVALID_STATION) {
 
					st = GetStation(st_index);
 
@@ -2861,11 +2861,11 @@ void BuildOilRig(TileIndex tile)
 
				return;
 

	
 
			SetTileType(tile, MP_STATION);
 
			_map5[tile] = 0x4B;
 
			_m[tile].m5 = 0x4B;
 
			SetTileOwner(tile, OWNER_NONE);
 
			_map3_lo[tile] = 0;
 
			_map3_hi[tile] = 0;
 
			_map2[tile] = st->index;
 
			_m[tile].m3 = 0;
 
			_m[tile].m4 = 0;
 
			_m[tile].m2 = st->index;
 

	
 
			st->owner = OWNER_NONE;
 
      st->airport_flags = 0;
 
@@ -2901,7 +2901,7 @@ void BuildOilRig(TileIndex tile)
 

	
 
void DeleteOilRig(TileIndex tile)
 
{
 
	Station *st = GetStation(_map2[tile]);
 
	Station *st = GetStation(_m[tile].m2);
 

	
 
	DoClearSquare(tile);
 

	
 
@@ -2918,7 +2918,7 @@ static void ChangeTileOwner_Station(Tile
 
	if (!IsTileOwner(tile, old_player)) return;
 

	
 
	if (new_player != 255) {
 
		Station *st = GetStation(_map2[tile]);
 
		Station *st = GetStation(_m[tile].m2);
 
		SetTileOwner(tile, new_player);
 
		st->owner = new_player;
 
		_global_station_sort_dirty = true; // transfer ownership of station to another player
 
@@ -2930,7 +2930,7 @@ static void ChangeTileOwner_Station(Tile
 

	
 
static int32 ClearTile_Station(TileIndex tile, byte flags)
 
{
 
	byte m5 = _map5[tile];
 
	byte m5 = _m[tile].m5;
 
	Station *st;
 

	
 
	if (flags & DC_AUTO) {
 
@@ -2944,7 +2944,7 @@ static int32 ClearTile_Station(TileIndex
 
		return_cmd_error(STR_4800_IN_THE_WAY);
 
	}
 

	
 
	st = GetStation(_map2[tile]);
 
	st = GetStation(_m[tile].m2);
 

	
 
	if (m5 < 8)
 
		return RemoveRailroadStation(st, tile, flags);
 
@@ -3128,7 +3128,7 @@ static void Load_STNS(void)
 
		if (st->train_tile && st->trainst_h == 0) {
 
			int w = st->trainst_w >> 4;
 
			int h = st->trainst_w & 0xF;
 
			if (_map5[st->train_tile]&1) intswap(w,h);
 
			if (_m[st->train_tile].m5&1) intswap(w,h);
 
			st->trainst_w = w;
 
			st->trainst_h = h;
 
		}
tile.c
Show inline comments
 
@@ -4,13 +4,13 @@
 
void SetMapExtraBits(TileIndex tile, byte bits)
 
{
 
	assert(tile < MapSize());
 
	SB(_map_extra_bits[tile >> 2], (tile & 3) * 2, 2, bits & 3);
 
	SB(_m[tile].extra, 0, 2, bits & 3);
 
}
 

	
 
uint GetMapExtraBits(TileIndex tile)
 
{
 
	assert(tile < MapSize());
 
	return GB(_map_extra_bits[tile >> 2], (tile & 3) * 2, 2);
 
	return GB(_m[tile].extra, 0, 2);
 
}
 

	
 

	
tile.h
Show inline comments
 
@@ -58,14 +58,14 @@ static inline bool CorrectZ(uint tileh)
 
static inline uint TileHeight(TileIndex tile)
 
{
 
	assert(tile < MapSize());
 
	return GB(_map_type_and_height[tile], 0, 4);
 
	return GB(_m[tile].type_height, 0, 4);
 
}
 

	
 
static inline void SetTileHeight(TileIndex tile, uint height)
 
{
 
	assert(tile < MapSize());
 
	assert(height < 16);
 
	SB(_map_type_and_height[tile], 0, 4, height);
 
	SB(_m[tile].type_height, 0, 4, height);
 
}
 

	
 
static inline uint TilePixelHeight(TileIndex tile)
 
@@ -76,13 +76,13 @@ static inline uint TilePixelHeight(TileI
 
static inline TileType GetTileType(TileIndex tile)
 
{
 
	assert(tile < MapSize());
 
	return GB(_map_type_and_height[tile], 4, 4);
 
	return GB(_m[tile].type_height, 4, 4);
 
}
 

	
 
static inline void SetTileType(TileIndex tile, TileType type)
 
{
 
	assert(tile < MapSize());
 
	SB(_map_type_and_height[tile], 4, 4, type);
 
	SB(_m[tile].type_height, 4, 4, type);
 
}
 

	
 
static inline bool IsTileType(TileIndex tile, TileType type)
 
@@ -97,7 +97,7 @@ static inline Owner GetTileOwner(TileInd
 
	assert(!IsTileType(tile, MP_VOID));
 
	assert(!IsTileType(tile, MP_INDUSTRY));
 

	
 
	return _map_owner[tile];
 
	return _m[tile].owner;
 
}
 

	
 
static inline void SetTileOwner(TileIndex tile, Owner owner)
 
@@ -107,7 +107,7 @@ static inline void SetTileOwner(TileInde
 
	assert(!IsTileType(tile, MP_VOID));
 
	assert(!IsTileType(tile, MP_INDUSTRY));
 

	
 
	_map_owner[tile] = owner;
 
	_m[tile].owner = owner;
 
}
 

	
 
static inline bool IsTileOwner(TileIndex tile, Owner owner)
town_cmd.c
Show inline comments
 
@@ -73,7 +73,7 @@ typedef struct DrawTownTileStruct {
 

	
 
static void TownDrawTileProc1(TileInfo *ti)
 
{
 
	AddChildSpriteScreen(0x5A3, 0xE, 0x3C - (_map_owner[ti->tile]&0x7F));
 
	AddChildSpriteScreen(0x5A3, 0xE, 0x3C - (_m[ti->tile].owner&0x7F));
 
}
 

	
 
typedef void TownDrawTileProc(TileInfo *ti);
 
@@ -91,8 +91,8 @@ static void DrawTile_Town(TileInfo *ti)
 
	/* Retrieve pointer to the draw town tile struct */
 
	{
 
		/* this "randomizes" on the (up to) 4 variants of a building */
 
		byte gfx   = (byte)_map3_hi[ti->tile];
 
		byte stage = _map3_lo[ti->tile] >> 6;
 
		byte gfx   = (byte)_m[ti->tile].m4;
 
		byte stage = _m[ti->tile].m3 >> 6;
 
		uint variant;
 
		variant  = ti->x >> 4;
 
		variant ^= ti->x >> 6;
 
@@ -159,27 +159,27 @@ static void AnimateTile_Town(TileIndex t
 
	if (_tick_counter & 3)
 
		return;
 

	
 
	if (_map3_hi[tile] != 4 && _map3_hi[tile] != 5)
 
	if (_m[tile].m4 != 4 && _m[tile].m4 != 5)
 
		return;
 

	
 
	if (!((old=_map_owner[tile])&0x80)) {
 
		_map_owner[tile] |= 0x80;
 
	if (!((old=_m[tile].owner)&0x80)) {
 
		_m[tile].owner |= 0x80;
 

	
 
		do {
 
			i = (Random()&7) - 1;
 
		} while (i < 0 || i == 1 || i*6==old);
 

	
 
		_map5[tile] = (_map5[tile] & ~0x3F) | i;
 
		_m[tile].m5 = (_m[tile].m5 & ~0x3F) | i;
 
	}
 

	
 
	a = _map_owner[tile]&0x7F;
 
	b = (_map5[tile]&0x3F) * 6;
 
	a = _m[tile].owner&0x7F;
 
	b = (_m[tile].m5&0x3F) * 6;
 
	a += (a < b) ? 1 : -1;
 
	_map_owner[tile] = (_map_owner[tile]&0x80)|a;
 
	_m[tile].owner = (_m[tile].owner&0x80)|a;
 

	
 
	if (a == b) {
 
		_map5[tile] &= 0x40;
 
		_map_owner[tile] &= 0x7F;
 
		_m[tile].m5 &= 0x40;
 
		_m[tile].owner &= 0x7F;
 
		DeleteAnimatedTile(tile);
 
	}
 

	
 
@@ -248,26 +248,26 @@ static void MakeSingleHouseBigger(TileIn
 

	
 
	assert(IsTileType(tile, MP_HOUSE));
 

	
 
	b = _map5[tile];
 
	b = _m[tile].m5;
 
	if (b & 0x80)
 
		return;
 

	
 
	_map5[tile] = (b & 0xC0) | ((b+1)&7);
 
	_m[tile].m5 = (b & 0xC0) | ((b+1)&7);
 

	
 
	if ((_map5[tile]&7) != 0)
 
	if ((_m[tile].m5&7) != 0)
 
		return;
 

	
 
	_map3_lo[tile] = _map3_lo[tile] + 0x40;
 
	_m[tile].m3 = _m[tile].m3 + 0x40;
 

	
 
	if ( (_map3_lo[tile] & 0xC0) == 0xC0) {
 
		ChangePopulation(GetTown(_map2[tile]), _housetype_population[_map3_hi[tile]]);
 
	if ( (_m[tile].m3 & 0xC0) == 0xC0) {
 
		ChangePopulation(GetTown(_m[tile].m2), _housetype_population[_m[tile].m4]);
 
	}
 
	MarkTileDirtyByTile(tile);
 
}
 

	
 
static void MakeTownHouseBigger(TileIndex tile)
 
{
 
	uint flags = _house_more_flags[_map3_hi[tile]];
 
	uint flags = _house_more_flags[_m[tile].m4];
 
	if (flags & 8) MakeSingleHouseBigger(TILE_ADDXY(tile, 0, 0));
 
	if (flags & 4) MakeSingleHouseBigger(TILE_ADDXY(tile, 0, 1));
 
	if (flags & 2) MakeSingleHouseBigger(TILE_ADDXY(tile, 1, 0));
 
@@ -280,20 +280,20 @@ static void TileLoop_Town(TileIndex tile
 
	Town *t;
 
	uint32 r;
 

	
 
	if ((_map3_lo[tile] & 0xC0) != 0xC0) {
 
	if ((_m[tile].m3 & 0xC0) != 0xC0) {
 
		MakeTownHouseBigger(tile);
 
		return;
 
	}
 

	
 
	house = _map3_hi[tile];
 
	house = _m[tile].m4;
 
	if (_housetype_extra_flags[house] & 0x20 &&
 
			!(_map5[tile] & 0x80) &&
 
			!(_m[tile].m5 & 0x80) &&
 
			CHANCE16(1,2) &&
 
			AddAnimatedTile(tile)) {
 
		_map5[tile] = (_map5[tile] & 0x40)|0x80;
 
		_m[tile].m5 = (_m[tile].m5 & 0x40)|0x80;
 
	}
 

	
 
	t = GetTown(_map2[tile]);
 
	t = GetTown(_m[tile].m2);
 

	
 
	r = Random();
 

	
 
@@ -345,12 +345,12 @@ static int32 ClearTile_Town(TileIndex ti
 
	if (!EnsureNoVehicle(tile)) return CMD_ERROR;
 
	if (flags&DC_AUTO && !(flags&DC_AI_BUILDING)) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
 

	
 
	house = _map3_hi[tile];
 
	house = _m[tile].m4;
 
	cost = _price.remove_house * _housetype_remove_cost[house] >> 8;
 

	
 
	rating = _housetype_remove_ratingmod[house];
 
	_cleared_town_rating += rating;
 
	_cleared_town = t = GetTown(_map2[tile]);
 
	_cleared_town = t = GetTown(_m[tile].m2);
 

	
 
	if (_current_player < MAX_PLAYERS) {
 
		if (rating > t->ratings[_current_player] && !(flags & DC_NO_TOWN_RATING) && !_cheats.magic_bulldozer.value) {
 
@@ -369,7 +369,7 @@ static int32 ClearTile_Town(TileIndex ti
 

	
 
static void GetAcceptedCargo_Town(TileIndex tile, AcceptedCargo ac)
 
{
 
	int type = _map3_hi[tile];
 
	int type = _m[tile].m4;
 

	
 
	ac[CT_PASSENGERS] = _housetype_cargo_passengers[type];
 
	ac[CT_MAIL] = _housetype_cargo_mail[type];
 
@@ -379,8 +379,8 @@ static void GetAcceptedCargo_Town(TileIn
 

	
 
static void GetTileDesc_Town(TileIndex tile, TileDesc *td)
 
{
 
	td->str = _town_tile_names[_map3_hi[tile]];
 
	if ((_map3_lo[tile] & 0xC0) != 0xC0) {
 
	td->str = _town_tile_names[_m[tile].m4];
 
	if ((_m[tile].m3 & 0xC0) != 0xC0) {
 
		SetDParamX(td->dparam, 0, td->str);
 
		td->str = STR_2058_UNDER_CONSTRUCTION;
 
	}
 
@@ -558,7 +558,7 @@ static void LevelTownLand(TileIndex tile
 
	}
 
}
 

	
 
#define IS_WATER_TILE(t) (IsTileType((t), MP_WATER) && _map5[(t)] == 0)
 
#define IS_WATER_TILE(t) (IsTileType((t), MP_WATER) && _m[(t)].m5 == 0)
 

	
 
static void GrowTownInTile(TileIndex *tile_ptr, uint mask, int block, Town *t1)
 
{
 
@@ -616,8 +616,8 @@ static void GrowTownInTile(TileIndex *ti
 
	} else {
 

	
 
		// Reached a tunnel? Then continue at the other side of it.
 
		if (IsTileType(tile, MP_TUNNELBRIDGE) && (_map5[tile]& ~3) == 4) {
 
			FindLengthOfTunnelResult flotr = FindLengthOfTunnel(tile, _map5[tile]&3);
 
		if (IsTileType(tile, MP_TUNNELBRIDGE) && (_m[tile].m5& ~3) == 4) {
 
			FindLengthOfTunnelResult flotr = FindLengthOfTunnel(tile, _m[tile].m5&3);
 
			*tile_ptr = flotr.tile;
 
			return;
 
		}
 
@@ -741,13 +741,13 @@ static int GrowTownAtRoad(Town *t, TileI
 

	
 
		if (IsTileType(tile, MP_STREET)) {
 
			/* Don't allow building over roads of other cities */
 
			if (IsTileOwner(tile, OWNER_TOWN) && GetTown(_map2[tile]) != t)
 
			if (IsTileOwner(tile, OWNER_TOWN) && GetTown(_m[tile].m2) != t)
 
				_grow_town_result = -1;
 
			else if (_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) */
 
				SetTileOwner(tile, OWNER_TOWN);
 
				_map2[tile] = t->index;
 
				_m[tile].m2 = t->index;
 
			}
 
		}
 

	
 
@@ -1382,7 +1382,7 @@ static void DoClearTownHouseHelper(TileI
 

	
 
static void ClearTownHouse(Town *t, TileIndex tile)
 
{
 
	uint house = _map3_hi[tile];
 
	uint house = _m[tile].m4;
 
	uint eflags;
 

	
 
	assert(IsTileType(tile, MP_HOUSE));
 
@@ -1406,7 +1406,7 @@ static void ClearTownHouse(Town *t, Tile
 

	
 
	// Remove population from the town if the
 
	// house is finished.
 
	if ((~_map3_lo[tile] & 0xC0) == 0) {
 
	if ((~_m[tile].m3 & 0xC0) == 0) {
 
		ChangePopulation(t, -_housetype_population[house]);
 
	}
 

	
 
@@ -1489,7 +1489,7 @@ void DeleteTown(Town *t)
 
	for (tile = 0; tile < MapSize(); ++tile) {
 
		switch (GetTileType(tile)) {
 
			case MP_HOUSE:
 
				if (GetTown(_map2[tile]) == t)
 
				if (GetTown(_m[tile].m2) == t)
 
					DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
 
				break;
 

	
 
@@ -1841,9 +1841,9 @@ Town *ClosestTownFromTile(TileIndex tile
 
	// XXX - Fix this so for a given tiletype the owner of the type is in the same variable
 
	if (IsTileType(tile, MP_HOUSE) || (
 
				IsTileType(tile, MP_STREET) &&
 
				(IsLevelCrossing(tile) ? _map3_lo[tile] : GetTileOwner(tile)) == OWNER_TOWN
 
				(IsLevelCrossing(tile) ? _m[tile].m3 : GetTileOwner(tile)) == OWNER_TOWN
 
			))
 
		return GetTown(_map2[tile]);
 
		return GetTown(_m[tile].m2);
 

	
 
	FOR_ALL_TOWNS(t) {
 
		if (t->xy != 0) {
train_cmd.c
Show inline comments
 
@@ -169,13 +169,13 @@ static bool TrainShouldStop(Vehicle *v, 
 
	//When does a train drive through a station
 
	//first we deal with the "new nonstop handling"
 
	if (_patches.new_nonstop && o->flags & OF_NON_STOP &&
 
			_map2[tile] == o->station )
 
			_m[tile].m2 == o->station )
 
		return false;
 

	
 
	if (v->last_station_visited == _map2[tile])
 
	if (v->last_station_visited == _m[tile].m2)
 
		return false;
 

	
 
	if (_map2[tile] != o->station &&
 
	if (_m[tile].m2 != o->station &&
 
			(o->flags & OF_NON_STOP || _patches.new_nonstop))
 
		return false;
 

	
 
@@ -432,7 +432,7 @@ static int32 CmdBuildRailWagon(uint engi
 

	
 
			v->engine_type = engine;
 

	
 
			dir = _map5[tile] & 3;
 
			dir = _m[tile].m5 & 3;
 

	
 
			v->direction = (byte)(dir*2+1);
 
			v->tile = tile;
 
@@ -608,7 +608,7 @@ int32 CmdBuildRailVehicle(int x, int y, 
 
		if (flags & DC_EXEC) {
 
			v->unitnumber = unit_num;
 

	
 
			dir = _map5[tile] & 3;
 
			dir = _m[tile].m5 & 3;
 

	
 
			v->direction = (byte)(dir*2+1);
 
			v->tile = tile;
 
@@ -668,7 +668,7 @@ int32 CmdBuildRailVehicle(int x, int y, 
 

	
 
static bool IsTunnelTile(TileIndex tile)
 
{
 
	return IsTileType(tile, MP_TUNNELBRIDGE) && (_map5[tile] & 0x80) == 0;
 
	return IsTileType(tile, MP_TUNNELBRIDGE) && (_m[tile].m5 & 0x80) == 0;
 
}
 

	
 

	
 
@@ -1243,8 +1243,8 @@ static void DisableTrainCrossing(TileInd
 
		/* Check if there is a train on the tile itself */
 
		if (VehicleFromPos(tile, &tile, TestTrainOnCrossing) == NULL) {
 
			/* If light is on, switch light off */
 
			if (_map5[tile] & 4) {
 
				_map5[tile] &= ~4;
 
			if (_m[tile].m5 & 4) {
 
				_m[tile].m5 &= ~4;
 
				MarkTileDirtyByTile(tile);
 
			}
 
		}
 
@@ -1308,7 +1308,7 @@ TileIndex GetVehicleTileOutOfTunnel(cons
 

	
 
	for (tile = v->tile;; tile += delta) {
 
		if (IsTileType(tile, MP_TUNNELBRIDGE) &&
 
				(_map5[tile] & 0xF3) != (direction) &&
 
				(_m[tile].m5 & 0xF3) != (direction) &&
 
				GetTileZ(tile) == v->z_pos)
 
 			break;
 
 	}
 
@@ -1568,7 +1568,7 @@ typedef struct TrainFindDepotData {
 
static bool TrainFindDepotEnumProc(TileIndex tile, TrainFindDepotData *tfdd, int track, uint length, byte *state)
 
{
 
	if (IsTileType(tile, MP_RAILWAY) && IsTileOwner(tile, tfdd->owner)) {
 
		if ((_map5[tile] & ~0x3) == 0xC0) {
 
		if ((_m[tile].m5 & ~0x3) == 0xC0) {
 
			if (length < tfdd->best_length) {
 
				tfdd->best_length = length;
 
				tfdd->tile = tile;
 
@@ -1577,8 +1577,8 @@ static bool TrainFindDepotEnumProc(TileI
 
		}
 

	
 
		// make sure the train doesn't run against a oneway signal
 
		if ((_map5[tile] & 0xC0) == 0x40) {
 
			if (!(_map3_lo[tile] & SignalAlongTrackdir(track)) && _map3_lo[tile] & SignalAgainstTrackdir(track))
 
		if ((_m[tile].m5 & 0xC0) == 0x40) {
 
			if (!(_m[tile].m3 & SignalAlongTrackdir(track)) && _m[tile].m3 & SignalAgainstTrackdir(track))
 
				return true;
 
		}
 
	}
 
@@ -1888,7 +1888,7 @@ static bool TrainTrackFollower(TileIndex
 

	
 
	// did we reach the final station?
 
	if ((ttfd->station_index == INVALID_STATION && tile == ttfd->dest_coords) ||
 
		(IsTileType(tile, MP_STATION) && IS_BYTE_INSIDE(_map5[tile], 0, 8) && _map2[tile] == ttfd->station_index)) {
 
		(IsTileType(tile, MP_STATION) && IS_BYTE_INSIDE(_m[tile].m5, 0, 8) && _m[tile].m2 == ttfd->station_index)) {
 
		/* We do not check for dest_coords if we have a station_index,
 
		 * because in that case the dest_coords are just an
 
		 * approximation of where the station is */
 
@@ -2180,7 +2180,7 @@ static bool ProcessTrainOrder(Vehicle *v
 

	
 
	// check if we've reached a non-stop station while TTDPatch nonstop is enabled..
 
	if (_patches.new_nonstop && v->current_order.flags & OF_NON_STOP &&
 
		v->current_order.station == _map2[v->tile] && IsTileType(v->tile, MP_STATION) ) {
 
		v->current_order.station == _m[v->tile].m2 && IsTileType(v->tile, MP_STATION) ) {
 
		v->cur_order_index++;
 
	}
 

	
 
@@ -2391,7 +2391,7 @@ static byte AfterSetTrainPos(Vehicle *v,
 
			TileIndex tile = TileVirtXY(v->x_pos, v->y_pos);
 

	
 
			// XXX workaround, whole UP/DOWN detection needs overhaul
 
			if (!IsTileType(tile, MP_TUNNELBRIDGE) || (_map5[tile] & 0x80) != 0)
 
			if (!IsTileType(tile, MP_TUNNELBRIDGE) || (_m[tile].m5 & 0x80) != 0)
 
				SETBIT(v->u.rail.flags, (new_z > old_z) ? VRF_GOINGUP : VRF_GOINGDOWN);
 
		}
 
	}
 
@@ -2454,7 +2454,7 @@ static bool CheckCompatibleRail(const Ve
 
			break;
 

	
 
		case MP_TUNNELBRIDGE:
 
			if ((_map5[tile] & 0xC0) == 0xC0) { // is bridge middle part?
 
			if ((_m[tile].m5 & 0xC0) == 0xC0) { // is bridge middle part?
 
				uint height;
 
				uint tileh = GetTileSlope(tile, &height);
 

	
 
@@ -2466,10 +2466,10 @@ static bool CheckCompatibleRail(const Ve
 
			break;
 

	
 
		case MP_STREET:
 
			// tracks over roads, do owner check of tracks (_map_owner[tile])
 
			// tracks over roads, do owner check of tracks (_m[tile].owner)
 
			return
 
				IsTileOwner(tile, v->owner) &&
 
				(v->subtype != TS_Front_Engine || (_map3_hi[tile] & 0xF) == v->u.rail.railtype);
 
				(v->subtype != TS_Front_Engine || (_m[tile].m4 & 0xF) == v->u.rail.railtype);
 

	
 
		default:
 
			return true;
 
@@ -2533,8 +2533,8 @@ static const byte _otherside_signal_dire
 
static void TrainMovedChangeSignals(TileIndex tile, int dir)
 
{
 
	int i;
 
	if (IsTileType(tile, MP_RAILWAY) && (_map5[tile] & 0xC0) == 0x40) {
 
		i = FindFirstBit2x64((_map5[tile]+(_map5[tile]<<8)) & _reachable_tracks[dir]);
 
	if (IsTileType(tile, MP_RAILWAY) && (_m[tile].m5 & 0xC0) == 0x40) {
 
		i = FindFirstBit2x64((_m[tile].m5+(_m[tile].m5<<8)) & _reachable_tracks[dir]);
 
		UpdateSignalsOnSegment(tile, _otherside_signal_directions[i]);
 
	}
 
}
 
@@ -2850,7 +2850,7 @@ green_light:
 
			GetNewVehiclePos(v, &gp);
 

	
 
			if (IsTileType(gp.new_tile, MP_TUNNELBRIDGE) &&
 
					!(_map5[gp.new_tile] & 0xF0)) {
 
					!(_m[gp.new_tile].m5 & 0xF0)) {
 
				r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y);
 
				if (r & 0x4) goto common;
 
			}
 
@@ -2893,13 +2893,13 @@ red_light: {
 
		 * FIND_FIRST_BIT only handles 6 bits at a time. */
 
		i = FindFirstBit2x64(ts);
 

	
 
		if (!(_map3_lo[gp.new_tile] & SignalAgainstTrackdir(i))) {
 
		if (!(_m[gp.new_tile].m3 & SignalAgainstTrackdir(i))) {
 
			v->cur_speed = 0;
 
			v->subspeed = 0;
 
			v->progress = 255-100;
 
			if (++v->load_unload_time_rem < _patches.wait_oneway_signal * 20)
 
				return;
 
		} else if (_map3_lo[gp.new_tile] & SignalAlongTrackdir(i)){
 
		} else if (_m[gp.new_tile].m3 & SignalAlongTrackdir(i)){
 
			v->cur_speed = 0;
 
			v->subspeed = 0;
 
			v->progress = 255-10;
 
@@ -3114,13 +3114,13 @@ static bool TrainCheckIfLineEnds(Vehicle
 

	
 
	// tunnel entrance?
 
	if (IsTileType(tile, MP_TUNNELBRIDGE) &&
 
			(_map5[tile] & 0xF0) == 0 && (byte)((_map5[tile] & 3)*2+1) == v->direction)
 
			(_m[tile].m5 & 0xF0) == 0 && (byte)((_m[tile].m5 & 3)*2+1) == v->direction)
 
				return true;
 

	
 
	// depot?
 
	/* XXX -- When enabled, this makes it possible to crash trains of others
 
	     (by building a depot right against a station) */
 
/*	if (IsTileType(tile, MP_RAILWAY) && (_map5[tile] & 0xFC) == 0xC0)
 
/*	if (IsTileType(tile, MP_RAILWAY) && (_m[tile].m5 & 0xFC) == 0xC0)
 
		return true;*/
 

	
 
	/* Determine the non-diagonal direction in which we will exit this tile */
 
@@ -3177,8 +3177,8 @@ static bool TrainCheckIfLineEnds(Vehicle
 
		if ((ts &= (ts >> 16)) == 0) {
 
			// make a rail/road crossing red
 
			if (IsTileType(tile, MP_STREET) && IsLevelCrossing(tile)) {
 
				if (!(_map5[tile] & 4)) {
 
					_map5[tile] |= 4;
 
				if (!(_m[tile].m5 & 4)) {
 
					_m[tile].m5 |= 4;
 
					SndPlayVehicleFx(SND_0E_LEVEL_CROSSING, v);
 
					MarkTileDirtyByTile(tile);
 
				}
 
@@ -3194,7 +3194,7 @@ static bool TrainCheckIfLineEnds(Vehicle
 
	if  (v->u.rail.pbs_status == PBS_STAT_HAS_PATH)
 
		return true;
 

	
 
	if ((trackdir != INVALID_TRACKDIR) && (PBSIsPbsSignal(tile,trackdir)) && !(IsTileType(v->tile, MP_STATION) && (v->current_order.station == _map2[v->tile]))) {
 
	if ((trackdir != INVALID_TRACKDIR) && (PBSIsPbsSignal(tile,trackdir)) && !(IsTileType(v->tile, MP_STATION) && (v->current_order.station == _m[v->tile].m2))) {
 
		NPFFindStationOrTileData fstd;
 
		NPFFoundTargetData ftd;
 

	
 
@@ -3322,7 +3322,7 @@ static bool ValidateTrainInDepot( uint d
 

	
 
void TrainEnterDepot(Vehicle *v, TileIndex tile)
 
{
 
	SetSignalsOnBothDir(tile, _depot_track_ind[_map5[tile]&3]);
 
	SetSignalsOnBothDir(tile, _depot_track_ind[_m[tile].m5&3]);
 

	
 
	if (v->subtype != TS_Front_Engine)
 
		v = GetFirstVehicleInChain(v);
train_gui.c
Show inline comments
 
@@ -320,7 +320,7 @@ static void ShowBuildTrainWindow(TileInd
 

	
 
	if (tile != 0) {
 
		w->caption_color = GetTileOwner(tile);
 
		WP(w,buildtrain_d).railtype = _map3_lo[tile] & 0xF;
 
		WP(w,buildtrain_d).railtype = _m[tile].m3 & 0xF;
 
	} else {
 
		w->caption_color = _local_player;
 
		WP(w,buildtrain_d).railtype = GetPlayer(_local_player)->max_railtype - 1;
tree_cmd.c
Show inline comments
 
@@ -44,20 +44,20 @@ static void PlaceTree(TileIndex tile, ui
 
		m5 = (byte)(r >> 16);
 
		if ((m5 & 0x7) == 7) m5--; // there is no growth state 7
 

	
 
		_map5[tile] = m5 & 0x07;	// growth state;
 
		_map5[tile] |=  m5 & 0xC0;	// amount of trees
 
		_m[tile].m5 = m5 & 0x07;	// growth state;
 
		_m[tile].m5 |=  m5 & 0xC0;	// amount of trees
 

	
 
		_map3_lo[tile] = tree;		// set type of tree
 
		_map3_hi[tile] = 0;		// no hedge
 
		_m[tile].m3 = tree;		// set type of tree
 
		_m[tile].m4 = 0;		// no hedge
 

	
 
		// above snowline?
 
		if (_opt.landscape == LT_HILLY && GetTileZ(tile) > _opt.snow_line) {
 
			_map2[tile] = 0xE0;	// set land type to snow
 
			_map2[tile] |= (byte)(r >> 24)&0x07; // randomize counter
 
			_m[tile].m2 = 0xE0;	// set land type to snow
 
			_m[tile].m2 |= (byte)(r >> 24)&0x07; // randomize counter
 
		}
 
		else
 
		{
 
			_map2[tile] = (byte)(r >> 24)&0x1F; // randomize counter and ground
 
			_m[tile].m2 = (byte)(r >> 24)&0x1F; // randomize counter and ground
 
		}
 

	
 

	
 
@@ -86,7 +86,7 @@ static void DoPlaceMoreTrees(TileIndex t
 
		/* Only on tiles within 13 squares from tile,
 
		    on clear tiles, and NOT on farm-tiles or rocks */
 
		if (dist <= 13 && IsTileType(cur_tile, MP_CLEAR) &&
 
			 (_map5[cur_tile] & 0x1F) != 0x0F && (_map5[cur_tile] & 0x1C) != 8) {
 
			 (_m[cur_tile].m5 & 0x1F) != 0x0F && (_m[cur_tile].m5 & 0x1C) != 8) {
 
			PlaceTree(cur_tile, r, dist <= 6 ? 0xC0 : 0);
 
		}
 
	} while (--i);
 
@@ -111,7 +111,7 @@ void PlaceTreesRandomly(void)
 
		r = Random();
 
		tile = TILE_MASK(r);
 
		/* Only on clear tiles, and NOT on farm-tiles or rocks */
 
		if (IsTileType(tile, MP_CLEAR) && (_map5[tile] & 0x1F) != 0x0F && (_map5[tile] & 0x1C) != 8) {
 
		if (IsTileType(tile, MP_CLEAR) && (_m[tile].m5 & 0x1F) != 0x0F && (_m[tile].m5 & 0x1C) != 8) {
 
			PlaceTree(tile, r, 0);
 
		}
 
	} while (--i);
 
@@ -188,7 +188,7 @@ int32 CmdPlantTree(int ex, int ey, uint3
 
					}
 

	
 
					if (flags & DC_EXEC) {
 
						_map5[ti.tile] = ti.map5 + 0x40;
 
						_m[ti.tile].m5 = ti.map5 + 0x40;
 
						MarkTileDirtyByTile(ti.tile);
 
					}
 
					// 2x as expensive to add more trees to an existing tile
 
@@ -274,7 +274,7 @@ static void DrawTile_Trees(TileInfo *ti)
 
	byte z;
 
	TreeListEnt te[4];
 

	
 
	m2 = _map2[ti->tile];
 
	m2 = _m[ti->tile].m2;
 

	
 
	if ( (m2&0x30) == 0) {
 
		DrawClearLandTile(ti, 3);
 
@@ -284,7 +284,7 @@ static void DrawTile_Trees(TileInfo *ti)
 
		DrawHillyLandTile(ti);
 
	}
 

	
 
	DrawClearLandFence(ti, _map3_hi[ti->tile] >> 2);
 
	DrawClearLandFence(ti, _m[ti->tile].m4 >> 2);
 

	
 
	z = ti->z;
 
	if (ti->tileh != 0) {
 
@@ -306,7 +306,7 @@ static void DrawTile_Trees(TileInfo *ti)
 

	
 
		d = _tree_layout_xy[(tmp & 0x30) >> 4];
 

	
 
		index = ((tmp>>6)&3) + (_map3_lo[ti->tile]<<2);
 
		index = ((tmp>>6)&3) + (_m[ti->tile].m3<<2);
 

	
 
		/* different tree styles above one of the grounds */
 
		if ((m2 & 0xB0) == 0xA0 && index >= 48 && index < 80)
 
@@ -378,8 +378,8 @@ static int32 ClearTile_Trees(TileIndex t
 
			ChangeTownRating(t, RATING_TREE_DOWN_STEP, RATING_TREE_MINIMUM);
 
	}
 

	
 
	num = (_map5[tile] >> 6) + 1;
 
	if ( (byte)(_map3_lo[tile]-0x14) <= (0x1A-0x14))
 
	num = (_m[tile].m5 >> 6) + 1;
 
	if ( (byte)(_m[tile].m3-0x14) <= (0x1A-0x14))
 
		num <<= 2;
 

	
 
	if (flags & DC_EXEC)
 
@@ -400,7 +400,7 @@ static void GetTileDesc_Trees(TileIndex 
 

	
 
	td->owner = GetTileOwner(tile);
 

	
 
	b = _map3_lo[tile];
 
	b = _m[tile].m3;
 
	(str=STR_2810_CACTUS_PLANTS, b==0x1B) ||
 
	(str=STR_280F_RAINFOREST, IS_BYTE_INSIDE(b, 0x14, 0x1A+1)) ||
 
	(str=STR_280E_TREES, true);
 
@@ -430,9 +430,9 @@ static void TileLoopTreesDesert(TileInde
 
			SndPlayTileFx(_desert_sounds[(r >> 16) & 3], tile);
 
		}
 
	} else if (b == 1) {
 
		if ((_map2[tile] & 0x30) != 0x20) {
 
			_map2[tile] &= 0xF;
 
			_map2[tile] |= 0xE0;
 
		if ((_m[tile].m2 & 0x30) != 0x20) {
 
			_m[tile].m2 &= 0xF;
 
			_m[tile].m2 |= 0xE0;
 
			MarkTileDirtyByTile(tile);
 
		}
 
	}
 
@@ -446,7 +446,7 @@ static void TileLoopTreesAlps(TileIndex 
 
	/* distance from snow line, in steps of 8 */
 
	k = GetTileZ(tile) - _opt.snow_line;
 

	
 
	tmp = _map5[tile] & 0xF0;
 
	tmp = _m[tile].m5 & 0xF0;
 

	
 
	if (k < -8) {
 
		/* snow_m2_down */
 
@@ -481,8 +481,8 @@ static void TileLoopTreesAlps(TileIndex 
 
		}
 
	}
 

	
 
	_map2[tile] &= 0xF;
 
	_map2[tile] |= m2;
 
	_m[tile].m2 &= 0xF;
 
	_m[tile].m2 |= m2;
 
	MarkTileDirtyByTile(tile);
 
}
 

	
 
@@ -512,16 +512,16 @@ static void TileLoop_Trees(TileIndex til
 

	
 
	/* increase counter */
 
	{
 
		uint16 m2 = _map2[tile];
 
		_map2[tile] = m2 = (m2 & 0xF0) | ((m2+1)&0xF);
 
		uint16 m2 = _m[tile].m2;
 
		_m[tile].m2 = m2 = (m2 & 0xF0) | ((m2+1)&0xF);
 
		if (m2 & 0xF)
 
			return;
 
	}
 

	
 
	m5 = _map5[tile];
 
	m5 = _m[tile].m5;
 
	if ((m5&7) == 3) {
 
		/* regular sized tree */
 
		if (_opt.landscape == LT_DESERT && _map3_lo[tile]!=0x1B && GetMapExtraBits(tile)==1) {
 
		if (_opt.landscape == LT_DESERT && _m[tile].m3!=0x1B && GetMapExtraBits(tile)==1) {
 
			m5++; /* start destructing */
 
		} else {
 
			switch(Random() & 0x7) {
 
@@ -537,25 +537,25 @@ static void TileLoop_Trees(TileIndex til
 
				/* fall through */
 

	
 
			case 2: { /* add a neighbouring tree */
 
				byte m3 = _map3_lo[tile];
 
				byte m3 = _m[tile].m3;
 

	
 
				tile += ToTileIndexDiff(_tileloop_trees_dir[Random() & 7]);
 

	
 
				if (!IsTileType(tile, MP_CLEAR))
 
					return;
 

	
 
				if ( (_map5[tile] & 0x1C) == 4) {
 
					_map2[tile] = 0x10;
 
				} else if ((_map5[tile] & 0x1C) == 16) {
 
					_map2[tile] = ((_map5[tile] & 3) << 6) | 0x20;
 
				if ( (_m[tile].m5 & 0x1C) == 4) {
 
					_m[tile].m2 = 0x10;
 
				} else if ((_m[tile].m5 & 0x1C) == 16) {
 
					_m[tile].m2 = ((_m[tile].m5 & 3) << 6) | 0x20;
 
				} else {
 
					if ((_map5[tile] & 0x1F) != 3)
 
					if ((_m[tile].m5 & 0x1F) != 3)
 
						return;
 
					_map2[tile] = 0;
 
					_m[tile].m2 = 0;
 
				}
 

	
 
				_map3_lo[tile] = m3;
 
				_map3_hi[tile] = 0;
 
				_m[tile].m3 = m3;
 
				_m[tile].m4 = 0;
 
				SetTileType(tile, MP_TREES);
 

	
 
				m5 = 0;
 
@@ -576,7 +576,7 @@ static void TileLoop_Trees(TileIndex til
 
			SetTileType(tile, MP_CLEAR);
 

	
 
			m5 = 3;
 
			m2 = _map2[tile];
 
			m2 = _m[tile].m2;
 
			if ((m2&0x30) != 0) { // on snow/desert or rough land
 
				m5 = (m2 >> 6) | 0x10;
 
				if ((m2&0x30) != 0x20) // if not on snow/desert, then on rough land
 
@@ -589,7 +589,7 @@ static void TileLoop_Trees(TileIndex til
 
		m5++;
 
	}
 

	
 
	_map5[tile] = m5;
 
	_m[tile].m5 = m5;
 
	MarkTileDirtyByTile(tile);
 
}
 

	
 
@@ -604,7 +604,7 @@ void OnTick_Trees(void)
 
	if (_opt.landscape == LT_DESERT &&
 
			(r=Random(),tile=TILE_MASK(r),GetMapExtraBits(tile)==2) &&
 
			IsTileType(tile, MP_CLEAR) &&
 
			(m=_map5[tile]&0x1C, m<=4) &&
 
			(m=_m[tile].m5&0x1C, m<=4) &&
 
			(tree=GetRandomTreeType(tile, r>>24)) >= 0) {
 

	
 
		ModifyTile(tile,
 
@@ -612,7 +612,7 @@ void OnTick_Trees(void)
 
			MP_MAP2 | MP_MAP3LO | MP_MAP3HI | MP_MAP5,
 
			(m == 4 ? 0x10 : 0),
 
			tree,
 
			_map3_hi[tile] & ~3,
 
			_m[tile].m4 & ~3,
 
			0
 
		);
 
	}
 
@@ -625,7 +625,7 @@ void OnTick_Trees(void)
 
	r = Random();
 
	tile = TILE_MASK(r);
 
	if (IsTileType(tile, MP_CLEAR) &&
 
			(m=_map5[tile]&0x1C, m==0 || m==4 || m==0x10) &&
 
			(m=_m[tile].m5&0x1C, m==0 || m==4 || m==0x10) &&
 
			(tree=GetRandomTreeType(tile, r>>24)) >= 0) {
 
		int m2;
 

	
 
@@ -634,7 +634,7 @@ void OnTick_Trees(void)
 
		} else if (m == 4) {
 
			m2 = 0x10;
 
		} else {
 
			m2 = ((_map5[tile] & 3) << 6) | 0x20;
 
			m2 = ((_m[tile].m5 & 3) << 6) | 0x20;
 
		}
 

	
 
		ModifyTile(tile,
 
@@ -642,7 +642,7 @@ void OnTick_Trees(void)
 
			MP_MAP2 | MP_MAP3LO | MP_MAP3HI | MP_MAP5,
 
			m2,
 
			tree,
 
			_map3_hi[tile] & ~3,
 
			_m[tile].m4 & ~3,
 
			0
 
		);
 
	}
tunnelbridge_cmd.c
Show inline comments
 
@@ -348,7 +348,7 @@ not_valid_below:;
 

	
 
		/* do middle part of bridge */
 
		if (flags & DC_EXEC) {
 
			_map5[ti.tile] = (byte)(m5 | direction | rail_or_road);
 
			_m[ti.tile].m5 = (byte)(m5 | direction | rail_or_road);
 
			SetTileType(ti.tile, MP_TUNNELBRIDGE);
 

	
 
			//bridges pieces sequence (middle parts)
 
@@ -376,9 +376,9 @@ not_valid_below:;
 
					m5 = 2 + ((i%2==0)^(i>odd_middle_part));
 
			}
 

	
 
			_map2[ti.tile] = (bridge_type << 4) | m5;
 
			_map3_lo[ti.tile] &= 0xF;
 
			_map3_lo[ti.tile] |= (byte)(railtype << 4);
 
			_m[ti.tile].m2 = (bridge_type << 4) | m5;
 
			_m[ti.tile].m3 &= 0xF;
 
			_m[ti.tile].m3 |= (byte)(railtype << 4);
 

	
 
			MarkTileDirtyByTile(ti.tile);
 
		}
 
@@ -590,7 +590,7 @@ int32 CmdBuildTunnel(int x, int y, uint3
 
TileIndex CheckTunnelBusy(TileIndex tile, uint *length)
 
{
 
	uint z = GetTileZ(tile);
 
	byte m5 = _map5[tile];
 
	byte m5 = _m[tile].m5;
 
	int delta = TileOffsByDir(m5 & 3);
 
	uint len = 0;
 
	TileIndex starttile = tile;
 
@@ -601,8 +601,8 @@ TileIndex CheckTunnelBusy(TileIndex tile
 
		len++;
 
	} while (
 
		!IsTileType(tile, MP_TUNNELBRIDGE) ||
 
		(_map5[tile] & 0xF0) != 0 ||
 
		(byte)(_map5[tile] ^ 2) != m5 ||
 
		(_m[tile].m5 & 0xF0) != 0 ||
 
		(byte)(_m[tile].m5 ^ 2) != m5 ||
 
		GetTileZ(tile) != z
 
	);
 

	
 
@@ -650,8 +650,8 @@ static int32 DoClearTunnel(TileIndex til
 
	if (flags & DC_EXEC) {
 
		// We first need to request the direction before calling DoClearSquare
 
		//  else the direction is always 0.. dah!! ;)
 
		byte tile_dir = _map5[tile]&3;
 
		byte endtile_dir = _map5[endtile]&3;
 
		byte tile_dir = _m[tile].m5&3;
 
		byte endtile_dir = _m[endtile].m5&3;
 
		DoClearSquare(tile);
 
		DoClearSquare(endtile);
 
		UpdateSignalsOnSegment(tile, _updsignals_tunnel_dir[tile_dir]);
 
@@ -664,12 +664,12 @@ static int32 DoClearTunnel(TileIndex til
 

	
 
static TileIndex FindEdgesOfBridge(TileIndex tile, TileIndex *endtile)
 
{
 
	int direction = _map5[tile] & 1;
 
	int direction = _m[tile].m5 & 1;
 
	TileIndex start;
 

	
 
	// find start of bridge
 
	for(;;) {
 
		if (IsTileType(tile, MP_TUNNELBRIDGE) && (_map5[tile] & 0xE0) == 0x80)
 
		if (IsTileType(tile, MP_TUNNELBRIDGE) && (_m[tile].m5 & 0xE0) == 0x80)
 
			break;
 
		tile += direction ? TileDiffXY(0, -1) : TileDiffXY(-1, 0);
 
	}
 
@@ -678,7 +678,7 @@ static TileIndex FindEdgesOfBridge(TileI
 

	
 
	// find end of bridge
 
	for(;;) {
 
		if (IsTileType(tile, MP_TUNNELBRIDGE) && (_map5[tile] & 0xE0) == 0xA0)
 
		if (IsTileType(tile, MP_TUNNELBRIDGE) && (_m[tile].m5 & 0xE0) == 0xA0)
 
			break;
 
		tile += direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
 
	}
 
@@ -697,27 +697,27 @@ static int32 DoClearBridge(TileIndex til
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	direction = _map5[tile]&1;
 
	direction = _m[tile].m5&1;
 

	
 
	/* delete stuff under the middle part if there's a transport route there..? */
 
	if ((_map5[tile] & 0xE0) == 0xE0) {
 
	if ((_m[tile].m5 & 0xE0) == 0xE0) {
 
		int32 cost;
 

	
 
		// check if we own the tile below the bridge..
 
		if (_current_player != OWNER_WATER && (!CheckTileOwnership(tile) || !EnsureNoVehicleZ(tile, TilePixelHeight(tile))))
 
			return CMD_ERROR;
 

	
 
		cost = (_map5[tile] & 8) ? _price.remove_road * 2 : _price.remove_rail;
 
		cost = (_m[tile].m5 & 8) ? _price.remove_road * 2 : _price.remove_rail;
 

	
 
		if (flags & DC_EXEC) {
 
			_map5[tile] = _map5[tile] & ~0x38;
 
			_m[tile].m5 = _m[tile].m5 & ~0x38;
 
			SetTileOwner(tile, OWNER_NONE);
 
			MarkTileDirtyByTile(tile);
 
		}
 
		return cost;
 

	
 
	/* delete canal under bridge */
 
	} else if ((_map5[tile] & 0xC8) == 0xC8 && TilePixelHeight(tile) != 0) {
 
	} else if ((_m[tile].m5 & 0xC8) == 0xC8 && TilePixelHeight(tile) != 0) {
 
		int32 cost;
 

	
 
		// check for vehicles under bridge
 
@@ -725,7 +725,7 @@ static int32 DoClearBridge(TileIndex til
 
			return CMD_ERROR;
 
		cost = _price.clear_water;
 
		if (flags & DC_EXEC) {
 
			_map5[tile] = _map5[tile] & ~0x38;
 
			_m[tile].m5 = _m[tile].m5 & ~0x38;
 
			SetTileOwner(tile, OWNER_NONE);
 
			MarkTileDirtyByTile(tile);
 
		}
 
@@ -780,7 +780,7 @@ static int32 DoClearBridge(TileIndex til
 
			ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM);
 

	
 
		do {
 
			m5 = _map5[c];
 
			m5 = _m[c].m5;
 
			pbs = PBSTileReserved(c);
 

	
 
			if (m5 & 0x40) {
 
@@ -793,9 +793,9 @@ static int32 DoClearBridge(TileIndex til
 
				}
 

	
 
				SetTileType(c, new_data >> 12);
 
				_map5[c] = (byte)new_data;
 
				_map2[c] = 0;
 
				_map3_hi[c] &= 0x0F;
 
				_m[c].m5 = (byte)new_data;
 
				_m[c].m2 = 0;
 
				_m[c].m4 &= 0x0F;
 
				if (direction ? HASBIT(pbs,0) : HASBIT(pbs,1))
 
					PBSReserveTrack(c, direction ? 0 : 1);
 

	
 
@@ -818,7 +818,7 @@ clear_it:;
 

	
 
static int32 ClearTile_TunnelBridge(TileIndex tile, byte flags)
 
{
 
	byte m5 = _map5[tile];
 
	byte m5 = _m[tile].m5;
 

	
 
	if ((m5 & 0xF0) == 0) {
 
		if (flags & DC_AUTO)
 
@@ -841,37 +841,37 @@ int32 DoConvertTunnelBridgeRail(TileInde
 
	uint length;
 
	Vehicle *v;
 

	
 
	if ((_map5[tile] & 0xFC) == 0x00) {
 
	if ((_m[tile].m5 & 0xFC) == 0x00) {
 
		// railway tunnel
 
		if (!CheckTileOwnership(tile)) return CMD_ERROR;
 

	
 
		if ( (uint)(_map3_lo[tile] & 0xF) == totype) return CMD_ERROR;
 
		if ( (uint)(_m[tile].m3 & 0xF) == totype) return CMD_ERROR;
 

	
 
		endtile = CheckTunnelBusy(tile, &length);
 
		if (endtile == INVALID_TILE) return CMD_ERROR;
 

	
 
		if (exec) {
 
			_map3_lo[tile] = (_map3_lo[tile] & 0xF0) + totype;
 
			_map3_lo[endtile] = (_map3_lo[endtile] & 0xF0) + totype;
 
			_m[tile].m3 = (_m[tile].m3 & 0xF0) + totype;
 
			_m[endtile].m3 = (_m[endtile].m3 & 0xF0) + totype;
 
			MarkTileDirtyByTile(tile);
 
			MarkTileDirtyByTile(endtile);
 
		}
 
		return (length + 1) * (_price.build_rail >> 1);
 
	} else if ((_map5[tile] & 0xF8) == 0xE0) {
 
	} else if ((_m[tile].m5 & 0xF8) == 0xE0) {
 
		// bridge middle part with rail below
 
		// only check for train under bridge
 
		if (!CheckTileOwnership(tile) || !EnsureNoVehicleZ(tile, TilePixelHeight(tile)))
 
			return CMD_ERROR;
 

	
 
		// tile is already of requested type?
 
		if ( (uint)(_map3_lo[tile] & 0xF) == totype) return CMD_ERROR;
 
		if ( (uint)(_m[tile].m3 & 0xF) == totype) return CMD_ERROR;
 
		// change type.
 
		if (exec) {
 
			_map3_lo[tile] = (_map3_lo[tile] & 0xF0) + totype;
 
			_m[tile].m3 = (_m[tile].m3 & 0xF0) + totype;
 
			MarkTileDirtyByTile(tile);
 
		}
 
		return _price.build_rail >> 1;
 
	} else if ((_map5[tile]&0xC6) == 0x80) {
 
	} else if ((_m[tile].m5&0xC6) == 0x80) {
 
		TileIndex starttile;
 
		int32 cost;
 
		uint z = TilePixelHeight(tile);
 
@@ -893,19 +893,19 @@ int32 DoConvertTunnelBridgeRail(TileInde
 
			return CMD_ERROR;
 
		}
 

	
 
		if ( (uint)(_map3_lo[tile] & 0xF) == totype) return CMD_ERROR;
 
		if ( (uint)(_m[tile].m3 & 0xF) == totype) return CMD_ERROR;
 
		cost = 0;
 
		do {
 
			if (exec) {
 
				if (tile == starttile || tile == endtile) {
 
					_map3_lo[tile] = (_map3_lo[tile] & 0xF0) + totype;
 
					_m[tile].m3 = (_m[tile].m3 & 0xF0) + totype;
 
				} else {
 
					_map3_lo[tile] = (_map3_lo[tile] & 0x0F) + (totype << 4);
 
					_m[tile].m3 = (_m[tile].m3 & 0x0F) + (totype << 4);
 
				}
 
				MarkTileDirtyByTile(tile);
 
			}
 
			cost += (_price.build_rail>>1);
 
			tile += _map5[tile] & 1 ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
 
			tile += _m[tile].m5 & 1 ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
 
		} while (tile <= endtile);
 

	
 
		return cost;
 
@@ -921,11 +921,11 @@ static uint GetBridgeHeight(const TileIn
 
	TileIndex tile = ti->tile;
 

	
 
	// find the end tile of the bridge.
 
	delta = (_map5[tile] & 1) ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
 
	delta = (_m[tile].m5 & 1) ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
 
	do {
 
		assert((_map5[tile] & 0xC0) == 0xC0);	// bridge and middle part
 
		assert((_m[tile].m5 & 0xC0) == 0xC0);	// bridge and middle part
 
		tile += delta;
 
	} while (_map5[tile] & 0x40);	// while bridge middle parts
 
	} while (_m[tile].m5 & 0x40);	// while bridge middle parts
 

	
 
	/* Return the height there (the height of the NORTH CORNER)
 
	 * If the end of the bridge is on a tileh 7 (all raised, except north corner),
 
@@ -952,12 +952,12 @@ static void DrawBridgePillars(TileInfo *
 
	uint32 image;
 
	int piece;
 

	
 
	b = _bridge_poles_table[_map2[ti->tile]>>4];
 
	b = _bridge_poles_table[_m[ti->tile].m2>>4];
 

	
 
	// Draw first piece
 
	// (necessary for cantilever bridges)
 
	image = b[12 + (ti->map5&0x01)];
 
	piece = _map2[ti->tile]&0xF;
 
	piece = _m[ti->tile].m2&0xF;
 
	if (image != 0 && piece != 0) {
 
		if (_display_opt & DO_TRANS_BUILDINGS) image = (image & 0x3FFF) | 0x03224000;
 
		DrawGroundSpriteAt(image, x, y, z);
 
@@ -1012,12 +1012,12 @@ static void DrawTile_TunnelBridge(TileIn
 
	uint32 image;
 
	uint tmp;
 
	const uint32 *b;
 
	bool ice = _map3_hi[ti->tile] & 0x80;
 
	bool ice = _m[ti->tile].m4 & 0x80;
 

	
 
	// draw tunnel?
 
	if ( (byte)(ti->map5&0xF0) == 0) {
 
		/* railway type */
 
		image = (_map3_lo[ti->tile] & 0xF) * 8;
 
		image = (_m[ti->tile].m3 & 0xF) * 8;
 

	
 
		/* ice? */
 
		if (ice)
 
@@ -1031,7 +1031,7 @@ static void DrawTile_TunnelBridge(TileIn
 
	// draw bridge?
 
	} else if ((byte)ti->map5 & 0x80) {
 
		// get type of track on the bridge.
 
		tmp = _map3_lo[ti->tile];
 
		tmp = _m[ti->tile].m3;
 
		if (ti->map5 & 0x40) tmp >>= 4;
 
		tmp &= 0xF;
 

	
 
@@ -1055,7 +1055,7 @@ static void DrawTile_TunnelBridge(TileIn
 
			}
 

	
 
			// bridge ending.
 
			b = _bridge_sprite_table[(_map2[ti->tile] >> 4) & 0xF][6];
 
			b = _bridge_sprite_table[(_m[ti->tile].m2 >> 4) & 0xF][6];
 
			b += (tmp&(3<<1))*4; /* actually ((tmp>>2)&3)*8 */
 
			b += (tmp&1); // direction
 
			if (ti->tileh == 0) b += 4; // sloped "entrance" ?
 
@@ -1104,7 +1104,7 @@ static void DrawTile_TunnelBridge(TileIn
 
					// railway
 
					image = 0x3F3 + (ti->map5 & 1);
 
					if (ti->tileh != 0) image = _track_sloped_sprites[ti->tileh - 1] + 0x3F3;
 
					image += (_map3_lo[ti->tile] & 0xF) * TRACKTYPE_SPRITE_PITCH;
 
					image += (_m[ti->tile].m3 & 0xF) * TRACKTYPE_SPRITE_PITCH;
 
					if (ice) image += 26; // ice?
 
				} else {
 
					// road
 
@@ -1115,7 +1115,7 @@ static void DrawTile_TunnelBridge(TileIn
 
				DrawGroundSprite(image);
 
			}
 
			// get bridge sprites
 
			b = _bridge_sprite_table[(_map2[ti->tile] >> 4) & 0xF][_map2[ti->tile]&0xF] + tmp * 4;
 
			b = _bridge_sprite_table[(_m[ti->tile].m2 >> 4) & 0xF][_m[ti->tile].m2&0xF] + tmp * 4;
 

	
 
			z = GetBridgeHeight(ti) + 5;
 

	
 
@@ -1284,16 +1284,16 @@ static const StringID _bridge_tile_str[(
 

	
 
static void GetTileDesc_TunnelBridge(TileIndex tile, TileDesc *td)
 
{
 
	if ((_map5[tile] & 0x80) == 0) {
 
		td->str = STR_5017_RAILROAD_TUNNEL + ((_map5[tile] >> 2) & 3);
 
	if ((_m[tile].m5 & 0x80) == 0) {
 
		td->str = STR_5017_RAILROAD_TUNNEL + ((_m[tile].m5 >> 2) & 3);
 
	} else {
 
		td->str = _bridge_tile_str[ (_map2[tile] >> 4) + (((_map5[tile]>>1)&3)<<4) ];
 
		td->str = _bridge_tile_str[ (_m[tile].m2 >> 4) + (((_m[tile].m5>>1)&3)<<4) ];
 

	
 
		/* scan to the end of the bridge, that's where the owner is stored */
 
		if (_map5[tile] & 0x40) {
 
			TileIndexDiff delta = _map5[tile] & 1 ? TileDiffXY(0, -1) : TileDiffXY(-1, 0);
 
		if (_m[tile].m5 & 0x40) {
 
			TileIndexDiff delta = _m[tile].m5 & 1 ? TileDiffXY(0, -1) : TileDiffXY(-1, 0);
 

	
 
			do tile += delta; while (_map5[tile] & 0x40);
 
			do tile += delta; while (_m[tile].m5 & 0x40);
 
		}
 
	}
 
	td->owner = GetTileOwner(tile);
 
@@ -1309,25 +1309,25 @@ static void TileLoop_TunnelBridge(TileIn
 
{
 
	if (_opt.landscape == LT_HILLY) {
 
		if ( GetTileZ(tile) > _opt.snow_line) {
 
			if (!(_map3_hi[tile] & 0x80)) {
 
				_map3_hi[tile] |= 0x80;
 
			if (!(_m[tile].m4 & 0x80)) {
 
				_m[tile].m4 |= 0x80;
 
				MarkTileDirtyByTile(tile);
 
			}
 
		} else {
 
			if (_map3_hi[tile] & 0x80) {
 
				_map3_hi[tile] &= ~0x80;
 
			if (_m[tile].m4 & 0x80) {
 
				_m[tile].m4 &= ~0x80;
 
				MarkTileDirtyByTile(tile);
 
			}
 
		}
 
	} else if (_opt.landscape == LT_DESERT) {
 
		if (GetMapExtraBits(tile) == 1 && !(_map3_hi[tile]&0x80)) {
 
			_map3_hi[tile] |= 0x80;
 
		if (GetMapExtraBits(tile) == 1 && !(_m[tile].m4&0x80)) {
 
			_m[tile].m4 |= 0x80;
 
			MarkTileDirtyByTile(tile);
 
		}
 
	}
 

	
 
	// if it's a bridge with water below, call tileloop_water on it.
 
	if ((_map5[tile] & 0xF8) == 0xC8) TileLoop_Water(tile);
 
	if ((_m[tile].m5 & 0xF8) == 0xC8) TileLoop_Water(tile);
 
}
 

	
 
static void ClickTile_TunnelBridge(TileIndex tile)
 
@@ -1339,7 +1339,7 @@ static void ClickTile_TunnelBridge(TileI
 
static uint32 GetTileTrackStatus_TunnelBridge(TileIndex tile, TransportType mode)
 
{
 
	uint32 result;
 
	byte m5 = _map5[tile];
 
	byte m5 = _m[tile].m5;
 

	
 
	if ((m5 & 0xF0) == 0) {
 
		/* This is a tunnel */
 
@@ -1390,11 +1390,11 @@ static void ChangeTileOwner_TunnelBridge
 
	if (new_player != 255) {
 
		SetTileOwner(tile, new_player);
 
	}	else {
 
		if((_map5[tile] & 0xC0)==0xC0) {
 
		if((_m[tile].m5 & 0xC0)==0xC0) {
 
			// the stuff BELOW the middle part is owned by the deleted player.
 
			if (!(_map5[tile] & (1 << 4 | 1 << 3))) {
 
			if (!(_m[tile].m5 & (1 << 4 | 1 << 3))) {
 
				// convert railway into grass.
 
				_map5[tile] &= ~(1 << 5 | 1 << 4 | 1 << 3); // no transport route under bridge anymore..
 
				_m[tile].m5 &= ~(1 << 5 | 1 << 4 | 1 << 3); // no transport route under bridge anymore..
 
			} else {
 
				// for road, change the owner of the road to local authority
 
				SetTileOwner(tile, OWNER_NONE);
 
@@ -1425,7 +1425,7 @@ static uint32 VehicleEnter_TunnelBridge(
 
	int dir, vdir;
 
	byte fc;
 

	
 
	if ((_map5[tile] & 0xF0) == 0) {
 
	if ((_m[tile].m5 & 0xF0) == 0) {
 
		z = GetSlopeZ(x, y) - v->z_pos;
 
		if (myabs(z) > 2)
 
			return 8;
 
@@ -1433,7 +1433,7 @@ static uint32 VehicleEnter_TunnelBridge(
 
		if (v->type == VEH_Train) {
 
			fc = (x&0xF)+(y<<4);
 

	
 
			dir = _map5[tile] & 3;
 
			dir = _m[tile].m5 & 3;
 
			vdir = v->direction >> 1;
 

	
 
			if (v->u.rail.track != 0x40 && dir == vdir) {
 
@@ -1462,7 +1462,7 @@ static uint32 VehicleEnter_TunnelBridge(
 
			}
 
		} else if (v->type == VEH_Road) {
 
			fc = (x&0xF)+(y<<4);
 
			dir = _map5[tile] & 3;
 
			dir = _m[tile].m5 & 3;
 
			vdir = v->direction >> 1;
 

	
 
			// Enter tunnel?
 
@@ -1491,16 +1491,16 @@ static uint32 VehicleEnter_TunnelBridge(
 
				return 4;
 
			}
 
		}
 
	} else if (_map5[tile] & 0x80) {
 
	} else if (_m[tile].m5 & 0x80) {
 
		if (v->type == VEH_Road || (v->type == VEH_Train && v->subtype == TS_Front_Engine)) {
 
			uint h;
 

	
 
			if (GetTileSlope(tile, &h) != 0)
 
				h += 8; // Compensate for possible foundation
 
			if (!(_map5[tile] & 0x40) || // start/end tile of bridge
 
			if (!(_m[tile].m5 & 0x40) || // start/end tile of bridge
 
					myabs(h - v->z_pos) > 2) { // high above the ground -> on the bridge
 
				/* modify speed of vehicle */
 
				uint16 spd = _bridge_speeds[_map2[tile] >> 4];
 
				uint16 spd = _bridge_speeds[_m[tile].m2 >> 4];
 
				if (v->type == VEH_Road) spd<<=1;
 
				if (spd < v->cur_speed)
 
					v->cur_speed = spd;
 
@@ -1517,7 +1517,7 @@ TileIndex GetVehicleOutOfTunnelTile(cons
 
	byte z = v->z_pos;
 

	
 
	for (tile = v->tile;; tile += delta) {
 
		if (IsTileType(tile, MP_TUNNELBRIDGE) && (_map5[tile] & 0xF0) == 0 &&
 
		if (IsTileType(tile, MP_TUNNELBRIDGE) && (_m[tile].m5 & 0xF0) == 0 &&
 
				GetTileZ(tile) == z)
 
			break;
 
	}
unmovable_cmd.c
Show inline comments
 
@@ -195,7 +195,7 @@ static uint GetSlopeTileh_Unmovable(Tile
 

	
 
static int32 ClearTile_Unmovable(TileIndex tile, byte flags)
 
{
 
	byte m5 = _map5[tile];
 
	byte m5 = _m[tile].m5;
 

	
 
	if (m5 & 0x80) {
 
		if (_current_player == OWNER_WATER) return DestroyCompanyHQ(tile, DC_EXEC);
 
@@ -218,7 +218,7 @@ static int32 ClearTile_Unmovable(TileInd
 

	
 
static void GetAcceptedCargo_Unmovable(TileIndex tile, AcceptedCargo ac)
 
{
 
	byte m5 = _map5[tile];
 
	byte m5 = _m[tile].m5;
 
	uint level; // HQ level (depends on company performance) in the range 1..5.
 

	
 
	if (!(m5 & 0x80)) {
 
@@ -252,7 +252,7 @@ static const StringID _unmovable_tile_st
 

	
 
static void GetTileDesc_Unmovable(TileIndex tile, TileDesc *td)
 
{
 
	int i = _map5[tile];
 
	int i = _m[tile].m5;
 
	if (i & 0x80) i = -1;
 
	td->str = _unmovable_tile_str[i + 1];
 
	td->owner = GetTileOwner(tile);
 
@@ -265,7 +265,7 @@ static void AnimateTile_Unmovable(TileIn
 

	
 
static void TileLoop_Unmovable(TileIndex tile)
 
{
 
	byte m5 = _map5[tile];
 
	byte m5 = _m[tile].m5;
 
	byte level; // HQ level (depends on company performance) in the range 1..5.
 
	uint32 r;
 

	
 
@@ -307,7 +307,7 @@ static uint32 GetTileTrackStatus_Unmovab
 

	
 
static void ClickTile_Unmovable(TileIndex tile)
 
{
 
	if (_map5[tile] & 0x80) {
 
	if (_m[tile].m5 & 0x80) {
 
		ShowPlayerCompany(GetTileOwner(tile));
 
	}
 
}
 
@@ -326,7 +326,7 @@ static bool checkRadioTowerNearby(TileIn
 

	
 
	BEGIN_TILE_LOOP(tile, 9, 9, tile_s)
 
		// already a radio tower here?
 
		if (IsTileType(tile, MP_UNMOVABLE) && _map5[tile] == 0)
 
		if (IsTileType(tile, MP_UNMOVABLE) && _m[tile].m5 == 0)
 
			return false;
 
	END_TILE_LOOP(tile, 9, 9, tile_s)
 
	return true;
 
@@ -355,7 +355,7 @@ void GenerateUnmovables(void)
 
			if(!checkRadioTowerNearby(tile))
 
				continue;
 
			SetTileType(tile, MP_UNMOVABLE);
 
			_map5[tile] = 0;
 
			_m[tile].m5 = 0;
 
			SetTileOwner(tile, OWNER_NONE);
 
			if (--j == 0)
 
				break;
 
@@ -387,7 +387,7 @@ restart:
 
		assert(tile == TILE_MASK(tile));
 

	
 
		SetTileType(tile, MP_UNMOVABLE);
 
		_map5[tile] = 1;
 
		_m[tile].m5 = 1;
 
		SetTileOwner(tile, OWNER_NONE);
 
	} while (--i);
 
}
 
@@ -396,7 +396,7 @@ static void ChangeTileOwner_Unmovable(Ti
 
{
 
	if (!IsTileOwner(tile, old_player)) return;
 

	
 
	if (_map5[tile]==3 && new_player != 255) {
 
	if (_m[tile].m5==3 && new_player != 255) {
 
		SetTileOwner(tile, new_player);
 
	} else {
 
		DoClearSquare(tile);
vehicle.c
Show inline comments
 
@@ -1128,10 +1128,7 @@ static void BubbleTick(Vehicle *v)
 
		SndPlayVehicleFx(SND_31_EXTRACT, v);
 

	
 
		tile = TileVirtXY(v->x_pos, v->y_pos);
 
		if (IsTileType(tile, MP_INDUSTRY) &&
 
				_map5[tile] == 0xA2) {
 
			AddAnimatedTile(tile);
 
		}
 
		if (IsTileType(tile, MP_INDUSTRY) && _m[tile].m5 == 0xA2) AddAnimatedTile(tile);
 
	}
 

	
 
	v->engine_type = et;
water_cmd.c
Show inline comments
 
@@ -87,7 +87,7 @@ static int32 RemoveShipDepot(TileIndex t
 
	if (!EnsureNoVehicle(tile))
 
		return CMD_ERROR;
 

	
 
	tile2 = tile + ((_map5[tile] & 2) ? TileDiffXY(0, 1) : TileDiffXY(1, 0));
 
	tile2 = tile + ((_m[tile].m5 & 2) ? TileDiffXY(0, 1) : TileDiffXY(1, 0));
 

	
 
	if (!EnsureNoVehicle(tile2))
 
		return CMD_ERROR;
 
@@ -136,7 +136,7 @@ static int32 DoBuildShiplift(TileIndex t
 

	
 
static int32 RemoveShiplift(TileIndex tile, uint32 flags)
 
{
 
	TileIndexDiff delta = TileOffsByDir(_map5[tile] & 3);
 
	TileIndexDiff delta = TileOffsByDir(_m[tile].m5 & 3);
 

	
 
	// make sure no vehicle is on the tile.
 
	if (!EnsureNoVehicle(tile) || !EnsureNoVehicle(tile + delta) || !EnsureNoVehicle(tile - delta))
 
@@ -219,11 +219,11 @@ int32 CmdBuildCanal(int x, int y, uint32
 
				_error_message = STR_1007_ALREADY_BUILT;
 
			} else {
 
				/* is middle piece of a bridge? */
 
				if (IsTileType(tile, MP_TUNNELBRIDGE) && _map5[tile] & 0x40) { /* build under bridge */
 
					if (_map5[tile] & 0x20) // transport route under bridge
 
				if (IsTileType(tile, MP_TUNNELBRIDGE) && _m[tile].m5 & 0x40) { /* build under bridge */
 
					if (_m[tile].m5 & 0x20) // transport route under bridge
 
						return_cmd_error(STR_5800_OBJECT_IN_THE_WAY);
 

	
 
					if (_map5[tile] & 0x18) // already water under bridge
 
					if (_m[tile].m5 & 0x18) // already water under bridge
 
						return_cmd_error(STR_1007_ALREADY_BUILT);
 
				/* no bridge? then try to clear it. */
 
				} else
 
@@ -236,7 +236,7 @@ int32 CmdBuildCanal(int x, int y, uint32
 
				if (flags & DC_EXEC) {
 
					if (IsTileType(tile, MP_TUNNELBRIDGE)) {
 
						// change owner to OWNER_WATER and set land under bridge bit to water
 
						ModifyTile(tile, MP_MAP5 | MP_MAPOWNER, OWNER_WATER, _map5[tile] | 0x08);
 
						ModifyTile(tile, MP_MAP5 | MP_MAPOWNER, OWNER_WATER, _m[tile].m5 | 0x08);
 
					} else {
 
						ModifyTile(tile, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, OWNER_WATER, 0);
 
					}
 
@@ -253,7 +253,7 @@ int32 CmdBuildCanal(int x, int y, uint32
 

	
 
static int32 ClearTile_Water(TileIndex tile, byte flags)
 
{
 
	byte m5 = _map5[tile];
 
	byte m5 = _m[tile].m5;
 
	uint slope;
 

	
 
	if (m5 <= 1) { // water and shore
 
@@ -318,7 +318,7 @@ static int32 ClearTile_Water(TileIndex t
 
// return true if a tile is a water tile.
 
static bool IsWateredTile(TileIndex tile)
 
{
 
	byte m5 = _map5[tile];
 
	byte m5 = _m[tile].m5;
 

	
 
	switch (GetTileType(tile)) {
 
		case MP_WATER:
 
@@ -455,13 +455,13 @@ static void GetAcceptedCargo_Water(TileI
 

	
 
static void GetTileDesc_Water(TileIndex tile, TileDesc *td)
 
{
 
	if (_map5[tile] == 0 && TilePixelHeight(tile) == 0)
 
	if (_m[tile].m5 == 0 && TilePixelHeight(tile) == 0)
 
		td->str = STR_3804_WATER;
 
	else if (_map5[tile] == 0)
 
	else if (_m[tile].m5 == 0)
 
		td->str = STR_LANDINFO_CANAL;
 
	else if (_map5[tile] == 1)
 
	else if (_m[tile].m5 == 1)
 
		td->str = STR_3805_COAST_OR_RIVERBANK;
 
	else if ((_map5[tile]&0xF0) == 0x10)
 
	else if ((_m[tile].m5&0xF0) == 0x10)
 
		td->str = STR_LANDINFO_LOCK;
 
	else
 
		td->str = STR_3806_SHIP_DEPOT;
 
@@ -492,7 +492,7 @@ static void TileLoopWaterHelper(TileInde
 
		switch (GetTileType(target)) {
 
			case MP_RAILWAY: {
 
				uint slope = GetTileSlope(target, NULL);
 
				byte tracks = _map5[target] & 0x3F;
 
				byte tracks = _m[target].m5 & 0x3F;
 
				if (!(
 
						(slope == 1 && tracks == 0x20) ||
 
						(slope == 2 && tracks == 0x04) ||
 
@@ -517,8 +517,8 @@ static void TileLoopWaterHelper(TileInde
 

	
 
			case MP_TUNNELBRIDGE:
 
				// Middle part of bridge with clear land below?
 
				if ((_map5[target] & 0xF8) == 0xC0) {
 
					_map5[target] |= 0x08;
 
				if ((_m[target].m5 & 0xF8) == 0xC0) {
 
					_m[target].m5 |= 0x08;
 
					MarkTileDirtyByTile(tile);
 
				}
 
				break;
 
@@ -528,7 +528,7 @@ static void TileLoopWaterHelper(TileInde
 
		}
 
	} else {
 
		if (IsTileType(target, MP_TUNNELBRIDGE)) {
 
			byte m5 = _map5[target];
 
			byte m5 = _m[target].m5;
 
			if ((m5 & 0xF8) == 0xC8 || (m5 & 0xF8) == 0xF0)
 
				return;
 

	
 
@@ -650,7 +650,7 @@ static uint32 GetTileTrackStatus_Water(T
 
	if (mode != TRANSPORT_WATER)
 
		return 0;
 

	
 
	m5 = _map5[tile];
 
	m5 = _m[tile].m5;
 
	if (m5 == 0)
 
		return 0x3F3F;
 

	
 
@@ -676,7 +676,7 @@ extern void ShowShipDepotWindow(TileInde
 

	
 
static void ClickTile_Water(TileIndex tile)
 
{
 
	byte m5 = _map5[tile] - 0x80;
 
	byte m5 = _m[tile].m5 - 0x80;
 

	
 
	if (IS_BYTE_INSIDE(m5, 0, 3+1)) {
 
		if (m5 & 1)
waypoint.c
Show inline comments
 
@@ -165,7 +165,7 @@ int32 CmdBuildTrainWaypoint(int x, int y
 
	/* if custom gfx are used, make sure it is within bounds */
 
	if (p1 > 0x100 + (uint)GetCustomStationsCount(STAT_CLASS_WAYP)) return CMD_ERROR;
 

	
 
	if (!IsTileType(tile, MP_RAILWAY) || ((dir = 0, _map5[tile] != 1) && (dir = 1, _map5[tile] != 2)))
 
	if (!IsTileType(tile, MP_RAILWAY) || ((dir = 0, _m[tile].m5 != 1) && (dir = 1, _m[tile].m5 != 2)))
 
		return_cmd_error(STR_1005_NO_SUITABLE_RAILROAD_TRACK);
 

	
 
	if (!CheckTileOwnership(tile))
 
@@ -194,8 +194,8 @@ int32 CmdBuildTrainWaypoint(int x, int y
 
		ModifyTile(tile, MP_MAP5, RAIL_TYPE_WAYPOINT | dir);
 
		if (--p1 & 0x100) { // waypoint type 0 uses default graphics
 
			// custom graphics
 
			_map3_lo[tile] |= 16;
 
			_map3_hi[tile] = p1 & 0xff;
 
			_m[tile].m3 |= 16;
 
			_m[tile].m4 = p1 & 0xff;
 
		}
 

	
 
		wp->deleted = 0;
 
@@ -248,7 +248,7 @@ int32 RemoveTrainWaypoint(TileIndex tile
 
	Waypoint *wp;
 

	
 
	/* Make sure it's a waypoint */
 
	if (!IsTileType(tile, MP_RAILWAY) || !IsRailWaypoint(_map5[tile]))
 
	if (!IsTileType(tile, MP_RAILWAY) || !IsRailWaypoint(_m[tile].m5))
 
		return CMD_ERROR;
 

	
 
	if (!CheckTileOwnership(tile) && !(_current_player == OWNER_WATER))
 
@@ -258,7 +258,7 @@ int32 RemoveTrainWaypoint(TileIndex tile
 
		return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		int direction = _map5[tile] & RAIL_WAYPOINT_TRACK_MASK;
 
		int direction = _m[tile].m5 & RAIL_WAYPOINT_TRACK_MASK;
 

	
 
		wp = GetWaypointByTile(tile);
 

	
 
@@ -267,8 +267,8 @@ int32 RemoveTrainWaypoint(TileIndex tile
 

	
 
		if (justremove) {
 
			ModifyTile(tile, MP_MAP5, 1<<direction);
 
			_map3_lo[tile] &= ~16;
 
			_map3_hi[tile] = 0;
 
			_m[tile].m3 &= ~16;
 
			_m[tile].m4 = 0;
 
		} else {
 
			DoClearSquare(tile);
 
			SetSignalsOnBothDir(tile, direction);
0 comments (0 inline, 0 general)