The Battle for Wesnoth  1.17.0-dev
fake_unit_manager.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2021
3  by Chris Beck <render787@gmail.com>
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 "fake_unit_manager.hpp"
17 
18 #include "display.hpp"
19 #include "fake_unit_ptr.hpp"
20 #include "log.hpp"
21 #include "units/unit.hpp"
23 
24 static lg::log_domain log_engine("engine");
25 #define ERR_NG LOG_STREAM(err, log_engine)
26 
27 /** Temporarily register a unit to be drawn on the map (moving: can overlap others).
28  * The temp unit is added at the end of the temporary unit dequeue,
29  * and therefore gets drawn last, over other units and temp units.
30  * Adding the same unit twice isn't allowed.
31  */
33 {
34  if(std::find(fake_units_.begin(),fake_units_.end(), u) != fake_units_.end()) {
35  ERR_NG << "In fake_unit_manager::place_temporary_unit: attempt to add duplicate fake unit." << std::endl;
36  } else {
37  fake_units_.push_back(u);
38  my_display_.invalidate(u->get_location());
39  }
40 }
41 
42 /** Removes any instances of this unit from the temporary unit database. */
44 {
45  int removed = 0;
46  if (fake_units_.empty())
47  return removed;
49  std::remove(fake_units_.begin(), fake_units_.end(), u);
50  if (it != fake_units_.end()) {
51  removed = std::distance(it, fake_units_.end());
52  //std::remove doesn't remove anything without using erase afterwards.
53  fake_units_.erase(it, fake_units_.end());
54  my_display_.invalidate(u->get_location());
55  // Redraw with no location to get rid of haloes
56  u->anim_comp().clear_haloes();
57  }
58  if (removed > 1) {
59  ERR_NG << "Error: duplicate temp unit found in fake_unit_manager::remove_temporary_unit" << std::endl;
60  }
61  return removed;
62 }
void remove()
Removes a tip.
Definition: tooltip.cpp:175
bool invalidate(const map_location &loc)
Function to invalidate a specific tile for redrawing.
Definition: display.cpp:3026
static lg::log_domain log_engine("engine")
int remove_temporary_unit(internal_ptr_type)
Deregister a unit from this manager.
std::deque< internal_ptr_type > fake_units_
collection of units destined to be drawn but not put into the unit map
map_display and display: classes which take care of displaying the map and game-data on the screen...
unit const * internal_ptr_type
display & my_display_
Reference to my display.
void place_temporary_unit(internal_ptr_type)
Register a unit with this manager.
Standard logging facilities (interface).
std::string::const_iterator iterator
Definition: tokenizer.hpp:25
#define ERR_NG