Changeset - r1901:e806afa50723
[Not reviewed]
master
0 25 0
tron - 19 years ago 2005-06-04 11:56:32
tron@openttd.org
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
25 files changed with 118 insertions and 122 deletions:
0 comments (0 inline, 0 general)
ai.c
Show inline comments
 
@@ -3634,14 +3634,14 @@ static void AiStateRemoveStation(Player 
 

	
 
static void AiRemovePlayerRailOrRoad(Player *p, TileIndex tile)
 
{
 
	byte m5;
 

	
 
	if (IsTileType(tile, MP_RAILWAY)) {
 
		if (_map_owner[tile] != _current_player)
 
			return;
 
		if (!IsTileOwner(tile, _current_player)) return;
 

	
 
		m5 = _map5[tile];
 
		if ((m5&~0x3) != 0xC0) {
 
is_rail_crossing:;
 
			m5 = GetRailTrackStatus(tile);
 

	
 
			if (m5 == 0xC || m5 == 0x30)
 
@@ -3693,36 +3693,35 @@ pos_3:
 
			if (GetRailTrackStatus(tile + TileOffsByDir(m5)) & _depot_bits[m5])
 
				return;
 

	
 
			DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
 
		}
 
	} else if (IsTileType(tile, MP_STREET)) {
 
		if (_map_owner[tile] != _current_player)
 
			return;
 
		if (!IsTileOwner(tile, _current_player)) return;
 

	
 
		if ( (_map5[tile]&0xF0) == 0x10)
 
			goto is_rail_crossing;
 

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

	
 
			// Check if there are any stations around.
 
			if (IsTileType(tile + TILE_XY(-1,0), MP_STATION) &&
 
					_map_owner[tile + TILE_XY(-1,0)] == _current_player)
 
					IsTileOwner(tile + TILE_XY(-1, 0), _current_player))
 
						return;
 

	
 
			if (IsTileType(tile + TILE_XY(1,0), MP_STATION) &&
 
					_map_owner[tile + TILE_XY(1,0)] == _current_player)
 
					IsTileOwner(tile + TILE_XY(1, 0), _current_player))
 
						return;
 

	
 
			if (IsTileType(tile + TILE_XY(0,-1), MP_STATION) &&
 
					_map_owner[tile + TILE_XY(0,-1)] == _current_player)
 
					IsTileOwner(tile + TILE_XY(0, -1), _current_player))
 
						return;
 

	
 
			if (IsTileType(tile + TILE_XY(0,1), MP_STATION) &&
 
					_map_owner[tile + TILE_XY(0,1)] == _current_player)
 
					IsTileOwner(tile + TILE_XY(0, 1), _current_player))
 
						return;
 

	
 
			dir = _map5[tile] & 3;
 

	
 
			DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
 
			DoCommandByTile(
 
@@ -3732,13 +3731,13 @@ pos_3:
 
				DC_EXEC,
 
				CMD_REMOVE_ROAD);
 
		}
 
	} else if (IsTileType(tile, MP_TUNNELBRIDGE)) {
 
		byte b;
 

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

	
 
		m5 = 0;
 

	
 
		b = _map5[tile] & 0x21;
 
		if (b == 0) goto pos_0;
ai_new.c
Show inline comments
 
@@ -760,13 +760,13 @@ static void AiNew_State_FindDepot(Player
 
		tile = p->ainew.path_info.route[i];
 
		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) {
 
					// We found a depot, is it ours? (TELL ME!!!)
 
					if (_map_owner[tile + TileOffsByDir(j)] == _current_player) {
 
					if (IsTileOwner(tile + TileOffsByDir(j), _current_player)) {
 
						// Now, is it pointing to the right direction.........
 
						if ((_map5[tile + TileOffsByDir(j)] & 3) == (j ^ 2)) {
 
							// Yeah!!!
 
							p->ainew.depot_tile = tile + TileOffsByDir(j);
 
							p->ainew.depot_direction = j ^ 2; // Reverse direction
 
							p->ainew.state = AI_STATE_VERIFY_ROUTE;
 
@@ -1059,13 +1059,13 @@ static void AiNew_State_BuildPath(Player
 
// Builds the depot
 
static void AiNew_State_BuildDepot(Player *p) {
 
	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 (_map_owner[p->ainew.depot_tile] == _current_player) {
 
		if (IsTileOwner(p->ainew.depot_tile, _current_player)) {
 
			// The depot is already builded!
 
			p->ainew.state = AI_STATE_BUILD_VEHICLE;
 
			return;
 
		} else {
 
			// There is a depot, but not of our team! :(
 
			p->ainew.state = AI_STATE_NOTHING;
aircraft_cmd.c
Show inline comments
 
@@ -175,13 +175,13 @@ int32 CmdBuildAircraft(int x, int y, uin
 

	
 
	if (!IsEngineBuildable(p1, VEH_Aircraft)) return CMD_ERROR;
 

	
 
	// Workaround: TODO: make AI players try to build planes in a hangar instead of just an airport tile.
 
	if (!IsAircraftHangarTile(tile) && IS_HUMAN_PLAYER(_current_player)) return CMD_ERROR;
 

	
 
	if (_map_owner[tile] != _current_player && IS_HUMAN_PLAYER(_current_player)) return CMD_ERROR;
 
	if (!IsTileOwner(tile, _current_player) && IS_HUMAN_PLAYER(_current_player)) return CMD_ERROR;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
 

	
 
	value = EstimateAircraftCost(p1);
 

	
 
	if (flags & DC_QUERY_COST) return value;
aircraft_gui.c
Show inline comments
 
@@ -196,13 +196,13 @@ static void ShowBuildAircraftWindow(uint
 
	w->vscroll.cap = 4;
 
	w->widget[2].unkA = (w->vscroll.cap << 8) + 1;
 

	
 
	w->resize.step_height = 24;
 

	
 
	if (tile != 0) {
 
		w->caption_color = _map_owner[tile];
 
		w->caption_color = GetTileOwner(tile);
 
	} else {
 
		w->caption_color = _local_player;
 
	}
 
}
 

	
 
static void AircraftRefitWndProc(Window *w, WindowEvent *e)
 
@@ -609,13 +609,14 @@ static void DrawAircraftDepotWindow(Wind
 
	Vehicle *v;
 
	int num,x,y;
 

	
 
	tile = w->window_number;
 

	
 
	/* setup disabled buttons */
 
	w->disabled_state = (_map_owner[tile]==_local_player) ? 0 : ((1<<4)|(1<<7));
 
	w->disabled_state =
 
		IsTileOwner(tile, _local_player) ? 0 : ((1 << 4) | (1 << 7));
 

	
 
	/* determine amount of items for scroller */
 
	num = 0;
 
	FOR_ALL_VEHICLES(v) {
 
		if (v->type == VEH_Aircraft && v->subtype <= 2 && v->vehstatus&VS_HIDDEN &&
 
				v->tile == (TileIndex)tile)
 
@@ -825,13 +826,13 @@ static const WindowDesc _aircraft_depot_
 
void ShowAircraftDepotWindow(uint tile)
 
{
 
	Window *w;
 

	
 
	w = AllocateWindowDescFront(&_aircraft_depot_desc, tile);
 
	if (w) {
 
		w->caption_color = _map_owner[tile];
 
		w->caption_color = GetTileOwner(tile);
 
		w->vscroll.cap = 2;
 
		w->hscroll.cap = 4;
 
		w->resize.step_width = 74;
 
		w->resize.step_height = 24;
 
		WP(w,traindepot_d).sel = INVALID_VEHICLE;
 
		_backup_orders_tile = 0;
 
@@ -1010,13 +1011,13 @@ static void PlayerAircraftWndProc(Window
 

	
 
			if (!IsWindowOfPrototype(w, _player_aircraft_widgets))
 
				break;
 

	
 
			tile = _last_built_aircraft_depot_tile;
 
			do {
 
				if (_map_owner[tile] == _local_player && IsAircraftHangarTile(tile)) {
 
				if (IsTileOwner(tile, _local_player) && IsAircraftHangarTile(tile)) {
 
					ShowAircraftDepotWindow(tile);
 
					ShowBuildAircraftWindow(tile);
 
					return;
 
				}
 

	
 
				tile = TILE_MASK(tile + 1);
clear_cmd.c
Show inline comments
 
@@ -396,13 +396,14 @@ int32 CmdPurchaseLandArea(int x, int y, 
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	tile = TILE_FROM_XY(x,y);
 

	
 
	if (!EnsureNoVehicle(tile)) return CMD_ERROR;
 

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

	
 
	cost = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	if (CmdFailed(cost)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
@@ -834,13 +835,13 @@ static const StringID _clear_land_str[4+
 
static void GetTileDesc_Clear(uint tile, TileDesc *td)
 
{
 
	int i = (_map5[tile]>>2) & 7;
 
	if (i == 0)
 
		i = (_map5[tile] & 3) + 8;
 
	td->str = _clear_land_str[i - 1];
 
	td->owner = _map_owner[tile];
 
	td->owner = GetTileOwner(tile);
 
}
 

	
 
static void ChangeTileOwner_Clear(uint tile, byte old_player, byte new_player)
 
{
 
	return;
 
}
disaster_cmd.c
Show inline comments
 
@@ -18,13 +18,13 @@ static void DisasterClearSquare(TileInde
 
{
 
	if (!EnsureNoVehicle(tile))
 
		return;
 

	
 
	switch (GetTileType(tile)) {
 
		case MP_RAILWAY:
 
			if (IS_HUMAN_PLAYER(_map_owner[tile])) DoClearSquare(tile);
 
			if (IS_HUMAN_PLAYER(GetTileOwner(tile))) DoClearSquare(tile);
 
			break;
 

	
 
		case MP_HOUSE: {
 
			byte p = _current_player;
 
			_current_player = OWNER_NONE;
 
			DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
 
@@ -170,15 +170,14 @@ static void DisasterTick_Zeppeliner(Vehi
 
			}
 
		} else if (v->current_order.station == 0) {
 
			tile = v->tile; /**/
 

	
 
			if (IsValidTile(tile) &&
 
					IsTileType(tile, MP_STATION) &&
 
				IS_BYTE_INSIDE(_map5[tile], 8, 0x43) &&
 
				IS_HUMAN_PLAYER(_map_owner[tile])) {
 

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

	
 
				SetDParam(0, _map2[tile]);
 
				AddNewsItem(STR_B000_ZEPPELIN_DISASTER_AT,
 
					NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0),
 
@@ -196,15 +195,14 @@ static void DisasterTick_Zeppeliner(Vehi
 
			return;
 

	
 
		tile = v->tile; /**/
 

	
 
		if (IsValidTile(tile) &&
 
				IsTileType(tile, MP_STATION) &&
 
			IS_BYTE_INSIDE(_map5[tile], 8, 0x43) &&
 
			IS_HUMAN_PLAYER(_map_owner[tile])) {
 

	
 
				IS_BYTE_INSIDE(_map5[tile], 8, 0x43) &&
 
				IS_HUMAN_PLAYER(GetTileOwner(tile))) {
 
			st = GetStation(_map2[tile]);
 
			CLRBITS(st->airport_flags, RUNWAY_IN_block);
 
		}
 

	
 
		SetDisasterVehiclePos(v, v->x_pos, v->y_pos, v->z_pos);
 
		DeleteDisasterVeh(v);
 
@@ -239,14 +237,14 @@ static void DisasterTick_Zeppeliner(Vehi
 
		v->age = 0;
 
	}
 

	
 
	tile = v->tile;/**/
 
	if (IsValidTile(tile) &&
 
			IsTileType(tile, MP_STATION) &&
 
		IS_BYTE_INSIDE(_map5[tile], 8, 0x43) &&
 
		IS_HUMAN_PLAYER(_map_owner[tile])) {
 
			IS_BYTE_INSIDE(_map5[tile], 8, 0x43) &&
 
			IS_HUMAN_PLAYER(GetTileOwner(tile))) {
 

	
 
		st = GetStation(_map2[tile]);
 
		SETBITS(st->airport_flags, RUNWAY_IN_block);
 
	}
 
}
 

	
 
@@ -578,14 +576,14 @@ static void DisasterTick_4(Vehicle *v)
 
		}
 
		v->current_order.station = 1;
 

	
 
		tile_org = tile = TILE_MASK(Random());
 
		do {
 
			if (IsTileType(tile, MP_RAILWAY) &&
 
					(_map5[tile]&~3)!=0xC0 &&	IS_HUMAN_PLAYER(_map_owner[tile]))
 
						break;
 
					(_map5[tile] & ~3) != 0xC0 && IS_HUMAN_PLAYER(GetTileOwner(tile)))
 
				break;
 
			tile = TILE_MASK(tile+1);
 
		} while (tile != tile_org);
 
		v->dest_tile = tile;
 
		v->age = 0;
 
	} else
 
		return;
openttd.c
Show inline comments
 
@@ -1296,13 +1296,13 @@ bool AfterLoadGame(uint version)
 
	if (version <= 0x402) {
 
		TileIndex tile = TILE_XY(0,0);
 
		uint w = MapSizeX();
 
		uint h = MapSizeY();
 

	
 
		BEGIN_TILE_LOOP(tile_cur, w, h, tile)
 
			if (IsTileType(tile_cur, MP_WATER) && _map_owner[tile_cur] >= MAX_PLAYERS)
 
			if (IsTileType(tile_cur, MP_WATER) && GetTileOwner(tile_cur) >= MAX_PLAYERS)
 
				_map_owner[tile_cur] = OWNER_WATER;
 
		END_TILE_LOOP(tile_cur, w, h, tile)
 
	}
 

	
 
	// convert road side to my format.
 
	if (_opt.road_side) _opt.road_side = 1;
 
@@ -1390,19 +1390,20 @@ bool AfterLoadGame(uint version)
 
				//XXX magic
 
				SetTileType(tile, MP_VOID);
 
				_map2[tile] = ClosestTownFromTile(tile,(uint)-1)->index;
 
				SetTileType(tile, MP_HOUSE);
 
			} else if (IsTileType(tile, MP_STREET)) {
 
				//XXX magic
 
				SetTileType(tile, MP_VOID);
 
				_map3_hi[tile] |= (_map2[tile] << 4);
 
				if ( _map_owner[tile] == OWNER_TOWN)
 
				if (IsTileOwner(tile, OWNER_TOWN)) {
 
					SetTileType(tile, MP_VOID);
 
					_map2[tile] = ClosestTownFromTile(tile,(uint)-1)->index;
 
				else
 
					SetTileType(tile, MP_STREET);
 
				} else {
 
					_map2[tile] = 0;
 
				SetTileType(tile, MP_STREET);
 
				}
 
			}
 
		} END_TILE_LOOP(tile, MapSizeX(), MapSizeY(), 0);
 
	}
 

	
 
	if (version < 0x900) {
 
		Town *t;
order_gui.c
Show inline comments
 
@@ -164,34 +164,34 @@ static Order GetOrderCmdFromTile(Vehicle
 
	int st_index;
 

	
 
	// check depot first
 
	if (_patches.gotodepot) {
 
		switch (GetTileType(tile)) {
 
		case MP_RAILWAY:
 
			if (v->type == VEH_Train && _map_owner[tile] == _local_player) {
 
			if (v->type == VEH_Train && IsTileOwner(tile, _local_player)) {
 
				if ((_map5[tile]&0xFC)==0xC0) {
 
					order.type = OT_GOTO_DEPOT;
 
					order.flags = OF_PART_OF_ORDERS;
 
					order.station = GetDepotByTile(tile)->index;
 
					return order;
 
				}
 
			}
 
			break;
 

	
 
		case MP_STREET:
 
			if ((_map5[tile] & 0xF0) == 0x20 && v->type == VEH_Road && _map_owner[tile] == _local_player) {
 
			if ((_map5[tile] & 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;
 
				return order;
 
			}
 
			break;
 

	
 
		case MP_STATION:
 
			if (v->type != VEH_Aircraft) break;
 
			if ( IsAircraftHangarTile(tile) && _map_owner[tile] == _local_player) {
 
			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];
 
				return order;
 
			}
 
			break;
 
@@ -213,16 +213,16 @@ static Order GetOrderCmdFromTile(Vehicle
 
			default:
 
				break;
 
		}
 
	}
 

	
 
	// check waypoint
 
	if (IsTileType(tile, MP_RAILWAY)
 
	&& v->type == VEH_Train
 
	&& _map_owner[tile] == _local_player
 
	&& (_map5[tile]&0xFE)==0xC4) {
 
	if (IsTileType(tile, MP_RAILWAY) &&
 
			v->type == VEH_Train &&
 
			IsTileOwner(tile, _local_player) &&
 
			(_map5[tile] & 0xFE) == 0xC4) {
 
		order.type = OT_GOTO_WAYPOINT;
 
		order.flags = 0;
 
		order.station = GetWaypointByTile(tile)->index;
 
		return order;
 
	}
 

	
pathfind.c
Show inline comments
 
@@ -130,13 +130,13 @@ static void TPFMode2(TrackPathFinder *tp
 
	int i;
 
	RememberData rd;
 
	int owner = -1;
 

	
 
	if (tpf->tracktype == TRANSPORT_RAIL) {
 
		if (IsTileType(tile, MP_RAILWAY) || IsTileType(tile, MP_STATION) || IsTileType(tile, MP_TUNNELBRIDGE)) {
 
			owner = _map_owner[tile];
 
			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)
 
				owner = -1;
 
		}
 
	}
 

	
 
@@ -147,13 +147,13 @@ static void TPFMode2(TrackPathFinder *tp
 

	
 
	/* Check in case of rail if the owner is the same */
 
	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 (owner != -1 && _map_owner[tile] != owner)
 
				if (owner != -1 && !IsTileOwner(tile, owner))
 
					return;
 
	}
 

	
 
	if (++tpf->rd.cur_length > 50)
 
		return;
 

	
 
@@ -293,13 +293,13 @@ static void TPFMode1(TrackPathFinder *tp
 
	if (tpf->tracktype == TRANSPORT_RAIL) {
 
		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 (_map_owner[tile_org] != _map_owner[tile])
 
						if (GetTileOwner(tile_org) != GetTileOwner(tile))
 
							return;
 
	}
 

	
 
	tpf->rd.cur_length++;
 

	
 
	bits = GetTileTrackStatus(tile, tpf->tracktype);
players.c
Show inline comments
 
@@ -278,14 +278,16 @@ bool CheckOwnership(byte owner)
 
	GetNameOfOwner(owner, 0);
 
	return false;
 
}
 

	
 
bool CheckTileOwnership(uint tile)
 
{
 
	byte owner = _map_owner[tile];
 
	byte owner = GetTileOwner(tile);
 

	
 
	assert(owner <= OWNER_WATER);
 

	
 
	if (owner == _current_player)
 
		return true;
 
	_error_message = STR_013B_OWNED_BY;
 

	
 
	// no need to get the name of the owner unless we're the local player (saves some time)
 
	if (_current_player == _local_player)
rail_cmd.c
Show inline comments
 
@@ -361,13 +361,13 @@ int32 CmdBuildSingleRail(int x, int y, u
 

	
 
			if ((m5 & 0xF0) == 0 && ( // normal road?
 
						(rail_bit == 1 && m5 == 0x05) ||
 
						(rail_bit == 2 && m5 == 0x0A) // correct direction?
 
					)) {
 
				if (flags & DC_EXEC) {
 
					_map3_lo[tile] = _map_owner[tile];
 
					_map3_lo[tile] = GetTileOwner(tile);
 
					_map_owner[tile] = _current_player;
 
					_map3_hi[tile] = p1;
 
					_map5[tile] = 0x10 | (rail_bit == 1 ? 0x08 : 0x00); // level crossing
 
				}
 
				break;
 
			}
 
@@ -1064,13 +1064,13 @@ static int32 ClearTile_Track(TileIndex t
 
	m5 = _map5[tile];
 

	
 
	if (flags & DC_AUTO) {
 
		if (m5 & RAIL_TYPE_SPECIAL)
 
			return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
 

	
 
		if (_map_owner[tile] != _current_player)
 
		if (!IsTileOwner(tile, _current_player))
 
			return_cmd_error(STR_1024_AREA_IS_OWNED_BY_ANOTHER);
 

	
 
		return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK);
 
	}
 

	
 
	cost = 0;
 
@@ -1321,13 +1321,13 @@ static void DrawSpecialBuilding(uint32 i
 

	
 
static void DrawTile_Track(TileInfo *ti)
 
{
 
	uint32 tracktype_offs, image;
 
	byte m5;
 

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

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

	
 
	m5 = (byte)ti->map5;
 
	if (!(m5 & RAIL_TYPE_SPECIAL)) {
 
		bool special;
 
@@ -1897,38 +1897,38 @@ static void TileLoop_Track(uint tile)
 
			a2 = RAIL_GROUND_FENCE_HORIZ2;
 
		} else if (rail == RAIL_BIT_LEFT) {
 
			a2 = RAIL_GROUND_FENCE_VERT1;
 
		} else if (rail == RAIL_BIT_RIGHT) {
 
			a2 = RAIL_GROUND_FENCE_VERT2;
 
		} else {
 
			owner = _map_owner[tile];
 
			owner = GetTileOwner(tile);
 

	
 
			if ( (!(rail&(RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LEFT)) && (rail&RAIL_BIT_DIAG1)) || rail==(RAIL_BIT_LOWER|RAIL_BIT_RIGHT)) {
 
				if (!IsTileType(tile + TILE_XY(0,-1), MP_RAILWAY) ||
 
						owner != _map_owner[tile + TILE_XY(0,-1)] ||
 
						!IsTileOwner(tile + TILE_XY(0, -1), owner) ||
 
						(_map5[tile + TILE_XY(0,-1)]==RAIL_BIT_UPPER || _map5[tile + TILE_XY(0,-1)]==RAIL_BIT_LEFT))
 
							a2 = RAIL_GROUND_FENCE_NW;
 
			}
 

	
 
			if ( (!(rail&(RAIL_BIT_DIAG2|RAIL_BIT_LOWER|RAIL_BIT_RIGHT)) && (rail&RAIL_BIT_DIAG1)) || rail==(RAIL_BIT_UPPER|RAIL_BIT_LEFT)) {
 
				if (!IsTileType(tile + TILE_XY(0,1), MP_RAILWAY) ||
 
						owner != _map_owner[tile + TILE_XY(0,1)] ||
 
						!IsTileOwner(tile + TILE_XY(0, 1), owner) ||
 
						(_map5[tile + TILE_XY(0,1)]==RAIL_BIT_LOWER || _map5[tile + TILE_XY(0,1)]==RAIL_BIT_RIGHT))
 
							a2 = (a2 == RAIL_GROUND_FENCE_NW) ? RAIL_GROUND_FENCE_SENW : RAIL_GROUND_FENCE_SE;
 
			}
 

	
 
			if ( (!(rail&(RAIL_BIT_DIAG1|RAIL_BIT_UPPER|RAIL_BIT_RIGHT)) && (rail&RAIL_BIT_DIAG2)) || rail==(RAIL_BIT_LOWER|RAIL_BIT_LEFT)) {
 
				if (!IsTileType(tile + TILE_XY(-1,0), MP_RAILWAY) ||
 
						owner != _map_owner[tile + TILE_XY(-1,0)] ||
 
						!IsTileOwner(tile + TILE_XY(-1, 0), owner) ||
 
						(_map5[tile + TILE_XY(-1,0)]==RAIL_BIT_UPPER || _map5[tile + TILE_XY(-1,0)]==RAIL_BIT_RIGHT))
 
							a2 = RAIL_GROUND_FENCE_NE;
 
			}
 

	
 
			if ( (!(rail&(RAIL_BIT_DIAG1|RAIL_BIT_LOWER|RAIL_BIT_LEFT)) && (rail&RAIL_BIT_DIAG2)) || rail==(RAIL_BIT_UPPER|RAIL_BIT_RIGHT)) {
 
				if (!IsTileType(tile + TILE_XY(1,0), MP_RAILWAY) ||
 
						owner != _map_owner[tile + TILE_XY(1,0)] ||
 
						!IsTileOwner(tile + TILE_XY(1, 0), owner) ||
 
						(_map5[tile + TILE_XY(1,0)]==RAIL_BIT_LOWER || _map5[tile + TILE_XY(1,0)]==RAIL_BIT_LEFT))
 
							a2 = (a2 == RAIL_GROUND_FENCE_NE) ? RAIL_GROUND_FENCE_NESW : RAIL_GROUND_FENCE_SW;
 
			}
 
		}
 
	}
 

	
 
@@ -1994,13 +1994,13 @@ static void ClickTile_Track(uint tile)
 
		ShowRenameWaypointWindow(GetWaypointByTile(tile));
 

	
 
}
 

	
 
static void GetTileDesc_Track(TileIndex tile, TileDesc *td)
 
{
 
	td->owner = _map_owner[tile];
 
	td->owner = GetTileOwner(tile);
 
	switch (_map5[tile] & RAIL_TYPE_MASK) {
 
		case RAIL_TYPE_NORMAL:
 
			td->str = STR_1021_RAILROAD_TRACK;
 
			break;
 

	
 
		case RAIL_TYPE_SIGNALS: {
 
@@ -2022,14 +2022,13 @@ static void GetTileDesc_Track(TileIndex 
 
			break;
 
	}
 
}
 

	
 
static void ChangeTileOwner_Track(uint tile, byte old_player, byte new_player)
 
{
 
	if (_map_owner[tile] != old_player)
 
		return;
 
	if (!IsTileOwner(tile, old_player)) return;
 

	
 
	if (new_player != 255) {
 
		_map_owner[tile] = new_player;
 
	}	else {
 
		DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
 
	}
road_cmd.c
Show inline comments
 
@@ -78,13 +78,13 @@ static bool CheckAllowRemoveRoad(uint ti
 
		return true;
 

	
 
	// A railway crossing has the road owner in the map3_lo byte.
 
	if (IsTileType(tile, MP_STREET) && (_map5[tile] & 0xF0) == 0x10) {
 
		owner = _map3_lo[tile];
 
	} else {
 
		owner = _map_owner[tile];
 
		owner = GetTileOwner(tile);
 
	}
 
	// Only do the special processing if the road is owned
 
	// by a town
 
	if (owner != OWNER_TOWN) {
 
		return owner == OWNER_NONE || CheckOwnership(owner);
 
	}
 
@@ -154,13 +154,13 @@ 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) && (_map5[tile] & 0xF0) == 0x10) {
 
		owner = _map3_lo[tile];
 
	} else
 
		owner = _map_owner[tile];
 
		owner = GetTileOwner(tile);
 

	
 
	if (owner == OWNER_TOWN && _game_mode != GM_EDITOR) {
 
		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]);
 
@@ -683,13 +683,13 @@ static int32 ClearTile_Road(uint tile, b
 
	byte m5 = _map5[tile];
 

	
 
	if ( (m5 & 0xF0) == 0) {
 
		byte b = m5 & 0xF;
 

	
 
		if (! ((1 << b) & (M(1)|M(2)|M(4)|M(8))) ) {
 
			if ( (!(flags & DC_AI_BUILDING) || _map_owner[tile]!=OWNER_TOWN) && flags&DC_AUTO)
 
			if ((!(flags & DC_AI_BUILDING) || !IsTileOwner(tile, OWNER_TOWN)) && flags & DC_AUTO)
 
				return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST);
 
		}
 
		return DoCommandByTile(tile, b, 0, flags, CMD_REMOVE_ROAD);
 
	} else if ( (m5 & 0xE0) == 0) {
 
		if (flags & DC_AUTO)
 
			return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST);
 
@@ -832,13 +832,13 @@ static void DrawTile_Road(TileInfo *ti)
 
		int player;
 
		const DrawRoadSeqStruct *drss;
 

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

	
 
		ormod = 0x315;
 
		player = _map_owner[ti->tile];
 
		player = GetTileOwner(ti->tile);
 
		if (player < MAX_PLAYERS)
 
			ormod = PLAYER_SPRITE_COLOR(player);
 

	
 
		drss = _road_display_datas[ti->map5 & 0xF];
 

	
 
		DrawGroundSprite(drss++->image);
 
@@ -1098,13 +1098,13 @@ static const StringID _road_tile_strings
 
static void GetTileDesc_Road(uint tile, TileDesc *td)
 
{
 
	int i = (_map5[tile] >> 4);
 
	if (i == 0)
 
		i = ((_map3_hi[tile] & 0x70) >> 4) + 3;
 
	td->str = _road_tile_strings[i - 1];
 
	td->owner = _map_owner[tile];
 
	td->owner = GetTileOwner(tile);
 
}
 

	
 
static const byte _roadveh_enter_depot_unk0[4] = {
 
	8, 9, 0, 1
 
};
 

	
 
@@ -1142,14 +1142,13 @@ static void ChangeTileOwner_Road(uint ti
 

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

	
 
	if (_map_owner[tile] != old_player)
 
		return;
 
	if (!IsTileOwner(tile, old_player)) return;
 

	
 
	if (new_player != 255) {
 
		_map_owner[tile] = new_player;
 
	}	else {
 
		b = _map5[tile]&0xF0;
 
		if (b == 0) {
roadveh_cmd.c
Show inline comments
 
@@ -130,13 +130,13 @@ int32 CmdBuildRoadVeh(int x, int y, uint
 
	cost = EstimateRoadVehCost(p1);
 
	if (flags & DC_QUERY_COST) return cost;
 

	
 
	/* The ai_new queries the vehicle cost before building the route,
 
	 * so we must check against cheaters no sooner than now. --pasky */
 
	if (!IsTileDepotType(tile, TRANSPORT_ROAD)) return CMD_ERROR;
 
	if (_map_owner[tile] != _current_player) return CMD_ERROR;
 
	if (!IsTileOwner(tile, _current_player)) return CMD_ERROR;
 

	
 
	v = AllocateVehicle();
 
	if (v == NULL || IsOrderPoolFull())
 
		return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
 

	
 
	/* find the first free roadveh id */
 
@@ -294,13 +294,13 @@ static const byte _road_pf_directions[16
 
static bool EnumRoadSignalFindDepot(uint tile, RoadFindDepotData *rfdd, int track, uint length, byte *state)
 
{
 
	tile += TileOffsByDir(_road_pf_directions[track]);
 

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

	
 
		if (length < rfdd->best_length) {
 
			rfdd->best_length = length;
 
			rfdd->tile = tile;
 
		}
 
	}
 
@@ -1045,17 +1045,17 @@ static int RoadFindPathToDest(Vehicle *v
 
		r = GetTileTrackStatus(tile, TRANSPORT_ROAD);
 
		signal = (uint16)(r >> 16);
 
		bitmask = (uint16)r;
 
	}
 

	
 
	if (IsTileType(tile, MP_STREET)) {
 
		if ((_map5[tile]&0xF0) == 0x20 && v->owner == _map_owner[tile])
 
		if ((_map5[tile]&0xF0) == 0x20 && IsTileOwner(tile, v->owner))
 
			/* Road crossing */
 
			bitmask |= _road_veh_fp_ax_or[_map5[tile]&3];
 
	} else if (IsTileType(tile, MP_STATION)) {
 
		if (_map_owner[tile] == OWNER_NONE || _map_owner[tile] == v->owner) {
 
		if (IsTileOwner(tile, OWNER_NONE) || IsTileOwner(tile, v->owner)) {
 
			/* Our station */
 
			Station *st = GetStation(_map2[tile]);
 
			byte val = _map5[tile];
 
			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];
roadveh_gui.c
Show inline comments
 
@@ -491,13 +491,13 @@ static void ShowBuildRoadVehWindow(TileI
 
	w->widget[2].unkA = (w->vscroll.cap << 8) + 1;
 

	
 
	w->resize.step_height = 14;
 
	w->resize.height = w->height - 14 * 4; /* Minimum of 4 vehicles in the display */
 

	
 
	if (tile != 0) {
 
		w->caption_color = _map_owner[tile];
 
		w->caption_color = GetTileOwner(tile);
 
	} else {
 
		w->caption_color = _local_player;
 
	}
 
}
 

	
 
static void DrawRoadDepotWindow(Window *w)
 
@@ -507,13 +507,14 @@ static void DrawRoadDepotWindow(Window *
 
	int num,x,y;
 
	Depot *depot;
 

	
 
	tile = w->window_number;
 

	
 
	/* setup disabled buttons */
 
	w->disabled_state = (_map_owner[tile]==_local_player) ? 0 : ((1<<4)|(1<<7));
 
	w->disabled_state =
 
		IsTileOwner(tile, _local_player) ? 0 : ((1 << 4) | (1 << 7));
 

	
 
	/* determine amount of items for scroller */
 
	num = 0;
 
	FOR_ALL_VEHICLES(v) {
 
		if (v->type == VEH_Road && v->u.road.state == 254 &&
 
				v->tile == (TileIndex)tile)
 
@@ -731,13 +732,13 @@ static const WindowDesc _road_depot_desc
 
void ShowRoadDepotWindow(uint tile)
 
{
 
	Window *w;
 

	
 
	w = AllocateWindowDescFront(&_road_depot_desc, tile);
 
	if (w) {
 
		w->caption_color = _map_owner[w->window_number];
 
		w->caption_color = GetTileOwner(w->window_number);
 
		w->hscroll.cap = 5;
 
		w->vscroll.cap = 3;
 
		w->resize.step_width = 56;
 
		w->resize.step_height = 14;
 
		WP(w,traindepot_d).sel = INVALID_VEHICLE;
 
		_backup_orders_tile = 0;
ship_cmd.c
Show inline comments
 
@@ -873,13 +873,13 @@ int32 CmdBuildShip(int x, int y, uint32 
 
	value = EstimateShipCost(p1);
 
	if (flags & DC_QUERY_COST) return value;
 

	
 
	/* The ai_new queries the vehicle cost before building the route,
 
	 * so we must check against cheaters no sooner than now. --pasky */
 
	if (!IsTileDepotType(tile, TRANSPORT_WATER)) return CMD_ERROR;
 
	if (_map_owner[tile] != _current_player) return CMD_ERROR;
 
	if (!IsTileOwner(tile, _current_player)) return CMD_ERROR;
 

	
 
	v = AllocateVehicle();
 
	if (v == NULL || IsOrderPoolFull() ||
 
			(unit_num = GetFreeUnitNumber(VEH_Ship)) > _patches.max_ships)
 
		return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
 

	
ship_gui.c
Show inline comments
 
@@ -425,13 +425,13 @@ static void ShowBuildShipWindow(TileInde
 
	w->vscroll.cap = 4;
 
	w->widget[2].unkA = (w->vscroll.cap << 8) + 1;
 

	
 
	w->resize.step_height = 24;
 

	
 
	if (tile != 0) {
 
		w->caption_color = _map_owner[tile];
 
		w->caption_color = GetTileOwner(tile);
 
	} else {
 
		w->caption_color = _local_player;
 
	}
 

	
 
}
 

	
 
@@ -585,13 +585,14 @@ static void DrawShipDepotWindow(Window *
 
	int num,x,y;
 
	Depot *depot;
 

	
 
	tile = w->window_number;
 

	
 
	/* setup disabled buttons */
 
	w->disabled_state = (_map_owner[tile]==_local_player) ? 0 : ((1<<4)|(1<<7));
 
	w->disabled_state =
 
		IsTileOwner(tile, _local_player) ? 0 : ((1 << 4) | (1 << 7));
 

	
 
	/* determine amount of items for scroller */
 
	num = 0;
 
	FOR_ALL_VEHICLES(v) {
 
		if (v->type == VEH_Ship && v->u.ship.state == 0x80 &&
 
				v->tile == (TileIndex)tile)
 
@@ -805,13 +806,13 @@ static const WindowDesc _ship_depot_desc
 
void ShowShipDepotWindow(uint tile)
 
{
 
	Window *w;
 

	
 
	w = AllocateWindowDescFront(&_ship_depot_desc,tile);
 
	if (w) {
 
		w->caption_color = _map_owner[w->window_number];
 
		w->caption_color = GetTileOwner(w->window_number);
 
		w->vscroll.cap = 2;
 
		w->hscroll.cap = 3;
 
		w->resize.step_width = 90;
 
		w->resize.step_height = 24;
 
		WP(w,traindepot_d).sel = INVALID_VEHICLE;
 
		_backup_orders_tile = 0;
 
@@ -992,13 +993,13 @@ static void PlayerShipsWndProc(Window *w
 
			if (!IsWindowOfPrototype(w, _player_ships_widgets))
 
				break;
 

	
 

	
 
			tile = _last_built_ship_depot_tile;
 
			do {
 
				if (_map_owner[tile] == _local_player && IsTileDepotType(tile, TRANSPORT_WATER)) {
 
				if (IsTileOwner(tile, _local_player) && IsTileDepotType(tile, TRANSPORT_WATER)) {
 
					ShowShipDepotWindow(tile);
 
					ShowBuildShipWindow(tile);
 
					return;
 
				}
 

	
 
				tile = TILE_MASK(tile + 1);
smallmap_gui.c
Show inline comments
 
@@ -493,18 +493,18 @@ static void DrawSmallMapVegetation(byte 
 
static uint32 _owner_colors[256];
 

	
 
static inline uint32 GetSmallMapOwnerPixels(TileIndex tile)
 
{
 
	TileType t = GetTileType(tile);
 

	
 
	if (t == MP_HOUSE || _map_owner[tile] == OWNER_TOWN) {
 
	if (t == MP_INDUSTRY) {
 
		t = 0xff;
 
	} else if (t == MP_HOUSE || IsTileOwner(tile, OWNER_TOWN)) {
 
		t = 0x80;
 
	} else if (t == MP_INDUSTRY) {
 
		t = 0xff;
 
	} else {
 
		t = _map_owner[tile];
 
		t = GetTileOwner(tile);
 
	}
 

	
 
	return _owner_colors[t];
 
}
 

	
 

	
station_cmd.c
Show inline comments
 
@@ -2100,13 +2100,13 @@ static void DrawTile_Station(TileInfo *t
 
	const DrawTileSeqStruct *dtss;
 
	const DrawTileSprites *t = NULL;
 
	byte railtype = _map3_lo[ti->tile] & 0xF;
 
	uint32 relocation = 0;
 

	
 
	{
 
		uint owner = _map_owner[ti->tile];
 
		uint owner = GetTileOwner(ti->tile);
 
		image_or_modificator = 0x315 << 16; /* NOTE: possible bug in ttd here? */
 
		if (owner < MAX_PLAYERS)
 
			image_or_modificator = PLAYER_SPRITE_COLOR(owner);
 
	}
 

	
 
	// don't show foundation for docks (docks are between 76 (0x4C) and 81 (0x51))
 
@@ -2201,13 +2201,13 @@ static void GetAcceptedCargo_Station(uin
 

	
 
static void GetTileDesc_Station(uint tile, TileDesc *td)
 
{
 
	byte m5;
 
	StringID str;
 

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

	
 
	m5 = _map5[tile];
 
	(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)) ||
 
@@ -2877,14 +2877,13 @@ void DeleteOilRig(uint tile)
 
	UpdateStationVirtCoordDirty(st);
 
	DeleteStation(st);
 
}
 

	
 
static void ChangeTileOwner_Station(uint tile, byte old_player, byte new_player)
 
{
 
	if (_map_owner[tile] != old_player)
 
		return;
 
	if (!IsTileOwner(tile, old_player)) return;
 

	
 
	if (new_player != 255) {
 
		Station *st = GetStation(_map2[tile]);
 
		_map_owner[tile] = new_player;
 
		st->owner = new_player;
 
		_global_station_sort_dirty = true; // transfer ownership of station to another player
town_cmd.c
Show inline comments
 
@@ -738,13 +738,13 @@ static int GrowTownAtRoad(Town *t, uint 
 
		// and continue the search from there.
 
		do block = Random() & 3; while (!HASBIT(mask,block));
 
		tile += ToTileIndexDiff(_roadblock_tileadd[block]);
 

	
 
		if (IsTileType(tile, MP_STREET)) {
 
			/* Don't allow building over roads of other cities */
 
			if (_map_owner[tile] == OWNER_TOWN && GetTown(_map2[tile]) != t)
 
			if (IsTileOwner(tile, OWNER_TOWN) && GetTown(_map2[tile]) != 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) */
 
				_map_owner[tile] = OWNER_TOWN;
 
				_map2[tile] = t->index;
 
@@ -1492,13 +1492,13 @@ void DeleteTown(Town *t)
 
				if (GetTown(_map2[tile]) == t)
 
					DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
 
				break;
 

	
 
			case MP_STREET:
 
			case MP_TUNNELBRIDGE:
 
				if (_map_owner[tile] == OWNER_TOWN &&
 
				if (IsTileOwner(tile, OWNER_TOWN) &&
 
						ClosestTownFromTile(tile, (uint)-1) == t)
 
					DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
 
				break;
 

	
 
			default:
 
				break;
 
@@ -1834,21 +1834,18 @@ bool CheckIfAuthorityAllows(uint tile)
 

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

	
 
	// XXX - Fix this so for a given tiletype the owner of the type is in the same variable
 
	if (IsTileType(tile, MP_STREET) && (_map5[tile] & 0xF0) == 0x10) { // rail crossing
 
		owner = _map3_lo[tile];
 
	} else
 
		owner = _map_owner[tile];
 

	
 
	if ((IsTileType(tile, MP_STREET) && owner == OWNER_TOWN) || IsTileType(tile, MP_HOUSE))
 
	if (IsTileType(tile, MP_HOUSE) || (
 
				IsTileType(tile, MP_STREET) &&
 
				((_map5[tile] & 0xF0) != 0x10 ? GetTileOwner(tile) : _map3_lo[tile]) == OWNER_TOWN
 
			))
 
		return GetTown(_map2[tile]);
 

	
 
	FOR_ALL_TOWNS(t) {
 
		if (t->xy != 0) {
 
			dist = DistanceManhattan(tile, t->xy);
 
			if (dist < best) {
train_cmd.c
Show inline comments
 
@@ -535,13 +535,13 @@ int32 CmdBuildRailVehicle(int x, int y, 
 
	if (!IsEngineBuildable(p1, VEH_Train)) return CMD_ERROR;
 

	
 
	/* Check if the train is actually being built in a depot belonging
 
	 * to the player. Doesn't matter if only the cost is queried */
 
	if (!(flags & DC_QUERY_COST)) {
 
		if (!IsTileDepotType(tile, TRANSPORT_RAIL)) return CMD_ERROR;
 
		if (_map_owner[tile] != _current_player) return CMD_ERROR;
 
		if (!IsTileOwner(tile, _current_player)) return CMD_ERROR;
 
	}
 

	
 
	_cmd_build_rail_veh_var1 = 0;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
 

	
 
@@ -1384,13 +1384,13 @@ typedef struct TrainFindDepotData {
 
	 */
 
	bool reverse;
 
} TrainFindDepotData;
 

	
 
static bool TrainFindDepotEnumProc(uint tile, TrainFindDepotData *tfdd, int track, uint length, byte *state)
 
{
 
	if (IsTileType(tile, MP_RAILWAY) && _map_owner[tile] == tfdd->owner) {
 
	if (IsTileType(tile, MP_RAILWAY) && IsTileOwner(tile, tfdd->owner)) {
 
		if ((_map5[tile] & ~0x3) == 0xC0) {
 
			if (length < tfdd->best_length) {
 
				tfdd->best_length = length;
 
				tfdd->tile = tile;
 
			}
 
			return true;
 
@@ -2311,21 +2311,21 @@ static bool CheckCompatibleRail(const Ve
 
			}
 
			break;
 

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

	
 
		default:
 
			return true;
 
	}
 

	
 
	return
 
		_map_owner[tile] == v->owner &&
 
		IsTileOwner(tile, v->owner) &&
 
		(v->subtype != TS_Front_Engine || (_map3_lo[tile] & 0xF) == v->u.rail.railtype);
 
}
 

	
 
typedef struct {
 
	byte small_turn, large_turn;
 
	byte z_up; // fraction to remove when moving up
train_gui.c
Show inline comments
 
@@ -268,13 +268,13 @@ static void ShowBuildTrainWindow(uint ti
 
	w->widget[2].unkA = (w->vscroll.cap << 8) + 1;
 

	
 
	w->resize.step_height = 14;
 
	w->resize.height = w->height - 14 * 4; /* Minimum of 4 vehicles in the display */
 

	
 
	if (tile != 0) {
 
		w->caption_color = _map_owner[tile];
 
		w->caption_color = GetTileOwner(tile);
 
		WP(w,buildtrain_d).railtype = _map3_lo[tile] & 0xF;
 
	} else {
 
		w->caption_color = _local_player;
 
		WP(w,buildtrain_d).railtype = DEREF_PLAYER(_local_player)->max_railtype - 1;
 
	}
 
}
 
@@ -304,13 +304,14 @@ static void DrawTrainDepotWindow(Window 
 
	int num,x,y,i, hnum;
 
	Depot *depot;
 

	
 
	tile = w->window_number;
 

	
 
	/* setup disabled buttons */
 
	w->disabled_state = (_map_owner[tile]==_local_player) ? 0 : ((1<<4)|(1<<5)|(1<<8));
 
	w->disabled_state =
 
		IsTileOwner(tile, _local_player) ? 0 : ((1 << 4) | (1 << 5) | (1 << 8));
 

	
 
	/* determine amount of items for scroller */
 
	num = 0;
 
	hnum = 1;
 
	FOR_ALL_VEHICLES(v) {
 
		if (v->type == VEH_Train &&
 
@@ -648,13 +649,13 @@ static const WindowDesc _train_depot_des
 
void ShowTrainDepotWindow(uint tile)
 
{
 
	Window *w;
 

	
 
	w = AllocateWindowDescFront(&_train_depot_desc, tile);
 
	if (w) {
 
		w->caption_color = _map_owner[w->window_number];
 
		w->caption_color = GetTileOwner(w->window_number);
 
		w->vscroll.cap = 6;
 
		w->hscroll.cap = 10;
 
		w->resize.step_width = 29;
 
		w->resize.step_height = 14;
 
		WP(w,traindepot_d).sel = INVALID_VEHICLE;
 
		_backup_orders_tile = 0;
 
@@ -1342,13 +1343,13 @@ static void PlayerTrainsWndProc(Window *
 

	
 
			if (!IsWindowOfPrototype(w, _player_trains_widgets))
 
				break;
 

	
 
			tile = _last_built_train_depot_tile;
 
			do {
 
				if (_map_owner[tile] == _local_player && IsTileDepotType(tile, TRANSPORT_RAIL)) {
 
				if (IsTileOwner(tile, _local_player) && IsTileDepotType(tile, TRANSPORT_RAIL)) {
 
					ShowTrainDepotWindow(tile);
 
					ShowBuildTrainWindow(tile);
 
					return;
 
				}
 

	
 
				tile = TILE_MASK(tile + 1);
tree_cmd.c
Show inline comments
 
@@ -192,13 +192,13 @@ int32 CmdPlantTree(int ex, int ey, uint3
 
					}
 
					// 2x as expensive to add more trees to an existing tile
 
					cost += _price.build_trees * 2;
 
					break;
 

	
 
				case MP_CLEAR:
 
					if (_map_owner[ti.tile] != OWNER_NONE) {
 
					if (!IsTileOwner(ti.tile, OWNER_NONE)) {
 
						_error_message = STR_2804_SITE_UNSUITABLE;
 
						continue;
 
					}
 

	
 
					// it's expensive to clear farmland
 
					if ((ti.map5 & 0x1F) == 0xF)
 
@@ -393,13 +393,13 @@ static void GetAcceptedCargo_Trees(uint 
 

	
 
static void GetTileDesc_Trees(uint tile, TileDesc *td)
 
{
 
	byte b;
 
	StringID str;
 

	
 
	td->owner = _map_owner[tile];
 
	td->owner = GetTileOwner(tile);
 

	
 
	b = _map3_lo[tile];
 
	(str=STR_2810_CACTUS_PLANTS, b==0x1B) ||
 
	(str=STR_280F_RAINFOREST, IS_BYTE_INSIDE(b, 0x14, 0x1A+1)) ||
 
	(str=STR_280E_TREES, true);
 
	td->str = str;
tunnelbridge_cmd.c
Show inline comments
 
@@ -625,25 +625,25 @@ static int32 DoClearTunnel(uint tile, ui
 
	static const byte _updsignals_tunnel_dir[4] = { 5, 7, 1, 3};
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	// in scenario editor you can always destroy tunnels
 
	if (_game_mode != GM_EDITOR && !CheckTileOwnership(tile)) {
 
		if (!(_patches.extra_dynamite || _cheats.magic_bulldozer.value) || _map_owner[tile] != OWNER_TOWN)
 
		if (!(_patches.extra_dynamite || _cheats.magic_bulldozer.value) || !IsTileOwner(tile, OWNER_TOWN))
 
			return CMD_ERROR;
 
	}
 

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

	
 
	_build_tunnel_endtile = endtile;
 

	
 
	t = ClosestTownFromTile(tile, (uint)-1); //needed for town rating penalty
 
	// check if you're allowed to remove the tunnel owned by a town
 
	// removal allowal depends on difficulty settings
 
	if(_map_owner[tile] == OWNER_TOWN && _game_mode != GM_EDITOR ) {
 
	if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
 
		if (!CheckforTownRating(tile, flags, t, TUNNELBRIDGE_REMOVE)) {
 
			SetDParam(0, t->index);
 
			return_cmd_error(STR_2009_LOCAL_AUTHORITY_REFUSES);
 
		}
 
	}
 

	
 
@@ -653,13 +653,13 @@ static int32 DoClearTunnel(uint tile, ui
 
		byte tile_dir = _map5[tile]&3;
 
		byte endtile_dir = _map5[endtile]&3;
 
		DoClearSquare(tile);
 
		DoClearSquare(endtile);
 
		UpdateSignalsOnSegment(tile, _updsignals_tunnel_dir[tile_dir]);
 
		UpdateSignalsOnSegment(endtile, _updsignals_tunnel_dir[endtile_dir]);
 
		if (_map_owner[tile] == OWNER_TOWN && _game_mode != GM_EDITOR)
 
		if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR)
 
			ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM);
 
	}
 
	return  _price.clear_tunnel * (length + 1);
 
}
 

	
 
static uint FindEdgesOfBridge(uint tile, uint *endtile)
 
@@ -733,13 +733,13 @@ static int32 DoClearBridge(uint tile, ui
 
	}
 

	
 
	tile = FindEdgesOfBridge(tile, &endtile);
 

	
 
	// floods, scenario editor can always destroy bridges
 
	if (_current_player != OWNER_WATER && _game_mode != GM_EDITOR && !CheckTileOwnership(tile)) {
 
		if (!(_patches.extra_dynamite || _cheats.magic_bulldozer.value) || _map_owner[tile] != OWNER_TOWN)
 
		if (!(_patches.extra_dynamite || _cheats.magic_bulldozer.value) || !IsTileOwner(tile, OWNER_TOWN))
 
			return CMD_ERROR;
 
	}
 

	
 
	if (!EnsureNoVehicle(tile) || !EnsureNoVehicle(endtile))
 
		return CMD_ERROR;
 

	
 
@@ -760,25 +760,25 @@ static int32 DoClearBridge(uint tile, ui
 
	endtile	+= direction ? TILE_XY(0, 1) : TILE_XY( 1,0);
 

	
 

	
 
	t = ClosestTownFromTile(tile, (uint)-1); //needed for town rating penalty
 
	// check if you're allowed to remove the bridge owned by a town.
 
	// removal allowal depends on difficulty settings
 
	if(_map_owner[tile] == OWNER_TOWN && _game_mode != GM_EDITOR) {
 
	if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
 
		if (!CheckforTownRating(tile, flags, t, TUNNELBRIDGE_REMOVE))
 
			return CMD_ERROR;
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		byte m5;
 
		uint c = tile;
 
		uint16 new_data;
 

	
 
		//checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until
 
		// you have a "Poor" (0) town rating
 
		if (_map_owner[tile] == OWNER_TOWN && _game_mode != GM_EDITOR)
 
		if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR)
 
			ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM);
 

	
 
		do {
 
			m5 = _map5[c];
 

	
 
			if (m5 & 0x40) {
 
@@ -1278,13 +1278,13 @@ static void GetTileDesc_TunnelBridge(uin
 
		/* scan to the end of the bridge, that's where the owner is stored */
 
		if (_map5[tile] & 0x40) {
 
			delta = _map5[tile] & 1 ? TILE_XY(0,-1) : TILE_XY(-1,0);
 
			do tile += delta; while (_map5[tile] & 0x40);
 
		}
 
	}
 
	td->owner = _map_owner[tile];
 
	td->owner = GetTileOwner(tile);
 
}
 

	
 

	
 
static void AnimateTile_TunnelBridge(uint tile)
 
{
 
	/* not used */
 
@@ -1367,14 +1367,13 @@ static uint32 GetTileTrackStatus_TunnelB
 
	}
 
	return 0;
 
}
 

	
 
static void ChangeTileOwner_TunnelBridge(uint tile, byte old_player, byte new_player)
 
{
 
	if (_map_owner[tile] != old_player)
 
		return;
 
	if (!IsTileOwner(tile, old_player)) return;
 

	
 
	if (new_player != 255) {
 
		_map_owner[tile] = new_player;
 
	}	else {
 
		if((_map5[tile] & 0xC0)==0xC0) {
 
			// the stuff BELOW the middle part is owned by the deleted player.
unmovable_cmd.c
Show inline comments
 
@@ -119,24 +119,24 @@ static void DrawTile_Unmovable(TileInfo 
 
	if (!(ti->map5 & 0x80)) {
 
		if (ti->map5 == 2) {
 

	
 
			// statue
 
			DrawGroundSprite(0x58C);
 

	
 
			image = PLAYER_SPRITE_COLOR(_map_owner[ti->tile]);
 
			image = PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile));
 
			image += 0x8A48;
 
			if (_display_opt & DO_TRANS_BUILDINGS)
 
				image = (image & 0x3FFF) | 0x3224000;
 
			AddSortableSpriteToDraw(image, ti->x, ti->y, 16, 16, 25, ti->z);
 
		} else if (ti->map5 == 3) {
 

	
 
			// "owned by" sign
 
			DrawClearLandTile(ti, 0);
 

	
 
			AddSortableSpriteToDraw(
 
				PLAYER_SPRITE_COLOR(_map_owner[ti->tile]) + 0x92B6,
 
				PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)) + 0x92B6,
 
				ti->x+8, ti->y+8,
 
				1, 1,
 
				10,
 
				GetSlopeZ(ti->x+8, ti->y+8)
 
			);
 
		} else {
 
@@ -162,13 +162,13 @@ static void DrawTile_Unmovable(TileInfo 
 
	} else {
 
		const DrawTileSeqStruct *dtss;
 
		const DrawTileSprites *t;
 

	
 
		if (ti->tileh) DrawFoundation(ti, ti->tileh);
 

	
 
		ormod = PLAYER_SPRITE_COLOR(_map_owner[ti->tile]);
 
		ormod = PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile));
 

	
 
		t = &_unmovable_display_datas[ti->map5 & 0x7F];
 
		DrawGroundSprite(t->ground_sprite | ormod);
 

	
 
		foreach_draw_tile_seq(dtss, t->seq) {
 
			image =	dtss->image;
 
@@ -252,13 +252,13 @@ static const StringID _unmovable_tile_st
 

	
 
static void GetTileDesc_Unmovable(uint tile, TileDesc *td)
 
{
 
	int i = _map5[tile];
 
	if (i & 0x80) i = -1;
 
	td->str = _unmovable_tile_str[i + 1];
 
	td->owner = _map_owner[tile];
 
	td->owner = GetTileOwner(tile);
 
}
 

	
 
static void AnimateTile_Unmovable(uint tile)
 
{
 
	/* not used */
 
}
 
@@ -305,13 +305,13 @@ static uint32 GetTileTrackStatus_Unmovab
 
	return 0;
 
}
 

	
 
static void ClickTile_Unmovable(uint tile)
 
{
 
	if (_map5[tile] & 0x80) {
 
		ShowPlayerCompany(_map_owner[tile]);
 
		ShowPlayerCompany(GetTileOwner(tile));
 
	}
 
}
 

	
 
static const TileIndexDiffC _tile_add[] = {
 
	{ 1,  0},
 
	{ 0,  1},
 
@@ -393,14 +393,13 @@ restart:
 
		_map_owner[tile] = OWNER_NONE;
 
	} while (--i);
 
}
 

	
 
static void ChangeTileOwner_Unmovable(uint tile, byte old_player, byte new_player)
 
{
 
	if (_map_owner[tile] != old_player)
 
		return;
 
	if (!IsTileOwner(tile, old_player)) return;
 

	
 
	if (_map5[tile]==3 && new_player != 255) {
 
		_map_owner[tile] = new_player;
 
	}	else {
 
		DoClearSquare(tile);
 
	}
water_cmd.c
Show inline comments
 
@@ -418,13 +418,13 @@ static void DrawTile_Water(TileInfo *ti)
 
	if ((ti->map5 & 0xF0) == 0x10) {
 
		const WaterDrawTileStruct *t = _shiplift_display_seq[ti->map5 & 0xF];
 
		DrawWaterStuff(ti, t, 0, ti->z > t[3].delta_y ? 24 : 0);
 
		return;
 
	}
 

	
 
	DrawWaterStuff(ti, _shipdepot_display_seq[ti->map5 & 0x7F], PLAYER_SPRITE_COLOR(_map_owner[ti->tile]), 0);
 
	DrawWaterStuff(ti, _shipdepot_display_seq[ti->map5 & 0x7F], PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)), 0);
 
}
 

	
 
void DrawShipDepotSprite(int x, int y, int image)
 
{
 
	const WaterDrawTileStruct *wdts = _shipdepot_display_seq[image];
 

	
 
@@ -462,13 +462,13 @@ static void GetTileDesc_Water(uint tile,
 
		td->str = STR_3805_COAST_OR_RIVERBANK;
 
	else if ((_map5[tile]&0xF0) == 0x10)
 
		td->str = STR_LANDINFO_LOCK;
 
	else
 
		td->str = STR_3806_SHIP_DEPOT;
 

	
 
	td->owner = _map_owner[tile];
 
	td->owner = GetTileOwner(tile);
 
}
 

	
 
static void AnimateTile_Water(uint tile)
 
{
 
	/* not used */
 
}
 
@@ -683,14 +683,13 @@ static void ClickTile_Water(uint tile)
 
		ShowShipDepotWindow(tile);
 
	}
 
}
 

	
 
static void ChangeTileOwner_Water(uint tile, byte old_player, byte new_player)
 
{
 
	if (_map_owner[tile] != old_player)
 
		return;
 
	if (!IsTileOwner(tile, old_player)) return;
 

	
 
	if (new_player != 255) {
 
		_map_owner[tile] = new_player;
 
	} else {
 
		DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
 
	}
0 comments (0 inline, 0 general)