Skip to content

Commit

Permalink
Migrate code from player to character (#39623)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramza13 authored Apr 18, 2020
1 parent 76e9c94 commit 242b2f9
Show file tree
Hide file tree
Showing 6 changed files with 224 additions and 247 deletions.
87 changes: 87 additions & 0 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ static const trait_id trait_DOWN( "DOWN" );
static const trait_id trait_ELECTRORECEPTORS( "ELECTRORECEPTORS" );
static const trait_id trait_ELFA_FNV( "ELFA_FNV" );
static const trait_id trait_ELFA_NV( "ELFA_NV" );
static const trait_id trait_FASTLEARNER( "FASTLEARNER" );
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" );
Expand Down Expand Up @@ -284,6 +285,7 @@ static const trait_id trait_SHOUT2( "SHOUT2" );
static const trait_id trait_SHOUT3( "SHOUT3" );
static const trait_id trait_SLIMESPAWNER( "SLIMESPAWNER" );
static const trait_id trait_SLIMY( "SLIMY" );
static const trait_id trait_SLOWLEARNER( "SLOWLEARNER" );
static const trait_id trait_STRONGSTOMACH( "STRONGSTOMACH" );
static const trait_id trait_THRESH_CEPHALOPOD( "THRESH_CEPHALOPOD" );
static const trait_id trait_THRESH_INSECT( "THRESH_INSECT" );
Expand Down Expand Up @@ -9795,3 +9797,88 @@ int Character::heartrate_bpm() const
heartbeat = clamp( heartbeat, average_heartbeat, max_heartbeat );
return heartbeat;
}

void Character::on_worn_item_washed( const item &it )
{
if( is_worn( it ) ) {
morale->on_worn_item_washed( it );
}
}

void Character::on_item_wear( const item &it )
{
morale->on_item_wear( it );
}

void Character::on_item_takeoff( const item &it )
{
morale->on_item_takeoff( it );
}

void Character::on_effect_int_change( const efftype_id &eid, int intensity, body_part bp )
{
// Adrenaline can reduce perceived pain (or increase it when you enter comedown).
// See @ref get_perceived_pain()
if( eid == effect_adrenaline ) {
// Note that calling this does no harm if it wasn't changed.
on_stat_change( "perceived_pain", get_perceived_pain() );
}

morale->on_effect_int_change( eid, intensity, bp );
}

void Character::on_mutation_gain( const trait_id &mid )
{
morale->on_mutation_gain( mid );
magic.on_mutation_gain( mid, *this );
update_type_of_scent( mid );
recalculate_enchantment_cache(); // mutations can have enchantments
}

void Character::on_mutation_loss( const trait_id &mid )
{
morale->on_mutation_loss( mid );
magic.on_mutation_loss( mid );
update_type_of_scent( mid, false );
recalculate_enchantment_cache(); // mutations can have enchantments
}

void Character::on_stat_change( const std::string &stat, int value )
{
morale->on_stat_change( stat, value );
}

bool Character::has_opposite_trait( const trait_id &flag ) const
{
for( const trait_id &i : flag->cancels ) {
if( has_trait( i ) ) {
return true;
}
}
for( const std::pair<const trait_id, trait_data> &mut : my_mutations ) {
for( const trait_id &canceled_trait : mut.first->cancels ) {
if( canceled_trait == flag ) {
return true;
}
}
}
return false;
}

int Character::adjust_for_focus( int amount ) const
{
int effective_focus = focus_pool;
if( has_trait( trait_FASTLEARNER ) ) {
effective_focus += 15;
}
if( has_active_bionic( bio_memory ) ) {
effective_focus += 10;
}
if( has_trait( trait_SLOWLEARNER ) ) {
effective_focus -= 15;
}
effective_focus += ( get_int_base() - get_option<int>( "INT_BASED_LEARNING_BASE_VALUE" ) ) *
get_option<int>( "INT_BASED_LEARNING_FOCUS_ADJUSTMENT" );
double tmp = amount * ( effective_focus / 100.0 );
return roll_remainder( tmp );
}
25 changes: 17 additions & 8 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -1738,18 +1738,26 @@ class Character : public Creature, public visitable<Character>
void update_stamina( int turns );

protected:
void on_stat_change( const std::string &, int ) override {}
void on_damage_of_type( int adjusted_damage, damage_type type, body_part bp ) override;
virtual void on_mutation_gain( const trait_id & ) {}
virtual void on_mutation_loss( const trait_id & ) {}
public:
virtual void on_item_wear( const item & ) {}
virtual void on_item_takeoff( const item & ) {}
virtual void on_worn_item_washed( const item & ) {}

/** Called when an item is worn */
void on_item_wear( const item &it );
/** Called when an item is taken off */
void on_item_takeoff( const item &it );
/** Called when an item is washed */
void on_worn_item_washed( const item &it );
/** Called when effect intensity has been changed */
void on_effect_int_change( const efftype_id &eid, int intensity, body_part bp = num_bp ) override;
/** Called when a mutation is gained */
void on_mutation_gain( const trait_id &mid );
/** Called when a mutation is lost */
void on_mutation_loss( const trait_id &mid );
/** Called when a stat is changed */
void on_stat_change( const std::string &stat, int value ) override;
/** Returns an unoccupied, safe adjacent point. If none exists, returns player position. */
tripoint adjacent_tile() const;

/** Returns true if the player has a trait which cancels the entered trait */
bool has_opposite_trait( const trait_id &flag ) const;
/** Removes "sleep" and "lying_down" */
void wake_up();
// how loud a character can shout. based on mutations and clothing
Expand All @@ -1766,6 +1774,7 @@ class Character : public Creature, public visitable<Character>

std::map<std::string, int> mutation_category_level;

int adjust_for_focus( int amount ) const;
void update_type_of_scent( bool init = false );
void update_type_of_scent( const trait_id &mut, bool gain = true );
void set_type_of_scent( const scenttype_id &id );
Expand Down
Loading

0 comments on commit 242b2f9

Please sign in to comment.