Merge branch 'master' into jgrpp

# Conflicts:
#	src/industry_cmd.cpp
#	src/landscape.cpp
#	src/object_cmd.cpp
#	src/rail_cmd.cpp
#	src/script/api/script_tile.cpp
#	src/table/settings/difficulty_settings.ini
#	src/table/settings/world_settings.ini
#	src/terraform_cmd.cpp
#	src/tilearea_type.h
#	src/tree_cmd.cpp
#	src/tree_cmd.h
#	src/tree_gui.cpp
#	src/water_cmd.cpp
This commit is contained in:
Jonathan G Rennison
2023-01-14 16:40:24 +00:00
16 changed files with 62 additions and 53 deletions

View File

@@ -132,9 +132,9 @@ public:
return *this; return *this;
} }
virtual TileIterator *Clone() const virtual std::unique_ptr<TileIterator> Clone() const
{ {
return new BitmapTileIterator(*this); return std::make_unique<BitmapTileIterator>(*this);
} }
}; };

View File

@@ -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. */ /* Run tile loop to update the ground density. */
for (uint i = 0; i != 256; i++) { for (uint i = 0; i != 256; i++) {
if (i % 64 == 0) IncreaseGeneratingWorldProgress(GWP_RIVER); if (i % 64 == 0) IncreaseGeneratingWorldProgress(GWP_RIVER);

View File

@@ -399,7 +399,7 @@ STR_SCENEDIT_TOOLBAR_TOWN_GENERATION :{BLACK}Town gen
STR_SCENEDIT_TOOLBAR_INDUSTRY_GENERATION :{BLACK}Industry generation STR_SCENEDIT_TOOLBAR_INDUSTRY_GENERATION :{BLACK}Industry generation
STR_SCENEDIT_TOOLBAR_ROAD_CONSTRUCTION :{BLACK}Road construction STR_SCENEDIT_TOOLBAR_ROAD_CONSTRUCTION :{BLACK}Road construction
STR_SCENEDIT_TOOLBAR_TRAM_CONSTRUCTION :{BLACK}Tramway 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_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_OBJECT :{BLACK}Place object. Ctrl selects the area diagonally. Shift toggles building/showing cost estimate
STR_SCENEDIT_TOOLBAR_PLACE_HOUSE :{BLACK}Place house 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_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_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 :{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_BUTTON :{BLACK}Random Trees
STR_TREES_RANDOM_TREES_TOOLTIP :{BLACK}Plant trees randomly throughout the landscape STR_TREES_RANDOM_TREES_TOOLTIP :{BLACK}Plant trees randomly throughout the landscape
STR_TREES_REMOVE_TREES_BUTTON :{BLACK}Remove all Trees STR_TREES_REMOVE_TREES_BUTTON :{BLACK}Remove all Trees

View File

@@ -1271,7 +1271,7 @@ static ChangeInfoResult RailVehicleChangeInfo(uint engine, int numinfo, int prop
break; break;
case 0x2F: // Engine variant case 0x2F: // Engine variant
ei->variant_id = GetNewEngineID(_cur.grffile, VEH_TRAIN, buf->ReadWord()); ei->variant_id = buf->ReadWord();
break; break;
case 0x30: // Extra miscellaneous flags case 0x30: // Extra miscellaneous flags
@@ -1473,7 +1473,7 @@ static ChangeInfoResult RoadVehicleChangeInfo(uint engine, int numinfo, int prop
} }
case 0x26: // Engine variant case 0x26: // Engine variant
ei->variant_id = GetNewEngineID(_cur.grffile, VEH_ROAD, buf->ReadWord()); ei->variant_id = buf->ReadWord();
break; break;
case 0x27: // Extra miscellaneous flags case 0x27: // Extra miscellaneous flags
@@ -1653,7 +1653,7 @@ static ChangeInfoResult ShipVehicleChangeInfo(uint engine, int numinfo, int prop
} }
case 0x20: // Engine variant case 0x20: // Engine variant
ei->variant_id = GetNewEngineID(_cur.grffile, VEH_SHIP, buf->ReadWord()); ei->variant_id = buf->ReadWord();
break; break;
case 0x21: // Extra miscellaneous flags case 0x21: // Extra miscellaneous flags
@@ -1815,7 +1815,7 @@ static ChangeInfoResult AircraftVehicleChangeInfo(uint engine, int numinfo, int
break; break;
case 0x20: // Engine variant case 0x20: // Engine variant
ei->variant_id = GetNewEngineID(_cur.grffile, VEH_AIRCRAFT, buf->ReadWord()); ei->variant_id = buf->ReadWord();
break; break;
case 0x21: // Extra miscellaneous flags case 0x21: // Extra miscellaneous flags
@@ -10575,13 +10575,16 @@ static void FinaliseEngineArray()
} }
} }
if (!HasBit(e->info.climates, _settings_game.game_creation.landscape)) continue; /* Do final mapping on variant engine ID and set appropriate flags on variant engine */
/* Set appropriate flags on variant engine */
if (e->info.variant_id != INVALID_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 */ /* Skip wagons, there livery is defined via the engine */
if (e->type != VEH_TRAIN || e->u.rail.railveh_type != RAILVEH_WAGON) { if (e->type != VEH_TRAIN || e->u.rail.railveh_type != RAILVEH_WAGON) {
LiveryScheme ls = GetEngineLiveryScheme(e->index, INVALID_ENGINE, nullptr); LiveryScheme ls = GetEngineLiveryScheme(e->index, INVALID_ENGINE, nullptr);

View File

@@ -58,9 +58,9 @@ public:
return this->att->gfx; return this->att->gfx;
} }
virtual AirportTileTableIterator *Clone() const virtual std::unique_ptr<TileIterator> Clone() const
{ {
return new AirportTileTableIterator(*this); return std::make_unique<AirportTileTableIterator>(*this);
} }
}; };

