The Battle for Wesnoth  1.17.17+dev
reports.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2023
3  by David White <dave@whitevine.net>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #include "actions/attack.hpp"
17 #include "attack_prediction.hpp"
18 #include "desktop/battery_info.hpp"
19 #include "font/pango/escape.hpp"
20 #include "font/text_formatting.hpp"
21 #include "formatter.hpp"
22 #include "formula/string_utils.hpp"
23 #include "preferences/game.hpp"
24 #include "gettext.hpp"
25 #include "language.hpp"
26 #include "map/map.hpp"
27 #include "mouse_events.hpp"
28 #include "pathfind/pathfind.hpp"
29 #include "picture.hpp"
30 #include "reports.hpp"
31 #include "resources.hpp"
32 #include "color.hpp"
33 #include "team.hpp"
34 #include "terrain/movement.hpp"
35 #include "tod_manager.hpp"
36 #include "units/unit.hpp"
37 #include "units/helper.hpp"
38 #include "units/types.hpp"
40 #include "whiteboard/manager.hpp"
41 
42 #include <cassert>
43 #include <ctime>
44 #include <iomanip>
45 #include <boost/dynamic_bitset.hpp>
46 #include <boost/format.hpp>
47 #include <boost/lexical_cast.hpp>
48 
49 static void add_text(config &report, const std::string &text,
50  const std::string &tooltip, const std::string &help = "")
51 {
52  config &element = report.add_child("element");
53  element["text"] = text;
54  if (!tooltip.empty()) element["tooltip"] = tooltip;
55  if (!help.empty()) element["help"] = help;
56 }
57 
58 static void add_image(config &report, const std::string &image,
59  const std::string &tooltip, const std::string &help = "")
60 {
61  config &element = report.add_child("element");
62  element["image"] = image;
63  if (!tooltip.empty()) element["tooltip"] = tooltip;
64  if (!help.empty()) element["help"] = help;
65 }
66 
67 static config text_report(const std::string &text,
68  const std::string &tooltip = "", const std::string &help = "")
69 {
70  config r;
71  add_text(r, text, tooltip, help);
72  return r;
73 }
74 
75 static config image_report(const std::string &image,
76  const std::string &tooltip = "", const std::string &help = "")
77 {
78  config r;
80  return r;
81 }
82 
83 using font::span_color;
84 
85 static void add_status(config &r,
86  char const *path, char const *desc1, char const *desc2)
87 {
88  std::ostringstream s;
89  s << translation::gettext(desc1) << translation::gettext(desc2);
90  add_image(r, path, s.str());
91 }
92 
93 static std::string flush(std::ostringstream &s)
94 {
95  std::string r(s.str());
96  s.str(std::string());
97  return r;
98 }
99 
101 {
102  const team &viewing_team = rc.teams()[rc.screen().viewing_team()];
103  if (viewing_team.shrouded(hex)) {
104  // Don't show time on shrouded tiles.
105  return rc.tod().get_time_of_day();
106  } else if (viewing_team.fogged(hex)) {
107  // Don't show illuminated time on fogged tiles.
108  return rc.tod().get_time_of_day(hex);
109  } else {
110  return rc.tod().get_illuminated_time_of_day(rc.units(), rc.map(), hex);
111  }
112 }
113 
114 typedef std::map<std::string, reports::generator_function> static_report_generators;
116 
118 {
120  {
121  static_generators.insert(static_report_generators::value_type(name, g));
122  }
123 };
124 
125 #define REPORT_GENERATOR(n, cn) \
126  static config report_##n(const reports::context& cn); \
127  static report_generator_helper reg_gen_##n(#n, &report_##n); \
128  static config report_##n(const reports::context& cn)
129 
130 static char const *naps = "</span>";
131 
132 static const unit *get_visible_unit(const reports::context& rc)
133 {
134  return rc.dc().get_visible_unit(rc.screen().displayed_unit_hex(),
135  rc.teams()[rc.screen().viewing_team()],
136  rc.screen().show_everything());
137 }
138 
139 static const unit *get_selected_unit(const reports::context& rc)
140 {
141  return rc.dc().get_visible_unit(rc.screen().selected_hex(),
142  rc.teams()[rc.screen().viewing_team()],
143  rc.screen().show_everything());
144 }
145 
147 {
149  rc.teams()[rc.screen().viewing_team()],
150  rc.screen().show_everything());
151 }
152 
153 static config gray_inactive(const reports::context& rc, const std::string &str, const std::string& tooltip = "")
154 {
155  if ( rc.screen().viewing_side() == rc.screen().playing_side() )
156  return text_report(str, tooltip);
157 
159 }
160 
161 static config unit_name(const unit *u)
162 {
163  if (!u) {
164  return config();
165  }
166 
167  /*
168  * The name needs to be escaped, it might be set by the user and using
169  * markup. Also names often contain a forbidden single quote.
170  */
171  const std::string& name = font::escape_text(u->name());
172  std::ostringstream str, tooltip;
173  str << "<b>" << name << "</b>";
174  tooltip << _("Name: ") << "<b>" << name << "</b>";
175  return text_report(str.str(), tooltip.str());
176 }
177 
179 {
180  const unit *u = get_visible_unit(rc);
181  return unit_name(u);
182 }
183 REPORT_GENERATOR(selected_unit_name, rc)
184 {
185  const unit *u = get_selected_unit(rc);
186  return unit_name(u);
187 }
188 
189 static config unit_type(const unit* u)
190 {
191  if (!u) return config();
192  std::string has_variations_prefix = (u->type().show_variations_in_help() ? ".." : "");
193  std::ostringstream str, tooltip;
194  str << u->type_name();
195  tooltip << _("Type: ") << "<b>" << u->type_name() << "</b>\n"
196  << u->unit_description();
197  if(const auto& notes = u->unit_special_notes(); !notes.empty()) {
198  tooltip << "\n\n" << _("Special Notes:") << '\n';
199  for(const auto& note : notes) {
200  tooltip << font::unicode_bullet << " " << note << '\n';
201  }
202  }
203  return text_report(str.str(), tooltip.str(), has_variations_prefix + "unit_" + u->type_id());
204 }
206 {
207  const unit *u = get_visible_unit(rc);
208  return unit_type(u);
209 }
210 REPORT_GENERATOR(selected_unit_type, rc)
211 {
212  const unit *u = get_selected_unit(rc);
213  return unit_type(u);
214 }
215 
216 static config unit_race(const unit* u)
217 {
218  if (!u) return config();
219  std::ostringstream str, tooltip;
220  str << u->race()->name(u->gender());
221  tooltip << _("Race: ") << "<b>" << u->race()->name(u->gender()) << "</b>";
222  return text_report(str.str(), tooltip.str(), "..race_" + u->race()->id());
223 }
225 {
226  const unit *u = get_visible_unit(rc);
227  return unit_race(u);
228 }
229 REPORT_GENERATOR(selected_unit_race, rc)
230 {
231  const unit *u = get_selected_unit(rc);
232  return unit_race(u);
233 }
234 
235 static std::string side_tooltip(const team& team)
236 {
237  if(team.side_name().empty())
238  return "";
239 
240  return VGETTEXT("Side: <b>$side_name</b> ($color_name)",
241  {{"side_name", team.side_name()},
242  {"color_name", team::get_side_color_name_for_UI(team.side()) }});
243 }
244 
245 static config unit_side(const reports::context& rc, const unit* u)
246 {
247  if (!u) return config();
248 
249  config report;
250  const team &u_team = rc.dc().get_team(u->side());
251  std::string flag_icon = u_team.flag_icon();
252  std::string old_rgb = game_config::flag_rgb;
253  std::string new_rgb = u_team.color();
254  std::string mods = "~RC(" + old_rgb + ">" + new_rgb + ")";
255  if (flag_icon.empty())
257 
258  std::stringstream text;
259  text << " " << u->side();
260 
261  const std::string& tooltip = side_tooltip(u_team);
262  add_image(report, flag_icon + mods, tooltip, "");
263  add_text(report, text.str(), tooltip, "");
264  return report;
265 }
267 {
268  const unit *u = get_visible_unit(rc);
269  return unit_side(rc,u);
270 }
271 REPORT_GENERATOR(selected_unit_side, rc)
272 {
273  const unit *u = get_selected_unit(rc);
274  return unit_side(rc, u);
275 }
276 
277 static config unit_level(const unit* u)
278 {
279  if (!u) return config();
280  return text_report(std::to_string(u->level()), unit_helper::unit_level_tooltip(*u));
281 }
283 {
284  const unit *u = get_visible_unit(rc);
285  return unit_level(u);
286 }
287 REPORT_GENERATOR(selected_unit_level, rc)
288 {
289  const unit *u = get_selected_unit(rc);
290  return unit_level(u);
291 }
292 
293 REPORT_GENERATOR(unit_amla, rc)
294 {
295  const unit *u = get_visible_unit(rc);
296  if (!u) return config();
297  config res;
298  typedef std::pair<std::string, std::string> pair_string;
299  for (const pair_string &ps : u->amla_icons()) {
300  add_image(res, ps.first, ps.second);
301  }
302  return res;
303 }
304 
305 static config unit_traits(const unit* u)
306 {
307  if (!u) return config();
308  config res;
309  const std::vector<t_string> &traits = u->trait_names();
310  const std::vector<t_string> &descriptions = u->trait_descriptions();
311  const std::vector<std::string> &trait_ids = u->get_traits_list();
312  unsigned nb = traits.size();
313  for (unsigned i = 0; i < nb; ++i)
314  {
315  std::ostringstream str, tooltip;
316  str << traits[i];
317  if (i != nb - 1 ) str << ", ";
318  tooltip << _("Trait: ") << "<b>" << traits[i] << "</b>\n"
319  << descriptions[i];
320  add_text(res, str.str(), tooltip.str(), "traits_" + trait_ids[i]);
321  }
322  return res;
323 }
325 {
326  const unit *u = get_visible_unit(rc);
327  return unit_traits(u);
328 }
329 REPORT_GENERATOR(selected_unit_traits, rc)
330 {
331  const unit *u = get_selected_unit(rc);
332  return unit_traits(u);
333 }
334 
335 static config unit_status(const reports::context& rc, const unit* u)
336 {
337  if (!u) return config();
338  config res;
339  map_location displayed_unit_hex = rc.screen().displayed_unit_hex();
340  if (rc.map().on_board(displayed_unit_hex) && u->invisible(displayed_unit_hex)) {
341  add_status(res, "misc/invisible.png", N_("invisible: "),
342  N_("This unit is invisible. It cannot be seen or attacked by enemy units."));
343  }
344  if (u->get_state(unit::STATE_SLOWED)) {
345  add_status(res, "misc/slowed.png", N_("slowed: "),
346  N_("This unit has been slowed. It will only deal half its normal damage when attacking and its movement cost is doubled."));
347  }
349  add_status(res, "misc/poisoned.png", N_("poisoned: "),
350  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."));
351  }
353  add_status(res, "misc/petrified.png", N_("petrified: "),
354  N_("This unit has been petrified. It may not move or attack."));
355  }
357  add_status(res, "misc/unhealable.png", N_("unhealable: "),
358  N_("This unit is unhealable. It cannot be healed by healers or villages and doesn’t benefit from resting."));
359  }
361  add_status(res, "misc/invulnerable.png", N_("invulnerable: "),
362  N_("This unit is invulnerable. It cannot be harmed by any attack."));
363  }
364  return res;
365 }
367 {
368  const unit *u = get_visible_unit(rc);
369  return unit_status(rc,u);
370 }
371 REPORT_GENERATOR(selected_unit_status, rc)
372 {
373  const unit *u = get_selected_unit(rc);
374  return unit_status(rc, u);
375 }
376 
377 static config unit_alignment(const reports::context& rc, const unit* u, const map_location& hex)
378 {
379  if (!u) return config();
380  std::ostringstream str, tooltip;
381  const std::string align = unit_type::alignment_description(u->alignment(), u->gender());
382  const std::string align_id = unit_alignments::get_string(u->alignment());
383  const time_of_day effective_tod = get_visible_time_of_day_at(rc, hex);
384  int cm = combat_modifier(effective_tod, u->alignment(), u->is_fearless());
385 
386  color_t color = font::weapon_color;
387  if (cm != 0)
388  color = (cm > 0) ? font::good_dmg_color : font::bad_dmg_color;
389 
390  str << align << " (" << span_color(color) << utils::signed_percent(cm)
391  << naps << ")";
392 
393  tooltip << _("Alignment: ") << "<b>" << align << "</b>\n"
394  << string_table[align_id + "_description"];
395 
396  return text_report(str.str(), tooltip.str(), "time_of_day");
397 }
399 {
400  const unit *u = get_visible_unit(rc);
401  const map_location& mouseover_hex = rc.screen().mouseover_hex();
402  const map_location& displayed_unit_hex = rc.screen().displayed_unit_hex();
403  const map_location& hex = mouseover_hex.valid() ? mouseover_hex : displayed_unit_hex;
404  return unit_alignment(rc, u, hex);
405 }
406 REPORT_GENERATOR(selected_unit_alignment, rc)
407 {
408  const unit *u = get_selected_unit(rc);
409  const map_location& attack_indicator_src = game_display::get_singleton()->get_attack_indicator_src();
410  const map_location& hex_to_show_alignment_at =
411  attack_indicator_src.valid() ? attack_indicator_src : u->get_location();
412  return unit_alignment(rc, u, hex_to_show_alignment_at);
413 }
414 
415 static config unit_abilities(const unit* u, const map_location& loc)
416 {
417  if (!u) return config();
418  config res;
419 
420  boost::dynamic_bitset<> active;
421  const auto abilities = u->ability_tooltips(active, loc);
422 
423  const std::size_t abilities_size = abilities.size();
424  for(std::size_t i = 0; i != abilities_size; ++i) {
425  // Aliases for readability:
426  const auto& [id, base_name, display_name, description] = abilities[i];
427 
428  std::ostringstream str, tooltip;
429 
430  if(active[i]) {
431  str << display_name;
432  } else {
433  str << span_color(font::inactive_ability_color) << display_name << naps;
434  }
435 
436  if(i + 1 != abilities_size) {
437  str << ", ";
438  }
439 
440  tooltip << _("Ability: ") << "<b>" << display_name << "</b>";
441  if(!active[i]) {
442  tooltip << "<i>" << _(" (inactive)") << "</i>";
443  }
444 
445  tooltip << '\n' << description;
446 
447  add_text(res, str.str(), tooltip.str(), "ability_" + id + base_name.base_str());
448  }
449 
450  return res;
451 }
453 {
454  const unit *u = get_visible_unit(rc);
455  const team &viewing_team = rc.teams()[rc.screen().viewing_team()];
456  const map_location& mouseover_hex = rc.screen().mouseover_hex();
457  const map_location& displayed_unit_hex = rc.screen().displayed_unit_hex();
458  const map_location& hex = (mouseover_hex.valid() && !viewing_team.shrouded(mouseover_hex)) ? mouseover_hex : displayed_unit_hex;
459 
460  return unit_abilities(u, hex);
461 }
462 REPORT_GENERATOR(selected_unit_abilities, rc)
463 {
464  const unit *u = get_selected_unit(rc);
465 
466  const map_location& mouseover_hex = rc.screen().mouseover_hex();
467  const unit *visible_unit = get_visible_unit(rc);
468  const team &viewing_team = rc.teams()[rc.screen().viewing_team()];
469 
470  if (visible_unit && u && visible_unit->id() != u->id() && mouseover_hex.valid() && !viewing_team.shrouded(mouseover_hex))
471  return unit_abilities(u, mouseover_hex);
472  else
473  return unit_abilities(u, u->get_location());
474 }
475 
476 
477 static config unit_hp(const reports::context& rc, const unit* u)
478 {
479  if (!u) return config();
480  std::ostringstream str, tooltip;
481  str << span_color(u->hp_color()) << u->hitpoints()
482  << '/' << u->max_hitpoints() << naps;
483 
484  std::vector<std::string> resistances_table;
485 
486  bool att_def_diff = false;
487  map_location displayed_unit_hex = rc.screen().displayed_unit_hex();
488  for (const utils::string_map_res::value_type &resist : u->get_base_resistances())
489  {
490  std::ostringstream line;
491  line << translation::gettext(resist.first.c_str()) << ": ";
492  // Some units have different resistances when attacking or defending.
493  int res_att = 100 - u->resistance_against(resist.first, true, displayed_unit_hex);
494  int res_def = 100 - u->resistance_against(resist.first, false, displayed_unit_hex);
495  const std::string def_color = unit_helper::resistance_color(res_def);
496  if (res_att == res_def) {
497  line << "<span foreground=\"" << def_color << "\">" << utils::signed_percent(res_def)
498  << naps << '\n';
499  } else {
500  const std::string att_color = unit_helper::resistance_color(res_att);
501  line << "<span foreground=\"" << att_color << "\">" << utils::signed_percent(res_att)
502  << naps << "/"
503  << "<span foreground=\"" << def_color << "\">" << utils::signed_percent(res_def)
504  << naps << '\n';
505  att_def_diff = true;
506  }
507  resistances_table.push_back(line.str());
508  }
509 
510  tooltip << _("Resistances: ");
511  if (att_def_diff)
512  tooltip << _("(Att / Def)");
513  tooltip << '\n';
514  for (const std::string &line : resistances_table) {
515  tooltip << line;
516  }
517  return text_report(str.str(), tooltip.str());
518 }
520 {
521  const unit *u = get_visible_unit(rc);
522  return unit_hp(rc, u);
523 }
524 REPORT_GENERATOR(selected_unit_hp, rc)
525 {
526  const unit *u = get_selected_unit(rc);
527  return unit_hp(rc, u);
528 }
529 
530 static config unit_xp(const unit* u)
531 {
532  if (!u) return config();
533  std::ostringstream str, tooltip;
534  str << span_color(u->xp_color());
535  if(u->can_advance()) {
536  str << u->experience() << '/' << u->max_experience();
537  } else {
538  str << font::unicode_en_dash;
539  }
540  str << naps;
541 
543  tooltip << _("Experience Modifier: ") << exp_mod << '%';
544  return text_report(str.str(), tooltip.str());
545 }
547 {
548  const unit *u = get_visible_unit(rc);
549  return unit_xp(u);
550 }
551 REPORT_GENERATOR(selected_unit_xp, rc)
552 {
553  const unit *u = get_selected_unit(rc);
554  return unit_xp(u);
555 }
556 
558 {
559  if (!u) return config();
560  config res;
561  for (const auto& ps : u->advancement_icons()) {
562  add_image(res, ps.first, ps.second);
563  }
564  return res;
565 }
567 {
568  const unit *u = get_visible_unit(rc);
569  return unit_advancement_options(u);
570 }
571 REPORT_GENERATOR(selected_unit_advancement_options, rc)
572 {
573  const unit *u = get_selected_unit(rc);
574  return unit_advancement_options(u);
575 }
576 
577 static config unit_defense(const reports::context& rc, const unit* u, const map_location& displayed_unit_hex)
578 {
579  if(!u) {
580  return config();
581  }
582 
583  std::ostringstream str, tooltip;
584  const gamemap &map = rc.map();
585  if(!rc.map().on_board(displayed_unit_hex)) {
586  return config();
587  }
588 
589  const t_translation::terrain_code &terrain = map[displayed_unit_hex];
590  int def = 100 - u->defense_modifier(terrain);
591  color_t color = game_config::red_to_green(def);
592  str << span_color(color) << def << '%' << naps;
593  tooltip << _("Terrain: ") << "<b>" << map.get_terrain_info(terrain).description() << "</b>\n";
594 
595  const t_translation::ter_list &underlyings = map.underlying_def_terrain(terrain);
596  if (underlyings.size() != 1 || underlyings.front() != terrain)
597  {
598  bool revert = false;
599  for (const t_translation::terrain_code &t : underlyings)
600  {
601  if (t == t_translation::MINUS) {
602  revert = true;
603  } else if (t == t_translation::PLUS) {
604  revert = false;
605  } else {
606  int t_def = 100 - u->defense_modifier(t);
607  color_t t_color = game_config::red_to_green(t_def);
608  tooltip << '\t' << map.get_terrain_info(t).description() << ": "
609  << span_color(t_color) << t_def << '%' << naps
610  << (revert ? _("maximum^max.") : _("minimum^min.")) << '\n';
611  }
612  }
613  }
614 
615  tooltip << "<b>" << _("Defense: ") << span_color(color) << def << '%' << naps << "</b>";
616  const std::string has_variations_prefix = (u->type().show_variations_in_help() ? ".." : "");
617  return text_report(str.str(), tooltip.str(), has_variations_prefix + "unit_" + u->type_id());
618 }
620 {
621  const unit *u = get_visible_unit(rc);
622  const team &viewing_team = rc.teams()[rc.screen().viewing_team()];
623  const map_location& mouseover_hex = rc.screen().mouseover_hex();
624  const map_location& displayed_unit_hex = rc.screen().displayed_unit_hex();
625  const map_location& hex = (mouseover_hex.valid() && !viewing_team.shrouded(mouseover_hex)) ? mouseover_hex : displayed_unit_hex;
626  return unit_defense(rc, u, hex);
627 }
628 REPORT_GENERATOR(selected_unit_defense, rc)
629 {
630  const unit *u = get_selected_unit(rc);
631  const map_location& attack_indicator_src = game_display::get_singleton()->get_attack_indicator_src();
632  if(attack_indicator_src.valid())
633  return unit_defense(rc, u, attack_indicator_src);
634 
635  const map_location& mouseover_hex = rc.screen().mouseover_hex();
636  const unit *visible_unit = get_visible_unit(rc);
637  if(visible_unit && u && visible_unit->id() != u->id() && mouseover_hex.valid())
638  return unit_defense(rc, u, mouseover_hex);
639  else
640  return unit_defense(rc, u, u->get_location());
641 }
642 
643 static config unit_vision(const unit* u)
644 {
645  if (!u) return config();
646 
647  // TODO
648  std::ostringstream str, tooltip;
649  if (u->vision() != u->total_movement()) {
650  str << _("vision:") << ' ' << u->vision();
651  tooltip << _("vision:") << ' ' << u->vision() << '\n';
652  }
653  if (u->jamming() != 0) {
654  if (static_cast<std::streamoff>(str.tellp()) == 0)
655  str << _("jamming:") << ' ' << u->jamming();
656  tooltip << _("jamming:") << ' ' << u->jamming() << '\n';
657  }
658  return text_report(str.str(), tooltip.str());
659 }
661 {
662  const unit* u = get_visible_unit(rc);
663  return unit_vision(u);
664 }
665 REPORT_GENERATOR(selected_unit_vision, rc)
666 {
667  const unit* u = get_selected_unit(rc);
668  return unit_vision(u);
669 }
670 
671 static config unit_moves(const reports::context& rc, const unit* u, bool is_visible_unit)
672 {
673  if (!u) return config();
674  std::ostringstream str, tooltip;
675  double movement_frac = 1.0;
676 
677  std::set<terrain_movement> terrain_moves;
678 
679  if (u->side() == rc.screen().playing_side()) {
680  movement_frac = static_cast<double>(u->movement_left()) / std::max<int>(1, u->total_movement());
681  if (movement_frac > 1.0)
682  movement_frac = 1.0;
683  }
684 
685  tooltip << _("Movement Costs:") << "\n";
688  continue;
689 
690  const terrain_type& info = rc.map().get_terrain_info(terrain);
691 
692  if (info.union_type().size() == 1 && info.union_type()[0] == info.number() && info.is_nonnull()) {
693  terrain_moves.emplace(info.name(), u->movement_cost(terrain));
694  }
695  }
696 
697  for (const terrain_movement& tm : terrain_moves) {
698  tooltip << tm.name << ": ";
699 
700  //movement - range: 1 .. 5, movetype::UNREACHABLE=impassable
701  const bool cannot_move = tm.moves > u->total_movement(); // cannot move in this terrain
702  double movement_red_to_green = 100.0 - 25.0 * tm.moves;
703 
704  // passing true to select the less saturated red-to-green scale
705  std::string color = game_config::red_to_green(movement_red_to_green, true).to_hex_string();
706  tooltip << "<span foreground=\"" << color << "\">";
707  // A 5 MP margin; if the movement costs go above
708  // the unit's max moves + 5, we replace it with dashes.
709  if (cannot_move && (tm.moves > u->total_movement() + 5)) {
711  } else if (cannot_move) {
712  tooltip << "(" << tm.moves << ")";
713  } else {
714  tooltip << tm.moves;
715  }
716  if(tm.moves != 0) {
717  const int movement_hexes_per_turn = u->total_movement() / tm.moves;
718  tooltip << " ";
719  for(int i = 0; i < movement_hexes_per_turn; ++i) {
720  // Unicode horizontal black hexagon and Unicode zero width space (to allow a line break)
721  tooltip << "\u2b23\u200b";
722  }
723  }
724  tooltip << naps << '\n';
725  }
726 
727  int grey = 128 + static_cast<int>((255 - 128) * movement_frac);
728  color_t c = color_t(grey, grey, grey);
729  int numerator = u->movement_left();
730  if(is_visible_unit) {
732  if(route.steps.size() > 0) {
733  numerator -= route.move_cost;
734  if(numerator < 0) {
735  // Multi-turn move
736  // TODO: what to show in this case?
737  numerator = 0;
738  }
739 
740  // If the route captures a village, assume that uses up all remaining MP.
741  const auto& end = route.marks.find(route.steps.back());
742  if(end != route.marks.end() && end->second.capture) {
743  numerator = 0;
744  }
745  } else {
746  // TODO: if the mouseover hex is unreachable (for example, a deep water hex
747  // and the current unit is a land unit), what to show?
748  }
749  }
750  str << span_color(c) << numerator << '/' << u->total_movement() << naps;
751  return text_report(str.str(), tooltip.str());
752 }
754 {
755  const unit *u = get_visible_unit(rc);
756  return unit_moves(rc, u, true);
757 }
758 REPORT_GENERATOR(selected_unit_moves, rc)
759 {
760  const unit *u = get_selected_unit(rc);
761  return unit_moves(rc, u, false);
762 }
763 
764 /**
765  * Maps resistance <= -60 (resistance value <= -60%) to intense red.
766  * Maps resistance >= 60 (resistance value >= 60%) to intense green.
767  * Intermediate values are affinely mapped to the red-to-green scale,
768  * with 0 (0%) being mapped to yellow.
769  * Compare unit_helper::resistance_color().
770  */
771 static inline const color_t attack_info_percent_color(int resistance)
772 {
773  // Passing false to select the more saturated red-to-green scale.
774  return game_config::red_to_green(50.0 + resistance * 5.0 / 6.0, false);
775 }
776 
777 static int attack_info(const reports::context& rc, const attack_type &at, config &res, const unit &u, const map_location &hex, const unit* sec_u = nullptr, const_attack_ptr sec_u_weapon = nullptr)
778 {
779  std::ostringstream str, tooltip;
780  int damage = 0;
781 
782  struct string_with_tooltip {
783  std::string str;
784  std::string tooltip;
785  };
786 
787  {
788  auto ctx = at.specials_context(u.shared_from_this(), hex, u.side() == rc.screen().playing_side());
789  int base_damage = at.damage();
790  int specials_damage = at.modified_damage();
791  int damage_multiplier = 100;
792  const_attack_ptr weapon = at.shared_from_this();
793  int tod_bonus = combat_modifier(get_visible_time_of_day_at(rc, hex), u.alignment(), u.is_fearless());
794  damage_multiplier += tod_bonus;
795  int leader_bonus = under_leadership(u, hex, weapon);
796  if (leader_bonus != 0)
797  damage_multiplier += leader_bonus;
798 
800  int damage_divisor = slowed ? 20000 : 10000;
801  // Assume no specific resistance (i.e. multiply by 100).
802  damage = round_damage(specials_damage, damage_multiplier * 100, damage_divisor);
803 
804  // Hit points are used to calculate swarm, so they need to be bounded.
805  unsigned max_hp = u.max_hitpoints();
806  unsigned cur_hp = std::min<unsigned>(std::max(0, u.hitpoints()), max_hp);
807 
808  unsigned base_attacks = at.num_attacks();
809  unsigned min_attacks, max_attacks;
810  at.modified_attacks(min_attacks, max_attacks);
811  unsigned num_attacks = swarm_blows(min_attacks, max_attacks, cur_hp, max_hp);
812 
813  color_t dmg_color = font::weapon_color;
814  if ( damage > specials_damage )
815  dmg_color = font::good_dmg_color;
816  else if ( damage < specials_damage )
817  dmg_color = font::bad_dmg_color;
818 
819  str << span_color(dmg_color) << " " << damage << naps << span_color(font::weapon_color)
820  << font::weapon_numbers_sep << num_attacks << ' ' << at.name()
821  << "</span>\n";
822  tooltip << _("Weapon: ") << "<b>" << at.name() << "</b>\n"
823  << _("Damage: ") << "<b>" << damage << "</b>\n";
824 
825  if ( tod_bonus || leader_bonus || slowed || specials_damage != base_damage )
826  {
827  tooltip << '\t' << _("Base damage: ") << base_damage << '\n';
828  if ( specials_damage != base_damage ) {
829  tooltip << '\t' << _("With specials: ") << specials_damage << '\n';
830  }
831  if (tod_bonus) {
832  tooltip << '\t' << _("Time of day: ")
833  << utils::signed_percent(tod_bonus) << '\n';
834  }
835  if (leader_bonus) {
836  tooltip << '\t' << _("Leadership: ")
837  << utils::signed_percent(leader_bonus) << '\n';
838  }
839  if (slowed) {
840  tooltip << '\t' << _("Slowed: ") << "/ 2" << '\n';
841  }
842  }
843 
844  tooltip << _("Attacks: ") << "<b>" << num_attacks << "</b>\n";
845  if ( max_attacks != min_attacks && cur_hp != max_hp ) {
846  if ( max_attacks < min_attacks ) {
847  // "Reverse swarm"
848  tooltip << '\t' << _("Max swarm bonus: ") << (min_attacks-max_attacks) << '\n';
849  tooltip << '\t' << _("Swarm: ") << "* "<< (100 - cur_hp*100/max_hp) << "%\n";
850  tooltip << '\t' << _("Base attacks: ") << '+' << base_attacks << '\n';
851  // The specials line will not necessarily match up with how the
852  // specials are calculated, but for an unusual case, simple brevity
853  // trumps complexities.
854  if ( max_attacks != base_attacks ) {
855  int attack_diff = static_cast<int>(max_attacks) - static_cast<int>(base_attacks);
856  tooltip << '\t' << _("Specials: ") << utils::signed_value(attack_diff) << '\n';
857  }
858  }
859  else {
860  // Regular swarm
861  tooltip << '\t' << _("Base attacks: ") << base_attacks << '\n';
862  if ( max_attacks != base_attacks ) {
863  tooltip << '\t' << _("With specials: ") << max_attacks << '\n';
864  }
865  if ( min_attacks != 0 ) {
866  tooltip << '\t' << _("Subject to swarm: ") << (max_attacks-min_attacks) << '\n';
867  }
868  tooltip << '\t' << _("Swarm: ") << "* "<< (cur_hp*100/max_hp) << "%\n";
869  }
870  }
871  else if ( num_attacks != base_attacks ) {
872  tooltip << '\t' << _("Base attacks: ") << base_attacks << '\n';
873  tooltip << '\t' << _("With specials: ") << num_attacks << '\n';
874  }
875 
876  const string_with_tooltip damage_and_num_attacks {flush(str), flush(tooltip)};
877 
878  std::string range = string_table["range_" + at.range()];
879  std::string lang_type = string_table["type_" + at.type()];
880 
881  // SCALE_INTO() is needed in case the 72x72 images/misc/missing-image.png is substituted.
882  const std::string range_png = std::string("icons/profiles/") + at.range() + "_attack.png~SCALE_INTO(16,16)";
883  const std::string type_png = std::string("icons/profiles/") + at.type() + ".png~SCALE_INTO(16,16)";
884  const bool range_png_exists = image::locator(range_png).file_exists();
885  const bool type_png_exists = image::locator(type_png).file_exists();
886 
887  if(!range_png_exists || !type_png_exists) {
888  str << span_color(font::weapon_details_color) << " " << " "
889  << range << font::weapon_details_sep
890  << lang_type << "</span>\n";
891  }
892 
893  tooltip << _("Weapon range: ") << "<b>" << range << "</b>\n"
894  << _("Damage type: ") << "<b>" << lang_type << "</b>\n"
895  << _("Damage versus: ") << '\n';
896 
897  // Show this weapon damage and resistance against all the different units.
898  // We want weak resistances (= good damage) first.
899  std::map<int, std::set<std::string>, std::greater<int>> resistances;
900  std::set<std::string> seen_types;
901  const team &unit_team = rc.dc().get_team(u.side());
902  const team &viewing_team = rc.teams()[rc.screen().viewing_team()];
903  for (const unit &enemy : rc.units())
904  {
905  if (enemy.incapacitated()) //we can't attack statues so don't display them in this tooltip
906  continue;
907  if (!unit_team.is_enemy(enemy.side()))
908  continue;
909  const map_location &loc = enemy.get_location();
910  const bool see_all = game_config::debug || rc.screen().show_everything();
911  if (!enemy.is_visible_to_team(viewing_team, see_all))
912  continue;
913  bool new_type = seen_types.insert(enemy.type_id()).second;
914  if (new_type) {
915  int resistance = enemy.resistance_against(at, false, loc);
916  resistances[resistance].insert(enemy.type_name());
917  }
918  }
919 
920  for (const auto& resist : resistances) {
921  int damage_with_resistance = round_damage(specials_damage, damage_multiplier * resist.first, damage_divisor);
922  tooltip << "<b>" << damage_with_resistance << "</b> "
923  << "<span color='" << attack_info_percent_color(resist.first-100).to_hex_string() << "'>"
924  << "<i>(" << utils::signed_percent(resist.first-100) << ")</i>"
925  << naps
926  << " : \t" // spaces to align the tab to a multiple of 8
927  << utils::join(resist.second, " " + font::unicode_bullet + " ") << '\n';
928  }
929  const string_with_tooltip damage_versus {flush(str), flush(tooltip)};
930 
931 #if 0
932  // We wanted to use the attack icon here, but couldn't find a good layout.
933  // The default images are 60x60 and have a 2-pixel transparent border. Trim it.
934  // The first SCALE() accounts for theoretically possible add-ons attack images larger than 60x60.
935  const std::string attack_icon = at.icon() + "~SCALE_INTO_SHARP(60,60)~CROP(2,2,56,56)~SCALE_INTO_SHARP(32,32)";
936  add_image(res, attack_icon, at.name());
937  add_text(res, " ", "");
938 #endif
939 
940  // The icons are 16x16. We add 5px padding for alignment reasons (placement of the icon in relation to ascender and descender letters).
941  const std::string spacer = "misc/blank.png~CROP(0, 0, 16, 21)"; // 21 == 16+5
942  add_image(res, spacer + "~BLIT(" + range_png + ",0,5)", damage_versus.tooltip);
943  add_image(res, spacer + "~BLIT(" + type_png + ",0,5)", damage_versus.tooltip);
944  add_text(res, damage_and_num_attacks.str, damage_and_num_attacks.tooltip);
945  add_text(res, damage_versus.str, damage_versus.tooltip); // This string is usually empty
946 
947  const std::string &accuracy_parry = at.accuracy_parry_description();
948  if (!accuracy_parry.empty())
949  {
951  << " " << accuracy_parry << "</span>\n";
952  int accuracy = at.accuracy();
953  if (accuracy) {
954  tooltip << _("Accuracy:") << "<b>"
955  << utils::signed_percent(accuracy) << "</b>\n";
956  }
957  int parry = at.parry();
958  if (parry) {
959  tooltip << _("Parry:") << "<b>"
960  << utils::signed_percent(parry) << "</b>\n";
961  }
962  add_text(res, flush(str), flush(tooltip));
963  }
964  }
965 
966  {
967  //If we have a second unit, do the 2-unit specials_context
968  bool attacking = (u.side() == rc.screen().playing_side());
969  auto ctx = (sec_u == nullptr) ? at.specials_context_for_listing(attacking) :
970  at.specials_context(u.shared_from_this(), sec_u->shared_from_this(), hex, sec_u->get_location(), attacking, sec_u_weapon);
971 
972  boost::dynamic_bitset<> active;
973  const std::vector<std::pair<t_string, t_string>> &specials = at.special_tooltips(&active);
974  const std::size_t specials_size = specials.size();
975  for ( std::size_t i = 0; i != specials_size; ++i )
976  {
977  // Aliases for readability:
978  const t_string &name = specials[i].first;
979  const t_string &description = specials[i].second;
980  const color_t &details_color = active[i] ? font::weapon_details_color :
982 
983  str << span_color(details_color) << " " << " " << name << naps << '\n';
984  std::string help_page = "weaponspecial_" + name.base_str();
985  tooltip << _("Weapon special: ") << "<b>" << name << "</b>";
986  if ( !active[i] )
987  tooltip << "<i>" << _(" (inactive)") << "</i>";
988  tooltip << '\n' << description;
989 
990  add_text(res, flush(str), flush(tooltip), help_page);
991  }
992  if(!specials.empty()) {
993  // Add some padding so the end of the specials list
994  // isn't too close vertically to the attack icons of
995  // the next attack. Also for symmetry with the padding
996  // above the list of specials (below the attack icon line).
997  const std::string spacer = "misc/blank.png~CROP(0, 0, 1, 5)";
998  add_image(res, spacer, "");
999  add_text(res, "\n", "");
1000  }
1001  }
1002  return damage;
1003 }
1004 
1005 // Conversion routine for both unscathed and damage change percentage.
1006 static std::string format_prob(double prob)
1007 {
1008  if(prob > 0.9995) {
1009  return "100%";
1010  } else if(prob < 0.0005) {
1011  return "0%";
1012  }
1013  std::ostringstream res;
1014  res << std::setprecision(prob < 0.01 ? 1 : prob < 0.1 ? 2 : 3) << 100.0 * prob << "%";
1015  return res.str();
1016 }
1017 
1018 static std::string format_hp(unsigned hp)
1019 {
1020  std::ostringstream res;
1021  res << ' ' << std::setw(3) << hp;
1022  return res.str();
1023 }
1024 
1025 static config unit_weapons(const reports::context& rc, unit_const_ptr attacker, const map_location &attacker_pos, const unit *defender, bool show_attacker)
1026 {
1027  if (!attacker || !defender) return config();
1028 
1029  const unit* u = show_attacker ? attacker.get() : defender;
1030  const unit* sec_u = !show_attacker ? attacker.get() : defender;
1031  const map_location unit_loc = show_attacker ? attacker_pos : defender->get_location();
1032 
1033  std::ostringstream str, tooltip;
1034  config res;
1035 
1036  std::vector<battle_context> weapons;
1037  for (unsigned int i = 0; i < attacker->attacks().size(); i++) {
1038  // skip weapons with attack_weight=0
1039  if (attacker->attacks()[i].attack_weight() > 0) {
1040  weapons.emplace_back(rc.units(), attacker_pos, defender->get_location(), i, -1, 0.0, nullptr, attacker);
1041  }
1042  }
1043 
1044  for (const battle_context& weapon : weapons) {
1045 
1046  // Predict the battle outcome.
1047  combatant attacker_combatant(weapon.get_attacker_stats());
1048  combatant defender_combatant(weapon.get_defender_stats());
1049  attacker_combatant.fight(defender_combatant);
1050 
1051  const battle_context_unit_stats& context_unit_stats =
1052  show_attacker ? weapon.get_attacker_stats() : weapon.get_defender_stats();
1053  const battle_context_unit_stats& other_context_unit_stats =
1054  !show_attacker ? weapon.get_attacker_stats() : weapon.get_defender_stats();
1055 
1056  int total_damage = 0;
1057  int base_damage = 0;
1058  int num_blows = 0;
1059  int chance_to_hit = 0;
1060  t_string weapon_name = _("weapon^None");
1061 
1062  color_t dmg_color = font::weapon_color;
1063  if (context_unit_stats.weapon) {
1064  base_damage = attack_info(rc, *context_unit_stats.weapon, res, *u, unit_loc, sec_u, other_context_unit_stats.weapon);
1065  total_damage = context_unit_stats.damage;
1066  num_blows = context_unit_stats.num_blows;
1067  chance_to_hit = context_unit_stats.chance_to_hit;
1068  weapon_name = context_unit_stats.weapon->name();
1069 
1070  if ( total_damage > base_damage )
1071  dmg_color = font::good_dmg_color;
1072  else if ( total_damage < base_damage )
1073  dmg_color = font::bad_dmg_color;
1074  } else {
1075  str << span_color(font::weapon_color) << weapon_name << naps << "\n";
1076  tooltip << _("Weapon: ") << "<b>" << weapon_name << "</b>\n"
1077  << _("Damage: ") << "<b>" << "0" << "</b>\n";
1078  }
1079 
1080  color_t chance_color = game_config::red_to_green(chance_to_hit);
1081 
1082  // Total damage.
1083  str << " " << span_color(dmg_color) << total_damage << naps << span_color(font::weapon_color)
1084  << font::unicode_en_dash << num_blows
1085  << " (" << span_color(chance_color) << chance_to_hit << "%" << naps << ")"
1086  << naps << "\n";
1087 
1088  tooltip << _("Weapon: ") << "<b>" << weapon_name << "</b>\n"
1089  << _("Total damage") << "<b>" << total_damage << "</b>\n";
1090 
1091  // Create the hitpoints distribution.
1092  std::vector<std::pair<int, double>> hp_prob_vector;
1093 
1094  // First, we sort the probabilities in ascending order.
1095  std::vector<std::pair<double, int>> prob_hp_vector;
1096  int i;
1097 
1098  combatant* c = show_attacker ? &attacker_combatant : &defender_combatant;
1099 
1100  for(i = 0; i < static_cast<int>(c->hp_dist.size()); i++) {
1101  double prob = c->hp_dist[i];
1102 
1103  // We keep only values above 0.1%.
1104  if(prob > 0.001)
1105  prob_hp_vector.emplace_back(prob, i);
1106  }
1107 
1108  std::sort(prob_hp_vector.begin(), prob_hp_vector.end());
1109 
1110  //TODO fendrin -- make that dynamically
1111  int max_hp_distrib_rows_ = 10;
1112 
1113  // We store a few of the highest probability hitpoint values.
1114  int nb_elem = std::min<int>(max_hp_distrib_rows_, prob_hp_vector.size());
1115 
1116  for(i = prob_hp_vector.size() - nb_elem;
1117  i < static_cast<int>(prob_hp_vector.size()); i++) {
1118 
1119  hp_prob_vector.emplace_back(prob_hp_vector[i].second, prob_hp_vector[i].first);
1120  }
1121 
1122  // Then, we sort the hitpoint values in ascending order.
1123  std::sort(hp_prob_vector.begin(), hp_prob_vector.end());
1124  // And reverse the order. Might be doable in a better manor.
1125  std::reverse(hp_prob_vector.begin(), hp_prob_vector.end());
1126 
1127  for(i = 0; i < static_cast<int>(hp_prob_vector.size()); i++) {
1128 
1129  int hp = hp_prob_vector[i].first;
1130  double prob = hp_prob_vector[i].second;
1131  color_t prob_color = game_config::blue_to_white(prob * 100.0, true);
1132 
1133  str << span_color(font::weapon_details_color) << " " << " "
1134  << span_color(u->hp_color(hp)) << format_hp(hp) << naps
1135  << " " << font::weapon_numbers_sep << " "
1136  << span_color(prob_color) << format_prob(prob) << naps
1137  << naps << "\n";
1138  }
1139 
1140  add_text(res, flush(str), flush(tooltip));
1141  }
1142  return res;
1143 }
1144 
1145 /*
1146  * Display the attacks of the displayed unit against the unit passed as argument.
1147  * 'hex' is the location the attacker will be at during combat.
1148  */
1149 static config unit_weapons(const reports::context& rc, const unit *u, const map_location &hex)
1150 {
1151  config res = config();
1152  if ((u != nullptr) && (!u->attacks().empty())) {
1153  const std::string attack_headline = _n("Attack", "Attacks", u->attacks().size());
1154 
1156  + attack_headline + "</span>" + '\n', "");
1157 
1158  const auto left = u->attacks_left(false), max = u->max_attacks();
1159  if(max != 1) {
1160  // TRANSLATORS: This string is shown in the sidebar beneath the word "Attacks" when a unit can attack multiple times per turn
1161  const std::string line = VGETTEXT("Remaining: $left/$max",
1162  {{"left", std::to_string(left)},
1163  {"max", std::to_string(max)}});
1164  add_text(res, " " + span_color(font::weapon_details_color, line) + "\n",
1165  _("This unit can attack multiple times per turn."));
1166  }
1167 
1168  for (const attack_type &at : u->attacks())
1169  {
1170  attack_info(rc, at, res, *u, hex);
1171  }
1172  }
1173  return res;
1174 }
1176 {
1177  const unit *u = get_visible_unit(rc);
1178  const map_location& mouseover_hex = rc.screen().mouseover_hex();
1179  const map_location& displayed_unit_hex = rc.screen().displayed_unit_hex();
1180  const map_location& hex = mouseover_hex.valid() ? mouseover_hex : displayed_unit_hex;
1181  if (!u) return config();
1182 
1183  return unit_weapons(rc, u, hex);
1184 }
1185 REPORT_GENERATOR(highlighted_unit_weapons, rc)
1186 {
1188  const unit *sec_u = get_visible_unit(rc);
1189 
1190  if (!u) return report_unit_weapons(rc);
1191  if (!sec_u || u.get() == sec_u) return unit_weapons(rc, sec_u, rc.screen().mouseover_hex());
1192 
1193  map_location highlighted_hex = rc.screen().displayed_unit_hex();
1194  map_location attack_loc;
1195  if (rc.mhb())
1196  attack_loc = rc.mhb()->current_unit_attacks_from(highlighted_hex);
1197 
1198  if (!attack_loc.valid())
1199  return unit_weapons(rc, sec_u, rc.screen().mouseover_hex());
1200 
1201  //TODO: shouldn't this pass sec_u as secodn parameter ?
1202  return unit_weapons(rc, u, attack_loc, sec_u, false);
1203 }
1204 REPORT_GENERATOR(selected_unit_weapons, rc)
1205 {
1207  const unit *sec_u = get_visible_unit(rc);
1208 
1209  if (!u) return config();
1210  if (!sec_u || u.get() == sec_u) return unit_weapons(rc, u.get(), u->get_location());
1211 
1212  map_location highlighted_hex = rc.screen().displayed_unit_hex();
1213  map_location attack_loc;
1214  if (rc.mhb())
1215  attack_loc = rc.mhb()->current_unit_attacks_from(highlighted_hex);
1216 
1217  if (!attack_loc.valid())
1218  return unit_weapons(rc, u.get(), u->get_location());
1219 
1220  return unit_weapons(rc, u, attack_loc, sec_u, true);
1221 }
1222 
1223 REPORT_GENERATOR(unit_image,rc)
1224 {
1225  const unit *u = get_visible_unit(rc);
1226  if (!u) return config();
1227  return image_report(u->absolute_image() + u->image_mods());
1228 }
1229 REPORT_GENERATOR(selected_unit_image, rc)
1230 {
1231  const unit *u = get_selected_unit(rc);
1232  if (!u) return config();
1233  return image_report(u->absolute_image() + u->image_mods());
1234 }
1235 
1236 REPORT_GENERATOR(selected_unit_profile, rc)
1237 {
1238  const unit *u = get_selected_unit(rc);
1239  if (!u) return config();
1240  return image_report(u->small_profile());
1241 }
1242 REPORT_GENERATOR(unit_profile, rc)
1243 {
1244  const unit *u = get_visible_unit(rc);
1245  if (!u) return config();
1246  return image_report(u->small_profile());
1247 }
1248 
1249 static config tod_stats_at(const reports::context& rc, const map_location& hex)
1250 {
1251  std::ostringstream tooltip;
1252  std::ostringstream text;
1253 
1254  const map_location& tod_schedule_hex = (hex.valid() && !display::get_singleton()->shrouded(hex)) ? hex : map_location::null_location();
1255  const std::vector<time_of_day>& schedule = rc.tod().times(tod_schedule_hex);
1256 
1257  tooltip << _("Time of day schedule:") << " \n";
1258  int current = rc.tod().get_current_time(tod_schedule_hex);
1259  int i = 0;
1260  for (const time_of_day& tod : schedule) {
1261  if (i == current) tooltip << "<big><b>";
1262  tooltip << tod.name << "\n";
1263  if (i == current) tooltip << "</b></big>";
1264  i++;
1265  }
1266 
1267  int times = schedule.size();
1268  text << current + 1 << "/" << times;
1269 
1270  return text_report(text.str(), tooltip.str(), "..schedule");
1271 }
1272 REPORT_GENERATOR(tod_stats, rc)
1273 {
1274  map_location mouseover_hex = rc.screen().mouseover_hex();
1275  if (mouseover_hex.valid()) return tod_stats_at(rc, mouseover_hex);
1276  return tod_stats_at(rc, rc.screen().selected_hex());
1277 }
1278 REPORT_GENERATOR(selected_tod_stats, rc)
1279 {
1280  const unit *u = get_selected_unit(rc);
1281  if(!u) return tod_stats_at(rc, map_location::null_location());
1282  const map_location& attack_indicator_src = game_display::get_singleton()->get_attack_indicator_src();
1283  const map_location& hex =
1284  attack_indicator_src.valid() ? attack_indicator_src : u->get_location();
1285  return tod_stats_at(rc, hex);
1286 }
1287 
1288 static config time_of_day_at(const reports::context& rc, const map_location& mouseover_hex)
1289 {
1290  std::ostringstream tooltip;
1291  time_of_day tod = get_visible_time_of_day_at(rc, mouseover_hex);
1292 
1293  int b = tod.lawful_bonus;
1294  int l = generic_combat_modifier(b, unit_alignments::type::liminal, false, rc.tod().get_max_liminal_bonus());
1295  std::string lawful_color("white");
1296  std::string chaotic_color("white");
1297  std::string liminal_color("white");
1298 
1299  if (b != 0) {
1300  lawful_color = (b > 0) ? "#0f0" : "#f00";
1301  chaotic_color = (b < 0) ? "#0f0" : "#f00";
1302  }
1303  if (l != 0) {
1304  liminal_color = (l > 0) ? "#0f0" : "#f00";
1305  }
1306  tooltip << _("Time of day:") << " <b>" << tod.name << "</b>\n"
1307  << _("Lawful units: ") << "<span foreground=\"" << lawful_color << "\">"
1308  << utils::signed_percent(b) << "</span>\n"
1309  << _("Neutral units: ") << utils::signed_percent(0) << '\n'
1310  << _("Chaotic units: ") << "<span foreground=\"" << chaotic_color << "\">"
1311  << utils::signed_percent(-b) << "</span>\n"
1312  << _("Liminal units: ") << "<span foreground=\"" << liminal_color << "\">"
1313  << utils::signed_percent(l) << "</span>\n";
1314 
1315  std::string tod_image = tod.image;
1316  if(tod.bonus_modified > 0) {
1317  tod_image += (formatter() << "~BLIT(" << game_config::images::tod_bright << ")").str();
1318  } else if(tod.bonus_modified < 0) {
1319  tod_image += (formatter() << "~BLIT(" << game_config::images::tod_dark << ")").str();
1320  }
1321 
1322  return image_report(tod_image, tooltip.str(), "time_of_day_" + tod.id);
1323 }
1325 {
1326  map_location mouseover_hex = rc.screen().mouseover_hex();
1327  if (mouseover_hex.valid()) return time_of_day_at(rc, mouseover_hex);
1328  return time_of_day_at(rc, rc.screen().selected_hex());
1329 }
1330 REPORT_GENERATOR(selected_time_of_day, rc)
1331 {
1332  const unit *u = get_selected_unit(rc);
1333  if(!u) return time_of_day_at(rc, map_location::null_location());
1334  const map_location& attack_indicator_src = game_display::get_singleton()->get_attack_indicator_src();
1335  const map_location& hex =
1336  attack_indicator_src.valid() ? attack_indicator_src : u->get_location();
1337  return time_of_day_at(rc, hex);
1338 }
1339 
1340 static config unit_box_at(const reports::context& rc, const map_location& mouseover_hex)
1341 {
1342  std::ostringstream tooltip;
1343  time_of_day global_tod = rc.tod().get_time_of_day();
1344  time_of_day local_tod = get_visible_time_of_day_at(rc, mouseover_hex);
1345 
1346  int bonus = local_tod.lawful_bonus;
1347  int l = generic_combat_modifier(bonus, unit_alignments::type::liminal, false, rc.tod().get_max_liminal_bonus());
1348 
1349  std::string lawful_color("white");
1350  std::string chaotic_color("white");
1351  std::string liminal_color("white");
1352 
1353  if (bonus != 0) {
1354  lawful_color = (bonus > 0) ? "green" : "red";
1355  chaotic_color = (bonus < 0) ? "green" : "red";
1356  }
1357  if (l != 0) {
1358  liminal_color = (l > 0) ? "green" : "red";
1359  }
1360  tooltip << local_tod.name << '\n'
1361  << _("Lawful units: ") << "<span foreground=\"" << lawful_color << "\">"
1362  << utils::signed_percent(bonus) << "</span>\n"
1363  << _("Neutral units: ") << utils::signed_percent(0) << '\n'
1364  << _("Chaotic units: ") << "<span foreground=\"" << chaotic_color << "\">"
1365  << utils::signed_percent(-bonus) << "</span>\n"
1366  << _("Liminal units: ") << "<span foreground=\"" << liminal_color << "\">"
1367  << utils::signed_percent(l) << "</span>\n";
1368 
1369  std::string local_tod_image = "themes/classic/" + local_tod.image;
1370  std::string global_tod_image = "themes/classic/" + global_tod.image;
1371  if(local_tod.bonus_modified != 0) {
1372  local_tod_image += "~BLIT(";
1373  if (local_tod.bonus_modified > 0) local_tod_image += game_config::images::tod_bright;
1374  else if (local_tod.bonus_modified < 0) local_tod_image += game_config::images::tod_dark;
1375  local_tod_image += ")";
1376  }
1377 
1378  const gamemap &map = rc.map();
1379  t_translation::terrain_code terrain = map.get_terrain(mouseover_hex);
1380 
1381  //if (t_translation::terrain_matches(terrain, t_translation::ALL_OFF_MAP))
1382  // return config();
1383 
1384  //if (map.is_keep(mouseover_hex)) {
1385  // add_image(cfg, "icons/terrain/terrain_type_keep.png", "");
1386  //}
1387 
1388  const t_translation::ter_list& underlying_terrains = map.underlying_union_terrain(terrain);
1389 
1390  std::string bg_terrain_image;
1391 
1392  for (const t_translation::terrain_code& underlying_terrain : underlying_terrains) {
1393  const std::string& terrain_id = map.get_terrain_info(underlying_terrain).id();
1394  bg_terrain_image = "~BLIT(unit_env/terrain/terrain-" + terrain_id + ".png)" + bg_terrain_image;
1395  }
1396 
1397  std::stringstream color;
1398  color << local_tod.color;
1399 
1400  bg_terrain_image = bg_terrain_image + "~CS(" + color.str() + ")";
1401 
1402  const unit *u = get_visible_unit(rc);
1403  std::string unit_image;
1404  if (u)
1405  unit_image = "~BLIT(" + u->absolute_image() + u->image_mods() + ",35,22)";
1406 
1407  std::string tod_image = global_tod_image + "~BLIT(" + local_tod_image + ")";
1408 
1409  return image_report(tod_image + bg_terrain_image + unit_image, tooltip.str(), "time_of_day");
1410 }
1411 REPORT_GENERATOR(unit_box, rc)
1412 {
1413  map_location mouseover_hex = rc.screen().mouseover_hex();
1414  return unit_box_at(rc, mouseover_hex);
1415 }
1416 
1417 
1419 {
1420  std::ostringstream str, tooltip;
1421  str << rc.tod().turn();
1422  int nb = rc.tod().number_of_turns();
1423  if (nb != -1) str << '/' << nb;
1424 
1425  tooltip << _("Turn Number");
1426  if(nb != -1) {
1427  tooltip << "\n\n" << _("When the game exceeds the number of turns indicated by the second number, it will end.");
1428  }
1429  return text_report(str.str(), tooltip.str());
1430 }
1431 
1433 {
1434  std::ostringstream str;
1435  int viewing_side = rc.screen().viewing_side();
1436  // Suppose the full unit map is applied.
1437  int fake_gold = rc.dc().get_team(viewing_side).gold();
1438 
1439  if (rc.wb())
1440  fake_gold -= rc.wb()->get_spent_gold_for(viewing_side);
1441  char const *end = naps;
1442  if (viewing_side != rc.screen().playing_side()) {
1443  str << span_color(font::GRAY_COLOR);
1444  }
1445  else if (fake_gold < 0) {
1446  str << span_color(font::BAD_COLOR);
1447  }
1448  else {
1449  end = "";
1450  }
1451  str << utils::half_signed_value(fake_gold) << end;
1452  return text_report(str.str(), _("Gold") + "\n\n" + _("The amount of gold currently available to recruit and maintain your army."));
1453 }
1454 
1455 REPORT_GENERATOR(villages, rc)
1456 {
1457  std::ostringstream str;
1458  int viewing_side = rc.screen().viewing_side();
1459  const team &viewing_team = rc.dc().get_team(viewing_side);
1460  str << viewing_team.villages().size() << '/';
1461  if (viewing_team.uses_shroud()) {
1462  int unshrouded_villages = 0;
1463  for (const map_location &loc : rc.map().villages()) {
1464  if (!viewing_team.shrouded(loc))
1465  ++unshrouded_villages;
1466  }
1467  str << unshrouded_villages;
1468  } else {
1469  str << rc.map().villages().size();
1470  }
1471  return gray_inactive(rc,str.str(), _("Villages") + "\n\n" + _("The fraction of known villages that your side has captured."));
1472 }
1473 
1474 REPORT_GENERATOR(num_units, rc)
1475 {
1476  return gray_inactive(rc, std::to_string(rc.dc().side_units(rc.screen().viewing_side())), _("Units") + "\n\n" + _("The total number of units on your side."));
1477 }
1478 
1479 REPORT_GENERATOR(upkeep, rc)
1480 {
1481  std::ostringstream str;
1482  int viewing_side = rc.screen().viewing_side();
1483  const team &viewing_team = rc.dc().get_team(viewing_side);
1484  team_data td(rc.dc(), viewing_team);
1485  str << td.expenses << " (" << td.upkeep << ")";
1486  return gray_inactive(rc,str.str(), _("Upkeep") + "\n\n" + _("The expenses incurred at the end of every turn to maintain your army. The first number is the amount of gold that will be deducted. It is equal to the number of unit levels not supported by villages. The second is the total cost of upkeep, including that covered by villages — in other words, the amount of gold that would be deducted if you lost all villages."));
1487 }
1488 
1489 REPORT_GENERATOR(expenses, rc)
1490 {
1491  int viewing_side = rc.screen().viewing_side();
1492  const team &viewing_team = rc.dc().get_team(viewing_side);
1493  team_data td(rc.dc(), viewing_team);
1494  return gray_inactive(rc,std::to_string(td.expenses));
1495 }
1496 
1497 REPORT_GENERATOR(income, rc)
1498 {
1499  std::ostringstream str;
1500  int viewing_side = rc.screen().viewing_side();
1501  const team &viewing_team = rc.dc().get_team(viewing_side);
1502  team_data td(rc.dc(), viewing_team);
1503  char const *end = naps;
1504  if (viewing_side != rc.screen().playing_side()) {
1505  if (td.net_income < 0) {
1506  td.net_income = - td.net_income;
1507  str << span_color(font::GRAY_COLOR);
1508  str << font::unicode_minus;
1509  }
1510  else {
1511  str << span_color(font::GRAY_COLOR);
1512  }
1513  }
1514  else if (td.net_income < 0) {
1515  td.net_income = - td.net_income;
1516  str << span_color(font::BAD_COLOR);
1517  str << font::unicode_minus;
1518  }
1519  else {
1520  end = "";
1521  }
1522  str << td.net_income << end;
1523  return text_report(str.str(), _("Net Income") + "\n\n" + _("The net amount of gold you gain or lose each turn, taking into account income from controlled villages and payment of upkeep."));
1524 }
1525 
1526 namespace {
1527 void blit_tced_icon(config &cfg, const std::string &terrain_id, const std::string &icon_image, bool high_res,
1528  const std::string &terrain_name) {
1529  const std::string tc_base = high_res ? "images/buttons/icon-base-32.png" : "images/buttons/icon-base-16.png";
1530  const std::string terrain_image = "terrain/" + icon_image + (high_res ? "_30.png" : ".png");
1531  add_image(cfg, tc_base + "~RC(magenta>" + terrain_id + ")~BLIT(" + terrain_image + ")", terrain_name);
1532 }
1533 }
1534 
1535 REPORT_GENERATOR(terrain_info, rc)
1536 {
1537  const gamemap &map = rc.map();
1538  map_location mouseover_hex = rc.screen().mouseover_hex();
1539 
1540  if (!map.on_board(mouseover_hex))
1541  mouseover_hex = rc.screen().selected_hex();
1542 
1543  if (!map.on_board(mouseover_hex))
1544  return config();
1545 
1546  t_translation::terrain_code terrain = map.get_terrain(mouseover_hex);
1548  return config();
1549 
1550  config cfg;
1551 
1552  bool high_res = false;
1553 
1554  if (display::get_singleton()->shrouded(mouseover_hex)) {
1555  return cfg;
1556  }
1557  //TODO
1558 // if (display::get_singleton()->fogged(mouseover_hex)) {
1559 // blit_tced_icon(cfg, "fog", high_res);
1560 // }
1561 //
1562 // if (map.is_keep(mouseover_hex)) {
1563 // blit_tced_icon(cfg, "keep", high_res);
1564 // }
1565 
1566  const t_translation::ter_list& underlying_terrains = map.underlying_union_terrain(terrain);
1567  for (const t_translation::terrain_code& underlying_terrain : underlying_terrains) {
1568 
1570  continue;
1571  const std::string& terrain_id = map.get_terrain_info(underlying_terrain).id();
1572  const std::string& terrain_name = map.get_terrain_string(underlying_terrain);
1573  const std::string& terrain_icon = map.get_terrain_info(underlying_terrain).icon_image();
1574  if (terrain_icon.empty())
1575  continue;
1576  blit_tced_icon(cfg, terrain_id, terrain_icon, high_res, terrain_name);
1577  }
1578  return cfg;
1579 }
1580 
1581 REPORT_GENERATOR(terrain, rc)
1582 {
1583  const gamemap &map = rc.map();
1584  int viewing_side = rc.screen().viewing_side();
1585  const team &viewing_team = rc.dc().get_team(viewing_side);
1586  map_location mouseover_hex = rc.screen().mouseover_hex();
1587  if (!map.on_board(mouseover_hex) || viewing_team.shrouded(mouseover_hex))
1588  return config();
1589 
1590  t_translation::terrain_code terrain = map.get_terrain(mouseover_hex);
1592  return config();
1593 
1594  std::ostringstream str;
1595  if (map.is_village(mouseover_hex))
1596  {
1597  int owner = rc.dc().village_owner(mouseover_hex);
1598  if (owner == 0 || viewing_team.fogged(mouseover_hex)) {
1599  str << map.get_terrain_info(terrain).income_description();
1600  } else if (owner == viewing_side) {
1601  str << map.get_terrain_info(terrain).income_description_own();
1602  } else if (viewing_team.is_enemy(owner)) {
1603  str << map.get_terrain_info(terrain).income_description_enemy();
1604  } else {
1605  str << map.get_terrain_info(terrain).income_description_ally();
1606  }
1607 
1608  const std::string& underlying_desc = map.get_underlying_terrain_string(terrain);
1609  if(!underlying_desc.empty()) {
1610  str << underlying_desc;
1611  }
1612  } else {
1613  str << map.get_terrain_string(terrain);
1614  }
1615 
1616  return text_report(str.str());
1617 }
1618 
1619 REPORT_GENERATOR(zoom_level, rc)
1620 {
1621  std::ostringstream text;
1622  std::ostringstream tooltip;
1623  std::ostringstream help;
1624 
1625  text << static_cast<int>(rc.screen().get_zoom_factor() * 100) << "%";
1626 
1627  return text_report(text.str(), tooltip.str(), help.str());
1628 }
1629 
1630 REPORT_GENERATOR(position, rc)
1631 {
1632  const gamemap &map = rc.map();
1633  map_location mouseover_hex = rc.screen().mouseover_hex(),
1634  displayed_unit_hex = rc.screen().displayed_unit_hex(),
1635  selected_hex = rc.screen().selected_hex();
1636 
1637  if (!map.on_board(mouseover_hex)) {
1638  if (!map.on_board(selected_hex))
1639  return config();
1640  else {
1641  mouseover_hex = selected_hex;
1642  }
1643  }
1644 
1645  t_translation::terrain_code terrain = map[mouseover_hex];
1647  return config();
1648 
1649  std::ostringstream str;
1650  str << mouseover_hex;
1651 
1652  const unit *u = get_visible_unit(rc);
1653  const team &viewing_team = rc.teams()[rc.screen().viewing_team()];
1654  if (!u ||
1655  (displayed_unit_hex != mouseover_hex &&
1656  displayed_unit_hex != rc.screen().selected_hex()) ||
1657  viewing_team.shrouded(mouseover_hex))
1658  return text_report(str.str());
1659 
1660  int move_cost = u->movement_cost(terrain);
1661  int defense = 100 - u->defense_modifier(terrain);
1662  if (move_cost < movetype::UNREACHABLE) {
1663  str << " " << defense << "%," << move_cost;
1664  } else if (mouseover_hex == displayed_unit_hex) {
1665  str << " " << defense << "%,‒";
1666  } else {
1667  str << " ‒";
1668  }
1669  return text_report(str.str());
1670 }
1671 
1672 REPORT_GENERATOR(side_playing, rc)
1673 {
1674  const team &active_team = rc.teams()[rc.screen().playing_team()];
1675  std::string flag_icon = active_team.flag_icon();
1676  std::string old_rgb = game_config::flag_rgb;
1677  std::string new_rgb = team::get_side_color_id(rc.screen().playing_side());
1678  std::string mods = "~RC(" + old_rgb + ">" + new_rgb + ")";
1679  if (flag_icon.empty())
1681  return image_report(flag_icon + mods, side_tooltip(active_team));
1682 }
1683 
1684 REPORT_GENERATOR(observers, rc)
1685 {
1686  const std::set<std::string> &observers = rc.screen().observers();
1687  if (observers.empty())
1688  return config();
1689 
1690  std::ostringstream str;
1691  str << _("Observers:") << '\n';
1692  for (const std::string &obs : observers) {
1693  str << obs << '\n';
1694  }
1695  return image_report(game_config::images::observer, str.str());
1696 }
1697 
1698 /* TODO unused
1699 REPORT_GENERATOR(selected_terrain)
1700 {
1701  const std::string selected_terrain = editor::get_selected_terrain();
1702  if (selected_terrain.empty())
1703  return config();
1704  else
1705  return text_report(selected_terrain);
1706 }
1707 */
1708 
1709 /* TODO this is unused
1710 REPORT_GENERATOR(edit_left_button_function)
1711 {
1712  const std::string left_button_function = editor::get_left_button_function();
1713  if (left_button_function.empty())
1714  return config();
1715  else
1716  return text_report(left_button_function);
1717 }
1718 */
1719 
1720 REPORT_GENERATOR(report_clock, /*rc*/)
1721 {
1722  config report;
1724 
1725  std::ostringstream ss;
1726 
1728  ? "%I:%M %p"
1729  : "%H:%M";
1730 
1731  std::time_t t = std::time(nullptr);
1732  ss << std::put_time(std::localtime(&t), format);
1733  add_text(report, ss.str(), _("Clock"));
1734 
1735  return report;
1736 }
1737 
1738 
1739 REPORT_GENERATOR(battery, /*rc*/)
1740 {
1741  config report;
1742 
1744  add_text(report, (boost::format("%.0f %%") % desktop::battery_info::get_battery_percentage()).str(), _("Battery"));
1745 
1746  return report;
1747 }
1748 
1749 REPORT_GENERATOR(report_countdown, rc)
1750 {
1751  int viewing_side = rc.screen().viewing_side();
1752  const team &viewing_team = rc.dc().get_team(viewing_side);
1753  int min, sec;
1754  if (viewing_team.countdown_time() == 0)
1755  return report_report_clock(rc);
1756  std::ostringstream str;
1757  sec = viewing_team.countdown_time() / 1000;
1758  char const *end = naps;
1759  if (viewing_side != rc.screen().playing_side())
1760  str << span_color(font::GRAY_COLOR);
1761  else if (sec < 60)
1762  str << "<span foreground=\"#c80000\">";
1763  else if (sec < 120)
1764  str << "<span foreground=\"#c8c800\">";
1765  else
1766  end = "";
1767  min = sec / 60;
1768  str << min << ':';
1769  sec = sec % 60;
1770  if (sec < 10) str << '0';
1771  str << sec << end;
1772 
1773  config report;
1775  add_text(report, str.str(), _("Turn Countdown") + "\n\n" + _("Countdown until your turn automatically ends."));
1776 
1777  return report;
1778 }
1779 
1780 void reports::register_generator(const std::string &name, reports::generator *g)
1781 {
1782  dynamic_generators_[name].reset(g);
1783 }
1784 
1785 config reports::generate_report(const std::string &name, const reports::context& rc, bool only_static)
1786 {
1787  if (!only_static) {
1788  dynamic_report_generators::const_iterator i = dynamic_generators_.find(name);
1789  if (i != dynamic_generators_.end())
1790  return i->second->generate(rc);
1791  }
1792  static_report_generators::const_iterator j = static_generators.find(name);
1793  if (j != static_generators.end())
1794  return j->second(rc);
1795  return config();
1796 }
1797 
1798 const std::set<std::string> &reports::report_list()
1799 {
1800  if (!all_reports_.empty()) return all_reports_;
1801  for (const static_report_generators::value_type &v : static_generators) {
1802  all_reports_.insert(v.first);
1803  }
1804  for (const dynamic_report_generators::value_type &v : dynamic_generators_) {
1805  all_reports_.insert(v.first);
1806  }
1807  return all_reports_;
1808 }
int under_leadership(const unit &u, const map_location &loc, const_attack_ptr weapon, const_attack_ptr opp_weapon)
Tests if the unit at loc is currently affected by leadership.
Definition: attack.cpp:1579
int generic_combat_modifier(int lawful_bonus, unit_alignments::type alignment, bool is_fearless, int max_liminal_bonus)
Returns the amount that a unit's damage should be multiplied by due to a given lawful_bonus.
Definition: attack.cpp:1606
int combat_modifier(const unit_map &units, const gamemap &map, const map_location &loc, unit_alignments::type alignment, bool is_fearless)
Returns the amount that a unit's damage should be multiplied by due to the current time of day.
Definition: attack.cpp:1586
Various functions that implement attacks and attack calculations.
unsigned swarm_blows(unsigned min_blows, unsigned max_blows, unsigned hp, unsigned max_hp)
Calculates the number of blows resulting from swarm.
Definition: attack.hpp:41
double t
Definition: astarsearch.cpp:65
double g
Definition: astarsearch.cpp:65
Computes the statistics of a battle between an attacker and a defender unit.
Definition: attack.hpp:168
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:161
config & add_child(config_key_type key)
Definition: config.cpp:445
const team & get_team(int side) const
This getter takes a 1-based side number, not a 0-based team number.
const unit * get_visible_unit(const map_location &loc, const team &current_team, bool see_all=false) const
unit_const_ptr get_visible_unit_shared_ptr(const map_location &loc, const team &current_team, bool see_all=false) const
int viewing_side() const
The 1-based equivalent of the 0-based viewing_team() function.
Definition: display.hpp:130
std::size_t viewing_team() const
The viewing team is the team currently viewing the game.
Definition: display.hpp:122
virtual int playing_side() const
Definition: display.hpp:219
virtual const map_location & displayed_unit_hex() const
Virtual functions shadowed in game_display.
Definition: display.hpp:218
const map_location & selected_hex() const
Definition: display.hpp:306
bool show_everything() const
Definition: display.hpp:103
static display * get_singleton()
Returns the display object if a display object exists.
Definition: display.hpp:101
bool shrouded(const map_location &loc) const
Returns true if location (x,y) is covered in shroud.
Definition: display.cpp:702
std::ostringstream wrapper.
Definition: formatter.hpp:40
const map_location & get_attack_indicator_src()
const pathfind::marked_route & get_route()
Gets the route along which footsteps are drawn to show movement of a unit.
static game_display * get_singleton()
terrain_code get_terrain(const map_location &loc) const
Looks up terrain at a particular location.
Definition: map.cpp:302
bool on_board(const map_location &loc) const
Tell if a location is on the map.
Definition: map.cpp:385
Encapsulates the map of the game.
Definition: map.hpp:172
const t_translation::ter_list & underlying_union_terrain(const map_location &loc) const
Definition: map.cpp:59
bool is_village(const map_location &loc) const
Definition: map.cpp:66
std::string get_underlying_terrain_string(const t_translation::terrain_code &terrain) const
Definition: map.cpp:87
const t_translation::ter_list & underlying_def_terrain(const map_location &loc) const
Definition: map.cpp:57
std::string get_terrain_string(const map_location &loc) const
Definition: map.cpp:61
const terrain_type & get_terrain_info(const t_translation::terrain_code &terrain) const
Definition: map.cpp:98
Generic locator abstracting the location of an image.
Definition: picture.hpp:64
bool file_exists() const
Tests whether the file the locator points at exists.
Definition: picture.cpp:577
static const int UNREACHABLE
Magic value that signifies a hex is unreachable.
Definition: movetype.hpp:176
const display_context & dc() const
Definition: reports.hpp:55
const std::vector< team > & teams() const
Definition: reports.hpp:51
const unit_map & units() const
Definition: reports.hpp:52
const tod_manager & tod() const
Definition: reports.hpp:57
const gamemap & map() const
Definition: reports.hpp:53
const display & screen() const
Definition: reports.hpp:56
config generate_report(const std::string &name, const context &ct, bool only_static=false)
Definition: reports.cpp:1785
void register_generator(const std::string &name, generator *)
Definition: reports.cpp:1780
std::set< std::string > all_reports_
Definition: reports.hpp:87
const std::set< std::string > & report_list()
Definition: reports.cpp:1798
std::function< config(const reports::context &)> generator_function
Definition: reports.hpp:81
dynamic_report_generators dynamic_generators_
Definition: reports.hpp:89
std::string base_str() const
Definition: tstring.hpp:195
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:76
bool uses_shroud() const
Definition: team.hpp:305
const std::string & color() const
Definition: team.hpp:244
const std::string & side_name() const
Definition: team.hpp:295
int side() const
Definition: team.hpp:176
bool is_enemy(int n) const
Definition: team.hpp:231
const std::set< map_location > & villages() const
Definition: team.hpp:172
static const t_string get_side_color_name_for_UI(unsigned side)
Definition: team.cpp:996
static std::string get_side_color_id(unsigned side)
Definition: team.cpp:969
bool shrouded(const map_location &loc) const
Definition: team.cpp:648
const std::string & flag_icon() const
Definition: team.hpp:289
int countdown_time() const
Definition: team.hpp:198
bool fogged(const map_location &loc) const
Definition: team.cpp:657
const t_string & income_description_enemy() const
Definition: terrain.hpp:149
const std::string & icon_image() const
Definition: terrain.hpp:44
const t_string & income_description() const
Definition: terrain.hpp:147
const t_string & income_description_ally() const
Definition: terrain.hpp:148
const std::string & id() const
Definition: terrain.hpp:52
const t_string & description() const
Definition: terrain.hpp:50
const t_string & income_description_own() const
Definition: terrain.hpp:150
int get_max_liminal_bonus() const
const time_of_day get_illuminated_time_of_day(const unit_map &units, const gamemap &map, const map_location &loc, int for_turn=0) const
Returns time of day object for the passed turn at a location.
const std::vector< time_of_day > & times(const map_location &loc=map_location::null_location()) const
int get_current_time(const map_location &loc=map_location::null_location()) const
const time_of_day & get_time_of_day(int for_turn=0) const
Returns global time of day for the passed turn.
Definition: tod_manager.hpp:56
const std::string & id() const
Definition: race.hpp:35
const t_string & name(GENDER gender=MALE) const
Definition: race.hpp:37
A single unit type that the player may recruit.
Definition: types.hpp:46
static std::string alignment_description(unit_alignments::type align, unit_race::GENDER gender=unit_race::MALE)
Implementation detail of unit_type::alignment_description.
Definition: types.cpp:839
bool show_variations_in_help() const
Whether the unit type has at least one help-visible variation.
Definition: types.cpp:762
This class represents a single unit of a specific type.
Definition: unit.hpp:134
#define VGETTEXT(msgid,...)
Handy wrappers around interpolate_variables_into_string and gettext.
std::size_t i
Definition: function.cpp:968
static std::string _n(const char *str1, const char *str2, int n)
Definition: gettext.hpp:97
#define N_(String)
Definition: gettext.hpp:101
static std::string _(const char *str)
Definition: gettext.hpp:93
std::vector< std::tuple< std::string, t_string, t_string, t_string > > ability_tooltips() const
Gets the names and descriptions of this unit's abilities.
Definition: abilities.cpp:326
bool invisible(const map_location &loc, bool see_all=true) const
Definition: unit.cpp:2640
int max_hitpoints() const
The max number of hitpoints this unit can have.
Definition: unit.hpp:506
unit_alignments::type alignment() const
The alignment of this unit.
Definition: unit.hpp:476
int level() const
The current level of this unit.
Definition: unit.hpp:560
const t_string & type_name() const
Gets the translatable name of this unit's type.
Definition: unit.hpp:370
int hitpoints() const
The current number of hitpoints this unit has.
Definition: unit.hpp:500
bool get_state(const std::string &state) const
Check if the unit is affected by a status effect.
Definition: unit.cpp:1327
std::string small_profile() const
An optional profile image to display in Help.
Definition: unit.cpp:1037
const std::string & type_id() const
The id of this unit's type.
Definition: unit.cpp:1979
const unit_race * race() const
Gets this unit's race.
Definition: unit.hpp:494
const unit_type & type() const
This unit's type, accounting for gender and variation.
Definition: unit.hpp:356
int experience() const
The current number of experience points this unit has.
Definition: unit.hpp:524
const std::string & id() const
Gets this unit's id.
Definition: unit.hpp:381
int side() const
The side this unit belongs to.
Definition: unit.hpp:344
std::vector< t_string > unit_special_notes() const
The unit's special notes.
Definition: unit.cpp:2884
int max_experience() const
The max number of experience points this unit can have.
Definition: unit.hpp:530
unit_race::GENDER gender() const
The gender of this unit.
Definition: unit.hpp:466
const t_string & name() const
Gets this unit's translatable display name.
Definition: unit.hpp:404
t_string unit_description() const
A detailed description of this unit.
Definition: unit.hpp:451
@ STATE_SLOWED
Definition: unit.hpp:861
@ STATE_INVULNERABLE
The unit is a guardian - it won't move unless a target is sighted.
Definition: unit.hpp:868
@ STATE_PETRIFIED
The unit is poisoned - it loses health each turn.
Definition: unit.hpp:863
@ STATE_UNHEALABLE
The unit has not moved.
Definition: unit.hpp:866
@ STATE_POISONED
The unit is slowed - it moves slower and does less damage.
Definition: unit.hpp:862
std::vector< std::pair< std::string, std::string > > amla_icons() const
Gets the image and description data for modification advancements.
Definition: unit.cpp:1891
bool can_advance() const
Checks whether this unit has any options to advance to.
Definition: unit.hpp:273
std::map< std::string, std::string > advancement_icons() const
Gets and image path and and associated description for each advancement option.
Definition: unit.cpp:1851
int defense_modifier(const t_translation::terrain_code &terrain) const
The unit's defense on a given terrain.
Definition: unit.cpp:1787
attack_itors attacks()
Gets an iterator over this unit's attacks.
Definition: unit.hpp:928
utils::string_map_res get_base_resistances() const
Gets resistances without any abilities applied.
Definition: unit.hpp:1050
int max_attacks() const
The maximum number of attacks this unit may perform per turn, usually 1.
Definition: unit.hpp:979
int resistance_against(const std::string &damage_name, bool attacker, const map_location &loc, const_attack_ptr weapon=nullptr, const_attack_ptr opp_weapon=nullptr) const
The unit's resistance against a given damage type.
Definition: unit.cpp:1830
int attacks_left() const
Gets the remaining number of attacks this unit can perform this turn.
Definition: unit.hpp:995
color_t xp_color() const
Color for this unit's XP.
Definition: unit.cpp:1152
color_t hp_color() const
Color for this unit's current hitpoints.
Definition: unit.cpp:1098
std::string image_mods() const
Gets an IPF string containing all IPF image mods.
Definition: unit.cpp:2798
std::string absolute_image() const
The name of the file to game_display (used in menus).
Definition: unit.cpp:2617
int jamming() const
Gets the unit's jamming points.
Definition: unit.hpp:1407
const map_location & get_location() const
The current map location this unit is at.
Definition: unit.hpp:1358
int movement_cost(const t_translation::terrain_code &terrain) const
Get the unit's movement cost on a particular terrain.
Definition: unit.hpp:1441
int movement_left() const
Gets how far a unit can move, considering the incapacitated flag.
Definition: unit.hpp:1283
int total_movement() const
The maximum moves this unit has.
Definition: unit.hpp:1267
int vision() const
Gets the unit's vision points.
Definition: unit.hpp:1401
bool is_fearless() const
Gets whether this unit is fearless - ie, unaffected by time of day.
Definition: unit.hpp:1248
std::vector< std::string > get_traits_list() const
Gets a list of the traits this unit currently has.
Definition: unit.cpp:872
const std::vector< t_string > & trait_descriptions() const
Gets the descriptions of the currently registered traits.
Definition: unit.hpp:1094
const std::vector< t_string > & trait_names() const
Gets the names of the currently registered traits.
Definition: unit.hpp:1084
std::string tooltip
Shown when hovering over an entry in the filter's drop-down list.
Definition: manager.cpp:219
std::string id
Text to match against addon_info.tags()
Definition: manager.cpp:215
symbol_table string_table
Definition: language.cpp:65
constexpr int round_damage(int base_damage, int bonus, int divisor)
round (base_damage * bonus / divisor) to the closest integer, but up or down towards base_damage
Definition: math.hpp:80
double get_battery_percentage()
void line(int from_x, int from_y, int to_x, int to_y)
Draw a line.
Definition: draw.cpp:171
std::string base_name(const std::string &file, const bool remove_extension)
Returns the base filename of a file, with directory name stripped.
const std::string weapon_details_sep
Definition: constants.cpp:50
const color_t inactive_details_color
const color_t inactive_ability_color
const color_t BAD_COLOR
std::string escape_text(const std::string &text)
Escapes the pango markup characters in a text.
Definition: escape.hpp:33
const color_t GRAY_COLOR
const std::string unicode_bullet
Definition: constants.cpp:47
const color_t weapon_details_color
const color_t good_dmg_color
const std::string unicode_en_dash
Definition: constants.cpp:43
std::string span_color(const color_t &color)
Returns a Pango formatting string using the provided color_t object.
const color_t weapon_color
const std::string unicode_figure_dash
Definition: constants.cpp:45
const std::string weapon_numbers_sep
Definition: constants.cpp:49
const std::string unicode_minus
Definition: constants.cpp:42
const color_t bad_dmg_color
std::string tod_bright
std::string time_icon
std::string observer
std::string flag_icon
std::string battery_icon
std::string tod_dark
std::string path
Definition: filesystem.cpp:83
std::string flag_rgb
color_t blue_to_white(double val, bool for_text)
const bool & debug
Definition: game_config.cpp:91
color_t red_to_green(double val, bool for_text)
Return a color corresponding to the value val red for val=0.0 to green for val=100....
Definition: help.cpp:57
Functions to load and save images from/to disk.
logger & info()
Definition: log.cpp:232
bool use_twelve_hour_clock_format()
Definition: general.cpp:974
std::set< t_translation::terrain_code > & encountered_terrains()
Definition: game.cpp:921
static std::string at(const std::string &file, int line)
const terrain_code VOID_TERRAIN
VOID_TERRAIN is used for shrouded hexes.
const terrain_code MINUS
bool terrain_matches(const terrain_code &src, const terrain_code &dest)
Tests whether a specific terrain matches an expression, for matching rules see above.
std::vector< terrain_code > ter_list
Definition: translation.hpp:77
const ter_match ALL_OFF_MAP
const terrain_code PLUS
const terrain_code FOGGED
static std::string gettext(const char *str)
Definition: gettext.hpp:60
static std::string unit_level_tooltip(const int level, const std::vector< std::string > &adv_to_types, const std::vector< config > &adv_to_mods)
Definition: helper.cpp:56
std::string resistance_color(const int resistance)
Maps resistance <= -60 (resistance value <= -60%) to intense red.
Definition: helper.cpp:50
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:87
std::string half_signed_value(int val)
Sign with Unicode "−" if negative.
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
std::string signed_value(int val)
Convert into a signed value (using the Unicode "−" and +0 convention.
std::string signed_percent(int val)
Convert into a percentage (using the Unicode "−" and +0% convention.
@ enemy
Belongs to a non-friendly side; normally visualised by not displaying an orb.
This module contains various pathfinding functions and utilities.
std::shared_ptr< const unit > unit_const_ptr
Definition: ptr.hpp:27
std::shared_ptr< const attack_type > const_attack_ptr
Definition: ptr.hpp:34
static config unit_name(const unit *u)
Definition: reports.cpp:161
static config image_report(const std::string &image, const std::string &tooltip="", const std::string &help="")
Definition: reports.cpp:75
static std::string flush(std::ostringstream &s)
Definition: reports.cpp:93
static void add_image(config &report, const std::string &image, const std::string &tooltip, const std::string &help="")
Definition: reports.cpp:58
static config unit_hp(const reports::context &rc, const unit *u)
Definition: reports.cpp:477
static int attack_info(const reports::context &rc, const attack_type &at, config &res, const unit &u, const map_location &hex, const unit *sec_u=nullptr, const_attack_ptr sec_u_weapon=nullptr)
Definition: reports.cpp:777
static config unit_type(const unit *u)
Definition: reports.cpp:189
static std::string side_tooltip(const team &team)
Definition: reports.cpp:235
static const unit * get_visible_unit(const reports::context &rc)
Definition: reports.cpp:132
static config tod_stats_at(const reports::context &rc, const map_location &hex)
Definition: reports.cpp:1249
static unit_const_ptr get_selected_unit_ptr(const reports::context &rc)
Definition: reports.cpp:146
std::map< std::string, reports::generator_function > static_report_generators
Definition: reports.cpp:114
static config unit_side(const reports::context &rc, const unit *u)
Definition: reports.cpp:245
static config unit_defense(const reports::context &rc, const unit *u, const map_location &displayed_unit_hex)
Definition: reports.cpp:577
static std::string format_prob(double prob)
Definition: reports.cpp:1006
static config unit_status(const reports::context &rc, const unit *u)
Definition: reports.cpp:335
static config gray_inactive(const reports::context &rc, const std::string &str, const std::string &tooltip="")
Definition: reports.cpp:153
static static_report_generators static_generators
Definition: reports.cpp:115
static config unit_level(const unit *u)
Definition: reports.cpp:277
static config unit_vision(const unit *u)
Definition: reports.cpp:643
static const color_t attack_info_percent_color(int resistance)
Maps resistance <= -60 (resistance value <= -60%) to intense red.
Definition: reports.cpp:771
static config unit_traits(const unit *u)
Definition: reports.cpp:305
static config unit_weapons(const reports::context &rc, unit_const_ptr attacker, const map_location &attacker_pos, const unit *defender, bool show_attacker)
Definition: reports.cpp:1025
static void add_status(config &r, char const *path, char const *desc1, char const *desc2)
Definition: reports.cpp:85
static config unit_box_at(const reports::context &rc, const map_location &mouseover_hex)
Definition: reports.cpp:1340
static const time_of_day get_visible_time_of_day_at(const reports::context &rc, const map_location &hex)
Definition: reports.cpp:100
static config unit_race(const unit *u)
Definition: reports.cpp:216
static void add_text(config &report, const std::string &text, const std::string &tooltip, const std::string &help="")
Definition: reports.cpp:49
static config unit_abilities(const unit *u, const map_location &loc)
Definition: reports.cpp:415
static config time_of_day_at(const reports::context &rc, const map_location &mouseover_hex)
Definition: reports.cpp:1288
#define REPORT_GENERATOR(n, cn)
Definition: reports.cpp:125
static config text_report(const std::string &text, const std::string &tooltip="", const std::string &help="")
Definition: reports.cpp:67
static config unit_moves(const reports::context &rc, const unit *u, bool is_visible_unit)
Definition: reports.cpp:671
static config unit_alignment(const reports::context &rc, const unit *u, const map_location &hex)
Definition: reports.cpp:377
static const unit * get_selected_unit(const reports::context &rc)
Definition: reports.cpp:139
static char const * naps
Definition: reports.cpp:130
static std::string format_hp(unsigned hp)
Definition: reports.cpp:1018
static config unit_advancement_options(const unit *u)
Definition: reports.cpp:557
static config unit_xp(const unit *u)
Definition: reports.cpp:530
Structure describing the statistics of a unit involved in the battle.
Definition: attack.hpp:52
unsigned int num_blows
Effective number of blows, takes swarm into account.
Definition: attack.hpp:77
const_attack_ptr weapon
The weapon used by the unit to attack the opponent, or nullptr if there is none.
Definition: attack.hpp:53
int damage
Effective damage of the weapon (all factors accounted for).
Definition: attack.hpp:73
unsigned int chance_to_hit
Effective chance to hit as a percentage (all factors accounted for).
Definition: attack.hpp:72
The basic class for representing 8-bit RGB or RGBA colour values.
Definition: color.hpp:59
std::string to_hex_string() const
Returns the stored color in rrggbb hex format.
Definition: color.cpp:78
All combat-related info.
void fight(combatant &opponent, bool levelup_considered=true)
Simulate a fight! Can be called multiple times for cumulative calculations.
Encapsulates the map of the game.
Definition: location.hpp:38
bool valid() const
Definition: location.hpp:89
static const map_location & null_location()
Definition: location.hpp:81
Structure which holds a single route and marks for special events.
Definition: pathfind.hpp:142
std::vector< map_location > & steps
Definition: pathfind.hpp:187
report_generator_helper(const char *name, reports::generator_function g)
Definition: reports.cpp:119
static std::string get_string(enum_type key)
Converts a enum to its string equivalent.
Definition: enum_base.hpp:46
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
Definition: translation.hpp:49
Object which defines a time of day with associated bonuses, image, sounds etc.
Definition: time_of_day.hpp:57
int bonus_modified
Definition: time_of_day.hpp:84
std::string id
Definition: time_of_day.hpp:90
tod_color color
The color modifications that should be made to the game board to reflect the time of day.
int lawful_bonus
The % bonus lawful units receive.
Definition: time_of_day.hpp:83
t_string name
Definition: time_of_day.hpp:88
std::string image
The image to be displayed in the game status.
Definition: time_of_day.hpp:87
static int get_acceleration()
Definition: types.cpp:572
mock_char c
static map_location::DIRECTION s
#define b