Freeciv-3.2: /fast/freeciv/nightly/S3_2/client/text.c Source File

Freeciv-3.2

Loading...
Searching...
No Matches
text.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 2002 - The Freeciv Project
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#include <stdarg.h>
19#include <string.h>
20#include <math.h> /* ceil */
21
22/* utility */
23#include "astring.h"
24#include "bitvector.h"
25#include "fcintl.h"
26#include "log.h"
27#include "support.h"
28
29/* common */
30#include "calendar.h"
31#include "citizens.h"
32#include "clientutils.h"
33#include "combat.h"
34#include "culture.h"
35#include "fc_types.h" /* LINE_BREAK */
36#include "game.h"
37#include "government.h"
38#include "map.h"
39#include "nation.h"
40#include "research.h"
41#include "traderoutes.h"
42#include "unitlist.h"
43
44/* client */
45#include "client_main.h"
46#include "climap.h"
47#include "climisc.h"
48#include "control.h"
49#include "goto.h"
50#include "helpdata.h"
51
52#include "text.h"
53
54
55static int get_bulbs_per_turn(int *pours, bool *pteam, int *ptheirs);
56static const char *format_duration(int duration);
57
58/************************************************************************/
63 const char *get_tile_output_text(const struct tile *ptile)
64{
65 static struct astring str = ASTRING_INIT;
66 int i;
67 char output_text[O_LAST][16];
68
69 for (i = 0; i < O_LAST; i++) {
70 int before_penalty = 0;
71 int x = city_tile_output(NULL, ptile, FALSE, i);
72
73 if (NULL != client.conn.playing) {
74 before_penalty = get_player_output_bonus(client.conn.playing,
75 get_output_type(i),
76 EFT_OUTPUT_PENALTY_TILE);
77 }
78
79 if (before_penalty > 0 && x > before_penalty) {
80 fc_snprintf(output_text[i], sizeof(output_text[i]), "%d(-1)", x);
81 } else {
82 fc_snprintf(output_text[i], sizeof(output_text[i]), "%d", x);
83 }
84 }
85
86 astr_set(&str, "%s/%s/%s", output_text[O_FOOD],
87 output_text[O_SHIELD], output_text[O_TRADE]);
88
89 return astr_str(&str);
90}
91
92/************************************************************************/
96 static inline void get_full_username(char *buf, int buflen,
97 const struct player *pplayer)
98{
99 if (!buf || buflen < 1) {
100 return;
101 }
102
103 if (!pplayer) {
104 buf[0] = '\0';
105 return;
106 }
107
108 if (is_ai(pplayer)) {
109 /* TRANS: "AI <player name>" */
110 fc_snprintf(buf, buflen, _("AI %s"), pplayer->name);
111 } else {
112 fc_strlcpy(buf, pplayer->username, buflen);
113 }
114}
115
116/************************************************************************/
120 static inline void get_full_nation(char *buf, int buflen,
121 const struct player *pplayer)
122{
123 if (!buf || buflen < 1) {
124 return;
125 }
126
127 if (!pplayer) {
128 buf[0] = '\0';
129 return;
130 }
131
132 if (pplayer->team) {
133 /* TRANS: "<nation adjective>, team <team name>" */
134 fc_snprintf(buf, buflen, _("%s, team %s"),
135 nation_adjective_for_player(pplayer),
136 team_name_translation(pplayer->team));
137 } else {
138 fc_strlcpy(buf, nation_adjective_for_player(pplayer), buflen);
139 }
140}
141
142/************************************************************************/
147 const char *popup_info_text(struct tile *ptile)
148{
149 const char *activity_text;
150 struct city *pcity = tile_city(ptile);
151 struct unit *punit = find_visible_unit(ptile);
152 const char *diplo_nation_plural_adjectives[DS_LAST] =
153 {"" /* unused, DS_ARMISTICE */, Q_("?nation:Hostile"),
154 "" /* unused, DS_CEASEFIRE */,
155 Q_("?nation:Peaceful"), Q_("?nation:Friendly"),
156 Q_("?nation:Mysterious"), Q_("?nation:Friendly(team)")};
157 const char *diplo_city_adjectives[DS_LAST] =
158 {"" /* unused, DS_ARMISTICE */, Q_("?city:Hostile"),
159 "" /* unused, DS_CEASEFIRE */,
160 Q_("?city:Peaceful"), Q_("?city:Friendly"), Q_("?city:Mysterious"),
161 Q_("?city:Friendly(team)")};
162 static struct astring str = ASTRING_INIT;
163 char username[MAX_LEN_NAME + 32];
164 char nation[2 * MAX_LEN_NAME + 32];
165 int tile_x, tile_y, nat_x, nat_y;
166 bool first;
167
168 astr_clear(&str);
169 index_to_map_pos(&tile_x, &tile_y, tile_index(ptile));
170 astr_add_line(&str, _("Location: (%d, %d) [%d]"),
171 tile_x, tile_y, tile_continent(ptile));
172 index_to_native_pos(&nat_x, &nat_y, tile_index(ptile));
173 astr_add_line(&str, _("Native coordinates: (%d, %d)"),
174 nat_x, nat_y);
175 astr_add_line(&str, _("Latitude: %d"),
176 map_signed_latitude(ptile));
177
178 if (client_tile_get_known(ptile) == TILE_UNKNOWN) {
179 astr_add(&str, _("Unknown"));
180 return astr_str(&str);
181 }
182 astr_add_line(&str, _("Terrain: %s"), tile_get_info_text(ptile, TRUE, 0));
183 astr_add_line(&str, _("Food/Prod/Trade: %s"),
184 get_tile_output_text(ptile));
185 first = TRUE;
186 extra_type_iterate(pextra) {
187 if (pextra->category == ECAT_BONUS && tile_has_visible_extra(ptile, pextra)) {
188 if (!first) {
189 astr_add(&str, ",%s", extra_name_translation(pextra));
190 } else {
191 astr_add_line(&str, "%s", extra_name_translation(pextra));
192 first = FALSE;
193 }
194 }
195 } extra_type_iterate_end;
196 if (BORDERS_DISABLED != game.info.borders && !pcity) {
197 struct player *owner = tile_owner(ptile);
198
199 get_full_username(username, sizeof(username), owner);
200 get_full_nation(nation, sizeof(nation), owner);
201
202 if (NULL != client.conn.playing && owner == client.conn.playing) {
203 astr_add_line(&str, _("Our territory"));
204 } else if (NULL != owner && NULL == client.conn.playing) {
205 /* TRANS: "Territory of <username> (<nation + team>)" */
206 astr_add_line(&str, _("Territory of %s (%s)"), username, nation);
207 } else if (NULL != owner) {
208 struct player_diplstate *ds = player_diplstate_get(client.conn.playing,
209 owner);
210
211 if (ds->type == DS_CEASEFIRE) {
212 int turns = ds->turns_left;
213
214 astr_add_line(&str,
215 /* TRANS: "Territory of <username> (<nation + team>)
216 * (<number> turn cease-fire)" */
217 PL_("Territory of %s (%s) (%d turn cease-fire)",
218 "Territory of %s (%s) (%d turn cease-fire)",
219 turns),
220 username, nation, turns);
221 } else if (ds->type == DS_ARMISTICE) {
222 int turns = ds->turns_left;
223
224 astr_add_line(&str,
225 /* TRANS: "Territory of <username> (<nation + team>)
226 * (<number> turn armistice)" */
227 PL_("Territory of %s (%s) (%d turn armistice)",
228 "Territory of %s (%s) (%d turn armistice)",
229 turns),
230 username, nation, turns);
231 } else {
232 int type = ds->type;
233
234 /* TRANS: "Territory of <username>
235 * (<nation + team> | <diplomatic state>)" */
236 astr_add_line(&str, _("Territory of %s (%s | %s)"),
237 username, nation,
238 diplo_nation_plural_adjectives[type]);
239 }
240 } else {
241 astr_add_line(&str, _("Unclaimed territory"));
242 }
243 }
244 if (pcity) {
245 /* Look at city owner, not tile owner (the two should be the same, if
246 * borders are in use). */
247 struct player *owner = city_owner(pcity);
248 const char *improvements[improvement_count()];
249 int has_improvements = 0;
250
251 get_full_username(username, sizeof(username), owner);
252 get_full_nation(nation, sizeof(nation), owner);
253
254 if (NULL == client.conn.playing || owner == client.conn.playing) {
255 /* TRANS: "City: <city name> | <username> (<nation + team>)" */
256 astr_add_line(&str, _("City: %s | %s (%s)"),
257 city_name_get(pcity), username, nation);
258 } else {
259 struct player_diplstate *ds
260 = player_diplstate_get(client_player(), owner);
261 if (ds->type == DS_CEASEFIRE) {
262 int turns = ds->turns_left;
263
264 /* TRANS: "City: <city name> | <username>
265 * (<nation + team>, <number> turn cease-fire)" */
266 astr_add_line(&str, PL_("City: %s | %s (%s, %d turn cease-fire)",
267 "City: %s | %s (%s, %d turn cease-fire)",
268 turns),
269 city_name_get(pcity), username, nation, turns);
270 } else if (ds->type == DS_ARMISTICE) {
271 int turns = ds->turns_left;
272
273 /* TRANS: "City: <city name> | <username>
274 * (<nation + team>, <number> turn armistice)" */
275 astr_add_line(&str, PL_("City: %s | %s (%s, %d turn armistice)",
276 "City: %s | %s (%s, %d turn armistice)",
277 turns),
278 city_name_get(pcity), username, nation, turns);
279 } else {
280 /* TRANS: "City: <city name> | <username>
281 * (<nation + team>, <diplomatic state>)" */
282 astr_add_line(&str, _("City: %s | %s (%s, %s)"),
283 city_name_get(pcity), username, nation,
284 diplo_city_adjectives[ds->type]);
285 }
286 }
287 if (can_player_see_units_in_city(client_player(), pcity)) {
288 int count = unit_list_size(ptile->units);
289
290 if (count > 0) {
291 /* TRANS: preserve leading space */
292 astr_add(&str, PL_(" | Occupied with %d unit.",
293 " | Occupied with %d units.", count), count);
294 } else {
295 /* TRANS: preserve leading space */
296 astr_add(&str, _(" | Not occupied."));
297 }
298 } else {
299 if (city_is_occupied(pcity)) {
300 /* TRANS: preserve leading space */
301 astr_add(&str, _(" | Occupied."));
302 } else {
303 /* TRANS: preserve leading space */
304 astr_add(&str, _(" | Not occupied."));
305 }
306 }
307 improvement_iterate(pimprove) {
308 if (is_improvement_visible(pimprove)
309 && city_has_building(pcity, pimprove)) {
310 improvements[has_improvements++] =
311 improvement_name_translation(pimprove);
312 }
313 } improvement_iterate_end;
314
315 if (0 < has_improvements) {
316 struct astring list = ASTRING_INIT;
317
318 astr_build_and_list(&list, improvements, has_improvements);
319 /* TRANS: %s is a list of "and"-separated improvements. */
320 astr_add_line(&str, _(" with %s."), astr_str(&list));
321 astr_free(&list);
322 }
323
324 unit_list_iterate(get_units_in_focus(), pfocus_unit) {
325 struct city *hcity = game_city_by_number(pfocus_unit->homecity);
326
327 if (utype_can_do_action(unit_type_get(pfocus_unit), ACTION_TRADE_ROUTE)
328 && can_cities_trade(hcity, pcity)
329 && can_establish_trade_route(hcity, pcity)) {
330 /* TRANS: "Trade from Warsaw: 5" */
331 astr_add_line(&str, _("Trade from %s: %d"),
332 city_name_get(hcity),
333 trade_base_between_cities(hcity, pcity));
334 }
335 } unit_list_iterate_end;
336 }
337 {
338 const char *infratext = get_infrastructure_text(ptile->extras);
339
340 if (*infratext != '\0') {
341 astr_add_line(&str, _("Infrastructure: %s"), infratext);
342 }
343 }
344 activity_text = concat_tile_activity_text(ptile);
345 if (strlen(activity_text) > 0) {
346 astr_add_line(&str, _("Activity: %s"), activity_text);
347 }
348 if (punit && !pcity) {
349 struct player *owner = unit_owner(punit);
350 const struct unit_type *ptype = unit_type_get(punit);
351
352 get_full_username(username, sizeof(username), owner);
353 get_full_nation(nation, sizeof(nation), owner);
354
355 if (!client_player() || owner == client_player()) {
356 struct city *hcity = player_city_by_number(owner, punit->homecity);
357
358 /* TRANS: "Unit: <unit type> | <username> (<nation + team>)" */
359 astr_add_line(&str, _("Unit: %s | %s (%s)"),
360 utype_name_translation(ptype), username, nation);
361
362 if (game.info.citizen_nationality
363 && unit_nationality(punit) != unit_owner(punit)) {
364 if (hcity != NULL) {
365 /* TRANS: on own line immediately following \n, "from <city> |
366 * <nationality> people" */
367 astr_add_line(&str, _("from %s | %s people"), city_name_get(hcity),
368 nation_adjective_for_player(unit_nationality(punit)));
369 } else {
370 /* TRANS: Nationality of the people comprising a unit, if
371 * different from owner. */
372 astr_add_line(&str, _("%s people"),
373 nation_adjective_for_player(unit_nationality(punit)));
374 }
375 } else if (hcity != NULL) {
376 /* TRANS: on own line immediately following \n, ... <city> */
377 astr_add_line(&str, _("from %s"), city_name_get(hcity));
378 }
379 } else if (NULL != owner) {
380 struct player_diplstate *ds = player_diplstate_get(client_player(),
381 owner);
382 if (ds->type == DS_CEASEFIRE) {
383 int turns = ds->turns_left;
384
385 /* TRANS: "Unit: <unit type> | <username> (<nation + team>,
386 * <number> turn cease-fire)" */
387 astr_add_line(&str, PL_("Unit: %s | %s (%s, %d turn cease-fire)",
388 "Unit: %s | %s (%s, %d turn cease-fire)",
389 turns),
390 utype_name_translation(ptype),
391 username, nation, turns);
392 } else if (ds->type == DS_ARMISTICE) {
393 int turns = ds->turns_left;
394
395 /* TRANS: "Unit: <unit type> | <username> (<nation + team>,
396 * <number> turn armistice)" */
397 astr_add_line(&str, PL_("Unit: %s | %s (%s, %d turn armistice)",
398 "Unit: %s | %s (%s, %d turn armistice)",
399 turns),
400 utype_name_translation(ptype),
401 username, nation, turns);
402 } else {
403 /* TRANS: "Unit: <unit type> | <username> (<nation + team>,
404 * <diplomatic state>)" */
405 astr_add_line(&str, _("Unit: %s | %s (%s, %s)"),
406 utype_name_translation(ptype), username, nation,
407 diplo_city_adjectives[ds->type]);
408 }
409 }
410
411 combat_odds_to_astr(&str, get_units_in_focus(), ptile, punit, "%%");
412
413 if (unit_owner(punit) == client_player()
414 || client_is_global_observer()) {
415 /* Show bribe cost for own units. */
416 astr_add_line(&str, _("Probable bribe cost: %d"),
417 unit_bribe_cost(punit, NULL));
418 } else {
419 /* We can only give an (lower) boundary for units of other players. */
420 astr_add_line(&str, _("Estimated bribe cost: > %d"),
421 unit_bribe_cost(punit, client_player()));
422 }
423
424 if ((NULL == client.conn.playing || owner == client.conn.playing)
425 && unit_list_size(ptile->units) >= 2) {
426 /* TRANS: "5 more" units on this tile */
427 astr_add(&str, _(" (%d more)"), unit_list_size(ptile->units) - 1);
428 }
429 }
430
431 astr_break_lines(&str, LINE_BREAK);
432 return astr_str(&str);
433}
434
435#define FAR_CITY_SQUARE_DIST (2*(6*6))
436/************************************************************************/
441 const char *get_nearest_city_text(struct city *pcity, int sq_dist)
442{
443 static struct astring str = ASTRING_INIT;
444
445 astr_clear(&str);
446
447 /* Just to be sure */
448 if (!pcity) {
449 sq_dist = -1;
450 }
451
452 astr_add(&str, (sq_dist >= FAR_CITY_SQUARE_DIST)
453 /* TRANS: on own line immediately following \n, ... <city> */
454 ? _("far from %s")
455 : (sq_dist > 0)
456 /* TRANS: on own line immediately following \n, ... <city> */
457 ? _("near %s")
458 : (sq_dist == 0)
459 /* TRANS: on own line immediately following \n, ... <city> */
460 ? _("in %s")
461 : "%s",
462 pcity
463 ? city_name_get(pcity)
464 : "");
465
466 return astr_str(&str);
467}
468
469/************************************************************************/
475 const char *unit_description(struct unit *punit)
476{
477 int pcity_near_dist;
478 struct player *owner = unit_owner(punit);
479 struct player *nationality = unit_nationality(punit);
480 struct city *pcity =
481 player_city_by_number(owner, punit->homecity);
482 struct city *pcity_near = get_nearest_city(punit, &pcity_near_dist);
483 const struct unit_type *ptype = unit_type_get(punit);
484 static struct astring str = ASTRING_INIT;
485 const struct player *pplayer = client_player();
486
487 astr_clear(&str);
488
489 astr_add(&str, "%s", utype_name_translation(ptype));
490
491 {
492 const char *veteran_name =
493 utype_veteran_name_translation(ptype, punit->veteran);
494 if (veteran_name) {
495 astr_add(&str, " (%s)", veteran_name);
496 }
497 }
498
499 if (pplayer == owner) {
500 unit_upkeep_astr(punit, &str);
501 } else {
502 astr_add(&str, "\n");
503 }
504 unit_activity_astr(punit, &str);
505
506 if (pcity) {
507 /* TRANS: on own line immediately following \n, ... <city> */
508 astr_add_line(&str, _("from %s"), city_name_get(pcity));
509 } else {
510 astr_add(&str, "\n");
511 }
512 if (game.info.citizen_nationality) {
513 if (nationality != NULL && owner != nationality) {
514 /* TRANS: Nationality of the people comprising a unit, if
515 * different from owner. */
516 astr_add_line(&str, _("%s people"),
517 nation_adjective_for_player(nationality));
518 } else {
519 astr_add(&str, "\n");
520 }
521 }
522
523 astr_add_line(&str, "%s",
524 get_nearest_city_text(pcity_near, pcity_near_dist));
525#ifdef FREECIV_DEBUG
526 astr_add_line(&str, "Unit ID: %d", punit->id);
527#endif
528
529 return astr_str(&str);
530}
531
532/************************************************************************/
545 const char *get_airlift_text(const struct unit_list *punits,
546 const struct city *pdest)
547{
548 static struct astring str = ASTRING_INIT;
549 bool src = (pdest == NULL);
550 enum texttype { AL_IMPOSSIBLE, AL_UNKNOWN, AL_FINITE, AL_INFINITE }
551 best = AL_IMPOSSIBLE;
552 int cur = 0, max = 0;
553
554 unit_list_iterate(punits, punit) {
555 enum texttype this = AL_IMPOSSIBLE;
556 enum unit_airlift_result result;
557
558 /* NULL will tell us about the capability of airlifting from source */
559 result = test_unit_can_airlift_to(&(wld.map), client_player(), punit, pdest);
560
561 switch (result) {
562 case AR_NO_MOVES:
563 case AR_WRONG_UNITTYPE:
564 case AR_OCCUPIED:
565 case AR_NOT_IN_CITY:
566 case AR_BAD_SRC_CITY:
567 case AR_BAD_DST_CITY:
568 /* No chance of an airlift. */
569 this = AL_IMPOSSIBLE;
570 break;
571 case AR_OK:
572 case AR_OK_SRC_UNKNOWN:
573 case AR_OK_DST_UNKNOWN:
574 case AR_SRC_NO_FLIGHTS:
575 case AR_DST_NO_FLIGHTS:
576 /* May or may not be able to airlift now, but there's a chance we could
577 * later */
578 {
579 const struct city *pcity = src ? tile_city(unit_tile(punit)) : pdest;
580
581 fc_assert_ret_val(pcity != NULL, fc_strdup("-"));
582 if (!src && ((game.info.airlifting_style & AIRLIFTING_UNLIMITED_DEST)
583 && game.info.airlift_to_always_enabled)) {
584 /* No restrictions on destination (and we can infer this even for
585 * other players' cities). */
586 this = AL_INFINITE;
587 } else if (src && ((game.info.airlifting_style & AIRLIFTING_UNLIMITED_SRC)
588 && game.info.airlift_from_always_enabled)) {
589 this = AL_INFINITE;
590 } else if (client_player() == city_owner(pcity)) {
591 /* A city we know about. */
592 int this_cur = pcity->airlift, this_max = city_airlift_max(pcity);
593
594 if (this_max <= 0) {
595 /* City known not to be airlift-capable. */
596 this = AL_IMPOSSIBLE;
597 } else {
598 if (src
599 && (game.info.airlifting_style & AIRLIFTING_UNLIMITED_SRC)) {
600 /* Unlimited capacity. */
601 this = AL_INFINITE;
602 } else if (!src
603 && (game.info.airlifting_style & AIRLIFTING_UNLIMITED_DEST)) {
604 this = AL_INFINITE;
605 } else {
606 /* Limited capacity (possibly zero right now). */
607 this = AL_FINITE;
608 /* Store the numbers. This whole setup assumes that numeric
609 * capacity isn't unit-dependent. */
610 if (best == AL_FINITE) {
611 fc_assert(cur == this_cur && max == this_max);
612 }
613 cur = this_cur;
614 max = this_max;
615 }
616 }
617 } else {
618 /* Unknown capacity. */
619 this = AL_UNKNOWN;
620 }
621 }
622 break;
623 }
624
625 /* Now take the most optimistic view. */
626 best = MAX(best, this);
627 } unit_list_iterate_end;
628
629 switch (best) {
630 case AL_IMPOSSIBLE:
631 return NULL;
632 case AL_UNKNOWN:
633 astr_set(&str, "?");
634 break;
635 case AL_FINITE:
636 astr_set(&str, "%d/%d", cur, max);
637 break;
638 case AL_INFINITE:
639 astr_set(&str, _("Yes"));
640 break;
641 }
642
643 return astr_str(&str);
644}
645
646/************************************************************************/
649 static int get_bulbs_per_turn(int *pours, bool *pteam, int *ptheirs)
650{
651 const struct research *presearch;
652 int ours = 0, theirs = 0;
653 bool team = FALSE;
654
655 if (!client_has_player()) {
656 return 0;
657 }
658 presearch = research_get(client_player());
659
660 /* Sum up science */
661 research_players_iterate(presearch, pplayer) {
662 if (pplayer == client_player()) {
663 city_list_iterate(pplayer->cities, pcity) {
664 ours += pcity->surplus[O_SCIENCE];
665 } city_list_iterate_end;
666 } else {
667 team = TRUE;
668 theirs -= pplayer->client.tech_upkeep;
669 }
670 } research_players_iterate_end;
671
672 if (team) {
673 theirs += presearch->client.total_bulbs_prod - ours;
674 }
675 ours -= client_player()->client.tech_upkeep;
676
677 if (pours) {
678 *pours = ours;
679 }
680 if (pteam) {
681 *pteam = team;
682 }
683 if (ptheirs) {
684 *ptheirs = theirs;
685 }
686
687 return ours + theirs;
688}
689
690/************************************************************************/
693 static int turns_to_research_done(const struct research *presearch,
694 int per_turn)
695{
696 if (per_turn > 0) {
697 return ceil((double)(presearch->client.researching_cost
698 - presearch->bulbs_researched) / per_turn);
699 } else {
700 return -1;
701 }
702}
703
704/************************************************************************/
708 static int turns_per_advance(const struct research *presearch, int per_turn)
709{
710 if (per_turn > 0) {
711 return MAX(1, ceil((double)presearch->client.researching_cost) / per_turn);
712 } else {
713 return -1;
714 }
715}
716
717/************************************************************************/
721 static int turns_to_tech_loss(const struct research *presearch, int per_turn)
722{
723 if (per_turn >= 0 || game.info.techloss_forgiveness == -1) {
724 /* With techloss_forgiveness == -1, we'll never lose a tech, just
725 * get further into debt. */
726 return -1;
727 } else {
728 int bulbs_to_loss = presearch->bulbs_researched
729 + (presearch->client.researching_cost
730 * game.info.techloss_forgiveness / 100);
731
732 return ceil((double)bulbs_to_loss / -per_turn);
733 }
734}
735
736/************************************************************************/
741 const char *science_dialog_text(void)
742{
743 bool team;
744 int ours, theirs, perturn, upkeep;
745 static struct astring str = ASTRING_INIT;
746 struct astring ourbuf = ASTRING_INIT, theirbuf = ASTRING_INIT;
747 struct research *research;
748
749 astr_clear(&str);
750
751 perturn = get_bulbs_per_turn(&ours, &team, &theirs);
752
753 research = research_get(client_player());
754 upkeep = client_player()->client.tech_upkeep;
755
756 if (NULL == client.conn.playing || (ours == 0 && theirs == 0
757 && upkeep == 0)) {
758 return _("Progress: no research");
759 }
760
761 if (A_UNSET == research->researching) {
762 astr_add(&str, _("Progress: no research"));
763 } else {
764 int turns;
765
766 if ((turns = turns_per_advance(research, perturn)) >= 0) {
767 astr_add(&str, PL_("Progress: %d turn/advance",
768 "Progress: %d turns/advance",
769 turns), turns);
770 } else if ((turns = turns_to_tech_loss(research, perturn)) >= 0) {
771 /* FIXME: turns to next loss is not a good predictor of turns to
772 * following loss, due to techloss_restore etc. But it'll do. */
773 astr_add(&str, PL_("Progress: %d turn/advance loss",
774 "Progress: %d turns/advance loss",
775 turns), turns);
776 } else {
777 /* no forward progress -- no research, or tech loss disallowed */
778 if (perturn < 0) {
779 astr_add(&str, _("Progress: decreasing!"));
780 } else {
781 astr_add(&str, _("Progress: none"));
782 }
783 }
784 }
785 astr_set(&ourbuf, PL_("%d bulb/turn", "%d bulbs/turn", ours), ours);
786 if (team) {
787 /* Techpool version */
788 astr_set(&theirbuf,
789 /* TRANS: This is appended to "%d bulb/turn" text */
790 PL_(", %d bulb/turn from team",
791 ", %d bulbs/turn from team", theirs), theirs);
792 } else {
793 astr_clear(&theirbuf);
794 }
795 astr_add(&str, " (%s%s)", astr_str(&ourbuf), astr_str(&theirbuf));
796 astr_free(&ourbuf);
797 astr_free(&theirbuf);
798
799 if (game.info.tech_upkeep_style != TECH_UPKEEP_NONE) {
800 /* perturn is defined as: (bulbs produced) - upkeep */
801 astr_add_line(&str, _("Bulbs produced per turn: %d"), perturn + upkeep);
802 /* TRANS: keep leading space; appended to "Bulbs produced per turn: %d" */
803 astr_add(&str, _(" (needed for technology upkeep: %d)"), upkeep);
804 }
805
806 return astr_str(&str);
807}
808
809/************************************************************************/
820 const char *get_science_target_text(double *percent)
821{
822 struct research *research = research_get(client_player());
823 static struct astring str = ASTRING_INIT;
824
825 if (!research) {
826 return "-";
827 }
828
829 astr_clear(&str);
830 if (research->researching == A_UNSET) {
831 astr_add(&str, _("%d/- (never)"), research->bulbs_researched);
832 if (percent) {
833 *percent = 0.0;
834 }
835 } else {
836 int total = research->client.researching_cost;
837 int done = research->bulbs_researched;
838 int perturn = get_bulbs_per_turn(NULL, NULL, NULL);
839 int turns;
840
841 if ((turns = turns_to_research_done(research, perturn)) >= 0) {
842 astr_add(&str, PL_("%d/%d (%d turn)", "%d/%d (%d turns)", turns),
843 done, total, turns);
844 } else if ((turns = turns_to_tech_loss(research, perturn)) >= 0) {
845 astr_add(&str, PL_("%d/%d (%d turn to loss)",
846 "%d/%d (%d turns to loss)", turns),
847 done, total, turns);
848 } else {
849 /* no forward progress -- no research, or tech loss disallowed */
850 astr_add(&str, _("%d/%d (never)"), done, total);
851 }
852 if (percent) {
853 *percent = (double)done / (double)total;
854 *percent = CLIP(0.0, *percent, 1.0);
855 }
856 }
857
858 return astr_str(&str);
859}
860
861/************************************************************************/
866 const char *get_science_goal_text(Tech_type_id goal)
867{
868 const struct research *research = research_get(client_player());
869 int steps = research_goal_unknown_techs(research, goal);
870 int bulbs_needed = research_goal_bulbs_required(research, goal);
871 int turns;
872 int perturn = get_bulbs_per_turn(NULL, NULL, NULL);
873 static struct astring str = ASTRING_INIT;
874 struct astring buf1 = ASTRING_INIT,
875 buf2 = ASTRING_INIT,
876 buf3 = ASTRING_INIT;
877
878 if (!research) {
879 return "-";
880 }
881
882 astr_clear(&str);
883
884 if (research_goal_tech_req(research, goal, research->researching)
885 || research->researching == goal) {
886 bulbs_needed -= research->bulbs_researched;
887 }
888
889 astr_set(&buf1,
890 PL_("%d step", "%d steps", steps), steps);
891 astr_set(&buf2,
892 PL_("%d bulb", "%d bulbs", bulbs_needed), bulbs_needed);
893 if (perturn > 0) {
894 turns = (bulbs_needed + perturn - 1) / perturn;
895 astr_set(&buf3,
896 PL_("%d turn", "%d turns", turns), turns);
897 } else {
898 astr_set(&buf3, _("never"));
899 }
900 astr_add_line(&str, "(%s - %s - %s)",
901 astr_str(&buf1), astr_str(&buf2), astr_str(&buf3));
902 astr_free(&buf1);
903 astr_free(&buf2);
904 astr_free(&buf3);
905
906 return astr_str(&str);
907}
908
909/************************************************************************/
917 const char *get_info_label_text(bool moreinfo)
918{
919 static struct astring str = ASTRING_INIT;
920
921 astr_clear(&str);
922
923 if (NULL != client.conn.playing) {
924 astr_add_line(&str, _("Population: %s"),
925 population_to_text(civ_population(client.conn.playing)));
926 }
927 astr_add_line(&str, _("Year: %s (T%d)"),
928 calendar_text(), game.info.turn);
929
930 if (NULL != client.conn.playing) {
931 astr_add_line(&str, _("Gold: %d (%+d)"),
932 client.conn.playing->economic.gold,
933 player_get_expected_income(client.conn.playing));
934 astr_add_line(&str, _("Tax: %d Lux: %d Sci: %d"),
935 client.conn.playing->economic.tax,
936 client.conn.playing->economic.luxury,
937 client.conn.playing->economic.science);
938 }
939 if (game.info.phase_mode == PMT_PLAYERS_ALTERNATE) {
940 if (game.info.phase < 0 || game.info.phase >= player_count()) {
941 astr_add_line(&str, _("Moving: Nobody"));
942 } else {
943 astr_add_line(&str, _("Moving: %s"),
944 player_name(player_by_number(game.info.phase)));
945 }
946 } else if (game.info.phase_mode == PMT_TEAMS_ALTERNATE) {
947 if (game.info.phase < 0 || game.info.phase >= team_count()) {
948 astr_add_line(&str, _("Moving: Nobody"));
949 } else {
950 astr_add_line(&str, _("Moving: %s"),
951 team_name_translation(team_by_number(game.info.phase)));
952 }
953 }
954
955 if (moreinfo) {
956 astr_add_line(&str, _("(Click for more info)"));
957 }
958
959 return astr_str(&str);
960}
961
962/************************************************************************/
969 const char *get_info_label_text_popup(void)
970{
971 static struct astring str = ASTRING_INIT;
972
973 astr_clear(&str);
974
975 if (NULL != client.conn.playing) {
976 astr_add_line(&str, _("%s People"),
977 population_to_text(civ_population(client.conn.playing)));
978 }
979 astr_add_line(&str, _("Year: %s"), calendar_text());
980 astr_add_line(&str, _("Turn: %d"), game.info.turn);
981
982 if (NULL != client.conn.playing) {
983 const struct research *presearch = research_get(client_player());
984 int perturn = get_bulbs_per_turn(NULL, NULL, NULL);
985 int upkeep = client_player()->client.tech_upkeep;
986
987 astr_add_line(&str, _("Gold: %d"),
988 client.conn.playing->economic.gold);
989 astr_add_line(&str, _("Net Income: %d"),
990 player_get_expected_income(client.conn.playing));
991 /* TRANS: Gold, luxury, and science rates are in percentage values. */
992 astr_add_line(&str, _("Tax rates: Gold:%d%% Luxury:%d%% Science:%d%%"),
993 client.conn.playing->economic.tax,
994 client.conn.playing->economic.luxury,
995 client.conn.playing->economic.science);
996 astr_add_line(&str, _("Researching %s: %s"),
997 research_advance_name_translation(presearch,
998 presearch->researching),
999 get_science_target_text(NULL));
1000 /* perturn is defined as: (bulbs produced) - upkeep */
1001 if (game.info.tech_upkeep_style != TECH_UPKEEP_NONE) {
1002 astr_add_line(&str, _("Bulbs per turn: %d - %d = %d"), perturn + upkeep,
1003 upkeep, perturn);
1004 } else {
1005 fc_assert(upkeep == 0);
1006 astr_add_line(&str, _("Bulbs per turn: %d"), perturn);
1007 }
1008 {
1009 int history_perturn = nation_history_gain(client.conn.playing);
1010
1011 city_list_iterate(client.conn.playing->cities, pcity) {
1012 history_perturn += city_history_gain(pcity);
1013 } city_list_iterate_end;
1014 astr_add_line(&str, _("Culture: %d (%+d/turn)"),
1015 client.conn.playing->client.culture, history_perturn);
1016 }
1017 }
1018
1019 /* See also get_global_warming_tooltip() and get_nuclear_winter_tooltip(). */
1020
1021 if (game.info.global_warming) {
1022 int chance, rate;
1023 global_warming_scaled(&chance, &rate, 100);
1024 astr_add_line(&str, _("Global warming chance: %d%% (%+d%%/turn)"),
1025 chance, rate);
1026 } else {
1027 astr_add_line(&str, _("Global warming deactivated."));
1028 }
1029
1030 if (game.info.nuclear_winter) {
1031 int chance, rate;
1032 nuclear_winter_scaled(&chance, &rate, 100);
1033 astr_add_line(&str, _("Nuclear winter chance: %d%% (%+d%%/turn)"),
1034 chance, rate);
1035 } else {
1036 astr_add_line(&str, _("Nuclear winter deactivated."));
1037 }
1038
1039 if (NULL != client.conn.playing) {
1040 astr_add_line(&str, _("Government: %s"),
1041 government_name_for_player(client.conn.playing));
1042 }
1043
1044 return astr_str(&str);
1045}
1046
1047/************************************************************************/
1054 const char *get_unit_info_label_text1(struct unit_list *punits)
1055{
1056 static struct astring str = ASTRING_INIT;
1057
1058 astr_clear(&str);
1059
1060 if (punits) {
1061 int count = unit_list_size(punits);
1062
1063 if (count == 1) {
1064 astr_add(&str, "%s", unit_name_translation(unit_list_get(punits, 0)));
1065 } else {
1066 astr_add(&str, PL_("%d unit", "%d units", count), count);
1067 }
1068 }
1069 return astr_str(&str);
1070}
1071
1072/************************************************************************/
1079 const char *get_unit_info_label_text2(struct unit_list *punits, int linebreaks)
1080{
1081 static struct astring str = ASTRING_INIT;
1082 int count;
1083
1084 astr_clear(&str);
1085
1086 if (!punits) {
1087 return "";
1088 }
1089
1090 count = unit_list_size(punits);
1091
1092 /* This text should always have the same number of lines if
1093 * 'linebreaks' has no flags at all. Otherwise the GUI widgets may be
1094 * confused and try to resize themselves. If caller asks for
1095 * conditional 'linebreaks', it should take care of these problems
1096 * itself. */
1097
1098 /* Line 1. Goto or activity text. */
1099 if (count > 0 && hover_state != HOVER_NONE) {
1100 int min, max;
1101
1102 if (!goto_get_turns(&min, &max)) {
1103 /* TRANS: Impossible to reach goto target tile */
1104 astr_add_line(&str, "%s", Q_("?goto:Unreachable"));
1105 } else if (min == max) {
1106 astr_add_line(&str, _("Turns to target: %d"), max);
1107 } else {
1108 astr_add_line(&str, _("Turns to target: %d to %d"), min, max);
1109 }
1110 } else if (count == 1) {
1111 struct astring addition = ASTRING_INIT;
1112
1113 unit_activity_astr(unit_list_get(punits, 0), &addition);
1114 astr_add_line(&str, "%s", astr_str(&addition));
1115 astr_free(&addition);
1116 } else if (count > 1) {
1117 astr_add_line(&str, PL_("%d unit selected",
1118 "%d units selected",
1119 count),
1120 count);
1121 } else {
1122 astr_add_line(&str, _("No units selected."));
1123 }
1124
1125 /* Lines 2, 3, 4, and possible 5 vary. */
1126 if (count == 1) {
1127 struct unit *punit = unit_list_get(punits, 0);
1128 struct player *owner = unit_owner(punit);
1129 struct city *pcity = player_city_by_number(owner,
1130 punit->homecity);
1131
1132 astr_add_line(&str, "%s", tile_get_info_text(unit_tile(punit), TRUE,
1133 linebreaks));
1134 {
1135 const char *infratext = get_infrastructure_text(unit_tile(punit)->extras);
1136
1137 if (*infratext != '\0') {
1138 astr_add_line(&str, "%s", infratext);
1139 } else {
1140 astr_add_line(&str, " ");
1141 }
1142 }
1143 if (pcity) {
1144 astr_add_line(&str, "%s", city_name_get(pcity));
1145 } else {
1146 astr_add_line(&str, " ");
1147 }
1148
1149 if (game.info.citizen_nationality) {
1150 struct player *nationality = unit_nationality(punit);
1151
1152 /* Line 5, nationality text */
1153 if (nationality != NULL && owner != nationality) {
1154 /* TRANS: Nationality of the people comprising a unit, if
1155 * different from owner. */
1156 astr_add_line(&str, _("%s people"),
1157 nation_adjective_for_player(nationality));
1158 } else {
1159 astr_add_line(&str, " ");
1160 }
1161 }
1162
1163 } else if (count > 1) {
1164 int mil = 0, nonmil = 0;
1165 int types_count[U_LAST], i;
1166 struct unit_type *top[3];
1167
1168 memset(types_count, 0, sizeof(types_count));
1169 unit_list_iterate(punits, punit) {
1170 if (unit_has_type_flag(punit, UTYF_CIVILIAN)) {
1171 nonmil++;
1172 } else {
1173 mil++;
1174 }
1175 types_count[utype_index(unit_type_get(punit))]++;
1176 } unit_list_iterate_end;
1177
1178 top[0] = top[1] = top[2] = NULL;
1179 unit_type_iterate(utype) {
1180 if (!top[2]
1181 || types_count[utype_index(top[2])] < types_count[utype_index(utype)]) {
1182 top[2] = utype;
1183
1184 if (!top[1]
1185 || types_count[utype_index(top[1])] < types_count[utype_index(top[2])]) {
1186 top[2] = top[1];
1187 top[1] = utype;
1188
1189 if (!top[0]
1190 || types_count[utype_index(top[0])] < types_count[utype_index(utype)]) {
1191 top[1] = top[0];
1192 top[0] = utype;
1193 }
1194 }
1195 }
1196 } unit_type_iterate_end;
1197
1198 for (i = 0; i < 2; i++) {
1199 if (top[i] && types_count[utype_index(top[i])] > 0) {
1200 if (utype_has_flag(top[i], UTYF_CIVILIAN)) {
1201 nonmil -= types_count[utype_index(top[i])];
1202 } else {
1203 mil -= types_count[utype_index(top[i])];
1204 }
1205 astr_add_line(&str, "%d: %s",
1206 types_count[utype_index(top[i])],
1207 utype_name_translation(top[i]));
1208 } else {
1209 astr_add_line(&str, " ");
1210 }
1211 }
1212
1213 if (top[2] && types_count[utype_index(top[2])] > 0
1214 && types_count[utype_index(top[2])] == nonmil + mil) {
1215 astr_add_line(&str, "%d: %s", types_count[utype_index(top[2])],
1216 utype_name_translation(top[2]));
1217 } else if (nonmil > 0 && mil > 0) {
1218 astr_add_line(&str, _("Others: %d civil; %d military"), nonmil, mil);
1219 } else if (nonmil > 0) {
1220 astr_add_line(&str, _("Others: %d civilian"), nonmil);
1221 } else if (mil > 0) {
1222 astr_add_line(&str, _("Others: %d military"), mil);
1223 } else {
1224 astr_add_line(&str, " ");
1225 }
1226
1227 if (game.info.citizen_nationality) {
1228 astr_add_line(&str, " ");
1229 }
1230 } else {
1231 astr_add_line(&str, " ");
1232 astr_add_line(&str, " ");
1233 astr_add_line(&str, " ");
1234
1235 if (game.info.citizen_nationality) {
1236 astr_add_line(&str, " ");
1237 }
1238 }
1239
1240 /* Line 5/6. Debug text. */
1241#ifdef FREECIV_DEBUG
1242 if (count == 1) {
1243 astr_add_line(&str, "(Unit ID %d)", unit_list_get(punits, 0)->id);
1244 } else {
1245 astr_add_line(&str, " ");
1246 }
1247#endif /* FREECIV_DEBUG */
1248
1249 return astr_str(&str);
1250}
1251
1252/************************************************************************/
1257 bool get_units_upgrade_info(char *buf, size_t bufsz,
1258 struct unit_list *punits)
1259{
1260 if (unit_list_size(punits) == 0) {
1261 fc_snprintf(buf, bufsz, _("No units to upgrade!"));
1262 return FALSE;
1263 } else if (unit_list_size(punits) == 1) {
1264 return (UU_OK == unit_upgrade_info(&(wld.map), unit_list_front(punits), buf, bufsz));
1265 } else {
1266 int upgrade_cost = 0;
1267 int num_upgraded = 0;
1268 int min_upgrade_cost = FC_INFINITY;
1269
1270 unit_list_iterate(punits, punit) {
1271 if (unit_owner(punit) == client_player()
1272 && UU_OK == unit_upgrade_test(&(wld.map), punit, FALSE)) {
1273 const struct unit_type *from_unittype = unit_type_get(punit);
1274 const struct unit_type *to_unittype = can_upgrade_unittype(client.conn.playing,
1275 from_unittype);
1276 int cost = unit_upgrade_price(unit_owner(punit),
1277 from_unittype, to_unittype);
1278
1279 num_upgraded++;
1280 upgrade_cost += cost;
1281 min_upgrade_cost = MIN(min_upgrade_cost, cost);
1282 }
1283 } unit_list_iterate_end;
1284 if (num_upgraded == 0) {
1285 fc_snprintf(buf, bufsz, _("None of these units may be upgraded."));
1286 return FALSE;
1287 } else {
1288 /* This may trigger sometimes if you don't have enough money for
1289 * a full upgrade. If you have enough to upgrade at least one, it
1290 * will do it. */
1291 /* Construct prompt in several parts to allow separate pluralisation
1292 * by localizations */
1293 char tbuf[MAX_LEN_MSG], ubuf[MAX_LEN_MSG];
1294
1295 fc_snprintf(tbuf, ARRAY_SIZE(tbuf), PL_("Treasury contains %d gold.",
1296 "Treasury contains %d gold.",
1297 client_player()->economic.gold),
1298 client_player()->economic.gold);
1299 /* TRANS: this whole string is a sentence fragment that is only ever
1300 * used by including it in another string (search comments for this
1301 * string to find it) */
1302 fc_snprintf(ubuf, ARRAY_SIZE(ubuf), PL_("Upgrade %d unit",
1303 "Upgrade %d units",
1304 num_upgraded),
1305 num_upgraded);
1306 /* TRANS: This is complicated. The first %s is a pre-pluralised
1307 * sentence fragment "Upgrade %d unit(s)"; the second is pre-pluralised
1308 * "Treasury contains %d gold." So the whole thing reads
1309 * "Upgrade 13 units for 1000 gold?\nTreasury contains 2000 gold." */
1310 fc_snprintf(buf, bufsz, PL_("%s for %d gold?\n%s",
1311 "%s for %d gold?\n%s", upgrade_cost),
1312 ubuf, upgrade_cost, tbuf);
1313 return TRUE;
1314 }
1315 }
1316}
1317
1318/************************************************************************/
1323 bool get_units_disband_info(char *buf, size_t bufsz,
1324 struct unit_list *punits)
1325{
1326 if (unit_list_size(punits) == 0) {
1327 fc_snprintf(buf, bufsz, _("No units to disband!"));
1328 return FALSE;
1329 } else if (unit_list_size(punits) == 1) {
1330 if (!unit_can_do_action(unit_list_front(punits),
1331 ACTION_DISBAND_UNIT)) {
1332 fc_snprintf(buf, bufsz, _("%s refuses to disband!"),
1333 unit_name_translation(unit_list_front(punits)));
1334 return FALSE;
1335 } else {
1336 /* TRANS: %s is a unit type */
1337 fc_snprintf(buf, bufsz, _("Disband %s?"),
1338 unit_name_translation(unit_list_front(punits)));
1339 return TRUE;
1340 }
1341 } else {
1342 int count = 0;
1343
1344 unit_list_iterate(punits, punit) {
1345 if (unit_can_do_action(punit, ACTION_DISBAND_UNIT)) {
1346 count++;
1347 }
1348 } unit_list_iterate_end;
1349 if (count == 0) {
1350 fc_snprintf(buf, bufsz, _("None of these units may be disbanded."));
1351 return FALSE;
1352 } else {
1353 /* TRANS: %d is never 0 or 1 */
1354 fc_snprintf(buf, bufsz, PL_("Disband %d unit?",
1355 "Disband %d units?", count), count);
1356 return TRUE;
1357 }
1358 }
1359}
1360
1361/************************************************************************/
1367 const char *get_bulb_tooltip(void)
1368{
1369 static struct astring str = ASTRING_INIT;
1370
1371 astr_clear(&str);
1372
1373 astr_add_line(&str, _("Shows your progress in "
1374 "researching the current technology."));
1375
1376 if (NULL != client.conn.playing) {
1377 struct research *research = research_get(client_player());
1378
1379 if (research->researching == A_UNSET) {
1380 astr_add_line(&str, _("No research target."));
1381 } else {
1382 int turns;
1383 int perturn = get_bulbs_per_turn(NULL, NULL, NULL);
1384 struct astring buf1 = ASTRING_INIT, buf2 = ASTRING_INIT;
1385
1386 if ((turns = turns_to_research_done(research, perturn)) >= 0) {
1387 astr_set(&buf1, PL_("%d turn", "%d turns", turns), turns);
1388 } else if ((turns = turns_to_tech_loss(research, perturn)) >= 0) {
1389 astr_set(&buf1, PL_("%d turn to loss", "%d turns to loss", turns),
1390 turns);
1391 } else {
1392 if (perturn < 0) {
1393 astr_set(&buf1, _("Decreasing"));
1394 } else {
1395 astr_set(&buf1, _("No progress"));
1396 }
1397 }
1398
1399 /* TRANS: <perturn> bulbs/turn */
1400 astr_set(&buf2, PL_("%d bulb/turn", "%d bulbs/turn", perturn), perturn);
1401
1402 /* TRANS: <tech>: <amount>/<total bulbs> */
1403 astr_add_line(&str, _("%s: %d/%d (%s, %s)."),
1404 research_advance_name_translation(research,
1405 research->researching),
1406 research->bulbs_researched,
1407 research->client.researching_cost,
1408 astr_str(&buf1), astr_str(&buf2));
1409
1410 astr_free(&buf1);
1411 astr_free(&buf2);
1412 }
1413 }
1414
1415 return astr_str(&str);
1416}
1417
1418/************************************************************************/
1424 const char *get_global_warming_tooltip(void)
1425{
1426 static struct astring str = ASTRING_INIT;
1427
1428 astr_clear(&str);
1429
1430 if (!game.info.global_warming) {
1431 astr_add_line(&str, _("Global warming deactivated."));
1432 } else {
1433 int chance, rate;
1434
1435 global_warming_scaled(&chance, &rate, 100);
1436 astr_add_line(&str, _("Shows the progress of global warming:"));
1437 astr_add_line(&str, _("Pollution rate: %d%%"), rate);
1438 astr_add_line(&str, _("Chance of catastrophic warming each turn: %d%%"),
1439 chance);
1440 }
1441
1442 return astr_str(&str);
1443}
1444
1445/************************************************************************/
1451 const char *get_nuclear_winter_tooltip(void)
1452{
1453 static struct astring str = ASTRING_INIT;
1454
1455 astr_clear(&str);
1456
1457 if (!game.info.nuclear_winter) {
1458 astr_add_line(&str, _("Nuclear winter deactivated."));
1459 } else {
1460 int chance, rate;
1461
1462 nuclear_winter_scaled(&chance, &rate, 100);
1463 astr_add_line(&str, _("Shows the progress of nuclear winter:"));
1464 astr_add_line(&str, _("Fallout rate: %d%%"), rate);
1465 astr_add_line(&str, _("Chance of catastrophic winter each turn: %d%%"),
1466 chance);
1467 }
1468
1469 return astr_str(&str);
1470}
1471
1472/************************************************************************/
1478 const char *get_government_tooltip(void)
1479{
1480 static struct astring str = ASTRING_INIT;
1481
1482 astr_clear(&str);
1483
1484 astr_add_line(&str, _("Shows your current government:"));
1485
1486 if (NULL != client.conn.playing) {
1487 astr_add_line(&str, "%s",
1488 government_name_for_player(client.conn.playing));
1489 }
1490
1491 return astr_str(&str);
1492}
1493
1494/************************************************************************/
1500 const char *get_spaceship_descr(struct player_spaceship *pship)
1501{
1502 struct player_spaceship ship;
1503 static struct astring str = ASTRING_INIT;
1504
1505 astr_clear(&str);
1506
1507 if (!pship) {
1508 pship = &ship;
1509 memset(&ship, 0, sizeof(ship));
1510 }
1511
1512 /* TRANS: spaceship text; should have constant width. */
1513 astr_add_line(&str, _("Population: %5d"), pship->population);
1514
1515 /* TRANS: spaceship text; should have constant width. */
1516 astr_add_line(&str, _("Support: %5d %%"),
1517 (int) (pship->support_rate * 100.0));
1518
1519 /* TRANS: spaceship text; should have constant width. */
1520 astr_add_line(&str, _("Energy: %5d %%"),
1521 (int) (pship->energy_rate * 100.0));
1522
1523 /* TRANS: spaceship text; should have constant width. */
1524 astr_add_line(&str, PL_("Mass: %5d ton",
1525 "Mass: %5d tons",
1526 pship->mass), pship->mass);
1527
1528 if (pship->propulsion > 0) {
1529 /* TRANS: spaceship text; should have constant width. */
1530 astr_add_line(&str, _("Travel time: %5.1f years"),
1531 (float) (0.1 * ((int) (pship->travel_time * 10.0))));
1532 } else {
1533 /* TRANS: spaceship text; should have constant width. */
1534 astr_add_line(&str, "%s", _("Travel time: N/A "));
1535 }
1536
1537 /* TRANS: spaceship text; should have constant width. */
1538 astr_add_line(&str, _("Success prob.: %5d %%"),
1539 (int) (pship->success_rate * 100.0));
1540
1541 /* TRANS: spaceship text; should have constant width. */
1542 astr_add_line(&str, _("Year of arrival: %8s"),
1543 (pship->state == SSHIP_LAUNCHED)
1544 ? textyear((int) (pship->launch_year +
1545 (int) pship->travel_time))
1546 : "- ");
1547
1548 return astr_str(&str);
1549}
1550
1551/************************************************************************/
1557 const char *get_timeout_label_text(void)
1558{
1559 static struct astring str = ASTRING_INIT;
1560
1561 astr_clear(&str);
1562
1563 if (is_waiting_turn_change() && game.tinfo.last_turn_change_time >= 1.5) {
1564 int wt = get_seconds_to_new_turn();
1565
1566 if (wt <= 0) {
1567 astr_add(&str, "%s", Q_("?timeout:wait"));
1568 } else {
1569 astr_add(&str, "%s: %s", Q_("?timeout:eta"), format_duration(wt));
1570 }
1571 } else {
1572 if (current_turn_timeout() <= 0) {
1573 astr_add(&str, "%s", Q_("?timeout:off"));
1574 } else {
1575 astr_add(&str, "%s", format_duration(get_seconds_to_turndone()));
1576 }
1577 }
1578
1579 return astr_str(&str);
1580}
1581
1582/************************************************************************/
1590 static const char *format_duration(int duration)
1591{
1592 static struct astring str = ASTRING_INIT;
1593
1594 astr_clear(&str);
1595
1596 if (duration < 0) {
1597 duration = 0;
1598 }
1599 if (duration < 60) {
1600 astr_add(&str, Q_("?seconds:%02ds"), duration);
1601 } else if (duration < 3600) { /* < 60 minutes */
1602 astr_add(&str, Q_("?mins/secs:%02dm %02ds"), duration / 60, duration % 60);
1603 } else if (duration < 360000) { /* < 100 hours */
1604 astr_add(&str, Q_("?hrs/mns:%02dh %02dm"), duration / 3600, (duration / 60) % 60);
1605 } else if (duration < 8640000) { /* < 100 days */
1606 astr_add(&str, Q_("?dys/hrs:%02dd %02dh"), duration / 86400,
1607 (duration / 3600) % 24);
1608 } else {
1609 astr_add(&str, "%s", Q_("?duration:overflow"));
1610 }
1611
1612 return astr_str(&str);
1613}
1614
1615/************************************************************************/
1621 const char *get_ping_time_text(const struct player *pplayer)
1622{
1623 static struct astring str = ASTRING_INIT;
1624
1625 astr_clear(&str);
1626
1627 conn_list_iterate(pplayer->connections, pconn) {
1628 if (!pconn->observer
1629 /* Certainly not needed, but safer. */
1630 && 0 == strcmp(pconn->username, pplayer->username)) {
1631 if (pconn->ping_time >= 0) {
1632 double ping_time_in_ms = 1000 * pconn->ping_time;
1633
1634 astr_add(&str, _("%6d.%02d ms"), (int) ping_time_in_ms,
1635 ((int) (ping_time_in_ms * 100.0)) % 100);
1636 }
1637 break;
1638 }
1639 } conn_list_iterate_end;
1640
1641 return astr_str(&str);
1642}
1643
1644/************************************************************************/
1650 const char *get_score_text(const struct player *pplayer)
1651{
1652 static struct astring str = ASTRING_INIT;
1653
1654 astr_clear(&str);
1655
1656 if (pplayer->score.game >= 0) {
1657 astr_add(&str, "%d", pplayer->score.game);
1658 } else {
1659 astr_add(&str, "?");
1660 }
1661
1662 return astr_str(&str);
1663}
1664
1665/************************************************************************/
1672 const char *get_report_title(const char *report_name)
1673{
1674 static struct astring str = ASTRING_INIT;
1675 const struct player *pplayer = client_player();
1676
1677 astr_clear(&str);
1678
1679 astr_add_line(&str, "%s", report_name);
1680
1681 if (pplayer != NULL) {
1682 char buf[4 * MAX_LEN_NAME];
1683
1684 /* TRANS: <nation adjective> <government name>.
1685 * E.g. "Polish Republic". */
1686 astr_add_line(&str, Q_("?nationgovernment:%s %s"),
1687 nation_adjective_for_player(pplayer),
1688 government_name_for_player(pplayer));
1689
1690 /* TRANS: Just appending 2 strings, using the correct localized
1691 * syntax. */
1692 astr_add_line(&str, _("%s - %s"),
1693 ruler_title_for_player(pplayer, buf, sizeof(buf)),
1694 calendar_text());
1695 } else {
1696 /* TRANS: "Observer - 1985 AD" */
1697 astr_add_line(&str, _("Observer - %s"),
1698 calendar_text());
1699 }
1700
1701 return astr_str(&str);
1702}
1703
1704/**********************************************************************/
1710 const char *get_act_sel_action_custom_text(struct action *paction,
1711 const struct act_prob prob,
1712 const struct unit *actor_unit,
1713 const struct city *target_city)
1714{
1715 static struct astring custom = ASTRING_INIT;
1716
1717 struct city *actor_homecity = unit_home(actor_unit);
1718
1719 if (!action_prob_possible(prob)) {
1720 /* No info since impossible. */
1721 return NULL;
1722 }
1723
1724 fc_assert_ret_val((action_get_target_kind(paction) != ATK_CITY
1725 || target_city != NULL),
1726 NULL);
1727
1728 if (action_has_result(paction, ACTRES_TRADE_ROUTE)) {
1729 int revenue = get_caravan_enter_city_trade_bonus(actor_homecity,
1730 target_city,
1731 unit_type_get(actor_unit),
1732 actor_unit->carrying,
1733 TRUE);
1734
1735 if (revenue > 0) {
1736 astr_set(&custom,
1737 /* TRANS: Estimated one time bonus and recurring revenue for
1738 * the Establish Trade _Route action. */
1739 _("%d one time bonus + %d trade"),
1740 revenue,
1741 trade_base_between_cities(actor_homecity, target_city));
1742 } else {
1743 astr_set(&custom,
1744 /* TRANS: Estimated recurring revenue for
1745 * the Establish Trade _Route action. */
1746 _("%d trade"),
1747 trade_base_between_cities(actor_homecity, target_city));
1748 }
1749 } else if (action_has_result(paction, ACTRES_MARKETPLACE)) {
1750 int revenue = get_caravan_enter_city_trade_bonus(actor_homecity,
1751 target_city,
1752 unit_type_get(actor_unit),
1753 actor_unit->carrying,
1754 FALSE);
1755
1756 if (revenue > 0) {
1757 astr_set(&custom,
1758 /* TRANS: Estimated one time bonus for the Enter Marketplace
1759 * action. */
1760 _("%d one time bonus"), revenue);
1761 } else {
1762 /* No info to add. */
1763 return NULL;
1764 }
1765 } else if ((action_has_result(paction, ACTRES_HELP_WONDER)
1766 || action_has_result(paction, ACTRES_DISBAND_UNIT_RECOVER))
1767 && city_owner(target_city) == client.conn.playing) {
1768 /* Can only give remaining production for domestic and existing
1769 * cities. */
1770 int cost = city_production_build_shield_cost(target_city);
1771
1772 astr_set(&custom, _("%d remaining"), cost - target_city->shield_stock);
1773 } else {
1774 /* No info to add. */
1775 return NULL;
1776 }
1777
1778 return astr_str(&custom);
1779}
1780
1781/**********************************************************************/
1789 const char *act_sel_action_tool_tip(const struct action *paction,
1790 const struct act_prob prob)
1791{
1792 return action_prob_explain(prob);
1793}
1794
1795/************************************************************************/
1800 const char *text_happiness_buildings(const struct city *pcity)
1801{
1802 struct effect_list *plist = effect_list_new();
1803 static struct astring str = ASTRING_INIT;
1804
1805 get_city_bonus_effects(plist, pcity, NULL, EFT_MAKE_CONTENT);
1806 if (0 < effect_list_size(plist)) {
1807 struct astring effects = ASTRING_INIT;
1808
1809 get_effect_list_req_text(plist, &effects);
1810 astr_set(&str, _("Buildings: %s."), astr_str(&effects));
1811 astr_free(&effects);
1812 } else {
1813 astr_set(&str, _("Buildings: None."));
1814 }
1815 effect_list_destroy(plist);
1816
1817 /* Add line breaks after 80 characters. */
1818 astr_break_lines(&str, 80);
1819
1820 return astr_str(&str);
1821}
1822
1823/************************************************************************/
1828 const char *text_happiness_nationality(const struct city *pcity)
1829{
1830 static struct astring str = ASTRING_INIT;
1831 int enemies = 0;
1832
1833 astr_clear(&str);
1834
1835 astr_add_line(&str, _("Nationality: "));
1836
1837 if (game.info.citizen_nationality) {
1838 if (get_city_bonus(pcity, EFT_ENEMY_CITIZEN_UNHAPPY_PCT) > 0) {
1839 struct player *owner = city_owner(pcity);
1840
1841 citizens_foreign_iterate(pcity, pslot, nationality) {
1842 if (pplayers_at_war(owner, player_slot_get_player(pslot))) {
1843 enemies += nationality;
1844 }
1845 } citizens_foreign_iterate_end;
1846
1847 if (enemies > 0) {
1848 astr_add(&str, PL_("%d enemy nationalist", "%d enemy nationalists", enemies),
1849 enemies);
1850 }
1851 }
1852
1853 if (enemies == 0) {
1854 /* TRANS: No enemy nationalities, as there's no enemies present. */
1855 astr_add(&str, _("None."));
1856 }
1857 } else {
1858 /* TRANS: No nationalities present. */
1859 astr_add(&str, _("Disabled."));
1860 }
1861
1862 return astr_str(&str);
1863}
1864
1865/************************************************************************/
1870 const char *text_happiness_wonders(const struct city *pcity)
1871{
1872 struct effect_list *plist = effect_list_new();
1873 static struct astring str = ASTRING_INIT;
1874
1875 get_city_bonus_effects(plist, pcity, NULL, EFT_MAKE_HAPPY);
1876 get_city_bonus_effects(plist, pcity, NULL, EFT_FORCE_CONTENT);
1877 get_city_bonus_effects(plist, pcity, NULL, EFT_NO_UNHAPPY);
1878 if (0 < effect_list_size(plist)) {
1879 struct astring effects = ASTRING_INIT;
1880
1881 get_effect_list_req_text(plist, &effects);
1882 astr_set(&str, _("Wonders: %s."), astr_str(&effects));
1883 astr_free(&effects);
1884 } else {
1885 astr_set(&str, _("Wonders: None."));
1886 }
1887
1888 /* Add line breaks after 80 characters. */
1889 astr_break_lines(&str, 80);
1890 effect_list_destroy(plist);
1891
1892 return astr_str(&str);
1893}
1894
1895/************************************************************************/
1900 const char *text_happiness_cities(const struct city *pcity)
1901{
1902 struct player *pplayer = city_owner(pcity);
1903 int cities = city_list_size(pplayer->cities);
1904 int content = get_player_bonus(pplayer, EFT_CITY_UNHAPPY_SIZE);
1905 int basis = get_player_bonus(pplayer, EFT_EMPIRE_SIZE_BASE);
1906 int step = get_player_bonus(pplayer, EFT_EMPIRE_SIZE_STEP);
1907 static struct astring str = ASTRING_INIT;
1908
1909 astr_clear(&str);
1910
1911 if (basis+step <= 0) {
1912 /* Special case where penalty is disabled; see
1913 * player_content_citizens(). */
1914 astr_add_line(&str,
1915 PL_("Cities: %d total, but no penalty for empire size.",
1916 "Cities: %d total, but no penalty for empire size.",
1917 cities),
1918 cities);
1919 astr_add_line(&str,
1920 /* TRANS: %d is number of citizens */
1921 PL_("%d content per city.",
1922 "%d content per city.", content),
1923 content);
1924 } else {
1925 /* Can have up to and including 'basis' cities without penalty */
1926 int excess = MAX(cities - basis, 0);
1927 int penalty;
1928 int unhappy, angry;
1929 int last, next;
1930
1931 if (excess > 0) {
1932 if (step > 0) {
1933 penalty = 1 + (excess - 1) / step;
1934 } else {
1935 penalty = 1;
1936 }
1937 } else {
1938 penalty = 0;
1939 }
1940
1941 unhappy = MIN(penalty, content);
1942 angry = game.info.angrycitizen ? MAX(penalty-content, 0) : 0;
1943 if (penalty >= 1) {
1944 /* 'last' is when last actual malcontent appeared, will saturate
1945 * if no angry citizens */
1946 last = basis + (unhappy+angry-1)*step;
1947 if (!game.info.angrycitizen && unhappy == content) {
1948 /* Maxed out unhappy citizens, so no more penalties */
1949 next = 0;
1950 } else {
1951 /* Angry citizens can continue appearing indefinitely */
1952 next = last + step;
1953 }
1954 } else {
1955 last = 0;
1956 next = basis;
1957 }
1958
1959 astr_add_line(&str,
1960 /* TRANS: sentence fragment, will have text appended */
1961 PL_("Cities: %d total:",
1962 "Cities: %d total:", cities),
1963 cities);
1964 if (excess > 0) {
1965 astr_add(&str,
1966 /* TRANS: appended to "Cities: %d total:"; preserve leading
1967 * space. Pluralized in "nearest threshold of %d cities". */
1968 PL_(" %d over nearest threshold of %d city.",
1969 " %d over nearest threshold of %d cities.", last),
1970 cities - last, last);
1971 astr_add_line(&str,
1972 /* TRANS: Number of content [citizen(s)] ... */
1973 PL_("%d content before penalty.",
1974 "%d content before penalty.", content),
1975 content);
1976 astr_add_line(&str,
1977 PL_("%d additional unhappy citizen.",
1978 "%d additional unhappy citizens.", unhappy),
1979 unhappy);
1980 if (angry > 0) {
1981 astr_add_line(&str,
1982 PL_("%d angry citizen.",
1983 "%d angry citizens.", angry),
1984 angry);
1985 }
1986 } else {
1987 astr_add(&str,
1988 /* TRANS: appended to "Cities: %d total:"; preserve leading
1989 * space. */
1990 PL_(" not more than %d, so no empire size penalty.",
1991 " not more than %d, so no empire size penalty.", next),
1992 next);
1993 astr_add_line(&str,
1994 /* TRANS: %d is number of citizens */
1995 PL_("%d content per city.",
1996 "%d content per city.", content),
1997 content);
1998 }
1999 if (next >= cities && penalty < content) {
2000 astr_add_line(&str,
2001 PL_("With %d more city, another citizen will become "
2002 "unhappy.",
2003 "With %d more cities, another citizen will become "
2004 "unhappy.",
2005 next + 1 - cities),
2006 next + 1 - cities);
2007 } else if (next >= cities) {
2008 /* We maxed out the number of unhappy citizens, but they can get
2009 * angry instead. */
2010 fc_assert(game.info.angrycitizen);
2011 astr_add_line(&str,
2012 PL_("With %d more city, another citizen will become "
2013 "angry.",
2014 "With %d more cities, another citizen will become "
2015 "angry.",
2016 next + 1 - cities),
2017 next + 1 - cities);
2018 } else {
2019 /* Either no Empire_Size_Step, or we maxed out on unhappy citizens
2020 * and ruleset doesn't allow angry ones. */
2021 astr_add_line(&str,
2022 _("More cities will not cause more unhappy citizens."));
2023 }
2024 }
2025
2026 return astr_str(&str);
2027}
2028
2029/************************************************************************/
2034 const char *text_happiness_units(const struct city *pcity)
2035{
2036 int mlmax = get_city_bonus(pcity, EFT_MARTIAL_LAW_MAX);
2037 int uhcfac = get_city_bonus(pcity, EFT_UNHAPPY_FACTOR);
2038 static struct astring str = ASTRING_INIT;
2039
2040 astr_clear(&str);
2041
2042 if (mlmax > 0) {
2043 int mleach = get_city_bonus(pcity, EFT_MARTIAL_LAW_EACH);
2044 if (mlmax == 100) {
2045 astr_add_line(&str, "%s", _("Unlimited martial law in effect."));
2046 } else {
2047 astr_add_line(&str, PL_("%d military unit may impose martial law.",
2048 "Up to %d military units may impose martial "
2049 "law.", mlmax), mlmax);
2050 }
2051 astr_add_line(&str, PL_("Each military unit makes %d "
2052 "unhappy citizen content.",
2053 "Each military unit makes %d "
2054 "unhappy citizens content.",
2055 mleach), mleach);
2056 } else if (uhcfac > 0) {
2057 astr_add_line(&str,
2058 _("Military units in the field may cause unhappiness. "));
2059 } else {
2060 astr_add_line(&str,
2061 _("Military units have no happiness effect. "));
2062 }
2063
2064 return astr_str(&str);
2065}
2066
2067/************************************************************************/
2072 const char *text_happiness_luxuries(const struct city *pcity)
2073{
2074 static struct astring str = ASTRING_INIT;
2075
2076 astr_clear(&str);
2077
2078 astr_add_line(&str,
2079 _("Luxury: %d total."),
2080 pcity->prod[O_LUXURY]);
2081
2082 return astr_str(&str);
2083}
2084
2085/************************************************************************/
2089 const char *production_help(const struct universal *uni, char *buf,
2090 size_t bufsize)
2091{
2092 buf[0] = '\0';
2093 int segments = 0;
2094
2095 if (uni->kind == VUT_UTYPE) {
2096 if (uni->value.utype->helptext != NULL) {
2097 strvec_iterate(uni->value.utype->helptext, text) {
2098 if (segments++) {
2099 cat_snprintf(buf, bufsize, "\n\n");
2100 }
2101 cat_snprintf(buf, bufsize, "%s", _(text));
2102 } strvec_iterate_end;
2103 }
2104 } else {
2105 fc_assert(uni->kind == VUT_IMPROVEMENT);
2106
2107 if (uni->value.building->helptext != NULL) {
2108 strvec_iterate(uni->value.building->helptext, text) {
2109 if (segments++) {
2110 cat_snprintf(buf, bufsize, "\n\n");
2111 }
2112 cat_snprintf(buf, bufsize, "%s", _(text));
2113 } strvec_iterate_end;
2114 }
2115 }
2116
2117 return buf;
2118}
2119
2120/************************************************************************/
2126 const char *score_tooltip(const struct player *pplayer, int score)
2127{
2128 static char buf[1024];
2129 char *relation;
2130
2131 if (client.conn.playing != NULL) {
2132 if (pplayer == client.conn.playing) {
2133 relation = _(" (us)");
2134 } else if (pplayers_allied(pplayer, client.conn.playing)) {
2135 relation = _(" (an ally)");
2136 } else if (player_diplstate_get(pplayer, client.conn.playing)->type == DS_WAR) {
2137 /* Actual enemy; don't want to use pplayers_at_war() that considers also
2138 * never met players enemies. */
2139 relation = _(" (an enemy)");
2140 } else {
2141 relation = "";
2142 }
2143 } else {
2144 relation = "";
2145 }
2146
2147 if (score >= 0) {
2148 /* TRANS: %s is a Nation */
2149 fc_snprintf(buf, sizeof(buf), _("%s%s: score %d"),
2150 nation_adjective_for_player(pplayer), relation,
2151 score);
2152 } else {
2153 fc_snprintf(buf, sizeof(buf), "%s%s",
2154 nation_adjective_for_player(pplayer), relation);
2155 }
2156
2157 return buf;
2158}
action_prob_explain
const char * action_prob_explain(const struct act_prob prob)
Definition actions.c:2175
action_prob_possible
bool action_prob_possible(const struct act_prob probability)
Definition actions.c:5823
action_get_target_kind
enum action_target_kind action_get_target_kind(const struct action *paction)
Definition actions.c:1860
action_has_result
#define action_has_result(_act_, _res_)
Definition actions.h:429
astr_free
void astr_free(struct astring *astr)
Definition astring.c:153
astr_set
void astr_set(struct astring *astr, const char *format,...)
Definition astring.c:267
astr_build_and_list
const char * astr_build_and_list(struct astring *astr, const char *const *items, size_t number)
Definition astring.c:367
astr_add_line
void astr_add_line(struct astring *astr, const char *format,...)
Definition astring.c:299
astr_clear
void astr_clear(struct astring *astr)
Definition astring.c:205
astr_add
void astr_add(struct astring *astr, const char *format,...)
Definition astring.c:287
str
#define str
Definition astring.c:76
astr_break_lines
void astr_break_lines(struct astring *astr, size_t desired_len)
Definition astring.c:318
astring.h
astr_str
static const char * astr_str(const struct astring *astr) fc__attribute((nonnull(1)))
Definition astring.h:93
ASTRING_INIT
#define ASTRING_INIT
Definition astring.h:44
bitvector.h
calendar_text
const char * calendar_text(void)
Definition calendar.c:141
textyear
const char * textyear(int year)
Definition calendar.c:120
calendar.h
citizens.h
citizens_foreign_iterate_end
#define citizens_foreign_iterate_end
Definition citizens.h:63
citizens_foreign_iterate
#define citizens_foreign_iterate(_pcity, _pslot, _nationality)
Definition citizens.h:58
city_production_build_shield_cost
int city_production_build_shield_cost(const struct city *pcity)
Definition city.c:736
city_has_building
bool city_has_building(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:1231
city_name_get
const char * city_name_get(const struct city *pcity)
Definition city.c:1128
city_airlift_max
int city_airlift_max(const struct city *pcity)
Definition city.c:2933
get_output_type
struct output_type * get_output_type(Output_type_id output)
Definition city.c:637
city_is_occupied
bool city_is_occupied(const struct city *pcity)
Definition city.c:1657
city_tile_output
int city_tile_output(const struct city *pcity, const struct tile *ptile, bool is_celebrating, Output_type_id otype)
Definition city.c:1274
city_list_iterate
#define city_list_iterate(citylist, pcity)
Definition city.h:508
city_owner
#define city_owner(_pcity_)
Definition city.h:563
city_list_iterate_end
#define city_list_iterate_end
Definition city.h:510
client_is_global_observer
bool client_is_global_observer(void)
Definition client_main.c:1345
get_seconds_to_new_turn
int get_seconds_to_new_turn(void)
Definition client_main.c:1172
get_seconds_to_turndone
int get_seconds_to_turndone(void)
Definition client_main.c:1158
client
struct civclient client
Definition client_main.c:150
is_waiting_turn_change
bool is_waiting_turn_change(void)
Definition client_main.c:1127
client_has_player
bool client_has_player(void)
Definition client_main.c:1364
client_main.h
client_player
#define client_player()
Definition client_main.h:106
combat_odds_to_astr
void combat_odds_to_astr(struct astring *str, struct unit_list *punits, const struct tile *ptile, const struct unit *punit, const char *pct_str)
Definition clientutils.c:312
concat_tile_activity_text
const char * concat_tile_activity_text(struct tile *ptile)
Definition clientutils.c:237
clientutils.h
client_tile_get_known
enum known_type client_tile_get_known(const struct tile *ptile)
Definition climap.c:36
climap.h
nuclear_winter_scaled
void nuclear_winter_scaled(int *chance, int *rate, int max)
Definition climisc.c:344
global_warming_scaled
void global_warming_scaled(int *chance, int *rate, int max)
Definition climisc.c:334
get_nearest_city
struct city * get_nearest_city(const struct unit *punit, int *sq_dist)
Definition climisc.c:1107
climisc.h
list
static struct fc_sockaddr_list * list
Definition clinet.c:102
combat.h
incite_cost
char * incite_cost
Definition comments.c:74
MAX_LEN_MSG
#define MAX_LEN_MSG
Definition conn_types.h:37
conn_list_iterate
#define conn_list_iterate(connlist, pconn)
Definition connection.h:108
conn_list_iterate_end
#define conn_list_iterate_end
Definition connection.h:110
get_units_in_focus
struct unit_list * get_units_in_focus(void)
Definition control.c:177
hover_state
enum cursor_hover_state hover_state
Definition control.c:89
find_visible_unit
struct unit * find_visible_unit(struct tile *ptile)
Definition control.c:804
control.h
HOVER_NONE
@ HOVER_NONE
Definition control.h:26
city_history_gain
int city_history_gain(const struct city *pcity)
Definition culture.c:37
nation_history_gain
int nation_history_gain(const struct player *pplayer)
Definition culture.c:61
culture.h
actor_unit
struct unit * actor_unit
Definition dialogs_g.h:55
punit
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
target_city
struct unit struct city * target_city
Definition dialogs_g.h:56
cost
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
effects
struct effect_list * effects[EFT_COUNT]
Definition effects.c:127
get_player_output_bonus
int get_player_output_bonus(const struct player *pplayer, const struct output_type *poutput, enum effect_type effect_type)
Definition effects.c:961
get_city_bonus
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:846
get_city_bonus_effects
int get_city_bonus_effects(struct effect_list *plist, const struct city *pcity, const struct output_type *poutput, enum effect_type effect_type)
Definition effects.c:1153
get_player_bonus
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:828
get_effect_list_req_text
void get_effect_list_req_text(const struct effect_list *plist, struct astring *astr)
Definition effects.c:1303
extras
static struct extra_type extras[MAX_EXTRA_TYPES]
Definition extras.c:31
extra_name_translation
const char * extra_name_translation(const struct extra_type *pextra)
Definition extras.c:194
extra_type_iterate
#define extra_type_iterate(_p)
Definition extras.h:315
extra_type_iterate_end
#define extra_type_iterate_end
Definition extras.h:321
fc_types.h
Tech_type_id
int Tech_type_id
Definition fc_types.h:380
MAX_LEN_NAME
#define MAX_LEN_NAME
Definition fc_types.h:66
O_SHIELD
@ O_SHIELD
Definition fc_types.h:101
O_FOOD
@ O_FOOD
Definition fc_types.h:101
O_TRADE
@ O_TRADE
Definition fc_types.h:101
O_SCIENCE
@ O_SCIENCE
Definition fc_types.h:101
O_LUXURY
@ O_LUXURY
Definition fc_types.h:101
O_LAST
@ O_LAST
Definition fc_types.h:101
LINE_BREAK
#define LINE_BREAK
Definition fc_types.h:77
BORDERS_DISABLED
@ BORDERS_DISABLED
Definition fc_types.h:1038
fcintl.h
Q_
#define Q_(String)
Definition fcintl.h:70
PL_
#define PL_(String1, String2, n)
Definition fcintl.h:71
_
#define _(String)
Definition fcintl.h:67
population_to_text
const char * population_to_text(int thousand_citizen)
Definition game.c:732
game
struct civ_game game
Definition game.c:62
current_turn_timeout
int current_turn_timeout(void)
Definition game.c:846
wld
struct world wld
Definition game.c:63
civ_population
int civ_population(const struct player *pplayer)
Definition game.c:74
game_city_by_number
struct city * game_city_by_number(int id)
Definition game.c:107
game.h
goto_get_turns
bool goto_get_turns(int *min, int *max)
Definition goto.c:1068
goto.h
ruler_title_for_player
const char * ruler_title_for_player(const struct player *pplayer, char *buf, size_t buf_len)
Definition government.c:391
government_name_for_player
const char * government_name_for_player(const struct player *pplayer)
Definition government.c:154
government.h
owner
struct city * owner
Definition citydlg.c:220
type
GType type
Definition repodlgs.c:1313
bufsz
static const int bufsz
Definition helpdlg.c:70
helpdata.h
is_improvement_visible
bool is_improvement_visible(const struct impr_type *pimprove)
Definition improvement.c:393
improvement_name_translation
const char * improvement_name_translation(const struct impr_type *pimprove)
Definition improvement.c:243
improvement_count
Impr_type_id improvement_count(void)
Definition improvement.c:164
improvement_iterate_end
#define improvement_iterate_end
Definition improvement.h:205
improvement_iterate
#define improvement_iterate(_p)
Definition improvement.h:199
log.h
fc_assert
#define fc_assert(condition)
Definition log.h:176
fc_assert_ret_val
#define fc_assert_ret_val(condition, val)
Definition log.h:194
nat_x
#define nat_x
nat_y
#define nat_y
map_signed_latitude
int map_signed_latitude(const struct tile *ptile)
Definition map.c:1550
map.h
index_to_native_pos
#define index_to_native_pos(pnat_x, pnat_y, mindex)
Definition map.h:157
index_to_map_pos
#define index_to_map_pos(pmap_x, pmap_y, mindex)
Definition map.h:233
fc_strdup
#define fc_strdup(str)
Definition mem.h:43
nation_adjective_for_player
const char * nation_adjective_for_player(const struct player *pplayer)
Definition nation.c:169
nation.h
cities
struct city_list * cities
Definition packhand.c:119
player_by_number
struct player * player_by_number(const int player_id)
Definition player.c:849
player_count
int player_count(void)
Definition player.c:817
player_get_expected_income
int player_get_expected_income(const struct player *pplayer)
Definition player.c:1286
player_name
const char * player_name(const struct player *pplayer)
Definition player.c:895
pplayers_at_war
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1388
player_city_by_number
struct city * player_city_by_number(const struct player *pplayer, int city_id)
Definition player.c:1203
player_diplstate_get
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Definition player.c:324
pplayers_allied
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1405
can_player_see_units_in_city
bool can_player_see_units_in_city(const struct player *pplayer, const struct city *pcity)
Definition player.c:1133
player_slot_get_player
struct player * player_slot_get_player(const struct player_slot *pslot)
Definition player.c:437
is_ai
#define is_ai(plr)
Definition player.h:230
research_goal_unknown_techs
int research_goal_unknown_techs(const struct research *presearch, Tech_type_id goal)
Definition research.c:750
research_goal_tech_req
bool research_goal_tech_req(const struct research *presearch, Tech_type_id goal, Tech_type_id tech)
Definition research.c:807
research_goal_bulbs_required
int research_goal_bulbs_required(const struct research *presearch, Tech_type_id goal)
Definition research.c:772
research_advance_name_translation
const char * research_advance_name_translation(const struct research *presearch, Tech_type_id tech)
Definition research.c:273
research_get
struct research * research_get(const struct player *pplayer)
Definition research.c:128
research.h
research_players_iterate
#define research_players_iterate(_presearch, _pplayer)
Definition research.h:166
research_players_iterate_end
#define research_players_iterate_end
Definition research.h:170
CLIP
#define CLIP(lower, current, upper)
Definition shared.h:57
ARRAY_SIZE
#define ARRAY_SIZE(x)
Definition shared.h:85
MIN
#define MIN(x, y)
Definition shared.h:55
FC_INFINITY
#define FC_INFINITY
Definition shared.h:36
MAX
#define MAX(x, y)
Definition shared.h:54
SSHIP_LAUNCHED
@ SSHIP_LAUNCHED
Definition spaceship.h:85
step
int step
Definition specpq.h:92
x
struct sprite int x
Definition sprite_g.h:31
strvec_iterate
#define strvec_iterate(psv, str)
Definition string_vector.h:61
strvec_iterate_end
#define strvec_iterate_end
Definition string_vector.h:68
act_prob
Definition fc_types.h:1241
action
Definition actions.h:360
astring
Definition astring.h:36
city
Definition city.h:320
city::airlift
int airlift
Definition city.h:378
city::prod
int prod[O_LAST]
Definition city.h:358
civ_game::info
struct packet_game_info info
Definition game.h:89
civ_game::tinfo
struct packet_timeout_info tinfo
Definition game.h:91
civclient::conn
struct connection conn
Definition client_main.h:96
connection::playing
struct player * playing
Definition connection.h:151
impr_type::helptext
struct strvec * helptext
Definition improvement.h:65
packet_game_info::borders
enum borders_mode borders
Definition packets_gen.h:130
packet_game_info::techloss_forgiveness
int techloss_forgiveness
Definition packets_gen.h:230
packet_game_info::citizen_nationality
bool citizen_nationality
Definition packets_gen.h:140
packet_game_info::angrycitizen
int angrycitizen
Definition packets_gen.h:122
packet_game_info::tech_upkeep_style
enum tech_upkeep_style tech_upkeep_style
Definition packets_gen.h:229
packet_game_info::airlifting_style
enum airlifting_style airlifting_style
Definition packets_gen.h:119
packet_game_info::phase_mode
enum phase_mode_type phase_mode
Definition packets_gen.h:207
packet_game_info::airlift_from_always_enabled
bool airlift_from_always_enabled
Definition packets_gen.h:120
packet_game_info::turn
int turn
Definition packets_gen.h:241
packet_game_info::phase
int phase
Definition packets_gen.h:206
packet_game_info::nuclear_winter
bool nuclear_winter
Definition packets_gen.h:204
packet_game_info::airlift_to_always_enabled
bool airlift_to_always_enabled
Definition packets_gen.h:121
packet_game_info::global_warming
bool global_warming
Definition packets_gen.h:163
packet_timeout_info::last_turn_change_time
float last_turn_change_time
Definition packets_gen.h:264
player_diplstate
Definition player.h:196
player_diplstate::type
enum diplstate_type type
Definition player.h:197
player_economic::luxury
int luxury
Definition player.h:64
player_economic::science
int science
Definition player.h:63
player_economic::tax
int tax
Definition player.h:62
player_economic::gold
int gold
Definition player.h:61
player_score::game
int game
Definition player.h:108
player_spaceship
Definition spaceship.h:94
player
Definition player.h:247
player::cities
struct city_list * cities
Definition player.h:279
player::username
char username[MAX_LEN_NAME]
Definition player.h:250
player::team
struct team * team
Definition player.h:259
player::connections
struct conn_list * connections
Definition player.h:296
player::client
struct player::@70::@73 client
player::economic
struct player_economic economic
Definition player.h:282
player::culture
int culture
Definition player.h:365
player::name
char name[MAX_LEN_NAME]
Definition player.h:249
player::score
struct player_score score
Definition player.h:281
player::nation
struct nation_type * nation
Definition player.h:258
research
Definition research.h:39
research::researching
Tech_type_id researching
Definition research.h:52
research::client
struct research::@76::@78 client
research::researching_cost
int researching_cost
Definition research.h:96
research::bulbs_researched
int bulbs_researched
Definition research.h:53
team
Definition team.c:40
tile
Definition tile.h:50
tile::extras
bv_extras extras
Definition tile.h:55
tile::units
struct unit_list * units
Definition tile.h:58
unit_type
Definition unittype.h:500
unit_type::helptext
struct strvec * helptext
Definition unittype.h:571
unit
Definition unit.h:138
unit::id
int id
Definition unit.h:145
unit::homecity
int homecity
Definition unit.h:146
unit::carrying
struct goods_type * carrying
Definition unit.h:186
unit::veteran
int veteran
Definition unit.h:152
universal
Definition fc_types.h:901
universal::kind
enum universals_n kind
Definition fc_types.h:903
universal::value
universals_u value
Definition fc_types.h:902
world::map
struct civ_map map
Definition world_object.h:38
fc_snprintf
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:974
fc_strlcpy
size_t fc_strlcpy(char *dest, const char *src, size_t n)
Definition support.c:791
cat_snprintf
int cat_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:1000
support.h
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
team_count
int team_count(void)
Definition team.c:375
team_by_number
struct team * team_by_number(const int team_id)
Definition team.c:400
team_name_translation
const char * team_name_translation(const struct team *pteam)
Definition team.c:420
A_UNSET
#define A_UNSET
Definition tech.h:48
get_infrastructure_text
const char * get_infrastructure_text(bv_extras extras)
Definition terrain.c:508
get_government_tooltip
const char * get_government_tooltip(void)
Definition text.c:1478
text_happiness_cities
const char * text_happiness_cities(const struct city *pcity)
Definition text.c:1900
format_duration
static const char * format_duration(int duration)
Definition text.c:1590
get_full_username
static void get_full_username(char *buf, int buflen, const struct player *pplayer)
Definition text.c:96
text_happiness_nationality
const char * text_happiness_nationality(const struct city *pcity)
Definition text.c:1828
FAR_CITY_SQUARE_DIST
#define FAR_CITY_SQUARE_DIST
Definition text.c:435
score_tooltip
const char * score_tooltip(const struct player *pplayer, int score)
Definition text.c:2126
text_happiness_wonders
const char * text_happiness_wonders(const struct city *pcity)
Definition text.c:1870
get_units_upgrade_info
bool get_units_upgrade_info(char *buf, size_t bufsz, struct unit_list *punits)
Definition text.c:1257
get_units_disband_info
bool get_units_disband_info(char *buf, size_t bufsz, struct unit_list *punits)
Definition text.c:1323
turns_to_research_done
static int turns_to_research_done(const struct research *presearch, int per_turn)
Definition text.c:693
get_airlift_text
const char * get_airlift_text(const struct unit_list *punits, const struct city *pdest)
Definition text.c:545
get_info_label_text_popup
const char * get_info_label_text_popup(void)
Definition text.c:969
text_happiness_units
const char * text_happiness_units(const struct city *pcity)
Definition text.c:2034
text_happiness_luxuries
const char * text_happiness_luxuries(const struct city *pcity)
Definition text.c:2072
science_dialog_text
const char * science_dialog_text(void)
Definition text.c:741
get_bulbs_per_turn
static int get_bulbs_per_turn(int *pours, bool *pteam, int *ptheirs)
Definition text.c:649
text_happiness_buildings
const char * text_happiness_buildings(const struct city *pcity)
Definition text.c:1800
get_ping_time_text
const char * get_ping_time_text(const struct player *pplayer)
Definition text.c:1621
get_report_title
const char * get_report_title(const char *report_name)
Definition text.c:1672
turns_to_tech_loss
static int turns_to_tech_loss(const struct research *presearch, int per_turn)
Definition text.c:721
get_nuclear_winter_tooltip
const char * get_nuclear_winter_tooltip(void)
Definition text.c:1451
get_score_text
const char * get_score_text(const struct player *pplayer)
Definition text.c:1650
get_science_target_text
const char * get_science_target_text(double *percent)
Definition text.c:820
get_bulb_tooltip
const char * get_bulb_tooltip(void)
Definition text.c:1367
get_timeout_label_text
const char * get_timeout_label_text(void)
Definition text.c:1557
get_nearest_city_text
const char * get_nearest_city_text(struct city *pcity, int sq_dist)
Definition text.c:441
get_act_sel_action_custom_text
const char * get_act_sel_action_custom_text(struct action *paction, const struct act_prob prob, const struct unit *actor_unit, const struct city *target_city)
Definition text.c:1710
popup_info_text
const char * popup_info_text(struct tile *ptile)
Definition text.c:147
unit_description
const char * unit_description(struct unit *punit)
Definition text.c:475
get_full_nation
static void get_full_nation(char *buf, int buflen, const struct player *pplayer)
Definition text.c:120
get_global_warming_tooltip
const char * get_global_warming_tooltip(void)
Definition text.c:1424
get_tile_output_text
const char * get_tile_output_text(const struct tile *ptile)
Definition text.c:63
get_info_label_text
const char * get_info_label_text(bool moreinfo)
Definition text.c:917
production_help
const char * production_help(const struct universal *uni, char *buf, size_t bufsize)
Definition text.c:2089
turns_per_advance
static int turns_per_advance(const struct research *presearch, int per_turn)
Definition text.c:708
get_science_goal_text
const char * get_science_goal_text(Tech_type_id goal)
Definition text.c:866
get_unit_info_label_text2
const char * get_unit_info_label_text2(struct unit_list *punits, int linebreaks)
Definition text.c:1079
get_unit_info_label_text1
const char * get_unit_info_label_text1(struct unit_list *punits)
Definition text.c:1054
get_spaceship_descr
const char * get_spaceship_descr(struct player_spaceship *pship)
Definition text.c:1500
act_sel_action_tool_tip
const char * act_sel_action_tool_tip(const struct action *paction, const struct act_prob prob)
Definition text.c:1789
text.h
tile_has_visible_extra
bool tile_has_visible_extra(const struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:917
tile_get_info_text
const char * tile_get_info_text(const struct tile *ptile, bool include_nuisances, int linebreaks)
Definition tile.c:771
tile_city
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
tile_index
#define tile_index(_pt_)
Definition tile.h:88
TILE_UNKNOWN
@ TILE_UNKNOWN
Definition tile.h:36
tile_continent
#define tile_continent(_tile)
Definition tile.h:92
tile_owner
#define tile_owner(_tile)
Definition tile.h:96
can_cities_trade
bool can_cities_trade(const struct city *pc1, const struct city *pc2)
Definition traderoutes.c:214
trade_base_between_cities
int trade_base_between_cities(const struct city *pc1, const struct city *pc2)
Definition traderoutes.c:322
can_establish_trade_route
bool can_establish_trade_route(const struct city *pc1, const struct city *pc2)
Definition traderoutes.c:275
get_caravan_enter_city_trade_bonus
int get_caravan_enter_city_trade_bonus(const struct city *pc1, const struct city *pc2, const struct unit_type *ut, struct goods_type *pgood, const bool establish_trade)
Definition traderoutes.c:467
traderoutes.h
universals_u::utype
const struct unit_type * utype
Definition fc_types.h:724
universals_u::building
const struct impr_type * building
Definition fc_types.h:717
unit_upgrade_info
enum unit_upgrade_result unit_upgrade_info(const struct civ_map *nmap, const struct unit *punit, char *buf, size_t bufsz)
Definition unit.c:2047
unit_nationality
struct player * unit_nationality(const struct unit *punit)
Definition unit.c:1242
test_unit_can_airlift_to
enum unit_airlift_result test_unit_can_airlift_to(const struct civ_map *nmap, const struct player *restriction, const struct unit *punit, const struct city *pdest_city)
Definition unit.c:81
unit_bribe_cost
int unit_bribe_cost(struct unit *punit, struct player *briber)
Definition unit.c:2300
unit_upkeep_astr
void unit_upkeep_astr(const struct unit *punit, struct astring *astr)
Definition unit.c:1228
unit_can_do_action
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Definition unit.c:361
unit_activity_astr
void unit_activity_astr(const struct unit *punit, struct astring *astr)
Definition unit.c:1152
unit_upgrade_test
enum unit_upgrade_result unit_upgrade_test(const struct civ_map *nmap, const struct unit *punit, bool is_free)
Definition unit.c:1984
unit_tile
#define unit_tile(_pu)
Definition unit.h:390
unit_owner
#define unit_owner(_pu)
Definition unit.h:389
UU_OK
@ UU_OK
Definition unit.h:61
unit_home
#define unit_home(_pu_)
Definition unit.h:387
unit_airlift_result
unit_airlift_result
Definition unit.h:72
AR_SRC_NO_FLIGHTS
@ AR_SRC_NO_FLIGHTS
Definition unit.h:84
AR_OK_SRC_UNKNOWN
@ AR_OK_SRC_UNKNOWN
Definition unit.h:75
AR_OK_DST_UNKNOWN
@ AR_OK_DST_UNKNOWN
Definition unit.h:76
AR_NO_MOVES
@ AR_NO_MOVES
Definition unit.h:78
AR_BAD_DST_CITY
@ AR_BAD_DST_CITY
Definition unit.h:83
AR_NOT_IN_CITY
@ AR_NOT_IN_CITY
Definition unit.h:81
AR_OCCUPIED
@ AR_OCCUPIED
Definition unit.h:80
AR_OK
@ AR_OK
Definition unit.h:74
AR_DST_NO_FLIGHTS
@ AR_DST_NO_FLIGHTS
Definition unit.h:85
AR_WRONG_UNITTYPE
@ AR_WRONG_UNITTYPE
Definition unit.h:79
AR_BAD_SRC_CITY
@ AR_BAD_SRC_CITY
Definition unit.h:82
unitlist.h
unit_list_iterate
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
unit_list_iterate_end
#define unit_list_iterate_end
Definition unitlist.h:33
utype_veteran_name_translation
const char * utype_veteran_name_translation(const struct unit_type *punittype, int level)
Definition unittype.c:2598
unit_type_get
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
unit_name_translation
const char * unit_name_translation(const struct unit *punit)
Definition unittype.c:1569
can_upgrade_unittype
const struct unit_type * can_upgrade_unittype(const struct player *pplayer, const struct unit_type *punittype)
Definition unittype.c:1703
unit_has_type_flag
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Definition unittype.c:190
utype_index
Unit_type_id utype_index(const struct unit_type *punittype)
Definition unittype.c:91
utype_name_translation
const char * utype_name_translation(const struct unit_type *punittype)
Definition unittype.c:1560
utype_can_do_action
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:371
unit_upgrade_price
int unit_upgrade_price(const struct player *pplayer, const struct unit_type *from, const struct unit_type *to)
Definition unittype.c:1731
utype_has_flag
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition unittype.h:617
unit_type_iterate
#define unit_type_iterate(_p)
Definition unittype.h:852
U_LAST
#define U_LAST
Definition unittype.h:40
unit_type_iterate_end
#define unit_type_iterate_end
Definition unittype.h:859