Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TRANSLUCENT terrain flag which blocks vision but not light #76290

Merged
merged 10 commits into from
Sep 10, 2024
4 changes: 2 additions & 2 deletions data/json/furniture_and_terrain/terrain-doors.json
Original file line number Diff line number Diff line change
Expand Up @@ -3086,7 +3086,7 @@
"connect_groups": "WALL",
"connects_to": "WALL",
"rotates_to": "INDOORFLOOR",
"flags": [ "DOOR", "NOITEM", "BLOCK_WIND", "SUPPORTS_ROOF" ],
"flags": [ "DOOR", "NOITEM", "BLOCK_WIND", "SUPPORTS_ROOF", "TRANSLUCENT" ],
"open": "t_door_glass_frosted_o",
"copy-from": "t_door_glass_c"
},
Expand All @@ -3101,7 +3101,7 @@
"connect_groups": "WALL",
"connects_to": "WALL",
"rotates_to": "INDOORFLOOR",
"flags": [ "DOOR", "NOITEM", "SUPPORTS_ROOF" ],
"flags": [ "DOOR", "NOITEM", "SUPPORTS_ROOF", "TRANSLUCENT" ],
"open": "t_door_glass_frosted_lab_o",
"copy-from": "t_door_glass_frosted_c"
},
Expand Down
3 changes: 3 additions & 0 deletions data/json/furniture_and_terrain/terrain-windows.json
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,7 @@
"BLOCK_WIND",
"REDUCE_SCENT",
"WINDOW",
"TRANSLUCENT",
"SUPPORTS_ROOF"
],
"bash": {
Expand Down Expand Up @@ -1051,6 +1052,7 @@
"BLOCK_WIND",
"REDUCE_SCENT",
"WINDOW",
"TRANSLUCENT",
"SUPPORTS_ROOF"
],
"bash": {
Expand Down Expand Up @@ -1083,6 +1085,7 @@
"BLOCK_WIND",
"REDUCE_SCENT",
"WINDOW",
"TRANSLUCENT",
"SUPPORTS_ROOF"
],
"bash": {
Expand Down
1 change: 1 addition & 0 deletions doc/JSON_FLAGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@ List of known flags, used in both `furniture` and `terrain`. Some work for both
- ```TRANSLOCATOR``` Tile is a translocator gate, for purposes of the `translocator` examine action.
- ```TRANSPARENT_FLOOR``` This terrain allows light to the z-level below.
- ```TRANSPARENT``` Players and monsters can see through/past it. Also sets ter_t.transparent.
- ```TRANSLUCENT``` Player and monsters can't see through/past it, but it can pass the light
- ```UNSTABLE``` Walking here cause the bouldering effect on the character.
- ```USABLE_FIRE``` This terrain or furniture counts as a nearby fire for crafting.
- ```WALL``` This terrain is an upright obstacle. Used for fungal conversion, and also implies `CONNECT_WITH_WALL`.
Expand Down
18 changes: 17 additions & 1 deletion src/lightmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ bool map::build_transparency_cache( const int zlev )
// Fields are either transparent or not, however we want some to be translucent
value = value * i_level.translucency;
}
// TODO: [lightmap] Have glass reduce light as well
// TODO: [lightmap] Have glass reduce light as well.
// Note, binary transluceny is implemented in build_vision_transparency_cache below
return std::make_pair( value, value_wo_fields );
};

Expand Down Expand Up @@ -208,6 +209,8 @@ bool map::build_vision_transparency_cache( const int zlev )

bool dirty = false;

// This segment handles vision when the player is crouching or prone. It only checks adjacent tiles.
// If you change this, also consider creature::sees and map::obstacle_coverage.
bool is_crouching = player_character.is_crouching();
bool low_profile = player_character.has_effect( effect_quadruped_full ) &&
player_character.is_running();
Expand All @@ -229,6 +232,19 @@ bool map::build_vision_transparency_cache( const int zlev )
}
}

// This segment handles blocking vision through TRANSLUCENT flagged terrain.
// 60 tile radius should cover all potentially visible tiles.
// magical number, TODO replace when Eso finish reality bub things
for( const tripoint &loc : points_in_radius( p, 60 ) ) {
GuardianDll marked this conversation as resolved.
Show resolved Hide resolved
if( loc == p ) {
// The tile player is standing on should always be visible
vision_transparency_cache[p.x][p.y] = LIGHT_TRANSPARENCY_OPEN_AIR;
} else if( map::ter( loc ).obj().has_flag( ter_furn_flag::TFLAG_TRANSLUCENT ) ) {
vision_transparency_cache[loc.x][loc.y] = LIGHT_TRANSPARENCY_SOLID;
dirty = true;
}
}

