Freeciv-3.2
Loading...
Searching...
No Matches
repodlgs_common.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 "fcintl.h"
20#include "log.h"
21#include "mem.h" /* free() */
22#include "support.h" /* fc_snprintf() */
23
24/* common */
25#include "game.h"
26#include "government.h"
27#include "unitlist.h"
28
29/* client/include */
30#include "repodlgs_g.h"
31
32/* client */
33#include "client_main.h"
34#include "connectdlg_common.h" /* is_server_running() */
35#include "control.h"
36#include "options.h"
37#include <packhand_gen.h> /* <> so looked from the build directory first. */
38
39#include "repodlgs_common.h"
40
41
42/************************************************************************/
47 int *num_entries_used, int *total_cost,
48 int *total_income)
49{
51 *total_cost = 0;
52 *total_income = 0;
53
54 if (NULL == client.conn.playing) {
55 return;
56 }
57
58 improvement_iterate(pimprove) {
59 if (is_improvement(pimprove)) {
60 int count = 0, redundant = 0, cost = 0;
62 if (city_has_building(pcity, pimprove)) {
63 count++;
64 cost += city_improvement_upkeep(pcity, pimprove);
65 if (is_improvement_redundant(pcity, pimprove)) {
66 redundant++;
67 }
68 }
69 }
71
72 if (count == 0) {
73 continue;
74 }
75
76 entries[*num_entries_used].type = pimprove;
77 entries[*num_entries_used].count = count;
78 entries[*num_entries_used].redundant = redundant;
79 entries[*num_entries_used].total_cost = cost;
80 entries[*num_entries_used].cost = cost / count;
81 (*num_entries_used)++;
82
83 /* Currently there is no building expense under anarchy. It's
84 * not a good idea to hard-code this in the client, but what
85 * else can we do? */
88 *total_cost += cost;
89 }
90 }
92
94 *total_income += pcity->prod[O_GOLD];
96 *total_income += MAX(0, pcity->surplus[O_SHIELD]);
97 }
99}
100
101/************************************************************************/
106 int *num_entries_used, int *total_cost)
107{
108 int count, cost, partial_cost;
109
110 *num_entries_used = 0;
111 *total_cost = 0;
112
113 if (NULL == client.conn.playing) {
114 return;
115 }
116
117 unit_type_iterate(unittype) {
119
120 if (cost == 0) {
121 /* Short-circuit all of the following checks. */
122 continue;
123 }
124
125 count = 0;
126 partial_cost = 0;
127
129 unit_list_iterate(pcity->units_supported, punit) {
130 if (unit_type_get(punit) == unittype) {
131 count++;
133 }
134
137
138 if (count == 0) {
139 continue;
140 }
141
142 (*total_cost) += partial_cost;
143
144 entries[*num_entries_used].type = unittype;
145 entries[*num_entries_used].count = count;
148 (*num_entries_used)++;
149
151}
152
153/************************************************************************/
160void sell_all_improvements(const struct impr_type *pimprove, bool redundant_only,
161 char *message, size_t message_sz)
162{
163 int count = 0, gold = 0;
164
166 fc_snprintf(message, message_sz, _("You cannot sell improvements."));
167 return;
168 }
169
171 if (!pcity->did_sell && city_has_building(pcity, pimprove)
172 && (!redundant_only
173 || is_improvement_redundant(pcity, pimprove))) {
174 count++;
175 gold += impr_sell_gold(pimprove);
177 }
179
180 if (count > 0) {
181 /* FIXME: plurality of count is ignored! */
182 /* TRANS: "Sold 3 Harbor for 90 gold." (Pluralisation is in gold --
183 * second %d -- not in buildings.) */
184 fc_snprintf(message, message_sz, PL_("Sold %d %s for %d gold.",
185 "Sold %d %s for %d gold.", gold),
186 count, improvement_name_translation(pimprove), gold);
187 } else {
188 fc_snprintf(message, message_sz, _("No %s could be sold."),
190 }
191}
192
193/************************************************************************/
201 char *message, size_t message_sz)
202{
203 int count = 0;
204
206 /* TRANS: Obscure observer error. */
207 fc_snprintf(message, message_sz, _("You cannot disband units."));
208 return;
209 }
210
212 fc_snprintf(message, message_sz, _("%s cannot be disbanded."),
214 return;
215 }
216
218 /* Only supported units are disbanded. Units with no homecity have no
219 * cost and are not disbanded. */
220 unit_list_iterate(pcity->units_supported, punit) {
221 struct city *incity = tile_city(unit_tile(punit));
222
224 && (!in_cities_only
225 || (incity && city_owner(incity) == client.conn.playing))) {
226 count++;
228 }
231
232 if (count > 0) {
233 fc_snprintf(message, message_sz, _("Disbanded %d %s."),
235 } else {
236 fc_snprintf(message, message_sz, _("No %s could be disbanded."),
238 }
239}
struct @126::my_agent entries[MAX_AGENTS]
bool city_has_building(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:1240
int city_improvement_upkeep(const struct city *pcity, const struct impr_type *b)
Definition city.c:1255
bool city_production_has_flag(const struct city *pcity, enum impr_flag_id flag)
Definition city.c:727
#define city_list_iterate(citylist, pcity)
Definition city.h:508
#define city_owner(_pcity_)
Definition city.h:563
#define city_list_iterate_end
Definition city.h:510
int city_sell_improvement(struct city *pcity, Impr_type_id sell_id)
struct civclient client
bool can_client_issue_orders(void)
char * incite_cost
Definition comments.c:75
void request_unit_disband(struct unit *punit)
Definition control.c:2075
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 * punit
Definition dialogs_g.h:74
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 cost
Definition dialogs_g.h:74
@ O_SHIELD
Definition fc_types.h:101
@ O_GOLD
Definition fc_types.h:101
#define PL_(String1, String2, n)
Definition fcintl.h:71
#define _(String)
Definition fcintl.h:67
struct civ_game game
Definition game.c:62
struct government * government_of_player(const struct player *pplayer)
Definition government.c:114
int impr_sell_gold(const struct impr_type *pimprove)
bool is_improvement_redundant(const struct city *pcity, const struct impr_type *pimprove)
bool is_improvement(const struct impr_type *pimprove)
Impr_type_id improvement_number(const struct impr_type *pimprove)
const char * improvement_name_translation(const struct impr_type *pimprove)
#define improvement_iterate_end
#define improvement_iterate(_p)
void get_economy_report_units_data(struct unit_entry *entries, int *num_entries_used, int *total_cost)
void get_economy_report_data(struct improvement_entry *entries, int *num_entries_used, int *total_cost, int *total_income)
void sell_all_improvements(const struct impr_type *pimprove, bool redundant_only, char *message, size_t message_sz)
void disband_all_units(const struct unit_type *punittype, bool in_cities_only, char *message, size_t message_sz)
#define MAX(x, y)
Definition shared.h:54
Definition city.h:320
struct government * government_during_revolution
Definition game.h:94
struct connection conn
Definition client_main.h:96
struct player * playing
Definition connection.h:151
struct city_list * cities
Definition player.h:279
int upkeep[O_LAST]
Definition unit.h:148
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:974
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define unit_tile(_pu)
Definition unit.h:397
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_end
Definition unitlist.h:33
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
int utype_upkeep_cost(const struct unit_type *ut, struct player *pplayer, Output_type_id otype)
Definition unittype.c:132
const char * utype_name_translation(const struct unit_type *punittype)
Definition unittype.c:1560
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:371
#define unit_type_iterate(_p)
Definition unittype.h:855
#define unit_type_iterate_end
Definition unittype.h:862