The Battle for Wesnoth  1.19.0-dev
entity_location.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2024
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 unit_filter;
28 
29 namespace game_events
30 {
31  struct entity_location : public map_location {
32  entity_location(const map_location &loc, std::size_t id = 0);
33  entity_location(const map_location &loc, std::size_t id,
34  const map_location &filter_loc);
35  explicit entity_location(const unit &);
36  entity_location(const unit &u, const map_location &filter_loc);
37 
38  const map_location& filter_loc() const { return filter_loc_; }
39  bool matches_unit(const unit_map::const_iterator & un_it) const;
41  const unit_filter& filter) const;
42  unit_const_ptr get_unit() const;
43 
45 
46  private:
47  /**
48  * The underlying ID of the unit associated with this.
49  * Set to 0 if there is no associated unit.
50  */
51  std::size_t id_;
52 
53  /**
54  * This map_location allows a unit to be filtered as if it were
55  * somewhere other than where it is. (Use the parent struct if
56  * you want to locate the unit.)
57  */
59  };
60 }
This class represents a single unit of a specific type.
Definition: unit.hpp:133
Domain specific events.
std::shared_ptr< const unit > unit_const_ptr
Definition: ptr.hpp:27
entity_location(const map_location &loc, std::size_t id=0)
Constructor for when an event has a location but not necessarily a unit.
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...
static const entity_location null_entity
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 unit_filter &filter) const
Determines if un_it matches filter.
map_location filter_loc_
This map_location allows a unit to be filtered as if it were somewhere other than where it is.
const map_location & filter_loc() const
unit_const_ptr get_unit() const
Encapsulates the map of the game.
Definition: location.hpp:38