src/rail_cmd.cpp
changeset 6902 9da0ee122fd5
parent 6889 f7f6d9cb07a0
child 6916 e87d54a598ea
equal deleted inserted replaced
6901:2201a832ae42 6902:9da0ee122fd5
   252 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   252 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   253 
   253 
   254 	switch (GetTileType(tile)) {
   254 	switch (GetTileType(tile)) {
   255 		case MP_RAILWAY:
   255 		case MP_RAILWAY:
   256 			if (!CheckTrackCombination(tile, trackbit, flags) ||
   256 			if (!CheckTrackCombination(tile, trackbit, flags) ||
   257 					!EnsureNoVehicle(tile)) {
   257 					!EnsureNoVehicleOnGround(tile)) {
   258 				return CMD_ERROR;
   258 				return CMD_ERROR;
   259 			}
   259 			}
   260 			if (!IsTileOwner(tile, _current_player) ||
   260 			if (!IsTileOwner(tile, _current_player) ||
   261 					!IsCompatibleRail(GetRailType(tile), railtype)) {
   261 					!IsCompatibleRail(GetRailType(tile), railtype)) {
   262 				// Get detailed error message
   262 				// Get detailed error message
   287 			if (!HASBIT(M(SLOPE_SEN) | M(SLOPE_ENW) | M(SLOPE_NWS) | M(SLOPE_NS) | M(SLOPE_WSE) | M(SLOPE_EW) | M(SLOPE_FLAT), tileh)) {
   287 			if (!HASBIT(M(SLOPE_SEN) | M(SLOPE_ENW) | M(SLOPE_NWS) | M(SLOPE_NS) | M(SLOPE_WSE) | M(SLOPE_EW) | M(SLOPE_FLAT), tileh)) {
   288 				return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
   288 				return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
   289 			}
   289 			}
   290 #undef M
   290 #undef M
   291 
   291 
   292 			if (!EnsureNoVehicle(tile)) return CMD_ERROR;
   292 			if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
   293 
   293 
   294 			if (GetRoadTileType(tile) == ROAD_TILE_NORMAL) {
   294 			if (GetRoadTileType(tile) == ROAD_TILE_NORMAL) {
   295 				if (HasRoadWorks(tile)) return_cmd_error(STR_ROAD_WORKS_IN_PROGRESS);
   295 				if (HasRoadWorks(tile)) return_cmd_error(STR_ROAD_WORKS_IN_PROGRESS);
   296 
   296 
   297 				if ((track == TRACK_X && GetRoadBits(tile) == ROAD_Y) ||
   297 				if ((track == TRACK_X && GetRoadBits(tile) == ROAD_Y) ||
   350 	switch (GetTileType(tile)) {
   350 	switch (GetTileType(tile)) {
   351 		case MP_STREET: {
   351 		case MP_STREET: {
   352 			if (!IsLevelCrossing(tile) ||
   352 			if (!IsLevelCrossing(tile) ||
   353 					GetCrossingRailBits(tile) != trackbit ||
   353 					GetCrossingRailBits(tile) != trackbit ||
   354 					(_current_player != OWNER_WATER && !CheckTileOwnership(tile)) ||
   354 					(_current_player != OWNER_WATER && !CheckTileOwnership(tile)) ||
   355 					!EnsureNoVehicle(tile)) {
   355 					!EnsureNoVehicleOnGround(tile)) {
   356 				return CMD_ERROR;
   356 				return CMD_ERROR;
   357 			}
   357 			}
   358 
   358 
   359 			if (flags & DC_EXEC) {
   359 			if (flags & DC_EXEC) {
   360 				MakeRoadNormal(tile, GetCrossingRoadOwner(tile), GetCrossingRoadBits(tile), GetTownIndex(tile));
   360 				MakeRoadNormal(tile, GetCrossingRoadOwner(tile), GetCrossingRoadBits(tile), GetTownIndex(tile));
   365 		case MP_RAILWAY: {
   365 		case MP_RAILWAY: {
   366 			TrackBits present;
   366 			TrackBits present;
   367 
   367 
   368 			if (!IsPlainRailTile(tile) ||
   368 			if (!IsPlainRailTile(tile) ||
   369 					(_current_player != OWNER_WATER && !CheckTileOwnership(tile)) ||
   369 					(_current_player != OWNER_WATER && !CheckTileOwnership(tile)) ||
   370 					!EnsureNoVehicle(tile)) {
   370 					!EnsureNoVehicleOnGround(tile)) {
   371 				return CMD_ERROR;
   371 				return CMD_ERROR;
   372 			}
   372 			}
   373 
   373 
   374 			present = GetTrackBits(tile);
   374 			present = GetTrackBits(tile);
   375 			if ((present & trackbit) == 0) return CMD_ERROR;
   375 			if ((present & trackbit) == 0) return CMD_ERROR;
   621 	Track track = (Track)GB(p1, 0, 3);
   621 	Track track = (Track)GB(p1, 0, 3);
   622 	bool pre_signal = HASBIT(p1, 3);
   622 	bool pre_signal = HASBIT(p1, 3);
   623 	SignalVariant sigvar = (pre_signal ^ HASBIT(p1, 4)) ? SIG_SEMAPHORE : SIG_ELECTRIC;
   623 	SignalVariant sigvar = (pre_signal ^ HASBIT(p1, 4)) ? SIG_SEMAPHORE : SIG_ELECTRIC;
   624 	int32 cost;
   624 	int32 cost;
   625 
   625 
   626 	if (!ValParamTrackOrientation(track) || !IsTileType(tile, MP_RAILWAY) || !EnsureNoVehicle(tile))
   626 	if (!ValParamTrackOrientation(track) || !IsTileType(tile, MP_RAILWAY) || !EnsureNoVehicleOnGround(tile))
   627 		return CMD_ERROR;
   627 		return CMD_ERROR;
   628 
   628 
   629 	/* Protect against invalid signal copying */
   629 	/* Protect against invalid signal copying */
   630 	if (p2 != 0 && (p2 & SignalOnTrack(track)) == 0) return CMD_ERROR;
   630 	if (p2 != 0 && (p2 & SignalOnTrack(track)) == 0) return CMD_ERROR;
   631 
   631 
   808 {
   808 {
   809 	Track track = (Track)GB(p1, 0, 3);
   809 	Track track = (Track)GB(p1, 0, 3);
   810 
   810 
   811 	if (!ValParamTrackOrientation(track) ||
   811 	if (!ValParamTrackOrientation(track) ||
   812 			!IsTileType(tile, MP_RAILWAY) ||
   812 			!IsTileType(tile, MP_RAILWAY) ||
   813 			!EnsureNoVehicle(tile) ||
   813 			!EnsureNoVehicleOnGround(tile) ||
   814 			!HasSignalOnTrack(tile, track)) {
   814 			!HasSignalOnTrack(tile, track)) {
   815 		return CMD_ERROR;
   815 		return CMD_ERROR;
   816 	}
   816 	}
   817 
   817 
   818 	/* Only water can remove signals from anyone */
   818 	/* Only water can remove signals from anyone */
   865 {
   865 {
   866 	if (!CheckTileOwnership(tile)) return CMD_ERROR;
   866 	if (!CheckTileOwnership(tile)) return CMD_ERROR;
   867 
   867 
   868 	if (GetRailType(tile) == totype) return CMD_ERROR;
   868 	if (GetRailType(tile) == totype) return CMD_ERROR;
   869 
   869 
   870 	if (!EnsureNoVehicle(tile) && (!IsCompatibleRail(GetRailType(tile), totype) || IsPlainRailTile(tile))) return CMD_ERROR;
   870 	if (!EnsureNoVehicleOnGround(tile) && (!IsCompatibleRail(GetRailType(tile), totype) || IsPlainRailTile(tile))) return CMD_ERROR;
   871 
   871 
   872 	// 'hidden' elrails can't be downgraded to normal rail when elrails are disabled
   872 	// 'hidden' elrails can't be downgraded to normal rail when elrails are disabled
   873 	if (_patches.disable_elrails && totype == RAILTYPE_RAIL && GetRailType(tile) == RAILTYPE_ELECTRIC) return CMD_ERROR;
   873 	if (_patches.disable_elrails && totype == RAILTYPE_RAIL && GetRailType(tile) == RAILTYPE_ELECTRIC) return CMD_ERROR;
   874 
   874 
   875 	// change type.
   875 	// change type.
   969 static int32 RemoveTrainDepot(TileIndex tile, uint32 flags)
   969 static int32 RemoveTrainDepot(TileIndex tile, uint32 flags)
   970 {
   970 {
   971 	if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER)
   971 	if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER)
   972 		return CMD_ERROR;
   972 		return CMD_ERROR;
   973 
   973 
   974 	if (!EnsureNoVehicle(tile))
   974 	if (!EnsureNoVehicleOnGround(tile))
   975 		return CMD_ERROR;
   975 		return CMD_ERROR;
   976 
   976 
   977 	if (flags & DC_EXEC) {
   977 	if (flags & DC_EXEC) {
   978 		DiagDirection dir = GetRailDepotDirection(tile);
   978 		DiagDirection dir = GetRailDepotDirection(tile);
   979 
   979