diff --git a/src/bitmap_type.h b/src/bitmap_type.h index 09c9258e34..c66de23021 100644 --- a/src/bitmap_type.h +++ b/src/bitmap_type.h @@ -132,9 +132,9 @@ public: return *this; } - virtual TileIterator *Clone() const + virtual std::unique_ptr Clone() const { - return new BitmapTileIterator(*this); + return std::make_unique(*this); } }; diff --git a/src/landscape.cpp b/src/landscape.cpp index 77e5d36dbe..8a9a0b41f2 100644 --- a/src/landscape.cpp +++ b/src/landscape.cpp @@ -1435,6 +1435,9 @@ static void CreateRivers() } } + /* Widening rivers may have left some tiles requiring to be watered. */ + ConvertGroundTilesIntoWaterTiles(); + /* Run tile loop to update the ground density. */ for (uint i = 0; i != 256; i++) { if (i % 64 == 0) IncreaseGeneratingWorldProgress(GWP_RIVER); diff --git a/src/lang/english.txt b/src/lang/english.txt index 1eae3f4323..6e0a9e8236 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -399,7 +399,7 @@ STR_SCENEDIT_TOOLBAR_TOWN_GENERATION :{BLACK}Town gen STR_SCENEDIT_TOOLBAR_INDUSTRY_GENERATION :{BLACK}Industry generation STR_SCENEDIT_TOOLBAR_ROAD_CONSTRUCTION :{BLACK}Road construction STR_SCENEDIT_TOOLBAR_TRAM_CONSTRUCTION :{BLACK}Tramway construction -STR_SCENEDIT_TOOLBAR_PLANT_TREES :{BLACK}Plant trees. Shift toggles building/showing cost estimate +STR_SCENEDIT_TOOLBAR_PLANT_TREES :{BLACK}Plant trees. Ctrl selects the area diagonally. Shift toggles building/showing cost estimate STR_SCENEDIT_TOOLBAR_PLACE_SIGN :{BLACK}Place sign STR_SCENEDIT_TOOLBAR_PLACE_OBJECT :{BLACK}Place object. Ctrl selects the area diagonally. Shift toggles building/showing cost estimate STR_SCENEDIT_TOOLBAR_PLACE_HOUSE :{BLACK}Place house @@ -3776,7 +3776,7 @@ STR_SELECT_TOWN_LIST_ITEM :{BLACK}{TOWN} STR_PLANT_TREE_CAPTION :{WHITE}Trees STR_PLANT_TREE_TOOLTIP :{BLACK}Select tree type to plant. If the tile already has a tree, this will add more trees of mixed types independent of the selected type STR_TREES_RANDOM_TYPE :{BLACK}Trees of random type -STR_TREES_RANDOM_TYPE_TOOLTIP :{BLACK}Place trees of random type. Shift toggles building/showing cost estimate +STR_TREES_RANDOM_TYPE_TOOLTIP :{BLACK}Place trees of random type. Ctrl selects the area diagonally. Shift toggles building/showing cost estimate STR_TREES_RANDOM_TREES_BUTTON :{BLACK}Random Trees STR_TREES_RANDOM_TREES_TOOLTIP :{BLACK}Plant trees randomly throughout the landscape STR_TREES_REMOVE_TREES_BUTTON :{BLACK}Remove all Trees diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 41536871d3..69d2363c93 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -1271,7 +1271,7 @@ static ChangeInfoResult RailVehicleChangeInfo(uint engine, int numinfo, int prop break; case 0x2F: // Engine variant - ei->variant_id = GetNewEngineID(_cur.grffile, VEH_TRAIN, buf->ReadWord()); + ei->variant_id = buf->ReadWord(); break; case 0x30: // Extra miscellaneous flags @@ -1473,7 +1473,7 @@ static ChangeInfoResult RoadVehicleChangeInfo(uint engine, int numinfo, int prop } case 0x26: // Engine variant - ei->variant_id = GetNewEngineID(_cur.grffile, VEH_ROAD, buf->ReadWord()); + ei->variant_id = buf->ReadWord(); break; case 0x27: // Extra miscellaneous flags @@ -1653,7 +1653,7 @@ static ChangeInfoResult ShipVehicleChangeInfo(uint engine, int numinfo, int prop } case 0x20: // Engine variant - ei->variant_id = GetNewEngineID(_cur.grffile, VEH_SHIP, buf->ReadWord()); + ei->variant_id = buf->ReadWord(); break; case 0x21: // Extra miscellaneous flags @@ -1815,7 +1815,7 @@ static ChangeInfoResult AircraftVehicleChangeInfo(uint engine, int numinfo, int break; case 0x20: // Engine variant - ei->variant_id = GetNewEngineID(_cur.grffile, VEH_AIRCRAFT, buf->ReadWord()); + ei->variant_id = buf->ReadWord(); break; case 0x21: // Extra miscellaneous flags @@ -10575,13 +10575,16 @@ static void FinaliseEngineArray() } } - if (!HasBit(e->info.climates, _settings_game.game_creation.landscape)) continue; - - /* Set appropriate flags on variant engine */ + /* Do final mapping on variant engine ID and set appropriate flags on variant engine */ if (e->info.variant_id != INVALID_ENGINE) { - Engine::Get(e->info.variant_id)->display_flags |= EngineDisplayFlags::HasVariants | EngineDisplayFlags::IsFolded; + e->info.variant_id = GetNewEngineID(e->grf_prop.grffile, e->type, e->info.variant_id); + if (e->info.variant_id != INVALID_ENGINE) { + Engine::Get(e->info.variant_id)->display_flags |= EngineDisplayFlags::HasVariants | EngineDisplayFlags::IsFolded; + } } + if (!HasBit(e->info.climates, _settings_game.game_creation.landscape)) continue; + /* Skip wagons, there livery is defined via the engine */ if (e->type != VEH_TRAIN || e->u.rail.railveh_type != RAILVEH_WAGON) { LiveryScheme ls = GetEngineLiveryScheme(e->index, INVALID_ENGINE, nullptr); diff --git a/src/newgrf_airport.h b/src/newgrf_airport.h index 264da05ebb..2774fbc645 100644 --- a/src/newgrf_airport.h +++ b/src/newgrf_airport.h @@ -58,9 +58,9 @@ public: return this->att->gfx; } - virtual AirportTileTableIterator *Clone() const + virtual std::unique_ptr Clone() const { - return new AirportTileTableIterator(*this); + return std::make_unique(*this); } }; diff --git a/src/os/macosx/string_osx.cpp b/src/os/macosx/string_osx.cpp index c34a7b6208..1cebbe3e16 100644 --- a/src/os/macosx/string_osx.cpp +++ b/src/os/macosx/string_osx.cpp @@ -446,9 +446,9 @@ int MacOSStringCompare(const char *s1, const char *s2) return this->utf16_to_utf8[this->cur_pos]; } -/* static */ StringIterator *OSXStringIterator::Create() +/* static */ std::unique_ptr OSXStringIterator::Create() { if (!MacOSVersionIsAtLeast(10, 5, 0)) return nullptr; - return new OSXStringIterator(); + return std::make_unique(); } diff --git a/src/os/macosx/string_osx.h b/src/os/macosx/string_osx.h index 88e5924e8c..fc737b1639 100644 --- a/src/os/macosx/string_osx.h +++ b/src/os/macosx/string_osx.h @@ -33,7 +33,7 @@ public: size_t Next(IterType what) override; size_t Prev(IterType what) override; - static StringIterator *Create(); + static std::unique_ptr Create(); }; /** diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp index 0c06b661ca..7010d6f223 100644 --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -3019,8 +3019,8 @@ CommandCost CmdConvertRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 CommandCost error = CommandCost((rtt == RTT_TRAM) ? STR_ERROR_NO_SUITABLE_TRAMWAY : STR_ERROR_NO_SUITABLE_ROAD); // by default, there is no road to convert. bool found_convertible_road = false; // whether we actually did convert any road/tram (see bug #7633) - TileIterator *iter = new OrthogonalTileIterator(area_start, area_end); - for (; (tile = *iter) != INVALID_TILE; ++(*iter)) { + OrthogonalTileIterator iter(area_start, area_end); + for (; (tile = *iter) != INVALID_TILE; ++iter) { /* Is road present on tile? */ if (!MayHaveRoad(tile)) continue; @@ -3209,7 +3209,6 @@ CommandCost CmdConvertRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 } } - delete iter; return found_convertible_road ? cost : error; } diff --git a/src/settings_type.h b/src/settings_type.h index e062bee9eb..96a7128892 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -416,6 +416,7 @@ struct GameCreationSettings { byte landscape; ///< the landscape we're currently in byte water_borders; ///< bitset of the borders that are water uint16 custom_town_number; ///< manually entered number of towns + uint16 custom_industry_number; ///< manually entered number of industries byte variety; ///< variety level applied to TGP byte custom_terrain_type; ///< manually entered height for TGP to aim for byte custom_sea_level; ///< manually entered percentage of water in the map @@ -431,7 +432,6 @@ struct GameCreationSettings { uint8 amount_of_rocks; ///< the amount of rocks uint8 height_affects_rocks; ///< the affect that map height has on rocks uint8 build_public_roads; ///< build public roads connecting towns - uint16 custom_industry_number; ///< manually entered number of industries }; /** Settings related to construction in-game */ diff --git a/src/station_base.h b/src/station_base.h index 8725913818..f671f62ca2 100644 --- a/src/station_base.h +++ b/src/station_base.h @@ -924,9 +924,9 @@ public: return *this; } - virtual TileIterator *Clone() const + virtual std::unique_ptr Clone() const { - return new AirportTileIterator(*this); + return std::make_unique(*this); } }; diff --git a/src/string.cpp b/src/string.cpp index afb1ee7591..8dc11ee469 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -905,9 +905,9 @@ int strnatcmp(const char *s1, const char *s2, bool ignore_garbage_at_front) #ifdef WITH_UNISCRIBE -/* static */ StringIterator *StringIterator::Create() +/* static */ std::unique_ptr StringIterator::Create() { - return new UniscribeStringIterator(); + return std::make_unique(); } #elif defined(WITH_ICU_I18N) @@ -1061,9 +1061,9 @@ public: } }; -/* static */ StringIterator *StringIterator::Create() +/* static */ std::unique_ptr StringIterator::Create() { - return new IcuStringIterator(); + return std::make_unique(); } #else @@ -1172,17 +1172,17 @@ public: }; #if defined(WITH_COCOA) && !defined(STRGEN) && !defined(SETTINGSGEN) -/* static */ StringIterator *StringIterator::Create() +/* static */ std::unique_ptr StringIterator::Create() { - StringIterator *i = OSXStringIterator::Create(); + std::unique_ptr i = OSXStringIterator::Create(); if (i != nullptr) return i; - return new DefaultStringIterator(); + return std::make_unique(); } #else -/* static */ StringIterator *StringIterator::Create() +/* static */ std::unique_ptr StringIterator::Create() { - return new DefaultStringIterator(); + return std::make_unique(); } #endif /* defined(WITH_COCOA) && !defined(STRGEN) && !defined(SETTINGSGEN) */ diff --git a/src/string_base.h b/src/string_base.h index a22be65713..d7414c9156 100644 --- a/src/string_base.h +++ b/src/string_base.h @@ -26,7 +26,7 @@ public: * Create a new iterator instance. * @return New iterator instance. */ - static StringIterator *Create(); + static std::unique_ptr Create(); virtual ~StringIterator() {} diff --git a/src/textbuf.cpp b/src/textbuf.cpp index 4ab6bc9f7c..14d24c5d86 100644 --- a/src/textbuf.cpp +++ b/src/textbuf.cpp @@ -371,13 +371,11 @@ bool Textbuf::MovePos(uint16 keycode) * @param max_chars maximum size in chars, including terminating '\0' */ Textbuf::Textbuf(uint16 max_bytes, uint16 max_chars) - : buf(MallocT(max_bytes)) + : buf(MallocT(max_bytes)), char_iter(StringIterator::Create()) { assert(max_bytes != 0); assert(max_chars != 0); - this->char_iter = StringIterator::Create(); - this->afilter = CS_ALPHANUMERAL; this->max_bytes = max_bytes; this->max_chars = max_chars == UINT16_MAX ? max_bytes : max_chars; @@ -387,7 +385,6 @@ Textbuf::Textbuf(uint16 max_bytes, uint16 max_chars) Textbuf::~Textbuf() { - delete this->char_iter; free(this->buf); } diff --git a/src/textbuf_type.h b/src/textbuf_type.h index b4f234f737..14e92cbb3d 100644 --- a/src/textbuf_type.h +++ b/src/textbuf_type.h @@ -67,7 +67,7 @@ struct Textbuf { void DiscardMarkedText(bool update = true); private: - StringIterator *char_iter; + std::unique_ptr char_iter; bool CanDelChar(bool backspace); diff --git a/src/tilearea.cpp b/src/tilearea.cpp index e6ed6d428c..a2689bb856 100644 --- a/src/tilearea.cpp +++ b/src/tilearea.cpp @@ -280,3 +280,18 @@ TileIterator &DiagonalTileIterator::operator++() if (this->b_max == this->b_cur) this->tile = INVALID_TILE; return *this; } + +/** + * Create either an OrthogonalTileIterator or DiagonalTileIterator given the diagonal parameter. + * @param corner1 Tile from where to begin iterating. + * @param corner2 Tile where to end the iterating. + * @param diagonal Whether to create a DiagonalTileIterator or OrthogonalTileIterator. + * @return unique_ptr to the allocated TileIterator. + */ +/* static */ std::unique_ptr TileIterator::Create(TileIndex corner1, TileIndex corner2, bool diagonal) +{ + if (diagonal) { + return std::make_unique(corner1, corner2); + } + return std::make_unique(corner1, corner2); +} diff --git a/src/tilearea_type.h b/src/tilearea_type.h index 80aaba0dab..bdcf6d3e21 100644 --- a/src/tilearea_type.h +++ b/src/tilearea_type.h @@ -154,7 +154,9 @@ public: /** * Allocate a new iterator that is a copy of this one. */ - virtual TileIterator *Clone() const = 0; + virtual std::unique_ptr Clone() const = 0; + + static std::unique_ptr Create(TileIndex corner1, TileIndex corner2, bool diagonal); }; /** Iterator to iterate over a tile area (rectangle) of the map. */ @@ -201,9 +203,9 @@ public: return *this; } - virtual TileIterator *Clone() const + virtual std::unique_ptr Clone() const { - return new OrthogonalTileIterator(*this); + return std::make_unique(*this); } }; @@ -227,11 +229,6 @@ public: PREFETCH_NTA(&_m[ta.tile]); } - /** Some compilers really like this. */ - virtual ~OrthogonalPrefetchTileIterator() - { - } - /** * Get the tile we are currently at. * @return The tile we are at, or INVALID_TILE when we're done. @@ -259,11 +256,6 @@ public: } return *this; } - - virtual OrthogonalPrefetchTileIterator *Clone() const - { - return new OrthogonalPrefetchTileIterator(*this); - } }; /** Iterator to iterate over a diagonal area of the map. */ @@ -299,9 +291,9 @@ public: TileIterator& operator ++(); - virtual TileIterator *Clone() const + virtual std::unique_ptr Clone() const { - return new DiagonalTileIterator(*this); + return std::make_unique(*this); } };