Freeciv-3.3
Loading...
Searching...
No Matches
modpack.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/* utility */
19#include "capability.h"
20#include "registry.h"
21#include "section_file.h"
22#include "shared.h"
23
24/* common */
25#include "game.h"
26
27#include "modpack.h"
28
31 char *filename;
32 char *target;
33};
34
35/* Get 'struct modpack_cache_list' and related functions: */
36#define SPECLIST_TAG modpack_cache
37#define SPECLIST_TYPE struct modpack_cache_item
38#include "speclist.h"
39
40#define modpack_cache_iterate(mplist, item) \
41 TYPED_LIST_ITERATE(struct modpack_cache_item, mplist, item)
42#define modpack_cache_iterate_end LIST_ITERATE_END
43
46
47/************************************************************************/
50void modpacks_init(void)
51{
52 if (is_server()) {
54 } else {
56 }
57}
58
59/************************************************************************/
62void modpacks_free(void)
63{
64 if (is_server()) {
66 free(item->modpack_name);
67 free(item->filename);
68 free(item);
70
72 } else {
74 free(item->modpack_name);
75 free(item->filename);
76 free(item->target);
77 free(item);
79
81 }
82}
83
84/************************************************************************/
92bool modpack_check_capabilities(struct section_file *file, const char *us_capstr,
93 const char *filename, bool verbose)
94{
95 enum log_level level = verbose ? LOG_WARN : LOG_DEBUG;
96
97 const char *file_capstr = secfile_lookup_str(file, "datafile.options");
98
99 if (file_capstr == nullptr) {
100 log_base(level, "\"%s\": file doesn't have a capability string",
101 filename);
102 return FALSE;
103 }
105 log_base(level, "\"%s\": file appears incompatible:",
106 filename);
107 log_base(level, " datafile options: %s", file_capstr);
108 log_base(level, " supported options: %s", us_capstr);
109 return FALSE;
110 }
112 log_base(level, "\"%s\": file requires option(s) "
113 "that freeciv doesn't support:", filename);
114 log_base(level, " datafile options: %s", file_capstr);
115 log_base(level, " supported options: %s", us_capstr);
116 return FALSE;
117 }
118
119 return TRUE;
120}
121
122/************************************************************************/
128{
129 struct fileinfo_list *files;
130
131 /* Search for modpack files. */
133
134 return files;
135}
136
137/************************************************************************/
144const char *modpack_has_ruleset(struct section_file *sf)
145{
146 if (sf != nullptr) {
148 FALSE)) {
149 return nullptr;
150 }
151
152 if (secfile_lookup_bool_default(sf, FALSE, "components.ruleset")) {
153 return secfile_lookup_str_default(sf, nullptr, "modpack.name");
154 }
155 }
156
157 return nullptr;
158}
159
160/************************************************************************/
167const char *modpack_has_tileset(struct section_file *sf)
168{
169 if (sf != nullptr) {
171 FALSE)) {
172 return nullptr;
173 }
174
175 if (secfile_lookup_bool_default(sf, FALSE, "components.tileset")) {
176 return secfile_lookup_str_default(sf, nullptr, "modpack.name");
177 }
178 }
179
180 return nullptr;
181}
182
183/************************************************************************/
189const char *modpack_serv_file(struct section_file *sf)
190{
191 if (sf != nullptr) {
192 return secfile_lookup_str_default(sf, nullptr, "ruleset.serv");
193 }
194
195 return nullptr;
196}
197
198/************************************************************************/
204const char *modpack_rulesetdir(struct section_file *sf)
205{
206 if (sf != nullptr) {
207 return secfile_lookup_str_default(sf, nullptr, "ruleset.rulesetdir");
208 }
209
210 return nullptr;
211}
212
213/************************************************************************/
219const char *modpack_tilespec(struct section_file *sf)
220{
221 if (sf != nullptr) {
222 return secfile_lookup_str_default(sf, nullptr, "tileset.tilespec");
223 }
224
225 return nullptr;
226}
227
228/************************************************************************/
235const char *modpack_cache_ruleset(struct section_file *sf)
236{
237 const char *mp_name = modpack_has_ruleset(sf);
238 struct modpack_cache_item *item;
239
240 if (mp_name == nullptr) {
241 return nullptr;
242 }
243
244 fc_assert(sf->name != nullptr);
245
246 item = fc_malloc(sizeof(struct modpack_cache_item));
247 item->modpack_name = fc_strdup(mp_name);
248 item->filename = fc_strdup(sf->name);
249
251
252 return mp_name;
253}
254
255/************************************************************************/
262const char *modpack_cache_tileset(struct section_file *sf)
263{
264 const char *mp_name = modpack_has_tileset(sf);
265 struct modpack_cache_item *item;
266 const char *target;
267
268 if (mp_name == nullptr) {
269 return nullptr;
270 }
271
272 fc_assert(sf->name != nullptr);
273
274 item = fc_malloc(sizeof(struct modpack_cache_item));
275 item->modpack_name = fc_strdup(mp_name);
276 item->filename = fc_strdup(sf->name);
277 target = secfile_lookup_str_default(sf, nullptr, "tileset.tilespec");
278 if (target != nullptr) {
279 item->target = fc_strdup(target);
280 } else {
281 item->target = nullptr;
282 }
283
285
286 return mp_name;
287}
288
289/************************************************************************/
295const char *modpack_file_from_ruleset_cache(const char *name)
296{
298 if (!fc_strcasecmp(name, item->modpack_name)) {
299 return item->filename;
300 }
302
303 return nullptr;
304}
305
306/************************************************************************/
312const char *modpack_file_from_tileset_cache(const char *name)
313{
315 if (!fc_strcasecmp(name, item->modpack_name)) {
316 return item->filename;
317 }
319
320 return nullptr;
321}
322
323/************************************************************************/
329const char *modpack_tileset_target(const char *name)
330{
332 if (!fc_strcasecmp(name, item->modpack_name)) {
333 return item->target;
334 }
336
337 return nullptr;
338}
339
340/************************************************************************/
347{
349 cb(item->modpack_name, item->filename, data);
351}
352
353
354/************************************************************************/
361{
363 cb(item->modpack_name, item->filename, data);
365}
bool has_capabilities(const char *us, const char *them)
Definition capability.c:88
char * incite_cost
Definition comments.c:76
static bool is_server(void)
const char * name
Definition inputfile.c:127
#define fc_assert(condition)
Definition log.h:177
#define log_base(level, message,...)
Definition log.h:95
log_level
Definition log.h:29
@ LOG_DEBUG
Definition log.h:35
@ LOG_WARN
Definition log.h:32
#define fc_strdup(str)
Definition mem.h:43
#define fc_malloc(sz)
Definition mem.h:34
static struct modpack_cache_list * modpack_rulesets
Definition modpack.c:44
const char * modpack_file_from_tileset_cache(const char *name)
Definition modpack.c:312
void modpacks_free(void)
Definition modpack.c:62
const char * modpack_has_ruleset(struct section_file *sf)
Definition modpack.c:144
const char * modpack_tileset_target(const char *name)
Definition modpack.c:329
void modpack_tileset_cache_iterate(mrc_cb cb, void *data)
Definition modpack.c:360
void modpack_ruleset_cache_iterate(mrc_cb cb, void *data)
Definition modpack.c:346
bool modpack_check_capabilities(struct section_file *file, const char *us_capstr, const char *filename, bool verbose)
Definition modpack.c:92
const char * modpack_has_tileset(struct section_file *sf)
Definition modpack.c:167
static struct modpack_cache_list * modpack_tilesets
Definition modpack.c:45
const char * modpack_file_from_ruleset_cache(const char *name)
Definition modpack.c:295
#define modpack_cache_iterate_end
Definition modpack.c:42
const char * modpack_serv_file(struct section_file *sf)
Definition modpack.c:189
void modpacks_init(void)
Definition modpack.c:50
const char * modpack_rulesetdir(struct section_file *sf)
Definition modpack.c:204
struct fileinfo_list * get_modpacks_list(void)
Definition modpack.c:127
const char * modpack_cache_ruleset(struct section_file *sf)
Definition modpack.c:235
#define modpack_cache_iterate(mplist, item)
Definition modpack.c:40
const char * modpack_cache_tileset(struct section_file *sf)
Definition modpack.c:262
const char * modpack_tilespec(struct section_file *sf)
Definition modpack.c:219
void(* mrc_cb)(const char *, const char *, void *data)
Definition modpack.h:45
#define MODPACK_SUFFIX
Definition modpack.h:22
#define MODPACK_CAPSTR
Definition modpack.h:20
const char * secfile_lookup_str(const struct section_file *secfile, const char *path,...)
bool secfile_lookup_bool_default(const struct section_file *secfile, bool def, const char *path,...)
const char * secfile_lookup_str_default(const struct section_file *secfile, const char *def, const char *path,...)
struct setting_list * level[OLEVELS_NUM]
Definition settings.c:190
const struct strvec * get_data_dirs(void)
Definition shared.c:886
struct fileinfo_list * fileinfolist_infix(const struct strvec *dirs, const char *infix, bool nodups)
Definition shared.c:1204
Definition climisc.h:82
char * modpack_name
Definition modpack.c:30
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:186
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47