Skip to content

Commit

Permalink
Don't need direction for road calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
idshibanov committed Sep 9, 2020
1 parent 42482c2 commit af4d5cc
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/fheroes2/dialog/dialog_quickinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ std::string ShowGroundInfo( const Maps::Tiles & tile, bool show, const Heroes *
if ( show && hero ) {
int dir = Direction::Get( hero->GetIndex(), tile.GetIndex() );
if ( dir != Direction::UNKNOWN ) {
uint32_t cost = ( tile.isRoad( dir ) ) ? Maps::Ground::roadPenalty : Maps::Ground::GetPenalty( tile, hero->GetLevelSkill( Skill::Secondary::PATHFINDING ) );
uint32_t cost = tile.isRoad() ? Maps::Ground::roadPenalty : Maps::Ground::GetPenalty( tile, hero->GetLevelSkill( Skill::Secondary::PATHFINDING ) );

if ( cost ) {
str.append( "\n" );
Expand Down
3 changes: 1 addition & 2 deletions src/fheroes2/gui/interface_gamearea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,8 @@ void Interface::GameArea::Redraw( fheroes2::Image & dst, int flag ) const
if ( pathEnd != nextStep ) {
const Maps::Tiles & tileTo = world.GetTiles( currentStep->GetIndex() );
uint32_t cost = Maps::Ground::GetPenalty( tileTo, pathfinding );
const int direction = currentStep->GetDirection();

if ( world.GetTiles( currentStep->GetFrom() ).isRoad( direction ) || tileTo.isRoad( Direction::Reflect( direction ) ) )
if ( world.GetTiles( currentStep->GetFrom() ).isRoad() && tileTo.isRoad() )
cost = Maps::Ground::roadPenalty;

index = Route::Path::GetIndexSprite( ( *currentStep ).GetDirection(), ( *nextStep ).GetDirection(), cost );
Expand Down
14 changes: 7 additions & 7 deletions src/fheroes2/maps/maps_tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ int Maps::TilesAddon::GetActionObject( const Maps::TilesAddon & ta )
return MP2::OBJ_ZERO;
}

bool Maps::TilesAddon::isRoad( int direct ) const
bool Maps::TilesAddon::isRoad() const
{
switch ( MP2::GetICNObject( object ) ) {
// from sprite road
Expand Down Expand Up @@ -425,7 +425,7 @@ bool Maps::TilesAddon::isRoad( int direct ) const
return false;
}

bool Maps::TilesAddon::isRoadObject() const
bool Maps::TilesAddon::hasRoadFlag() const
{
// This MP2 "object" is a bitfield
// 6 bits is ICN tileset id, 1 bit isRoad flag, 1 bit hasAnimation flag
Expand Down Expand Up @@ -503,7 +503,7 @@ bool Maps::TilesAddon::isStream( const TilesAddon & ta )
return ICN::STREAM == MP2::GetICNObject( ta.object ) || ( ICN::OBJNMUL2 == MP2::GetICNObject( ta.object ) && ( ta.index < 14 ) );
}

bool Maps::TilesAddon::isRoad( const TilesAddon & ta )
bool Maps::TilesAddon::isRoadObject( const TilesAddon & ta )
{
return ICN::ROAD == MP2::GetICNObject( ta.object );
}
Expand Down Expand Up @@ -1203,7 +1203,7 @@ bool isForestsTrees( const Maps::TilesAddon & ta )

bool Exclude4LongObject( const Maps::TilesAddon & ta )
{
return Maps::TilesAddon::isStream( ta ) || Maps::TilesAddon::isRoad( ta ) || Maps::TilesAddon::isShadow( ta );
return Maps::TilesAddon::isStream( ta ) || Maps::TilesAddon::isRoadObject( ta ) || Maps::TilesAddon::isShadow( ta );
}

bool HaveLongObjectUniq( const Maps::Addons & level, u32 uid )
Expand Down Expand Up @@ -1593,7 +1593,7 @@ void Maps::Tiles::RedrawBoat( fheroes2::Image & dst ) const

bool SkipRedrawTileBottom4Hero( const Maps::TilesAddon & ta, int passable )
{
if ( Maps::TilesAddon::isStream( ta ) || Maps::TilesAddon::isRoad( ta ) )
if ( Maps::TilesAddon::isStream( ta ) || Maps::TilesAddon::isRoadObject( ta ) )
return true;
else
switch ( MP2::GetICNObject( ta.object ) ) {
Expand Down Expand Up @@ -1895,9 +1895,9 @@ void Maps::Tiles::SetObjectPassable( bool pass )
}

/* check road */
bool Maps::Tiles::isRoad( int direct ) const
bool Maps::Tiles::isRoad() const
{
return addons_level1.end() != std::find_if( addons_level1.begin(), addons_level1.end(), std::bind2nd( std::mem_fun_ref( &TilesAddon::isRoad ), direct ) );
return tileIsRoad;
}

bool Maps::Tiles::isStream( void ) const
Expand Down
8 changes: 4 additions & 4 deletions src/fheroes2/maps/maps_tiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ namespace Maps
TilesAddon & operator=( const TilesAddon & ta );

bool isUniq( u32 ) const;
bool isRoad( int ) const;
bool isRoadObject() const;
bool isRoad() const;
bool hasRoadFlag() const;
bool isICN( int ) const;

std::string String( int level ) const;

static bool hasColorCycling( const TilesAddon & addon );
static bool isStream( const TilesAddon & );
static bool isRoad( const TilesAddon & );
static bool isRoadObject( const TilesAddon & );

static bool isResource( const TilesAddon & );
static bool isWaterResource( const TilesAddon & );
Expand Down Expand Up @@ -169,7 +169,7 @@ namespace Maps

bool validateWaterRules( bool fromWater ) const;
bool isPassable( int direct, bool fromWater, bool skipfog ) const;
bool isRoad( int = DIRECTION_ALL ) const;
bool isRoad() const;
bool isObject( int obj ) const
{
return obj == mp2_object;
Expand Down
3 changes: 1 addition & 2 deletions src/fheroes2/world/world_pathfinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ void Pathfinder::reEvaluateIfNeeded( int from, uint8_t skill )
uint32_t Pathfinder::getMovementPenalty( int from, int target, int direction, uint8_t skill )
{
const Maps::Tiles & tileTo = world.GetTiles( target );
uint32_t penalty = ( world.GetTiles( from ).isRoad( direction ) && tileTo.isRoad( Direction::Reflect( direction ) ) ) ? Maps::Ground::roadPenalty
: Maps::Ground::GetPenalty( tileTo, skill );
uint32_t penalty = ( world.GetTiles( from ).isRoad() && tileTo.isRoad() ) ? Maps::Ground::roadPenalty : Maps::Ground::GetPenalty( tileTo, skill );

// diagonal move costs 50% extra
if ( direction & ( Direction::TOP_RIGHT | Direction::BOTTOM_RIGHT | Direction::BOTTOM_LEFT | Direction::TOP_LEFT ) )
Expand Down

0 comments on commit af4d5cc

Please sign in to comment.