Skip to content

Commit

Permalink
Get rotation and subtile from oter_t
Browse files Browse the repository at this point in the history
Rather than deriving the rotation and subtile from adjacent terrains, we
instead compute them based on the properties of the oter_t.  This
entails yet another table of rotation and subtile values, but does a
better job.  In particular, road connections to other oter_ts
(buildings, bridges) are now rendered correctly, where they were not
before.
  • Loading branch information
jbytheway committed Jul 10, 2021
1 parent b18a310 commit 7683ba0
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 69 deletions.
12 changes: 0 additions & 12 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
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
49 changes: 33 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 @@ -696,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
59 changes: 18 additions & 41 deletions src/sdltiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,45 +758,16 @@ static cata::optional<std::pair<tripoint_abs_omt, std::string>> get_mission_arro
std::string cata_tiles::get_omt_id_rotation_and_subtile(
const tripoint_abs_omt &omp, int &rota, int &subtile )
{
auto oter_at = []( const tripoint_abs_omt & p ) {
const oter_id &cur_ter = overmap_buffer.ter( p );
oter_id ot_id = overmap_buffer.ter( omp );

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

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

oter_id ot_id = oter_at( omp );
const oter_t &ot = *ot_id;
oter_type_id ot_type_id = ot.get_type_id();

if( ot.is_linear() ) {
// get terrain neighborhood
const oter_type_id neighborhood[4] = {
oter_at( omp + point_south )->get_type_id(),
oter_at( omp + point_east )->get_type_id(),
oter_at( omp + point_west )->get_type_id(),
oter_at( omp + point_north )->get_type_id()
};

char val = 0;

// populate connection information
for( int i = 0; i < 4; ++i ) {
if( neighborhood[i] == ot_type_id ) {
val += 1 << i;
}
}

get_rotation_and_subtile( val, rota, subtile );
} else {
// 'Regular', nonlinear terrain only needs to worry about rotation, not
// subtile
rota = static_cast<int>( ot.get_dir() );
}
ot.get_rotation_and_subtile( rota, subtile );
return ot_type_id.id().str();
}

Expand Down Expand Up @@ -961,10 +932,13 @@ 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->get_type_id().str();
const int rotation = static_cast<int>( terrain->get_dir() );
draw_from_id_string( id, global_omt_to_draw_position( center_abs_omt ), -1, 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 ) {
Expand All @@ -973,8 +947,11 @@ void cata_tiles::draw_om( const point &dest, const tripoint_abs_omt &center_abs_
// TODO: fix point types
const point_rel_omt rp( om_direction::rotate( s_ter.p.xy(), uistate.omedit_rotation ) );
oter_id rotated_id = s_ter.terrain->get_rotated( uistate.omedit_rotation );
std::string id = s_ter.terrain.str();
const int rotation = static_cast<int>( rotated_id->get_dir() );
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 7683ba0

Please sign in to comment.