Freeciv-3.1
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
76/* forward declaration */
77struct setting;
78
79struct setting *setting_by_number(int id);
80struct setting *setting_by_name(const char *name);
81int setting_number(const struct setting *pset);
82
83const char *setting_name(const struct setting *pset);
84const char *setting_short_help(const struct setting *pset);
85const char *setting_extra_help(const struct setting *pset, bool constant);
86enum sset_type setting_type(const struct setting *pset);
87enum sset_level setting_level(const struct setting *pset);
88enum sset_category setting_category(const struct setting *pset);
89
90bool setting_is_changeable(const struct setting *pset,
91 struct connection *caller, char *reject_msg,
92 size_t reject_msg_len);
93bool setting_is_visible_at_level(const struct setting *pset,
94 enum cmdlevel plevel);
95bool setting_is_visible(const struct setting *pset,
96 struct connection *caller);
97
98const char *setting_value_name(const struct setting *pset, bool pretty,
99 char *buf, size_t buf_len);
100const char *setting_default_name(const struct setting *pset, bool pretty,
101 char *buf, size_t buf_len);
102
103void setting_set_to_default(struct setting *pset);
104
105int read_enum_value(const struct setting *pset);
106const char *setting_enum_secfile_str(secfile_data_t data, int val);
107const char *setting_bitwise_secfile_str(secfile_data_t data, int bit);
108
109/* Type SST_BOOL setting functions. */
110bool setting_bool_set(struct setting *pset, const char *val,
111 struct connection *caller, char *reject_msg,
112 size_t reject_msg_len);
113bool setting_bool_validate(const struct setting *pset, const char *val,
114 struct connection *caller, char *reject_msg,
115 size_t reject_msg_len);
116bool setting_bool_get(struct setting *pset);
117
118/* Type SST_INT setting functions. */
119int setting_int_min(const struct setting *pset);
120int setting_int_max(const struct setting *pset);
121bool setting_int_set(struct setting *pset, int val,
122 struct connection *caller, char *reject_msg,
123 size_t reject_msg_len);
124bool setting_int_validate(const struct setting *pset, int val,
125 struct connection *caller, char *reject_msg,
126 size_t reject_msg_len);
127int setting_int_get(struct setting *pset);
128
129/* Type SST_STRING setting functions. */
130bool setting_str_set(struct setting *pset, const char *val,
131 struct connection *caller, char *reject_msg,
132 size_t reject_msg_len);
133bool setting_str_validate(const struct setting *pset, const char *val,
134 struct connection *caller, char *reject_msg,
135 size_t reject_msg_len);
136char *setting_str_get(struct setting *pset);
137
138/* Type SST_ENUM setting functions. */
139const char *setting_enum_val(const struct setting *pset, int val,
140 bool pretty);
141bool setting_enum_set(struct setting *pset, const char *val,
142 struct connection *caller, char *reject_msg,
143 size_t reject_msg_len);
144bool setting_enum_validate(const struct setting *pset, const char *val,
145 struct connection *caller, char *reject_msg,
146 size_t reject_msg_len);
147
148/* Type SST_BITWISE setting functions. */
149const char *setting_bitwise_bit(const struct setting *pset,
150 int bit, bool pretty);
151bool setting_bitwise_set(struct setting *pset, const char *val,
152 struct connection *caller, char *reject_msg,
153 size_t reject_msg_len);
154bool setting_bitwise_validate(const struct setting *pset, const char *val,
155 struct connection *caller, char *reject_msg,
156 size_t reject_msg_len);
157int setting_bitwise_get(struct setting *pset);
158
159void setting_action(const struct setting *pset);
160
161bool setting_non_default(const struct setting *pset);
162bool setting_locked(const struct setting *pset);
163void setting_lock_set(struct setting *pset, bool lock);
164
165/* get 'struct setting_list' and related functions: */
166#define SPECLIST_TAG setting
167#define SPECLIST_TYPE struct setting
168#include "speclist.h"
169
170#define setting_list_iterate(_setting_list, _setting) \
171 TYPED_LIST_ITERATE(struct setting, _setting_list, _setting)
172#define setting_list_iterate_end \
173 LIST_ITERATE_END
174
175/* Iterate over all settings; this additionally checks if the list is
176 * created and valid. */
177#define settings_iterate(_level, _pset) \
178{ \
179 struct setting_list *_setting_list = settings_list_get(_level); \
180 if (_setting_list != NULL) { \
181 setting_list_iterate(_setting_list, _pset) {
182
183#define settings_iterate_end \
184 } setting_list_iterate_end; \
185 } \
186}
187
188void settings_game_start(void);
189void settings_game_save(struct section_file *file, const char *section);
190void settings_game_load(struct section_file *file, const char *section);
191bool settings_game_reset(void);
192
193void settings_init(bool act);
194void settings_reset(void);
195void settings_turn(void);
196void settings_free(void);
197int settings_number(void);
198
199void settings_list_update(void);
200struct setting_list *settings_list_get(enum sset_level level);
201
202bool settings_ruleset(struct section_file *file, const char *section, bool act);
203
204void send_server_setting(struct conn_list *dest, const struct setting *pset);
205void send_server_settings(struct conn_list *dest);
206void send_server_access_level_settings(struct conn_list *dest,
207 enum cmdlevel old_level,
208 enum cmdlevel new_level);
209void send_server_setting_control(struct connection *pconn);
210
211void setting_changed(struct setting *pset);
212enum setting_default_level setting_get_setdef(const struct setting *pset);
213
214#ifdef __cplusplus
215}
216#endif /* __cplusplus */
217
218#endif /* FC__SETTINGS_H */
const char * name
Definition inputfile.c:127
const void * secfile_data_t
struct setting_list * level[OLEVELS_NUM]
Definition settings.c:183
bool setting_int_validate(const struct setting *pset, int val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:3583
void settings_init(bool act)
Definition settings.c:4952
void setting_action(const struct setting *pset)
Definition settings.c:4168
int setting_int_get(struct setting *pset)
Definition settings.c:3608
const char * setting_default_name(const struct setting *pset, bool pretty, char *buf, size_t buf_len)
Definition settings.c:4102
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:3861
struct setting * setting_by_name(const char *name)
Definition settings.c:3138
void setting_set_to_default(struct setting *pset)
Definition settings.c:4138
const char * setting_value_name(const struct setting *pset, bool pretty, char *buf, size_t buf_len)
Definition settings.c:4066
void settings_game_load(struct section_file *file, const char *section)
Definition settings.c:4648
const char * setting_extra_help(const struct setting *pset, bool constant)
Definition settings.c:3179
int setting_number(const struct setting *pset)
Definition settings.c:3153
struct setting * setting_by_number(int id)
Definition settings.c:3130
bool setting_int_set(struct setting *pset, int val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:3563
enum sset_category setting_category(const struct setting *pset)
Definition settings.c:3207
bool setting_is_visible(const struct setting *pset, struct connection *caller)
Definition settings.c:3326
bool setting_locked(const struct setting *pset)
Definition settings.c:4420
bool setting_non_default(const struct setting *pset)
Definition settings.c:4394
enum sset_type setting_type(const struct setting *pset)
Definition settings.c:3191
void settings_free(void)
Definition settings.c:4993
bool setting_str_set(struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:3634
int setting_int_max(const struct setting *pset)
Definition settings.c:3553
void setting_lock_set(struct setting *pset, bool lock)
Definition settings.c:4428
enum sset_level setting_level(const struct setting *pset)
Definition settings.c:3199
bool setting_bitwise_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_enum_secfile_str(secfile_data_t data, int val)
Definition settings.c:3690
void settings_game_save(struct section_file *file, const char *section)
Definition settings.c:4561
int settings_number(void)
Definition settings.c:5005
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:3654
void settings_turn(void)
Definition settings.c:4985
bool settings_ruleset(struct section_file *file, const char *section, bool act)
Definition settings.c:4178
const char * setting_enum_val(const struct setting *pset, int val, bool pretty)
Definition settings.c:3702
void setting_changed(struct setting *pset)
Definition settings.c:5341
enum setting_default_level setting_get_setdef(const struct setting *pset)
Definition settings.c:5349
void settings_game_start(void)
Definition settings.c:4548
bool setting_enum_set(struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:3832
const char * setting_short_help(const struct setting *pset)
Definition settings.c:3170
void send_server_setting_control(struct connection *pconn)
Definition settings.c:5177
const char * setting_bitwise_bit(const struct setting *pset, int bit, bool pretty)
Definition settings.c:3887
int setting_int_min(const struct setting *pset)
Definition settings.c:3544
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:4043
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:3508
struct setting_list * settings_list_get(enum sset_level level)
Definition settings.c:5312
bool setting_is_changeable(const struct setting *pset, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:3289
void settings_reset(void)
Definition settings.c:4971
const char * setting_name(const struct setting *pset)
Definition settings.c:3162
bool settings_game_reset(void)
Definition settings.c:4935
int setting_bitwise_get(struct setting *pset)
Definition settings.c:4056
void settings_list_update(void)
Definition settings.c:5270
char * setting_str_get(struct setting *pset)
Definition settings.c:3679
bool setting_bool_get(struct setting *pset)
Definition settings.c:3496
const char * setting_bitwise_secfile_str(secfile_data_t data, int bit)
Definition settings.c:3875
bool setting_is_visible_at_level(const struct setting *pset, enum cmdlevel plevel)
Definition settings.c:3316
bool setting_bool_set(struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:3477
void send_server_setting(struct conn_list *dest, const struct setting *pset)
Definition settings.c:5014
void send_server_settings(struct conn_list *dest)
Definition settings.c:5133
void send_server_access_level_settings(struct conn_list *dest, enum cmdlevel old_level, enum cmdlevel new_level)
Definition settings.c:5145
int read_enum_value(const struct setting *pset)
Definition settings.c:3805
const char * support
Definition settings.h:29
const char * pretty
Definition settings.h:31