Skip to content

Commit

Permalink
Allow unit_attack() to play an optional list of extra sounds on a hit
Browse files Browse the repository at this point in the history
  • Loading branch information
ln-zookeeper committed Aug 28, 2015
1 parent a245f0e commit 95bab79
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/unit_display.cpp
Expand Up @@ -25,6 +25,7 @@
#include "log.hpp"
#include "mouse_events.hpp"
#include "resources.hpp"
#include "sound.hpp"
#include "terrain_filter.hpp"
#include "unit.hpp"
#include "unit_animation_component.hpp"
Expand Down Expand Up @@ -573,7 +574,7 @@ void unit_die(const map_location& loc, unit& loser,
void unit_attack(display * disp, game_board & board,
const map_location& a, const map_location& b, int damage,
const attack_type& attack, const attack_type* secondary_attack,
int swing,std::string hit_text,int drain_amount,std::string att_text)
int swing,std::string hit_text,int drain_amount,std::string att_text, const std::vector<std::string>* extra_hit_sounds)
{
if(!disp ||disp->video().update_locked() || disp->video().faked() ||
(disp->fogged(a) && disp->fogged(b)) || preferences::show_combat() == false) {
Expand Down Expand Up @@ -653,7 +654,15 @@ void unit_attack(display * disp, game_board & board,
animator.start_animations();
animator.wait_until(0);
int damage_left = damage;
bool extra_hit_sounds_played = false;
while(damage_left > 0 && !animator.would_end()) {
if(!extra_hit_sounds_played && extra_hit_sounds != NULL) {
BOOST_FOREACH (std::string hit_sound, *extra_hit_sounds) {
sound::play_sound(hit_sound);
}
extra_hit_sounds_played = true;
}

int step_left = (animator.get_end_time() - animator.get_animation_time() )/50;
if(step_left < 1) step_left = 1;
int removed_hp = damage_left/step_left ;
Expand Down
2 changes: 1 addition & 1 deletion src/unit_display.hpp
Expand Up @@ -117,7 +117,7 @@ void unit_sheath_weapon( const map_location& loc, unit* u=NULL, const attack_typ
void unit_attack(display * disp, game_board & board, //TODO: Would be nice if this could be purely a display function and defer damage dealing to its caller
const map_location& a, const map_location& b, int damage,
const attack_type& attack, const attack_type* secondary_attack,
int swing, std::string hit_text, int drain_amount, std::string att_text);
int swing, std::string hit_text, int drain_amount, std::string att_text, const std::vector<std::string>* extra_hit_sounds=NULL);


void unit_recruited(const map_location& loc,
Expand Down

0 comments on commit 95bab79

Please sign in to comment.