Find "best" transport from correct tile for transport dialog.
[freeciv.git] / common / calendar.c
blob1028bfe903b26cbfa7faebb0b3f11ec764a61010
1 /****************************************************************************
2 Freeciv - Copyright (C) 2004 - The Freeciv Team
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.
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 ****************************************************************************/
14 #ifdef HAVE_CONFIG_H
15 #include <fc_config.h>
16 #endif
18 /* common */
19 #include "game.h"
20 #include "victory.h"
22 #include "calendar.h"
24 /***************************************************************
25 Returns the next year in the game.
26 ***************************************************************/
27 int game_next_year(int year)
29 int increase = get_world_bonus(EFT_TURN_YEARS);
30 const int slowdown = (victory_enabled(VC_SPACERACE)
31 ? get_world_bonus(EFT_SLOW_DOWN_TIMELINE) : 0);
32 int fragment_years;
34 if (game.info.year_0_hack) {
35 /* hacked it to get rid of year 0 */
36 year = 0;
37 game.info.year_0_hack = FALSE;
40 /* !McFred:
41 - want year += 1 for spaceship.
44 /* test game with 7 normal AI's, gen 4 map, foodbox 10, foodbase 0:
45 * Gunpowder about 0 AD
46 * Railroad about 500 AD
47 * Electricity about 1000 AD
48 * Refining about 1500 AD (212 active units)
49 * about 1750 AD
50 * about 1900 AD
53 /* Note the slowdown operates even if Enable_Space is not active. See
54 * README.effects for specifics. */
55 if (slowdown >= 3) {
56 if (increase > 1) {
57 increase = 1;
59 } else if (slowdown >= 2) {
60 if (increase > 2) {
61 increase = 2;
63 } else if (slowdown >= 1) {
64 if (increase > 5) {
65 increase = 5;
69 if (game.info.calendar_fragments) {
70 game.info.fragment_count += get_world_bonus(EFT_TURN_FRAGMENTS);
71 fragment_years = game.info.fragment_count / game.info.calendar_fragments;
73 increase += fragment_years;
74 game.info.fragment_count -= fragment_years * game.info.calendar_fragments;
77 year += increase;
79 if (year == 0 && game.info.calendar_skip_0) {
80 year = 1;
81 game.info.year_0_hack = TRUE;
84 return year;
87 /***************************************************************
88 Advance the game year.
89 ***************************************************************/
90 void game_advance_year(void)
92 game.info.year = game_next_year(game.info.year);
93 game.info.turn++;
96 /****************************************************************************
97 Produce a statically allocated textual representation of the given
98 year.
99 ****************************************************************************/
100 const char *textyear(int year)
102 static char y[32];
104 if (year < 0) {
105 /* TRANS: <year> <label> -> "1000 BC" */
106 fc_snprintf(y, sizeof(y), _("%d %s"), -year,
107 _(game.info.negative_year_label));
108 } else {
109 /* TRANS: <year> <label> -> "1000 AD" */
110 fc_snprintf(y, sizeof(y), _("%d %s"), year,
111 _(game.info.positive_year_label));
114 return y;
117 /****************************************************************************
118 Produce a statically allocated textual representation of the current
119 calendar time.
120 ****************************************************************************/
121 const char *calendar_text(void)
123 if (game.info.calendar_fragments) {
124 static char buffer[128];
126 if (game.info.calendar_fragment_name[game.info.fragment_count][0] != '\0') {
127 fc_snprintf(buffer, sizeof(buffer), "%s/%s", textyear(game.info.year),
128 _(game.info.calendar_fragment_name[game.info.fragment_count]));
129 } else {
130 /* Human readable fragment count starts from 1, not 0 */
131 fc_snprintf(buffer, sizeof(buffer), "%s/%d", textyear(game.info.year),
132 game.info.fragment_count + 1);
135 return buffer;
136 } else {
137 return textyear(game.info.year);