REPORT_GENERATOR(income, rc) { std::ostringstream str; int viewing_side = rc.screen().viewing_side(); const team &viewing_team = rc.teams()[viewing_side - 1]; team_data td = rc.dc().calculate_team_data(viewing_team, viewing_side); char const *end = naps; if (viewing_side != rc.screen().playing_side()) { if (td.net_income < 0) { td.net_income = - td.net_income; str << span_color(font::GRAY_COLOR); str << utils::unicode_minus; } else { str << span_color(font::GRAY_COLOR); } } else if (td.net_income < 0) { td.net_income = - td.net_income; str << span_color(font::BAD_COLOR); str << utils::unicode_minus; } else { end = ""; } str << td.net_income << end; return text_report(str.str()); }
static config unit_abilities(const unit* u) { if (!u) return report(); config res; std::vector<bool> active; const std::vector<boost::tuple<t_string,t_string,t_string> > &abilities = u->ability_tooltips(&active); const size_t abilities_size = abilities.size(); for ( size_t i = 0; i != abilities_size; ++i ) { // Aliases for readability: const std::string &base_name = abilities[i].get<0>().base_str(); const t_string &display_name = abilities[i].get<1>(); const t_string &description = abilities[i].get<2>(); std::ostringstream str, tooltip; if ( active[i] ) str << display_name; else str << span_color(font::inactive_ability_color) << display_name << naps; if ( i + 1 != abilities_size ) str << ", "; tooltip << _("Ability: ") << "<b>" << display_name << "</b>"; if ( !active[i] ) tooltip << "<i>" << _(" (inactive)") << "</i>"; tooltip << '\n' << description; add_text(res, str.str(), tooltip.str(), "ability_" + base_name); } return res; }
static config gray_inactive(reports::context & rc, const std::string &str) { if ( rc.screen().viewing_side() == rc.screen().playing_side() ) return text_report(str); return text_report(span_color(font::GRAY_COLOR) + str + naps); }
static config unit_race(const unit* u) { if (!u) return report(); std::ostringstream str, tooltip; str << span_color(font::race_color) << u->race()->name(u->gender()) << naps; tooltip << _("Race: ") << "<b>" << u->race()->name(u->gender()) << "</b>"; return text_report(str.str(), tooltip.str(), "..race_" + u->race()->id()); }
static config unit_type(const unit* u) { if (!u) return report(); std::ostringstream str, tooltip; str << span_color(font::unit_type_color) << u->type_name() << naps; tooltip << _("Type: ") << "<b>" << u->type_name() << "</b>\n" << u->unit_description(); return text_report(str.str(), tooltip.str(), "unit_" + u->type_id()); }
static config gray_inactive(const std::string &str) { if ( (resources::screen && (resources::screen->viewing_side() == resources::screen->playing_side()) ) || !resources::screen ) return text_report(str); return text_report(span_color(font::GRAY_COLOR) + str + naps); }
static config unit_moves(reports::context & rc, const unit* u) { if (!u) return config(); std::ostringstream str, tooltip; double movement_frac = 1.0; if (u->side() == rc.screen().playing_side()) { movement_frac = double(u->movement_left()) / std::max<int>(1, u->total_movement()); if (movement_frac > 1.0) movement_frac = 1.0; } std::set<t_translation::t_terrain>::const_iterator terrain_it = preferences::encountered_terrains().begin(); tooltip << _("Movement Costs:") << "\n"; for (; terrain_it != preferences::encountered_terrains().end(); ++terrain_it) { const t_translation::t_terrain terrain = *terrain_it; if (terrain == t_translation::FOGGED || terrain == t_translation::VOID_TERRAIN || terrain == t_translation::OFF_MAP_USER) continue; const terrain_type& info = rc.map().get_terrain_info(terrain); if (info.union_type().size() == 1 && info.union_type()[0] == info.number() && info.is_nonnull()) { const std::string& name = info.name(); const int moves = u->movement_cost(terrain); tooltip << name << ": "; std::string color; //movement - range: 1 .. 5, movetype::UNREACHABLE=impassable const bool cannot_move = moves > u->total_movement(); if (cannot_move) // cannot move in this terrain color = "red"; else if (moves > 1) color = "yellow"; else color = "white"; tooltip << "<span foreground=\"" << color << "\">"; // A 5 MP margin; if the movement costs go above // the unit's max moves + 5, we replace it with dashes. if(cannot_move && (moves > u->total_movement() + 5)) { tooltip << utils::unicode_figure_dash; } else { tooltip << moves; } tooltip << naps << '\n'; } } int grey = 128 + int((255 - 128) * movement_frac); SDL_Color c = create_color(grey, grey, grey); str << span_color(c) << u->movement_left() << '/' << u->total_movement() << naps; return text_report(str.str(), tooltip.str()); }
static config unit_xp(const unit* u) { if (!u) return report(); std::ostringstream str, tooltip; str << span_color(u->xp_color()) << u->experience() << '/' << u->max_experience() << naps; int exp_mod = unit_type::experience_accelerator::get_acceleration(); tooltip << _("Experience Modifier: ") << exp_mod << '%'; return text_report(str.str(), tooltip.str()); }
static config unit_defense(reports::context & rc, const unit* u, const map_location& displayed_unit_hex) { if(!u) { return config(); } std::ostringstream str, tooltip; const gamemap &map = rc.map(); if(!rc.map().on_board(displayed_unit_hex)) { return config(); } const t_translation::t_terrain &terrain = map[displayed_unit_hex]; int def = 100 - u->defense_modifier(terrain); SDL_Color color = int_to_color(game_config::red_to_green(def)); str << span_color(color) << def << '%' << naps; tooltip << _("Terrain: ") << "<b>" << map.get_terrain_info(terrain).description() << "</b>\n"; const t_translation::t_list &underlyings = map.underlying_def_terrain(terrain); if (underlyings.size() != 1 || underlyings.front() != terrain) { bool revert = false; for (const t_translation::t_terrain &t : underlyings) { if (t == t_translation::MINUS) { revert = true; } else if (t == t_translation::PLUS) { revert = false; } else { int t_def = 100 - u->defense_modifier(t); SDL_Color color = int_to_color(game_config::red_to_green(t_def)); tooltip << '\t' << map.get_terrain_info(t).description() << ": " << span_color(color) << t_def << '%' << naps << (revert ? _("maximum^max.") : _("minimum^min.")) << '\n'; } } } tooltip << "<b>" << _("Defense: ") << span_color(color) << def << '%' << naps << "</b>"; return text_report(str.str(), tooltip.str()); }
REPORT_GENERATOR(gold, rc) { std::ostringstream str; int viewing_side = rc.screen().viewing_side(); // Suppose the full unit map is applied. int fake_gold = rc.teams()[viewing_side - 1].gold(); if (rc.wb()) fake_gold -= rc.wb()->get_spent_gold_for(viewing_side); char const *end = naps; if (viewing_side != rc.screen().playing_side()) { str << span_color(font::GRAY_COLOR); } else if (fake_gold < 0) { str << span_color(font::BAD_COLOR); } else { end = ""; } str << utils::half_signed_value(fake_gold) << end; return text_report(str.str()); }
static config unit_defense(const unit* u, const map_location& displayed_unit_hex) { if(!u) { return report(); } std::ostringstream str, tooltip; const gamemap &map = *resources::game_map; if(!resources::game_map->on_board(displayed_unit_hex)) { return report(); } const t_translation::t_terrain &terrain = map[displayed_unit_hex]; int def = 100 - u->defense_modifier(terrain); SDL_Color color = int_to_color(game_config::red_to_green(def)); str << span_color(color) << def << "%</span>"; tooltip << _("Terrain: ") << "<b>" << map.get_terrain_info(terrain).description() << "</b>\n"; const t_translation::t_list &underlyings = map.underlying_def_terrain(terrain); if (underlyings.size() != 1 || underlyings.front() != terrain) { bool revert = false; BOOST_FOREACH(const t_translation::t_terrain &t, underlyings) { if (t == t_translation::MINUS) { revert = true; } else if (t == t_translation::PLUS) { revert = false; } else { int t_def = 100 - u->defense_modifier(t); SDL_Color color = int_to_color(game_config::red_to_green(t_def)); tooltip << '\t' << map.get_terrain_info(t).description() << ": " << span_color(color) << t_def << "%</span> " << (revert ? _("maximum^max.") : _("minimum^min.")) << '\n'; } } }
static config unit_hp(const unit* u) { if (!u) return report(); std::ostringstream str, tooltip; str << span_color(u->hp_color()) << u->hitpoints() << '/' << u->max_hitpoints() << naps; std::set<std::string> resistances_table; utils::string_map resistances = u->get_base_resistances(); bool att_def_diff = false; map_location displayed_unit_hex = resources::screen->displayed_unit_hex(); BOOST_FOREACH(const utils::string_map::value_type &resist, u->get_base_resistances()) { std::ostringstream line; line << gettext(resist.first.c_str()) << ": "; // Some units have different resistances when attacking or defending. int res_att = 100 - u->resistance_against(resist.first, true, displayed_unit_hex); int res_def = 100 - u->resistance_against(resist.first, false, displayed_unit_hex); const std::string def_color = unit_helper::resistance_color(res_def); if (res_att == res_def) { line << "<span foreground=\"" << def_color << "\">" << utils::signed_percent(res_def) << "</span>\n"; } else { const std::string att_color = unit_helper::resistance_color(res_att); line << "<span foreground=\"" << att_color << "\">" << utils::signed_percent(res_att) << "</span>/" << "<span foreground=\"" << def_color << "\">" << utils::signed_percent(res_def) << "</span>\n"; att_def_diff = true; } resistances_table.insert(line.str()); } tooltip << _("Resistances: "); if (att_def_diff) tooltip << _("(Att / Def)"); tooltip << '\n'; BOOST_FOREACH(const std::string &line, resistances_table) { tooltip << line; } return text_report(str.str(), tooltip.str()); }
static config unit_alignment(reports::context & rc, const unit* u) { if (!u) return config(); std::ostringstream str, tooltip; const std::string align = unit_type::alignment_description(u->alignment(), u->gender()); const std::string align_id = lexical_cast<std::string>(u->alignment()); int cm = combat_modifier(rc.units(), rc.map(), rc.screen().displayed_unit_hex(), u->alignment(), u->is_fearless()); SDL_Color color = font::weapon_color; if (cm != 0) color = (cm > 0) ? font::good_dmg_color : font::bad_dmg_color; str << align << " (" << span_color(color) << utils::signed_percent(cm) << naps << ")"; tooltip << _("Alignment: ") << "<b>" << align << "</b>\n" << string_table[align_id + "_description"]; return text_report(str.str(), tooltip.str(), "time_of_day"); }
report generate_report(TYPE type, const team &viewing_team, int current_side, int playing_side, const map_location& loc, const map_location& mouseover, const std::set<std::string> &observers, const config& level, bool show_everything) { unit_map& units = *resources::units; gamemap& map = *resources::game_map; std::vector<team>& teams = *resources::teams; const unit *u = NULL; if ((int(type) >= int(UNIT_REPORTS_BEGIN) && int(type) < int(UNIT_REPORTS_END)) || type == POSITION){ u = get_visible_unit(loc, viewing_team, show_everything); if (!u && type != POSITION) { return report(); } } std::ostringstream str; std::ostringstream tooltip; using utils::signed_percent; using font::span_color; switch(type) { case UNIT_NAME: // str << font::SMALL_TEXT << u->name(); str << u->name(); tooltip << _("Name: ") << u->name(); return report(str.str(), "", tooltip.str()); case UNIT_TYPE: { if (!u->packed()) { str << "<245,230,193>" << u->type_name(); } else { str << "<245,230,193>" << u->packee_type()->type_name(); str << "[" << u->type_name() << "]"; } if (game_config::tiny_gui) { str << "(" << hero::adaptability_str2(ftofxp12(u->adaptability_[u->arms()])) << ")"; } tooltip << _("Type: ") << u->type_name(); const std::string help_page = "unit_" + u->type_id(); return report(str.str(), "", tooltip.str(), help_page); } case UNIT_RACE: { str << "<166,146,117>" << u->race()->name(u->gender()); const std::string help_page = "..race_" + u->race()->id(); return report(str.str(), "", tooltip.str(), help_page); } case UNIT_SIDE: { std::string flag_icon = teams[u->side() - 1].flag_icon(); std::string old_rgb = game_config::flag_rgb; std::string new_rgb = team::get_side_color_index(u->side()); std::string mods = "~RC(" + old_rgb + ">" + new_rgb + ")"; if(flag_icon.empty()) { flag_icon = game_config::images::flag_icon; } image::locator flag_icon_img(flag_icon, mods); return report("", flag_icon_img, teams[u->side() - 1].current_player()); } case UNIT_LEVEL: { str << u->level(); tooltip << _("Level: ") << "<b>" << u->level() << "</b>\n"; const std::vector<std::string>& adv_to = u->advances_to(); if(adv_to.empty()) { tooltip << _("No advancement"); } else { tooltip << _("Advances to:") << "\n" << "<b>\t" << utils::join(adv_to, "\n\t") << "</b>"; } return report(str.str(), "", tooltip.str()); } case UNIT_AMLA: { report res; typedef std::pair<std::string, std::string> pair_string; foreach(const pair_string& ps, u->amla_icons()) { res.add_image(ps.first,ps.second); } return(res); } case UNIT_TRAITS: { report res; const std::vector<t_string>& traits = u->trait_names(); unsigned int nb = traits.size(); for(unsigned int i = 0; i < nb; ++i) { str << traits[i]; if(i != nb - 1 ) str << ", "; tooltip << _("Trait: ") << "<b>" << traits[i] << "</b>\n"; res.add_text(flush(str), flush(tooltip)); } return res; } case UNIT_STATUS: { report res; if (map.on_board(loc) && u->invisible(loc)) { add_status(res, "misc/invisible.png", N_("invisible: "), N_("This unit is invisible. It cannot be seen or attacked by enemy units.")); } if (u->get_state(unit::STATE_SLOWED)) { add_status(res, "misc/slowed.png", N_("slowed: "), N_("This unit has been slowed. It will only deal half its normal damage when attacking and its movement cost is doubled.")); } if (u->get_state(unit::STATE_BROKEN)) { add_status(res, "misc/broken.png", N_("broken: "), N_("This unit has been broken. It will suffer 1.5 times its normal damage when defending.")); } if (u->get_state(unit::STATE_POISONED)) { add_status(res, "misc/poisoned.png", N_("poisoned: "), N_("This unit is poisoned. It will lose 8 HP every turn until it can seek a cure to the poison in a village or from a friendly unit with the 'cures' ability.\n\nUnits cannot be killed by poison alone. The poison will not reduce it below 1 HP.")); } if (u->get_state(unit::STATE_PETRIFIED)) { add_status(res, "misc/petrified.png", N_("petrified: "), N_("This unit has been petrified. It may not move or attack.")); } return res; } case UNIT_ALIGNMENT: { const std::string &align = unit_type::alignment_description(u->alignment(), u->gender()); const std::string &align_id = unit_type::alignment_id(u->alignment()); int cm = combat_modifier(loc, u->alignment(), u->is_fearless()); str << align << " (" << signed_percent(cm) << ")"; tooltip << _("Alignment: ") << "<b>" << align << "</b>\n" << string_table[align_id + "_description"]; return report(str.str(), "", tooltip.str(), "time_of_day"); } case UNIT_ABILITIES: { report res; const std::vector<std::string> &abilities = u->ability_tooltips(); for(std::vector<std::string>::const_iterator i = abilities.begin(); i != abilities.end(); ++i) { const std::string& name = gettext(i->c_str()); str << name; if(i+2 != abilities.end()) str << ", "; ++i; //FIXME pull out ability's name from description tooltip << _("Ability: ") << *i; const std::string help_page = "ability_" + name; res.add_text(flush(str), flush(tooltip), help_page); } return res; } case UNIT_HP: { str << font::color2markup(u->hp_color()) << u->hitpoints() << '/' << u->max_hitpoints(); return report(str.str(), "", tooltip.str()); } case UNIT_XP: { str << font::color2markup(u->xp_color()) << u->experience() << '/' << u->max_experience(); return report(str.str(), "", tooltip.str()); } case UNIT_ADVANCEMENT_OPTIONS: { report res; typedef std::pair<std::string, std::string> pair_string; foreach(const pair_string& ps, u->advancement_icons()){ res.add_image(ps.first,ps.second); } return res; } case UNIT_WEAPONS: { if (u->second().valid()) { str << u->second().name(); } if (u->third().valid()) { str << " " << u->third().name(); } return report(str.str(), "", tooltip.str()); } case UNIT_IMAGE: { // const std::vector<Uint32>& old_rgb = u->second.team_rgb_range(); // color_range new_rgb = team::get_side_color_range(u->second.side()); report res("", image::locator(u->absolute_image(), u->image_mods()), ""); if (!u->is_artifical() && u->character() != NO_CHARACTER) { res.add_image(unit_types.character(u->character()).image_, ""); res.back().rect.w = 16; res.back().rect.h = 16; } return res; } case TIME_OF_DAY: { time_of_day tod; if (viewing_team.shrouded(mouseover)) { // Don't show time on shrouded tiles. tod = resources::tod_manager->get_time_of_day(); } else if (viewing_team.fogged(mouseover)) { // Don't show illuminated time on fogged tiles. tod = resources::tod_manager->get_time_of_day(mouseover); } else { tod = resources::tod_manager->time_of_day_at(mouseover); } int b = tod.lawful_bonus; int c = tod.liminal_bonus; tooltip << tod.name << '\n' << _("Lawful units: ") << signed_percent(b) << "\n" << _("Neutral units: ") << signed_percent(0) << "\n" << _("Chaotic units: ") << signed_percent(-b); if (tod.liminal_present) tooltip << "\n" << _("Liminal units: ") << signed_percent(c); std::string tod_image = tod.image; if (tod.lawful_bonus_modified > 0) tod_image += "~BRIGHTEN()"; else if (tod.lawful_bonus_modified < 0) tod_image += "~DARKEN()"; if (preferences::flip_time()) tod_image += "~FL(horiz)"; if (game_config::tiny_gui) { return report("", tod_image, ""); } else { return report("", tod_image, tooltip.str(), "time_of_day"); } } case TURN: { str << teams[playing_side-1].name() << "[" << resources::tod_manager->turn() << "]"; int nb = resources::tod_manager->number_of_turns(); if (nb != -1) str << '/' << nb; break; } // For the following status reports, show them in gray text // when it is not the active player's turn. case GOLD: { //Supposes the full/"pathfind" unit map is applied int fake_gold = viewing_team.gold(); if (current_side != playing_side) { str << font::GRAY_TEXT; } else if (fake_gold < 0) { str << font::RED_TEXT; } int cost_exponent = viewing_team.cost_exponent(); int hundred = cost_exponent / 100; str << viewing_team.gold() << "(" << hundred << "." << (cost_exponent - hundred * 100) / 10 << ")"; break; } case VILLAGES: { const team_data data = calculate_team_data(viewing_team,current_side); if (current_side != playing_side) str << font::GRAY_TEXT; str << data.villages << '/'; if (viewing_team.uses_shroud()) { int unshrouded_villages = 0; std::vector<map_location>::const_iterator i = map.villages().begin(); for (; i != map.villages().end(); ++i) { if (!viewing_team.shrouded(*i)) ++unshrouded_villages; } str << unshrouded_villages; } else { str << map.villages().size(); } break; } case UPKEEP: { const team_data data = calculate_team_data(viewing_team,current_side); if (current_side != playing_side) str << font::GRAY_TEXT; str << data.expenses << "(" << data.upkeep << ")"; break; } case EXPENSES: { const team_data data = calculate_team_data(viewing_team,current_side); if (current_side != playing_side) str << font::GRAY_TEXT; str << data.expenses; break; } case INCOME: { team_data data = calculate_team_data(viewing_team, current_side); if (current_side != playing_side) str << font::GRAY_TEXT; else if (data.net_income < 0) str << font::BAD_TEXT; str << data.net_income; break; } case TACTIC: { int tactic_point = viewing_team.tactic_point(); if (current_side != playing_side) { str << font::GRAY_TEXT; } else if (tactic_point >= game_config::max_tactic_point) { str << font::RED_TEXT; } else if (tactic_point > game_config::max_tactic_point * 2 / 3) { str << "<255,255,0>"; } else { str << font::GOOD_TEXT; } str << viewing_team.tactic_point(); break; } case TERRAIN: { if(!map.on_board(mouseover) || viewing_team.shrouded(mouseover)) break; const t_translation::t_terrain terrain = map.get_terrain(mouseover); if (terrain == t_translation::OFF_MAP_USER) break; const t_translation::t_list& underlying = map.underlying_union_terrain(terrain); if(map.is_village(mouseover)) { int owner = village_owner(mouseover, teams) + 1; if(owner == 0 || viewing_team.fogged(mouseover)) { str << map.get_terrain_info(terrain).income_description(); } else if(owner == current_side) { str << map.get_terrain_info(terrain).income_description_own(); } else if(viewing_team.is_enemy(owner)) { str << map.get_terrain_info(terrain).income_description_enemy(); } else { str << map.get_terrain_info(terrain).income_description_ally(); } str << " "; } else { str << map.get_terrain_info(terrain).description(); } if(underlying.size() != 1 || underlying.front() != terrain) { str << " ("; for(t_translation::t_list::const_iterator i = underlying.begin(); i != underlying.end(); ++i) { str << map.get_terrain_info(*i).name(); if(i+1 != underlying.end()) { str << ","; } } str << ")"; } break; } case POSITION: { // coordinate [terrain] resitance if (!map.on_board(mouseover)) { break; } const t_translation::t_terrain terrain = map[mouseover]; if (terrain == t_translation::OFF_MAP_USER) break; str << mouseover; if (game_config::tiny_gui) { str << "\n"; } if (!viewing_team.shrouded(mouseover)) { const t_translation::t_list& underlying = map.underlying_union_terrain(terrain); if (!game_config::tiny_gui) { str << _("Terrains") << ":"; } if (map.is_village(mouseover)) { int owner = village_owner(mouseover, teams) + 1; if(owner == 0 || viewing_team.fogged(mouseover)) { str << map.get_terrain_info(terrain).income_description(); } else if(owner == current_side) { str << map.get_terrain_info(terrain).income_description_own(); } else if(viewing_team.is_enemy(owner)) { str << map.get_terrain_info(terrain).income_description_enemy(); } else { str << map.get_terrain_info(terrain).income_description_ally(); } str << " "; } else { str << map.get_terrain_info(terrain).description(); } if (underlying.size() != 1 || underlying.front() != terrain) { str << " ("; for(t_translation::t_list::const_iterator i = underlying.begin(); i != underlying.end(); ++i) { str << map.get_terrain_info(*i).name(); if(i+1 != underlying.end()) { str << ","; } } str << ")"; } // display ownership std::map<const map_location, int>::const_iterator it = unit_map::economy_areas_.find(mouseover); if (it != unit_map::economy_areas_.end()) { str << "(" << units.city_from_cityno(it->second)->name() << ")"; } else if (terrain == t_translation::TERRAIN_ECONOMY_AREA) { str << "(--)"; } str << " "; if (game_config::tiny_gui) { str << "\n"; } } if (!u) break; if (viewing_team.shrouded(mouseover)) break; int move_cost = u->movement_cost(terrain); int defense = 100 - u->defense_modifier(terrain); if (!game_config::tiny_gui) { str << " "; } if (move_cost < unit_movement_type::UNREACHABLE) { str << "(" << defense << "%," << move_cost << ")"; } else if (mouseover == loc) { str << "(" << defense << "%,-)"; } else { str << "(-,-)"; } break; } case STRATUM: { const hero* rpg_hero = rpg::h; std::string stratum_icon; if (rpg::stratum == hero_stratum_wander) { stratum_icon = "/misc/stratum-wander.png"; } else if (rpg::stratum == hero_stratum_citizen) { stratum_icon = "/misc/stratum-citizen.png"; } else if (rpg::stratum == hero_stratum_mayor) { stratum_icon = "/misc/stratum-mayor.png"; } else if (rpg::stratum == hero_stratum_leader) { stratum_icon = "/misc/stratum-leader.png"; } image::locator stratum_icon_img(stratum_icon); return report("", stratum_icon_img, ""); } case MERITORIOUS: { str << rpg::h->meritorious_; break; } case SIDE_PLAYING: { std::string flag_icon = teams[playing_side-1].flag_icon(); std::string old_rgb = game_config::flag_rgb; std::string new_rgb = team::get_side_color_index(playing_side); std::string mods = "~RC(" + old_rgb + ">" + new_rgb + ")"; if(flag_icon.empty()) { flag_icon = game_config::images::flag_icon; } image::locator flag_icon_img(flag_icon, mods); return report("", flag_icon_img, teams[playing_side-1].name()); } case OBSERVERS: { if(observers.empty()) { return report(); } str << _("Observers:") << "\n"; for(std::set<std::string>::const_iterator i = observers.begin(); i != observers.end(); ++i) { str << *i << "\n"; } return report("",game_config::images::observer,str.str()); } #ifdef DISABLE_EDITOR case EDITOR_SELECTED_TERRAIN: case EDITOR_LEFT_BUTTON_FUNCTION: return report(); #else case EDITOR_SELECTED_TERRAIN: { if (editor::selected_terrain.empty()) return report(); else return report(editor::selected_terrain); } case EDITOR_LEFT_BUTTON_FUNCTION: { if (editor::left_button_function.empty()) return report(); else return report(editor::left_button_function); } #endif case REPORT_COUNTDOWN: { int min; int sec; if (viewing_team.countdown_time() > 0){ sec = viewing_team.countdown_time() / 1000; char const *end = naps; if (current_side != playing_side) str << span_color(font::GRAY_COLOR); else if (sec < 60) str << "<span foreground=\"#c80000\">"; else if (sec < 120) str << "<span foreground=\"#c8c800\">"; else end = ""; min = sec / 60; str << min << ":"; sec = sec % 60; if (sec < 10) { str << "0"; } str << sec << end; break; } // Intentional fall-through to REPORT_CLOCK // if the time countdown isn't valid. // If there is no turn time limit, // then we display the clock instead. } case REPORT_CLOCK: { time_t t = std::time(NULL); struct tm *lt = std::localtime(&t); if (lt) { char temp[10]; size_t s = std::strftime(temp, 10, preferences::clock_format().c_str(), lt); if(s>0) { return report(temp); } else { return report(); } } else { return report(); } } default: assert(false); break; } return report(str.str()); }
static config unit_weapons(reports::context & rc, const unit *attacker, const map_location &attacker_pos, const unit *defender, bool show_attacker) { if (!attacker || !defender) return config(); const unit* u = show_attacker ? attacker : defender; const map_location unit_loc = show_attacker ? attacker_pos : defender->get_location(); std::ostringstream str, tooltip; config res; std::vector<battle_context> weapons; for (unsigned int i = 0; i < attacker->attacks().size(); i++) { // skip weapons with attack_weight=0 if (attacker->attacks()[i].attack_weight() > 0) { battle_context weapon(rc.units(), attacker_pos, defender->get_location(), i, -1, 0.0, nullptr, attacker); weapons.push_back(weapon); } } for (const battle_context& weapon : weapons) { // Predict the battle outcome. combatant attacker_combatant(weapon.get_attacker_stats()); combatant defender_combatant(weapon.get_defender_stats()); attacker_combatant.fight(defender_combatant); const battle_context_unit_stats& context_unit_stats = show_attacker ? weapon.get_attacker_stats() : weapon.get_defender_stats(); int total_damage = 0; int base_damage = 0; int num_blows = 0; int chance_to_hit = 0; t_string weapon_name = _("None"); SDL_Color dmg_color = font::weapon_color; if (context_unit_stats.weapon) { base_damage = attack_info(rc, *context_unit_stats.weapon, res, *u, unit_loc); total_damage = context_unit_stats.damage; num_blows = context_unit_stats.num_blows; chance_to_hit = context_unit_stats.chance_to_hit; weapon_name = context_unit_stats.weapon->name(); if ( total_damage > base_damage ) dmg_color = font::good_dmg_color; else if ( total_damage < base_damage ) dmg_color = font::bad_dmg_color; } else { str << span_color(font::weapon_color) << weapon_name << naps << "\n"; tooltip << _("Weapon: ") << "<b>" << weapon_name << "</b>\n" << _("Damage: ") << "<b>" << "0" << "</b>\n"; } SDL_Color chance_color = int_to_color(game_config::red_to_green(chance_to_hit)); // Total damage. str << " " << span_color(dmg_color) << total_damage << naps << span_color(font::weapon_color) << utils::unicode_en_dash << num_blows << " (" << span_color(chance_color) << chance_to_hit << "%" << naps << ")" << naps << "\n"; tooltip << _("Weapon: ") << "<b>" << weapon_name << "</b>\n" << _("Total damage") << "<b>" << total_damage << "</b>\n"; // Create the hitpoints distribution. std::vector<std::pair<int, double> > hp_prob_vector; // First, we sort the probabilities in ascending order. std::vector<std::pair<double, int> > prob_hp_vector; int i; combatant* c = show_attacker ? &attacker_combatant : &defender_combatant; for(i = 0; i < static_cast<int>(c->hp_dist.size()); i++) { double prob = c->hp_dist[i]; // We keep only values above 0.1%. if(prob > 0.001) prob_hp_vector.push_back(std::pair<double, int>(prob, i)); } std::sort(prob_hp_vector.begin(), prob_hp_vector.end()); //TODO fendrin -- make that dynamically int max_hp_distrib_rows_ = 10; // We store a few of the highest probability hitpoint values. int nb_elem = std::min<int>(max_hp_distrib_rows_, prob_hp_vector.size()); for(i = prob_hp_vector.size() - nb_elem; i < static_cast<int>(prob_hp_vector.size()); i++) { hp_prob_vector.push_back(std::pair<int, double> (prob_hp_vector[i].second, prob_hp_vector[i].first)); } // Then, we sort the hitpoint values in ascending order. std::sort(hp_prob_vector.begin(), hp_prob_vector.end()); // And reverse the order. Might be doable in a better manor. std::reverse(hp_prob_vector.begin(), hp_prob_vector.end()); for(i = 0; i < static_cast<int>(hp_prob_vector.size()); i++) { int hp = hp_prob_vector[i].first; double prob = hp_prob_vector[i].second; char prob_buf[10]; format_prob(prob_buf, prob); char hp_buf[10]; format_hp(hp_buf, hp); SDL_Color prob_color = int_to_color(game_config::blue_to_white(prob * 100.0, true)); str << span_color(font::weapon_details_color) << " " << " " << span_color(u->hp_color(hp)) << hp_buf << naps << " " << font::weapon_numbers_sep << " " << span_color(prob_color) << prob_buf << naps << naps << "\n"; } add_text(res, flush(str), flush(tooltip)); } return res; }
static int attack_info(reports::context & rc, const attack_type &at, config &res, const unit &u, const map_location &displayed_unit_hex) { std::ostringstream str, tooltip; at.set_specials_context(displayed_unit_hex, u.side() == rc.screen().playing_side()); int base_damage = at.damage(); int specials_damage = at.modified_damage(false); int damage_multiplier = 100; int tod_bonus = combat_modifier(rc.units(), rc.map(), displayed_unit_hex, u.alignment(), u.is_fearless()); damage_multiplier += tod_bonus; int leader_bonus = 0; if (under_leadership(rc.units(), displayed_unit_hex, &leader_bonus).valid()) damage_multiplier += leader_bonus; bool slowed = u.get_state(unit::STATE_SLOWED); int damage_divisor = slowed ? 20000 : 10000; // Assume no specific resistance (i.e. multiply by 100). int damage = round_damage(specials_damage, damage_multiplier * 100, damage_divisor); // Hit points are used to calculate swarm, so they need to be bounded. unsigned max_hp = u.max_hitpoints(); unsigned cur_hp = std::min<unsigned>(std::max(0, u.hitpoints()), max_hp); unsigned base_attacks = at.num_attacks(); unsigned min_attacks, max_attacks; at.modified_attacks(false, min_attacks, max_attacks); unsigned num_attacks = swarm_blows(min_attacks, max_attacks, cur_hp, max_hp); SDL_Color dmg_color = font::weapon_color; if ( damage > specials_damage ) dmg_color = font::good_dmg_color; else if ( damage < specials_damage ) dmg_color = font::bad_dmg_color; str << span_color(dmg_color) << " " << damage << naps << span_color(font::weapon_color) << font::weapon_numbers_sep << num_attacks << ' ' << at.name() << "</span>\n"; tooltip << _("Weapon: ") << "<b>" << at.name() << "</b>\n" << _("Damage: ") << "<b>" << damage << "</b>\n"; if ( tod_bonus || leader_bonus || slowed || specials_damage != base_damage ) { tooltip << '\t' << _("Base damage: ") << base_damage << '\n'; if ( specials_damage != base_damage ) { tooltip << '\t' << _("With specials: ") << specials_damage << '\n'; } if (tod_bonus) { tooltip << '\t' << _("Time of day: ") << utils::signed_percent(tod_bonus) << '\n'; } if (leader_bonus) { tooltip << '\t' << _("Leadership: ") << utils::signed_percent(leader_bonus) << '\n'; } if (slowed) { tooltip << '\t' << _("Slowed: ") << "/ 2" << '\n'; } } tooltip << _("Attacks: ") << "<b>" << num_attacks << "</b>\n"; if ( max_attacks != min_attacks && cur_hp != max_hp ) { if ( max_attacks < min_attacks ) { // "Reverse swarm" tooltip << '\t' << _("Max swarm bonus: ") << (min_attacks-max_attacks) << '\n'; tooltip << '\t' << _("Swarm: ") << "* "<< (100 - cur_hp*100/max_hp) << "%\n"; tooltip << '\t' << _("Base attacks: ") << '+' << base_attacks << '\n'; // The specials line will not necessarily match up with how the // specials are calculated, but for an unusual case, simple brevity // trumps complexities. if ( max_attacks != base_attacks ) { int attack_diff = int(max_attacks) - int(base_attacks); tooltip << '\t' << _("Specials: ") << utils::signed_value(attack_diff) << '\n'; } } else { // Regular swarm tooltip << '\t' << _("Base attacks: ") << base_attacks << '\n'; if ( max_attacks != base_attacks ) { tooltip << '\t' << _("With specials: ") << max_attacks << '\n'; } if ( min_attacks != 0 ) { tooltip << '\t' << _("Subject to swarm: ") << (max_attacks-min_attacks) << '\n'; } tooltip << '\t' << _("Swarm: ") << "* "<< (cur_hp*100/max_hp) << "%\n"; } } else if ( num_attacks != base_attacks ) { tooltip << '\t' << _("Base attacks: ") << base_attacks << '\n'; tooltip << '\t' << _("With specials: ") << num_attacks << '\n'; } add_text(res, flush(str), flush(tooltip)); std::string range = string_table["range_" + at.range()]; std::string lang_type = string_table["type_" + at.type()]; str << span_color(font::weapon_details_color) << " " << " " << range << font::weapon_details_sep << lang_type << "</span>\n"; tooltip << _("Weapon range: ") << "<b>" << range << "</b>\n" << _("Damage type: ") << "<b>" << lang_type << "</b>\n" << _("Damage versus: ") << '\n'; // Show this weapon damage and resistance against all the different units. // We want weak resistances (= good damage) first. std::map<int, std::set<std::string>, std::greater<int> > resistances; std::set<std::string> seen_types; const team &unit_team = rc.teams()[u.side() - 1]; const team &viewing_team = rc.teams()[rc.screen().viewing_team()]; for (const unit &enemy : rc.units()) { if (enemy.incapacitated()) //we can't attack statues so don't display them in this tooltip continue; if (!unit_team.is_enemy(enemy.side())) continue; const map_location &loc = enemy.get_location(); if (viewing_team.fogged(loc) || (viewing_team.is_enemy(enemy.side()) && enemy.invisible(loc))) continue; bool new_type = seen_types.insert(enemy.type_id()).second; if (new_type) { int resistance = enemy.resistance_against(at, false, loc); resistances[resistance].insert(enemy.type_name()); } } typedef std::pair<int, std::set<std::string> > resist_units; for (const resist_units &resist : resistances) { int damage = round_damage(specials_damage, damage_multiplier * resist.first, damage_divisor); tooltip << "<b>" << damage << "</b> " << "<i>(" << utils::signed_percent(resist.first-100) << ")</i> : " << utils::join(resist.second, ", ") << '\n'; } add_text(res, flush(str), flush(tooltip)); const std::string &accuracy_parry = at.accuracy_parry_description(); if (!accuracy_parry.empty()) { str << span_color(font::weapon_details_color) << " " << accuracy_parry << "</span>\n"; int accuracy = at.accuracy(); if (accuracy) { tooltip << _("Accuracy:") << "<b>" << utils::signed_percent(accuracy) << "</b>\n"; } int parry = at.parry(); if (parry) { tooltip << _("Parry:") << "<b>" << utils::signed_percent(parry) << "</b>\n"; } add_text(res, flush(str), flush(tooltip)); } at.set_specials_context_for_listing(); std::vector<bool> active; const std::vector<std::pair<t_string, t_string> > &specials = at.special_tooltips(&active); const size_t specials_size = specials.size(); for ( size_t i = 0; i != specials_size; ++i ) { // Aliases for readability: const t_string &name = specials[i].first; const t_string &description = specials[i].second; const SDL_Color &details_color = active[i] ? font::weapon_details_color : font::inactive_details_color; str << span_color(details_color) << " " << " " << name << naps << '\n'; std::string help_page = "weaponspecial_" + name.base_str(); tooltip << _("Weapon special: ") << "<b>" << name << "</b>"; if ( !active[i] ) tooltip << "<i>" << _(" (inactive)") << "</i>"; tooltip << '\n' << description; add_text(res, flush(str), flush(tooltip), help_page); } return damage; }