Feature #1473 ยป 0096-tiledef-Load-from-ruleset.patch
server/ruleset/ruleload.c | ||
---|---|---|
#include "specialist.h"
|
||
#include "style.h"
|
||
#include "tech.h"
|
||
#include "tiledef.h"
|
||
#include "traderoutes.h"
|
||
#include "unit.h"
|
||
#include "unittype.h"
|
||
... | ... | |
#define BASE_SECTION_PREFIX "base_"
|
||
#define ROAD_SECTION_PREFIX "road_"
|
||
#define RESOURCE_SECTION_PREFIX "resource_"
|
||
#define TILEDEF_SECTION_PREFIX "tiledef_"
|
||
#define GOODS_SECTION_PREFIX "goods_"
|
||
#define SPECIALIST_SECTION_PREFIX "specialist_"
|
||
#define SUPER_SPECIALIST_SECTION_PREFIX "super_specialist_"
|
||
... | ... | |
#define check_name(name) (check_strlen(name, MAX_LEN_NAME, NULL))
|
||
#define check_cityname(name) (check_strlen(name, MAX_LEN_CITYNAME, NULL))
|
||
/* avoid re-reading files */
|
||
/* Avoid re-reading files */
|
||
static const char name_too_long[] = "Name \"%s\" too long; truncating.";
|
||
#define MAX_SECTION_LABEL 64
|
||
#define section_strlcpy(dst, src) \
|
||
... | ... | |
static char *extra_sections = NULL;
|
||
static char *base_sections = NULL;
|
||
static char *road_sections = NULL;
|
||
static char *tiledef_sections = nullptr;
|
||
static struct requirement_vector reqs_list;
|
||
... | ... | |
if (ok) {
|
||
game.control.terrain_count = nval;
|
||
/* avoid re-reading files */
|
||
/* Avoid re-reading files */
|
||
if (terrain_sections) {
|
||
free(terrain_sections);
|
||
}
|
||
... | ... | |
section_list_destroy(sec);
|
||
sec = NULL;
|
||
game.control.num_tiledef_types = 0;
|
||
/* extra names */
|
||
/* Extra names */
|
||
if (ok) {
|
||
sec = secfile_sections_by_name_prefix(file, EXTRA_SECTION_PREFIX);
|
||
... | ... | |
}
|
||
}
|
||
section_list_destroy(sec);
|
||
sec = nullptr;
|
||
/* Tiledef names */
|
||
if (ok) {
|
||
sec = secfile_sections_by_name_prefix(file, TILEDEF_SECTION_PREFIX);
|
||
nval = (NULL != sec ? section_list_size(sec) : 0);
|
||
if (nval > MAX_TILEDEFS) {
|
||
ruleset_error(NULL, LOG_ERROR,
|
||
"\"%s\": Too many tiledefs (%d, max %d)",
|
||
filename, nval, MAX_TILEDEFS);
|
||
ok = FALSE;
|
||
}
|
||
}
|
||
if (ok) {
|
||
int idx;
|
||
game.control.num_tiledef_types = nval;
|
||
if (tiledef_sections) {
|
||
free(tiledef_sections);
|
||
}
|
||
tiledef_sections = fc_calloc(nval, MAX_SECTION_LABEL);
|
||
if (ok) {
|
||
for (idx = 0; idx < nval; idx++) {
|
||
const char *sec_name = section_name(section_list_get(sec, idx));
|
||
struct tiledef *td = tiledef_by_number(idx);
|
||
if (!ruleset_load_names(&td->name, NULL, file, sec_name)) {
|
||
ok = FALSE;
|
||
break;
|
||
}
|
||
section_strlcpy(&tiledef_sections[idx * MAX_SECTION_LABEL], sec_name);
|
||
}
|
||
}
|
||
}
|
||
section_list_destroy(sec);
|
||
return ok;
|
||
... | ... | |
} extra_type_iterate_end;
|
||
}
|
||
if (ok) {
|
||
/* Tiledef details */
|
||
tiledef_iterate(td) {
|
||
int tdidx = tiledef_index(td);
|
||
const char *section = &tiledef_sections[tdidx * MAX_SECTION_LABEL];
|
||
const char **slist;
|
||
int ej;
|
||
slist = secfile_lookup_str_vec(file, &nval, "%s.extras", section);
|
||
for (ej = 0; ej < nval; ej++) {
|
||
const char *sval = slist[ej];
|
||
struct extra_type *pextra = extra_type_by_rule_name(sval);
|
||
if (pextra != nullptr) {
|
||
extra_type_list_iterate(td->extras, old_extra) {
|
||
if (pextra == old_extra) {
|
||
ruleset_error(nullptr, LOG_ERROR,
|
||
"%s: Duplicate extra %s.",
|
||
section, extra_rule_name(pextra));
|
||
ok = FALSE;
|
||
break;
|
||
}
|
||
} extra_type_list_iterate_end;
|
||
if (ok) {
|
||
extra_type_list_append(td->extras, pextra);
|
||
}
|
||
} else {
|
||
ruleset_error(nullptr, LOG_ERROR,
|
||
"%s: Unknown extra name \"%s\".",
|
||
section, sval);
|
||
ok = FALSE;
|
||
}
|
||
if (!ok) {
|
||
break;
|
||
}
|
||
}
|
||
} tiledef_iterate_end;
|
||
}
|
||
if (ok) {
|
||
secfile_check_unused(file);
|
||
}
|
tools/ruleutil/rulesave.c | ||
---|---|---|
#include "sex.h"
|
||
#include "specialist.h"
|
||
#include "style.h"
|
||
#include "tiledef.h"
|
||
#include "unittype.h"
|
||
#include "version.h"
|
||
... | ... | |
}
|
||
} extra_type_by_cause_iterate_end;
|
||
// comment_tiledefs(sfile);
|
||
sect_idx = 0;
|
||
tiledef_iterate(td) {
|
||
char path[512];
|
||
const char *extra_names[MAX_EXTRA_TYPES];
|
||
int set_count;
|
||
fc_snprintf(path, sizeof(path), "tiledef_%d", sect_idx++);
|
||
save_name_translation(sfile, &(td->name), path);
|
||
set_count = 0;
|
||
extra_type_list_iterate(td->extras, pextra) {
|
||
extra_names[set_count++] = extra_rule_name(pextra);
|
||
} extra_type_list_iterate_end;
|
||
if (set_count > 0) {
|
||
secfile_insert_str_vec(sfile, extra_names, set_count,
|
||
"%s.extras", path);
|
||
}
|
||
} tiledef_iterate_end;
|
||
return save_ruleset_file(sfile, filename);
|
||
}
|
||