The Battle for Wesnoth  1.17.0-dev
entity_location.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2021
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 /**
17  * @file
18  * Define locations as used by the game's events mechanism.
19  */
20 
21 #pragma once
22 
23 #include "map/location.hpp"
24 #include "units/map.hpp"
25 
26 class unit;
27 class vconfig;
28 
29 
30 namespace game_events
31 {
32  struct entity_location : public map_location {
33  entity_location(const map_location &loc, std::size_t id = 0);
34  entity_location(const map_location &loc, std::size_t id,
35  const map_location &filter_loc);
36  explicit entity_location(const unit &);
37  entity_location(const unit &u, const map_location &filter_loc);
38 
39  const map_location& filter_loc() const { return filter_loc_; }
40  bool matches_unit(const unit_map::const_iterator & un_it) const;
42  const vconfig & filter) const;
43  unit_const_ptr get_unit() const;
44 
46 
47  private:
48  /**
49  * The underlying ID of the unit associated with this.
50  * Set to 0 if there is no associated unit.
51  */
52  std::size_t id_;
53 
54  /**
55  * This map_location allows a unit to be filtered as if it were
56  * somewhere other than where it is. (Use the parent struct if
57  * you want to locate the unit.)
58  */
60  };
61 }
std::size_t id_
The underlying ID of the unit associated with this.
bool matches_unit_filter(const unit_map::const_iterator &un_it, const vconfig &filter) const
Determines if un_it matches filter.
This class represents a single unit of a specific type.
Definition: unit.hpp:121
const map_location & filter_loc() const
std::shared_ptr< const unit > unit_const_ptr
Definition: ptr.hpp:27
unit_const_ptr get_unit() const
static const entity_location null_entity
bool matches_unit(const unit_map::const_iterator &un_it) const
Determines if un_it matches (using underlying ID) the unit that was supplied when this was constructe...
entity_location(const map_location &loc, std::size_t id=0)
Constructor for when an event has a location but not necessarily a unit.
Encapsulates the map of the game.
Definition: location.hpp:38
Domain specific events.
Definition: action_wml.cpp:87
map_location filter_loc_
This map_location allows a unit to be filtered as if it were somewhere other than where it is...
A variable-expanding proxy for the config class.
Definition: variable.hpp:44