Skip to content

Commit

Permalink
Merge pull request #59061 from Night-Pryanik/nyctophobia
Browse files Browse the repository at this point in the history
Nyctophobia
  • Loading branch information
dseguin authored Jul 18, 2022
2 parents adcf041 + a5852d9 commit 46ef9e3
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
11 changes: 11 additions & 0 deletions data/json/mutations/mutations.json
Original file line number Diff line number Diff line change
Expand Up @@ -8041,5 +8041,16 @@
"player_display": false,
"purifiable": false,
"valid": false
},
{
"type": "mutation",
"id": "NYCTOPHOBIA",
"name": { "str": "Nyctophobia" },
"points": -3,
"description": "You are terribly afraid of the dark. You refuse to enter very dark areas. If you somehow still happen to stay in dark areas, you suffer from various detrimental mental and physical effects.",
"valid": false,
"purifiable": false,
"starting_trait": true,
"flags": [ "NYCTOPHOBIA" ]
}
]
15 changes: 15 additions & 0 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ static const efftype_id effect_riding( "riding" );
static const efftype_id effect_stunned( "stunned" );
static const efftype_id effect_tetanus( "tetanus" );
static const efftype_id effect_tied( "tied" );
static const efftype_id effect_took_xanax( "took_xanax" );
static const efftype_id effect_winded( "winded" );

static const faction_id faction_no_faction( "no_faction" );
Expand Down Expand Up @@ -252,6 +253,7 @@ static const itype_id itype_towel_wet( "towel_wet" );

static const json_character_flag json_flag_CLIMB_NO_LADDER( "CLIMB_NO_LADDER" );
static const json_character_flag json_flag_HYPEROPIC( "HYPEROPIC" );
static const json_character_flag json_flag_NYCTOPHOBIA( "NYCTOPHOBIA" );
static const json_character_flag json_flag_WALL_CLING( "WALL_CLING" );
static const json_character_flag json_flag_WEB_RAPPEL( "WEB_RAPPEL" );

Expand Down Expand Up @@ -9642,6 +9644,19 @@ bool game::walk_move( const tripoint &dest_loc, const bool via_ramp, const bool
}
}

const float dest_light_level = get_map().ambient_light_at( dest_loc );

// Allow players with nyctophobia to move freely through cloudy and dark tiles
const float nyctophobia_threshold = LIGHT_AMBIENT_LIT - 3.0f;

// Forbid players from moving through very dark tiles, unless they are running or took xanax
if( u.has_flag( json_flag_NYCTOPHOBIA ) && !u.has_effect( effect_took_xanax ) && !u.is_running() &&
dest_light_level < nyctophobia_threshold ) {
add_msg( m_bad,
_( "It's so dark and scary in there! You can't force yourself to walk into this tile. Switch to running movement mode to move there." ) );
return false;
}

if( u.is_mounted() ) {
monster *mons = u.mounted_creature.get();
if( mons->has_flag( MF_RIDEABLE_MECH ) ) {
Expand Down
65 changes: 65 additions & 0 deletions src/suffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ static const efftype_id effect_deaf( "deaf" );
static const efftype_id effect_disabled( "disabled" );
static const efftype_id effect_downed( "downed" );
static const efftype_id effect_drunk( "drunk" );
static const efftype_id effect_fearparalyze( "fearparalyze" );
static const efftype_id effect_formication( "formication" );
static const efftype_id effect_grabbed( "grabbed" );
static const efftype_id effect_hallu( "hallu" );
Expand All @@ -97,6 +98,7 @@ static const efftype_id effect_shakes( "shakes" );
static const efftype_id effect_sleep( "sleep" );
static const efftype_id effect_took_antiasthmatic( "took_antiasthmatic" );
static const efftype_id effect_took_thorazine( "took_thorazine" );
static const efftype_id effect_took_xanax( "took_xanax" );
static const efftype_id effect_valium( "valium" );
static const efftype_id effect_visuals( "visuals" );
static const efftype_id effect_weary_0( "weary_0" );
Expand All @@ -119,6 +121,7 @@ static const json_character_flag json_flag_GILLS( "GILLS" );
static const json_character_flag json_flag_GLARE_RESIST( "GLARE_RESIST" );
static const json_character_flag json_flag_MEND_ALL( "MEND_ALL" );
static const json_character_flag json_flag_MEND_LIMB( "MEND_LIMB" );
static const json_character_flag json_flag_NYCTOPHOBIA( "NYCTOPHOBIA" );
static const json_character_flag json_flag_RAD_DETECT( "RAD_DETECT" );

static const mtype_id mon_zombie( "mon_zombie" );
Expand Down Expand Up @@ -199,6 +202,7 @@ static void from_exertion( Character &you );
static void without_sleep( Character &you, int sleep_deprivation );
static void from_tourniquet( Character &you );
static void from_pain( Character &you );
static void from_nyctophobia( Character &you );
} // namespace suffer

static float addiction_scaling( float at_min, float at_max, float add_lvl )
Expand Down Expand Up @@ -365,9 +369,15 @@ void suffer::while_awake( Character &you, const int current_stim )
you.add_effect( effect_downed, 2_turns, false, 0, true );
}
}

