Skip to content

Commit

Permalink
Merge pull request #49795 from jbytheway/better_overmap_fallback_fixes
Browse files Browse the repository at this point in the history
Better overmap fallback fixes
  • Loading branch information
ZhilkinSerg authored Jul 10, 2021
2 parents 3b3aa07 + 7683ba0 commit aa126fe
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@
"type": "overmap_terrain",
"id": "forest_trail",
"name": "forest trail",
"sym": "T",
"color": "green",
"mapgen_straight": [ { "method": "builtin", "name": "forest_trail_straight" } ],
"mapgen_curved": [ { "method": "builtin", "name": "forest_trail_curved" } ],
Expand Down
27 changes: 14 additions & 13 deletions gfx/RetroDaysTileset/tile_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5390,20 +5390,21 @@
{ "id": "river_nw", "fg": 2301, "rotates": false },
{ "id": "river_se", "fg": 2299, "rotates": false },
{ "id": "river_sw", "fg": 2300, "rotates": false },
{ "id": "road_end", "fg": [ 2274, 2275, 2276, 2277 ], "rotates": true },
{ "id": "road_es", "fg": 2281, "rotates": false },
{ "id": "road_esw", "fg": 2288, "rotates": false },
{ "id": "road_ew", "fg": 2284, "rotates": false },
{ "id": "road_isolated", "fg": 2278, "rotates": false },
{ "id": "road_ne", "fg": 2279, "rotates": false },
{ "id": "road_nes", "fg": 2282, "rotates": false },
{ "id": "road_nesw", "fg": 2289, "rotates": false },
{
"id": "road",
"fg": 2278,
"rotates": true,
"multitile": true,
"additional_tiles": [
{ "id": "center", "fg": 2289 },
{ "id": "corner", "fg": 2281 },
{ "id": "edge", "fg": 2280 },
{ "id": "end_piece", "fg": 2274 },
{ "id": "t_connection", "fg": 2288 },
{ "id": "unconnected", "fg": 2278 }
]
},
{ "id": "road_nesw_manhole", "fg": 2290, "rotates": false },
{ "id": "road_new", "fg": 2285, "rotates": false },
{ "id": "road_ns", "fg": 2280, "rotates": false },
{ "id": "road_nsw", "fg": 2287, "rotates": false },
{ "id": "road_sw", "fg": 2286, "rotates": false },
{ "id": "road_wn", "fg": 2283, "rotates": false },
{
"id": [ "s_clothes", "s_clothes_1", "s_clothes_2", "s_clothes_3", "s_clothes_4", "s_clothes_5", "s_clothes_6" ],
"fg": [ 2353, 2353, 2353, 2353 ],
Expand Down
2 changes: 1 addition & 1 deletion src/cata_tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1881,7 +1881,7 @@ bool cata_tiles::draw_from_id_string( const std::string &id, TILE_CATEGORY categ
sym = tmp->get_uint32_symbol();
col = tmp->get_color();
} else if( type_tmp.is_valid() ) {
sym = type_tmp->get_symbol().front();
sym = type_tmp->symbol;
col = type_tmp->color;
}
} else if( category == C_OVERMAP_NOTE ) {
Expand Down
15 changes: 2 additions & 13 deletions src/cata_tiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,6 @@ struct tile_type {
std::vector<std::string> available_subtiles;
};

/* Enums */
enum MULTITILE_TYPE {
center,
corner,
edge,
t_connection,
end_piece,
unconnected,
open_,
broken,
num_multitile_types
};
// Make sure to change TILE_CATEGORY_IDS if this changes!
enum TILE_CATEGORY {
C_NONE,
Expand Down Expand Up @@ -539,7 +527,8 @@ class cata_tiles
static std::vector<options_manager::id_and_option> build_renderer_list();
static std::vector<options_manager::id_and_option> build_display_list();
private:
int get_omt_rotation( std::string &id );
std::string get_omt_id_rotation_and_subtile(
const tripoint_abs_omt &omp, int &rota, int &subtile );
protected:
template <typename maptype>
void tile_loading_report( const maptype &tiletypemap, TILE_CATEGORY category,
Expand Down
12 changes: 12 additions & 0 deletions src/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,18 @@ struct social_modifiers {
}
};

enum MULTITILE_TYPE {
center,
corner,
edge,
t_connection,
end_piece,
unconnected,
open_,
broken,
num_multitile_types
};

enum class reachability_cache_quadrant : int {
NE, SE, NW, SW
};
Expand Down
1 change: 1 addition & 0 deletions src/omdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ struct oter_t {
size_t get_line() const {
return line;
}
void get_rotation_and_subtile( int &rotation, int &subtile ) const;

unsigned char get_see_cost() const {
return type->see_cost;
Expand Down
57 changes: 41 additions & 16 deletions src/overmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ namespace om_lines
struct type {
uint32_t symbol;
size_t mapgen;
MULTITILE_TYPE subtile;
int rotation;
std::string suffix;
};

Expand All @@ -100,22 +102,22 @@ const std::array<std::string, 5> mapgen_suffixes = {{
};

const std::array < type, 1 + om_direction::bits > all = {{
{ UTF8_getch( LINE_XXXX_S ), 4, "_isolated" }, // 0 ----
{ UTF8_getch( LINE_XOXO_S ), 2, "_end_south" }, // 1 ---n
{ UTF8_getch( LINE_OXOX_S ), 2, "_end_west" }, // 2 --e-
{ UTF8_getch( LINE_XXOO_S ), 1, "_ne" }, // 3 --en
{ UTF8_getch( LINE_XOXO_S ), 2, "_end_north" }, // 4 -s--
{ UTF8_getch( LINE_XOXO_S ), 0, "_ns" }, // 5 -s-n
{ UTF8_getch( LINE_OXXO_S ), 1, "_es" }, // 6 -se-
{ UTF8_getch( LINE_XXXO_S ), 3, "_nes" }, // 7 -sen
{ UTF8_getch( LINE_OXOX_S ), 2, "_end_east" }, // 8 w---
{ UTF8_getch( LINE_XOOX_S ), 1, "_wn" }, // 9 w--n
{ UTF8_getch( LINE_OXOX_S ), 0, "_ew" }, // 10 w-e-
{ UTF8_getch( LINE_XXOX_S ), 3, "_new" }, // 11 w-en
{ UTF8_getch( LINE_OOXX_S ), 1, "_sw" }, // 12 ws--
{ UTF8_getch( LINE_XOXX_S ), 3, "_nsw" }, // 13 ws-n
{ UTF8_getch( LINE_OXXX_S ), 3, "_esw" }, // 14 wse-
{ UTF8_getch( LINE_XXXX_S ), 4, "_nesw" } // 15 wsen
{ UTF8_getch( LINE_XXXX_S ), 4, unconnected, 0, "_isolated" }, // 0 ----
{ UTF8_getch( LINE_XOXO_S ), 2, end_piece, 2, "_end_south" }, // 1 ---n
{ UTF8_getch( LINE_OXOX_S ), 2, end_piece, 1, "_end_west" }, // 2 --e-
{ UTF8_getch( LINE_XXOO_S ), 1, corner, 1, "_ne" }, // 3 --en
{ UTF8_getch( LINE_XOXO_S ), 2, end_piece, 0, "_end_north" }, // 4 -s--
{ UTF8_getch( LINE_XOXO_S ), 0, edge, 0, "_ns" }, // 5 -s-n
{ UTF8_getch( LINE_OXXO_S ), 1, corner, 0, "_es" }, // 6 -se-
{ UTF8_getch( LINE_XXXO_S ), 3, t_connection, 1, "_nes" }, // 7 -sen
{ UTF8_getch( LINE_OXOX_S ), 2, end_piece, 3, "_end_east" }, // 8 w---
{ UTF8_getch( LINE_XOOX_S ), 1, corner, 2, "_wn" }, // 9 w--n
{ UTF8_getch( LINE_OXOX_S ), 0, edge, 1, "_ew" }, // 10 w-e-
{ UTF8_getch( LINE_XXOX_S ), 3, t_connection, 2, "_new" }, // 11 w-en
{ UTF8_getch( LINE_OOXX_S ), 1, corner, 3, "_sw" }, // 12 ws--
{ UTF8_getch( LINE_XOXX_S ), 3, t_connection, 3, "_nsw" }, // 13 ws-n
{ UTF8_getch( LINE_OXXX_S ), 3, t_connection, 0, "_esw" }, // 14 wse-
{ UTF8_getch( LINE_XXXX_S ), 4, center, 0, "_nesw" } // 15 wsen
}
};

Expand Down Expand Up @@ -568,6 +570,14 @@ void oter_type_t::load( const JsonObject &jo, const std::string &src )
for( const auto &elem : om_lines::mapgen_suffixes ) {
load_overmap_terrain_mapgens( jo, id.str(), elem );
}

if( symbol == NULL_UNICODE ) {
// Default the sym for linear terrains to a specific value which
// has special behaviour when using fallback ASCII tiles so as to
// cause it to draw using the box drawing characters (see
// load_ascii_set).
symbol = LINE_XOXO_C;
}
} else {
if( symbol == NULL_UNICODE && !jo.has_string( "abstract" ) ) {
DebugLog( D_ERROR, D_MAP_GEN ) << "sym is not defined for overmap_terrain: "
Expand Down Expand Up @@ -688,6 +698,21 @@ oter_id oter_t::get_rotated( om_direction::type dir ) const
: type->get_rotated( om_direction::add( this->dir, dir ) );
}

void oter_t::get_rotation_and_subtile( int &rotation, int &subtile ) const
{
if( is_linear() ) {
const om_lines::type &t = om_lines::all[line];
rotation = t.rotation;
subtile = t.subtile;
} else if( is_rotatable() ) {
rotation = static_cast<int>( get_dir() );
subtile = -1;
} else {
rotation = 0;
subtile = -1;
}
}

bool oter_t::type_is( const int_id<oter_type_t> &type_id ) const
{
return type->id.id() == type_id;
Expand Down
79 changes: 32 additions & 47 deletions src/sdltiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,38 +755,20 @@ static cata::optional<std::pair<tripoint_abs_omt, std::string>> get_mission_arro
return std::make_pair( tripoint_abs_omt( *prev ), mission_arrow_variant );
}

int cata_tiles::get_omt_rotation( std::string &id )
std::string cata_tiles::get_omt_id_rotation_and_subtile(
const tripoint_abs_omt &omp, int &rota, int &subtile )
{
if( id.length() < 5 ) {
return 0;
}
// save the id for later just in case we don't have a tile
const std::string first_id = id;
int rotation = 0;
std::string suffix = id.substr( id.length() - 5, id.length() - 1 );
if( suffix == "_east" ) {
id = id.substr( 0, id.length() - 5 );
rotation = 1;
} else if( suffix == "_west" ) {
id = id.substr( 0, id.length() - 5 );
rotation = 3;
}
if( id.length() < 6 ) {
return rotation;
}
suffix = id.substr( id.length() - 6, id.length() - 1 );
if( suffix == "_north" ) {
id = id.substr( 0, id.length() - 6 );
rotation = 0;
} else if( suffix == "_south" ) {
id = id.substr( 0, id.length() - 6 );
rotation = 2;
}
if( !find_tile_looks_like( id, TILE_CATEGORY::C_OVERMAP_TERRAIN ) ) {
//fallback tiles
id = first_id;
oter_id ot_id = overmap_buffer.ter( omp );

if( !uistate.overmap_show_forest_trails &&
is_ot_match( "forest_trail", ot_id, ot_match_type::type ) ) {
ot_id = oter_id( "forest" );
}
return rotation;

const oter_t &ot = *ot_id;
oter_type_id ot_type_id = ot.get_type_id();
ot.get_rotation_and_subtile( rota, subtile );
return ot_type_id.id().str();
}

void cata_tiles::draw_om( const point &dest, const tripoint_abs_omt &center_abs_omt, bool blink )
Expand Down Expand Up @@ -861,9 +843,10 @@ void cata_tiles::draw_om( const point &dest, const tripoint_abs_omt &center_abs_

const bool see = overmap_buffer.seen( omp );
const bool los = see && you.overmap_los( omp, sight_points );
const oter_id &cur_ter = overmap_buffer.ter( omp );
// the full string from the ter_id including _north etc.
std::string id;
int rotation = 0;
int subtile = -1;

if( viewing_weather ) {
const tripoint_abs_omt omp_sky( omp.xy(), OVERMAP_HEIGHT );
Expand All @@ -873,21 +856,16 @@ void cata_tiles::draw_om( const point &dest, const tripoint_abs_omt &center_abs_
} else {
id = "unexplored_terrain";
}
} else if( !see ) {
id = "unknown_terrain";
} else {
id = see ? cur_ter->id.c_str() : "unknown_terrain";

if( !uistate.overmap_show_forest_trails &&
is_ot_match( "forest_trail", cur_ter, ot_match_type::type ) ) {
id = "forest";
}
id = get_omt_id_rotation_and_subtile( omp, rotation, subtile );
}

const int rotation = get_omt_rotation( id );

const lit_level ll = overmap_buffer.is_explored( omp ) ? lit_level::LOW : lit_level::LIT;
// light level is now used for choosing between grayscale filter and normal lit tiles.
draw_from_id_string( id, TILE_CATEGORY::C_OVERMAP_TERRAIN, "overmap_terrain", pos, -1, rotation,
ll, false, height_3d );
draw_from_id_string( id, TILE_CATEGORY::C_OVERMAP_TERRAIN, "overmap_terrain", pos,
subtile, rotation, ll, false, height_3d );

if( see ) {
if( blink && uistate.overmap_debug_mongroup ) {
Expand Down Expand Up @@ -954,19 +932,26 @@ void cata_tiles::draw_om( const point &dest, const tripoint_abs_omt &center_abs_
}

if( uistate.place_terrain ) {
const oter_str_id &terrain = uistate.place_terrain->id;
std::string id = terrain.c_str();
const int rotation = get_omt_rotation( id );
draw_from_id_string( id, global_omt_to_draw_position( center_abs_omt ), 0, rotation,
const oter_str_id &terrain_id = uistate.place_terrain->id;
const oter_t &terrain = *terrain_id;
std::string id = terrain.get_type_id().str();
int rotation;
int subtile;
terrain.get_rotation_and_subtile( rotation, subtile );
draw_from_id_string( id, global_omt_to_draw_position( center_abs_omt ), subtile, rotation,
lit_level::LOW, true );
}
if( uistate.place_special ) {
for( const overmap_special_terrain &s_ter : uistate.place_special->terrains ) {
if( s_ter.p.z == 0 ) {
// TODO: fix point types
const point_rel_omt rp( om_direction::rotate( s_ter.p.xy(), uistate.omedit_rotation ) );
std::string id = s_ter.terrain->get_rotated( uistate.omedit_rotation ).id().c_str();
const int rotation = get_omt_rotation( id );
oter_id rotated_id = s_ter.terrain->get_rotated( uistate.omedit_rotation );
const oter_t &terrain = *rotated_id;
std::string id = terrain.get_type_id().str();
int rotation;
int subtile;
terrain.get_rotation_and_subtile( rotation, subtile );

draw_from_id_string( id, TILE_CATEGORY::C_OVERMAP_TERRAIN, "overmap_terrain",
global_omt_to_draw_position( center_abs_omt + rp ), 0, rotation, lit_level::LOW, true );
Expand Down

0 comments on commit aa126fe

Please sign in to comment.