Freeciv21
Develop your civilization from humble roots to a global empire
layer_city_size.cpp
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPLv3-or-later
2 // SPDX-FileCopyrightText: Freeciv authors
3 // SPDX-FileCopyrightText: Freeciv21 authors
4 // SPDX-FileCopyrightText: Louis Moureaux <m_louis30@yahoo.com>
5 
6 #include "layer_city_size.h"
7 
8 #include "citybar.h"
9 #include "tilespec.h"
10 
11 namespace freeciv {
12 
13 layer_city_size::layer_city_size(struct tileset *ts, const QPoint &offset)
14  : freeciv::layer(ts, LAYER_CITY2), m_offset(offset)
15 {
16 }
17 
19 {
20  // Digit sprites. We have a cascade of fallbacks.
21  QStringList patterns = {QStringLiteral("city.size_%1")};
22  assign_digit_sprites(tileset(), m_units.data(), m_tens.data(),
23  m_hundreds.data(), patterns);
24 }
25 
29 std::vector<drawn_sprite>
31  const tile_corner *pcorner,
32  const unit *punit) const
33 {
35  return {};
36  }
37 
38  auto pcity = tile_city(ptile);
39  if (!pcity) {
40  return {};
41  }
42 
43  // Now draw
44  std::vector<drawn_sprite> sprs;
45  auto size = city_size_get(pcity);
46 
47  // Units
48  auto sprite = m_units[size % NUM_TILES_DIGITS];
49  sprs.emplace_back(tileset(), sprite, false, m_offset);
50 
51  // Tens
53  if (size > 0 && (sprite = m_tens[size % NUM_TILES_DIGITS])) {
54  sprs.emplace_back(tileset(), sprite, false, m_offset);
55  }
56 
57  // Hundreds (optional)
59  if (size > 0 && (sprite = m_hundreds[size % NUM_TILES_DIGITS])) {
60  sprs.emplace_back(tileset(), sprite, false, m_offset);
61  // Divide for the warning: warn for thousands if we had a hundreds sprite
63  }
64 
65  // Warn if the city is too large (only once by tileset).
66  if (size > 0 && !m_warned) {
68  tileset(), QtWarningMsg,
69  _("Tileset \"%s\" doesn't support big city sizes, such as %d. "
70  "Size not displayed as expected."),
72  m_warned = true;
73  }
74 
75  return sprs;
76 }
77 
78 } // namespace freeciv
citizens city_size_get(const struct city *pcity)
Get the city size.
Definition: city.cpp:1101
virtual bool has_size() const
Returns whether the city size is shown in the bar.
Definition: citybar.h:56
static citybar_painter * current()
Returns the current painter (never null).
Definition: citybar.cpp:295
bool m_warned
Did we warn the user?
std::vector< drawn_sprite > fill_sprite_array(const tile *ptile, const tile_edge *pedge, const tile_corner *pcorner, const unit *punit) const override
Fill in the given sprite array with any needed city size sprites.
void load_sprites() override
Loads all sprites that do not depend on the ruleset.
layer_city_size(struct tileset *ts, const QPoint &offset)
std::array< QPixmap *, NUM_TILES_DIGITS > m_hundreds
std::array< QPixmap *, NUM_TILES_DIGITS > m_tens
std::array< QPixmap *, NUM_TILES_DIGITS > m_units
A layer when drawing the map.
Definition: layer.h:153
struct tileset * tileset() const
Definition: layer.h:241
#define _(String)
Definition: fcintl.h:50
#define NUM_TILES_DIGITS
Definition: layer.h:78
Definition: path.cpp:10
client_options * gui_options
Definition: options.cpp:74
size_t size
Definition: specvec.h:64
bool draw_cities
Definition: options.h:136
Definition: tile.h:42
Definition: unit.h:134
struct city * tile_city(const struct tile *ptile)
Return the city on this tile (or nullptr), checking for city center.
Definition: tile.cpp:72
const char * tileset_name_get(const struct tileset *t)
Return tileset name.
Definition: tilespec.cpp:3828
void assign_digit_sprites(struct tileset *t, QPixmap *units[NUM_TILES_DIGITS], QPixmap *tens[NUM_TILES_DIGITS], QPixmap *hundreds[NUM_TILES_DIGITS], const QStringList &patterns)
Assigns the digits for city or go-to orders, for units, tens, and hundreds (i.e.
Definition: tilespec.cpp:2408
void tileset_error(struct tileset *t, QtMsgType level, const char *format,...)
Called when ever there's problem in ruleset/tileset compatibility.
Definition: tilespec.cpp:291