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

Change scope of rooted() and dependent functions #34811

Merged
merged 3 commits into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include "rng.h"
#include "stomach.h"
#include "ui.h"
#include "vitamin.h"

static const bionic_id bio_ads( "bio_ads" );
static const bionic_id bio_armor_arms( "bio_armor_arms" );
Expand Down Expand Up @@ -131,6 +132,8 @@ static const trait_id trait_NIGHTVISION( "NIGHTVISION" );
static const trait_id trait_PACKMULE( "PACKMULE" );
static const trait_id trait_PER_SLIME_OK( "PER_SLIME_OK" );
static const trait_id trait_PER_SLIME( "PER_SLIME" );
static const trait_id trait_ROOTS2( "ROOTS2" );
static const trait_id trait_ROOTS3( "ROOTS3" );
static const trait_id trait_SEESLEEP( "SEESLEEP" );
static const trait_id trait_SHELL2( "SHELL2" );
static const trait_id trait_SHELL( "SHELL" );
Expand Down Expand Up @@ -4989,3 +4992,113 @@ void Character::blossoms()
g->m.add_field( tmp, fd_fungal_haze, rng( 1, 2 ) );
}
}

void Character::update_vitamins( const vitamin_id &vit )
{
if( is_npc() ) {
return; // NPCs cannot develop vitamin diseases
}

efftype_id def = vit.obj().deficiency();
efftype_id exc = vit.obj().excess();

int lvl = vit.obj().severity( vitamin_get( vit ) );
if( lvl <= 0 ) {
remove_effect( def );
}
if( lvl >= 0 ) {
remove_effect( exc );
}
if( lvl > 0 ) {
if( has_effect( def, num_bp ) ) {
get_effect( def, num_bp ).set_intensity( lvl, true );
} else {
add_effect( def, 1_turns, num_bp, true, lvl );
}
}
if( lvl < 0 ) {
if( has_effect( exc, num_bp ) ) {
get_effect( exc, num_bp ).set_intensity( lvl, true );
} else {
add_effect( exc, 1_turns, num_bp, true, lvl );
}
}
}

void Character::rooted_message() const
{
bool wearing_shoes = is_wearing_shoes( side::LEFT ) || is_wearing_shoes( side::RIGHT );
if( ( has_trait( trait_ROOTS2 ) || has_trait( trait_ROOTS3 ) ) &&
g->m.has_flag( "PLOWABLE", pos() ) &&
!wearing_shoes ) {
add_msg( m_info, _( "You sink your roots into the soil." ) );
}
}

void Character::rooted()
// Should average a point every two minutes or so; ground isn't uniformly fertile
{
double shoe_factor = footwear_factor();
if( ( has_trait( trait_ROOTS2 ) || has_trait( trait_ROOTS3 ) ) &&
g->m.has_flag( "PLOWABLE", pos() ) && shoe_factor != 1.0 ) {
if( one_in( 96 ) ) {
vitamin_mod( vitamin_id( "iron" ), 1, true );
vitamin_mod( vitamin_id( "calcium" ), 1, true );
}
if( get_thirst() <= -2000 && x_in_y( 75, 425 ) ) {
mod_thirst( -1 );
}
mod_healthy_mod( 5, 50 );
}
}

bool Character::wearing_something_on( body_part bp ) const
{
for( auto &i : worn ) {
if( i.covers( bp ) ) {
return true;
}
}
return false;
}

bool Character::is_wearing_shoes( const side &which_side ) const
{
bool left = true;
bool right = true;
if( which_side == side::LEFT || which_side == side::BOTH ) {
left = false;
for( const item &worn_item : worn ) {
if( worn_item.covers( bp_foot_l ) && !worn_item.has_flag( "BELTED" ) &&
!worn_item.has_flag( "PERSONAL" ) && !worn_item.has_flag( "AURA" ) &&
!worn_item.has_flag( "SEMITANGIBLE" ) && !worn_item.has_flag( "SKINTIGHT" ) ) {
left = true;
break;
}
}
}
if( which_side == side::RIGHT || which_side == side::BOTH ) {
right = false;
for( const item &worn_item : worn ) {
if( worn_item.covers( bp_foot_r ) && !worn_item.has_flag( "BELTED" ) &&
!worn_item.has_flag( "PERSONAL" ) && !worn_item.has_flag( "AURA" ) &&
!worn_item.has_flag( "SEMITANGIBLE" ) && !worn_item.has_flag( "SKINTIGHT" ) ) {
right = true;
break;
}
}
}
return ( left && right );
}

