Freeciv21
Develop your civilization from humble roots to a global empire
layer_base_flags.cpp
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 2021-2023 Freeciv21 contributors.
3 \_ \ / __/ This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 
14 #include "layer_base_flags.h"
15 
16 #include "extras.h"
17 #include "game.h" // For extra_type_iterate
18 #include "nation.h"
19 #include "tilespec.h"
20 
21 namespace freeciv {
22 
29 layer_base_flags::layer_base_flags(struct tileset *ts, const QPoint &offset)
30  : freeciv::layer(ts, LAYER_BASE_FLAGS), m_offset(offset)
31 {
32 }
33 
34 std::vector<drawn_sprite> layer_base_flags::fill_sprite_array(
35  const tile *ptile, const tile_edge *pedge, const tile_corner *pcorner,
36  const unit *punit) const
37 {
38  Q_UNUSED(pedge);
39  Q_UNUSED(pcorner);
40  Q_UNUSED(punit);
41 
42  if (ptile == nullptr) {
43  return {};
44  }
45 
46  const auto eowner = extra_owner(ptile);
47  if (eowner == nullptr) {
48  return {};
49  }
50 
51  extra_type_iterate(pextra)
52  {
53  if (tile_has_extra(ptile, pextra)
54  && extra_has_flag(pextra, EF_SHOW_FLAG)) {
55  bool hidden = false;
56 
57  extra_type_list_iterate(pextra->hiders, phider)
58  {
59  if (tile_has_extra(ptile, phider)) {
60  hidden = true;
61  break;
62  }
63  }
65 
66  if (!hidden) {
67  // Draw a flag for this extra
68  return {drawn_sprite(
69  tileset(),
71  true, m_offset)};
72  }
73  }
74  }
76 
77  return {};
78 }
79 
80 } // namespace freeciv
std::vector< drawn_sprite > fill_sprite_array(const tile *ptile, const tile_edge *pedge, const tile_corner *pcorner, const unit *punit) const override
Returns the list of sprites drawn by this layer somewhere on the map.
layer_base_flags(struct tileset *ts, const QPoint &offset)
A layer when drawing the map.
Definition: layer.h:153
struct tileset * tileset() const
Definition: layer.h:241
struct player * extra_owner(const struct tile *ptile)
Who owns extras on tile.
Definition: extras.cpp:1013
bool extra_has_flag(const struct extra_type *pextra, enum extra_flag_id flag)
Check if extra has given flag.
Definition: extras.cpp:779
#define extra_type_iterate(_p)
Definition: extras.h:279
#define extra_type_list_iterate(extralist, pextra)
Definition: extras.h:145
#define extra_type_iterate_end
Definition: extras.h:285
#define extra_type_list_iterate_end
Definition: extras.h:147
Definition: path.cpp:10
struct nation_type * nation_of_player(const struct player *pplayer)
Return the nation of a player.
Definition: nation.cpp:419
Definition: tile.h:42
Definition: unit.h:134
#define tile_has_extra(ptile, pextra)
Definition: tile.h:130
const QPixmap * get_nation_flag_sprite(const struct tileset *t, const struct nation_type *pnation)
Return the sprite for the nation.
Definition: tilespec.cpp:3367