Freeciv-3.3
Loading...
Searching...
No Matches
citizens.c
Go to the documentation of this file.
1/*****************************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12*****************************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18/* utility */
19#include "log.h"
20#include "rand.h"
21
22/* common */
23#include "city.h"
24#include "game.h"
25#include "player.h"
26
27#include "citizens.h"
28
29/*************************************************************************/
33{
35
37 return;
38 }
39
40 /* For the nationality of the citizens the informations for all player
41 * slots are allocated as once. Considering a size of citizens (= char)
42 * this results in an allocation of 2 * 128 * 1 bytes for the citizens
43 * per nation as well as the timer for a nationality change. */
44 if (pcity->nationality == NULL) {
45 /* Allocate the memory*/
47 sizeof(*pcity->nationality));
48 } else {
49 /* Reset the nationality information. */
52 }
53}
54
55/*************************************************************************/
59{
61
62 if (pcity->nationality) {
65 }
66}
67
68/*************************************************************************/
75 const struct player_slot *pslot)
76{
78 return 0;
79 }
80
81 fc_assert_ret_val(pslot != NULL, 0);
84
85 return *(pcity->nationality + player_slot_index(pslot));
86}
87
88/*************************************************************************/
96
97/*************************************************************************/
104void citizens_nation_add(struct city *pcity, const struct player_slot *pslot,
105 int add)
106{
107 citizens nationality = citizens_nation_get(pcity, pslot);
108
110 return;
111 }
112
113 fc_assert_ret(pslot != NULL);
116
117 fc_assert_ret(MAX_CITY_SIZE - nationality >= add);
118 fc_assert_ret(nationality >= -add);
119
120 citizens_nation_set(pcity, pslot, nationality + add);
121}
122
123/*************************************************************************/
131 const struct player_slot *pslot_from,
132 const struct player_slot *pslot_to,
133 int move)
134{
137}
138
139/*************************************************************************/
145void citizens_nation_set(struct city *pcity, const struct player_slot *pslot,
146 citizens count)
147{
149 return;
150 }
151
152 fc_assert_ret(pslot != NULL);
155
156 *(pcity->nationality + player_slot_index(pslot)) = count;
157}
158
159/*************************************************************************/
163{
164 /* Use int here to check for an possible overflow at the end. */
165 int count = 0;
166
168 return city_size_get(pcity);
169 }
170
171 citizens_iterate(pcity, pslot, nationality) {
172 /* If the citizens of a nation is greater than 0 there should be a player
173 * for this nation. This test should only be done on the server as the
174 * client does not has the knowledge about all players all the time. */
177
178 count += nationality;
180
181 fc_assert_ret_val(count >= 0 && count <= MAX_CITY_SIZE,
183
184 return (citizens)count;
185}
186
187/*************************************************************************/
190struct player_slot *citizens_random(const struct city *pcity)
191{
192 int total = citizens_count(pcity);
193 int chocen = fc_rand(total);
194
195 citizens_iterate(pcity, pslot, nationality) {
196 chocen -= nationality;
197 if (chocen <= 0) {
198 return pslot;
199 }
201
203
204 return NULL;
205}
struct player_slot * citizens_random(const struct city *pcity)
Definition citizens.c:190
void citizens_free(struct city *pcity)
Definition citizens.c:58
void citizens_nation_move(struct city *pcity, const struct player_slot *pslot_from, const struct player_slot *pslot_to, int move)
Definition citizens.c:130
void citizens_nation_add(struct city *pcity, const struct player_slot *pslot, int add)
Definition citizens.c:104
citizens citizens_nation_get(const struct city *pcity, const struct player_slot *pslot)
Definition citizens.c:74
void citizens_nation_set(struct city *pcity, const struct player_slot *pslot, citizens count)
Definition citizens.c:145
citizens citizens_nation_foreign(const struct city *pcity)
Definition citizens.c:91
citizens citizens_count(const struct city *pcity)
Definition citizens.c:162
void citizens_init(struct city *pcity)
Definition citizens.c:32
#define citizens_iterate_end
Definition citizens.h:54
#define citizens_iterate(_pcity, _pslot, _nationality)
Definition citizens.h:48
static citizens city_size_get(const struct city *pcity)
Definition city.h:566
#define city_owner(_pcity_)
Definition city.h:560
#define MAX_CITY_SIZE
Definition city.h:103
char * incite_cost
Definition comments.c:76
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
static bool is_server(void)
unsigned char citizens
Definition fc_types.h:247
#define MAX_NUM_PLAYER_SLOTS
Definition fc_types.h:32
struct civ_game game
Definition game.c:61
#define fc_assert_ret(condition)
Definition log.h:192
#define fc_assert(condition)
Definition log.h:177
#define fc_assert_ret_val(condition, val)
Definition log.h:195
#define fc_calloc(n, esz)
Definition mem.h:38
int player_slot_index(const struct player_slot *pslot)
Definition player.c:426
struct player * player_slot_get_player(const struct player_slot *pslot)
Definition player.c:437
#define fc_rand(_size)
Definition rand.h:56
Definition city.h:317
struct packet_game_info info
Definition game.h:89
struct player * nationality
Definition unit.h:146
#define FALSE
Definition support.h:47