Freeciv21
Develop your civilization from humble roots to a global empire
calendar.cpp
Go to the documentation of this file.
1 /*
2 _ ._ Copyright (c) 1996-2021 Freeciv21 and Freeciv contributors.
3  \ | This file is part of Freeciv21. Freeciv21 is free software: you
4  \_| can redistribute it and/or modify it under the terms of the
5  .' '. GNU General Public License as published by the Free
6  :O O: Software Foundation, either version 3 of the License,
7  '/ \' or (at your option) any later version. You should have
8  :X: received a copy of the GNU General Public License along with
9  :X: Freeciv21. If not, see https://www.gnu.org/licenses/.
10  */
11 
12 // common
13 #include "game.h"
14 #include "victory.h"
15 
16 #include "calendar.h"
17 
24 void game_next_year(struct packet_game_info *info)
25 {
26  int increase = get_world_bonus(EFT_TURN_YEARS);
27  const int slowdown = (victory_enabled(VC_SPACERACE)
28  ? get_world_bonus(EFT_SLOW_DOWN_TIMELINE)
29  : 0);
30  int fragment_years;
31 
32  if (info->year_0_hack) {
33  // hacked it to get rid of year 0
34  info->year = 0;
35  info->year_0_hack = false;
36  }
37 
38  /* !McFred:
39  - want year += 1 for spaceship.
40  */
41 
42  /* test game with 7 normal AI's, gen 4 map, foodbox 10, foodbase 0:
43  * Gunpowder about 0 AD
44  * Railroad about 500 AD
45  * Electricity about 1000 AD
46  * Refining about 1500 AD (212 active units)
47  * about 1750 AD
48  * about 1900 AD
49  */
50 
51  /* Note the slowdown operates even if Enable_Space is not active. See
52  * README.effects for specifics. */
53  if (slowdown >= 3) {
54  if (increase > 1) {
55  increase = 1;
56  }
57  } else if (slowdown >= 2) {
58  if (increase > 2) {
59  increase = 2;
60  }
61  } else if (slowdown >= 1) {
62  if (increase > 5) {
63  increase = 5;
64  }
65  }
66 
67  if (game.calendar.calendar_fragments) {
68  info->fragment_count += get_world_bonus(EFT_TURN_FRAGMENTS);
69  fragment_years = info->fragment_count / game.calendar.calendar_fragments;
70 
71  increase += fragment_years;
72  info->fragment_count -=
73  fragment_years * game.calendar.calendar_fragments;
74  }
75 
76  info->year += increase;
77 
78  if (info->year == 0 && game.calendar.calendar_skip_0) {
79  info->year = 1;
80  info->year_0_hack = true;
81  }
82 }
83 
88 {
90  game.info.turn++;
91 }
92 
97 const char *textcalfrag(int frag)
98 {
99  static char buf[MAX_LEN_NAME];
100 
101  fc_assert_ret_val(game.calendar.calendar_fragments > 0, "");
102  if (game.calendar.calendar_fragment_name[frag][0] != '\0') {
103  fc_snprintf(buf, sizeof(buf), "%s",
104  _(game.calendar.calendar_fragment_name[frag]));
105  } else {
106  // Human readable fragment count starts from 1, not 0
107  fc_snprintf(buf, sizeof(buf), "%d", frag + 1);
108  }
109  return buf;
110 }
111 
116 const char *textyear(int year)
117 {
118  static char y[32];
119 
120  if (year < 0) {
121  // TRANS: <year> <label> -> "1000 BC"
122  fc_snprintf(y, sizeof(y), _("%d %s"), -year,
123  _(game.calendar.negative_year_label));
124  } else {
125  // TRANS: <year> <label> -> "1000 AD"
126  fc_snprintf(y, sizeof(y), _("%d %s"), year,
127  _(game.calendar.positive_year_label));
128  }
129 
130  return y;
131 }
132 
137 const char *calendar_text()
138 {
139  if (game.calendar.calendar_fragments) {
140  static char buffer[128];
141 
142  fc_snprintf(buffer, sizeof(buffer), "%s/%s", textyear(game.info.year),
143  textcalfrag(game.info.fragment_count));
144  return buffer;
145  } else {
146  return textyear(game.info.year);
147  }
148 }
const char * calendar_text()
Produce a statically allocated textual representation of the current calendar time.
Definition: calendar.cpp:137
void game_advance_year()
Advance the game year.
Definition: calendar.cpp:87
void game_next_year(struct packet_game_info *info)
Advance the calendar in the passed game_info structure (may only be a copy of the real one).
Definition: calendar.cpp:24
const char * textcalfrag(int frag)
Produce a statically allocated textual representation of the given calendar fragment.
Definition: calendar.cpp:97
const char * textyear(int year)
Produce a statically allocated textual representation of the given year.
Definition: calendar.cpp:116
int get_world_bonus(enum effect_type effect_type)
Returns the effect bonus for the whole world.
Definition: effects.cpp:659
#define MAX_LEN_NAME
Definition: fc_types.h:61
@ VC_SPACERACE
Definition: fc_types.h:1083
#define _(String)
Definition: fcintl.h:50
struct civ_game game
Definition: game.cpp:47
#define fc_assert_ret_val(condition, val)
Definition: log.h:114
struct packet_game_info info
Definition: game.h:80
struct packet_calendar_info calendar
Definition: game.h:81
int fc_snprintf(char *str, size_t n, const char *format,...)
See also fc_utf8_snprintf_trunc(), fc_utf8_snprintf_rep().
Definition: support.cpp:537
bool victory_enabled(enum victory_condition_type victory)
Whether victory condition is enabled.
Definition: victory.cpp:20