933 do { |
933 do { |
934 TileIndex tile = tile_org; |
934 TileIndex tile = tile_org; |
935 int w = plat_len; |
935 int w = plat_len; |
936 do { |
936 do { |
937 byte layout = *layout_ptr++; |
937 byte layout = *layout_ptr++; |
938 MakeRailStation(tile, st->owner, st->index, axis, layout, (RailType)GB(p2, 0, 4)); |
938 MakeRailStation(tile, st->owner, st->index, axis, layout & ~1, (RailType)GB(p2, 0, 4)); |
939 SetCustomStationSpecIndex(tile, specindex); |
939 SetCustomStationSpecIndex(tile, specindex); |
940 SetStationTileRandomBits(tile, GB(Random(), 0, 4)); |
940 SetStationTileRandomBits(tile, GB(Random(), 0, 4)); |
941 |
941 |
942 if (statspec != NULL) { |
942 if (statspec != NULL) { |
943 /* Use a fixed axis for GetPlatformInfo as our platforms / numtracks are always the right way around */ |
943 /* Use a fixed axis for GetPlatformInfo as our platforms / numtracks are always the right way around */ |
944 uint32 platinfo = GetPlatformInfo(AXIS_X, 0, plat_len, numtracks_orig, plat_len - w, numtracks_orig - numtracks, false); |
944 uint32 platinfo = GetPlatformInfo(AXIS_X, 0, plat_len, numtracks_orig, plat_len - w, numtracks_orig - numtracks, false); |
945 uint16 callback = GetStationCallback(CBID_STATION_TILE_LAYOUT, platinfo, 0, statspec, st, tile); |
945 uint16 callback = GetStationCallback(CBID_STATION_TILE_LAYOUT, platinfo, 0, statspec, st, tile); |
946 if (callback != CALLBACK_FAILED && callback < 8) SetStationGfx(tile, callback + axis); |
946 if (callback != CALLBACK_FAILED && callback < 8) SetStationGfx(tile, (callback & ~1) + axis); |
947 } |
947 } |
948 |
948 |
949 tile += tile_delta; |
949 tile += tile_delta; |
950 } while (--w); |
950 } while (--w); |
951 SetSignalsOnBothDir(tile_org, track); |
951 SetSignalsOnBothDir(tile_org, track); |
1023 |
1023 |
1024 /** Remove a single tile from a railroad station. |
1024 /** Remove a single tile from a railroad station. |
1025 * This allows for custom-built station with holes and weird layouts |
1025 * This allows for custom-built station with holes and weird layouts |
1026 * @param tile tile of station piece to remove |
1026 * @param tile tile of station piece to remove |
1027 * @param flags operation to perform |
1027 * @param flags operation to perform |
1028 * @param p1 unused |
1028 * @param p1 start_tile |
1029 * @param p2 unused |
1029 * @param p2 unused |
1030 */ |
1030 */ |
1031 int32 CmdRemoveFromRailroadStation(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
1031 int32 CmdRemoveFromRailroadStation(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
1032 { |
1032 { |
|
1033 TileIndex start = p1 == 0 ? tile : p1; |
|
1034 |
|
1035 /* Count of the number of tiles removed */ |
|
1036 int quantity = 0; |
|
1037 |
|
1038 if (tile >= MapSize() || start >= MapSize()) return CMD_ERROR; |
|
1039 |
|
1040 /* make sure sx,sy are smaller than ex,ey */ |
|
1041 int ex = TileX(tile); |
|
1042 int ey = TileY(tile); |
|
1043 int sx = TileX(start); |
|
1044 int sy = TileY(start); |
|
1045 if (ex < sx) Swap(ex, sx); |
|
1046 if (ey < sy) Swap(ey, sy); |
|
1047 tile = TileXY(sx, sy); |
|
1048 |
|
1049 int size_x = ex - sx + 1; |
|
1050 int size_y = ey - sy + 1; |
|
1051 |
1033 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
1052 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
1034 |
1053 |
1035 // make sure the specified tile belongs to the current player, and that it is a railroad station. |
1054 /* Do the action for every tile into the area */ |
1036 if (!IsTileType(tile, MP_STATION) || !IsRailwayStation(tile) || !_patches.nonuniform_stations) return CMD_ERROR; |
1055 BEGIN_TILE_LOOP(tile2, size_x, size_y, tile) { |
1037 Station *st = GetStationByTile(tile); |
1056 /* Make sure the specified tile belongs to the current player, and that it is a railroad station. */ |
1038 if (_current_player != OWNER_WATER && (!CheckOwnership(st->owner) || !EnsureNoVehicle(tile))) return CMD_ERROR; |
1057 if (!IsTileType(tile2, MP_STATION) || !IsRailwayStation(tile2) || !_patches.nonuniform_stations) { |
1039 |
1058 continue; |
1040 // if we reached here, it means we can actually delete it. do that. |
1059 } |
1041 if (flags & DC_EXEC) { |
1060 |
1042 uint specindex = GetCustomStationSpecIndex(tile); |
1061 /* Check ownership of station */ |
1043 Track track = GetRailStationTrack(tile); |
1062 Station *st = GetStationByTile(tile2); |
1044 DoClearSquare(tile); |
1063 if (_current_player != OWNER_WATER && (!CheckOwnership(st->owner) || !EnsureNoVehicle(tile2))) { |
1045 st->rect.AfterRemoveTile(st, tile); |
1064 continue; |
1046 SetSignalsOnBothDir(tile, track); |
1065 } |
1047 YapfNotifyTrackLayoutChange(tile, track); |
1066 |
1048 |
1067 /* If we reached here, the tile is valid so increase the quantity of tiles we will remove */ |
1049 DeallocateSpecFromStation(st, specindex); |
1068 quantity++; |
1050 |
1069 |
1051 // now we need to make the "spanned" area of the railway station smaller if we deleted something at the edges. |
1070 if (flags & DC_EXEC) { |
1052 // we also need to adjust train_tile. |
1071 uint specindex = GetCustomStationSpecIndex(tile2); |
1053 MakeRailwayStationAreaSmaller(st); |
1072 Track track = GetRailStationTrack(tile2); |
1054 st->MarkTilesDirty(); |
1073 DoClearSquare(tile2); |
1055 UpdateStationSignCoord(st); |
1074 st->rect.AfterRemoveTile(st, tile2); |
1056 |
1075 SetSignalsOnBothDir(tile2, track); |
1057 // if we deleted the whole station, delete the train facility. |
1076 YapfNotifyTrackLayoutChange(tile2, track); |
1058 if (st->train_tile == 0) { |
1077 |
1059 st->facilities &= ~FACIL_TRAIN; |
1078 DeallocateSpecFromStation(st, specindex); |
1060 UpdateStationVirtCoordDirty(st); |
1079 |
1061 DeleteStationIfEmpty(st); |
1080 // now we need to make the "spanned" area of the railway station smaller if we deleted something at the edges. |
1062 } |
1081 // we also need to adjust train_tile. |
1063 } |
1082 MakeRailwayStationAreaSmaller(st); |
1064 return _price.remove_rail_station; |
1083 st->MarkTilesDirty(); |
|
1084 UpdateStationSignCoord(st); |
|
1085 |
|
1086 // if we deleted the whole station, delete the train facility. |
|
1087 if (st->train_tile == 0) { |
|
1088 st->facilities &= ~FACIL_TRAIN; |
|
1089 UpdateStationVirtCoordDirty(st); |
|
1090 DeleteStationIfEmpty(st); |
|
1091 } |
|
1092 } |
|
1093 } END_TILE_LOOP(tile2, size_x, size_y, tile) |
|
1094 |
|
1095 /* If we've not removed any tiles, give an error */ |
|
1096 if (quantity == 0) return CMD_ERROR; |
|
1097 |
|
1098 return _price.remove_rail_station * quantity; |
1065 } |
1099 } |
1066 |
1100 |
1067 |
1101 |
1068 static int32 RemoveRailroadStation(Station *st, TileIndex tile, uint32 flags) |
1102 static int32 RemoveRailroadStation(Station *st, TileIndex tile, uint32 flags) |
1069 { |
1103 { |