return dirty;
}

Expand Down
8 changes: 5 additions & 3 deletions src/mapdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,9 @@ std::string enum_to_string<ter_furn_flag>( ter_furn_flag data )
case ter_furn_flag::TFLAG_TRANSPARENT_FLOOR: return "TRANSPARENT_FLOOR";
case ter_furn_flag::TFLAG_TOILET_WATER: return "TOILET_WATER";
case ter_furn_flag::TFLAG_ELEVATOR: return "ELEVATOR";
case ter_furn_flag::TFLAG_ACTIVE_GENERATOR: return "ACTIVE_GENERATOR";
case ter_furn_flag::TFLAG_NO_FLOOR_WATER: return "NO_FLOOR_WATER";
case ter_furn_flag::TFLAG_ACTIVE_GENERATOR: return "ACTIVE_GENERATOR";
case ter_furn_flag::TFLAG_TRANSLUCENT: return "TRANSLUCENT";
case ter_furn_flag::TFLAG_NO_FLOOR_WATER: return "NO_FLOOR_WATER";
case ter_furn_flag::TFLAG_GRAZABLE: return "GRAZABLE";
case ter_furn_flag::TFLAG_GRAZER_INEDIBLE: return "GRAZER_INEDIBLE";
case ter_furn_flag::TFLAG_BROWSABLE: return "BROWSABLE";
Expand Down Expand Up @@ -679,7 +680,8 @@ void load_terrain( const JsonObject &jo, const std::string &src )

void map_data_common_t::extraprocess_flags( const ter_furn_flag flag )
{
if( !transparent && flag == ter_furn_flag::TFLAG_TRANSPARENT ) {
if( !transparent && ( flag == ter_furn_flag::TFLAG_TRANSPARENT ||
flag == ter_furn_flag::TFLAG_TRANSLUCENT ) ) {
transparent = true;
}

Expand Down
2 changes: 2 additions & 0 deletions src/mapdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ struct plant_data {
/*
* List of known flags, used in both terrain.json and furniture.json.
* TRANSPARENT - Players and monsters can see through/past it. Also sets ter_t.transparent
* TRANSLUCENT - Must be paired with TRANSPARENT. Allows light to pass through, but blocks vision.
* FLAT - Player can build and move furniture on
* CONTAINER - Items on this square are hidden until looted by the player
* PLACE_ITEM - Valid terrain for place_item() to put items on
Expand Down Expand Up @@ -201,6 +202,7 @@ struct plant_data {
*/
enum class ter_furn_flag : int {
TFLAG_TRANSPARENT,
TFLAG_TRANSLUCENT,
TFLAG_FLAMMABLE,
TFLAG_REDUCE_SCENT,
TFLAG_SWIMMABLE,
Expand Down
23 changes: 23 additions & 0 deletions tests/vision_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ static const ter_str_id ter_t_flat_roof( "t_flat_roof" );
static const ter_str_id ter_t_floor( "t_floor" );
static const ter_str_id ter_t_utility_light( "t_utility_light" );
static const ter_str_id ter_t_window_frame( "t_window_frame" );
static const ter_str_id ter_t_window_stained_green( "t_window_stained_green" );

static const trait_id trait_MYOPIC( "MYOPIC" );

Expand Down Expand Up @@ -125,6 +126,7 @@ static const tile_predicate set_up_tiles_common =
ifchar( '#', ter_set( ter_t_brick_wall ) + ter_set_flat_roof_above ) ||
ifchar( '=', ter_set( ter_t_window_frame ) + ter_set_flat_roof_above ) ||
ifchar( '-', ter_set( ter_t_floor ) + ter_set_flat_roof_above ) ||
ifchar( 'G', ter_set( ter_t_window_stained_green ) + ter_set_flat_roof_above ) ||
fail;

struct vision_test_flags {
Expand Down Expand Up @@ -424,6 +426,27 @@ TEST_CASE( "vision_crouching_blocks_vision_but_not_light", "[shadowcasting][visi
t.test_all();
}

TEST_CASE( "vision_translucent_blocks_vision_but_not_light", "[shadowcasting][vision]" )
{
vision_test_case t{
{
"###",
"#u#",
"#G#",
" ",
},
{
"444",
"444",
"444",
"666",
},
day_time
};

t.test_all();
}

TEST_CASE( "vision_see_wall_in_moonlight", "[shadowcasting][vision]" )
{
const time_point full_moon = calendar::turn_zero + calendar::season_length() / 6;
Expand Down
Loading