View File

@@ -446,9 +446,9 @@ int MacOSStringCompare(const char *s1, const char *s2)
return this->utf16_to_utf8[this->cur_pos]; return this->utf16_to_utf8[this->cur_pos];
} }
/* static */ StringIterator *OSXStringIterator::Create() /* static */ std::unique_ptr<StringIterator> OSXStringIterator::Create()
{ {
if (!MacOSVersionIsAtLeast(10, 5, 0)) return nullptr; if (!MacOSVersionIsAtLeast(10, 5, 0)) return nullptr;
return new OSXStringIterator(); return std::make_unique<OSXStringIterator>();
} }

View File

@@ -33,7 +33,7 @@ public:
size_t Next(IterType what) override; size_t Next(IterType what) override;
size_t Prev(IterType what) override; size_t Prev(IterType what) override;
static StringIterator *Create(); static std::unique_ptr<StringIterator> Create();
}; };
/** /**

View File

@@ -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. 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) bool found_convertible_road = false; // whether we actually did convert any road/tram (see bug #7633)
TileIterator *iter = new OrthogonalTileIterator(area_start, area_end); OrthogonalTileIterator iter(area_start, area_end);
for (; (tile = *iter) != INVALID_TILE; ++(*iter)) { for (; (tile = *iter) != INVALID_TILE; ++iter) {
/* Is road present on tile? */ /* Is road present on tile? */
if (!MayHaveRoad(tile)) continue; 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; return found_convertible_road ? cost : error;
} }

View File

@@ -416,6 +416,7 @@ struct GameCreationSettings {
byte landscape; ///< the landscape we're currently in byte landscape; ///< the landscape we're currently in
byte water_borders; ///< bitset of the borders that are water byte water_borders; ///< bitset of the borders that are water
uint16 custom_town_number; ///< manually entered number of towns 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 variety; ///< variety level applied to TGP
byte custom_terrain_type; ///< manually entered height for TGP to aim for byte custom_terrain_type; ///< manually entered height for TGP to aim for
byte custom_sea_level; ///< manually entered percentage of water in the map 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 amount_of_rocks; ///< the amount of rocks
uint8 height_affects_rocks; ///< the affect that map height has on rocks uint8 height_affects_rocks; ///< the affect that map height has on rocks
uint8 build_public_roads; ///< build public roads connecting towns uint8 build_public_roads; ///< build public roads connecting towns
uint16 custom_industry_number; ///< manually entered number of industries
}; };
/** Settings related to construction in-game */ /** Settings related to construction in-game */

View File

@@ -924,9 +924,9 @@ public:
return *this; return *this;
} }
virtual TileIterator *Clone() const virtual std::unique_ptr<TileIterator> Clone() const
{ {
return new AirportTileIterator(*this); return std::make_unique<AirportTileIterator>(*this);
} }
}; };

View File

@@ -905,9 +905,9 @@ int strnatcmp(const char *s1, const char *s2, bool ignore_garbage_at_front)
#ifdef WITH_UNISCRIBE #ifdef WITH_UNISCRIBE
/* static */ StringIterator *StringIterator::Create() /* static */ std::unique_ptr<StringIterator> StringIterator::Create()
{ {
return new UniscribeStringIterator(); return std::make_unique<UniscribeStringIterator>();
} }
#elif defined(WITH_ICU_I18N) #elif defined(WITH_ICU_I18N)
@@ -1061,9 +1061,9 @@ public:
} }
}; };
/* static */ StringIterator *StringIterator::Create() /* static */ std::unique_ptr<StringIterator> StringIterator::Create()
{ {
return new IcuStringIterator(); return std::make_unique<IcuStringIterator>();
} }
#else #else
@@ -1172,17 +1172,17 @@ public:
}; };
#if defined(WITH_COCOA) && !defined(STRGEN) && !defined(SETTINGSGEN) #if defined(WITH_COCOA) && !defined(STRGEN) && !defined(SETTINGSGEN)
/* static */ StringIterator *StringIterator::Create() /* static */ std::unique_ptr<StringIterator> StringIterator::Create()
{ {
StringIterator *i = OSXStringIterator::Create(); std::unique_ptr<StringIterator> i = OSXStringIterator::Create();
if (i != nullptr) return i; if (i != nullptr) return i;
return new DefaultStringIterator(); return std::make_unique<DefaultStringIterator>();
} }
#else #else
/* static */ StringIterator *StringIterator::Create() /* static */ std::unique_ptr<StringIterator> StringIterator::Create()
{ {
return new DefaultStringIterator(); return std::make_unique<DefaultStringIterator>();
} }
#endif /* defined(WITH_COCOA) && !defined(STRGEN) && !defined(SETTINGSGEN) */ #endif /* defined(WITH_COCOA) && !defined(STRGEN) && !defined(SETTINGSGEN) */

