Fix crash when trying to build stations outside the map
This commit is contained in:
@@ -240,7 +240,7 @@ void ObjectHighlight::PlaceExtraDepotRail(TileIndex tile, DiagDirection dir, Tra
|
|||||||
if (GetRailTileType(tile) != RAIL_TILE_NORMAL) return;
|
if (GetRailTileType(tile) != RAIL_TILE_NORMAL) return;
|
||||||
if ((GetTrackBits(tile) & DiagdirReachesTracks(dir)) == 0) return;
|
if ((GetTrackBits(tile) & DiagdirReachesTracks(dir)) == 0) return;
|
||||||
|
|
||||||
this->tiles.insert(std::make_pair(tile, ObjectTileHighlight::make_rail_track(CM_PALETTE_TINT_WHITE, track)));
|
this->AddTile(tile, ObjectTileHighlight::make_rail_track(CM_PALETTE_TINT_WHITE, track));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Additional pieces of track to add at the entrance of a depot. */
|
/** Additional pieces of track to add at the entrance of a depot. */
|
||||||
@@ -274,6 +274,11 @@ bool CanBuild(const CommandContainer &cc) {
|
|||||||
return CanBuild(cc.tile, cc.p1, cc.p2, cc.cmd);
|
return CanBuild(cc.tile, cc.p1, cc.p2, cc.cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ObjectHighlight::AddTile(TileIndex tile, ObjectTileHighlight &&oh) {
|
||||||
|
if (tile >= MapSize()) return;
|
||||||
|
this->tiles.insert(std::make_pair(tile, std::move(oh)));
|
||||||
|
}
|
||||||
|
|
||||||
void ObjectHighlight::UpdateTiles() {
|
void ObjectHighlight::UpdateTiles() {
|
||||||
this->tiles.clear();
|
this->tiles.clear();
|
||||||
switch (this->type) {
|
switch (this->type) {
|
||||||
@@ -325,7 +330,7 @@ void ObjectHighlight::UpdateTiles() {
|
|||||||
int w = plat_len;
|
int w = plat_len;
|
||||||
do {
|
do {
|
||||||
byte layout = *layout_ptr++;
|
byte layout = *layout_ptr++;
|
||||||
this->tiles.insert(std::make_pair(tile, ObjectTileHighlight::make_rail_station(palette, this->axis, layout & ~1)));
|
this->AddTile(tile, ObjectTileHighlight::make_rail_station(palette, this->axis, layout & ~1));
|
||||||
tile += tile_delta;
|
tile += tile_delta;
|
||||||
} while (--w);
|
} while (--w);
|
||||||
tile_track += tile_delta ^ TileDiffXY(1, 1); // perpendicular to tile_delta
|
tile_track += tile_delta ^ TileDiffXY(1, 1); // perpendicular to tile_delta
|
||||||
@@ -343,7 +348,7 @@ void ObjectHighlight::UpdateTiles() {
|
|||||||
) ? CM_PALETTE_TINT_WHITE : CM_PALETTE_TINT_RED_DEEP);
|
) ? CM_PALETTE_TINT_WHITE : CM_PALETTE_TINT_RED_DEEP);
|
||||||
TileIndex tile;
|
TileIndex tile;
|
||||||
for (TileIndex tile : ta) {
|
for (TileIndex tile : ta) {
|
||||||
this->tiles.insert(std::make_pair(tile, ObjectTileHighlight::make_road_stop(palette, this->roadtype, this->ddir, this->is_truck)));
|
this->AddTile(tile, ObjectTileHighlight::make_road_stop(palette, this->roadtype, this->ddir, this->is_truck));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -355,7 +360,7 @@ void ObjectHighlight::UpdateTiles() {
|
|||||||
0,
|
0,
|
||||||
CMD_BUILD_ROAD_DEPOT
|
CMD_BUILD_ROAD_DEPOT
|
||||||
) ? CM_PALETTE_TINT_WHITE : CM_PALETTE_TINT_RED_DEEP);
|
) ? CM_PALETTE_TINT_WHITE : CM_PALETTE_TINT_RED_DEEP);
|
||||||
this->tiles.insert(std::make_pair(this->tile, ObjectTileHighlight::make_road_depot(palette, this->roadtype, this->ddir)));
|
this->AddTile(this->tile, ObjectTileHighlight::make_road_depot(palette, this->roadtype, this->ddir));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -375,7 +380,7 @@ void ObjectHighlight::UpdateTiles() {
|
|||||||
if (rotation == DIR_E || rotation == DIR_W) Swap(w, h);
|
if (rotation == DIR_E || rotation == DIR_W) Swap(w, h);
|
||||||
TileArea airport_area = TileArea(this->tile, w, h);
|
TileArea airport_area = TileArea(this->tile, w, h);
|
||||||
for (AirportTileTableIterator iter(as->table[this->airport_layout], this->tile); iter != INVALID_TILE; ++iter) {
|
for (AirportTileTableIterator iter(as->table[this->airport_layout], this->tile); iter != INVALID_TILE; ++iter) {
|
||||||
this->tiles.insert(std::make_pair(iter, ObjectTileHighlight::make_airport_tile(palette, iter.GetStationGfx())));
|
this->AddTile(iter, ObjectTileHighlight::make_airport_tile(palette, iter.GetStationGfx()));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -214,6 +214,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
bool tiles_updated = false;
|
bool tiles_updated = false;
|
||||||
std::multimap<TileIndex, ObjectTileHighlight> tiles;
|
std::multimap<TileIndex, ObjectTileHighlight> tiles;
|
||||||
|
void AddTile(TileIndex tile, ObjectTileHighlight &&oh);
|
||||||
void UpdateTiles();
|
void UpdateTiles();
|
||||||
void PlaceExtraDepotRail(TileIndex tile, DiagDirection dir, Track track);
|
void PlaceExtraDepotRail(TileIndex tile, DiagDirection dir, Track track);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user