Skip to content

Commit

Permalink
Show a warning message that stream and road cannot be placed on water
Browse files Browse the repository at this point in the history
relates to #6845
  • Loading branch information
ihhub committed May 18, 2024
1 parent d097964 commit f1cda6a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/fheroes2/editor/editor_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,13 @@ namespace Interface
Maps::readMapInEditor( _mapFormat );
}
else if ( _editorPanel.isRoadDraw() ) {
if ( tile.isWater() ) {
std::string msg = _( "%{objects} cannot be placed on water." );
StringReplace( msg, "%{objects}", _( "Road" ) );
_warningMessage.reset( std::move( msg ) );
return;
}

fheroes2::ActionCreator action( _historyManager, _mapFormat );

if ( Maps::updateRoadOnTile( tile, true ) ) {
Expand All @@ -1249,6 +1256,13 @@ namespace Interface
}
}
else if ( _editorPanel.isStreamDraw() ) {
if ( tile.isWater() ) {
std::string msg = _( "%{objects} cannot be placed on water." );
StringReplace( msg, "%{objects}", _( "Stream" ) );
_warningMessage.reset( std::move( msg ) );
return;
}

fheroes2::ActionCreator action( _historyManager, _mapFormat );

if ( Maps::updateStreamOnTile( tile, true ) ) {
Expand Down
4 changes: 2 additions & 2 deletions src/fheroes2/maps/maps_tiles_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,7 @@ namespace Maps

bool updateRoadOnTile( Tiles & tile, const bool setRoad )
{
if ( setRoad == tile.isRoad() || ( tile.GetGround() == Ground::WATER && setRoad ) ) {
if ( setRoad == tile.isRoad() || ( tile.isWater() && setRoad ) ) {
// We cannot place roads on the water or above already placed roads.
return false;
}
Expand Down Expand Up @@ -1351,7 +1351,7 @@ namespace Maps

bool updateStreamOnTile( Tiles & tile, const bool setStream )
{
if ( setStream == tile.isStream() || ( tile.GetGround() == Ground::WATER && setStream ) ) {
if ( setStream == tile.isStream() || ( tile.isWater() && setStream ) ) {
// We cannot place streams on the water or on already placed streams.
return false;
}
Expand Down

0 comments on commit f1cda6a

Please sign in to comment.