View File

@@ -26,7 +26,7 @@ public:
* Create a new iterator instance. * Create a new iterator instance.
* @return New iterator instance. * @return New iterator instance.
*/ */
static StringIterator *Create(); static std::unique_ptr<StringIterator> Create();
virtual ~StringIterator() {} virtual ~StringIterator() {}

View File

@@ -371,13 +371,11 @@ bool Textbuf::MovePos(uint16 keycode)
* @param max_chars maximum size in chars, including terminating '\0' * @param max_chars maximum size in chars, including terminating '\0'
*/ */
Textbuf::Textbuf(uint16 max_bytes, uint16 max_chars) Textbuf::Textbuf(uint16 max_bytes, uint16 max_chars)
: buf(MallocT<char>(max_bytes)) : buf(MallocT<char>(max_bytes)), char_iter(StringIterator::Create())
{ {
assert(max_bytes != 0); assert(max_bytes != 0);
assert(max_chars != 0); assert(max_chars != 0);
this->char_iter = StringIterator::Create();
this->afilter = CS_ALPHANUMERAL; this->afilter = CS_ALPHANUMERAL;
this->max_bytes = max_bytes; this->max_bytes = max_bytes;
this->max_chars = max_chars == UINT16_MAX ? max_bytes : max_chars; 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() Textbuf::~Textbuf()
{ {
delete this->char_iter;
free(this->buf); free(this->buf);
} }

View File

@@ -67,7 +67,7 @@ struct Textbuf {
void DiscardMarkedText(bool update = true); void DiscardMarkedText(bool update = true);
private: private:
StringIterator *char_iter; std::unique_ptr<StringIterator> char_iter;
bool CanDelChar(bool backspace); bool CanDelChar(bool backspace);

View File

@@ -280,3 +280,18 @@ TileIterator &DiagonalTileIterator::operator++()
if (this->b_max == this->b_cur) this->tile = INVALID_TILE; if (this->b_max == this->b_cur) this->tile = INVALID_TILE;
return *this; 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> TileIterator::Create(TileIndex corner1, TileIndex corner2, bool diagonal)
{
if (diagonal) {
return std::make_unique<DiagonalTileIterator>(corner1, corner2);
}
return std::make_unique<OrthogonalTileIterator>(corner1, corner2);
}

View File

@@ -154,7 +154,9 @@ public:
/** /**
* Allocate a new iterator that is a copy of this one. * Allocate a new iterator that is a copy of this one.
*/ */
virtual TileIterator *Clone() const = 0; virtual std::unique_ptr<TileIterator> Clone() const = 0;
static std::unique_ptr<TileIterator> Create(TileIndex corner1, TileIndex corner2, bool diagonal);
}; };
/** Iterator to iterate over a tile area (rectangle) of the map. */ /** Iterator to iterate over a tile area (rectangle) of the map. */
@@ -201,9 +203,9 @@ public:
return *this; return *this;
} }
virtual TileIterator *Clone() const virtual std::unique_ptr<TileIterator> Clone() const
{ {
return new OrthogonalTileIterator(*this); return std::make_unique<OrthogonalTileIterator>(*this);
} }
}; };
@@ -227,11 +229,6 @@ public:
PREFETCH_NTA(&_m[ta.tile]); PREFETCH_NTA(&_m[ta.tile]);
} }
/** Some compilers really like this. */
virtual ~OrthogonalPrefetchTileIterator()
{
}
/** /**
* Get the tile we are currently at. * Get the tile we are currently at.
* @return The tile we are at, or INVALID_TILE when we're done. * @return The tile we are at, or INVALID_TILE when we're done.
@@ -259,11 +256,6 @@ public:
} }
return *this; return *this;
} }
virtual OrthogonalPrefetchTileIterator *Clone() const
{
return new OrthogonalPrefetchTileIterator(*this);
}
}; };
/** Iterator to iterate over a diagonal area of the map. */ /** Iterator to iterate over a diagonal area of the map. */
@@ -299,9 +291,9 @@ public:
TileIterator& operator ++(); TileIterator& operator ++();
virtual TileIterator *Clone() const virtual std::unique_ptr<TileIterator> Clone() const
{ {
return new DiagonalTileIterator(*this); return std::make_unique<DiagonalTileIterator>(*this);
} }
}; };