Skip to content

Commit

Permalink
Merge pull request #150 from CleverRaven/master
Browse files Browse the repository at this point in the history
Merge pull request CleverRaven#39807 from CleverRaven/kevingranade-fi…
  • Loading branch information
fengjixuchui authored Apr 22, 2020
2 parents ee58416 + 47bc012 commit 0ef4f58
Show file tree
Hide file tree
Showing 19 changed files with 697 additions and 395 deletions.
16 changes: 11 additions & 5 deletions src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1573,20 +1573,20 @@ void Character::bionics_uninstall_failure( int difficulty, int success, float ad
case 1:
if( !has_trait( trait_NOPAIN ) ) {
add_msg_if_player( m_bad, _( "It really hurts!" ) );
mod_pain( rng( failure_level * 3, failure_level * 6 ) );
mod_pain( rng( 10, 30 ) );
}
break;

case 2:
case 3:
for( const bodypart_id &bp : get_all_body_parts() ) {
const body_part enum_bp = bp->token;
if( has_effect( effect_under_op, enum_bp ) ) {
if( has_effect( effect_under_op, enum_bp ) && enum_bp != num_bp ) {
if( bp_hurt.count( mutate_to_main_part( enum_bp ) ) > 0 ) {
continue;
}
bp_hurt.emplace( mutate_to_main_part( enum_bp ) );
apply_damage( this, bp, rng( failure_level, failure_level * 2 ), true );
apply_damage( this, bp, rng( 2, 6 ), true );
add_msg_player_or_npc( m_bad, _( "Your %s is damaged." ), _( "<npcname>'s %s is damaged." ),
body_part_name_accusative( enum_bp ) );
}
Expand Down Expand Up @@ -1930,6 +1930,9 @@ bool Character::uninstall_bionic( const bionic_id &b_id, player &installer, bool
} else {
activity.str_values.push_back( "false" );
}
for( const std::pair<const body_part, size_t> &elem : b_id->occupied_bodyparts ) {
add_effect( effect_under_op, difficulty * 20_minutes, elem.first, true, difficulty );
}

return true;
}
Expand Down Expand Up @@ -2196,6 +2199,9 @@ bool Character::install_bionics( const itype &type, player &installer, bool auto
} else {
activity.str_values.push_back( "false" );
}
for( const std::pair<const body_part, size_t> &elem : bioid->occupied_bodyparts ) {
add_effect( effect_under_op, difficulty * 20_minutes, elem.first, true, difficulty );
}

return true;
}
Expand Down Expand Up @@ -2275,7 +2281,7 @@ void Character::bionics_install_failure( const bionic_id &bid, const std::string
case 1:
if( !( has_trait( trait_NOPAIN ) ) ) {
add_msg_if_player( m_bad, _( "It really hurts!" ) );
mod_pain( rng( failure_level * 3, failure_level * 6 ) );
mod_pain( rng( 10, 30 ) );
}
drop_cbm = true;
break;
Expand All @@ -2284,7 +2290,7 @@ void Character::bionics_install_failure( const bionic_id &bid, const std::string
case 3:
for( const bodypart_id &bp : get_all_body_parts() ) {
const body_part enum_bp = bp->token;
if( has_effect( effect_under_op, enum_bp ) ) {
if( has_effect( effect_under_op, enum_bp ) && enum_bp != num_bp ) {
if( bp_hurt.count( mutate_to_main_part( enum_bp ) ) > 0 ) {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6360,7 +6360,7 @@ float Character::active_light() const
lumination = static_cast<float>( maxlum );

float mut_lum = 0.0f;
for( const std::pair<trait_id, trait_data> &mut : my_mutations ) {
for( const std::pair<const trait_id, trait_data> &mut : my_mutations ) {
if( mut.second.powered ) {
float curr_lum = 0.0f;
for( const auto elem : mut.first->lumination ) {
Expand Down Expand Up @@ -7953,7 +7953,7 @@ void Character::recalculate_enchantment_cache()
}

// get from traits/ mutations
for( const std::pair<trait_id, trait_data> &mut_map : my_mutations ) {
for( const std::pair<const trait_id, trait_data> &mut_map : my_mutations ) {
const mutation_branch &mut = mut_map.first.obj();

// only add the passive or powered active mutations
Expand Down
8 changes: 4 additions & 4 deletions src/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ DEFINE_EVENT_FIELDS( teleports_into_wall )
} // namespace event_detail

template<event_type Type>
static void get_fields_if_match( event_type type, std::map<std::string, cata_variant_type> &out )
static void get_fields_if_match( event_type type, event::fields_type &out )
{
if( Type == type ) {
out = { event_detail::event_spec<Type>::fields.begin(),
Expand All @@ -148,18 +148,18 @@ static void get_fields_if_match( event_type type, std::map<std::string, cata_var
}

template<int... I>
static std::map<std::string, cata_variant_type>
static event::fields_type
get_fields_helper( event_type type, std::integer_sequence<int, I...> )
{
std::map<std::string, cata_variant_type> result;
event::fields_type result;
bool discard[] = {
( get_fields_if_match<static_cast<event_type>( I )>( type, result ), true )...
};
( void ) discard;
return result;
}

std::map<std::string, cata_variant_type> event::get_fields( event_type type )
event::fields_type event::get_fields( event_type type )
{
return get_fields_helper(
type, std::make_integer_sequence<int, static_cast<int>( event_type::num_event_types )> {} );
Expand Down
11 changes: 10 additions & 1 deletion src/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,8 @@ class event
> ()( calendar::turn, std::forward<Args>( args )... );
}

static std::map<std::string, cata_variant_type> get_fields( event_type );
using fields_type = std::unordered_map<std::string, cata_variant_type>;
static fields_type get_fields( event_type );

event_type type() const {
return type_;
Expand All @@ -577,6 +578,14 @@ class event
return it->second;
}

cata_variant get_variant_or_void( const std::string &key ) const {
auto it = data_.find( key );
if( it == data_.end() ) {
return cata_variant();
}
return it->second;
}

template<cata_variant_type Type>
auto get( const std::string &key ) const {
return get_variant( key ).get<Type>();
Expand Down
7 changes: 5 additions & 2 deletions src/event_field_transformations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ static std::vector<cata_variant> species_of_monster( const cata_variant &v )
return result;
}

const std::unordered_map<std::string, EventFieldTransformation> event_field_transformations = {
{ "species_of_monster", species_of_monster },
const std::unordered_map<std::string, event_field_transformation> event_field_transformations = {
{
"species_of_monster",
{ species_of_monster, cata_variant_type::species_id, { cata_variant_type::mtype_id } }
},
};
11 changes: 9 additions & 2 deletions src/event_field_transformations.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@

#include "cata_variant.h"

using EventFieldTransformation = std::vector<cata_variant>( * )( const cata_variant & );
extern const std::unordered_map<std::string, EventFieldTransformation> event_field_transformations;
struct event_field_transformation {
using function_type = std::vector<cata_variant>( * )( const cata_variant & );
function_type function;
cata_variant_type return_type;
std::vector<cata_variant_type> argument_types;
};

extern const std::unordered_map<std::string, event_field_transformation>
event_field_transformations;

#endif // CATA_SRC_EVENT_FIELD_TRANSFORMATIONS_H
Loading

0 comments on commit 0ef4f58

Please sign in to comment.