double Character::footwear_factor() const
{
double ret = 0;
if( wearing_something_on( bp_foot_l ) ) {
ret += .5;
}
if( wearing_something_on( bp_foot_r ) ) {
ret += .5;
}
return ret;
}
34 changes: 34 additions & 0 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,38 @@ class Character : public Creature, public visitable<Character>

void spores();
void blossoms();

/** Handles rooting effects */
void rooted_message() const;
void rooted();

/** Set vitamin deficiency/excess disease states dependent upon current vitamin levels */
void update_vitamins( const vitamin_id &vit );
/**
* Check current level of a vitamin
*
* Accesses level of a given vitamin. If the vitamin_id specified does not
* exist then this function simply returns 0.
*
* @param vit ID of vitamin to check level for.
* @returns current level for specified vitamin
*/
int vitamin_get( const vitamin_id &vit ) const;
/**
* Add or subtract vitamins from player storage pools
* @param vit ID of vitamin to modify
* @param qty amount by which to adjust vitamin (negative values are permitted)
* @param capped if true prevent vitamins which can accumulate in excess from doing so
* @return adjusted level for the vitamin or zero if vitamin does not exist
*/
int vitamin_mod( const vitamin_id &vit, int qty, bool capped = true );

/** Returns true if the player is wearing something on the entered body_part */
bool wearing_something_on( body_part bp ) const;
/** Returns 1 if the player is wearing something on both feet, .5 if on one, and 0 if on neither */
double footwear_factor() const;
/** Returns true if the player is wearing something on their feet that is not SKINTIGHT */
bool is_wearing_shoes( const side &which_side = side::BOTH ) const;
protected:
Character();
Character( Character && );
Expand Down Expand Up @@ -1222,6 +1254,8 @@ class Character : public Creature, public visitable<Character>
faction *my_fac = nullptr;

character_movemode move_mode;
/** Current deficiency/excess quantity for each vitamin */
std::map<vitamin_id, int> vitamin_levels;

private:
// a cache of all active enchantment values.
Expand Down
4 changes: 2 additions & 2 deletions src/consumption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ time_duration player::vitamin_rate( const vitamin_id &vit ) const
return res;
}

