the MP countdown timer alert can now start sounding while dialogs are open
This commit is contained in:
parent
0d4abdf849
commit
209a15ae5e
4 changed files with 59 additions and 20 deletions
|
@ -7,7 +7,8 @@ Version 1.3.6+svn:
|
|||
* language and i18n:
|
||||
* updated translations: Danish, Japanese, Swedish
|
||||
* multiplayer:
|
||||
* improvements to the sound of the timer countdown
|
||||
* improvements to the sound of the countdown timer
|
||||
* the countdown timer alert can now start sounding while dialogs are open
|
||||
* unit descriptions are no longer evaluated for the recruitment checksum
|
||||
and thus avoiding an OOS error when different languages are used.
|
||||
The change is incompatible with older trunk versions fixes (bug #9472).
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "cursor.hpp"
|
||||
#include "events.hpp"
|
||||
#include "log.hpp"
|
||||
#include "playmp_controller.hpp"
|
||||
#include "preferences_display.hpp"
|
||||
#include "sound.hpp"
|
||||
#include "video.hpp"
|
||||
|
@ -272,6 +273,7 @@ void pump()
|
|||
//used to keep track of double click events
|
||||
static int last_mouse_down = -1;
|
||||
static int last_click_x = -1, last_click_y = -1;
|
||||
int current_ticks = 0;
|
||||
|
||||
SDL_Event event;
|
||||
while(SDL_PollEvent(&event)) {
|
||||
|
@ -329,7 +331,7 @@ void pump()
|
|||
static const int DoubleClickTime = 500;
|
||||
|
||||
static const int DoubleClickMaxMove = 3;
|
||||
const int current_ticks = ::SDL_GetTicks();
|
||||
current_ticks = ::SDL_GetTicks();
|
||||
if(last_mouse_down >= 0 && current_ticks - last_mouse_down < DoubleClickTime &&
|
||||
abs(event.button.x - last_click_x) < DoubleClickMaxMove &&
|
||||
abs(event.button.y - last_click_y) < DoubleClickMaxMove) {
|
||||
|
@ -380,8 +382,21 @@ void pump()
|
|||
resize_dimensions.second = 0;
|
||||
}
|
||||
|
||||
if (preferences::music_on())
|
||||
if(preferences::music_on()) {
|
||||
sound::think_about_music();
|
||||
}
|
||||
|
||||
if(playmp_controller::counting_down()) {
|
||||
if(current_ticks) {
|
||||
playmp_controller::think_about_countdown(current_ticks);
|
||||
} else {
|
||||
const int timer_refresh_rate = 50;
|
||||
static int timer_refresh = 1;
|
||||
if(++timer_refresh % timer_refresh_rate == 0) {
|
||||
playmp_controller::think_about_countdown(::SDL_GetTicks());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void raise_process_event()
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#define LOG_NG LOG_STREAM(info, engine)
|
||||
|
||||
unsigned int playmp_controller::replay_last_turn_ = 0;
|
||||
int playmp_controller::beep_warning_time_ = 0;
|
||||
|
||||
LEVEL_RESULT playmp_scenario(const game_data& gameinfo, const config& game_config,
|
||||
config const* level, CVideo& video, game_state& state_of_game,
|
||||
|
@ -41,6 +42,14 @@ playmp_controller::playmp_controller(const config& level, const game_data& gamei
|
|||
turn_data_ = NULL;
|
||||
}
|
||||
|
||||
playmp_controller::~playmp_controller() {
|
||||
//halt and cancel the countdown timer
|
||||
if(beep_warning_time_ < 0) {
|
||||
sound::stop_bell();
|
||||
}
|
||||
beep_warning_time_ = 0;
|
||||
}
|
||||
|
||||
void playmp_controller::set_replay_last_turn(unsigned int turn){
|
||||
replay_last_turn_ = turn;
|
||||
}
|
||||
|
@ -62,7 +71,6 @@ void playmp_controller::shout(){
|
|||
}
|
||||
|
||||
void playmp_controller::play_side(const unsigned int team_index, bool save){
|
||||
beep_warning_time_ = 10000; //Starts beeping each second when time is less than this (millisec)
|
||||
do {
|
||||
player_type_changed_ = false;
|
||||
end_turn_ = false;
|
||||
|
@ -93,9 +101,6 @@ void playmp_controller::play_side(const unsigned int team_index, bool save){
|
|||
}
|
||||
}
|
||||
LOG_NG << "human finished turn...\n";
|
||||
if(beep_warning_time_ < 10000) {
|
||||
sound::stop_bell();
|
||||
}
|
||||
} else if(current_team().is_ai()) {
|
||||
play_ai_turn();
|
||||
} else if(current_team().is_network()) {
|
||||
|
@ -113,6 +118,22 @@ void playmp_controller::before_human_turn(bool save){
|
|||
turn_data_->replay_error().attach_handler(this);
|
||||
}
|
||||
|
||||
bool playmp_controller::counting_down() {
|
||||
return beep_warning_time_ > 0;
|
||||
}
|
||||
|
||||
void playmp_controller::think_about_countdown(int ticks){
|
||||
if(beep_warning_time_ > 0 && ticks >= beep_warning_time_){
|
||||
const bool bell_on = preferences::turn_bell();
|
||||
if(bell_on || preferences::sound_on() || preferences::UI_sound_on()) {
|
||||
preferences::set_turn_bell(true);
|
||||
sound::play_bell(game_config::sounds::timer_bell, 10000-(ticks-beep_warning_time_));
|
||||
beep_warning_time_ = -1;
|
||||
preferences::set_turn_bell(bell_on);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void playmp_controller::play_human_turn(){
|
||||
int cur_ticks = SDL_GetTicks();
|
||||
|
||||
|
@ -148,19 +169,13 @@ void playmp_controller::play_human_turn(){
|
|||
if (new_time > 0 ){
|
||||
current_team().set_countdown_time(new_time);
|
||||
cur_ticks = ticks;
|
||||
if (current_team().countdown_time() <= beep_warning_time_){
|
||||
beep_warning_time_ = -1;
|
||||
const bool bell_on = preferences::turn_bell();
|
||||
if(bell_on || preferences::sound_on() || preferences::UI_sound_on()) {
|
||||
preferences::set_turn_bell(true);
|
||||
sound::play_bell(game_config::sounds::timer_bell, new_time);
|
||||
preferences::set_turn_bell(bell_on);
|
||||
}
|
||||
if(current_team().is_human() && !beep_warning_time_) {
|
||||
beep_warning_time_ = new_time - 10000 + ticks;
|
||||
}
|
||||
think_about_countdown(ticks);
|
||||
} else {
|
||||
// Clock time ended
|
||||
// If no turn bonus or action bonus -> defeat
|
||||
beep_warning_time_ = 10000;
|
||||
const int action_increment = lexical_cast_default<int>(level_["mp_countdown_action_bonus"],0);
|
||||
if ( lexical_cast_default<int>(level_["mp_countdown_turn_bonus"],0) == 0
|
||||
&& (action_increment == 0 || current_team().action_bonus_count() == 0)) {
|
||||
|
@ -216,11 +231,16 @@ void playmp_controller::after_human_turn(){
|
|||
|
||||
void playmp_controller::finish_side_turn(){
|
||||
play_controller::finish_side_turn();
|
||||
|
||||
//just in case due to an exception turn_data_ has not been deleted in after_human_turn
|
||||
if (turn_data_ != NULL){
|
||||
delete turn_data_;
|
||||
turn_data_ = NULL;
|
||||
delete turn_data_;
|
||||
turn_data_ = NULL;
|
||||
|
||||
//halt and cancel the countdown timer
|
||||
if(beep_warning_time_ < 0) {
|
||||
sound::stop_bell();
|
||||
}
|
||||
beep_warning_time_ = 0;
|
||||
}
|
||||
|
||||
void playmp_controller::play_network_turn(){
|
||||
|
|
|
@ -27,9 +27,12 @@ class playmp_controller : public playsingle_controller
|
|||
public:
|
||||
playmp_controller(const config& level, const game_data& gameinfo, game_state& state_of_game,
|
||||
const int ticks, const int num_turns, const config& game_config, CVideo& video, bool skip_replay);
|
||||
~playmp_controller();
|
||||
|
||||
static unsigned int replay_last_turn() { return replay_last_turn_; }
|
||||
static void set_replay_last_turn(unsigned int turn);
|
||||
static bool counting_down();
|
||||
static void think_about_countdown(int ticks);
|
||||
|
||||
protected:
|
||||
virtual void handle_generic_event(const std::string& name);
|
||||
|
@ -49,7 +52,7 @@ protected:
|
|||
|
||||
turn_info* turn_data_;
|
||||
|
||||
int beep_warning_time_;
|
||||
static int beep_warning_time_;
|
||||
private:
|
||||
void process_oos(const std::string& err_msg);
|
||||
static unsigned int replay_last_turn_;
|
||||
|
|
Loading…
Add table
Reference in a new issue