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