int player::vitamin_mod( const vitamin_id &vit, int qty, bool capped )
int Character::vitamin_mod( const vitamin_id &vit, int qty, bool capped )
{
auto it = vitamin_levels.find( vit );
if( it == vitamin_levels.end() ) {
Expand Down Expand Up @@ -373,7 +373,7 @@ void player::vitamins_mod( const std::map<vitamin_id, int> &vitamins, bool cappe
}
}

int player::vitamin_get( const vitamin_id &vit ) const
int Character::vitamin_get( const vitamin_id &vit ) const
{
if( get_option<bool>( "NO_VITAMINS" ) ) {
return 0;
Expand Down
111 changes: 0 additions & 111 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3446,38 +3446,6 @@ void player::update_stomach( const time_point &from, const time_point &to )
}
}

void player::update_vitamins( const vitamin_id &vit )
{
if( is_npc() ) {
return; // NPCs cannot develop vitamin diseases
}

efftype_id def = vit.obj().deficiency();
efftype_id exc = vit.obj().excess();

int lvl = vit.obj().severity( vitamin_get( vit ) );
if( lvl <= 0 ) {
remove_effect( def );
}
if( lvl >= 0 ) {
remove_effect( exc );
}
if( lvl > 0 ) {
if( has_effect( def, num_bp ) ) {
get_effect( def, num_bp ).set_intensity( lvl, true );
} else {
add_effect( def, 1_turns, num_bp, true, lvl );
}
}
if( lvl < 0 ) {
if( has_effect( exc, num_bp ) ) {
get_effect( exc, num_bp ).set_intensity( lvl, true );
} else {
add_effect( exc, 1_turns, num_bp, true, lvl );
}
}
}

void player::get_sick()
{
// NPCs are too dumb to handle infections now
Expand Down Expand Up @@ -6864,34 +6832,6 @@ bool player::consume( int target_position )
return true;
}

void player::rooted_message() const
{
bool wearing_shoes = is_wearing_shoes( side::LEFT ) || is_wearing_shoes( side::RIGHT );
if( ( has_trait( trait_ROOTS2 ) || has_trait( trait_ROOTS3 ) ) &&
g->m.has_flag( "PLOWABLE", pos() ) &&
!wearing_shoes ) {
add_msg( m_info, _( "You sink your roots into the soil." ) );
}
}

// TODO: Move this into player::suffer()
void player::rooted()
// Should average a point every two minutes or so; ground isn't uniformly fertile
{
double shoe_factor = footwear_factor();
if( ( has_trait( trait_ROOTS2 ) || has_trait( trait_ROOTS3 ) ) &&
g->m.has_flag( "PLOWABLE", pos() ) && shoe_factor != 1.0 ) {
if( one_in( 96 ) ) {
vitamin_mod( vitamin_id( "iron" ), 1, true );
vitamin_mod( vitamin_id( "calcium" ), 1, true );
}
if( get_thirst() <= -2000 && x_in_y( 75, 425 ) ) {
mod_thirst( -1 );
}
mod_healthy_mod( 5, 50 );
}
}

bool player::add_faction_warning( const faction_id &id )
{
const auto it = warning_record.find( id );
Expand Down Expand Up @@ -9652,16 +9592,6 @@ int player::get_env_resist( body_part bp ) const
return ret;
}

bool player::wearing_something_on( body_part bp ) const
{
for( auto &i : worn ) {
if( i.covers( bp ) ) {
return true;
}
}
return false;
}

bool player::natural_attack_restricted_on( body_part bp ) const
{
for( auto &i : worn ) {
Expand All @@ -9673,35 +9603,6 @@ bool player::natural_attack_restricted_on( body_part bp ) const
return false;
}

bool player::is_wearing_shoes( const side &which_side ) const
{
bool left = true;
bool right = true;
if( which_side == side::LEFT || which_side == side::BOTH ) {
left = false;
for( const item &worn_item : worn ) {
if( worn_item.covers( bp_foot_l ) && !worn_item.has_flag( "BELTED" ) &&
!worn_item.has_flag( "PERSONAL" ) && !worn_item.has_flag( "AURA" ) &&
!worn_item.has_flag( "SEMITANGIBLE" ) && !worn_item.has_flag( "SKINTIGHT" ) ) {
left = true;
break;
}
}
}
if( which_side == side::RIGHT || which_side == side::BOTH ) {
right = false;
for( const item &worn_item : worn ) {
if( worn_item.covers( bp_foot_r ) && !worn_item.has_flag( "BELTED" ) &&
!worn_item.has_flag( "PERSONAL" ) && !worn_item.has_flag( "AURA" ) &&
!worn_item.has_flag( "SEMITANGIBLE" ) && !worn_item.has_flag( "SKINTIGHT" ) ) {
right = true;
break;
}
}
}
return ( left && right );
}

bool player::is_wearing_helmet() const
{
for( const item &i : worn ) {
Expand All @@ -9727,18 +9628,6 @@ int player::head_cloth_encumbrance() const
return ret;
}

double player::footwear_factor() const
{
double ret = 0;
if( wearing_something_on( bp_foot_l ) ) {
ret += .5;
}
if( wearing_something_on( bp_foot_r ) ) {
ret += .5;
}
return ret;
}

double player::armwear_factor() const
{
double ret = 0;
Expand Down
Loading