Skip to content

Commit

Permalink
Simplify old road logic
Browse files Browse the repository at this point in the history
  • Loading branch information
idshibanov committed Sep 9, 2020
1 parent 023c775 commit 42482c2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 44 deletions.
57 changes: 15 additions & 42 deletions src/fheroes2/maps/maps_tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,55 +402,21 @@ bool Maps::TilesAddon::isRoad( int direct ) const
switch ( MP2::GetICNObject( object ) ) {
// from sprite road
case ICN::ROAD:
if ( 0 == index || 26 == index || 31 == index )
return direct & ( Direction::TOP | Direction::BOTTOM );
else if ( 2 == index || 21 == index || 28 == index )
return direct & ( Direction::LEFT | Direction::RIGHT );
else if ( 17 == index || 29 == index )
return direct & ( Direction::TOP_LEFT | Direction::BOTTOM_RIGHT );
else if ( 18 == index || 30 == index )
return direct & ( Direction::TOP_RIGHT | Direction::BOTTOM_LEFT );
else if ( 3 == index )
return direct & ( Direction::TOP | Direction::BOTTOM | Direction::LEFT | Direction::RIGHT );
else if ( 4 == index )
return direct & ( Direction::TOP | Direction::BOTTOM | Direction::TOP_LEFT | Direction::TOP_RIGHT );
else if ( 5 == index )
return direct & ( Direction::TOP | Direction::BOTTOM | Direction::TOP_RIGHT );
else if ( 6 == index )
return direct & ( Direction::TOP | Direction::BOTTOM | Direction::RIGHT );
else if ( 7 == index )
return direct & ( Direction::TOP | Direction::RIGHT );
else if ( 9 == index )
return direct & ( Direction::BOTTOM | Direction::TOP_RIGHT );
else if ( 12 == index )
return direct & ( Direction::BOTTOM | Direction::TOP_LEFT );
else if ( 13 == index )
return direct & ( Direction::TOP | Direction::BOTTOM | Direction::TOP_LEFT );
else if ( 14 == index )
return direct & ( Direction::TOP | Direction::BOTTOM | Direction::LEFT );
else if ( 16 == index )
return direct & ( Direction::TOP | Direction::LEFT );
else if ( 19 == index )
return direct & ( Direction::TOP_LEFT | Direction::BOTTOM_RIGHT );
else if ( 20 == index )
return direct & ( Direction::TOP_RIGHT | Direction::BOTTOM_LEFT );

break;
if ( 1 == index || 8 == index || 10 == index || 11 == index || 15 == index || 22 == index || 23 == index || 24 == index || 25 == index || 27 == index )
return false;
else
return true;

// castle and tower (gate)
case ICN::OBJNTOWN:
if ( 13 == index || 29 == index || 45 == index || 61 == index || 77 == index || 93 == index || 109 == index || 125 == index || 141 == index || 157 == index
|| 173 == index || 189 == index )
return direct & ( Direction::TOP | Direction::BOTTOM );

break;
return true;

// castle lands (gate)
case ICN::OBJNTWBA:
if ( 7 == index || 17 == index || 27 == index || 37 == index || 47 == index || 57 == index || 67 == index || 77 == index )
return direct & ( Direction::TOP | Direction::BOTTOM );

break;
return true;

default:
break;
Expand Down Expand Up @@ -2840,6 +2806,13 @@ StreamBase & Maps::operator<<( StreamBase & msg, const Tiles & tile )

StreamBase & Maps::operator>>( StreamBase & msg, Tiles & tile )
{
return msg >> tile.maps_index >> tile.pack_sprite_index >> tile.tile_passable >> tile.mp2_object >> tile.fog_colors >> tile.quantity1 >> tile.quantity2
>> tile.quantity3 >> tile.addons_level1 >> tile.addons_level2;
msg >> tile.maps_index >> tile.pack_sprite_index >> tile.tile_passable >> tile.mp2_object >> tile.fog_colors >> tile.quantity1 >> tile.quantity2 >> tile.quantity3
>> tile.addons_level1 >> tile.addons_level2;
if ( FORMAT_VERSION_082_RELEASE > Game::GetLoadVersion() ) {

}
else {
msg >> tile.tileIsRoad;
}
return msg;
}
2 changes: 2 additions & 0 deletions src/fheroes2/maps/maps_tiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ namespace Maps
u8 quantity2;
u8 quantity3;

bool tileIsRoad = false;

#ifdef WITH_DEBUG
u8 passable_disable;
#endif
Expand Down
5 changes: 4 additions & 1 deletion src/fheroes2/system/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@
#include "system.h"

#define FORMAT_VERSION_090_RELEASE 9000
#define FORMAT_VERSION_082_RELEASE 8200
#define FORMAT_VERSION_080_RELEASE 8000
#define FORMAT_VERSION_070_RELEASE 3269
#define FORMAT_VERSION_3255 3255
#define CURRENT_FORMAT_VERSION FORMAT_VERSION_080_RELEASE // TODO: update this value for a new release
#define LAST_FORMAT_VERSION FORMAT_VERSION_3255

// Value is set to 8100+ to distinguish save format changes in master branch after 0.8.1 release
#define CURRENT_FORMAT_VERSION 8111 // TODO: update this value for a new release

enum
{
DBG_WARN = 0x0001,
Expand Down
2 changes: 1 addition & 1 deletion src/fheroes2/world/world_pathfinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +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
uint32_t penalty = ( world.GetTiles( from ).isRoad( direction ) && tileTo.isRoad( Direction::Reflect( direction ) ) ) ? Maps::Ground::roadPenalty
: Maps::Ground::GetPenalty( tileTo, skill );

// diagonal move costs 50% extra
Expand Down

0 comments on commit 42482c2

Please sign in to comment.