if( you.has_flag( json_flag_NYCTOPHOBIA ) && !you.has_effect( effect_took_xanax ) ) {
suffer::from_nyctophobia( you );
}

if( you.has_trait( trait_CHEMIMBALANCE ) ) {
suffer::from_chemimbalance( you );
}

if( you.has_trait( trait_SCHIZOPHRENIC ) &&
!you.has_effect( effect_took_thorazine ) ) {
suffer::from_schizophrenia( you );
Expand Down Expand Up @@ -1646,6 +1656,61 @@ void suffer::from_pain( Character &you )
}
}

void suffer::from_nyctophobia( Character &you )
{
std::vector<tripoint> dark_places;
const float nyctophobia_threshold = LIGHT_AMBIENT_LIT - 3.0f;

for( const tripoint &dark_place : points_in_radius( you.pos(), 5 ) ) {
if( !you.sees( dark_place ) || get_map().ambient_light_at( dark_place ) >= nyctophobia_threshold ) {
continue;
}
dark_places.push_back( dark_place );
}

const bool in_darkness = get_map().ambient_light_at( you.pos() ) < nyctophobia_threshold;
const int chance = in_darkness ? 10 : 50;

if( !dark_places.empty() && one_in( chance ) ) {
g->spawn_hallucination( random_entry( dark_places ) );
}

if( in_darkness ) {
if( one_turn_in( 5_minutes ) ) {
you.add_msg_if_player( m_bad, _( "You feel a twinge of panic as darkness engulfs you." ) );
}

if( one_in( 2 ) && one_turn_in( 30_seconds ) ) {
you.sound_hallu();
}

if( one_in( 50 ) && !you.is_on_ground() ) {
you.add_msg_if_player( m_bad,
_( "Your fear of the dark is so intense that your trembling legs fail you, and you fall to the ground." ) );
you.add_effect( effect_downed, rng( 1_minutes, 2_minutes ) );
}

if( one_in( 50 ) && !you.has_effect( effect_shakes ) ) {
you.add_msg_if_player( m_bad,
_( "Your fear of the dark is so intense that your hands start shaking uncontrollably." ) );
you.add_effect( effect_shakes, rng( 1_minutes, 2_minutes ) );
}

if( one_in( 50 ) ) {
you.add_msg_if_player( m_bad,
_( "Your fear of the dark is so intense that you start breathing rapidly, and you feel like your heart is ready to jump out of the chest." ) );
you.mod_stamina( -500 * rng( 1, 3 ) );
}

if( one_in( 50 ) && !you.has_effect( effect_fearparalyze ) ) {
you.add_msg_if_player( m_bad,
_( "Your fear of the dark is so intense that you stand paralyzed." ) );
you.add_effect( effect_fearparalyze, 5_turns );
you.mod_moves( -4 * you.get_speed() );
}
}
}

void Character::suffer()
{
const int current_stim = get_stim();
Expand Down

0 comments on commit 46ef9e3

Please sign in to comment.