Skip to content

Commit

Permalink
implement damage over time spell infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
KorGgenT authored and kevingranade committed May 5, 2020
1 parent a7f3241 commit 46b02d4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
36 changes: 33 additions & 3 deletions src/magic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,31 @@ int spell::damage() const
}
}

int spell::min_leveled_dot() const
{
return type->min_dot + std::round( get_level() * type->dot_increment );
}

int spell::damage_dot() const
{
const int leveled_dot = min_leveled_dot();
if( type->min_dot >= 0 || type->max_dot >= type->min_dot ) {
return std::min( leveled_dot, type->max_dot );
} else { // if it's negative, min and max work differently
return std::max( leveled_dot, type->max_dot );
}
}

damage_over_time_data spell::damage_over_time( const std::vector<bodypart_str_id> &bps ) const
{
damage_over_time_data temp;
temp.bps = bps;
temp.duration = duration_turns();
temp.amount = damage_dot();
temp.type = dmg_type();
return temp;
}

std::string spell::damage_string() const
{
if( has_flag( spell_flag::RANDOM_DAMAGE ) ) {
Expand Down Expand Up @@ -1708,9 +1733,14 @@ void spellcasting_callback::draw_spell_info( const spell &sp, const uilist *menu
if( fx == "target_attack" || fx == "projectile_attack" || fx == "cone_attack" ||
fx == "line_attack" ) {
if( damage > 0 ) {
damage_string = string_format( "%s: %s %s", _( "Damage" ), colorize( sp.damage_string(),
sp.damage_type_color() ),
colorize( sp.damage_type_string(), sp.damage_type_color() ) );
std::string dot_string;
if( sp.damage_dot() != 0 ) {
//~ amount of damage per second, abbreviated
dot_string = string_format( _( ", %d/sec" ), sp.damage_dot() );
}
damage_string = string_format( "%s: %s %s%s", _( "Damage" ), sp.damage_string(),
sp.damage_type_string(), dot_string );
damage_string = colorize( damage_string, sp.damage_type_color() );
} else if( damage < 0 ) {
damage_string = string_format( "%s: %s", _( "Healing" ), colorize( sp.damage_string(),
light_green ) );
Expand Down
3 changes: 3 additions & 0 deletions src/magic.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ class spell

// minimum damage including levels
int min_leveled_damage() const;
int min_leveled_dot() const;
// minimum aoe including levels
int min_leveled_aoe() const;
// minimum duration including levels (moves)
Expand Down Expand Up @@ -334,6 +335,8 @@ class spell
int field_intensity() const;
// how much damage does the spell do
int damage() const;
int damage_dot() const;
damage_over_time_data damage_over_time( const std::vector<bodypart_str_id> &bps ) const;
dealt_damage_instance get_dealt_damage_instance() const;
damage_instance get_damage_instance() const;
// how big is the spell's radius
Expand Down
2 changes: 2 additions & 0 deletions src/magic_spell_effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,8 @@ static void damage_targets( const spell &sp, Creature &caster,
sp.heal( target );
add_msg( m_good, _( "%s wounds are closing up!" ), cr->disp_name( true ) );
}
// TODO: randomize hit location
cr->add_damage_over_time( sp.damage_over_time( { bodypart_str_id( "torso" ) } ) );
}
}

Expand Down

0 comments on commit 46b02d4

Please sign in to comment.