Freeciv21
Develop your civilization from humble roots to a global empire
citizens.h
Go to the documentation of this file.
1 /**************************************************************************
2  Copyright (c) 1996-2021 Freeciv21 and Freeciv contributors. This file is
3  part of Freeciv21. Freeciv21 is free software: you can
4  ^oo^ redistribute it and/or modify it under the terms of the GNU
5  (..) General Public License as published by the Free Software
6  () () Foundation, either version 3 of the License, or (at your
7  ()__() option) any later version. You should have received
8  a copy of the GNU General Public License along with Freeciv21. If not,
9  see https://www.gnu.org/licenses/.
10 **************************************************************************/
11 #pragma once
12 
13 // common
14 #include "fc_types.h"
15 
16 struct player_slot;
17 struct city;
18 
19 void citizens_init(struct city *pcity);
20 void citizens_free(struct city *pcity);
21 
22 citizens citizens_nation_get(const struct city *pcity,
23  const struct player_slot *pslot);
24 citizens citizens_nation_foreign(const struct city *pcity);
25 void citizens_nation_set(struct city *pcity, const struct player_slot *pslot,
26  citizens count);
27 void citizens_nation_add(struct city *pcity, const struct player_slot *pslot,
28  int add);
29 void citizens_nation_move(struct city *pcity,
30  const struct player_slot *pslot_from,
31  const struct player_slot *pslot_to, int move);
32 
33 citizens citizens_count(const struct city *pcity);
34 struct player_slot *citizens_random(const struct city *pcity);
35 
36 // Iterates over all player slots (nationalities) with citizens.
37 #define citizens_iterate(_pcity, _pslot, _nationality) \
38  player_slots_iterate(_pslot) \
39  { \
40  citizens _nationality = citizens_nation_get(_pcity, _pslot); \
41  if (_nationality == 0) { \
42  continue; \
43  }
44 #define citizens_iterate_end \
45  } \
46  player_slots_iterate_end;
47 
48 // Like above but only foreign citizens.
49 #define citizens_foreign_iterate(_pcity, _pslot, _nationality) \
50  citizens_iterate(_pcity, _pslot, _nationality) \
51  { \
52  if (_pslot == city_owner(_pcity)->slot) { \
53  continue; \
54  }
55 #define citizens_foreign_iterate_end \
56  } \
57  citizens_iterate_end;
void citizens_free(struct city *pcity)
Free citizens data.
Definition: citizens.cpp:51
void citizens_nation_move(struct city *pcity, const struct player_slot *pslot_from, const struct player_slot *pslot_to, int move)
Convert a (positive or negative) value to the citizens from one nation to another.
Definition: citizens.cpp:123
void citizens_nation_add(struct city *pcity, const struct player_slot *pslot, int add)
Add a (positive or negative) value to the citizens of the given nationality.
Definition: citizens.cpp:96
citizens citizens_nation_get(const struct city *pcity, const struct player_slot *pslot)
Get the number of citizens with the given nationality.
Definition: citizens.cpp:65
void citizens_nation_set(struct city *pcity, const struct player_slot *pslot, citizens count)
Set the number of citizens with the given nationality.
Definition: citizens.cpp:137
citizens citizens_nation_foreign(const struct city *pcity)
Get the number of foreign citizens.
Definition: citizens.cpp:82
struct player_slot * citizens_random(const struct city *pcity)
Return random citizen from city.
Definition: citizens.cpp:185
citizens citizens_count(const struct city *pcity)
Return the number of citizens in a city.
Definition: citizens.cpp:154
void citizens_init(struct city *pcity)
Initialise citizens data.
Definition: citizens.cpp:26
unsigned char citizens
Definition: fc_types.h:305
Definition: city.h:291