Freeciv21
Develop your civilization from humble roots to a global empire
server_settings.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 "fc_interface.h"
14 
15 #include "server_settings.h"
16 
21 {
24 
26 }
27 
32 {
33  fc_assert_ret_val(fc_funcs, nullptr);
35 
37 }
38 
43 {
44  fc_assert_ret_val(fc_funcs, sset_type_invalid());
45  fc_assert_ret_val(fc_funcs->server_setting_type_get, sset_type_invalid());
46 
48 }
49 
54 {
55  return sset_type_is_valid(server_setting_type_get(id));
56 }
57 
62 {
65  fc_assert_ret_val(server_setting_type_get(id) == SST_BOOL, false);
66 
68 }
69 
74 {
77  fc_assert_ret_val(server_setting_type_get(id) == SST_INT, false);
78 
80 }
81 
86 {
87  /* Only Boolean and TRUE can be supported unless setting value encoding
88  * is implemented. */
89  if (!static_cast<bool>(value)) {
90  fc_assert(value == true);
91  return SSETV_NONE;
92  }
93 
94  /* Only Boolean settings can be supported unless the setting value is
95  * encoded with the setting id. */
96  if (server_setting_type_get(setting) != SST_BOOL) {
98  == SST_BOOL);
99  return SSETV_NONE;
100  }
101 
102  return static_cast<ssetv>(setting);
103 }
104 
109 {
110  /* Only Boolean settings can be supported unless the setting value is
111  * encoded with the setting id. */
113 
114  return static_cast<server_setting_id>(enc);
115 }
116 
121 {
122  ssetv val = static_cast<ssetv>(server_setting_by_name(name));
123 
124  /* Only Boolean settings can be supported unless the setting value is
125  * encoded with the setting id. */
126  if (server_setting_type_get(static_cast<server_setting_id>(val))
127  != SST_BOOL) {
128  return SSETV_NONE;
129  }
130 
131  return val;
132 }
133 
137 const char *ssetv_rule_name(ssetv val)
138 {
139  /* Only Boolean settings can be supported unless the setting value is
140  * encoded with the setting id. */
142 
143  return server_setting_name_get(static_cast<server_setting_id>(val));
144 }
145 
149 QString ssetv_human_readable(ssetv val, bool present)
150 {
151  QString out;
152 
153  /* Only Boolean settings can be supported unless the setting value is
154  * encoded with the setting id. */
156 
157  /* TRANS: the first %s is a server setting, the second %s is it's value.
158  * Example: killstack is enabled */
159  out =
160  QString(_("%1 is %2"))
161  .arg(server_setting_name_get(static_cast<server_setting_id>(val)),
162  present ? _("enabled") : _("disabled"));
163 
164  return qUtf8Printable(out);
165 }
166 
171 {
172  /* Only boolean settings can be supported unless the setting value is
173  * encoded with the setting id. */
175  server_setting_type_get((server_setting_id) val) == SST_BOOL, false);
176 
177  return server_setting_value_bool_get(static_cast<server_setting_id>(val));
178 }
const struct functions * fc_funcs
int server_setting_id
Definition: fc_types.h:893
int ssetv
Definition: fc_types.h:560
#define _(String)
Definition: fcintl.h:50
const char * name
Definition: inputfile.cpp:118
#define fc_assert(condition)
Definition: log.h:89
#define fc_assert_ret_val(condition, val)
Definition: log.h:114
QString ssetv_human_readable(ssetv val, bool present)
Returns the server setting - value pair formated in a user readable way.
server_setting_id server_setting_by_name(const char *name)
Returns the server setting with the specified name.
bool server_setting_value_bool_get(server_setting_id id)
Returns the value of the server setting with the specified id.
enum sset_type server_setting_type_get(server_setting_id id)
Returns the type of the server setting with the specified id.
server_setting_id ssetv_setting_get(ssetv enc)
Returns the server setting of the setting - value pair.
bool server_setting_exists(server_setting_id id)
Returns TRUE iff a server setting with the specified id exists.
const char * ssetv_rule_name(ssetv val)
Returns the server setting - value pair encoded as a string.
bool ssetv_setting_has_value(ssetv val)
Returns if the server setting currently has the value in the pair.
ssetv ssetv_by_rule_name(const char *name)
Returns the server setting - value pair encoded in the string.
const char * server_setting_name_get(server_setting_id id)
Returns the name of the server setting with the specified id.
ssetv ssetv_from_values(server_setting_id setting, int value)
Returns a server setting - value pair from its setting and value;.
int server_setting_value_int_get(server_setting_id id)
Returns the value of the server setting with the specified id.
#define SERVER_SETTING_NONE
#define SSETV_NONE
int(* server_setting_val_int_get)(server_setting_id id)
Definition: fc_interface.h:29
const char *(* server_setting_name_get)(server_setting_id id)
Definition: fc_interface.h:26
bool(* server_setting_val_bool_get)(server_setting_id id)
Definition: fc_interface.h:28
server_setting_id(* server_setting_by_name)(const char *name)
Definition: fc_interface.h:25
enum sset_type(* server_setting_type_get)(server_setting_id id)
Definition: fc_interface.h:27