From 2cc50b5e7a2678c6dd09d70a1fb2de0affa6a219 Mon Sep 17 00:00:00 2001 From: KorGgenT Date: Tue, 7 Jan 2020 19:51:08 -0500 Subject: [PATCH 1/4] change scope of members --- src/character.h | 23 +++++++++++++++++++++++ src/creature.h | 2 +- src/player.cpp | 37 ++++++++++++++++--------------------- src/player.h | 27 --------------------------- 4 files changed, 40 insertions(+), 49 deletions(-) diff --git a/src/character.h b/src/character.h index 88cc4acb1382c..0d6e8442c441e 100644 --- a/src/character.h +++ b/src/character.h @@ -416,6 +416,29 @@ class Character : public Creature, public visitable float get_dodge_base() const override; float get_hit_base() const override; + const tripoint &pos() const override; + /** Returns the player's sight range */ + int sight_range( int light_level ) const override; + /** Returns the player maximum vision range factoring in mutations, diseases, and other effects */ + int unimpaired_range() const; + /** Returns true if overmap tile is within player line-of-sight */ + bool overmap_los( const tripoint &omt, int sight_points ); + /** Returns the distance the player can see on the overmap */ + int overmap_sight_range( int light_level ) const; + /** Returns the distance the player can see through walls */ + int clairvoyance() const; + /** Returns true if the player has some form of impaired sight */ + bool sight_impaired() const; + /** Returns true if the player or their vehicle has an alarm clock */ + bool has_alarm_clock() const; + /** Returns true if the player or their vehicle has a watch */ + bool has_watch() const; + /** Called after every action, invalidates player caches */ + void action_taken(); + /** Returns true if the player is knocked over or has broken legs */ + bool is_on_ground() const override; + /** Returns the player's speed for swimming across water tiles */ + int swim_speed() const; /** * Adds a reason for why the player would miss a melee attack. * diff --git a/src/creature.h b/src/creature.h index 36982dcc3cf16..8c5017c5f85f7 100644 --- a/src/creature.h +++ b/src/creature.h @@ -277,7 +277,7 @@ class Creature virtual bool digging() const; virtual bool is_on_ground() const = 0; - virtual bool is_underwater() const = 0; + virtual bool is_underwater() const; virtual bool is_warm() const; // is this creature warm, for IR vision, heat drain, etc virtual bool in_species( const species_id & ) const; diff --git a/src/player.cpp b/src/player.cpp index 86b2c302a1e62..4a7c376d223c9 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -499,7 +499,7 @@ void player::process_turn() } } -void player::action_taken() +void Character::action_taken() { nv_cached = false; } @@ -710,7 +710,7 @@ int player::run_cost( int base_cost, bool diag ) const return static_cast( movecost ); } -int player::swim_speed() const +int Character::swim_speed() const { int ret; if( is_mounted() ) { @@ -788,12 +788,7 @@ int player::swim_speed() const return ret; } -bool player::digging() const -{ - return false; -} - -bool player::is_on_ground() const +bool Character::is_on_ground() const { return get_working_leg_count() < 2 || has_effect( effect_downed ); } @@ -827,7 +822,7 @@ double player::recoil_total() const return recoil + recoil_vehicle(); } -bool player::is_underwater() const +bool Creature::is_underwater() const { return underwater; } @@ -1031,12 +1026,12 @@ std::list player::get_artifact_items() return art_items; } -const tripoint &player::pos() const +const tripoint &Character::pos() const { return position; } -int player::sight_range( int light_level ) const +int Character::sight_range( int light_level ) const { if( light_level == 0 ) { return 1; @@ -1059,15 +1054,15 @@ int player::sight_range( int light_level ) const // int range = log(light_level * LIGHT_AMBIENT_LOW) / LIGHT_TRANSPARENCY_OPEN_AIR; // Clamp to [1, sight_max]. - return std::max( 1, std::min( range, sight_max ) ); + return clamp( range, 1, sight_max ); } -int player::unimpaired_range() const +int Character::unimpaired_range() const { return std::min( sight_max, 60 ); } -bool player::overmap_los( const tripoint &omt, int sight_points ) +bool Character::overmap_los( const tripoint &omt, int sight_points ) { const tripoint ompos = global_omt_location(); if( omt.x < ompos.x - sight_points || omt.x > ompos.x + sight_points || @@ -1088,7 +1083,7 @@ bool player::overmap_los( const tripoint &omt, int sight_points ) return true; } -int player::overmap_sight_range( int light_level ) const +int Character::overmap_sight_range( int light_level ) const { int sight = sight_range( light_level ); if( sight < SEEX ) { @@ -1104,9 +1099,9 @@ int player::overmap_sight_range( int light_level ) const // The higher up you are, the farther you can see. sight += std::max( 0, posz() ) * 2; // Mutations like Scout and Topographagnosia affect how far you can see. - sight += Character::mutation_value( "overmap_sight" ); + sight += mutation_value( "overmap_sight" ); - float multiplier = Character::mutation_value( "overmap_multiplier" ); + float multiplier = mutation_value( "overmap_multiplier" ); // Binoculars double your sight range. const bool has_optic = ( has_item_with_flag( "ZOOM" ) || has_bionic( bio_eye_optic ) || ( is_mounted() && @@ -1120,7 +1115,7 @@ int player::overmap_sight_range( int light_level ) const } #define MAX_CLAIRVOYANCE 40 -int player::clairvoyance() const +int Character::clairvoyance() const { if( vision_mode_cache[VISION_CLAIRVOYANCE_SUPER] ) { return MAX_CLAIRVOYANCE; @@ -1137,7 +1132,7 @@ int player::clairvoyance() const return 0; } -bool player::sight_impaired() const +bool Character::sight_impaired() const { return ( ( ( has_effect( effect_boomered ) || has_effect( effect_no_sight ) || has_effect( effect_darkness ) ) && @@ -1176,7 +1171,7 @@ bool player::avoid_trap( const tripoint &pos, const trap &tr ) const return myroll >= traproll; } -bool player::has_alarm_clock() const +bool Character::has_alarm_clock() const { return ( has_item_with_flag( "ALARMCLOCK", true ) || ( g->m.veh_at( pos() ) && @@ -1184,7 +1179,7 @@ bool player::has_alarm_clock() const has_bionic( bio_watch ) ); } -bool player::has_watch() const +bool Character::has_watch() const { return ( has_item_with_flag( "WATCH", true ) || ( g->m.veh_at( pos() ) && diff --git a/src/player.h b/src/player.h index d660528685e99..f5697ab4f234f 100644 --- a/src/player.h +++ b/src/player.h @@ -179,15 +179,11 @@ class player : public Character void process_turn() override; /** Calculates the various speed bonuses we will get from mutations, etc. */ void recalc_speed_bonus(); - /** Called after every action, invalidates player caches */ - void action_taken(); /** Define color for displaying the body temperature */ nc_color bodytemp_color( int bp ) const; /** Returns the player's modified base movement cost */ int run_cost( int base_cost, bool diag = false ) const; - /** Returns the player's speed for swimming across water tiles */ - int swim_speed() const; /** Maintains body wetness and handles the rate at which the player dries */ void update_body_wetness( const w_point &weather ); @@ -227,29 +223,11 @@ class player : public Character /** Returns the bionic with the given invlet, or NULL if no bionic has that invlet */ bionic *bionic_by_invlet( int ch ); - const tripoint &pos() const override; - /** Returns the player's sight range */ - int sight_range( int light_level ) const override; - /** Returns the player maximum vision range factoring in mutations, diseases, and other effects */ - int unimpaired_range() const; - /** Returns true if overmap tile is within player line-of-sight */ - bool overmap_los( const tripoint &omt, int sight_points ); - /** Returns the distance the player can see on the overmap */ - int overmap_sight_range( int light_level ) const; - /** Returns the distance the player can see through walls */ - int clairvoyance() const; - /** Returns true if the player has some form of impaired sight */ - bool sight_impaired() const; /** Calculates melee weapon wear-and-tear through use, returns true if item is destroyed. */ bool handle_melee_wear( item &shield, float wear_multiplier = 1.0f ); /** Called when a player triggers a trap, returns true if they don't set it off */ bool avoid_trap( const tripoint &pos, const trap &tr ) const override; - /** Returns true if the player or their vehicle has an alarm clock */ - bool has_alarm_clock() const; - /** Returns true if the player or their vehicle has a watch */ - bool has_watch() const; - // see Creature::sees bool sees( const tripoint &t, bool is_player = false, int range_mod = 0 ) const override; // see Creature::sees @@ -296,10 +274,6 @@ class player : public Character bool is_stealthy() const; /** Returns true if the current martial art works with the player's current weapon */ bool can_melee() const; - /** Always returns false, since players can't dig currently */ - bool digging() const override; - /** Returns true if the player is knocked over or has broken legs */ - bool is_on_ground() const override; /** Returns true if the player should be dead */ bool is_dead_state() const override; @@ -952,7 +926,6 @@ class player : public Character std::set follower_ids; void mod_stat( const std::string &stat, float modifier ) override; - bool is_underwater() const override; void set_underwater( bool ); bool is_hallucination() const override; void environmental_revert_effect(); From 2069490916552acc1ded60c633686da49869b9d7 Mon Sep 17 00:00:00 2001 From: KorGgenT Date: Tue, 7 Jan 2020 20:10:57 -0500 Subject: [PATCH 2/4] move function definitions to proper files --- src/character.cpp | 261 ++++++++++++++++++++++++++++++++++++++++++++++ src/character.h | 2 + src/creature.cpp | 5 + src/player.cpp | 254 -------------------------------------------- 4 files changed, 268 insertions(+), 254 deletions(-) diff --git a/src/character.cpp b/src/character.cpp index 2d08bcdc98e29..9b4d2a7478b5a 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -66,6 +66,7 @@ #include "vehicle.h" #include "vitamin.h" #include "vpart_position.h" +#include "vpart_range.h" static const activity_id ACT_DROP( "ACT_DROP" ); static const activity_id ACT_MOVE_ITEMS( "ACT_MOVE_ITEMS" ); @@ -74,6 +75,9 @@ static const activity_id ACT_TREE_COMMUNION( "ACT_TREE_COMMUNION" ); static const activity_id ACT_TRY_SLEEP( "ACT_TRY_SLEEP" ); static const activity_id ACT_WAIT_STAMINA( "ACT_WAIT_STAMINA" ); +static const bionic_id bio_eye_optic( "bio_eye_optic" ); +static const bionic_id bio_watch( "bio_watch" ); + static const efftype_id effect_adrenaline( "adrenaline" ); static const efftype_id effect_alarm_clock( "alarm_clock" ); static const efftype_id effect_bandaged( "bandaged" ); @@ -137,6 +141,12 @@ static const efftype_id effect_took_xanax( "took_xanax" ); static const efftype_id effect_webbed( "webbed" ); static const efftype_id effect_winded( "winded" ); +static const species_id ROBOT( "ROBOT" ); + +static const skill_id skill_dodge( "dodge" ); +static const skill_id skill_swimming( "swimming" ); +static const skill_id skill_throw( "throw" ); + static const trait_id trait_ACIDBLOOD( "ACIDBLOOD" ); static const trait_id trait_ACIDPROOF( "ACIDPROOF" ); static const trait_id trait_ADRENALINE( "ADRENALINE" ); @@ -210,6 +220,8 @@ static const trait_id trait_FEL_NV( "FEL_NV" ); static const trait_id trait_GILLS( "GILLS" ); static const trait_id trait_GILLS_CEPH( "GILLS_CEPH" ); static const trait_id trait_GLASSJAW( "GLASSJAW" ); +static const trait_id trait_HEAVYSLEEPER( "HEAVYSLEEPER" ); +static const trait_id trait_HEAVYSLEEPER2( "HEAVYSLEEPER2" ); static const trait_id trait_HIBERNATE( "HIBERNATE" ); static const trait_id trait_HOARDER( "HOARDER" ); static const trait_id trait_HOLLOW_BONES( "HOLLOW_BONES" ); @@ -232,6 +244,8 @@ static const trait_id trait_NOMAD2( "NOMAD2" ); static const trait_id trait_NOMAD3( "NOMAD3" ); static const trait_id trait_NOPAIN( "NOPAIN" ); static const trait_id trait_PACKMULE( "PACKMULE" ); +static const trait_id trait_PAWS( "PAWS" ); +static const trait_id trait_PAWS_LARGE( "PAWS_LARGE" ); static const trait_id trait_PER_SLIME( "PER_SLIME" ); static const trait_id trait_PER_SLIME_OK( "PER_SLIME_OK" ); static const trait_id trait_PROF_FOODP( "PROF_FOODP" ); @@ -255,9 +269,11 @@ static const trait_id trait_TRANSPIRATION( "TRANSPIRATION" ); static const trait_id trait_URSINE_EYE( "URSINE_EYE" ); static const trait_id trait_VISCOUS( "VISCOUS" ); static const trait_id trait_WATERSLEEP( "WATERSLEEP" ); +static const trait_id trait_WEBBED( "WEBBED" ); static const trait_id trait_WEB_SPINNER( "WEB_SPINNER" ); static const trait_id trait_WEB_WALKER( "WEB_WALKER" ); static const trait_id trait_WEB_WEAVER( "WEB_WEAVER" ); +static const trait_id debug_nodmg( "DEBUG_NODMG" ); static const std::string flag_ACTIVE_CLOAKING( "ACTIVE_CLOAKING" ); static const std::string flag_ALLOWS_NATURAL_ATTACKS( "ALLOWS_NATURAL_ATTACKS" ); @@ -624,6 +640,251 @@ double Character::aim_per_move( const item &gun, double recoil ) const return std::min( aim_speed, recoil - limit ); } +const tripoint &Character::pos() const +{ + return position; +} + +int Character::sight_range( int light_level ) const +{ + /* Via Beer-Lambert we have: + * light_level * (1 / exp( LIGHT_TRANSPARENCY_OPEN_AIR * distance) ) <= LIGHT_AMBIENT_LOW + * Solving for distance: + * 1 / exp( LIGHT_TRANSPARENCY_OPEN_AIR * distance ) <= LIGHT_AMBIENT_LOW / light_level + * 1 <= exp( LIGHT_TRANSPARENCY_OPEN_AIR * distance ) * LIGHT_AMBIENT_LOW / light_level + * light_level <= exp( LIGHT_TRANSPARENCY_OPEN_AIR * distance ) * LIGHT_AMBIENT_LOW + * log(light_level) <= LIGHT_TRANSPARENCY_OPEN_AIR * distance + log(LIGHT_AMBIENT_LOW) + * log(light_level) - log(LIGHT_AMBIENT_LOW) <= LIGHT_TRANSPARENCY_OPEN_AIR * distance + * log(LIGHT_AMBIENT_LOW / light_level) <= LIGHT_TRANSPARENCY_OPEN_AIR * distance + * log(LIGHT_AMBIENT_LOW / light_level) * (1 / LIGHT_TRANSPARENCY_OPEN_AIR) <= distance + */ + int range = static_cast( -log( get_vision_threshold( static_cast( g->m.ambient_light_at( + pos() ) ) ) / + static_cast( light_level ) ) * + ( 1.0 / LIGHT_TRANSPARENCY_OPEN_AIR ) ); + // int range = log(light_level * LIGHT_AMBIENT_LOW) / LIGHT_TRANSPARENCY_OPEN_AIR; + + // Clamp to [1, sight_max]. + return clamp( range, 1, sight_max ); +} + +int Character::unimpaired_range() const +{ + return std::min( sight_max, 60 ); +} + +bool Character::overmap_los( const tripoint &omt, int sight_points ) +{ + const tripoint ompos = global_omt_location(); + if( omt.x < ompos.x - sight_points || omt.x > ompos.x + sight_points || + omt.y < ompos.y - sight_points || omt.y > ompos.y + sight_points ) { + // Outside maximum sight range + return false; + } + + const std::vector line = line_to( ompos, omt, 0, 0 ); + for( size_t i = 0; i < line.size() && sight_points >= 0; i++ ) { + const tripoint &pt = line[i]; + const oter_id &ter = overmap_buffer.ter( pt ); + sight_points -= static_cast( ter->get_see_cost() ); + if( sight_points < 0 ) { + return false; + } + } + return true; +} + +int Character::overmap_sight_range( int light_level ) const +{ + int sight = sight_range( light_level ); + if( sight < SEEX ) { + return 0; + } + if( sight <= SEEX * 4 ) { + return ( sight / ( SEEX / 2 ) ); + } + + sight = 6; + // The higher your perception, the farther you can see. + sight += static_cast( get_per() / 2 ); + // The higher up you are, the farther you can see. + sight += std::max( 0, posz() ) * 2; + // Mutations like Scout and Topographagnosia affect how far you can see. + sight += mutation_value( "overmap_sight" ); + + float multiplier = mutation_value( "overmap_multiplier" ); + // Binoculars double your sight range. + const bool has_optic = ( has_item_with_flag( "ZOOM" ) || has_bionic( bio_eye_optic ) || + ( is_mounted() && + mounted_creature->has_flag( MF_MECH_RECON_VISION ) ) ); + if( has_optic ) { + multiplier += 1; + } + + sight = round( sight * multiplier ); + return std::max( sight, 3 ); +} + +int Character::clairvoyance() const +{ + if( vision_mode_cache[VISION_CLAIRVOYANCE_SUPER] ) { + return MAX_CLAIRVOYANCE; + } + + if( vision_mode_cache[VISION_CLAIRVOYANCE_PLUS] ) { + return 8; + } + + if( vision_mode_cache[VISION_CLAIRVOYANCE] ) { + return 3; + } + + return 0; +} + +bool Character::sight_impaired() const +{ + return ( ( ( has_effect( effect_boomered ) || has_effect( effect_no_sight ) || + has_effect( effect_darkness ) ) && + ( !( has_trait( trait_PER_SLIME_OK ) ) ) ) || + ( underwater && !has_bionic( bio_membrane ) && !has_trait( trait_MEMBRANE ) && + !worn_with_flag( "SWIM_GOGGLES" ) && !has_trait( trait_PER_SLIME_OK ) && + !has_trait( trait_CEPH_EYES ) && !has_trait( trait_SEESLEEP ) ) || + ( ( has_trait( trait_MYOPIC ) || has_trait( trait_URSINE_EYE ) ) && + !worn_with_flag( "FIX_NEARSIGHT" ) && + !has_effect( effect_contacts ) && + !has_bionic( bio_eye_optic ) ) || + has_trait( trait_PER_SLIME ) ); +} + +bool Character::has_alarm_clock() const +{ + return ( has_item_with_flag( "ALARMCLOCK", true ) || + ( g->m.veh_at( pos() ) && + !empty( g->m.veh_at( pos() )->vehicle().get_avail_parts( "ALARMCLOCK" ) ) ) || + has_bionic( bio_watch ) ); +} + +bool Character::has_watch() const +{ + return ( has_item_with_flag( "WATCH", true ) || + ( g->m.veh_at( pos() ) && + !empty( g->m.veh_at( pos() )->vehicle().get_avail_parts( "WATCH" ) ) ) || + has_bionic( bio_watch ) ); +} + +void Character::react_to_felt_pain( int intensity ) +{ + if( intensity <= 0 ) { + return; + } + if( is_player() && intensity >= 2 ) { + g->cancel_activity_or_ignore_query( distraction_type::pain, _( "Ouch, something hurts!" ) ); + } + // Only a large pain burst will actually wake people while sleeping. + if( has_effect( effect_sleep ) && !has_effect( effect_narcosis ) ) { + int pain_thresh = rng( 3, 5 ); + + if( has_trait( trait_HEAVYSLEEPER ) ) { + pain_thresh += 2; + } else if( has_trait( trait_HEAVYSLEEPER2 ) ) { + pain_thresh += 5; + } + + if( intensity >= pain_thresh ) { + wake_up(); + } + } +} + +void Character::action_taken() +{ + nv_cached = false; +} + +int Character::swim_speed() const +{ + int ret; + if( is_mounted() ) { + monster *mon = mounted_creature.get(); + // no difference in swim speed by monster type yet. + // TODO: difference in swim speed by monster type. + // No monsters are currently mountable and can swim, though mods may allow this. + if( mon->swims() ) { + ret = 25; + ret += get_weight() / 120_gram - 50 * ( mon->get_size() - 1 ); + return ret; + } + } + const auto usable = exclusive_flag_coverage( "ALLOWS_NATURAL_ATTACKS" ); + float hand_bonus_mult = ( usable.test( bp_hand_l ) ? 0.5f : 0.0f ) + + ( usable.test( bp_hand_r ) ? 0.5f : 0.0f ); + + // base swim speed. + ret = ( 440 * mutation_value( "movecost_swim_modifier" ) ) + weight_carried() / + ( 60_gram / mutation_value( "movecost_swim_modifier" ) ) - 50 * get_skill_level( skill_swimming ); + /** @EFFECT_STR increases swim speed bonus from PAWS */ + if( has_trait( trait_PAWS ) ) { + ret -= hand_bonus_mult * ( 20 + str_cur * 3 ); + } + /** @EFFECT_STR increases swim speed bonus from PAWS_LARGE */ + if( has_trait( trait_PAWS_LARGE ) ) { + ret -= hand_bonus_mult * ( 20 + str_cur * 4 ); + } + /** @EFFECT_STR increases swim speed bonus from swim_fins */ + if( worn_with_flag( "FIN", bp_foot_l ) || worn_with_flag( "FIN", bp_foot_r ) ) { + if( worn_with_flag( "FIN", bp_foot_l ) && worn_with_flag( "FIN", bp_foot_r ) ) { + ret -= ( 15 * str_cur ); + } else { + ret -= ( 15 * str_cur ) / 2; + } + } + /** @EFFECT_STR increases swim speed bonus from WEBBED */ + if( has_trait( trait_WEBBED ) ) { + ret -= hand_bonus_mult * ( 60 + str_cur * 5 ); + } + /** @EFFECT_SWIMMING increases swim speed */ + ret += ( 50 - get_skill_level( skill_swimming ) * 2 ) * ( ( encumb( bp_leg_l ) + encumb( + bp_leg_r ) ) / 10 ); + ret += ( 80 - get_skill_level( skill_swimming ) * 3 ) * ( encumb( bp_torso ) / 10 ); + if( get_skill_level( skill_swimming ) < 10 ) { + for( auto &i : worn ) { + ret += i.volume() / 125_ml * ( 10 - get_skill_level( skill_swimming ) ); + } + } + /** @EFFECT_STR increases swim speed */ + + /** @EFFECT_DEX increases swim speed */ + ret -= str_cur * 6 + dex_cur * 4; + if( worn_with_flag( "FLOTATION" ) ) { + ret = std::min( ret, 400 ); + ret = std::max( ret, 200 ); + } + // If (ret > 500), we can not swim; so do not apply the underwater bonus. + if( underwater && ret < 500 ) { + ret -= 50; + } + + // Running movement mode while swimming means faster swim style, like crawlstroke + if( move_mode == CMM_RUN ) { + ret -= 80; + } + // Crouching movement mode while swimming means slower swim style, like breaststroke + if( move_mode == CMM_CROUCH ) { + ret += 50; + } + + if( ret < 30 ) { + ret = 30; + } + return ret; +} + +bool Character::is_on_ground() const +{ + return get_working_leg_count() < 2 || has_effect( effect_downed ); +} + void Character::cancel_stashed_activity() { stashed_outbounds_activity = player_activity(); diff --git a/src/character.h b/src/character.h index 0d6e8442c441e..32dc3dac7325c 100644 --- a/src/character.h +++ b/src/character.h @@ -64,6 +64,8 @@ struct bionic; using drop_location = std::pair; using drop_locations = std::list; +#define MAX_CLAIRVOYANCE 40 + enum vision_modes { DEBUG_NIGHTVISION, NV_GOGGLES, diff --git a/src/creature.cpp b/src/creature.cpp index 375718e0c379a..54a9d88266ee1 100644 --- a/src/creature.cpp +++ b/src/creature.cpp @@ -156,6 +156,11 @@ void Creature::process_turn() } } +bool Creature::is_underwater() const +{ + return underwater; +} + bool Creature::digging() const { return false; diff --git a/src/player.cpp b/src/player.cpp index 4a7c376d223c9..3f39b9fcb10d0 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -499,11 +499,6 @@ void player::process_turn() } } -void Character::action_taken() -{ - nv_cached = false; -} - int player::kcal_speed_penalty() { static const std::vector> starv_thresholds = { { @@ -710,89 +705,6 @@ int player::run_cost( int base_cost, bool diag ) const return static_cast( movecost ); } -int Character::swim_speed() const -{ - int ret; - if( is_mounted() ) { - monster *mon = mounted_creature.get(); - // no difference in swim speed by monster type yet. - // TODO: difference in swim speed by monster type. - // No monsters are currently mountable and can swim, though mods may allow this. - if( mon->swims() ) { - ret = 25; - ret += get_weight() / 120_gram - 50 * ( mon->get_size() - 1 ); - return ret; - } - } - const auto usable = exclusive_flag_coverage( "ALLOWS_NATURAL_ATTACKS" ); - float hand_bonus_mult = ( usable.test( bp_hand_l ) ? 0.5f : 0.0f ) + - ( usable.test( bp_hand_r ) ? 0.5f : 0.0f ); - - // base swim speed. - ret = ( 440 * mutation_value( "movecost_swim_modifier" ) ) + weight_carried() / - ( 60_gram / mutation_value( "movecost_swim_modifier" ) ) - 50 * get_skill_level( skill_swimming ); - /** @EFFECT_STR increases swim speed bonus from PAWS */ - if( has_trait( trait_PAWS ) ) { - ret -= hand_bonus_mult * ( 20 + str_cur * 3 ); - } - /** @EFFECT_STR increases swim speed bonus from PAWS_LARGE */ - if( has_trait( trait_PAWS_LARGE ) ) { - ret -= hand_bonus_mult * ( 20 + str_cur * 4 ); - } - /** @EFFECT_STR increases swim speed bonus from swim_fins */ - if( worn_with_flag( "FIN", bp_foot_l ) || worn_with_flag( "FIN", bp_foot_r ) ) { - if( worn_with_flag( "FIN", bp_foot_l ) && worn_with_flag( "FIN", bp_foot_r ) ) { - ret -= ( 15 * str_cur ); - } else { - ret -= ( 15 * str_cur ) / 2; - } - } - /** @EFFECT_STR increases swim speed bonus from WEBBED */ - if( has_trait( trait_WEBBED ) ) { - ret -= hand_bonus_mult * ( 60 + str_cur * 5 ); - } - /** @EFFECT_SWIMMING increases swim speed */ - ret += ( 50 - get_skill_level( skill_swimming ) * 2 ) * ( ( encumb( bp_leg_l ) + encumb( - bp_leg_r ) ) / 10 ); - ret += ( 80 - get_skill_level( skill_swimming ) * 3 ) * ( encumb( bp_torso ) / 10 ); - if( get_skill_level( skill_swimming ) < 10 ) { - for( auto &i : worn ) { - ret += i.volume() / 125_ml * ( 10 - get_skill_level( skill_swimming ) ); - } - } - /** @EFFECT_STR increases swim speed */ - - /** @EFFECT_DEX increases swim speed */ - ret -= str_cur * 6 + dex_cur * 4; - if( worn_with_flag( "FLOTATION" ) ) { - ret = std::min( ret, 400 ); - ret = std::max( ret, 200 ); - } - // If (ret > 500), we can not swim; so do not apply the underwater bonus. - if( underwater && ret < 500 ) { - ret -= 50; - } - - // Running movement mode while swimming means faster swim style, like crawlstroke - if( move_mode == CMM_RUN ) { - ret -= 80; - } - // Crouching movement mode while swimming means slower swim style, like breaststroke - if( move_mode == CMM_CROUCH ) { - ret += 50; - } - - if( ret < 30 ) { - ret = 30; - } - return ret; -} - -bool Character::is_on_ground() const -{ - return get_working_leg_count() < 2 || has_effect( effect_downed ); -} - float player::stability_roll() const { /** @EFFECT_STR improves player stability roll */ @@ -822,11 +734,6 @@ double player::recoil_total() const return recoil + recoil_vehicle(); } -bool Creature::is_underwater() const -{ - return underwater; -} - bool player::is_hallucination() const { return false; @@ -1026,127 +933,6 @@ std::list player::get_artifact_items() return art_items; } -const tripoint &Character::pos() const -{ - return position; -} - -int Character::sight_range( int light_level ) const -{ - if( light_level == 0 ) { - return 1; - } - /* Via Beer-Lambert we have: - * light_level * (1 / exp( LIGHT_TRANSPARENCY_OPEN_AIR * distance) ) <= LIGHT_AMBIENT_LOW - * Solving for distance: - * 1 / exp( LIGHT_TRANSPARENCY_OPEN_AIR * distance ) <= LIGHT_AMBIENT_LOW / light_level - * 1 <= exp( LIGHT_TRANSPARENCY_OPEN_AIR * distance ) * LIGHT_AMBIENT_LOW / light_level - * light_level <= exp( LIGHT_TRANSPARENCY_OPEN_AIR * distance ) * LIGHT_AMBIENT_LOW - * log(light_level) <= LIGHT_TRANSPARENCY_OPEN_AIR * distance + log(LIGHT_AMBIENT_LOW) - * log(light_level) - log(LIGHT_AMBIENT_LOW) <= LIGHT_TRANSPARENCY_OPEN_AIR * distance - * log(LIGHT_AMBIENT_LOW / light_level) <= LIGHT_TRANSPARENCY_OPEN_AIR * distance - * log(LIGHT_AMBIENT_LOW / light_level) * (1 / LIGHT_TRANSPARENCY_OPEN_AIR) <= distance - */ - float vision_threshold = - get_vision_threshold( static_cast( g->m.ambient_light_at( pos() ) ) ); - int range = static_cast( -log( vision_threshold / light_level ) * - ( 1.0 / LIGHT_TRANSPARENCY_OPEN_AIR ) ); - // int range = log(light_level * LIGHT_AMBIENT_LOW) / LIGHT_TRANSPARENCY_OPEN_AIR; - - // Clamp to [1, sight_max]. - return clamp( range, 1, sight_max ); -} - -int Character::unimpaired_range() const -{ - return std::min( sight_max, 60 ); -} - -bool Character::overmap_los( const tripoint &omt, int sight_points ) -{ - const tripoint ompos = global_omt_location(); - if( omt.x < ompos.x - sight_points || omt.x > ompos.x + sight_points || - omt.y < ompos.y - sight_points || omt.y > ompos.y + sight_points ) { - // Outside maximum sight range - return false; - } - - const std::vector line = line_to( ompos, omt, 0, 0 ); - for( size_t i = 0; i < line.size() && sight_points >= 0; i++ ) { - const tripoint &pt = line[i]; - const oter_id &ter = overmap_buffer.ter( pt ); - sight_points -= static_cast( ter->get_see_cost() ); - if( sight_points < 0 ) { - return false; - } - } - return true; -} - -int Character::overmap_sight_range( int light_level ) const -{ - int sight = sight_range( light_level ); - if( sight < SEEX ) { - return 0; - } - if( sight <= SEEX * 4 ) { - return ( sight / ( SEEX / 2 ) ); - } - - sight = 6; - // The higher your perception, the farther you can see. - sight += static_cast( get_per() / 2 ); - // The higher up you are, the farther you can see. - sight += std::max( 0, posz() ) * 2; - // Mutations like Scout and Topographagnosia affect how far you can see. - sight += mutation_value( "overmap_sight" ); - - float multiplier = mutation_value( "overmap_multiplier" ); - // Binoculars double your sight range. - const bool has_optic = ( has_item_with_flag( "ZOOM" ) || has_bionic( bio_eye_optic ) || - ( is_mounted() && - mounted_creature->has_flag( MF_MECH_RECON_VISION ) ) ); - if( has_optic ) { - multiplier += 1; - } - - sight = round( sight * multiplier ); - return std::max( sight, 3 ); -} - -#define MAX_CLAIRVOYANCE 40 -int Character::clairvoyance() const -{ - if( vision_mode_cache[VISION_CLAIRVOYANCE_SUPER] ) { - return MAX_CLAIRVOYANCE; - } - - if( vision_mode_cache[VISION_CLAIRVOYANCE_PLUS] ) { - return 8; - } - - if( vision_mode_cache[VISION_CLAIRVOYANCE] ) { - return 3; - } - - return 0; -} - -bool Character::sight_impaired() const -{ - return ( ( ( has_effect( effect_boomered ) || has_effect( effect_no_sight ) || - has_effect( effect_darkness ) ) && - ( !( has_trait( trait_PER_SLIME_OK ) ) ) ) || - ( underwater && !has_bionic( bio_membrane ) && !has_trait( trait_MEMBRANE ) && - !worn_with_flag( "SWIM_GOGGLES" ) && !has_trait( trait_PER_SLIME_OK ) && - !has_trait( trait_CEPH_EYES ) && !has_trait( trait_SEESLEEP ) ) || - ( ( has_trait( trait_MYOPIC ) || has_trait( trait_URSINE_EYE ) ) && - !worn_with_flag( "FIX_NEARSIGHT" ) && - !has_effect( effect_contacts ) && - !has_bionic( bio_eye_optic ) ) || - has_trait( trait_PER_SLIME ) ); -} - bool player::avoid_trap( const tripoint &pos, const trap &tr ) const { /** @EFFECT_DEX increases chance to avoid traps */ @@ -1171,22 +957,6 @@ bool player::avoid_trap( const tripoint &pos, const trap &tr ) const return myroll >= traproll; } -bool Character::has_alarm_clock() const -{ - return ( has_item_with_flag( "ALARMCLOCK", true ) || - ( g->m.veh_at( pos() ) && - !empty( g->m.veh_at( pos() )->vehicle().get_avail_parts( "ALARMCLOCK" ) ) ) || - has_bionic( bio_watch ) ); -} - -bool Character::has_watch() const -{ - return ( has_item_with_flag( "WATCH", true ) || - ( g->m.veh_at( pos() ) && - !empty( g->m.veh_at( pos() )->vehicle().get_avail_parts( "WATCH" ) ) ) || - has_bionic( bio_watch ) ); -} - void player::pause() { moves = 0; @@ -1751,30 +1521,6 @@ int player::get_perceived_pain() const return std::max( get_pain() - get_painkiller(), 0 ); } -void Character::react_to_felt_pain( int intensity ) -{ - if( intensity <= 0 ) { - return; - } - if( is_player() && intensity >= 2 ) { - g->cancel_activity_or_ignore_query( distraction_type::pain, _( "Ouch, something hurts!" ) ); - } - // Only a large pain burst will actually wake people while sleeping. - if( has_effect( effect_sleep ) && !has_effect( effect_narcosis ) ) { - int pain_thresh = rng( 3, 5 ); - - if( has_trait( trait_HEAVYSLEEPER ) ) { - pain_thresh += 2; - } else if( has_trait( trait_HEAVYSLEEPER2 ) ) { - pain_thresh += 5; - } - - if( intensity >= pain_thresh ) { - wake_up(); - } - } -} - int player::reduce_healing_effect( const efftype_id &eff_id, int remove_med, body_part hurt ) { effect &e = get_effect( eff_id, hurt ); From 4ebf89b5c846c0debf961e03387ad869aef5acc7 Mon Sep 17 00:00:00 2001 From: Kevin Granade Date: Thu, 2 Apr 2020 14:24:27 -0700 Subject: [PATCH 3/4] Update character.cpp --- src/character.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/character.cpp b/src/character.cpp index 9b4d2a7478b5a..1e724a1b84d19 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -161,9 +161,6 @@ static const trait_id trait_SMALL_OK( "SMALL_OK" ); static const trait_id trait_SQUEAMISH( "SQUEAMISH" ); static const trait_id trait_WOOLALLERGY( "WOOLALLERGY" ); -static const skill_id skill_dodge( "dodge" ); -static const skill_id skill_throw( "throw" ); - static const species_id HUMAN( "HUMAN" ); static const species_id ROBOT( "ROBOT" ); From cd900327c879795f22228990e84d119ec20b10c1 Mon Sep 17 00:00:00 2001 From: Kevin Granade Date: Thu, 2 Apr 2020 14:25:59 -0700 Subject: [PATCH 4/4] Update character.cpp --- src/character.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/character.cpp b/src/character.cpp index 1e724a1b84d19..6d3b4cdcebdf4 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -141,12 +141,13 @@ static const efftype_id effect_took_xanax( "took_xanax" ); static const efftype_id effect_webbed( "webbed" ); static const efftype_id effect_winded( "winded" ); -static const species_id ROBOT( "ROBOT" ); - static const skill_id skill_dodge( "dodge" ); static const skill_id skill_swimming( "swimming" ); static const skill_id skill_throw( "throw" ); +static const species_id HUMAN( "HUMAN" ); +static const species_id ROBOT( "ROBOT" ); + static const trait_id trait_ACIDBLOOD( "ACIDBLOOD" ); static const trait_id trait_ACIDPROOF( "ACIDPROOF" ); static const trait_id trait_ADRENALINE( "ADRENALINE" ); @@ -161,9 +162,6 @@ static const trait_id trait_SMALL_OK( "SMALL_OK" ); static const trait_id trait_SQUEAMISH( "SQUEAMISH" ); static const trait_id trait_WOOLALLERGY( "WOOLALLERGY" ); -static const species_id HUMAN( "HUMAN" ); -static const species_id ROBOT( "ROBOT" ); - static const bionic_id bio_ads( "bio_ads" ); static const bionic_id bio_blaster( "bio_blaster" ); static const bionic_id bio_blindfold( "bio_blindfold" );