void add(const std::string& str, const Clr& clr, const bool INTERRUPT_ALL_PLAYER_ACTIONS, const More_prompt_on_msg add_more_prompt_on_msg) { ASSERT(!str.empty()); #ifndef NDEBUG if (str[0] == ' ') { TRACE << "Message starts with space: \"" << str << "\"" << std::endl; ASSERT(false); } #endif int cur_line_nr = lines_[1].empty() ? 0 : 1; Msg* prev_msg = nullptr; if (!lines_[cur_line_nr].empty()) { prev_msg = &lines_[cur_line_nr].back(); } bool is_repeated = false; //Check if message is identical to previous if (add_more_prompt_on_msg == More_prompt_on_msg::no && prev_msg) { std::string prev_str = ""; prev_msg->str_raw(prev_str); if (prev_str.compare(str) == 0) { prev_msg->incr_repeat(); is_repeated = true; } } if (!is_repeated) { const int REPEAT_STR_LEN = 4; const int PADDING_LEN = REPEAT_STR_LEN + (cur_line_nr == 0 ? 0 : (more_str.size() + 1)); int x_pos = x_after_msg(prev_msg); const bool IS_MSG_FIT = x_pos + (int)str.size() + PADDING_LEN - 1 < MAP_W; if (!IS_MSG_FIT) { if (cur_line_nr == 0) { cur_line_nr = 1; } else //Current line number is not zero { more_prompt(); cur_line_nr = 0; } x_pos = 0; } lines_[cur_line_nr].push_back(Msg(str, clr, x_pos)); } if (add_more_prompt_on_msg == More_prompt_on_msg::yes) { more_prompt(); } //Messages may stop long actions like first aid and quick walk if (INTERRUPT_ALL_PLAYER_ACTIONS) { map::player->interrupt_actions(); } //Some actions are always interrupted by messages, regardless of the //"INTERRUPT_ALL_PLAYER_ACTIONS" parameter map::player->on_log_msg_printed(); }
void add(const string& str, const Clr& clr, const bool INTERRUPT_PLAYER_ACTIONS, const bool ADD_MORE_PROMPT_AFTER_MSG) { assert(!str.empty()); #ifndef NDEBUG if (str[0] == ' ') { TRACE << "Message starts with space: \"" << str << "\"" << endl; assert(false); } #endif //If frenzied, change message bool props[size_t(Prop_id::END)]; map::player->get_prop_handler().get_prop_ids(props); if (props[size_t(Prop_id::frenzied)]) { string frenzied_str = str; bool has_lower_case = false; for (auto c : frenzied_str) { if (c >= 'a' && c <= 'z') { has_lower_case = true; break; } } const char LAST = frenzied_str.back(); bool is_ended_by_punctuation = LAST == '.' || LAST == '!'; if (has_lower_case && is_ended_by_punctuation) { //Convert to upper case text_format::all_to_upper(frenzied_str); //Do not put "!" if string contains "..." if (frenzied_str.find("...") == string::npos) { //Change "." to "!" at the end if (frenzied_str.back() == '.') { frenzied_str.back() = '!'; } //Add some "!" frenzied_str += "!!"; } add(frenzied_str, clr, INTERRUPT_PLAYER_ACTIONS, ADD_MORE_PROMPT_AFTER_MSG); return; } } int cur_line_nr = lines_[1].empty() ? 0 : 1; Msg* prev_msg = nullptr; if (!lines_[cur_line_nr].empty()) { prev_msg = &lines_[cur_line_nr].back(); } bool is_repeated = false; //Check if message is identical to previous if (!ADD_MORE_PROMPT_AFTER_MSG && prev_msg) { string prev_str = ""; prev_msg->get_str_raw(prev_str); if (prev_str.compare(str) == 0) { prev_msg->incr_repeat(); is_repeated = true; } } if (!is_repeated) { const int REPEAT_STR_LEN = 4; const int PADDING_LEN = REPEAT_STR_LEN + (cur_line_nr == 0 ? 0 : (more_str.size() + 1)); int x_pos = get_xAfter_msg(prev_msg); const bool IS_MSG_FIT = x_pos + int(str.size()) + PADDING_LEN - 1 < MAP_W; if (!IS_MSG_FIT) { if (cur_line_nr == 0) { cur_line_nr = 1; } else { more_prompt(); cur_line_nr = 0; } x_pos = 0; } lines_[cur_line_nr].push_back(Msg(str, clr, x_pos)); } if (ADD_MORE_PROMPT_AFTER_MSG) { more_prompt(); } //Messages may stop long actions like first aid and quick walk if (INTERRUPT_PLAYER_ACTIONS) { map::player->interrupt_actions(); } map::player->on_log_msg_printed(); }