Freeciv-3.3
Loading...
Searching...
No Matches
settings.h
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996-2004 - 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#ifndef FC__SETTINGS_H
15#define FC__SETTINGS_H
16
17#ifdef __cplusplus
18extern "C" {
19#endif /* __cplusplus */
20
21/* utility */
22#include "shared.h"
23
24/* common */
25#include "game.h"
26#include "server_settings.h"
27
29 const char *support; /* Untranslated long support name, used
30 * for saving. */
31 const char *pretty; /* Translated, used to display to the
32 * users. */
33};
34
35/* Categories allow options to be usefully organized when presented to the
36 * user */
37#define SPECENUM_NAME sset_category
38#define SPECENUM_VALUE0 SSET_GEOLOGY
39#define SPECENUM_VALUE0NAME N_("Geological")
40#define SPECENUM_VALUE1 SSET_SOCIOLOGY
41#define SPECENUM_VALUE1NAME N_("Sociological")
42#define SPECENUM_VALUE2 SSET_ECONOMICS
43#define SPECENUM_VALUE2NAME N_("Economic")
44#define SPECENUM_VALUE3 SSET_MILITARY
45#define SPECENUM_VALUE3NAME N_("Military")
46#define SPECENUM_VALUE4 SSET_SCIENCE
47#define SPECENUM_VALUE4NAME N_("Scientific")
48#define SPECENUM_VALUE5 SSET_INTERNAL
49#define SPECENUM_VALUE5NAME N_("Internal")
50#define SPECENUM_VALUE6 SSET_NETWORK
51#define SPECENUM_VALUE6NAME N_("Networking")
52/* keep this last */
53#define SPECENUM_COUNT SSET_NUM_CATEGORIES
54#include "specenum_gen.h"
55
56/* Levels allow options to be subdivided and thus easier to navigate */
57#define SPECENUM_NAME sset_level
58#define SPECENUM_VALUE0 SSET_NONE
59#define SPECENUM_VALUE0NAME N_("?ssetlevel:None")
60#define SPECENUM_VALUE1 SSET_ALL
61#define SPECENUM_VALUE1NAME N_("All")
62#define SPECENUM_VALUE2 SSET_VITAL
63#define SPECENUM_VALUE2NAME N_("Vital")
64#define SPECENUM_VALUE3 SSET_SITUATIONAL
65#define SPECENUM_VALUE3NAME N_("Situational")
66#define SPECENUM_VALUE4 SSET_RARE
67#define SPECENUM_VALUE4NAME N_("Rare")
68#define SPECENUM_VALUE5 SSET_CHANGED
69#define SPECENUM_VALUE5NAME N_("Changed")
70#define SPECENUM_VALUE6 SSET_LOCKED
71#define SPECENUM_VALUE6NAME N_("Locked")
72/* keep this last */
73#define SPECENUM_COUNT OLEVELS_NUM
74#include "specenum_gen.h"
75
77
78/* Forward declaration */
79struct setting;
80
81struct sf_cb_data {
82 struct setting *set;
83 bool compat;
84};
85
86struct setting *setting_by_number(int id);
87struct setting *setting_by_name(const char *name);
88int setting_number(const struct setting *pset);
89
90const char *setting_name(const struct setting *pset);
91const char *setting_short_help(const struct setting *pset);
92const char *setting_extra_help(const struct setting *pset, bool constant);
93enum sset_type setting_type(const struct setting *pset);
94enum sset_level setting_level(const struct setting *pset);
95enum sset_category setting_category(const struct setting *pset);
96
97bool setting_is_changeable(const struct setting *pset,
98 struct connection *caller, char *reject_msg,
99 size_t reject_msg_len);
100bool setting_is_visible_at_level(const struct setting *pset,
101 enum cmdlevel plevel);
102bool setting_is_visible(const struct setting *pset,
103 struct connection *caller);
104
105const char *setting_value_name(const struct setting *pset, bool pretty,
106 char *buf, size_t buf_len);
107const char *setting_default_name(const struct setting *pset, bool pretty,
108 char *buf, size_t buf_len);
109
111
112int read_enum_value(const struct setting *pset);
113const char *setting_enum_secfile_str(secfile_data_t data, int val);
114const char *setting_bitwise_secfile_str(secfile_data_t data, int bit);
115
116/* Type SST_BOOL setting functions. */
117bool setting_bool_set(struct setting *pset, const char *val,
118 struct connection *caller, char *reject_msg,
119 size_t reject_msg_len);
120bool setting_bool_validate(const struct setting *pset, const char *val,
121 struct connection *caller, char *reject_msg,
122 size_t reject_msg_len);
123bool setting_bool_get(struct setting *pset);
124
125/* Type SST_INT setting functions. */
126int setting_int_min(const struct setting *pset);
127int setting_int_max(const struct setting *pset);
128bool setting_int_set(struct setting *pset, int val,
129 struct connection *caller, char *reject_msg,
130 size_t reject_msg_len);
131bool setting_int_validate(const struct setting *pset, int val,
132 struct connection *caller, char *reject_msg,
133 size_t reject_msg_len);
134int setting_int_get(struct setting *pset);
135
136/* Type SST_STRING setting functions. */
137bool setting_str_set(struct setting *pset, const char *val,
138 struct connection *caller, char *reject_msg,
139 size_t reject_msg_len);
140bool setting_str_validate(const struct setting *pset, const char *val,
141 struct connection *caller, char *reject_msg,
142 size_t reject_msg_len);
143char *setting_str_get(struct setting *pset);
144
145/* Type SST_ENUM setting functions. */
146const char *setting_enum_val(const struct setting *pset, int val,
147 bool pretty);
148bool setting_enum_set(struct setting *pset, const char *val,
149 struct connection *caller, char *reject_msg,
150 size_t reject_msg_len);
151bool setting_enum_validate(const struct setting *pset, const char *val,
152 struct connection *caller, char *reject_msg,
153 size_t reject_msg_len);
154
155/* Type SST_BITWISE setting functions. */
156const char *setting_bitwise_bit(const struct setting *pset,
157 int bit, bool pretty);
158bool setting_bitwise_set(struct setting *pset, const char *val,
159 struct connection *caller, char *reject_msg,
160 size_t reject_msg_len);
161bool setting_bitwise_validate(const struct setting *pset, const char *val,
162 struct connection *caller, char *reject_msg,
163 size_t reject_msg_len);
164int setting_bitwise_get(struct setting *pset);
165
166void setting_action(const struct setting *pset);
167
168bool setting_non_default(const struct setting *pset);
169bool setting_locked(const struct setting *pset);
170bool setting_ruleset_locked(const struct setting *pset);
175
176/* get 'struct setting_list' and related functions: */
177#define SPECLIST_TAG setting
178#define SPECLIST_TYPE struct setting
179#include "speclist.h"
180
181#define setting_list_iterate(_setting_list, _setting) \
182 TYPED_LIST_ITERATE(struct setting, _setting_list, _setting)
183#define setting_list_iterate_end \
184 LIST_ITERATE_END
185
186/* Iterate over all settings; this additionally checks if the list is
187 * created and valid. */
188#define settings_iterate(_level, _pset) \
189{ \
190 struct setting_list *_setting_list = settings_list_get(_level); \
191 if (_setting_list != NULL) { \
192 setting_list_iterate(_setting_list, _pset) {
193
194#define settings_iterate_end \
195 } setting_list_iterate_end; \
196 } \
197}
198
199void settings_game_start(void);
200void settings_game_save(struct section_file *file, const char *section);
201void settings_game_load(struct section_file *file, const char *section);
202bool settings_game_reset(void);
203
204void settings_init(bool act);
205void settings_reset(void);
206void settings_turn(void);
207void settings_free(void);
208int settings_number(void);
209
210void settings_list_update(void);
212
213bool settings_ruleset(struct section_file *file, const char *section,
214 bool act, bool compat);
215
216void send_server_setting(struct conn_list *dest, const struct setting *pset);
217void send_server_settings(struct conn_list *dest);
219 enum cmdlevel old_level,
220 enum cmdlevel new_level);
222
223void setting_changed(struct setting *pset);
225
226#ifdef __cplusplus
227}
228#endif /* __cplusplus */
229
230#endif /* FC__SETTINGS_H */
char * incite_cost
Definition comments.c:76
const char * name
Definition inputfile.c:127
const void * secfile_data_t
static struct compatibility compat[]
Definition savecompat.c:112
struct setting_list * level[OLEVELS_NUM]
Definition settings.c:190
bool setting_ruleset_locked(const struct setting *pset)
Definition settings.c:4648
bool setting_int_validate(const struct setting *pset, int val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:3763
void settings_init(bool act)
Definition settings.c:5212
void setting_action(const struct setting *pset)
Definition settings.c:4369
void setting_ruleset_lock_clear(struct setting *pset)
Definition settings.c:4676
void setting_admin_lock_clear(struct setting *pset)
Definition settings.c:4688
int setting_int_get(struct setting *pset)
Definition settings.c:3788
const char * setting_default_name(const struct setting *pset, bool pretty, char *buf, size_t buf_len)
Definition settings.c:4303
bool setting_enum_validate(const struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:4051
struct setting * setting_by_name(const char *name)
Definition settings.c:3309
void setting_set_to_default(struct setting *pset)
Definition settings.c:4339
const char * setting_value_name(const struct setting *pset, bool pretty, char *buf, size_t buf_len)
Definition settings.c:4267
void settings_game_load(struct section_file *file, const char *section)
Definition settings.c:4913
const char * setting_extra_help(const struct setting *pset, bool constant)
Definition settings.c:3350
int setting_number(const struct setting *pset)
Definition settings.c:3324
struct setting * setting_by_number(int id)
Definition settings.c:3301
bool setting_int_set(struct setting *pset, int val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:3743
enum sset_category setting_category(const struct setting *pset)
Definition settings.c:3378
bool setting_is_visible(const struct setting *pset, struct connection *caller)
Definition settings.c:3506
bool setting_locked(const struct setting *pset)
Definition settings.c:4640
bool setting_non_default(const struct setting *pset)
Definition settings.c:4614
enum sset_type setting_type(const struct setting *pset)
Definition settings.c:3362
void settings_free(void)
Definition settings.c:5254
void setting_admin_lock_set(struct setting *pset)
Definition settings.c:4668
bool setting_str_set(struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:3814
int setting_int_max(const struct setting *pset)
Definition settings.c:3733
enum sset_level setting_level(const struct setting *pset)
Definition settings.c:3370
bool setting_bitwise_set(struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:4223
const char * setting_enum_secfile_str(secfile_data_t data, int val)
Definition settings.c:3870
void settings_game_save(struct section_file *file, const char *section)
Definition settings.c:4825
int settings_number(void)
Definition settings.c:5266
bool setting_str_validate(const struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:3834
void settings_turn(void)
Definition settings.c:5246
const char * setting_enum_val(const struct setting *pset, int val, bool pretty)
Definition settings.c:3893
void setting_changed(struct setting *pset)
Definition settings.c:5604
enum setting_default_level setting_get_setdef(const struct setting *pset)
Definition settings.c:5612
void settings_game_start(void)
Definition settings.c:4812
bool setting_enum_set(struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:4022
const char * setting_short_help(const struct setting *pset)
Definition settings.c:3341
void send_server_setting_control(struct connection *pconn)
Definition settings.c:5438
const char * setting_bitwise_bit(const struct setting *pset, int bit, bool pretty)
Definition settings.c:4088
int setting_int_min(const struct setting *pset)
Definition settings.c:3724
bool setting_bitwise_validate(const struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:4244
void setting_ruleset_lock_set(struct setting *pset)
Definition settings.c:4656
bool setting_bool_validate(const struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:3688
struct setting_list * settings_list_get(enum sset_level level)
Definition settings.c:5575
bool setting_is_changeable(const struct setting *pset, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:3460
void settings_reset(void)
Definition settings.c:5232
const char * setting_name(const struct setting *pset)
Definition settings.c:3333
bool settings_game_reset(void)
Definition settings.c:5195
int setting_bitwise_get(struct setting *pset)
Definition settings.c:4257
void settings_list_update(void)
Definition settings.c:5533
char * setting_str_get(struct setting *pset)
Definition settings.c:3859
bool settings_ruleset(struct section_file *file, const char *section, bool act, bool compat)
Definition settings.c:4379
bool setting_bool_get(struct setting *pset)
Definition settings.c:3676
const char * setting_bitwise_secfile_str(secfile_data_t data, int bit)
Definition settings.c:4065
bool setting_is_visible_at_level(const struct setting *pset, enum cmdlevel plevel)
Definition settings.c:3496
bool setting_bool_set(struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:3657
void send_server_setting(struct conn_list *dest, const struct setting *pset)
Definition settings.c:5275
void send_server_settings(struct conn_list *dest)
Definition settings.c:5394
void send_server_access_level_settings(struct conn_list *dest, enum cmdlevel old_level, enum cmdlevel new_level)
Definition settings.c:5406
int read_enum_value(const struct setting *pset)
Definition settings.c:3995
setting_lock_level
Definition settings.h:76
@ SLOCK_RULESET
Definition settings.h:76
@ SLOCK_ADMIN
Definition settings.h:76
@ SLOCK_NONE
Definition settings.h:76
struct setting * set
Definition settings.h:82
bool compat
Definition settings.h:83
const char * support
Definition settings.h:29
const char * pretty
Definition settings.h:31