Skip to content

Commit

Permalink
make bodypart warmth available in conditions (CleverRaven#59801)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlange-42 authored and alef committed Aug 5, 2022
1 parent 4116647 commit 459b732
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/condition.cpp
Expand Up @@ -495,6 +495,19 @@ void conditional_t<T>::set_has_hp( const JsonObject &jo, const std::string &memb
};
}

template<class T>
void conditional_t<T>::set_has_part_temp( const JsonObject &jo, const std::string &member,
bool is_npc )
{
int_or_var<T> iov = get_int_or_var<T>( jo, member );
cata::optional<bodypart_id> bp;
optional( jo, false, "bodypart", bp );
condition = [iov, bp, is_npc]( const T & d ) {
bodypart_id bid = bp.value_or( get_bp_from_str( d.reason ) );
return d.actor( is_npc )->get_cur_part_temp( bid ) >= iov.evaluate( d );
};
}

template<class T>
void conditional_t<T>::set_is_wearing( const JsonObject &jo, const std::string &member,
bool is_npc )
Expand Down Expand Up @@ -1459,6 +1472,13 @@ std::function<int( const T & )> conditional_t<T>::get_get_int( const JsonObject
bodypart_id bid = bp.value_or( get_bp_from_str( d.reason ) );
return d.actor( is_npc )->get_cur_hp( bid );
};
} else if( checked_value == "warmth" ) {
cata::optional<bodypart_id> bp;
optional( jo, false, "bodypart", bp );
return [is_npc, bp]( const T & d ) {
bodypart_id bid = bp.value_or( get_bp_from_str( d.reason ) );
return d.actor( is_npc )->get_cur_part_temp( bid );
};
} else if( checked_value == "effect_intensity" ) {
const std::string &effect_id = jo.get_string( "effect" );
cata::optional<bodypart_id> bp;
Expand Down Expand Up @@ -2611,6 +2631,10 @@ conditional_t<T>::conditional_t( const JsonObject &jo )
set_has_hp( jo, "u_has_hp" );
} else if( jo.has_int( "npc_has_hp" ) || jo.has_object( "npc_has_hp" ) ) {
set_has_hp( jo, "npc_has_hp", is_npc );
} else if( jo.has_int( "u_has_part_temp" ) || jo.has_object( "u_has_part_temp" ) ) {
set_has_part_temp( jo, "u_has_part_temp" );
} else if( jo.has_int( "npc_has_part_temp" ) || jo.has_object( "npc_has_part_temp" ) ) {
set_has_part_temp( jo, "npc_has_part_temp", is_npc );
} else if( jo.has_string( "u_is_wearing" ) ) {
set_is_wearing( jo, "u_is_wearing" );
} else if( jo.has_string( "npc_is_wearing" ) ) {
Expand Down
3 changes: 2 additions & 1 deletion src/condition.h
Expand Up @@ -40,7 +40,7 @@ const std::unordered_set<std::string> complex_conds = { {
"npc_role_nearby", "npc_allies", "npc_allies_global", "npc_service",
"u_has_cash", "u_are_owed", "u_query", "npc_query", "u_has_item_with_flag", "npc_has_item_with_flag",
"npc_aim_rule", "npc_engagement_rule", "npc_rule", "npc_override", "u_has_hp", "npc_has_hp",
"npc_cbm_reserve_rule", "npc_cbm_recharge_rule", "u_has_faction_trust",
"u_has_part_temp", "npc_has_part_temp", "npc_cbm_reserve_rule", "npc_cbm_recharge_rule", "u_has_faction_trust",
"days_since_cataclysm", "is_season", "mission_goal", "u_has_var", "npc_has_var",
"u_has_skill", "npc_has_skill", "u_know_recipe", "u_compare_var", "npc_compare_var",
"u_compare_time_since_var", "npc_compare_time_since_var", "is_weather", "one_in_chance", "x_in_y_chance",
Expand Down Expand Up @@ -251,6 +251,7 @@ struct conditional_t {
void set_has_intelligence( const JsonObject &jo, const std::string &member, bool is_npc = false );
void set_has_perception( const JsonObject &jo, const std::string &member, bool is_npc = false );
void set_has_hp( const JsonObject &jo, const std::string &member, bool is_npc = false );
void set_has_part_temp( const JsonObject &jo, const std::string &member, bool is_npc = false );
void set_is_deaf( bool is_npc = false );
void set_is_on_terrain( const JsonObject &jo, const std::string &member, bool is_npc = false );
void set_is_in_field( const JsonObject &jo, const std::string &member, bool is_npc = false );
Expand Down
3 changes: 3 additions & 0 deletions src/talker.h
Expand Up @@ -118,6 +118,9 @@ class talker
virtual int get_cur_hp( const bodypart_id & ) const {
return 0;
}
virtual int get_cur_part_temp( const bodypart_id & ) const {
return 0;
}

// stats, skills, traits, bionics, and magic
virtual int str_cur() const {
Expand Down
5 changes: 5 additions & 0 deletions src/talker_character.cpp
Expand Up @@ -82,6 +82,11 @@ int talker_character_const::get_cur_hp( const bodypart_id &bp ) const
return me_chr_const->get_hp( bp );
}

int talker_character_const::get_cur_part_temp( const bodypart_id &bp ) const
{
return me_chr_const->get_part_temp_conv( bp );
}

int talker_character_const::str_cur() const
{
return me_chr_const->str_cur;
Expand Down
1 change: 1 addition & 0 deletions src/talker_character.h
Expand Up @@ -44,6 +44,7 @@ class talker_character_const: public talker
tripoint_abs_ms global_pos() const override;
tripoint_abs_omt global_omt_location() const override;
int get_cur_hp( const bodypart_id &bp ) const override;
int get_cur_part_temp( const bodypart_id &bp ) const override;

// stats, skills, traits, bionics, and magic
int str_cur() const override;
Expand Down

0 comments on commit 459b732

Please sign in to comment.