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_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_weapons(reports::context & rc, const unit *u) { if (!u || u->attacks().empty()) return config(); map_location displayed_unit_hex = rc.screen().displayed_unit_hex(); config res; //TODO enable after the string frezze is lifted //const std::string attack_headline = // ( u->attacks().size() > 1 ) ? N_("Attacks") : N_("Attack"); //add_text(res, /*span_color(font::weapon_details_color) // +*/ attack_headline /*+ "</span>\n"*/ + '\n', ""); for (const attack_type &at : u->attacks()) { attack_info(rc, at, res, *u, displayed_unit_hex); } return res; }
static config unit_hp(reports::context& rc, const unit* u) { if (!u) return config(); std::ostringstream str, tooltip; str << span_color(u->hp_color()) << u->hitpoints() << '/' << u->max_hitpoints() << naps; std::set<std::string> resistances_table; bool att_def_diff = false; map_location displayed_unit_hex = rc.screen().displayed_unit_hex(); BOOST_FOREACH(const utils::string_map::value_type &resist, u->get_base_resistances()) { std::ostringstream line; line << translation::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) << naps << '\n'; } else { const std::string att_color = unit_helper::resistance_color(res_att); line << "<span foreground=\"" << att_color << "\">" << utils::signed_percent(res_att) << naps << "/" << "<span foreground=\"" << def_color << "\">" << utils::signed_percent(res_def) << naps << '\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 time_of_day_at(reports::context & rc, const map_location& mouseover_hex) { std::ostringstream tooltip; time_of_day tod; const team &viewing_team = rc.teams()[rc.screen().viewing_team()]; if (viewing_team.shrouded(mouseover_hex)) { // Don't show time on shrouded tiles. tod = rc.tod().get_time_of_day(); } else if (viewing_team.fogged(mouseover_hex)) { // Don't show illuminated time on fogged tiles. tod = rc.tod().get_time_of_day(mouseover_hex); } else { tod = rc.tod().get_illuminated_time_of_day(rc.units(), rc.map(), mouseover_hex); } int b = tod.lawful_bonus; std::string lawful_color("white"); std::string chaotic_color("white"); std::string liminal_color("white"); if (b != 0) { lawful_color = (b > 0) ? "green" : "red"; chaotic_color = (b < 0) ? "green" : "red"; liminal_color = "red"; } tooltip << tod.name << '\n' << _("Lawful units: ") << "<span foreground=\"" << lawful_color << "\">" << utils::signed_percent(b) << "</span>\n" << _("Neutral units: ") << utils::signed_percent(0) << '\n' << _("Chaotic units: ") << "<span foreground=\"" << chaotic_color << "\">" << utils::signed_percent(-b) << "</span>\n" << _("Liminal units: ") << "<span foreground=\"" << liminal_color << "\">" << utils::signed_percent(-(abs(b))) << "</span>\n"; std::string tod_image = tod.image; if (tod.bonus_modified > 0) tod_image += "~BRIGHTEN()"; else if (tod.bonus_modified < 0) tod_image += "~DARKEN()"; return image_report(tod_image, tooltip.str(), "time_of_day_" + tod.id); }
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"); }
static config unit_status(reports::context & rc, const unit* u) { if (!u) return config(); config res; map_location displayed_unit_hex = rc.screen().displayed_unit_hex(); if (rc.map().on_board(displayed_unit_hex) && u->invisible(displayed_unit_hex)) { 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_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; }
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; }
static config unit_box_at(reports::context & rc, const map_location& mouseover_hex) { std::ostringstream tooltip; time_of_day local_tod; time_of_day global_tod = rc.tod().get_time_of_day(); const team &viewing_team = rc.teams()[rc.screen().viewing_team()]; if (viewing_team.shrouded(mouseover_hex)) { // Don't show time on shrouded tiles. local_tod = global_tod; } else if (viewing_team.fogged(mouseover_hex)) { // Don't show illuminated time on fogged tiles. local_tod = rc.tod().get_time_of_day(mouseover_hex); } else { local_tod = rc.tod().get_illuminated_time_of_day(rc.units(), rc.map(),mouseover_hex); } int bonus = local_tod.lawful_bonus; std::string lawful_color("white"); std::string chaotic_color("white"); std::string liminal_color("white"); if (bonus != 0) { lawful_color = (bonus > 0) ? "green" : "red"; chaotic_color = (bonus < 0) ? "green" : "red"; liminal_color = "red"; } tooltip << local_tod.name << '\n' << _("Lawful units: ") << "<span foreground=\"" << lawful_color << "\">" << utils::signed_percent(bonus) << "</span>\n" << _("Neutral units: ") << utils::signed_percent(0) << '\n' << _("Chaotic units: ") << "<span foreground=\"" << chaotic_color << "\">" << utils::signed_percent(-bonus) << "</span>\n" << _("Liminal units: ") << "<span foreground=\"" << liminal_color << "\">" << utils::signed_percent(-(abs(bonus))) << "</span>\n"; std::string local_tod_image = "themes/classic/" + local_tod.image; std::string global_tod_image = "themes/classic/" + global_tod.image; if (local_tod.bonus_modified > 0) local_tod_image += "~BRIGHTEN()"; else if (local_tod.bonus_modified < 0) local_tod_image += "~DARKEN()"; const gamemap &map = rc.map(); t_translation::t_terrain terrain = map.get_terrain(mouseover_hex); //if (terrain == t_translation::OFF_MAP_USER) // return config(); //if (map.is_keep(mouseover_hex)) { // add_image(cfg, "icons/terrain/terrain_type_keep.png", ""); //} const t_translation::t_list& underlying_terrains = map.underlying_union_terrain(terrain); std::string bg_terrain_image; for (const t_translation::t_terrain& underlying_terrain : underlying_terrains) { const std::string& terrain_id = map.get_terrain_info(underlying_terrain).id(); bg_terrain_image = "~BLIT(unit_env/terrain/terrain-" + terrain_id + ".png)" + bg_terrain_image; } std::stringstream color; color << local_tod.color; bg_terrain_image = bg_terrain_image + "~CS(" + color.str() + ")"; const unit *u = get_visible_unit(rc); std::string unit_image; if (u) unit_image = "~BLIT(" + u->absolute_image() + u->image_mods() + ",35,22)"; std::string tod_image = global_tod_image + "~BLIT(" + local_tod_image + ")"; return image_report(tod_image + bg_terrain_image + unit_image, tooltip.str(), "time_of_day"); }