Skip to content

Commit

Permalink
move function definitions to proper files
Browse files Browse the repository at this point in the history
  • Loading branch information
KorGgenT committed Apr 2, 2020
1 parent 2cc50b5 commit 2069490
Show file tree
Hide file tree
Showing 4 changed files with 268 additions and 254 deletions.
261 changes: 261 additions & 0 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
Expand All @@ -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" );
Expand Down Expand Up @@ -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" );
Expand Down Expand Up @@ -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" );
Expand All @@ -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" );
Expand All @@ -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" );
Expand Down Expand Up @@ -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<int>( -log( get_vision_threshold( static_cast<int>( g->m.ambient_light_at(
pos() ) ) ) /
static_cast<float>( 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<tripoint> 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<int>( 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<int>( 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();
Expand Down
2 changes: 2 additions & 0 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ struct bionic;
using drop_location = std::pair<item_location, int>;
using drop_locations = std::list<drop_location>;

#define MAX_CLAIRVOYANCE 40

enum vision_modes {
DEBUG_NIGHTVISION,
NV_GOGGLES,
Expand Down
5 changes: 5 additions & 0 deletions src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ void Creature::process_turn()
}
}

bool Creature::is_underwater() const
{
return underwater;
}

bool Creature::digging() const
{
return false;
Expand Down
Loading

0 comments on commit 2069490

Please sign in to comment.