Stop sharing requirement_unit_state_ereq().
[freeciv.git] / common / calendar.c
blob82df57cc8861feef5e94ceab2aabf37345d98dea
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.calendar.calendar_fragments) {
70 game.info.fragment_count += get_world_bonus(EFT_TURN_FRAGMENTS);
71 fragment_years = game.info.fragment_count / game.calendar.calendar_fragments;
73 increase += fragment_years;
74 game.info.fragment_count -= fragment_years * game.calendar.calendar_fragments;
77 year += increase;
79 if (year == 0 && game.calendar.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 calendar fragment.
99 ****************************************************************************/
100 const char *textcalfrag(int frag)
102 static char buf[MAX_LEN_NAME];
104 fc_assert_ret_val(game.calendar.calendar_fragments > 0, "");
105 if (game.calendar.calendar_fragment_name[frag][0] != '\0') {
106 fc_snprintf(buf, sizeof(buf), "%s",
107 _(game.calendar.calendar_fragment_name[frag]));
108 } else {
109 /* Human readable fragment count starts from 1, not 0 */
110 fc_snprintf(buf, sizeof(buf), "%d", frag + 1);
112 return buf;
115 /****************************************************************************
116 Produce a statically allocated textual representation of the given
117 year.
118 ****************************************************************************/
119 const char *textyear(int year)
121 static char y[32];
123 if (year < 0) {
124 /* TRANS: <year> <label> -> "1000 BC" */
125 fc_snprintf(y, sizeof(y), _("%d %s"), -year,
126 _(game.calendar.negative_year_label));
127 } else {
128 /* TRANS: <year> <label> -> "1000 AD" */
129 fc_snprintf(y, sizeof(y), _("%d %s"), year,
130 _(game.calendar.positive_year_label));
133 return y;
136 /****************************************************************************
137 Produce a statically allocated textual representation of the current
138 calendar time.
139 ****************************************************************************/
140 const char *calendar_text(void)
142 if (game.calendar.calendar_fragments) {
143 static char buffer[128];
145 fc_snprintf(buffer, sizeof(buffer), "%s/%s", textyear(game.info.year),
146 textcalfrag(game.info.fragment_count));
147 return buffer;
148 } else {
149 return textyear(game.info.year);