Permalink
Browse files

Move connection computation logic to map

The hope is to share the logic with curses.  Also, it's using a lot of
map structures, so it seems to make sense here.
  • Loading branch information...
jbytheway committed Dec 1, 2018
1 parent 810b948 commit 4ce9fb14be80b81dfede114424ea67f29199a8af
Showing with 43 additions and 29 deletions.
  1. +2 −29 src/cata_tiles.cpp
  2. +34 −0 src/map.cpp
  3. +7 −0 src/map.h
@@ -3068,35 +3068,8 @@ void cata_tiles::get_rotation_and_subtile( const char val, int &rotation, int &s
void cata_tiles::get_connect_values( const tripoint &p, int &subtile, int &rotation,
int connect_group )
{
constexpr std::array<point, 4> offsets = {{
{ 0, 1 }, { 1, 0 }, { -1, 0 }, { 0, -1 }
}
};
auto &ch = g->m.access_cache( p.z );
bool is_transparent =
ch.transparency_cache[p.x][p.y] > LIGHT_TRANSPARENCY_SOLID;
char val = 0;

// populate connection information
for( int i = 0; i < 4; ++i ) {
tripoint neighbour = p + offsets[i];
if( !g->m.inbounds( neighbour ) ) {
continue;
}
const ter_t *neighbour_terrain = nullptr;
if( is_transparent || ch.visibility_cache[neighbour.x][neighbour.y] <= LL_BRIGHT ) {
neighbour_terrain = &g->m.ter( neighbour ).obj();
} else {
ter_str_id t_id( g->u.get_memorized_tile( g->m.getabs( neighbour ) ).tile );
if( t_id.is_valid() ) {
neighbour_terrain = &t_id.obj();
}
}
if( neighbour_terrain && neighbour_terrain->connects_to( connect_group ) ) {
val += 1 << i;
}
}
get_rotation_and_subtile( val, rotation, subtile );
uint8_t connections = g->m.get_known_connections( p, connect_group );
get_rotation_and_subtile( connections, rotation, subtile );
}

void cata_tiles::get_tile_values( const int t, const int *tn, int &subtile, int &rotation )
@@ -1333,6 +1333,40 @@ ter_id map::ter( const tripoint &p ) const
return current_submap->get_ter( l );
}

uint8_t map::get_known_connections( const tripoint &p, int connect_group ) const
{
constexpr std::array<point, 4> offsets = {{
{ 0, 1 }, { 1, 0 }, { -1, 0 }, { 0, -1 }
}
};
auto &ch = access_cache( p.z );
bool is_transparent =
ch.transparency_cache[p.x][p.y] > LIGHT_TRANSPARENCY_SOLID;
uint8_t val = 0;

// populate connection information
for( int i = 0; i < 4; ++i ) {
tripoint neighbour = p + offsets[i];
if( !inbounds( neighbour ) ) {
continue;
}
const ter_t *neighbour_terrain = nullptr;
if( is_transparent || ch.visibility_cache[neighbour.x][neighbour.y] <= LL_BRIGHT ) {
neighbour_terrain = &ter( neighbour ).obj();
} else {
ter_str_id t_id( g->u.get_memorized_tile( getabs( neighbour ) ).tile );
if( t_id.is_valid() ) {
neighbour_terrain = &t_id.obj();
}
}
if( neighbour_terrain && neighbour_terrain->connects_to( connect_group ) ) {
val += 1 << i;
}
}

return val;
}

/*
* Get the results of harvesting this tile's furniture or terrain
*/
@@ -591,6 +591,13 @@ class map
std::string tername( const int x, const int y ) const; // Name of terrain at (x, y)
// Terrain: 3D
ter_id ter( const tripoint &p ) const;

// Return a bitfield of the adjacent tiles which connect to the given
// connect_group. From least-significant bit the order is south, east,
// west, north (because that's what cata_tiles expects).
// Based on a combination of visibility and memory, not simply the true
// terrain.
uint8_t get_known_connections( const tripoint &p, int connect_group ) const;
/**
* Returns the full harvest list, for spawning.
*/

0 comments on commit 4ce9fb1

Please sign in to comment.