road_cmd.c
changeset 1927 4126e0e3e884
parent 1902 5d653da1abb7
child 1942 634961366cdc
equal deleted inserted replaced
1926:68d60188a22f 1927:4126e0e3e884
    30 	switch (GetTileType(tile)) {
    30 	switch (GetTileType(tile)) {
    31 	case MP_STREET:
    31 	case MP_STREET:
    32 		b = _map5[tile];
    32 		b = _map5[tile];
    33 
    33 
    34 		if ((b & 0xF0) == 0) {
    34 		if ((b & 0xF0) == 0) {
    35 		} else if ((b & 0xF0) == 0x10) {
    35 		} else if (IsLevelCrossing(tile)) {
    36 			b = (b&8)?5:10;
    36 			b = (b&8)?5:10;
    37 		} else if ((b & 0xF0) == 0x20) {
    37 		} else if ((b & 0xF0) == 0x20) {
    38 			return (~b & 3) == i;
    38 			return (~b & 3) == i;
    39 		} else
    39 		} else
    40 			return false;
    40 			return false;
    76 	// Only do the special processing for actual players.
    76 	// Only do the special processing for actual players.
    77 	if (_current_player >= MAX_PLAYERS)
    77 	if (_current_player >= MAX_PLAYERS)
    78 		return true;
    78 		return true;
    79 
    79 
    80 	// A railway crossing has the road owner in the map3_lo byte.
    80 	// A railway crossing has the road owner in the map3_lo byte.
    81 	if (IsTileType(tile, MP_STREET) && (_map5[tile] & 0xF0) == 0x10) {
    81 	if (IsTileType(tile, MP_STREET) && IsLevelCrossing(tile)) {
    82 		owner = _map3_lo[tile];
    82 		owner = _map3_lo[tile];
    83 	} else {
    83 	} else {
    84 		owner = GetTileOwner(tile);
    84 		owner = GetTileOwner(tile);
    85 	}
    85 	}
    86 	// Only do the special processing if the road is owned
    86 	// Only do the special processing if the road is owned
   152 	FindLandscapeHeight(&ti, x, y);
   152 	FindLandscapeHeight(&ti, x, y);
   153 	tile = ti.tile;
   153 	tile = ti.tile;
   154 
   154 
   155 	// owner for railraod crossing is stored somewhere else
   155 	// owner for railraod crossing is stored somewhere else
   156 	// XXX - Fix this so for a given tiletype the owner of the type is in the same variable
   156 	// XXX - Fix this so for a given tiletype the owner of the type is in the same variable
   157 	if (IsTileType(tile, MP_STREET) && (_map5[tile] & 0xF0) == 0x10) {
   157 	if (IsTileType(tile, MP_STREET) && IsLevelCrossing(tile)) {
   158 		owner = _map3_lo[tile];
   158 		owner = _map3_lo[tile];
   159 	} else
   159 	} else
   160 		owner = GetTileOwner(tile);
   160 		owner = GetTileOwner(tile);
   161 
   161 
   162 	if (owner == OWNER_TOWN && _game_mode != GM_EDITOR) {
   162 	if (owner == OWNER_TOWN && _game_mode != GM_EDITOR) {
   481 }
   481 }
   482 
   482 
   483 int32 DoConvertStreetRail(uint tile, uint totype, bool exec)
   483 int32 DoConvertStreetRail(uint tile, uint totype, bool exec)
   484 {
   484 {
   485 	// not a railroad crossing?
   485 	// not a railroad crossing?
   486 	if ((_map5[tile] & 0xF0) != 0x10) return CMD_ERROR;
   486 	if (!IsLevelCrossing(tile)) return CMD_ERROR;
   487 
   487 
   488 	// not owned by me?
   488 	// not owned by me?
   489 	if (!CheckTileOwnership(tile) || !EnsureNoVehicle(tile)) return CMD_ERROR;
   489 	if (!CheckTileOwnership(tile) || !EnsureNoVehicle(tile)) return CMD_ERROR;
   490 
   490 
   491 	// tile is already of requested type?
   491 	// tile is already of requested type?
   935 	/* not used */
   935 	/* not used */
   936 }
   936 }
   937 
   937 
   938 static void AnimateTile_Road(uint tile)
   938 static void AnimateTile_Road(uint tile)
   939 {
   939 {
   940 	if ((_map5[tile] & 0xF0) == 0x10) {
   940 	if (IsLevelCrossing(tile)) {
   941 		MarkTileDirtyByTile(tile);
   941 		MarkTileDirtyByTile(tile);
   942 	}
   942 	}
   943 }
   943 }
   944 
   944 
   945 static const byte _town_road_types[5][2] = {
   945 static const byte _town_road_types[5][2] = {
  1055 	0x0, 0x0, 0x0, 0x10, 0x0, 0x2, 0x8, 0x1A, 0x0, 0x4, 0x1, 0x15, 0x20, 0x26, 0x29, 0x3F,
  1055 	0x0, 0x0, 0x0, 0x10, 0x0, 0x2, 0x8, 0x1A, 0x0, 0x4, 0x1, 0x15, 0x20, 0x26, 0x29, 0x3F,
  1056 };
  1056 };
  1057 
  1057 
  1058 static uint32 GetTileTrackStatus_Road(uint tile, TransportType mode)	{
  1058 static uint32 GetTileTrackStatus_Road(uint tile, TransportType mode)	{
  1059 	if (mode == TRANSPORT_RAIL) {
  1059 	if (mode == TRANSPORT_RAIL) {
  1060 		if ((_map5[tile] & 0xF0) != 0x10)
  1060 		if (!IsLevelCrossing(tile))
  1061 			return 0;
  1061 			return 0;
  1062 		return _map5[tile] & 8 ? 0x101 : 0x202;
  1062 		return _map5[tile] & 8 ? 0x101 : 0x202;
  1063 	} else if  (mode == TRANSPORT_ROAD) {
  1063 	} else if  (mode == TRANSPORT_ROAD) {
  1064 		byte b = _map5[tile];
  1064 		byte b = _map5[tile];
  1065 		if ((b & 0xF0) == 0) {
  1065 		if ((b & 0xF0) == 0) {
  1066 			/* Ordinary road */
  1066 			/* Ordinary road */
  1067 			if (!_road_special_gettrackstatus && ((_map3_hi[tile]&0x70) >> 4) >= 6)
  1067 			if (!_road_special_gettrackstatus && ((_map3_hi[tile]&0x70) >> 4) >= 6)
  1068 				return 0;
  1068 				return 0;
  1069 			return _road_trackbits[b&0xF] * 0x101;
  1069 			return _road_trackbits[b&0xF] * 0x101;
  1070 		} else if ((b&0xF0) == 0x10) {
  1070 		} else if (IsLevelCrossing(tile)) {
  1071 			/* Crossing */
  1071 			/* Crossing */
  1072 			uint32 r = 0x101;
  1072 			uint32 r = 0x101;
  1073 			if (b&8) r <<= 1;
  1073 			if (b&8) r <<= 1;
  1074 
  1074 
  1075 			if (b&4) {
  1075 			if (b&4) {
  1108 	8, 9, 0, 1
  1108 	8, 9, 0, 1
  1109 };
  1109 };
  1110 
  1110 
  1111 static uint32 VehicleEnter_Road(Vehicle *v, uint tile, int x, int y)
  1111 static uint32 VehicleEnter_Road(Vehicle *v, uint tile, int x, int y)
  1112 {
  1112 {
  1113 	if ((_map5[tile] & 0xF0) == 0x10)	{
  1113 	if (IsLevelCrossing(tile)) {
  1114 		if (v->type == VEH_Train && (_map5[tile] & 4) == 0) {
  1114 		if (v->type == VEH_Train && (_map5[tile] & 4) == 0) {
  1115 			/* train crossing a road */
  1115 			/* train crossing a road */
  1116 			SndPlayVehicleFx(SND_0E_LEVEL_CROSSING, v);
  1116 			SndPlayVehicleFx(SND_0E_LEVEL_CROSSING, v);
  1117 			_map5[tile] |= 4;
  1117 			_map5[tile] |= 4;
  1118 			MarkTileDirtyByTile(tile);
  1118 			MarkTileDirtyByTile(tile);
  1128 	return 0;
  1128 	return 0;
  1129 }
  1129 }
  1130 
  1130 
  1131 static void VehicleLeave_Road(Vehicle *v, uint tile, int x, int y)
  1131 static void VehicleLeave_Road(Vehicle *v, uint tile, int x, int y)
  1132 {
  1132 {
  1133 	if ((_map5[tile] & 0xF0) == 0x10 && v->type == VEH_Train && v->next == NULL) {
  1133 	if (IsLevelCrossing(tile) && v->type == VEH_Train && v->next == NULL) {
       
  1134 		// Turn off level crossing lights
  1134 		_map5[tile] &= ~4;
  1135 		_map5[tile] &= ~4;
  1135 		MarkTileDirtyByTile(tile);
  1136 		MarkTileDirtyByTile(tile);
  1136 	}
  1137 	}
  1137 }
  1138 }
  1138 
  1139 
  1139 static void ChangeTileOwner_Road(uint tile, byte old_player, byte new_player)
  1140 static void ChangeTileOwner_Road(uint tile, byte old_player, byte new_player)
  1140 {
  1141 {
  1141 	byte b;
  1142 	byte b;
  1142 
  1143 
  1143 	// road/rail crossing where the road is owned by the current player?
  1144 	// road/rail crossing where the road is owned by the current player?
  1144 	if (old_player == _map3_lo[tile] && (_map5[tile]&0xF0) == 0x10) {
  1145 	if (old_player == _map3_lo[tile] && IsLevelCrossing(tile)) {
  1145 		_map3_lo[tile] = (new_player == 0xFF) ? OWNER_NONE : new_player;
  1146 		_map3_lo[tile] = (new_player == 0xFF) ? OWNER_NONE : new_player;
  1146 	}
  1147 	}
  1147 
  1148 
  1148 	if (!IsTileOwner(tile, old_player)) return;
  1149 	if (!IsTileOwner(tile, old_player)) return;
  1149 
  1150 
  1151 		SetTileOwner(tile, new_player);
  1152 		SetTileOwner(tile, new_player);
  1152 	}	else {
  1153 	}	else {
  1153 		b = _map5[tile]&0xF0;
  1154 		b = _map5[tile]&0xF0;
  1154 		if (b == 0) {
  1155 		if (b == 0) {
  1155 			SetTileOwner(tile, OWNER_NONE);
  1156 			SetTileOwner(tile, OWNER_NONE);
  1156 		} else if (b == 0x10) {
  1157 		} else if (IsLevelCrossing(tile)) {
  1157 			_map5[tile] = (_map5[tile]&8) ? 0x5 : 0xA;
  1158 			_map5[tile] = (_map5[tile]&8) ? 0x5 : 0xA;
  1158 			SetTileOwner(tile, _map3_lo[tile]);
  1159 			SetTileOwner(tile, _map3_lo[tile]);
  1159 			_map3_lo[tile] = 0;
  1160 			_map3_lo[tile] = 0;
  1160 			_map3_hi[tile] &= 0x80;
  1161 			_map3_hi[tile] &= 0x80;
  1161 		} else {
  1162 		} else {