Freeciv-3.1: /fast/freeciv/nightly/S3_1/common/calendar.c Source File

Freeciv-3.1

Loading...
Searching...
No Matches
calendar.c
Go to the documentation of this file.
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.
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/* common */
19#include "game.h"
20#include "victory.h"
21
22#include "calendar.h"
23
24/************************************************************************/
30 void game_next_year(struct packet_game_info *info)
31{
32 int increase = get_world_bonus(EFT_TURN_YEARS);
33 const int slowdown = (victory_enabled(VC_SPACERACE)
34 ? get_world_bonus(EFT_SLOW_DOWN_TIMELINE) : 0);
35 int fragment_years;
36
37 if (info->year_0_hack) {
38 /* hacked it to get rid of year 0 */
39 info->year = 0;
40 info->year_0_hack = FALSE;
41 }
42
43 /* !McFred:
44 - want year += 1 for spaceship.
45 */
46
47 /* test game with 7 normal AI's, gen 4 map, foodbox 10, foodbase 0:
48 * Gunpowder about 0 AD
49 * Railroad about 500 AD
50 * Electricity about 1000 AD
51 * Refining about 1500 AD (212 active units)
52 * about 1750 AD
53 * about 1900 AD
54 */
55
56 /* Note the slowdown operates even if Enable_Space is not active. See
57 * README.effects for specifics. */
58 if (slowdown >= 3) {
59 if (increase > 1) {
60 increase = 1;
61 }
62 } else if (slowdown >= 2) {
63 if (increase > 2) {
64 increase = 2;
65 }
66 } else if (slowdown >= 1) {
67 if (increase > 5) {
68 increase = 5;
69 }
70 }
71
72 if (game.calendar.calendar_fragments) {
73 info->fragment_count += get_world_bonus(EFT_TURN_FRAGMENTS);
74 fragment_years = info->fragment_count / game.calendar.calendar_fragments;
75
76 increase += fragment_years;
77 info->fragment_count -= fragment_years * game.calendar.calendar_fragments;
78 }
79
80 info->year += increase;
81
82 if (info->year == 0 && game.calendar.calendar_skip_0) {
83 info->year = 1;
84 info->year_0_hack = TRUE;
85 }
86}
87
88/************************************************************************/
91 void game_advance_year(void)
92{
93 game_next_year(&game.info);
94 game.info.turn++;
95}
96
97/************************************************************************/
101 const char *textcalfrag(int frag)
102{
103 static char buf[MAX_LEN_NAME];
104
105 fc_assert_ret_val(game.calendar.calendar_fragments > 0, "");
106 if (game.calendar.calendar_fragment_name[frag][0] != '\0') {
107 fc_snprintf(buf, sizeof(buf), "%s",
108 _(game.calendar.calendar_fragment_name[frag]));
109 } else {
110 /* Human readable fragment count starts from 1, not 0 */
111 fc_snprintf(buf, sizeof(buf), "%d", frag + 1);
112 }
113 return buf;
114}
115
116/************************************************************************/
120 const char *textyear(int year)
121{
122 static char y[32];
123
124 if (year < 0) {
125 /* TRANS: <year> <label> -> "1000 BC" */
126 fc_snprintf(y, sizeof(y), _("%d %s"), -year,
127 _(game.calendar.negative_year_label));
128 } else {
129 /* TRANS: <year> <label> -> "1000 AD" */
130 fc_snprintf(y, sizeof(y), _("%d %s"), year,
131 _(game.calendar.positive_year_label));
132 }
133
134 return y;
135}
136
137/************************************************************************/
141 const char *calendar_text(void)
142{
143 if (game.calendar.calendar_fragments) {
144 static char buffer[128];
145
146 fc_snprintf(buffer, sizeof(buffer), "%s/%s", textyear(game.info.year),
147 textcalfrag(game.info.fragment_count));
148 return buffer;
149 } else {
150 return textyear(game.info.year);
151 }
152}
game_advance_year
void game_advance_year(void)
Definition calendar.c:91
textcalfrag
const char * textcalfrag(int frag)
Definition calendar.c:101
calendar_text
const char * calendar_text(void)
Definition calendar.c:141
game_next_year
void game_next_year(struct packet_game_info *info)
Definition calendar.c:30
textyear
const char * textyear(int year)
Definition calendar.c:120
calendar.h
get_world_bonus
int get_world_bonus(enum effect_type effect_type)
Definition effects.c:759
MAX_LEN_NAME
#define MAX_LEN_NAME
Definition fc_types.h:66
VC_SPACERACE
@ VC_SPACERACE
Definition fc_types.h:1123
_
#define _(String)
Definition fcintl.h:67
game
struct civ_game game
Definition game.c:57
game.h
fc_assert_ret_val
#define fc_assert_ret_val(condition, val)
Definition log.h:194
civ_game::info
struct packet_game_info info
Definition game.h:89
civ_game::calendar
struct packet_calendar_info calendar
Definition game.h:90
packet_calendar_info::positive_year_label
char positive_year_label[MAX_LEN_NAME]
Definition packets_gen.h:254
packet_calendar_info::calendar_skip_0
bool calendar_skip_0
Definition packets_gen.h:258
packet_calendar_info::negative_year_label
char negative_year_label[MAX_LEN_NAME]
Definition packets_gen.h:255
packet_calendar_info::calendar_fragments
int calendar_fragments
Definition packets_gen.h:256
packet_calendar_info::calendar_fragment_name
char calendar_fragment_name[MAX_CALENDAR_FRAGMENTS][MAX_LEN_NAME]
Definition packets_gen.h:257
packet_game_info
Definition packets_gen.h:119
packet_game_info::year_0_hack
bool year_0_hack
Definition packets_gen.h:244
packet_game_info::fragment_count
int fragment_count
Definition packets_gen.h:245
packet_game_info::turn
int turn
Definition packets_gen.h:241
packet_game_info::year
int year
Definition packets_gen.h:243
fc_snprintf
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:969
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
victory_enabled
bool victory_enabled(enum victory_condition_type victory)
Definition victory.c:26
victory.h