The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
game_display.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by David White <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 /**
16  * @file
17  * During a game, show map & info-panels at top+right.
18  */
19 
20 #include "global.hpp"
21 #include "game_display.hpp"
22 
23 #include "gettext.hpp"
24 #include "wesconfig.h"
25 
26 #include "cursor.hpp"
27 #include "display_chat_manager.hpp"
28 #include "fake_unit_manager.hpp"
29 #include "fake_unit_ptr.hpp"
30 #include "floating_label.hpp"
31 #include "game_board.hpp"
32 #include "game_preferences.hpp"
33 #include "halo.hpp"
34 #include "log.hpp"
35 #include "map/map.hpp"
36 #include "map/label.hpp"
37 #include "marked-up_text.hpp"
38 #include "reports.hpp"
39 #include "resources.hpp"
40 #include "tod_manager.hpp"
41 #include "sound.hpp"
42 #include "synced_context.hpp"
43 #include "terrain/type_data.hpp"
44 #include "units/unit.hpp"
45 #include "units/drawer.hpp"
46 #include "whiteboard/manager.hpp"
47 
48 #include <boost/make_shared.hpp>
49 
50 static lg::log_domain log_display("display");
51 #define ERR_DP LOG_STREAM(err, log_display)
52 #define LOG_DP LOG_STREAM(info, log_display)
53 
54 static lg::log_domain log_engine("engine");
55 #define ERR_NG LOG_STREAM(err, log_engine)
56 
57 std::map<map_location,fixed_t> game_display::debugHighlights_;
58 
59 /**
60  * Function to return 2 half-hex footsteps images for the given location.
61  * Only loc is on the current route set by set_route.
62  *
63  * This function is only used internally by game_display so I have moved it out of the header into the compilaton unit.
64  */
65 #ifdef SDL_GPU
66 std::vector<sdl::timage> footsteps_images(const map_location& loc, const pathfind::marked_route & route_, const display_context * dc_);
67 #else
68 std::vector<surface> footsteps_images(const map_location& loc, const pathfind::marked_route & route_, const display_context * dc_);
69 #endif
70 
71 game_display::game_display(game_board& board, CVideo& video, boost::weak_ptr<wb::manager> wb,
72  reports & reports_object,
73  const tod_manager& tod,
74  const config& theme_cfg,
75  const config& level,
76  bool) :
77  display(&board, video, wb, reports_object, theme_cfg, level, false),
78  overlay_map_(),
79  attack_indicator_src_(),
80  attack_indicator_dst_(),
81  route_(),
82  tod_manager_(&tod),
83  displayedUnitHex_(),
84  sidebarScaling_(1.0),
85  first_turn_(true),
86  in_game_(false),
87  chat_man_(new display_chat_manager(*this)),
88  game_mode_(RUNNING),
89  needs_rebuild_(false)
90 {
92  clear_screen();
93 }
94 
96 {
97  static config dummy_cfg;
98  static config dummy_cfg2;
99  static game_board dummy_board(boost::make_shared<terrain_type_data>(dummy_cfg), dummy_cfg2);
100  static tod_manager dummy_tod(dummy_cfg);
101  static reports rep_;
102  return new game_display(dummy_board, video, boost::shared_ptr<wb::manager>(), rep_, dummy_tod,
103  dummy_cfg, dummy_cfg, true);
104 }
105 
107 {
108  try {
109  // SDL_FreeSurface(minimap_);
110  chat_man_->prune_chat_messages(true);
111  } catch (...) {}
112 }
113 
114 //TODO: proper SDL_gpu implementation
116 {
117  const time_of_day& tod = tod_manager_->get_time_of_day();
118 
119  if( !first_turn_) {
121 
122  if(old_tod.image_mask != tod.image_mask) {
123  const surface old_mask(image::get_image(old_tod.image_mask,image::SCALED_TO_HEX));
125 
126  const int niterations = static_cast<int>(10/turbo_speed());
127  const int frame_time = 30;
128  const int starting_ticks = SDL_GetTicks();
129  for(int i = 0; i != niterations; ++i) {
130 
131 #ifdef SDL_GPU
132  if(old_mask != nullptr) {
133  const fixed_t proportion = ftofxp(1.0) - fxpdiv(i,niterations);
134  tod_hex_mask1 = sdl::timage(adjust_surface_alpha(old_mask,proportion));
135  }
136 
137  if(new_mask != nullptr) {
138  const fixed_t proportion = fxpdiv(i,niterations);
139  tod_hex_mask2 = sdl::timage(adjust_surface_alpha(new_mask,proportion));
140  }
141 #else
142  if(old_mask != nullptr) {
143  const fixed_t proportion = ftofxp(1.0) - fxpdiv(i,niterations);
144  tod_hex_mask1.assign(adjust_surface_alpha(old_mask,proportion));
145  }
146 
147  if(new_mask != nullptr) {
148  const fixed_t proportion = fxpdiv(i,niterations);
149  tod_hex_mask2.assign(adjust_surface_alpha(new_mask,proportion));
150  }
151 #endif
152 
153  invalidate_all();
154  draw();
155 
156  const int cur_ticks = SDL_GetTicks();
157  const int wanted_ticks = starting_ticks + i*frame_time;
158  if(cur_ticks < wanted_ticks) {
159  SDL_Delay(wanted_ticks - cur_ticks);
160  }
161  }
162  }
163 
164 #ifdef SDL_GPU
165  tod_hex_mask1 = sdl::timage();
166  tod_hex_mask2 = sdl::timage();
167 #else
168  tod_hex_mask1.assign(nullptr);
169  tod_hex_mask2.assign(nullptr);
170 #endif
171  }
172 
173  first_turn_ = false;
174 
176 
177  invalidate_all();
178  draw();
179 }
180 
182 {
183  if(hex.valid() && fogged(hex)) {
184  return;
185  }
186  display::select_hex(hex);
187 
188  display_unit_hex(hex);
189 }
190 
192 {
193  wb::future_map_if future(!synced_context::is_synced()); /**< Lasts for whole method. */
194 
196  if (u) {
197  displayedUnitHex_ = hex;
198  invalidate_unit();
199  } else {
201  if (u) {
202  // mouse moved from unit hex to non-unit hex
203  if (dc_->units().count(selectedHex_)) {
205  invalidate_unit();
206  }
207  }
208  }
209 
212 }
213 
214 
216 {
217  if (!hex.valid())
218  return;
219 
220  wb::future_map_if future(!synced_context::is_synced()); /**< Lasts for whole method. */
221 
223  if (u) {
224  displayedUnitHex_ = hex;
225  invalidate_unit();
226  }
227 }
228 
230 {
231  if (src == displayedUnitHex_) {
233  invalidate_unit();
234  }
235 }
236 
237 void game_display::scroll_to_leader(int side, SCROLL_TYPE scroll_type,bool force)
238 {
239  unit_map::const_iterator leader = dc_->units().find_leader(side);
240 
241  if(leader.valid()) {
242  // YogiHH: I can't see why we need another key_handler here,
243  // therefore I will comment it out :
244  /*
245  const hotkey::basic_handler key_events_handler(gui_);
246  */
247  scroll_to_tile(leader->get_location(), scroll_type, true, force);
248  }
249 }
250 
252  if (boost::shared_ptr<wb::manager> w = wb_.lock()) {
253  w->pre_draw();
254  }
256  /**
257  * @todo FIXME: must modify changed, but best to do it at the
258  * floating_label level
259  */
260  chat_man_->prune_chat_messages();
261 }
262 
263 
265  if (boost::shared_ptr<wb::manager> w = wb_.lock()) {
266  w->post_draw();
267  }
268 }
269 
271 {
272  halo_man_->unrender(invalidated_);
274 
275  unit_drawer drawer = unit_drawer(*this, energy_bar_rects_);
276 
277  for (const unit* temp_unit : *fake_unit_man_) {
278  const map_location& loc = temp_unit->get_location();
280  if (invalidated_.find(loc) != invalidated_.end()
281  && (request == exclusive_unit_draw_requests_.end() || request->second == temp_unit->id()))
282  drawer.redraw_unit(*temp_unit);
283  }
284 }
285 
287 {
288  halo_man_->render();
289 }
290 
292 {
293  const bool on_map = get_map().on_board(loc);
294  const bool is_shrouded = shrouded(loc);
295 // const bool is_fogged = fogged(loc);
296  const int xpos = get_location_x(loc);
297  const int ypos = get_location_y(loc);
298 
299 // image::TYPE image_type = get_image_type(loc);
300 
301  display::draw_hex(loc);
302 
303  if(cursor::get() == cursor::WAIT) {
304  // Interaction is disabled, so we don't need anything else
305  return;
306  }
307 
308  if(on_map && loc == mouseoverHex_) {
309  tdrawing_layer hex_top_layer = LAYER_MOUSEOVER_BOTTOM;
311  if( u != nullptr ) {
312  hex_top_layer = LAYER_MOUSEOVER_TOP;
313  }
314 #ifdef SDL_GPU
315  if(u == nullptr) {
316  drawing_buffer_add( hex_top_layer, loc, xpos, ypos,
317  image::get_texture("misc/hover-hex-top.png~RC(magenta>gold)", image::SCALED_TO_HEX));
319  image::get_texture("misc/hover-hex-bottom.png~RC(magenta>gold)", image::SCALED_TO_HEX));
320  } else if(dc_->teams()[currentTeam_].is_enemy(u->side())) {
321  drawing_buffer_add( hex_top_layer, loc, xpos, ypos,
322  image::get_texture("misc/hover-hex-enemy-top.png~RC(magenta>red)", image::SCALED_TO_HEX));
324  image::get_texture("misc/hover-hex-enemy-bottom.png~RC(magenta>red)", image::SCALED_TO_HEX));
325  } else if(dc_->teams()[currentTeam_].side() == u->side()) {
326  drawing_buffer_add( hex_top_layer, loc, xpos, ypos,
327  image::get_texture("misc/hover-hex-top.png~RC(magenta>green)", image::SCALED_TO_HEX));
329  image::get_texture("misc/hover-hex-bottom.png~RC(magenta>green)", image::SCALED_TO_HEX));
330  } else {
331  drawing_buffer_add( hex_top_layer, loc, xpos, ypos,
332  image::get_texture("misc/hover-hex-top.png~RC(magenta>lightblue)", image::SCALED_TO_HEX));
334  image::get_texture("misc/hover-hex-bottom.png~RC(magenta>lightblue)", image::SCALED_TO_HEX));
335  }
336 #else
337  if(u == nullptr) {
338  drawing_buffer_add( hex_top_layer, loc, xpos, ypos,
339  image::get_image("misc/hover-hex-top.png~RC(magenta>gold)", image::SCALED_TO_HEX));
341  image::get_image("misc/hover-hex-bottom.png~RC(magenta>gold)", image::SCALED_TO_HEX));
342  } else if(dc_->teams()[currentTeam_].is_enemy(u->side())) {
343  drawing_buffer_add( hex_top_layer, loc, xpos, ypos,
344  image::get_image("misc/hover-hex-enemy-top.png~RC(magenta>red)", image::SCALED_TO_HEX));
346  image::get_image("misc/hover-hex-enemy-bottom.png~RC(magenta>red)", image::SCALED_TO_HEX));
347  } else if(dc_->teams()[currentTeam_].side() == u->side()) {
348  drawing_buffer_add( hex_top_layer, loc, xpos, ypos,
349  image::get_image("misc/hover-hex-top.png~RC(magenta>green)", image::SCALED_TO_HEX));
351  image::get_image("misc/hover-hex-bottom.png~RC(magenta>green)", image::SCALED_TO_HEX));
352  } else {
353  drawing_buffer_add( hex_top_layer, loc, xpos, ypos,
354  image::get_image("misc/hover-hex-top.png~RC(magenta>lightblue)", image::SCALED_TO_HEX));
356  image::get_image("misc/hover-hex-bottom.png~RC(magenta>lightblue)", image::SCALED_TO_HEX));
357  }
358 #endif
359  }
360 
361 
362 
363  // Draw reach_map information.
364  // We remove the reachability mask of the unit
365  // that we want to attack.
366  if (!is_shrouded && !reach_map_.empty()
367  && reach_map_.find(loc) == reach_map_.end() && loc != attack_indicator_dst_) {
369 #ifdef SDL_GPU
370  drawing_buffer_add(LAYER_REACHMAP, loc, xpos, ypos,
371  image::get_texture(unreachable,image::SCALED_TO_HEX));
372 #else
373  drawing_buffer_add(LAYER_REACHMAP, loc, xpos, ypos,
375 #endif
376  }
377 
378  if (boost::shared_ptr<wb::manager> w = wb_.lock()) {
379  w->draw_hex(loc);
380 
381  if (!(w->is_active() && w->has_temp_move()))
382  {
383 #ifdef SDL_GPU
384  std::vector<sdl::timage> footstepImages = footsteps_images(loc, route_, dc_);
385 #else
386  std::vector<surface> footstepImages = footsteps_images(loc, route_, dc_);
387 #endif
388  if (!footstepImages.empty()) {
390  }
391  }
392  }
393  // Draw the attack direction indicator
394 #ifdef SDL_GPU
395  if(on_map && loc == attack_indicator_src_) {
397  image::get_texture("misc/attack-indicator-src-" + attack_indicator_direction() + ".png", image::SCALED_TO_HEX));
398  } else if (on_map && loc == attack_indicator_dst_) {
400  image::get_texture("misc/attack-indicator-dst-" + attack_indicator_direction() + ".png", image::SCALED_TO_HEX));
401  }
402 
403  // Linger overlay unconditionally otherwise it might give glitches
404  // so it's drawn over the shroud and fog.
405  if(game_mode_ != RUNNING) {
407  drawing_buffer_add(LAYER_LINGER_OVERLAY, loc, xpos, ypos,
408  image::get_texture(linger, image::TOD_COLORED));
409  }
410 
411  if(on_map && loc == selectedHex_ && !game_config::images::selected.empty()) {
413  drawing_buffer_add(LAYER_SELECTED_HEX, loc, xpos, ypos,
414  image::get_texture(selected, image::SCALED_TO_HEX));
415  }
416 #else
417  if(on_map && loc == attack_indicator_src_) {
419  image::get_image("misc/attack-indicator-src-" + attack_indicator_direction() + ".png", image::SCALED_TO_HEX));
420  } else if (on_map && loc == attack_indicator_dst_) {
422  image::get_image("misc/attack-indicator-dst-" + attack_indicator_direction() + ".png", image::SCALED_TO_HEX));
423  }
424 
425  // Linger overlay unconditionally otherwise it might give glitches
426  // so it's drawn over the shroud and fog.
427  if(game_mode_ != RUNNING) {
429  drawing_buffer_add(LAYER_LINGER_OVERLAY, loc, xpos, ypos,
431  }
432 
433  if(on_map && loc == selectedHex_ && !game_config::images::selected.empty()) {
435  drawing_buffer_add(LAYER_SELECTED_HEX, loc, xpos, ypos,
437  }
438 #endif
439 
440  // Show def% and turn to reach info
441  if(!is_shrouded && on_map) {
442  draw_movement_info(loc);
443  }
444 
445  if(game_config::debug) {
446  int debugH = debugHighlights_[loc];
447  if (debugH) {
448  std::string txt = std::to_string(debugH);
450  }
451  }
452  //simulate_delay += 1;
453 }
454 
456 {
457  return tod_manager_->get_time_of_day(loc);
458 }
459 
461 {
462  return tod_manager_->has_time_area();
463 }
464 
466 {
467  if ( !team_valid() )
468  return;
469 
470  refresh_report("report_clock");
471  refresh_report("report_countdown");
472 
474  {
475  wb::future_map future; // start planned unit map scope
476 
477  // We display the unit the mouse is over if it is over a unit,
478  // otherwise we display the unit that is selected.
479  for (const std::string &name : reports_object_->report_list()) {
481  }
482  invalidateGameStatus_ = false;
483  }
484 }
485 
486 
488 {
489  if(game_mode != game_mode_) {
490  game_mode_ = game_mode;
491  invalidate_all();
492  }
493 }
494 
496 {
497  // Search if there is a mark here
499 
501 
502  // Don't use empty route or the first step (the unit will be there)
503  if(w != route_.marks.end()
504  && !route_.steps.empty() && route_.steps.front() != loc) {
505  const unit_map::const_iterator un =
506  (wb && wb->get_temp_move_unit().valid()) ?
507  wb->get_temp_move_unit() : dc_->units().find(route_.steps.front());
508  if(un != dc_->units().end()) {
509  // Display the def% of this terrain
510  int def = 100 - un->defense_modifier(get_map().get_terrain(loc));
511  std::stringstream def_text;
512  def_text << def << "%";
513 
514  SDL_Color color = int_to_color(game_config::red_to_green(def, false));
515 
516  // simple mark (no turn point) use smaller font
517  int def_font = w->second.turns > 0 ? 18 : 16;
518  draw_text_in_hex(loc, LAYER_MOVE_INFO, def_text.str(), def_font, color);
519 
520  int xpos = get_location_x(loc);
521  int ypos = get_location_y(loc);
522 #ifdef SDL_GPU
523  if (w->second.invisible) {
524  drawing_buffer_add(LAYER_MOVE_INFO, loc, xpos, ypos,
525  image::get_texture("misc/hidden.png", image::SCALED_TO_HEX));
526  }
527 
528  if (w->second.zoc) {
529  drawing_buffer_add(LAYER_MOVE_INFO, loc, xpos, ypos,
530  image::get_texture("misc/zoc.png", image::SCALED_TO_HEX));
531  }
532 
533  if (w->second.capture) {
534  drawing_buffer_add(LAYER_MOVE_INFO, loc, xpos, ypos,
535  image::get_texture("misc/capture.png", image::SCALED_TO_HEX));
536  }
537 #else
538  if (w->second.invisible) {
539  drawing_buffer_add(LAYER_MOVE_INFO, loc, xpos, ypos,
540  image::get_image("misc/hidden.png", image::SCALED_TO_HEX));
541  }
542 
543  if (w->second.zoc) {
544  drawing_buffer_add(LAYER_MOVE_INFO, loc, xpos, ypos,
545  image::get_image("misc/zoc.png", image::SCALED_TO_HEX));
546  }
547 
548  if (w->second.capture) {
549  drawing_buffer_add(LAYER_MOVE_INFO, loc, xpos, ypos,
550  image::get_image("misc/capture.png", image::SCALED_TO_HEX));
551  }
552 #endif
553 
554  //we display turn info only if different from a simple last "1"
555  if (w->second.turns > 1 || (w->second.turns == 1 && loc != route_.steps.back())) {
556  std::stringstream turns_text;
557  turns_text << w->second.turns;
558  draw_text_in_hex(loc, LAYER_MOVE_INFO, turns_text.str(), 17, font::NORMAL_COLOR, 0.5,0.8);
559  }
560 
561  // The hex is full now, so skip the "show enemy moves"
562  return;
563  }
564  }
565  // When out-of-turn, it's still interesting to check out the terrain defs of the selected unit
566  else if (selectedHex_.valid() && loc == mouseoverHex_)
567  {
570  if(selectedUnit != dc_->units().end() && mouseoveredUnit == dc_->units().end()) {
571  // Display the def% of this terrain
572  int def = 100 - selectedUnit->defense_modifier(get_map().get_terrain(loc));
573  std::stringstream def_text;
574  def_text << def << "%";
575 
576  SDL_Color color = int_to_color(game_config::red_to_green(def, false));
577 
578  // use small font
579  int def_font = 16;
580  draw_text_in_hex(loc, LAYER_MOVE_INFO, def_text.str(), def_font, color);
581  }
582  }
583 
584  if (!reach_map_.empty()) {
585  reach_map::iterator reach = reach_map_.find(loc);
586  if (reach != reach_map_.end() && reach->second > 1) {
587  const std::string num = std::to_string(reach->second);
589  }
590  }
591 }
592 
593 #ifdef SDL_GPU
594 std::vector<sdl::timage> footsteps_images(const map_location& loc, const pathfind::marked_route & route_, const display_context * dc_)
595 #else
596 std::vector<surface> footsteps_images(const map_location& loc, const pathfind::marked_route & route_, const display_context * dc_)
597 #endif
598 {
599 #ifdef SDL_GPU
600  std::vector<sdl::timage> res;
601 #else
602  std::vector<surface> res;
603 #endif
604 
605  if (route_.steps.size() < 2) {
606  return res; // no real "route"
607  }
608 
609  std::vector<map_location>::const_iterator i =
610  std::find(route_.steps.begin(),route_.steps.end(),loc);
611 
612  if( i == route_.steps.end()) {
613  return res; // not on the route
614  }
615 
616  // Check which footsteps images of game_config we will use
617  int move_cost = 1;
618  const unit_map::const_iterator u = dc_->units().find(route_.steps.front());
619  if(u != dc_->units().end()) {
620  move_cost = u->movement_cost(dc_->map().get_terrain(loc));
621  }
622  int image_number = std::min<int>(move_cost, game_config::foot_speed_prefix.size());
623  if (image_number < 1) {
624  return res; // Invalid movement cost or no images
625  }
627 
628 #ifdef SDL_GPU
629  sdl::timage teleport;
630 #else
631  surface teleport = nullptr;
632 #endif
633 
634  // We draw 2 half-hex (with possibly different directions),
635  // but skip the first for the first step.
636  const int first_half = (i == route_.steps.begin()) ? 1 : 0;
637  // and the second for the last step
638  const int second_half = (i+1 == route_.steps.end()) ? 0 : 1;
639 
640  for (int h = first_half; h <= second_half; ++h) {
641  const std::string sense( h==0 ? "-in" : "-out" );
642 
643  if (!tiles_adjacent(*(i+(h-1)), *(i+h))) {
644  std::string teleport_image =
646 #ifdef SDL_GPU
647  teleport = image::get_texture(teleport_image, image::SCALED_TO_HEX);
648 #else
649  teleport = image::get_image(teleport_image, image::SCALED_TO_HEX);
650 #endif
651  continue;
652  }
653 
654  // In function of the half, use the incoming or outgoing direction
655  map_location::DIRECTION dir = (i+(h-1))->get_relative_dir(*(i+h));
656 
657  std::string rotate;
658  if (dir > map_location::SOUTH_EAST) {
659  // No image, take the opposite direction and do a 180 rotation
660  dir = i->get_opposite_dir(dir);
661  rotate = "~FL(horiz)~FL(vert)";
662  }
663 
664  const std::string image = foot_speed_prefix
665  + sense + "-" + i->write_direction(dir)
666  + ".png" + rotate;
667 
668 #ifdef SDL_GPU
669  res.push_back(image::get_texture(image, image::SCALED_TO_HEX));
670 #else
671  res.push_back(image::get_image(image, image::SCALED_TO_HEX));
672 #endif
673  }
674 
675  // we draw teleport image (if any) in last
676 #ifdef SDL_GPU
677  if (!teleport.null()) res.push_back(teleport);
678 #else
679  if (teleport != nullptr) res.push_back(teleport);
680 #endif
681 
682  return res;
683 }
684 
685 
686 
688 {
690  highlight_another_reach(paths_list);
691 }
692 
694 {
695  // Fold endpoints of routes into reachability map.
696  for (const pathfind::paths::step &dest : paths_list.destinations) {
697  reach_map_[dest.curr]++;
698  }
699  reach_map_changed_ = true;
700 }
701 
703 {
704  reach_map_ = reach_map();
705  reach_map_changed_ = true;
706 }
707 
708 
709 
711 {
712  for(std::vector<map_location>::const_iterator i = route_.steps.begin();
713  i != route_.steps.end(); ++i) {
714  invalidate(*i);
715  }
716 }
717 
719 {
721 
722  if(route != nullptr) {
723  route_ = *route;
724  } else {
725  route_.steps.clear();
726  route_.marks.clear();
727  }
728 
730 }
731 
732 void game_display::float_label(const map_location& loc, const std::string& text, const SDL_Color& color)
733 {
734  if(preferences::show_floating_labels() == false || fogged(loc)) {
735  return;
736  }
737 
738  font::floating_label flabel(text);
740  flabel.set_color(color);
741  flabel.set_position(get_location_x(loc)+zoom_/2, get_location_y(loc));
742  flabel.set_move(0, -2 * turbo_speed());
743  flabel.set_lifetime(60/turbo_speed());
745 
746  font::add_floating_label(flabel);
747 }
748 
750 {
751  assert(game_config::debug);
752  return debugHighlights_[loc];
753 }
754 
756 {
757  if (attack_indicator_src_ != src || attack_indicator_dst_ != dst) {
760 
763 
766  }
767 }
768 
770 {
772 }
773 
775 {
776  if (team_valid())
777  {
778  return dc_->teams()[currentTeam_].team_name();
779  }
780  return std::string();
781 }
782 
783 
784 void game_display::set_playing_team(size_t teamindex)
785 {
786  assert(teamindex < dc_->teams().size());
787  activeTeam_ = teamindex;
789 }
790 
792 {
793  in_game_ = true;
794  create_buttons();
795  invalidate_all();
796 }
797 
799  if (b) {
800  needs_rebuild_ = true;
801  }
802 }
803 
805  if (needs_rebuild_) {
806  needs_rebuild_ = false;
808  invalidate_all();
809  rebuild_all();
810  return true;
811  }
812  return false;
813 }
void drawing_buffer_add(const tdrawing_layer layer, const map_location &loc, int x, int y, const surface &surf, const SDL_Rect &clip=SDL_Rect())
Add an item to the drawing buffer.
Definition: display.cpp:1241
boost::scoped_ptr< fake_unit_manager > fake_unit_man_
Definition: display.hpp:777
surface get_image(const image::locator &i_locator, TYPE type)
function to get the surface corresponding to an image.
Definition: image.cpp:878
virtual void highlight_hex(map_location hex)
Function to highlight a location.
void invalidate_unit_after_move(const map_location &src, const map_location &dst)
Same as invalidate_unit() if moving the displayed unit.
Game board class.
Definition: game_board.hpp:55
bool fogged(const map_location &loc) const
Returns true if location (x,y) is covered in fog.
Definition: display.hpp:353
std::string attack_indicator_direction() const
Function to get attack direction suffix.
bool null() const
Definition: utils.hpp:104
virtual void select_hex(map_location hex)
Definition: display.cpp:1792
size_t currentTeam_
Definition: display.hpp:769
reports * reports_object_
Definition: display.hpp:791
unit_iterator end()
Definition: map.hpp:311
static game_display * create_dummy_display(CVideo &video)
config dummy_cfg
Definition: help_impl.cpp:74
static int & debug_highlight(const map_location &loc)
annotate hex with number, useful for debugging or UI prototype
void invalidate_game_status()
Function to invalidate the game status displayed on the sidebar.
Definition: display.hpp:299
std::string image_mask
The image that is to be laid over all images while this time of day lasts.
Definition: time_of_day.hpp:83
bool invalidate(const map_location &loc)
Function to invalidate a specific tile for redrawing.
Definition: display.cpp:3536
Definition: unit.hpp:95
boost::weak_ptr< wb::manager > wb_
Definition: display.hpp:665
GLint level
Definition: glew.h:1220
std::map< surface, SDL_Rect > energy_bar_rects_
Definition: display.hpp:771
void set_move(double xmove, double ymove)
void invalidate_route()
size_t count(const map_location &loc) const
Definition: map.hpp:306
bool team_valid() const
Definition: display.hpp:99
bool reach_map_changed_
Definition: display.hpp:1131
std::string current_team_name() const
unit_iterator find_leader(int side)
Definition: map.cpp:297
Sint32 fixed_t
Definition: drawer.hpp:40
SDL_Color int_to_color(const Uint32 rgb)
Definition: utils.cpp:63
map_location attack_indicator_src_
Top half of image following the mouse.
Definition: display.hpp:872
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
Definition: video.hpp:58
#define fxpdiv(x, y)
IN: unsigned and int - OUT: fixed_t.
Definition: util.hpp:509
virtual void draw_invalidated()
Only called when there's actual redrawing to do.
Definition: display.cpp:2795
map_location mouseoverHex_
Definition: display.hpp:835
void invalidate_unit()
Function to invalidate that unit status displayed on the sidebar.
std::string unreachable
Definition: game_config.cpp:84
const std::set< std::string > & report_list()
Definition: reports.cpp:1582
Footsteps showing path from unit to mouse.
Definition: display.hpp:871
void float_label(const map_location &loc, const std::string &text, const SDL_Color &color)
Function to float a label above a tile.
dest_vect destinations
Definition: pathfind.hpp:100
Movement info (defense%, etc...).
Definition: display.hpp:902
Layer which holds the attack indicator.
Definition: display.hpp:897
reach_map reach_map_
Definition: display.hpp:1129
#define h
int side() const
Definition: unit.hpp:201
int get_location_x(const map_location &loc) const
Functions to get the on-screen positions of hexes.
Definition: display.cpp:713
map_location displayedUnitHex_
map_location selectedHex_
Definition: display.hpp:834
void set_font_size(int font_size)
void draw_text_in_hex(const map_location &loc, const tdrawing_layer layer, const std::string &text, size_t font_size, SDL_Color color, double x_in_hex=0.5, double y_in_hex=0.5)
Draw text on a hex.
Definition: display.cpp:1668
GLenum src
Definition: glew.h:2392
virtual void draw()
Draws invalidated items.
Definition: display.cpp:2706
const SDL_Color NORMAL_COLOR
Definition: font.cpp:564
no linger overlay, show fog and shroud.
void draw_invalidated()
Only called when there's actual redrawing to do.
virtual const gamemap & map() const =0
void new_turn()
Update lighting settings.
Uint32 red_to_green(int val, bool for_text)
Return a color corresponding to the value val red for val=0 to green for val=100, passing by yellow...
static std::map< map_location, int > debugHighlights_
surface tod_hex_mask2
Definition: display.hpp:829
Unit and team statistics.
int get_location_y(const map_location &loc) const
Definition: display.cpp:718
bool has_time_area() const
"black stripes" on unreachable hexes.
Definition: display.hpp:891
const time_of_day & get_previous_time_of_day() const
static lg::log_domain log_display("display")
GLdouble GLdouble GLdouble b
Definition: glew.h:6966
const int SIZE_XLARGE
Definition: font.hpp:68
Object which defines a time of day with associated bonuses, image, sounds etc.
Definition: time_of_day.hpp:48
static std::vector< team > *& teams
Definition: team.cpp:50
tdrawing_layer
The layers to render something on.
Definition: display.hpp:864
void scroll_to_leader(int side, SCROLL_TYPE scroll_type=ONSCREEN, bool force=true)
Scrolls to the leader of a certain side.
bool tiles_adjacent(const map_location &a, const map_location &b)
Function which tells if two locations are adjacent.
Definition: location.hpp:314
const SDL_Color BAD_COLOR
Definition: font.cpp:568
tgame_mode game_mode_
bool valid() const
Definition: location.hpp:69
const time_of_day & get_time_of_day(const map_location &loc) const
unit * get_visible_unit(const map_location &loc, const team &current_team, bool see_all=false)
Definition: game_board.cpp:192
void set_lifetime(int lifetime)
Applies the planned unit map for the duration of the struct's life.
Definition: manager.hpp:249
map_location curr
Definition: pathfind.hpp:88
void pre_draw()
game_display pre_draw does specific things related e.g.
void recalculate_minimap()
Schedule the minimap for recalculation.
Definition: display.hpp:623
virtual void select_hex(map_location hex)
Function to display a location as selected.
GLubyte GLubyte GLubyte GLubyte w
Definition: glew.h:1858
GLenum GLenum dst
Definition: glew.h:2392
surface adjust_surface_alpha(const surface &surf, fixed_t amount, bool optimize)
Definition: utils.cpp:1202
std::vector< surface > footsteps_images(const map_location &loc, const pathfind::marked_route &route_, const display_context *dc_)
Function to return 2 half-hex footsteps images for the given location.
game_board * gameboard
Definition: resources.cpp:20
std::string selected
Definition: game_config.cpp:84
std::string foot_teleport_enter
bool is_shrouded(const display &disp, const map_location &loc)
Definition: label.cpp:30
void set_color(const SDL_Color &color)
GLuint num
Definition: glew.h:2552
void highlight_another_reach(const pathfind::paths &paths_list)
Add more paths to highlight.
bool invalidateGameStatus_
Definition: display.hpp:789
void highlight_reach(const pathfind::paths &paths_list)
Sets the paths that are currently displayed as available for the unit to move along.
void set_position(double xpos, double ypos)
virtual const unit_map & units() const =0
void set_game_mode(const tgame_mode game_mode)
void create_buttons()
Definition: display.cpp:897
Structure which holds a single route and marks for special events.
Definition: pathfind.hpp:141
static const map_location & null_location()
Definition: location.hpp:195
int zoom_
Definition: display.hpp:775
void needs_rebuild(bool b)
Sets whether the screen (map visuals) needs to be rebuilt. This is typically after the map has been c...
void invalidate_all()
Function to invalidate all tiles.
Definition: display.cpp:3525
pathfind::marked_route route_
GLuint color
Definition: glew.h:5801
void draw_sidebar()
Called near the end of a draw operation, derived classes can use this to render a specific sidebar...
tgame_mode
Sets the linger mode for the display.
Encapsulates the map of the game.
Definition: location.hpp:38
void set_scroll_mode(LABEL_SCROLL_MODE scroll)
double turbo_speed() const
Definition: display.cpp:2631
void process_reachmap_changes()
Definition: display.cpp:3737
Some defines: VERSION, PACKAGE, MIN_SAVEGAME_VERSION.
GLuint res
Definition: glew.h:9258
surface tod_hex_mask1
Definition: display.hpp:829
virtual const std::vector< team > & teams() const =0
void scroll_to_tile(const map_location &loc, SCROLL_TYPE scroll_type=ONSCREEN, bool check_fogged=true, bool force=true)
Scroll such that location loc is on-screen.
Definition: display.cpp:2434
void unhighlight_reach()
Reset highlighting of paths.
virtual void highlight_hex(map_location hex)
Definition: display.cpp:1800
void post_draw()
Calls the whiteboard's post-draw method.
bool shrouded(const map_location &loc) const
Returns true if location (x,y) is covered in shroud.
Definition: display.hpp:349
bool dont_show_all_
Definition: display.hpp:770
GLfloat GLfloat GLfloat GLfloat h
Definition: glew.h:5910
size_t i
Definition: function.cpp:1057
CURSOR_TYPE get()
Definition: cursor.cpp:194
int add_floating_label(const floating_label &flabel)
add a label floating on the screen above everything else.
DIRECTION
Valid directions which can be moved in our hexagonal world.
Definition: location.hpp:40
virtual void draw_hex(const map_location &loc)
Redraws a single gamemap location.
Definition: display.cpp:2833
The overlay used for the linger mode.
Definition: display.hpp:903
std::vector< std::string > foot_speed_prefix
static lg::log_domain log_engine("engine")
const tod_manager * tod_manager_
GLuint const GLchar * name
Definition: glew.h:1782
t_translation::t_terrain get_terrain(const map_location &loc) const
Looks up terrain at a particular location.
Definition: map.cpp:341
bool on_board(const map_location &loc) const
Tell if a location is on the map.
Definition: map.cpp:467
game_display(game_board &board, CVideo &video, boost::weak_ptr< wb::manager > wb, reports &reports_object, const tod_manager &tod_manager, const config &theme_cfg, const config &level, bool dummy=false)
std::map< map_location, unsigned int > reach_map
Definition: display.hpp:1128
GLsizeiptr size
Definition: glew.h:1649
size_t activeTeam_
Definition: display.hpp:959
overlay_map overlay_map_
bool show_floating_labels()
std::string foot_teleport_exit
exclusive_unit_draw_requests_t exclusive_unit_draw_requests_
map of hexes where only one unit should be drawn, the one identified by the associated id string ...
Definition: display.hpp:669
bool has_time_area() const
const gamemap & get_map() const
Definition: display.hpp:92
std::set< map_location > invalidated_
Definition: display.hpp:818
bool find(E event, F functor)
Tests whether an event handler is available.
void post_commit()
Hook for actions to take right after draw() calls drawing_buffer_commit No action here by default...
void clear_screen()
Clear the screen contents.
Definition: display.cpp:2783
Image on the selected unit.
Definition: display.hpp:896
const display_context * dc_
Definition: display.hpp:663
this module manages the cache of images.
Definition: image.cpp:75
void update_tod()
Add r,g,b from tod_manager to the map.
Definition: display.cpp:446
Standard logging facilities (interface).
void assign(const surface &o)
Definition: utils.hpp:83
Object which contains all the possible locations a unit can move to, with associated best routes to t...
Definition: pathfind.hpp:71
Bottom half of image following the mouse.
Definition: display.hpp:892
void set_playing_team(size_t team)
Sets the team controlled by the player using the computer.
map_location attack_indicator_dst_
const SDL_Color YELLOW_COLOR
Definition: font.cpp:570
unit_iterator find(size_t id)
Definition: map.cpp:285
size_t viewing_team() const
The viewing team is the team currently viewing the game.
Definition: display.hpp:102
bool valid() const
Definition: map.hpp:229
boost::scoped_ptr< halo::manager > halo_man_
Definition: display.hpp:664
void draw_movement_info(const map_location &loc)
Draws the movement info (turns available) for a given location.
std::string::const_iterator iterator
Definition: tokenizer.hpp:21
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
void refresh_report(std::string const &report_name, const config *new_cfg=nullptr)
Redraws the specified report (if anything has changed).
Definition: display.cpp:3099
void set_route(const pathfind::marked_route *route)
Sets the route along which footsteps are drawn to show movement of a unit.
boost::scoped_ptr< display_chat_manager > chat_man_
void clear_attack_indicator()
void redraw_unit(const unit &u) const
draw a unit.
Definition: drawer.cpp:50
static bool is_synced()
void draw_hex(const map_location &loc)
Redraws a single gamemap location.
GLsizei const GLcharARB ** string
Definition: glew.h:4503
void display_unit_hex(map_location hex)
Change the unit to be displayed in the sidebar.
unit_map::iterator find_visible_unit(const map_location &loc, const team &current_team, bool see_all=false)
Definition: game_board.cpp:173
void set_attack_indicator(const map_location &src, const map_location &dst)
Set the attack direction indicator.
std::vector< map_location > & steps
Definition: pathfind.hpp:187
Definition: display.hpp:47
#define ftofxp(x)
IN: float or int - OUT: fixed_t.
Definition: util.hpp:503
void rebuild_all()
Rebuild all dynamic terrain.
Definition: display.cpp:482
const std::vector< map_location > & route_
Definition: move.cpp:288
void replace_overlay_map(overlay_map *overlays)
Definition: display.hpp:1175
bool maybe_rebuild()
Rebuilds the screen if needs_rebuild(true) was previously called, and resets the flag.
std::string linger
Definition: game_config.cpp:84